diff options
Diffstat (limited to 'libical/src')
220 files changed, 41192 insertions, 6814 deletions
diff --git a/libical/src/.cvsignore b/libical/src/.cvsignore index c038ed7864..bbc8ba00d1 100644 --- a/libical/src/.cvsignore +++ b/libical/src/.cvsignore @@ -1,2 +1,5 @@ Makefile -Makefile.in
\ No newline at end of file +.deps +.libs +*.lo +*.la diff --git a/libical/src/Makefile.am b/libical/src/Makefile.am index 7a3f9fcdff..5e5cd331db 100644 --- a/libical/src/Makefile.am +++ b/libical/src/Makefile.am @@ -4,6 +4,16 @@ else PYTHON_DIR = endif -# For evolution we only build libical at present. -SUBDIRS = libical libicalvcal -#SUBDIRS = libical libicalss libicalvcal # $(PYTHON_DIR) test +if WITH_JAVA +JAVA_DIR = java +else +JAVA_DIR = +endif + +if WITH_CAP +LIBICALCAP_DIR = libicalcap +else +LIBICALCAP_DIR = +endif + +SUBDIRS = libical libicalss $(LIBICALCAP_DIR) libicalvcal $(PYTHON_DIR) $(JAVA_DIR) test diff --git a/libical/src/Net-ICal-Libical/MANIFEST b/libical/src/Net-ICal-Libical/MANIFEST new file mode 100644 index 0000000000..1a6880e8b4 --- /dev/null +++ b/libical/src/Net-ICal-Libical/MANIFEST @@ -0,0 +1,16 @@ +MANIFEST +Makefile.PL +lib/Net/ICal/Libical.pm +netical.i +netical_wrap.c +netical_wrap.doc +test-data/2446.mime +test-data/error +test-data/mail-examples +test-data/no-error +test-data/rfc2445.ics +test-data/rfc2446.ics +test-data/single-with-error +test/example.pl +test/libical.pl +test/swig.pl diff --git a/libical/src/Net-ICal-Libical/Makefile.PL b/libical/src/Net-ICal-Libical/Makefile.PL new file mode 100644 index 0000000000..f46c61bc02 --- /dev/null +++ b/libical/src/Net-ICal-Libical/Makefile.PL @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# -*- Mode: perl -*- + +use ExtUtils::MakeMaker; +WriteMakefile( + 'MAKEFILE'=> 'Makefile', + 'VERSION_FROM' => 'lib/Net/ICal/Libical.pm', + 'NAME' => 'Net::ICal::Libical', + 'INC' => '-I../libical -I ../libicalss', + 'LIBS' => ['-L../libical/.libs -L../libicalss/.libs -lical -licalss -lm'], + 'OBJECT' => 'netical_wrap.o', # Object files + dist => { + COMPRESS =>'gzip', + SUFFIX =>'gz' + }, + + ); + +sub MY::top_targets +{ + my $self = shift; + + my $old = $self->MM::top_targets; + + return "all:: netical_wrap.o\n$old"; + +} + +sub MY::postamble +{ + + return <<EOM; + +netical_wrap.c: netical.i + swig -perl5 -package Net::ICal::Libical netical.i + +wrap: + swig -perl5 -package Net::ICal::Libical netical.i + + +EOM +} diff --git a/libical/src/Net-ICal-Libical/README b/libical/src/Net-ICal-Libical/README new file mode 100644 index 0000000000..b4b4b9c8b9 --- /dev/null +++ b/libical/src/Net-ICal-Libical/README @@ -0,0 +1,7 @@ + +Net::ICal::Libical: A perl binding to libical. + +This code is PRE-ALPHA. Some of the test routines work, but the code +is not really useful. It is looking for an author, so if you'd like to +have this binding working, please volunteer to work on it. Contact +Eric Busboom, eric@softwarestudio.org diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical.pm new file mode 100644 index 0000000000..a9b15f3855 --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical.pm @@ -0,0 +1,386 @@ +#!/usr/bin/perl +# -*- Mode: perl -*- +#====================================================================== +# FILE: Libical.pm +# CREATOR: eric +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +#====================================================================== + +# This part of this file was automatically generated by SWIG + +require Net::ICal::Libical::Component; +require Net::ICal::Libical::Property; +require Net::ICal::Libical::Time; +require Net::ICal::Libical::Duration; + +package Net::ICal::Libical; +require Exporter; +require DynaLoader; +@ISA = qw(Exporter DynaLoader); +package Net::ICal::Libical; +bootstrap Net::ICal::Libical; +var_Net__ICal__Libical_init(); +@EXPORT = qw( ); + +$VERSION = "0.01"; + +1; + + + + +sub validate_component { + my $comp_str = shift; + + + my $c = Net::ICal::Libical::icalparser_parse_string($comp_str); + my $out; + + die "Failed to parse component" if !$c; + + my $r = Net::ICal::Libical::icalrestriction_check($c); + + $out = Net::ICal::Libical::icalcomponent_as_ical_string($c); + + Net::ICal::Libical::icalcomponent_free($c); + + return $out; + +} + + +sub generate_occurrences { + my $rule = shift; + my $start = shift; + my $count = shift; + + my @out; + + my $array = Net::ICal::Libical::icallangbind_new_array(25); + + Net::ICal::Libical::icalrecur_expand_recurrence($rule,$start, + $count,$array); + + for($i = 0; $i<$count; $i++){ + my $t = Net::ICal::Libical::icallangbind_access_array($array,$i); + if($t != 0) { + push(@out,$t); + } + + } + + Net::ICal::Libical::icallangbind_free_array($array); + + return @out; +} + + +# The remaining code is just the interface declarations for a complete +# perl binding to libical. Currently, it is looking for an author.... + + + + + +1; + +__END__ + +#""" Represent iCalendar DATE, TIME and DATE-TIME "" + +package Net::ICal::Libical::Time; +@ISA = (Property); + +sub new {} + +#"""Updates value and value_type based on the (internal) self.tt.""" +sub _update_value { } + +# " Return true if this is a valid time " +sub valid { } + +# """ Return or set time in seconds past POSIX epoch""" +sub utc_seconds {} + +# """ Return or set boolean indicating if time is in UTC """ +sub is_utc {} + +# Get/Set booll indicating is time is a date +sub is_date(self,v=None): + +#"" Return or set the timezone string for this time """ +sub timezone {} + +#"" Get or set the seconds component of this time """ +sub second {} +sub minute {} +sub hour {} +sub day {} +sub month {} +sub year {} + +# How dow you over load +,- in perl? + +# Add duration to time = time +sub __add__{} + +# Subtract time from time = duration +# Subtract duration from time = time +sub __sub__(self,o): + + +package Net::ICal::Libical::Duration(Property): +@ISA = (Property); + +sub new {} +sub _update_value {} +#"Return true if this is a valid duration" +sub valid {} +# """Return or set duration in seconds""" +sub seconds {} + + +#"""Represent a span of time""" + +package Net::ICal::Libical::Period; +@ISA = (Property); + +sub new{} + +sub _end_is_duration {} +sub _end_is_time {} +sub _update_value {} + +#"Return true if this is a valid period" +sub valid {} + +#Return or set start time of the period. The start time may be +#expressed as an RFC2445 format string or an instance of Time. +#The return value is an instance of Time +sub start {} + +#Return or set end time of the period. The end time may be +#expressed as an RFC2445 format string or an instance of Time. +#The return value is an instance of Time. + +#If the Period has a duration set, but not an end time, this +#method will caluculate the end time from the duration. +sub end {} + +#Return or set the duration of the period. The duration may be +#expressed as an RFC2445 format string or an instance of Duration. +#The return value is an instance of Duration. +#If the period has an end time set, but not a duration, this +#method will calculate the duration from the end time. +sub duration{} + +# Get set the timezone for the period. Basically returns self->dict{TZID} +sub timezone(self,v=None): + + +# Represents the value and all parameters of an attendee +package Net::ICal::Libical::Attendee(Property): +@ISA = (Property); + +sub new{} + +# Methods for accessing enumerated parameters +sub cn {} +sub cutype {} +sub dir {} +sub delegated_from {} +sub delegated_to {} +sub language {} +sub member {} +sub partstat {} +sub role {} +sub rsvp {} +sub sent_by {} + + +package Net::ICal::Libical::Organizer; +@ISA = (Property) +# Methods for accessing enumerated parameters +sub cn{} +sub dir{} +sub language {} +sub sent_by {} + +package Net::ICal::Libical::Recurrence_Id; +@ISA= (Property) + +package Net::ICal::Libical::Attach; +@ISA= (Property) + +package Net::ICal::Libical::Event; +@ISA= (Component) + +sub component_type {} + +#"Returns a copy of the object." +sub clone {} + +#Sets or returns the value of the DTEND property. +#Usage: +#dtend(time_obj) # Set the value using a Time object +#dtend('19970101T123000Z') # Set the value as an iCalendar string +#dtend(982362522) # Set the value using seconds (time_t) +#dtend() # Return a Time +# +#If the dtend value is being set and duration() has a value, the +#duration property will be removed. +sub dtend{} + +#Sets or returns the value of the duration property. +#Usage: +#duration(dur_obj) # Set the value using a Duration object +#duration("P3DT12H") # Set value as an iCalendar string +#duration(3600) # Set duration using seconds +#duration() # Return a duration +# +#If the duration value is being set and dtend() has a value, the dtend +#property will be removed. +sub duration{} + +#Sets attendees or returns a list of Attendee objects. +sub attendees {} + +#Sets or gets the value of the ORGANIZER property. +#Usage: +#organizer(orgObj) # Set value using an organizer object +#organizer('MAILTO:jd@not.com') # Set value using a CAL-ADDRESS string +#organizer() # Return a CAL-ADDRESS string +sub organizer{} + +#"Sets or gets the SUMMARY value of the Event." +sub summary{} + +#Sets or gets the UID of the Event. +sub uid{} + +#Sets or gets the value for the RECURRENCE-ID property. +#Usage: +#Recurrence_id(recIdObj) # Set using a Recurrence_Id object +#Recurrence_id("19700801T133000") # Set using an iCalendar string +#Recurrence_id(8349873494) # Set using seconds from epoch +#Recurrence_id() # Return a Time +sub recurrence_id{} + +#Sets or gets the SEQUENCE value of the Event. +#Usage: +#sequence(1) # Set the value using an integer +#sequence('2') # Set the value using a string containing an integer +#sequence() # Return an integer +sub sequence{} + +#Sets or returns the value of the LAST-MODIFIED property. +#Usage: +#lastmodified(time_obj) # Set the value using a Time object +#lastmodified('19970101T123000Z')# Set using an iCalendar string +#lastmodified(982362522) # Set using seconds +#lastmodified() # Return a Time +sub lastmodified{} + + + +#Sets or returns the value of the CREATED property. +#Usage: +#created(time_obj) # Set the value using a Time object +#created('19970101T123000Z') # Set using an iCalendar string +#created(982362522) # Set using seconds +#created() # Return a Time +sub created {} + + +sub related_to{} +sub comment{} + +"Sets or returns the value of the DESCRIPTION property." + +sub description {} + +#Sets categories or returns a list of Attendee objects. +sub categories {} + +sub attach{} + +#Represents a set of event occurrences. This +#package controls a component's RRULE, EXRULE, RDATE and EXDATE +#properties and can produce from them a set of occurrences. +package Net::ICal::Libical::RecurrenceSet: + + +#Include a date or rule to the set. +#Use date= or pass in a +#Time instance to include a date. Included dates will add an +#RDATE property or will remove an EXDATE property of the same +#date. +#Use rule= or pass in a string to include a rule. Included +#rules with either add a RRULE property or remove an EXRULE +#property. + +sub include{} + +#Exclude date or rule to the set. +#Use date= or pass in a Time instance to exclude a +#date. Excluded dates will add an EXDATE property or will remove +#an RDATE property of the same date. +#Use rule= or pass in a string to exclude a rule. Excluded +#rules with either add an EXRULE property or remove an RRULE +#property. +sub exclude{} + +#Return 'count' occurrences as a tuple of Time instances. +sub occurrences{} + +package Net::ICal::Libical::Store; +sub new{} +sub path{} +sub mark{} +sub commit{} +sub addComponent{} +sub removeComponent{} +sub countComponents{} +sub select{} +sub clearSelect{} +sub fetch{} +sub fetchMatchK{} +sub modify{} +sub currentComponent{} +sub firstComponent{} +sub nextComponent{} + + +package Net::ICal::Libical::FileStore; +@ISA = (Store) +sub new{} +sub path{} +sub mark{} +sub commit{} +sub addComponent{} +sub removeComponent{} +sub countComponents{} +sub select{} +sub clearSelect{} +sub fetch{} +sub fetchMatchK{} +sub modify{} +sub currentComponent{} +sub firstComponent{} +sub nextComponent{} + + +1; diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm new file mode 100644 index 0000000000..c25297c111 --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm @@ -0,0 +1,175 @@ +#!/usr/bin/perl +# -*- Mode: perl -*- +#====================================================================== +# FILE: Component.pm +# CREATOR: eric 1 Mar 01 +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2000, Eric Busboom, eric@softwarestudio.org +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +# +#====================================================================== + + + +package Net::ICal::Libical::Component; +use Net::ICal::Libical; + +use strict; + +sub new{ + my $class = shift; + my $ical_str = shift; # Ical data in string form + my $self = {}; + + $self->{'comp_p'} = Net::ICal::Libical::icalparser_parse_string($ical_str); + + die "Can't parse string into component" if !$self->{'comp_p'}; + + bless $self, $class; +} + +sub new_from_ref { + my $class = shift; + my $r = shift; + my $self = {}; + + $self->{'comp_p'} = $r; + + bless $self, $class; +} + +# Destroy must call icalcomponent_free() if icalcomponent_get_parent() +# returns NULL +sub DESTROY { + my $self = shift; + + my $c = $self->{'comp_p'}; + + if($c && !Net::ICal::Libical::icalcomponent_get_parent($c)){ + Net::ICal::Libical::icalcomponent_free($c); + } + +} + +# Return an array of all properties of the given type +sub properties{ + + my $self = shift; + my $prop_name = shift; + + my @props; + + if(!$prop_name){ + $prop_name = 'ANY'; + } + + # To loop over properties + # $comp_p = $self->{'comp_p'} + # $p = icallangbind_get_first_property($comp_p,$prop_name) + # $p = icallangbind_get_next_property($comp_p,$prop_name) + + my $c = $self->{'comp_p'}; + my $p; + + for($p = Net::ICal::Libical::icallangbind_get_first_property($c,$prop_name); + $p; + $p = Net::ICal::Libical::icallangbind_get_next_property($c,$prop_name)){ + + my $d_string = Net::ICal::Libical::icallangbind_property_eval_string($p,"=>"); + my %dict = %{eval($d_string)}; + + $dict{'ref'} = $p; + + # Now, look at $dict{'value_type'} or $dict{'name'} to construct a + # derived class of Property. I'll do this later. + + my $prop; + + if($dict{'value_type'} eq 'DATE' or $dict{'value_type'} eq 'DATE-TIME'){ + $prop = new Net::ICal::Libical::Time(\%dict); + } elsif($dict{'value_type'} eq 'DURATION' ) { + $prop = new Net::ICal::Libical::Duration(\%dict); + } else { + $prop = new Net::ICal::Libical::Property(\%dict); + } + + push(@props,$prop); + + } + + + return @props; + +} + + +sub add_property { + + # if there is a 'ref' key in the prop's dict, then it is owned by + # an icalcomponent, so dont add it again. But, you may check that + # it is owned by this component with: + # icalproperty_get_parent(p->{'ref'}') != $self->{'comp_p'} + + # If there is no 'ref' key, then create one with $p->{'ref'} = + # icalproperty_new_from_string($p->as_ical_string) + +} + +sub remove_property { + +# If $p->{'ref'} is set, then remove the property with +# icalcomponent_remove_property() } +} + +# Return an array of all components of the given type +sub components { + + my $self = shift; + my $comp_name = shift; + + my @comps; + + if(!$comp_name){ + $comp_name = 'ANY'; + } + + my $c = $self->{'comp_p'}; + my $p; + + for($p = Net::ICal::Libical::icallangbind_get_first_component($c,$comp_name); + $p; + $p = Net::ICal::Libical::icallangbind_get_next_component($c,$comp_name)){ + + push(@comps, Net::ICal::Libical::Component->new_from_ref($p)); + + } + + return @comps; + +} + + +sub add_component {} + +sub remove_component {} + +sub as_ical_string { + my $self = shift; + + return Net::ICal::Libical::icalcomponent_as_ical_string($self->{'comp_p'}) +} + + + +1; diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Duration.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Duration.pm new file mode 100644 index 0000000000..13ec9c437e --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Duration.pm @@ -0,0 +1,160 @@ +#============================================================================= +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. (Either the Artistic License or +# the GPL.) +# +#============================================================================= + +=head1 NAME + +Net::ICal::Duration -- represent a length of time + +=head1 SYNOPSIS + + use Net::ICal; + $d = Net::ICal::Duration->new("P3DT6H15M10S"); + $d = Net::ICal::Duration->new(3600); # 1 hour in seconds + +=head1 DESCRIPTION + +I<Duration> Represents a length of time, such a 3 days, 30 seconds or +7 weeks. You would use this for representing an abstract block of +time; "I want to have a 1-hour meeting sometime." If you want a +calendar- and timezone-specific block of time, see Net::ICal::Period. + +=cut + +#============================================================================= + +package Net::ICal::Libical::Duration; +use Net::ICal::Libical::Property; +use strict; +use Carp; +@Net::ICal::Libical::Duration::ISA = qw ( Net::ICal::Libical::Property ); + +=head1 METHODS + +=head2 new + +Create a new I<Duration> from: + +=over 4 + +=item * A string in RFC2445 duration format + +=item * An integer representing a number of seconds + +=cut + +sub new { + my $package = shift; + my $arg = shift; + my $self; + + if (ref($arg) == 'HASH'){ + # Construct from dictionary + $self = Net::ICal::Libical::Property::new($package,$arg); + my $val=Net::ICal::Libical::icalproperty_get_value_as_string($self->{'ref'}); + $self->{'dur'} = Net::ICal::Libical::icaldurationtype_from_string($val); + + return $self; + + } elsif ($arg =~ /^[-+]?\d+$/){ + # Seconds + $self = Net::ICal::Libical::Property::new($package,'DURATION'); + $self->{'dur'} = Net::ICal::Libical::icaldurationtype_new_from_int($arg); + } elsif ($arg) { + # iCalendar string + $self = Net::ICal::Libical::Property::new($package,'DURATION'); + $self->{'dur'} = Net::ICal::Libical::icaldurationtype_new_from_string($arg); + } else { + die; + } + + $self->_update_value(); + return $self; + +} + +sub _update_value { + my $self = shift; + + die "Can't find internal icalduration reference" if !$self->{'dur'}; + + $self->value(Net::ICal::Libical::icaldurationtype_as_ical_string($self->{'dur'})); + +} +=head2 clone() + +Return a new copy of the duration. + +=cut + +sub clone { + die "Not Implemented"; + +} + + +=head2 is_valid() + +Determine if this is a valid duration (given criteria TBD). + +=cut + +sub is_valid { + + die "Not Implemented;" + +} + +=head2 seconds() + +Set or Get the length of the duration as seconds. + +=cut + +sub seconds { + my $self = shift; + my $seconds = shift; + + if($seconds){ + $self->{'dur'} = + Net::ICal::Libical::icaldurationtype_from_int($seconds); + $self->_update_value(); + } + + return Net::ICal::Libical::icaldurationtype_as_int($self->{'dur'}); + +} + +=head2 add($duration) + +Return a new duration that is the sum of this and $duration. Does not +modify this object. + +=cut + +sub add { + my ($self, $duration) = @_; + + return new Duration($self->seconds() + $duration->seconds()); +} + + +=head2 subtract($duration) + +Return a new duration that is the difference between this and +$duration. Does not modify this object. + +=cut + +sub subtract { + my ($self, $duration) = @_; + + return new Duration($self->seconds() - $duration->seconds()); +} + +1; diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Period.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Period.pm new file mode 100644 index 0000000000..ecf29f3370 --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Period.pm @@ -0,0 +1,359 @@ +#!/usr/bin/perl -w +# -*- Mode: perl -*- +#====================================================================== +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +# $Id$ +# +# (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org +# +# $Log +#====================================================================== + + +=pod +=head1 NAME + +Net::ICal::Period -- represent a period of time + +=head1 SYNOPSIS + + use Net::ICal; + $p = new Net::ICal::Period("19970101T120000","19970101T123000"); + $p = new Net::ICal::Period("19970101T120000","PT3W2D40S"); + $p = new Net::ICal::Period(time(),3600); + $p = new Net::ICal::Period( + new Net::ICal::Time("19970101T120000", + "America/Los_Angeles"), + new Net::ICal::Duration("2h")); + +=head1 DESCRIPTION + +Use this to make an object representing a block of time on a +real schedule. You can either say, "This event starts at 12 +and ends at 2" or "This event starts at 12 and lasts 2 hours." + +These two ways of specifying events can be treated differently +in schedules. If you say, "The meeting is from 12 to 2, but I +have to leave at 2," you are implying that the start date and +end date are fixed. If you say, "I have a 2-hour drive to +Chicago, and I need to leave at 4," you are saying that it will +take 2 hours no matter when you leave, and that moving the start +time will slide the end time correspondingly. + +=head1 BASIC METHODS + +=cut + + +#========================================================================= + +package Net::ICal::Period; +use strict; +use Net::ICal::Time; +use Net::ICal::Duration; + +use UNIVERSAL qw(isa); + +#------------------------------------------------------------------------- + +=pod +=head2 new($time, $time|$duration) + +Creates a new period object given to parameters: The first must be a +I<Time> object or valid argument to Net::ICal::Time::new. + +The second can be either: + +=pod + +=over 4 + +=item * a I<Time> object + +=item * a valid argument to Net::ICal::Time::new. + +=item * a I<Duration> object + +=item * a valid argument to Net::ICal::Duration::new. + +=back + +Either give a start time and an end time, or a start time and a duration. + +=cut + +sub new{ + my $package = shift; + my $arg1 = shift; + my $arg2 = shift; + my $self = {}; + + # Is the string in RFC2445 Format? + if(!$arg2 and $arg1 =~ /\//){ + my $tmp = $arg1; + ($arg1,$arg2) = split(/\//,$tmp); + } + + + if( ref($arg1) eq 'Net::ICal::Time'){ + $self->{START} = $arg1->clone(); + } else { + $self->{START} = new Net::ICal::Time($arg1); + } + + + if(isa($arg2,'Net::ICal::Time')){ + $self->{END} = $arg2->clone(); + } elsif (isa($arg2,'Net::ICal::Duration')) { + $self->{DURATION} = $arg2->clone(); + } elsif ($arg2 =~ /^P/) { + $self->{DURATION} = new Net::ICal::Duration($arg2); + } else { + # Hope that it is a time string + $self->{END} = new Net::ICal::Time($arg2); + } + + return bless($self,$package); +} + +#-------------------------------------------------------------------------- +=pod +=head2 clone() + +Create a copy of this component + +=cut +# XXX implement this +sub clone { + return "Not implemented"; +} + +#---------------------------------------------------------------------------- +=pod +=head2 is_valid() + +Return true if: + There is an end time and: + Both start and end times have no timezone ( Floating time) or + Both start and end time have (possibly different) timezones or + Both start and end times are in UTC and + The end time is after the start time. + + There is a duration and the duration is positive + +=cut + +# XXX implement this + +sub is_valid { + return "Not implemented"; +} + +#--------------------------------------------------------------------------- +=pod +=head2 start([$time]) + +Accessor for the start time of the event as a I<Time> object. +Can also take a valid time string or an integer (number of +seconds since the epoch) as a parameter. If a second parameter +is given, it'll set this Duration's start time. + +=cut + +sub start{ + my $self = shift; + my $t = shift; + + if($t){ + if(isa($t,'Net::ICal::Time')){ + $self->{START} = $t->clone(); + } else { + $self->{START} = new Net::ICal::Time($t); + } + } + + return $self->{START}; +} + +#----------------------------------------------------------------- +=pod +=head2 end([$time]) + +Accessor for the end time. Takes a I<Time> object, a valid time string, +or an integer and returns a time object. This routine is coupled to +the I<duration> accessor. See I<duration> below for more imformation. + +=cut + +sub end{ + + my $self = shift; + my $t = shift; + my $end; + + if($t){ + if(isa($t,'Net::ICal::Time')){ + $end = $t->clone(); + } else { + $end = new Net::ICal::Time($t); + } + + # If duration exists, use the time to compute a new duration + if ($self->{DURATION}){ + $self->{DURATION} = $end->subtract($self->{START}); + } else { + $self->{END} = $end; + } + } + + # Return end time, possibly computing it from DURATION + if($self->{DURATION}){ + return $self->{START}->add($self->{DURATION}); + } else { + return $self->{END}; + } + +} + +#---------------------------------------------------------------------- +=pod +=head2 duration([$duration]) + +Accessor for the duration of the event. Takes a I<duration> object and +returns a I<Duration> object. + +Since the end time and the duration both specify the end time, the +object will store one and access to the other will be computed. So, + +if you create: + + $p = new Net::ICal::Period("19970101T120000","19970101T123000") + +And then execute: + + $p->duration(45*60); + +The period object will adjust the end time to be 45 minutes after +the start time. It will not replace the end time with a +duration. This is required so that a CUA can take an incoming +component from a server, modify it, and send it back out in the same +basic form. + +=cut + +sub duration{ + my $self = shift; + my $d = shift; + my $dur; + + if($d){ + if(isa($d,'Net::ICal::Duration')){ + $dur = $d->clone(); + } else { + $dur = new Net::ICal::Duration($d); + } + + # If end exists, use the duration to compute a new end + # otherwise, set the duration. + if ($self->{END}){ + $self->{END} = $self->{START}->add($dur); + } else { + $self->{DURATION} = $dur; + } + } + + # Return duration, possibly computing it from END + if($self->{END}){ + return $self->{END}->subtract($self->{START}); + } else { + return $self->{DURATION}; + } + +} + +#------------------------------------------------------------------------ +=pod + +=head2 as_ical() + +Return a string that holds the RFC2445 text form of this duration + +=cut +sub as_ical { + my $self = shift; + my $out; + + $out = $self->{START}->as_ical() ."/"; + + if($self->{DURATION}){ + $out .= $self->{DURATION}->as_ical() + } else { + $out .= $self->{END}->as_ical() + } + + return $out; + +} + + +#------------------------------------------------------------------------ +=pod + +=head2 test() + +A set of developers' tests to make sure the module's working properly. + +=cut + +# Run this with a one-liner: +# perl -e "use lib('/home/srl/dev/rk/reefknot/base/'); use Net::ICal::Period; Net::ICal::Period::test();" +# adjusted for your environment. +sub test { + + print("--------- Test Net::ICal::Period --------------\n"); + + + my $p = new Net::ICal::Period("19970101T180000Z/19970102T070000Z"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/19970102T070000Z"; + + $p = new Net::ICal::Period("19970101T180000Z/PT5H30M"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/PT5H30M"; + + $p->duration("PT5H30M10S"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/PT5H30M10S" ; + + $p->duration(new Net::ICal::Duration("P10DT30M5S")); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/P10DT30M5S" ; + + $p->end("19970101T183000Z"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/PT30M" ; + + $p = new Net::ICal::Period("19970101T180000Z/19970102T070000Z"); + + $p->end("19970101T183000Z"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/19970101T183000Z" ; + + $p->duration("P1DT1H10M"); + print $p->as_ical()."\n"; + die if $p->as_ical() ne "19970101T180000Z/19970102T191000Z" ; + + + +} + +1; + + +__END__ + diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Property.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Property.pm new file mode 100644 index 0000000000..0aef347c43 --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Property.pm @@ -0,0 +1,173 @@ +#!/usr/bin/perl +# -*- Mode: perl -*- +#====================================================================== +# FILE: Property.pm +# CREATOR: eric 1 Mar 01 +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2000, Eric Busboom, eric@softwarestudio.org +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +# +#====================================================================== + +use Net::ICal::Libical::Property; + + +package Net::ICal::Libical::Property; +use strict; + + +sub new { + + my $class = shift; + my $arg = shift; + my $self = {}; + my $kind; + + if(ref($arg) == 'HASH'){ + + $self->{'ref'} = $arg->{'ref'}; + + } else { + $kind = Net::ICal::Libical::icalproperty_string_to_kind($arg); + $self->{'ref'} = Net::ICal::Libical::icalproperty_new($kind); + } + + die "Did not get icalproperty ref in Net::ICal::Libical::Property::new " if !$self->{'ref'}; + + bless $self, $class; +} + + +sub DESTROY { + my $self = shift; + + my $r = $self->{'ref'}; + + if($r && !Net::ICal::Libical::icalproperty_get_parent($r)){ + Net::ICal::Libical::icalproperty_free($self->{'ref'}); + } +} + +sub name { + my $self = shift; + my $str; + + die if !$self->{'ref'}; + + $str = Net::ICal::Libical::icalproperty_as_ical_string($self->{'ref'}); + + $str =~ /^([A-Z\-]+)\n/; + + return $1; + +} + +#Get/Set the internal reference to the libical icalproperty """ +sub prop_ref { + my $self = shift; + my $p_r = shift; + + if($p_r){ + $self->{'ref'} = $p_r; + } + + return $self->{'ref'}; + +} + + +#Get/set the RFC2445 representation of the value. Dict value 'value' +sub value { + my $self = shift; + my $v = shift; + my $kind = shift; + + my $vt; + if($v){ + + if ($kind) { + $self->{'VALUE'} = $kind; + $vt = $kind; + } + elsif ($self->{'VALUE'}) { + $vt = $self->{'VALUE'}; + } + else { + $vt = 'NO'; # Use the kind of the existing value + } + + + Net::ICal::Libical::icalproperty_set_value_from_string($self->{'ref'},$v,$vt); + + } + + return Net::ICal::Libical::icalproperty_get_value_as_string($self->{'ref'}); + +} + + +# Get a named parameter +sub get_parameter{ + my $self = shift; + my $key = shift; + + die "get_parameter: missing parameter name" if !$key; + + $key = uc($key); + my $ref = $self->{'ref'}; + + my $str = Net::ICal::Libical::icalproperty_get_parameter_as_string($ref,$key); + + if($str eq 'NULL') { + return undef; + } + + return $str + +} + + +# Set the value of the named parameter +sub set_parameter{ + my $self = shift; + my $key = shift; + my $value = shift; + + die "set_parameter: missing parameter name" if !$key; + die "set_parameter: missing parameter value" if !$value; + + $key = uc($key); + my $ref = $self->{'ref'}; + + my $str = Net::ICal::Libical::icalproperty_set_parameter_from_string($ref,$key,$value); + + + return $self->get_parameter($self); + +} + + +sub as_ical_string { + my $self = shift; + my $str = Net::ICal::Libical::icalproperty_as_ical_string($self->{'ref'}); + + $str =~ s/\r//g; + $str =~ s/\n\s?//g; + + return $str; +} + + + +1; diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm new file mode 100644 index 0000000000..76969ac60d --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm @@ -0,0 +1,468 @@ +#!/usr/bin/perl -w +# -*- Mode: perl -*- +#====================================================================== +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +# +#====================================================================== + + + +=pod + +=head1 NAME + +Net::ICal::Time -- represent a time and date + +=head1 SYNOPSIS + + $t = new Net::ICal::Time("19970101T120000Z"); + $t = new Net::ICal::Time("19970101T120000","America/Los_Angeles"); + $t = new Net::ICal::Time(time(),"America/Los_Angeles"); + + $t2 = $t->add(Net::Ical::Duration("1D")); + + $duration = $t->subtract(Net::ICal::Time("19970101T110000Z")) + + # Add 5 minutes + $t->min($t->min()+5); + + # Add 5 minutes + $t->sec($t->sec()+300); + + # Compare + if($t->compare($t2) > 0) {} + +=head1 DESCRIPTION + +I<Time> represents a time, but can also hold the time zone for the +time and indicate if the time should be treated as a date. The time +can be constructed from a variey of formats. + +=head1 METHODS + +=cut + +package Net::ICal::Libical::Time; +use Net::ICal::Libical::Duration; +use Net::ICal::Libical::Property; +use Time::Local; +use POSIX; +use Carp qw(confess cluck); +use strict; +use UNIVERSAL qw(isa); + +@Net::ICal::Libical::Time::ISA = qw(Net::ICal::Libical::Property); + +=pod + +=head2 new + +Creates a new time object given one of: + +=over 4 + +=item * ISO format string + +=item * Some other format string, maybe whatever a Date module understands + +=item * Integer representing seconds past the POSIX epoch + +=back + +The optional second argument is the timezone in Olsen place name format, +which looks like "America/Los_Angeles"; it can be used to get the standard +offset from UTC, the dates the location goes to and from Daylight Savings +Time, and the magnitude of the Daylight Savings time offset. + +=cut + +sub new{ + my $package = shift; + my $arg = shift; + + my $self; + + if (ref($arg) == 'HASH'){ + # Construct from dictionary + $self = Net::ICal::Libical::Property::new($package,$arg); + my $val=Net::ICal::Libical::icalproperty_get_value_as_string($self->{'ref'}); + $self->{'tt'} = Net::ICal::Libical::icaltime_from_string($val); + + return $self; + + } else { + + if ($#_ = 1){ + # iCalendar string + $self = Net::ICal::Libical::Property::new($package,'DTSTART'); + $self->{'tt'} = Net::ICal::Libical::icaltime_new_from_string($arg); + } else { + # Broken out time + die; + } + + $self->_update_value(); + return $self; + } + +} + + +sub _update_value { + my $self = shift; + + if(!$self->{'tt'}){ + die "Can't find reference to icaltimetype"; + } + + $self->value(Net::ICal::Libical::icaltime_as_ical_string($self->{'tt'})); + +} + +=pod + +=head2 clone() + +Create a new copy of this time. + +=cut + +# clone a Time object. +sub clone { + my $self = shift; + + bless( {%$self},ref($self)); + + $self->{'ref'} = Net::ICal::Libical::icalproperty_new_clone($self->{'ref'}); + +} + + + +=pod + +=head2 is_valid() + +TBD + +=cut + +sub is_valid{ + my $self = shift; + + return Net::ICal::Libical::icaltime_is_null_time($self->{'tt'}); + +} + + + +=pod + +=head2 is_date([true|false]) + +Accessor to the is_date flag. If true, the flag indicates that the +hour, minute and second fields are set to zero and not used in +comparisons. + +=cut + + +sub is_date { + my $self = shift; + if(@_){ + + # Convert to true or false + Net::ICal::Libical::icaltimetype_is_date_set($self->{'tt'}, + !(!($_[0]))); + } + + return Net::ICal::Libical::icaltimetype_is_date_get($self->{'tt'}); + +} + + +=pod + +=head2 is_utc([true|false]) + +Is_utc indicates if the time should be interpreted in the UTC timezone. + +=cut + +sub is_utc { + my $self = shift; + if(@_){ + + # Convert to true or false + Net::ICal::Libical::icaltimetype_is_utc_set($self->{'tt'}, + !(!($_[0]))); + } + + return Net::ICal::Libical::icaltimetype_is_utc_get($self->{'tt'}); + +} +=pod + +=head2 timezone + +Accessor to the timezone. Takes & Returns an Olsen place name +("America/Los_Angeles", etc. ) , an Abbreviation, 'UTC', or 'float' if +no zone was specified. + +=cut + +sub timezone { + my $self = shift; + my $tz = shift; + + if($tz){ + $self->set_parameter('TZID',$tz); + } + + return $self->get_parameter('TZID'); + +} + + + +=pod + +=head2 normalize() + +Adjust any out-of range values so that they are in-range. For +instance, 12:65:00 would become 13:05:00. + +=cut + +sub normalize{ + my $self = shift; + + $self->{'tt'} = Net::ICal::Libical::icaltime_normalize($self->{'tt'}); + $self->value(Net::ICal::Libical::icaltime_as_ical_string($self->{'tt'})); + +} + + +=pod + +=head2 hour([$hour]) + +Accessor to the hour. Out of range values are normalized. + +=cut + +=pod +=head2 minute([$min]) + +Accessor to the minute. Out of range values are normalized. + +=cut + +=pod +=head2 second([$dsecond]) + +Accessor to the second. Out of range values are normalized. For +instance, setting the second to -1 will decrement the minute and set +the second to 59, while setting the second to 3600 will increment the +hour. + +=cut + +=pod + +=head2 year([$year]) + +Accessor to the year. Out of range values are normalized. + +=cut + +=pod + +=head2 month([$month]) + +Accessor to the month. Out of range values are normalized. + +=cut + + +=pod + +=head2 day([$day]) + +Accessor to the month day. Out of range values are normalized. + +=cut + +sub _do_accessor { +no strict; + my $self = shift; + my $type = shift; + my $value = shift; + + $type = lc($type); + + if($value){ + my $set = "Net::ICal::Libical::icaltimetype_${type}_set"; + + &$set($self->{'tt'},$value); + $self->normalize(); + $self->_update_value(); + + } + + my $get = "Net::ICal::Libical::icaltimetype_${type}_get"; + + return &$get($self->{'tt'}); +} + + +sub second {my $s = shift; my $v = shift; return $s->_do_accessor('SECOND',$v);} +sub minute {my $s = shift; my $v = shift;return $s->_do_accessor('MINUTE',$v);} +sub hour {my $s = shift; my $v = shift; return $s->_do_accessor('HOUR',$v);} +sub day {my $s = shift; my $v = shift; return $s->_do_accessor('DAY',$v);} +sub month {my $s = shift; my $v = shift; return $s->_do_accessor('MONTH',$v);} +sub year {my $s = shift; my $v = shift; return $s->_do_accessor('YEAR',$v);} + + +=pod + +=head2 add($duration) + +Takes a I<Duration> and returns a I<Time> that is the sum of the time +and the duration. Does not modify this time. + +=cut +sub add { + my $self = shift; + my $dur = shift; + + cluck "Net::ICal::Time::add argument 1 requires a Net::ICal::Duration" if !isa($dur,'Net::ICal::Duration'); + + my $c = $self->clone(); + + $c->second($dur->as_int()); + + $c->normalize(); + + return $c; + +} + +=pod + +=head2 subtract($time) + +Subtract out a time of type I<Time> and return a I<Duration>. Does not +modify this time. + +=cut +sub subtract { + my $self = shift; + my $t = shift; + + cluck "Net::ICal::Time::subtract argrument 1 requires a Net::ICal::Time" if !isa($t,'Net::ICal::Time'); + + my $tint1 = $self->as_int(); + my $tint2 = $t->as_int(); + + return new Net::ICal::Duration($tint1 - $tint2); + +} + +=pod + +=head2 move_to_zone($zone); + +Change the time to what it would be in the named timezone. +The zone can be an Olsen placename or "UTC". + +=cut + +# XXX this needs implementing. +sub move_to_zone { + confess "Not Implemented\n"; +} + + + +=pod + +=head2 as_int() + +Convert the time to an integer that represents seconds past the POSIX +epoch + +=cut +sub as_int { + my $self = shift; + + return Net::ICal::Libical::icaltime_as_timet($self->{'tt'}); +} + +=pod + +=head2 as_localtime() + +Convert to list format, as per localtime() + +=cut +sub as_localtime { + my $self = shift; + + return localtime($self->as_int()); + +} + +=pod + +=head2 as_gmtime() + +Convert to list format, as per gmtime() + +=cut +sub as_gmtime { + my $self = shift; + + return gmtime($self->as_int()); + +} + +=pod + +=head2 compare($time) + +Compare a time to this one and return -1 if the argument is earlier +than this one, 1 if it is later, and 0 if it is the same. The routine +does the comparision after converting the time to UTC. It converts +floating times using the system notion of the timezone. + +=cut +sub compare { + my $self = shift; + my $a = $self->as_int(); + + my $arg = shift; + + if(!isa($arg,'Net::ICal::Time')){ + $arg = new Net::ICal::Time($arg); + } + + my $b = $arg->as_int(); + + if($a < $b){ + return -1; + } elsif ($a > $b) { + return 1; + } else { + return 0; + } + +} + +1; + diff --git a/libical/src/Net-ICal-Libical/netical.i b/libical/src/Net-ICal-Libical/netical.i new file mode 100644 index 0000000000..9d380dcec1 --- /dev/null +++ b/libical/src/Net-ICal-Libical/netical.i @@ -0,0 +1,317 @@ +/* -*- Mode: C -*-*/ +/*====================================================================== + FILE: ical.i + + (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 + + Contributions from: + Graham Davison (g.m.davison@computer.org) + + ======================================================================*/ + +%module Net__ICal__Libical + +%{ +#include "ical.h" + +#include <sys/types.h> /* for size_t */ +#include <time.h> + +%} + + + +typedef void icalcomponent; +typedef void icalproperty; + +icalcomponent* icalparser_parse_string(char* str); + + +icalcomponent* icalcomponent_new(icalcomponent_kind kind); +icalcomponent* icalcomponent_new_clone(icalcomponent* component); +icalcomponent* icalcomponent_new_from_string(char* str); + +char* icalcomponent_as_ical_string(icalcomponent* component); + +void icalcomponent_free(icalcomponent* component); +int icalcomponent_count_errors(icalcomponent* component); +void icalcomponent_strip_errors(icalcomponent* component); +void icalcomponent_convert_errors(icalcomponent* component); + +icalproperty* icalcomponent_get_current_property(icalcomponent* component); + +icalproperty* icalcomponent_get_first_property(icalcomponent* component, + icalproperty_kind kind); +icalproperty* icalcomponent_get_next_property(icalcomponent* component, + icalproperty_kind kind); + +icalcomponent* icalcomponent_get_current_component (icalcomponent* component); + +icalcomponent* icalcomponent_get_first_component(icalcomponent* component, + icalcomponent_kind kind); +icalcomponent* icalcomponent_get_next_component(icalcomponent* component, + icalcomponent_kind kind); + +void icalcomponent_add_property(icalcomponent* component, + icalproperty* property); + +void icalcomponent_remove_property(icalcomponent* component, + icalproperty* property); + + +icalcomponent* icalcomponent_get_parent(icalcomponent* component); + +icalcomponent_kind icalcomponent_isa(icalcomponent* component); + +int icalrestriction_check(icalcomponent* comp); + + +/* actually returns icalproperty_kind */ +int icalproperty_string_to_kind(const char* string); + +/* actually takes icalproperty_kind */ +icalproperty* icalproperty_new(int kind); + +icalproperty* icalproperty_new_from_string(char* str); + +char* icalproperty_as_ical_string(icalproperty *prop); + +void icalproperty_set_parameter_from_string(icalproperty* prop, + const char* name, const char* value); +void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char * kind); + +const char* icalproperty_get_value_as_string(icalproperty* prop); +const char* icalproperty_get_parameter_as_string(icalproperty* prop, + const char* name); + + +icalcomponent* icalproperty_get_parent(icalproperty* property); + +typedef enum icalerrorenum { + + ICAL_BADARG_ERROR, + ICAL_NEWFAILED_ERROR, + ICAL_MALFORMEDDATA_ERROR, + ICAL_PARSE_ERROR, + ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */ + ICAL_FILE_ERROR, + ICAL_ALLOCATION_ERROR, + ICAL_USAGE_ERROR, + ICAL_NO_ERROR, + ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror()*/ + +} icalerrorenum; + +/* Make an individual error fatal or non-fatal. */ +typedef enum icalererorstate { + ICAL_ERROR_FATAL, /* Not fata */ + ICAL_ERROR_NONFATAL, /* Fatal */ + ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/ + ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */ +} icalerrorstate ; + +void icalerror_set_error_state( icalerrorenum error, icalerrorstate); +icalerrorstate icalerror_get_error_state( icalerrorenum error); + + +const char* icalenum_property_kind_to_string(icalproperty_kind kind); +icalproperty_kind icalenum_string_to_property_kind(const char* string); + +const char* icalenum_value_kind_to_string(icalvalue_kind kind); +/*icalvalue_kind icalenum_value_kind_by_prop(icalproperty_kind kind);*/ + +const char* icalenum_parameter_kind_to_string(icalparameter_kind kind); +icalparameter_kind icalenum_string_to_parameter_kind(const char* string); + +const char* icalenum_component_kind_to_string(icalcomponent_kind kind); +icalcomponent_kind icalenum_string_to_component_kind(const char* string); + +icalvalue_kind icalenum_property_kind_to_value_kind(icalproperty_kind kind); + + +int* icallangbind_new_array(int size); +void icallangbind_free_array(int* array); +int icallangbind_access_array(int* array, int index); +int icalrecur_expand_recurrence(char* rule, int start, + int count, int* array); + + +/* Iterate through properties and components using strings for the kind */ +icalproperty* icallangbind_get_first_property(icalcomponent *c, + const char* prop); + +icalproperty* icallangbind_get_next_property(icalcomponent *c, + const char* prop); + +icalcomponent* icallangbind_get_first_component(icalcomponent *c, + const char* comp); + +icalcomponent* icallangbind_get_next_component(icalcomponent *c, + const char* comp); + + +/* Return a string that can be evaluated in perl or python to + generated a hash that holds the property's name, value and + parameters. Sep is the hash seperation string, "=>" for perl and + ":" for python */ +const char* icallangbind_property_eval_string(icalproperty* prop, char* sep); + +/*********************************************************************** + Time routines +***********************************************************************/ + + +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. */ + + const char* zone; /*Ptr to Olsen placename. Libical does not own mem*/ +}; + + +/* Convert seconds past UNIX epoch to a timetype*/ +struct icaltimetype icaltime_from_timet(int v, int is_date); + +/* Return the time as seconds past the UNIX epoch */ +/* Normally, this returns a time_t, but SWIG tries to turn that type + into a pointer */ +int icaltime_as_timet(struct icaltimetype); + +/* Return a string represention of the time, in RFC2445 format. The + string is owned by libical */ +char* icaltime_as_ical_string(struct icaltimetype tt); + +/* create a time from an ISO format string */ +struct icaltimetype icaltime_from_string(const char* str); + +/* Routines for handling timezones */ +/* Return the offset of the named zone as seconds. tt is a time + indicating the date for which you want the offset */ +int icaltime_utc_offset(struct icaltimetype tt, const char* tzid); + +/* convert tt, of timezone tzid, into a utc time. Does nothing if the + time is already UTC. */ +struct icaltimetype icaltime_as_utc(struct icaltimetype tt, + const char* tzid); + +/* convert tt, a time in UTC, into a time in timezone tzid */ +struct icaltimetype icaltime_as_zone(struct icaltimetype tt, + const char* tzid); + +/* Return a null time, which indicates no time has been set. This time represent the beginning of the epoch */ +struct icaltimetype icaltime_null_time(void); + +/* Return true of the time is null. */ +int icaltime_is_null_time(struct icaltimetype t); + +/* Returns false if the time is clearly invalid, but is not null. This + is usually the result of creating a new time type buy not clearing + it, or setting one of the flags to an illegal value. */ +int icaltime_is_valid_time(struct icaltimetype t); + +/* Reset all of the time components to be in their normal ranges. For + instance, given a time with minutes=70, the minutes will be reduces + to 10, and the hour incremented. This allows the caller to do + arithmetic on times without worrying about overflow or + underflow. */ +struct icaltimetype icaltime_normalize(struct icaltimetype t); + +/* Return the day of the year of the given time */ +short icaltime_day_of_year(struct icaltimetype t); + +/* Create a new time, given a day of year and a year. */ +struct icaltimetype icaltime_from_day_of_year(short doy, short year); + +/* Return the day of the week of the given time. Sunday is 0 */ +short icaltime_day_of_week(struct icaltimetype t); + +/* Return the day of the year for the Sunday of the week that the + given time is within. */ +short icaltime_start_doy_of_week(struct icaltimetype t); + +/* Return a string with the time represented in the same format as ctime(). THe string is owned by libical */ +char* icaltime_as_ctime(struct icaltimetype); + +/* Return the week number for the week the given time is within */ +short icaltime_week_number(struct icaltimetype t); + +/* Return -1, 0, or 1 to indicate that a<b, a==b or a>b */ +int icaltime_compare(struct icaltimetype a,struct icaltimetype b); + +/* like icaltime_compare, but only use the date parts. */ +int icaltime_compare_date_only(struct icaltimetype a, struct icaltimetype b); + +/* Return the number of days in the given month */ +short icaltime_days_in_month(short month,short year); + + +/*********************************************************************** + Duration Routines +***********************************************************************/ + + +struct icaldurationtype +{ + int is_neg; + unsigned int days; + unsigned int weeks; + unsigned int hours; + unsigned int minutes; + unsigned int seconds; +}; + +struct icaldurationtype icaldurationtype_from_int(int t); +struct icaldurationtype icaldurationtype_from_string(const char*); +int icaldurationtype_as_int(struct icaldurationtype duration); +char* icaldurationtype_as_ical_string(struct icaldurationtype d); +struct icaldurationtype icaldurationtype_null_duration(); +int icaldurationtype_is_null_duration(struct icaldurationtype d); + +struct icaltimetype icaltime_add(struct icaltimetype t, + struct icaldurationtype d); + +struct icaldurationtype icaltime_subtract(struct icaltimetype t1, + struct icaltimetype t2); + + +/*********************************************************************** + Period Routines +***********************************************************************/ + + +struct icalperiodtype +{ + struct icaltimetype start; + struct icaltimetype end; + struct icaldurationtype duration; +}; + +struct icalperiodtype icalperiodtype_from_string (const char* str); + +const char* icalperiodtype_as_ical_string(struct icalperiodtype p); +struct icalperiodtype icalperiodtype_null_period(); +int icalperiodtype_is_null_period(struct icalperiodtype p); +int icalperiodtype_is_valid_period(struct icalperiodtype p); + diff --git a/libical/src/Net-ICal-Libical/netical_wrap.c b/libical/src/Net-ICal-Libical/netical_wrap.c new file mode 100644 index 0000000000..233c2dc7f7 --- /dev/null +++ b/libical/src/Net-ICal-Libical/netical_wrap.c @@ -0,0 +1,3048 @@ +/* + * FILE : netical_wrap.c + * + * This file was automatically generated by : + * Simplified Wrapper and Interface Generator (SWIG) + * Version 1.1 (Patch 5) + * + * Portions Copyright (c) 1995-1998 + * The University of Utah and The Regents of the University of California. + * Permission is granted to distribute this file in any manner provided + * this notice remains intact. + * + * Do not make changes to this file--changes will be lost! + * + */ + + +#define SWIGCODE +/* Implementation : PERL 5 */ + +#define SWIGPERL +#define SWIGPERL5 +#ifdef __cplusplus +#include <math.h> +#include <stdlib.h> +extern "C" { +#endif +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +#undef free +#undef malloc +#include <string.h> +#ifdef __cplusplus +} +#endif +/* Definitions for compiling Perl extensions on a variety of machines */ + +#if defined(WIN32) || defined(__WIN32__) +# if defined(_MSC_VER) +# define SWIGEXPORT(a,b) __declspec(dllexport) a b +# else +# if defined(__BORLANDC__) +# define SWIGEXPORT(a,b) a _export b +# else +# define SWIGEXPORT(a,b) a b +# endif +# endif +#else +# define SWIGEXPORT(a,b) a b +#endif + +#ifdef PERL_OBJECT +#define MAGIC_PPERL CPerl *pPerl = (CPerl *) this; +#define MAGIC_CAST (int (CPerl::*)(SV *, MAGIC *)) +#define SWIGCLASS_STATIC +#else +#define MAGIC_PPERL +#define MAGIC_CAST +#define SWIGCLASS_STATIC static +#endif + + +/***************************************************************************** + * $Header$ + * + * perl5ptr.swg + * + * This file contains supporting code for the SWIG run-time type checking + * mechanism. The following functions are available : + * + * SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)); + * + * Registers a new type-mapping with the type-checker. origtype is the + * original datatype and newtype is an equivalent type. cast is optional + * pointer to a function to cast pointer values between types (this + * is only used to cast pointers from derived classes to base classes in C++) + * + * SWIG_MakePtr(char *buffer, void *ptr, char *typestring); + * + * Makes a pointer string from a pointer and typestring. The result is returned + * in buffer. + * + * char * SWIG_GetPtr(SV *obj, void **ptr, char *type) + * + * Gets a pointer value from a Perl5 scalar value. If there is a + * type-mismatch, returns a character string to the received type. + * On success, returns NULL. + * + * + * You can remap these functions by making a file called "swigptr.swg" in + * your the same directory as the interface file you are wrapping. + * + * These functions are normally declared static, but this file can be + * can be used in a multi-module environment by redefining the symbol + * SWIGSTATIC. + * + * $Log$ + * Revision 1.1 2003/09/11 22:04:08 hansp + * Import new libical from mainline HEAD and make appropriate changes to + * Evolution. + * + * Revision 1.6 2001/04/02 18:17:40 ebusboom + * Get perl extension compiling again. + * + * Revision 1.1 1996/12/26 22:17:29 beazley + * Initial revision + * + *****************************************************************************/ + +#include <stdlib.h> + +#ifdef SWIG_GLOBAL +#ifdef __cplusplus +#define SWIGSTATIC extern "C" +#else +#define SWIGSTATIC +#endif +#endif + +#ifndef SWIGSTATIC +#define SWIGSTATIC static +#endif + +/* These are internal variables. Should be static */ + +typedef struct SwigPtrType { + char *name; + int len; + void *(*cast)(void *); + struct SwigPtrType *next; +} SwigPtrType; + +/* Pointer cache structure */ + +typedef struct { + int stat; /* Status (valid) bit */ + SwigPtrType *tp; /* Pointer to type structure */ + char name[256]; /* Given datatype name */ + char mapped[256]; /* Equivalent name */ +} SwigCacheType; + +static int SwigPtrMax = 64; /* Max entries that can be currently held */ +static int SwigPtrN = 0; /* Current number of entries */ +static int SwigPtrSort = 0; /* Status flag indicating sort */ +static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */ +static int SwigStart[256]; /* Table containing starting positions */ + +/* Cached values */ + +#define SWIG_CACHESIZE 8 +#define SWIG_CACHEMASK 0x7 +static SwigCacheType SwigCache[SWIG_CACHESIZE]; +static int SwigCacheIndex = 0; +static int SwigLastCache = 0; + +/* Sort comparison function */ +static int swigsort(const void *data1, const void *data2) { + SwigPtrType *d1 = (SwigPtrType *) data1; + SwigPtrType *d2 = (SwigPtrType *) data2; + return strcmp(d1->name,d2->name); +} + +/* Binary Search function */ +static int swigcmp(const void *key, const void *data) { + char *k = (char *) key; + SwigPtrType *d = (SwigPtrType *) data; + return strncmp(k,d->name,d->len); +} + +/* Register a new datatype with the type-checker */ + +#ifndef PERL_OBJECT +SWIGSTATIC +void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) { +#else +SWIGSTATIC +#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c) +void _SWIG_RegisterMapping(CPerl *pPerl, char *origtype, char *newtype, void *(*cast)(void *)) { +#endif + + int i; + SwigPtrType *t = 0, *t1; + + if (!SwigPtrTable) { + SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType)); + SwigPtrN = 0; + } + if (SwigPtrN >= SwigPtrMax) { + SwigPtrMax = 2*SwigPtrMax; + SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType)); + } + for (i = 0; i < SwigPtrN; i++) + if (strcmp(SwigPtrTable[i].name,origtype) == 0) { + t = &SwigPtrTable[i]; + break; + } + if (!t) { + t = &SwigPtrTable[SwigPtrN]; + t->name = origtype; + t->len = strlen(t->name); + t->cast = 0; + t->next = 0; + SwigPtrN++; + } + while (t->next) { + if (strcmp(t->name,newtype) == 0) { + if (cast) t->cast = cast; + return; + } + t = t->next; + } + t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType)); + t1->name = newtype; + t1->len = strlen(t1->name); + t1->cast = cast; + t1->next = 0; + t->next = t1; + SwigPtrSort = 0; +} + +/* Make a pointer value string */ + +SWIGSTATIC +void SWIG_MakePtr(char *_c, const void *_ptr, char *type) { + static char _hex[16] = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + unsigned long _p, _s; + char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */ + _r = _result; + _p = (unsigned long) _ptr; + if (_p > 0) { + while (_p > 0) { + _s = _p & 0xf; + *(_r++) = _hex[_s]; + _p = _p >> 4; + } + *_r = '_'; + while (_r >= _result) + *(_c++) = *(_r--); + } else { + strcpy (_c, "NULL"); + } + if (_ptr) + strcpy (_c, type); +} + +/* Define for backwards compatibility */ + +#define _swig_make_hex SWIG_MakePtr + +/* Function for getting a pointer value */ + +#ifndef PERL_OBJECT +SWIGSTATIC +char *SWIG_GetPtr(SV *sv, void **ptr, char *_t) +#else +SWIGSTATIC +#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c) +char *_SWIG_GetPtr(CPerl *pPerl, SV *sv, void **ptr, char *_t) +#endif +{ + char temp_type[256]; + char *name,*_c; + int len,i,start,end; + IV tmp; + SwigPtrType *sp,*tp; + SwigCacheType *cache; + + /* If magical, apply more magic */ + + if (SvGMAGICAL(sv)) + mg_get(sv); + + /* Check to see if this is an object */ + if (sv_isobject(sv)) { + SV *tsv = (SV*) SvRV(sv); + if ((SvTYPE(tsv) == SVt_PVHV)) { + MAGIC *mg; + if (SvMAGICAL(tsv)) { + mg = mg_find(tsv,'P'); + if (mg) { + SV *rsv = mg->mg_obj; + if (sv_isobject(rsv)) { + tmp = SvIV((SV*)SvRV(rsv)); + } + } + } else { + return "Not a valid pointer value"; + } + } else { + tmp = SvIV((SV*)SvRV(sv)); + } + if (!_t) { + *(ptr) = (void *) tmp; + return (char *) 0; + } + } else if (sv == &sv_undef) { /* Check for undef */ + *(ptr) = (void *) 0; + return (char *) 0; + } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ + *(ptr) = (void *) 0; + if (!SvROK(sv)) + return (char *) 0; + else + return "Not a valid pointer value"; + } else { /* Don't know what it is */ + *(ptr) = (void *) 0; + return "Not a valid pointer value"; + } + if (_t) { + /* Now see if the types match */ + + if (!sv_isa(sv,_t)) { + _c = HvNAME(SvSTASH(SvRV(sv))); + if (!SwigPtrSort) { + qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort); + for (i = 0; i < 256; i++) { + SwigStart[i] = SwigPtrN; + } + for (i = SwigPtrN-1; i >= 0; i--) { + SwigStart[SwigPtrTable[i].name[0]] = i; + } + for (i = 255; i >= 1; i--) { + if (SwigStart[i-1] > SwigStart[i]) + SwigStart[i-1] = SwigStart[i]; + } + SwigPtrSort = 1; + for (i = 0; i < SWIG_CACHESIZE; i++) + SwigCache[i].stat = 0; + } + /* First check cache for matches. Uses last cache value as starting point */ + cache = &SwigCache[SwigLastCache]; + for (i = 0; i < SWIG_CACHESIZE; i++) { + if (cache->stat) { + if (strcmp(_t,cache->name) == 0) { + if (strcmp(_c,cache->mapped) == 0) { + cache->stat++; + *ptr = (void *) tmp; + if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr); + return (char *) 0; + } + } + } + SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK; + if (!SwigLastCache) cache = SwigCache; + else cache++; + } + + start = SwigStart[_t[0]]; + end = SwigStart[_t[0]+1]; + sp = &SwigPtrTable[start]; + while (start < end) { + if (swigcmp(_t,sp) == 0) break; + sp++; + start++; + } + if (start >= end) sp = 0; + if (sp) { + while (swigcmp(_t,sp) == 0) { + name = sp->name; + len = sp->len; + tp = sp->next; + while(tp) { + if (tp->len >= 255) { + return _c; + } + strcpy(temp_type,tp->name); + strncat(temp_type,_t+len,255-tp->len); + if (sv_isa(sv,temp_type)) { + /* Get pointer value */ + *ptr = (void *) tmp; + if (tp->cast) *ptr = (*(tp->cast))(*ptr); + + strcpy(SwigCache[SwigCacheIndex].mapped,_c); + strcpy(SwigCache[SwigCacheIndex].name,_t); + SwigCache[SwigCacheIndex].stat = 1; + SwigCache[SwigCacheIndex].tp = tp; + SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK; + return (char *) 0; + } + tp = tp->next; + } + /* Hmmm. Didn't find it this time */ + sp++; + } + } + /* Didn't find any sort of match for this data. + Get the pointer value and return the received type */ + *ptr = (void *) tmp; + return _c; + } else { + /* Found a match on the first try. Return pointer value */ + *ptr = (void *) tmp; + return (char *) 0; + } + } + *ptr = (void *) tmp; + return (char *) 0; +} + +/* Compatibility mode */ + +#define _swig_get_hex SWIG_GetPtr +/* Magic variable code */ +#ifndef PERL_OBJECT +#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c) +static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) { +#else +#define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c) +static void _swig_create_magic(CPerl *pPerl, SV *sv, char *name, int (CPerl::*set)(SV *, MAGIC *), int (CPerl::*get)(SV *, MAGIC *)) { +#endif + MAGIC *mg; + sv_magic(sv,sv,'U',name,strlen(name)); + mg = mg_find(sv,'U'); + mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL)); + mg->mg_virtual->svt_get = get; + mg->mg_virtual->svt_set = set; + mg->mg_virtual->svt_len = 0; + mg->mg_virtual->svt_clear = 0; + mg->mg_virtual->svt_free = 0; +} + +#define SWIG_init boot_Net__ICal__Libical + +#define SWIG_name "Net::ICal::Libical::boot_Net__ICal__Libical" +#define SWIG_varinit "Net::ICal::Libical::var_Net__ICal__Libical_init();" +#ifdef __cplusplus +extern "C" +#endif +#ifndef PERL_OBJECT +SWIGEXPORT(void,boot_Net__ICal__Libical)(CV* cv); +#else +SWIGEXPORT(void,boot_Net__ICal__Libical)(CPerl *, CV *cv); +#endif + +#include "ical.h" + +#include <sys/types.h> /* for size_t */ +#include <time.h> + +#ifndef PERL_OBJECT +#define swig_setiv(a,b) _swig_setiv(a,b) +static void _swig_setiv(char *name, long value) { +#else +#define swig_setiv(a,b) _swig_setiv(pPerl,a,b) +static void _swig_setiv(CPerl *pPerl, char *name, long value) { +#endif + SV *sv; + sv = perl_get_sv(name,TRUE | 0x2); + sv_setiv(sv, (IV) value); + SvREADONLY_on(sv); +} + +#ifndef PERL_OBJECT +#define swig_setpv(a,b) _swig_setpv(a,b) +static void _swig_setpv(char *name, char *value) { +#else +#define swig_setpv(a,b) _swig_setpv(pPerl,a,b) +static void _swig_setpv(CPerl *pPerl, char *name, char *value) { +#endif + SV *sv; + sv = perl_get_sv(name,TRUE | 0x2); + sv_setpv(sv, value); + SvREADONLY_on(sv); +} + +#ifdef PERL_OBJECT +#define MAGIC_CLASS _wrap_Net__ICal__Libical_var:: +class _wrap_Net__ICal__Libical_var : public CPerl { +public: +#else +#define MAGIC_CLASS +#endif +SWIGCLASS_STATIC int swig_magic_readonly(SV *sv, MAGIC *mg) { + MAGIC_PPERL + sv = sv; mg = mg; + croak("Value is read-only."); + return 0; +} + + +#ifdef PERL_OBJECT +}; +#endif + +XS(_wrap_icalparser_parse_string) { + + icalcomponent * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalparser_parse_string(str);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalcomponent *)icalparser_parse_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_new) { + + icalcomponent * _result; + icalcomponent_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_new(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalcomponent_kindPtr")) { + croak("Type error in argument 1 of icalcomponent_new. Expected icalcomponent_kindPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_new(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_new_clone) { + + icalcomponent * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_new_clone(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_new_clone. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_new_clone(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_new_from_string) { + + icalcomponent * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_new_from_string(str);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalcomponent *)icalcomponent_new_from_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_as_ical_string) { + + char * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_as_ical_string(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_as_ical_string. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (char *)icalcomponent_as_ical_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_free) { + + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_free(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_free. Expected icalcomponentPtr."); + XSRETURN(1); + } + icalcomponent_free(_arg0); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_count_errors) { + + int _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_count_errors(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_count_errors. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (int )icalcomponent_count_errors(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_strip_errors) { + + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_strip_errors(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_strip_errors. Expected icalcomponentPtr."); + XSRETURN(1); + } + icalcomponent_strip_errors(_arg0); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_convert_errors) { + + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_convert_errors(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_convert_errors. Expected icalcomponentPtr."); + XSRETURN(1); + } + icalcomponent_convert_errors(_arg0); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_current_property) { + + icalproperty * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_get_current_property(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_current_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (icalproperty *)icalcomponent_get_current_property(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_first_property) { + + icalproperty * _result; + icalcomponent * _arg0; + icalproperty_kind * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_get_first_property(component,kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_first_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"icalproperty_kindPtr")) { + croak("Type error in argument 2 of icalcomponent_get_first_property. Expected icalproperty_kindPtr."); + XSRETURN(1); + } + _result = (icalproperty *)icalcomponent_get_first_property(_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_next_property) { + + icalproperty * _result; + icalcomponent * _arg0; + icalproperty_kind * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_get_next_property(component,kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_next_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"icalproperty_kindPtr")) { + croak("Type error in argument 2 of icalcomponent_get_next_property. Expected icalproperty_kindPtr."); + XSRETURN(1); + } + _result = (icalproperty *)icalcomponent_get_next_property(_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_current_component) { + + icalcomponent * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_get_current_component(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_current_component. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_get_current_component(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_first_component) { + + icalcomponent * _result; + icalcomponent * _arg0; + icalcomponent_kind * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_get_first_component(component,kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_first_component. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"icalcomponent_kindPtr")) { + croak("Type error in argument 2 of icalcomponent_get_first_component. Expected icalcomponent_kindPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_get_first_component(_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_next_component) { + + icalcomponent * _result; + icalcomponent * _arg0; + icalcomponent_kind * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_get_next_component(component,kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_next_component. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"icalcomponent_kindPtr")) { + croak("Type error in argument 2 of icalcomponent_get_next_component. Expected icalcomponent_kindPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_get_next_component(_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_add_property) { + + icalcomponent * _arg0; + icalproperty * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_add_property(component,property);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_add_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,(char *) 0 )) { + croak("Type error in argument 2 of icalcomponent_add_property. Expected icalpropertyPtr."); + XSRETURN(1); + } + icalcomponent_add_property(_arg0,_arg1); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_remove_property) { + + icalcomponent * _arg0; + icalproperty * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalcomponent_remove_property(component,property);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_remove_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,(char *) 0 )) { + croak("Type error in argument 2 of icalcomponent_remove_property. Expected icalpropertyPtr."); + XSRETURN(1); + } + icalcomponent_remove_property(_arg0,_arg1); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_get_parent) { + + icalcomponent * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_get_parent(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_get_parent. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalcomponent_get_parent(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalcomponent_isa) { + + icalcomponent_kind * _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalcomponent_isa(component);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalcomponent_isa. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (icalcomponent_kind *) malloc(sizeof(icalcomponent_kind )); + *(_result) = icalcomponent_isa(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponent_kindPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalrestriction_check) { + + int _result; + icalcomponent * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalrestriction_check(comp);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalrestriction_check. Expected icalcomponentPtr."); + XSRETURN(1); + } + _result = (int )icalrestriction_check(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_string_to_kind) { + + int _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_string_to_kind(string);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (int )icalproperty_string_to_kind(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_new) { + + icalproperty * _result; + int _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_new(kind);"); + _arg0 = (int )SvIV(ST(0)); + _result = (icalproperty *)icalproperty_new(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_new_from_string) { + + icalproperty * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_new_from_string(str);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalproperty *)icalproperty_new_from_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_as_ical_string) { + + char * _result; + icalproperty * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_as_ical_string(prop);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_as_ical_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _result = (char *)icalproperty_as_ical_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_set_parameter_from_string) { + + icalproperty * _arg0; + char * _arg1; + char * _arg2; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 3) || (items > 3)) + croak("Usage: icalproperty_set_parameter_from_string(prop,name,value);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_set_parameter_from_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _arg2 = (char *) SvPV(ST(2),na); + icalproperty_set_parameter_from_string(_arg0,_arg1,_arg2); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_set_value_from_string) { + + icalproperty * _arg0; + char * _arg1; + char * _arg2; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 3) || (items > 3)) + croak("Usage: icalproperty_set_value_from_string(prop,value,kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_set_value_from_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _arg2 = (char *) SvPV(ST(2),na); + icalproperty_set_value_from_string(_arg0,_arg1,_arg2); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_get_value_as_string) { + + char * _result; + icalproperty * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_get_value_as_string(prop);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_get_value_as_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _result = (char *)icalproperty_get_value_as_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_get_parameter_as_string) { + + char * _result; + icalproperty * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalproperty_get_parameter_as_string(prop,name);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_get_parameter_as_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (char *)icalproperty_get_parameter_as_string(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalproperty_get_parent) { + + icalcomponent * _result; + icalproperty * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalproperty_get_parent(property);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icalproperty_get_parent. Expected icalpropertyPtr."); + XSRETURN(1); + } + _result = (icalcomponent *)icalproperty_get_parent(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalerror_set_error_state) { + + icalerrorenum _arg0; + icalerrorstate _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalerror_set_error_state(error,icalerrorstate );"); + _arg0 = (icalerrorenum )SvIV(ST(0)); + _arg1 = (icalerrorstate )SvIV(ST(1)); + icalerror_set_error_state(_arg0,_arg1); + XSRETURN(argvi); +} + +XS(_wrap_icalerror_get_error_state) { + + icalerrorstate _result; + icalerrorenum _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalerror_get_error_state(error);"); + _arg0 = (icalerrorenum )SvIV(ST(0)); + _result = (icalerrorstate )icalerror_get_error_state(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_property_kind_to_string) { + + char * _result; + icalproperty_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_property_kind_to_string(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalproperty_kindPtr")) { + croak("Type error in argument 1 of icalenum_property_kind_to_string. Expected icalproperty_kindPtr."); + XSRETURN(1); + } + _result = (char *)icalenum_property_kind_to_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_string_to_property_kind) { + + icalproperty_kind * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_string_to_property_kind(string);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalproperty_kind *) malloc(sizeof(icalproperty_kind )); + *(_result) = icalenum_string_to_property_kind(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalproperty_kindPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_value_kind_to_string) { + + char * _result; + icalvalue_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_value_kind_to_string(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalvalue_kindPtr")) { + croak("Type error in argument 1 of icalenum_value_kind_to_string. Expected icalvalue_kindPtr."); + XSRETURN(1); + } + _result = (char *)icalenum_value_kind_to_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_parameter_kind_to_string) { + + char * _result; + icalparameter_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_parameter_kind_to_string(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalparameter_kindPtr")) { + croak("Type error in argument 1 of icalenum_parameter_kind_to_string. Expected icalparameter_kindPtr."); + XSRETURN(1); + } + _result = (char *)icalenum_parameter_kind_to_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_string_to_parameter_kind) { + + icalparameter_kind * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_string_to_parameter_kind(string);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalparameter_kind *) malloc(sizeof(icalparameter_kind )); + *(_result) = icalenum_string_to_parameter_kind(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalparameter_kindPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_component_kind_to_string) { + + char * _result; + icalcomponent_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_component_kind_to_string(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalcomponent_kindPtr")) { + croak("Type error in argument 1 of icalenum_component_kind_to_string. Expected icalcomponent_kindPtr."); + XSRETURN(1); + } + _result = (char *)icalenum_component_kind_to_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_string_to_component_kind) { + + icalcomponent_kind * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_string_to_component_kind(string);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (icalcomponent_kind *) malloc(sizeof(icalcomponent_kind )); + *(_result) = icalenum_string_to_component_kind(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponent_kindPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalenum_property_kind_to_value_kind) { + + icalvalue_kind * _result; + icalproperty_kind * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalenum_property_kind_to_value_kind(kind);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"icalproperty_kindPtr")) { + croak("Type error in argument 1 of icalenum_property_kind_to_value_kind. Expected icalproperty_kindPtr."); + XSRETURN(1); + } + _result = (icalvalue_kind *) malloc(sizeof(icalvalue_kind )); + *(_result) = icalenum_property_kind_to_value_kind(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalvalue_kindPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_new_array) { + + int * _result; + int _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icallangbind_new_array(size);"); + _arg0 = (int )SvIV(ST(0)); + _result = (int *)icallangbind_new_array(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"intPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_free_array) { + + int * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icallangbind_free_array(array);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"intPtr")) { + croak("Type error in argument 1 of icallangbind_free_array. Expected intPtr."); + XSRETURN(1); + } + icallangbind_free_array(_arg0); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_access_array) { + + int _result; + int * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_access_array(array,index);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"intPtr")) { + croak("Type error in argument 1 of icallangbind_access_array. Expected intPtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icallangbind_access_array(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalrecur_expand_recurrence) { + + int _result; + char * _arg0; + int _arg1; + int _arg2; + int * _arg3; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 4) || (items > 4)) + croak("Usage: icalrecur_expand_recurrence(rule,start,count,array);"); + _arg0 = (char *) SvPV(ST(0),na); + _arg1 = (int )SvIV(ST(1)); + _arg2 = (int )SvIV(ST(2)); + if (SWIG_GetPtr(ST(3),(void **) &_arg3,"intPtr")) { + croak("Type error in argument 4 of icalrecur_expand_recurrence. Expected intPtr."); + XSRETURN(1); + } + _result = (int )icalrecur_expand_recurrence(_arg0,_arg1,_arg2,_arg3); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_get_first_property) { + + icalproperty * _result; + icalcomponent * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_get_first_property(c,prop);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icallangbind_get_first_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (icalproperty *)icallangbind_get_first_property(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_get_next_property) { + + icalproperty * _result; + icalcomponent * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_get_next_property(c,prop);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icallangbind_get_next_property. Expected icalcomponentPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (icalproperty *)icallangbind_get_next_property(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalpropertyPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_get_first_component) { + + icalcomponent * _result; + icalcomponent * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_get_first_component(c,comp);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icallangbind_get_first_component. Expected icalcomponentPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (icalcomponent *)icallangbind_get_first_component(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_get_next_component) { + + icalcomponent * _result; + icalcomponent * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_get_next_component(c,comp);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icallangbind_get_next_component. Expected icalcomponentPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (icalcomponent *)icallangbind_get_next_component(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icallangbind_property_eval_string) { + + char * _result; + icalproperty * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icallangbind_property_eval_string(prop,sep);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { + croak("Type error in argument 1 of icallangbind_property_eval_string. Expected icalpropertyPtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (char *)icallangbind_property_eval_string(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_from_timet) { + + struct icaltimetype * _result; + int _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_from_timet(v,is_date);"); + _arg0 = (int )SvIV(ST(0)); + _arg1 = (int )SvIV(ST(1)); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_from_timet(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_as_timet) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_as_timet(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_as_timet. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltime_as_timet(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_as_ical_string) { + + char * _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_as_ical_string(tt);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_as_ical_string. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (char *)icaltime_as_ical_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_from_string) { + + struct icaltimetype * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_from_string(str);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_from_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_utc_offset) { + + int _result; + struct icaltimetype * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_utc_offset(tt,tzid);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_utc_offset. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (int )icaltime_utc_offset(*_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_as_utc) { + + struct icaltimetype * _result; + struct icaltimetype * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_as_utc(tt,tzid);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_as_utc. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_as_utc(*_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_as_zone) { + + struct icaltimetype * _result; + struct icaltimetype * _arg0; + char * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_as_zone(tt,tzid);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_as_zone. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (char *) SvPV(ST(1),na); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_as_zone(*_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_null_time) { + + struct icaltimetype * _result; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 0) || (items > 0)) + croak("Usage: icaltime_null_time();"); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_null_time(); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_is_null_time) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_is_null_time(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_is_null_time. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltime_is_null_time(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_is_valid_time) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_is_valid_time(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_is_valid_time. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltime_is_valid_time(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_normalize) { + + struct icaltimetype * _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_normalize(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_normalize. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_normalize(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_day_of_year) { + + short _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_day_of_year(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_day_of_year. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (short )icaltime_day_of_year(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_from_day_of_year) { + + struct icaltimetype * _result; + short _arg0; + short _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_from_day_of_year(doy,year);"); + _arg0 = (short )SvIV(ST(0)); + _arg1 = (short )SvIV(ST(1)); + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_from_day_of_year(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_day_of_week) { + + short _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_day_of_week(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_day_of_week. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (short )icaltime_day_of_week(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_start_doy_of_week) { + + short _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_start_doy_of_week(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_start_doy_of_week. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (short )icaltime_start_doy_of_week(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_as_ctime) { + + char * _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_as_ctime(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_as_ctime. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (char *)icaltime_as_ctime(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_week_number) { + + short _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltime_week_number(t);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_week_number. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (short )icaltime_week_number(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_compare) { + + int _result; + struct icaltimetype * _arg0; + struct icaltimetype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_compare(a,b);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_compare. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaltimetypePtr")) { + croak("Type error in argument 2 of icaltime_compare. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltime_compare(*_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_compare_date_only) { + + int _result; + struct icaltimetype * _arg0; + struct icaltimetype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_compare_date_only(a,b);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_compare_date_only. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaltimetypePtr")) { + croak("Type error in argument 2 of icaltime_compare_date_only. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltime_compare_date_only(*_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_days_in_month) { + + short _result; + short _arg0; + short _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_days_in_month(month,year);"); + _arg0 = (short )SvIV(ST(0)); + _arg1 = (short )SvIV(ST(1)); + _result = (short )icaltime_days_in_month(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_from_int) { + + struct icaldurationtype * _result; + int _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_from_int(t);"); + _arg0 = (int )SvIV(ST(0)); + _result = (struct icaldurationtype *) malloc(sizeof(struct icaldurationtype )); + *(_result) = icaldurationtype_from_int(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_from_string) { + + struct icaldurationtype * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_from_string(char *);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (struct icaldurationtype *) malloc(sizeof(struct icaldurationtype )); + *(_result) = icaldurationtype_from_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_as_int) { + + int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_as_int(duration);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_as_int. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (int )icaldurationtype_as_int(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_as_ical_string) { + + char * _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_as_ical_string(d);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_as_ical_string. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (char *)icaldurationtype_as_ical_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_null_duration) { + + struct icaldurationtype * _result; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 0) || (items > 0)) + croak("Usage: icaldurationtype_null_duration();"); + _result = (struct icaldurationtype *) malloc(sizeof(struct icaldurationtype )); + *(_result) = icaldurationtype_null_duration(); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaldurationtype_is_null_duration) { + + int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_is_null_duration(d);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_is_null_duration. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (int )icaldurationtype_is_null_duration(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_add) { + + struct icaltimetype * _result; + struct icaltimetype * _arg0; + struct icaldurationtype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_add(t,d);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_add. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaldurationtypePtr")) { + croak("Type error in argument 2 of icaltime_add. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *) malloc(sizeof(struct icaltimetype )); + *(_result) = icaltime_add(*_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icaltime_subtract) { + + struct icaldurationtype * _result; + struct icaltimetype * _arg0; + struct icaltimetype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltime_subtract(t1,t2);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltime_subtract. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaltimetypePtr")) { + croak("Type error in argument 2 of icaltime_subtract. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (struct icaldurationtype *) malloc(sizeof(struct icaldurationtype )); + *(_result) = icaltime_subtract(*_arg0,*_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalperiodtype_from_string) { + + struct icalperiodtype * _result; + char * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_from_string(str);"); + _arg0 = (char *) SvPV(ST(0),na); + _result = (struct icalperiodtype *) malloc(sizeof(struct icalperiodtype )); + *(_result) = icalperiodtype_from_string(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icalperiodtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalperiodtype_as_ical_string) { + + char * _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_as_ical_string(p);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_as_ical_string. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (char *)icalperiodtype_as_ical_string(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setpv((SV*)ST(argvi++),(char *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalperiodtype_null_period) { + + struct icalperiodtype * _result; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 0) || (items > 0)) + croak("Usage: icalperiodtype_null_period();"); + _result = (struct icalperiodtype *) malloc(sizeof(struct icalperiodtype )); + *(_result) = icalperiodtype_null_period(); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icalperiodtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalperiodtype_is_null_period) { + + int _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_is_null_period(p);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_is_null_period. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (int )icalperiodtype_is_null_period(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +XS(_wrap_icalperiodtype_is_valid_period) { + + int _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_is_valid_period(p);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_is_valid_period. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (int )icalperiodtype_is_valid_period(*_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_year_set(_swigobj,_swigval) (_swigobj->year = _swigval,_swigval) +XS(_wrap_icaltimetype_year_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_year_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_year_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_year_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_year_get(_swigobj) ((int ) _swigobj->year) +XS(_wrap_icaltimetype_year_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_year_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_year_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_year_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_month_set(_swigobj,_swigval) (_swigobj->month = _swigval,_swigval) +XS(_wrap_icaltimetype_month_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_month_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_month_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_month_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_month_get(_swigobj) ((int ) _swigobj->month) +XS(_wrap_icaltimetype_month_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_month_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_month_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_month_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_day_set(_swigobj,_swigval) (_swigobj->day = _swigval,_swigval) +XS(_wrap_icaltimetype_day_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_day_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_day_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_day_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_day_get(_swigobj) ((int ) _swigobj->day) +XS(_wrap_icaltimetype_day_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_day_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_day_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_day_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_hour_set(_swigobj,_swigval) (_swigobj->hour = _swigval,_swigval) +XS(_wrap_icaltimetype_hour_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_hour_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_hour_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_hour_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_hour_get(_swigobj) ((int ) _swigobj->hour) +XS(_wrap_icaltimetype_hour_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_hour_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_hour_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_hour_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_minute_set(_swigobj,_swigval) (_swigobj->minute = _swigval,_swigval) +XS(_wrap_icaltimetype_minute_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_minute_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_minute_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_minute_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_minute_get(_swigobj) ((int ) _swigobj->minute) +XS(_wrap_icaltimetype_minute_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_minute_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_minute_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_minute_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_second_set(_swigobj,_swigval) (_swigobj->second = _swigval,_swigval) +XS(_wrap_icaltimetype_second_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_second_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_second_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_second_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_second_get(_swigobj) ((int ) _swigobj->second) +XS(_wrap_icaltimetype_second_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_second_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_second_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_second_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_is_utc_set(_swigobj,_swigval) (_swigobj->is_utc = _swigval,_swigval) +XS(_wrap_icaltimetype_is_utc_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_is_utc_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_is_utc_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_is_utc_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_is_utc_get(_swigobj) ((int ) _swigobj->is_utc) +XS(_wrap_icaltimetype_is_utc_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_is_utc_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_is_utc_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_is_utc_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_is_date_set(_swigobj,_swigval) (_swigobj->is_date = _swigval,_swigval) +XS(_wrap_icaltimetype_is_date_set) { + + int _result; + struct icaltimetype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaltimetype_is_date_set(struct icaltimetype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_is_date_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaltimetype_is_date_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaltimetype_is_date_get(_swigobj) ((int ) _swigobj->is_date) +XS(_wrap_icaltimetype_is_date_get) { + + int _result; + struct icaltimetype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaltimetype_is_date_get(struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaltimetypePtr")) { + croak("Type error in argument 1 of icaltimetype_is_date_get. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (int )icaltimetype_is_date_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_is_neg_set(_swigobj,_swigval) (_swigobj->is_neg = _swigval,_swigval) +XS(_wrap_icaldurationtype_is_neg_set) { + + int _result; + struct icaldurationtype * _arg0; + int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_is_neg_set(struct icaldurationtype *,int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_is_neg_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (int )SvIV(ST(1)); + _result = (int )icaldurationtype_is_neg_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_is_neg_get(_swigobj) ((int ) _swigobj->is_neg) +XS(_wrap_icaldurationtype_is_neg_get) { + + int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_is_neg_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_is_neg_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (int )icaldurationtype_is_neg_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_days_set(_swigobj,_swigval) (_swigobj->days = _swigval,_swigval) +XS(_wrap_icaldurationtype_days_set) { + + unsigned int _result; + struct icaldurationtype * _arg0; + unsigned int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_days_set(struct icaldurationtype *,unsigned int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_days_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (unsigned int )SvIV(ST(1)); + _result = (unsigned int )icaldurationtype_days_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_days_get(_swigobj) ((unsigned int ) _swigobj->days) +XS(_wrap_icaldurationtype_days_get) { + + unsigned int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_days_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_days_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (unsigned int )icaldurationtype_days_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_weeks_set(_swigobj,_swigval) (_swigobj->weeks = _swigval,_swigval) +XS(_wrap_icaldurationtype_weeks_set) { + + unsigned int _result; + struct icaldurationtype * _arg0; + unsigned int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_weeks_set(struct icaldurationtype *,unsigned int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_weeks_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (unsigned int )SvIV(ST(1)); + _result = (unsigned int )icaldurationtype_weeks_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_weeks_get(_swigobj) ((unsigned int ) _swigobj->weeks) +XS(_wrap_icaldurationtype_weeks_get) { + + unsigned int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_weeks_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_weeks_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (unsigned int )icaldurationtype_weeks_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_hours_set(_swigobj,_swigval) (_swigobj->hours = _swigval,_swigval) +XS(_wrap_icaldurationtype_hours_set) { + + unsigned int _result; + struct icaldurationtype * _arg0; + unsigned int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_hours_set(struct icaldurationtype *,unsigned int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_hours_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (unsigned int )SvIV(ST(1)); + _result = (unsigned int )icaldurationtype_hours_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_hours_get(_swigobj) ((unsigned int ) _swigobj->hours) +XS(_wrap_icaldurationtype_hours_get) { + + unsigned int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_hours_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_hours_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (unsigned int )icaldurationtype_hours_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_minutes_set(_swigobj,_swigval) (_swigobj->minutes = _swigval,_swigval) +XS(_wrap_icaldurationtype_minutes_set) { + + unsigned int _result; + struct icaldurationtype * _arg0; + unsigned int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_minutes_set(struct icaldurationtype *,unsigned int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_minutes_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (unsigned int )SvIV(ST(1)); + _result = (unsigned int )icaldurationtype_minutes_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_minutes_get(_swigobj) ((unsigned int ) _swigobj->minutes) +XS(_wrap_icaldurationtype_minutes_get) { + + unsigned int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_minutes_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_minutes_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (unsigned int )icaldurationtype_minutes_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_seconds_set(_swigobj,_swigval) (_swigobj->seconds = _swigval,_swigval) +XS(_wrap_icaldurationtype_seconds_set) { + + unsigned int _result; + struct icaldurationtype * _arg0; + unsigned int _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icaldurationtype_seconds_set(struct icaldurationtype *,unsigned int );"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_seconds_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _arg1 = (unsigned int )SvIV(ST(1)); + _result = (unsigned int )icaldurationtype_seconds_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icaldurationtype_seconds_get(_swigobj) ((unsigned int ) _swigobj->seconds) +XS(_wrap_icaldurationtype_seconds_get) { + + unsigned int _result; + struct icaldurationtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icaldurationtype_seconds_get(struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icaldurationtypePtr")) { + croak("Type error in argument 1 of icaldurationtype_seconds_get. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (unsigned int )icaldurationtype_seconds_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setiv(ST(argvi++),(IV) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_start_set(_swigobj,_swigval) (_swigobj->start = *(_swigval),_swigval) +XS(_wrap_icalperiodtype_start_set) { + + struct icaltimetype * _result; + struct icalperiodtype * _arg0; + struct icaltimetype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalperiodtype_start_set(struct icalperiodtype *,struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_start_set. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaltimetypePtr")) { + croak("Type error in argument 2 of icalperiodtype_start_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *)icalperiodtype_start_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_start_get(_swigobj) (&_swigobj->start) +XS(_wrap_icalperiodtype_start_get) { + + struct icaltimetype * _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_start_get(struct icalperiodtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_start_get. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *)icalperiodtype_start_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_end_set(_swigobj,_swigval) (_swigobj->end = *(_swigval),_swigval) +XS(_wrap_icalperiodtype_end_set) { + + struct icaltimetype * _result; + struct icalperiodtype * _arg0; + struct icaltimetype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalperiodtype_end_set(struct icalperiodtype *,struct icaltimetype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_end_set. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaltimetypePtr")) { + croak("Type error in argument 2 of icalperiodtype_end_set. Expected struct icaltimetypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *)icalperiodtype_end_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_end_get(_swigobj) (&_swigobj->end) +XS(_wrap_icalperiodtype_end_get) { + + struct icaltimetype * _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_end_get(struct icalperiodtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_end_get. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (struct icaltimetype *)icalperiodtype_end_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaltimetypePtr", (void *) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_duration_set(_swigobj,_swigval) (_swigobj->duration = *(_swigval),_swigval) +XS(_wrap_icalperiodtype_duration_set) { + + struct icaldurationtype * _result; + struct icalperiodtype * _arg0; + struct icaldurationtype * _arg1; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 2) || (items > 2)) + croak("Usage: icalperiodtype_duration_set(struct icalperiodtype *,struct icaldurationtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_duration_set. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + if (SWIG_GetPtr(ST(1),(void **) &_arg1,"struct icaldurationtypePtr")) { + croak("Type error in argument 2 of icalperiodtype_duration_set. Expected struct icaldurationtypePtr."); + XSRETURN(1); + } + _result = (struct icaldurationtype *)icalperiodtype_duration_set(_arg0,_arg1); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +#define icalperiodtype_duration_get(_swigobj) (&_swigobj->duration) +XS(_wrap_icalperiodtype_duration_get) { + + struct icaldurationtype * _result; + struct icalperiodtype * _arg0; + int argvi = 0; + dXSARGS ; + + cv = cv; + if ((items < 1) || (items > 1)) + croak("Usage: icalperiodtype_duration_get(struct icalperiodtype *);"); + if (SWIG_GetPtr(ST(0),(void **) &_arg0,"struct icalperiodtypePtr")) { + croak("Type error in argument 1 of icalperiodtype_duration_get. Expected struct icalperiodtypePtr."); + XSRETURN(1); + } + _result = (struct icaldurationtype *)icalperiodtype_duration_get(_arg0); + ST(argvi) = sv_newmortal(); + sv_setref_pv(ST(argvi++),"struct icaldurationtypePtr", (void *) _result); + XSRETURN(argvi); +} + +XS(_wrap_perl5_Net__ICal__Libical_var_init) { + dXSARGS; + SV *sv; + cv = cv; items = items; + swig_setiv("ICAL_BADARG_ERROR", (long) ICAL_BADARG_ERROR); + swig_setiv("ICAL_NEWFAILED_ERROR", (long) ICAL_NEWFAILED_ERROR); + swig_setiv("ICAL_MALFORMEDDATA_ERROR", (long) ICAL_MALFORMEDDATA_ERROR); + swig_setiv("ICAL_PARSE_ERROR", (long) ICAL_PARSE_ERROR); + swig_setiv("ICAL_INTERNAL_ERROR", (long) ICAL_INTERNAL_ERROR); + swig_setiv("ICAL_FILE_ERROR", (long) ICAL_FILE_ERROR); + swig_setiv("ICAL_ALLOCATION_ERROR", (long) ICAL_ALLOCATION_ERROR); + swig_setiv("ICAL_USAGE_ERROR", (long) ICAL_USAGE_ERROR); + swig_setiv("ICAL_NO_ERROR", (long) ICAL_NO_ERROR); + swig_setiv("ICAL_UNKNOWN_ERROR", (long) ICAL_UNKNOWN_ERROR); + swig_setiv("ICAL_ERROR_FATAL", (long) ICAL_ERROR_FATAL); + swig_setiv("ICAL_ERROR_NONFATAL", (long) ICAL_ERROR_NONFATAL); + swig_setiv("ICAL_ERROR_DEFAULT", (long) ICAL_ERROR_DEFAULT); + swig_setiv("ICAL_ERROR_UNKNOWN", (long) ICAL_ERROR_UNKNOWN); + swig_setpv("icaltimetype_zone", "icaltimetype::zone"); + XSRETURN(1); +} +#ifdef __cplusplus +extern "C" +#endif +XS(boot_Net__ICal__Libical) { + dXSARGS; + char *file = __FILE__; + cv = cv; items = items; + newXS("Net::ICal::Libical::var_Net__ICal__Libical_init", _wrap_perl5_Net__ICal__Libical_var_init, file); + newXS("Net::ICal::Libical::icalparser_parse_string", _wrap_icalparser_parse_string, file); + newXS("Net::ICal::Libical::icalcomponent_new", _wrap_icalcomponent_new, file); + newXS("Net::ICal::Libical::icalcomponent_new_clone", _wrap_icalcomponent_new_clone, file); + newXS("Net::ICal::Libical::icalcomponent_new_from_string", _wrap_icalcomponent_new_from_string, file); + newXS("Net::ICal::Libical::icalcomponent_as_ical_string", _wrap_icalcomponent_as_ical_string, file); + newXS("Net::ICal::Libical::icalcomponent_free", _wrap_icalcomponent_free, file); + newXS("Net::ICal::Libical::icalcomponent_count_errors", _wrap_icalcomponent_count_errors, file); + newXS("Net::ICal::Libical::icalcomponent_strip_errors", _wrap_icalcomponent_strip_errors, file); + newXS("Net::ICal::Libical::icalcomponent_convert_errors", _wrap_icalcomponent_convert_errors, file); + newXS("Net::ICal::Libical::icalcomponent_get_current_property", _wrap_icalcomponent_get_current_property, file); + newXS("Net::ICal::Libical::icalcomponent_get_first_property", _wrap_icalcomponent_get_first_property, file); + newXS("Net::ICal::Libical::icalcomponent_get_next_property", _wrap_icalcomponent_get_next_property, file); + newXS("Net::ICal::Libical::icalcomponent_get_current_component", _wrap_icalcomponent_get_current_component, file); + newXS("Net::ICal::Libical::icalcomponent_get_first_component", _wrap_icalcomponent_get_first_component, file); + newXS("Net::ICal::Libical::icalcomponent_get_next_component", _wrap_icalcomponent_get_next_component, file); + newXS("Net::ICal::Libical::icalcomponent_add_property", _wrap_icalcomponent_add_property, file); + newXS("Net::ICal::Libical::icalcomponent_remove_property", _wrap_icalcomponent_remove_property, file); + newXS("Net::ICal::Libical::icalcomponent_get_parent", _wrap_icalcomponent_get_parent, file); + newXS("Net::ICal::Libical::icalcomponent_isa", _wrap_icalcomponent_isa, file); + newXS("Net::ICal::Libical::icalrestriction_check", _wrap_icalrestriction_check, file); + newXS("Net::ICal::Libical::icalproperty_string_to_kind", _wrap_icalproperty_string_to_kind, file); + newXS("Net::ICal::Libical::icalproperty_new", _wrap_icalproperty_new, file); + newXS("Net::ICal::Libical::icalproperty_new_from_string", _wrap_icalproperty_new_from_string, file); + newXS("Net::ICal::Libical::icalproperty_as_ical_string", _wrap_icalproperty_as_ical_string, file); + newXS("Net::ICal::Libical::icalproperty_set_parameter_from_string", _wrap_icalproperty_set_parameter_from_string, file); + newXS("Net::ICal::Libical::icalproperty_set_value_from_string", _wrap_icalproperty_set_value_from_string, file); + newXS("Net::ICal::Libical::icalproperty_get_value_as_string", _wrap_icalproperty_get_value_as_string, file); + newXS("Net::ICal::Libical::icalproperty_get_parameter_as_string", _wrap_icalproperty_get_parameter_as_string, file); + newXS("Net::ICal::Libical::icalproperty_get_parent", _wrap_icalproperty_get_parent, file); + newXS("Net::ICal::Libical::icalerror_set_error_state", _wrap_icalerror_set_error_state, file); + newXS("Net::ICal::Libical::icalerror_get_error_state", _wrap_icalerror_get_error_state, file); + newXS("Net::ICal::Libical::icalenum_property_kind_to_string", _wrap_icalenum_property_kind_to_string, file); + newXS("Net::ICal::Libical::icalenum_string_to_property_kind", _wrap_icalenum_string_to_property_kind, file); + newXS("Net::ICal::Libical::icalenum_value_kind_to_string", _wrap_icalenum_value_kind_to_string, file); + newXS("Net::ICal::Libical::icalenum_parameter_kind_to_string", _wrap_icalenum_parameter_kind_to_string, file); + newXS("Net::ICal::Libical::icalenum_string_to_parameter_kind", _wrap_icalenum_string_to_parameter_kind, file); + newXS("Net::ICal::Libical::icalenum_component_kind_to_string", _wrap_icalenum_component_kind_to_string, file); + newXS("Net::ICal::Libical::icalenum_string_to_component_kind", _wrap_icalenum_string_to_component_kind, file); + newXS("Net::ICal::Libical::icalenum_property_kind_to_value_kind", _wrap_icalenum_property_kind_to_value_kind, file); + newXS("Net::ICal::Libical::icallangbind_new_array", _wrap_icallangbind_new_array, file); + newXS("Net::ICal::Libical::icallangbind_free_array", _wrap_icallangbind_free_array, file); + newXS("Net::ICal::Libical::icallangbind_access_array", _wrap_icallangbind_access_array, file); + newXS("Net::ICal::Libical::icalrecur_expand_recurrence", _wrap_icalrecur_expand_recurrence, file); + newXS("Net::ICal::Libical::icallangbind_get_first_property", _wrap_icallangbind_get_first_property, file); + newXS("Net::ICal::Libical::icallangbind_get_next_property", _wrap_icallangbind_get_next_property, file); + newXS("Net::ICal::Libical::icallangbind_get_first_component", _wrap_icallangbind_get_first_component, file); + newXS("Net::ICal::Libical::icallangbind_get_next_component", _wrap_icallangbind_get_next_component, file); + newXS("Net::ICal::Libical::icallangbind_property_eval_string", _wrap_icallangbind_property_eval_string, file); + newXS("Net::ICal::Libical::icaltime_from_timet", _wrap_icaltime_from_timet, file); + newXS("Net::ICal::Libical::icaltime_as_timet", _wrap_icaltime_as_timet, file); + newXS("Net::ICal::Libical::icaltime_as_ical_string", _wrap_icaltime_as_ical_string, file); + newXS("Net::ICal::Libical::icaltime_from_string", _wrap_icaltime_from_string, file); + newXS("Net::ICal::Libical::icaltime_utc_offset", _wrap_icaltime_utc_offset, file); + newXS("Net::ICal::Libical::icaltime_as_utc", _wrap_icaltime_as_utc, file); + newXS("Net::ICal::Libical::icaltime_as_zone", _wrap_icaltime_as_zone, file); + newXS("Net::ICal::Libical::icaltime_null_time", _wrap_icaltime_null_time, file); + newXS("Net::ICal::Libical::icaltime_is_null_time", _wrap_icaltime_is_null_time, file); + newXS("Net::ICal::Libical::icaltime_is_valid_time", _wrap_icaltime_is_valid_time, file); + newXS("Net::ICal::Libical::icaltime_normalize", _wrap_icaltime_normalize, file); + newXS("Net::ICal::Libical::icaltime_day_of_year", _wrap_icaltime_day_of_year, file); + newXS("Net::ICal::Libical::icaltime_from_day_of_year", _wrap_icaltime_from_day_of_year, file); + newXS("Net::ICal::Libical::icaltime_day_of_week", _wrap_icaltime_day_of_week, file); + newXS("Net::ICal::Libical::icaltime_start_doy_of_week", _wrap_icaltime_start_doy_of_week, file); + newXS("Net::ICal::Libical::icaltime_as_ctime", _wrap_icaltime_as_ctime, file); + newXS("Net::ICal::Libical::icaltime_week_number", _wrap_icaltime_week_number, file); + newXS("Net::ICal::Libical::icaltime_compare", _wrap_icaltime_compare, file); + newXS("Net::ICal::Libical::icaltime_compare_date_only", _wrap_icaltime_compare_date_only, file); + newXS("Net::ICal::Libical::icaltime_days_in_month", _wrap_icaltime_days_in_month, file); + newXS("Net::ICal::Libical::icaldurationtype_from_int", _wrap_icaldurationtype_from_int, file); + newXS("Net::ICal::Libical::icaldurationtype_from_string", _wrap_icaldurationtype_from_string, file); + newXS("Net::ICal::Libical::icaldurationtype_as_int", _wrap_icaldurationtype_as_int, file); + newXS("Net::ICal::Libical::icaldurationtype_as_ical_string", _wrap_icaldurationtype_as_ical_string, file); + newXS("Net::ICal::Libical::icaldurationtype_null_duration", _wrap_icaldurationtype_null_duration, file); + newXS("Net::ICal::Libical::icaldurationtype_is_null_duration", _wrap_icaldurationtype_is_null_duration, file); + newXS("Net::ICal::Libical::icaltime_add", _wrap_icaltime_add, file); + newXS("Net::ICal::Libical::icaltime_subtract", _wrap_icaltime_subtract, file); + newXS("Net::ICal::Libical::icalperiodtype_from_string", _wrap_icalperiodtype_from_string, file); + newXS("Net::ICal::Libical::icalperiodtype_as_ical_string", _wrap_icalperiodtype_as_ical_string, file); + newXS("Net::ICal::Libical::icalperiodtype_null_period", _wrap_icalperiodtype_null_period, file); + newXS("Net::ICal::Libical::icalperiodtype_is_null_period", _wrap_icalperiodtype_is_null_period, file); + newXS("Net::ICal::Libical::icalperiodtype_is_valid_period", _wrap_icalperiodtype_is_valid_period, file); + newXS("Net::ICal::Libical::icaltimetype_year_set", _wrap_icaltimetype_year_set, file); + newXS("Net::ICal::Libical::icaltimetype_year_get", _wrap_icaltimetype_year_get, file); + newXS("Net::ICal::Libical::icaltimetype_month_set", _wrap_icaltimetype_month_set, file); + newXS("Net::ICal::Libical::icaltimetype_month_get", _wrap_icaltimetype_month_get, file); + newXS("Net::ICal::Libical::icaltimetype_day_set", _wrap_icaltimetype_day_set, file); + newXS("Net::ICal::Libical::icaltimetype_day_get", _wrap_icaltimetype_day_get, file); + newXS("Net::ICal::Libical::icaltimetype_hour_set", _wrap_icaltimetype_hour_set, file); + newXS("Net::ICal::Libical::icaltimetype_hour_get", _wrap_icaltimetype_hour_get, file); + newXS("Net::ICal::Libical::icaltimetype_minute_set", _wrap_icaltimetype_minute_set, file); + newXS("Net::ICal::Libical::icaltimetype_minute_get", _wrap_icaltimetype_minute_get, file); + newXS("Net::ICal::Libical::icaltimetype_second_set", _wrap_icaltimetype_second_set, file); + newXS("Net::ICal::Libical::icaltimetype_second_get", _wrap_icaltimetype_second_get, file); + newXS("Net::ICal::Libical::icaltimetype_is_utc_set", _wrap_icaltimetype_is_utc_set, file); + newXS("Net::ICal::Libical::icaltimetype_is_utc_get", _wrap_icaltimetype_is_utc_get, file); + newXS("Net::ICal::Libical::icaltimetype_is_date_set", _wrap_icaltimetype_is_date_set, file); + newXS("Net::ICal::Libical::icaltimetype_is_date_get", _wrap_icaltimetype_is_date_get, file); + newXS("Net::ICal::Libical::icaldurationtype_is_neg_set", _wrap_icaldurationtype_is_neg_set, file); + newXS("Net::ICal::Libical::icaldurationtype_is_neg_get", _wrap_icaldurationtype_is_neg_get, file); + newXS("Net::ICal::Libical::icaldurationtype_days_set", _wrap_icaldurationtype_days_set, file); + newXS("Net::ICal::Libical::icaldurationtype_days_get", _wrap_icaldurationtype_days_get, file); + newXS("Net::ICal::Libical::icaldurationtype_weeks_set", _wrap_icaldurationtype_weeks_set, file); + newXS("Net::ICal::Libical::icaldurationtype_weeks_get", _wrap_icaldurationtype_weeks_get, file); + newXS("Net::ICal::Libical::icaldurationtype_hours_set", _wrap_icaldurationtype_hours_set, file); + newXS("Net::ICal::Libical::icaldurationtype_hours_get", _wrap_icaldurationtype_hours_get, file); + newXS("Net::ICal::Libical::icaldurationtype_minutes_set", _wrap_icaldurationtype_minutes_set, file); + newXS("Net::ICal::Libical::icaldurationtype_minutes_get", _wrap_icaldurationtype_minutes_get, file); + newXS("Net::ICal::Libical::icaldurationtype_seconds_set", _wrap_icaldurationtype_seconds_set, file); + newXS("Net::ICal::Libical::icaldurationtype_seconds_get", _wrap_icaldurationtype_seconds_get, file); + newXS("Net::ICal::Libical::icalperiodtype_start_set", _wrap_icalperiodtype_start_set, file); + newXS("Net::ICal::Libical::icalperiodtype_start_get", _wrap_icalperiodtype_start_get, file); + newXS("Net::ICal::Libical::icalperiodtype_end_set", _wrap_icalperiodtype_end_set, file); + newXS("Net::ICal::Libical::icalperiodtype_end_get", _wrap_icalperiodtype_end_get, file); + newXS("Net::ICal::Libical::icalperiodtype_duration_set", _wrap_icalperiodtype_duration_set, file); + newXS("Net::ICal::Libical::icalperiodtype_duration_get", _wrap_icalperiodtype_duration_get, file); +/* + * These are the pointer type-equivalency mappings. + * (Used by the SWIG pointer type-checker). + */ + SWIG_RegisterMapping("unsigned short","short",0); + SWIG_RegisterMapping("struct icaldurationtype","icaldurationtype",0); + SWIG_RegisterMapping("icalperiodtype","struct icalperiodtype",0); + SWIG_RegisterMapping("long","unsigned long",0); + SWIG_RegisterMapping("long","signed long",0); + SWIG_RegisterMapping("struct icaltimetype","icaltimetype",0); + SWIG_RegisterMapping("icaldurationtype","struct icaldurationtype",0); + SWIG_RegisterMapping("signed short","short",0); + SWIG_RegisterMapping("struct icalperiodtype","icalperiodtype",0); + SWIG_RegisterMapping("signed int","int",0); + SWIG_RegisterMapping("short","unsigned short",0); + SWIG_RegisterMapping("short","signed short",0); + SWIG_RegisterMapping("unsigned long","long",0); + SWIG_RegisterMapping("int","unsigned int",0); + SWIG_RegisterMapping("int","signed int",0); + SWIG_RegisterMapping("unsigned int","int",0); + SWIG_RegisterMapping("icaltimetype","struct icaltimetype",0); + SWIG_RegisterMapping("signed long","long",0); + ST(0) = &sv_yes; + XSRETURN(1); +} diff --git a/libical/src/Net-ICal-Libical/netical_wrap.doc b/libical/src/Net-ICal-Libical/netical_wrap.doc new file mode 100644 index 0000000000..41616c00da --- /dev/null +++ b/libical/src/Net-ICal-Libical/netical_wrap.doc @@ -0,0 +1,393 @@ +netical_wrap.c + +[ Module : Net__ICal__Libical, Package : Net::ICal::Libical ] + + +icalparser_parse_string(str); + [ returns icalcomponent * ] + +icalcomponent_new(kind); + [ returns icalcomponent * ] + +icalcomponent_new_clone(component); + [ returns icalcomponent * ] + +icalcomponent_new_from_string(str); + [ returns icalcomponent * ] + +icalcomponent_as_ical_string(component); + [ returns char * ] + +icalcomponent_free(component); + [ returns void ] + +icalcomponent_count_errors(component); + [ returns int ] + +icalcomponent_strip_errors(component); + [ returns void ] + +icalcomponent_convert_errors(component); + [ returns void ] + +icalcomponent_get_current_property(component); + [ returns icalproperty * ] + +icalcomponent_get_first_property(component,kind); + [ returns icalproperty * ] + +icalcomponent_get_next_property(component,kind); + [ returns icalproperty * ] + +icalcomponent_get_current_component(component); + [ returns icalcomponent * ] + +icalcomponent_get_first_component(component,kind); + [ returns icalcomponent * ] + +icalcomponent_get_next_component(component,kind); + [ returns icalcomponent * ] + +icalcomponent_add_property(component,property); + [ returns void ] + +icalcomponent_remove_property(component,property); + [ returns void ] + +icalcomponent_get_parent(component); + [ returns icalcomponent * ] + +icalcomponent_isa(component); + [ returns icalcomponent_kind ] + +icalrestriction_check(comp); + [ returns int ] + +icalproperty_string_to_kind(string); + [ returns int ] + +icalproperty_new(kind); + [ returns icalproperty * ] + +icalproperty_new_from_string(str); + [ returns icalproperty * ] + +icalproperty_as_ical_string(prop); + [ returns char * ] + +icalproperty_set_parameter_from_string(prop,name,value); + [ returns void ] + +icalproperty_set_value_from_string(prop,value,kind); + [ returns void ] + +icalproperty_get_value_as_string(prop); + [ returns char * ] + +icalproperty_get_parameter_as_string(prop,name); + [ returns char * ] + +icalproperty_get_parent(property); + [ returns icalcomponent * ] + +$ICAL_BADARG_ERROR = ICAL_BADARG_ERROR + [ Constant: int ] + +$ICAL_NEWFAILED_ERROR = ICAL_NEWFAILED_ERROR + [ Constant: int ] + +$ICAL_MALFORMEDDATA_ERROR = ICAL_MALFORMEDDATA_ERROR + [ Constant: int ] + +$ICAL_PARSE_ERROR = ICAL_PARSE_ERROR + [ Constant: int ] + +$ICAL_INTERNAL_ERROR = ICAL_INTERNAL_ERROR + [ Constant: int ] + Like assert --internal consist. prob + +$ICAL_FILE_ERROR = ICAL_FILE_ERROR + [ Constant: int ] + +$ICAL_ALLOCATION_ERROR = ICAL_ALLOCATION_ERROR + [ Constant: int ] + +$ICAL_USAGE_ERROR = ICAL_USAGE_ERROR + [ Constant: int ] + +$ICAL_NO_ERROR = ICAL_NO_ERROR + [ Constant: int ] + Used for problems in input to icalerror_strerror() + +$ICAL_UNKNOWN_ERROR = ICAL_UNKNOWN_ERROR + [ Constant: int ] + +$ICAL_ERROR_FATAL = ICAL_ERROR_FATAL + [ Constant: int ] + Not fata + +$ICAL_ERROR_NONFATAL = ICAL_ERROR_NONFATAL + [ Constant: int ] + Fatal + +$ICAL_ERROR_DEFAULT = ICAL_ERROR_DEFAULT + [ Constant: int ] + Use the value of icalerror_errors_are_fatal Asked state for an unknown + error type + +$ICAL_ERROR_UNKNOWN = ICAL_ERROR_UNKNOWN + [ Constant: int ] + +icalerror_set_error_state(error,icalerrorstate ); + [ returns void ] + +icalerror_get_error_state(error); + [ returns icalerrorstate ] + +icalenum_property_kind_to_string(kind); + [ returns char * ] + +icalenum_string_to_property_kind(string); + [ returns icalproperty_kind ] + +icalenum_value_kind_to_string(kind); + [ returns char * ] + icalvalue_kind icalenum_value_kind_by_prop(icalproperty_kind kind); + + +icalenum_parameter_kind_to_string(kind); + [ returns char * ] + +icalenum_string_to_parameter_kind(string); + [ returns icalparameter_kind ] + +icalenum_component_kind_to_string(kind); + [ returns char * ] + +icalenum_string_to_component_kind(string); + [ returns icalcomponent_kind ] + +icalenum_property_kind_to_value_kind(kind); + [ returns icalvalue_kind ] + +icallangbind_new_array(size); + [ returns int * ] + +icallangbind_free_array(array); + [ returns void ] + +icallangbind_access_array(array,index); + [ returns int ] + +icalrecur_expand_recurrence(rule,start,count,array); + [ returns int ] + +icallangbind_get_first_property(c,prop); + [ returns icalproperty * ] + +icallangbind_get_next_property(c,prop); + [ returns icalproperty * ] + +icallangbind_get_first_component(c,comp); + [ returns icalcomponent * ] + +icallangbind_get_next_component(c,comp); + [ returns icalcomponent * ] + +icallangbind_property_eval_string(prop,sep); + [ returns char * ] + +1. class icaltimetype +====================== +[ created from struct icaltimetype ] + + +icaltimetype_year_set(struct icaltimetype *,int ); +icaltimetype_year_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_month_set(struct icaltimetype *,int ); +icaltimetype_month_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_day_set(struct icaltimetype *,int ); +icaltimetype_day_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_hour_set(struct icaltimetype *,int ); +icaltimetype_hour_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_minute_set(struct icaltimetype *,int ); +icaltimetype_minute_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_second_set(struct icaltimetype *,int ); +icaltimetype_second_get(struct icaltimetype *); + [ Member data: returns int ] + +icaltimetype_is_utc_set(struct icaltimetype *,int ); +icaltimetype_is_utc_get(struct icaltimetype *); + [ Member data: returns int ] + 1-> time is in UTC timezone + +icaltimetype_is_date_set(struct icaltimetype *,int ); +icaltimetype_is_date_get(struct icaltimetype *); + [ Member data: returns int ] + 1 -> interpret this as date. + +$icaltimetype_zone = icaltimetype::zone + [ Constant: char * ] + Ptr to Olsen placename. Libical does not own mem + +---------- + +icaltime_from_timet(v,is_date); + [ returns struct icaltimetype ] + +icaltime_as_timet(struct icaltimetype *); + [ returns int ] + +icaltime_as_ical_string(tt); + [ returns char * ] + +icaltime_from_string(str); + [ returns struct icaltimetype ] + +icaltime_utc_offset(tt,tzid); + [ returns int ] + +icaltime_as_utc(tt,tzid); + [ returns struct icaltimetype ] + +icaltime_as_zone(tt,tzid); + [ returns struct icaltimetype ] + +icaltime_null_time(); + [ returns struct icaltimetype ] + +icaltime_is_null_time(t); + [ returns int ] + +icaltime_is_valid_time(t); + [ returns int ] + +icaltime_normalize(t); + [ returns struct icaltimetype ] + +icaltime_day_of_year(t); + [ returns short ] + +icaltime_from_day_of_year(doy,year); + [ returns struct icaltimetype ] + +icaltime_day_of_week(t); + [ returns short ] + +icaltime_start_doy_of_week(t); + [ returns short ] + +icaltime_as_ctime(struct icaltimetype *); + [ returns char * ] + +icaltime_week_number(t); + [ returns short ] + +icaltime_compare(a,b); + [ returns int ] + +icaltime_compare_date_only(a,b); + [ returns int ] + +icaltime_days_in_month(month,year); + [ returns short ] + +2. class icaldurationtype +========================== +[ created from struct icaldurationtype ] + + +icaldurationtype_is_neg_set(struct icaldurationtype *,int ); +icaldurationtype_is_neg_get(struct icaldurationtype *); + [ Member data: returns int ] + +icaldurationtype_days_set(struct icaldurationtype *,unsigned int ); +icaldurationtype_days_get(struct icaldurationtype *); + [ Member data: returns unsigned int ] + +icaldurationtype_weeks_set(struct icaldurationtype *,unsigned int ); +icaldurationtype_weeks_get(struct icaldurationtype *); + [ Member data: returns unsigned int ] + +icaldurationtype_hours_set(struct icaldurationtype *,unsigned int ); +icaldurationtype_hours_get(struct icaldurationtype *); + [ Member data: returns unsigned int ] + +icaldurationtype_minutes_set(struct icaldurationtype *,unsigned int ); +icaldurationtype_minutes_get(struct icaldurationtype *); + [ Member data: returns unsigned int ] + +icaldurationtype_seconds_set(struct icaldurationtype *,unsigned int ); +icaldurationtype_seconds_get(struct icaldurationtype *); + [ Member data: returns unsigned int ] + +---------- + +icaldurationtype_from_int(t); + [ returns struct icaldurationtype ] + +icaldurationtype_from_string(char *); + [ returns struct icaldurationtype ] + +icaldurationtype_as_int(duration); + [ returns int ] + +icaldurationtype_as_ical_string(d); + [ returns char * ] + +icaldurationtype_null_duration(); + [ returns struct icaldurationtype ] + +icaldurationtype_is_null_duration(d); + [ returns int ] + +icaltime_add(t,d); + [ returns struct icaltimetype ] + +icaltime_subtract(t1,t2); + [ returns struct icaldurationtype ] + +3. class icalperiodtype +======================== +[ created from struct icalperiodtype ] + + +icalperiodtype_start_set(struct icalperiodtype *,struct icaltimetype *); +icalperiodtype_start_get(struct icalperiodtype *); + [ Member data: returns struct icaltimetype * ] + +icalperiodtype_end_set(struct icalperiodtype *,struct icaltimetype *); +icalperiodtype_end_get(struct icalperiodtype *); + [ Member data: returns struct icaltimetype * ] + +icalperiodtype_duration_set(struct icalperiodtype *,struct icaldurationtype *); +icalperiodtype_duration_get(struct icalperiodtype *); + [ Member data: returns struct icaldurationtype * ] + +---------- + +icalperiodtype_from_string(str); + [ returns struct icalperiodtype ] + +icalperiodtype_as_ical_string(p); + [ returns char * ] + +icalperiodtype_null_period(); + [ returns struct icalperiodtype ] + +icalperiodtype_is_null_period(p); + [ returns int ] + +icalperiodtype_is_valid_period(p); + [ returns int ] + diff --git a/libical/src/Net-ICal-Libical/test-data/2446.mime b/libical/src/Net-ICal-Libical/test-data/2446.mime new file mode 100644 index 0000000000..919bfc423f --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/2446.mime @@ -0,0 +1,3426 @@ +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-0" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-0 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-0 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :PUBLISH +PRODID + :-//ACME/DesktopCalendar//EN +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :mailto:a@example.com +DTSTART + :19970701T200000Z +DTSTAMP + :19970611T190000Z +SUMMARY + :ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID + :0981234-1234234-23@example.com +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-0-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-1" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-1 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-1 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :PUBLISH +VERSION + :2.0 +PRODID + :-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER + :mailto:a@example.com +DTSTAMP + :19970612T190000Z +DTSTART + :19970701T210000Z +DTEND + :19970701T230000Z +SEQUENCE + :1 +UID + :0981234-1234234-23@example.com +SUMMARY + :ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-1-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-2" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-2 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-2 +Content-Type: text/calendar; method=CANCEL; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :CANCEL +VERSION + :2.0 +PRODID + :-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER + :mailto:a@example.com +COMMENT + :DUKES forfeit the game +SEQUENCE + :2 +UID + :0981234-1234234-23@example.com +DTSTAMP + :19970613T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-2-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-3" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-3 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-3 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :PUBLISH +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PROPERTY_PARSE_ERROR + :Parse error in property name: 'SCALE' +VERSION + :2.0 +BEGIN:VTIMEZONE +TZID + :America-Chicago +TZURL + :http://zones.stds_r_us.net/tz/America-Chicago +BEGIN:STANDARD +DTSTART + :19671029T020000 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=YEARLY\;BYDAY=-1SU\;BYMONTH=10' +TZOFFSETFROM + :-050000 +TZOFFSETTO + :-060000 +TZNAME + :CST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART + :19870405T020000 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=YEARLY\;BYDAY=1SU\;BYMONTH=4' +TZOFFSETFROM + :-060000 +TZOFFSETTO + :-050000 +TZNAME + :CDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +ORGANIZER + :mailto:a@example.com +ATTACH + :http://www.dukes.com/ +CATEGORIES + :SPORTS EVENT +CATEGORIES + :ENTERTAINMENT +CLASS + :PRIVATE +DESCRIPTION + :MIDWAY STADIUM\nBig time game. MUST see.\nExpected duration:2 hours\n +DTEND + ;TZID=America-Chicago + :19970701T180000 +DTSTART + ;TZID=America-Chicago + :19970702T160000 +DTSTAMP + :19970614T190000Z +STATUS + :CONFIRMED +LOCATION + ;VALUE=America-Chicago + :http://www.midwaystadium.com/ +PRIORITY + :2 +RESOURCES + :SCOREBOARD +SEQUENCE + :3 +SUMMARY + :ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID + :0981234-1234234-23@example.com +RELATED-TO + :0981234-1234234-14@example.com +BEGIN:VALARM +TRIGGER + :PT2H +ACTION + :DISPLAY +DESCRIPTION + :You should be leaving for the game now. +END:VALARM +BEGIN:VALARM +TRIGGER + :PT30M +ACTION + :AUDIO +END:VALARM +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-3-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-4" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-4 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-4 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :PUBLISH +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :mailto:a@example.com +DTSTAMP + :19970614T190000Z +UID + :0981234-1234234-23@example.com +DTSTART + ;VALUE=DATE + :19970714 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=YEARLY\;INTERVAL=1' +SUMMARY + : Bastille Day +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-4-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-5" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-5 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-5 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + ;CN=BIG A + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + ;CN=B + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + ;CN=C + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + ;CN=Hal + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=FALSE + :conf_Big@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=ROOM' +ATTENDEE + ;ROLE=NON-PARTICIPANT + ;RSVP=FALSE + :Mailto:E@example.com +DTSTAMP + :19970611T190000Z +DTSTART + :19970701T200000Z +DTEND + :19970701T200000Z +SUMMARY + :Conference +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-5-- + + +From eric@busboom.org Wed Jan 26 21:46:04 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-6" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-6 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-6 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VEVENT +ATTENDEE + ;PARTSTAT=ACCEPTED + :Mailto:B@example.com +ORGANIZER + :MAILTO:A@example.com +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +REQUEST-STATUS + :2.0\;Success +DTSTAMP + :19970612T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-6-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-7" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-7 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-7 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + ;CN=Hal + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;ROLE=NON-PARTICIPANT + ;RSVP=FALSE + ;CUTYPE=ROOM + :Mailto:Conf@example.com +ATTENDEE + ;ROLE=NON-PARTICIPANT + ;RSVP=FALSE + :Mailto:E@example.com +DTSTART + :19970701T180000Z +DTEND + :19970701T190000Z +SUMMARY + :Phone Conference +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :1 +DTSTAMP + :19970613T190000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-7-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951964-26278-8" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951964-26278-8 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951964-26278-8 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTART + :19970701T190000Z +DTEND + :19970701T200000Z +SUMMARY + :Discuss the Merits of the election results +LOCATION + :Green Conference Room +UID + :calsrv.example.com-873970198738777a@example.com +SEQUENCE + :0 +DTSTAMP + :19970611T190000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951964-26278-8-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-9" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-9 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-9 +Content-Type: text/calendar; method=COUNTER; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :COUNTER +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTART + :19970701T160000Z +DTEND + :19970701T190000Z +DTSTAMP + :19970612T190000Z +SUMMARY + :Discuss the Merits of the election results +LOCATION + :Green Conference Room +COMMENT + :This time works much better and I think the big conference room is + too big +UID + :calsrv.example.com-873970198738777a@example.com +SEQUENCE + :0 +DTSTAMP + :19970611T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-9-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-10" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-10 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-10 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTAMP + :19970613T190000Z +DTSTART + :19970701T160000Z +DTEND + :19970701T190000Z +SUMMARY + :Discuss the Merits of the election results - changed to meet B's schedule +LOCATION + :Green Conference Room +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :1 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-10-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-11" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-11 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-11 +Content-Type: text/calendar; method=DECLINECOUNTER; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :DECLINECOUNTER +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +COMMENT + :Sorry +COMMENT + : I cannot change this meeting time +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +DTSTAMP + :19970614T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-11-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-12" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-12 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-12 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :MAILTO:A@Example.com +ATTENDEE + ;PARTSTAT=DELEGATED + ;DELEGATED-TO="Mailto:E@example.com" + :Mailto:C@example.com +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +REQUEST-STATUS + :2.0\;Success +DTSTAMP + :19970611T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-12-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-13" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-13 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-13 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;PARTSTAT=DELEGATED + ;DELEGATED-TO="Mailto:E@example.com" + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + ;DELEGATED-FROM="Mailto:C@example.com" + :Mailto:E@example.com +DTSTART + :19970701T180000Z +DTEND + :19970701T200000Z +SUMMARY + :Phone Conference +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +DTSTAMP + :19970611T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-13-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-14" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-14 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-14 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :MAILTO:A@Example.com +ATTENDEE + ;PARTSTAT=ACCEPTED + ;DELEGATED-FROM="Mailto:C@example.com" + :Mailto:E@example.com +ATTENDEE + ;PARTSTAT=DELEGATED + ;DELEGATED-TO="Mailto:E@example.com" + :Mailto:C@example.com +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +REQUEST-STATUS + :2.0\;Success +DTSTAMP + :19970614T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-14-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-15" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-15 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-15 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :MAILTO:A@Example.com +ATTENDEE + ;PARTSTAT=DELEGATED + ;DELEGATED-TO="Mailto:E@example.com" + :Mailto:C@example.com +ATTENDEE + ;PARTSTAT=DECLINED + ;DELEGATED-FROM="Mailto:C@example.com" + :Mailto:E@example.com +COMMENT + :Sorry +COMMENT + : I will be out of town at that time. +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +REQUEST-STATUS + :2.0\;Success +DTSTAMP + :19970614T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-15-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-16" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-16 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-16 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :MAILTO:A@Example.com +ATTENDEE + ;PARTSTAT=DECLINED + ;DELEGATED-FROM="Mailto:C@example.com" + :Mailto:E@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +SUMMARY + :Phone Conference +DTSTART + :19970701T180000Z +DTEND + :19970701T200000Z +DTSTAMP + :19970614T200000Z +COMMENT + :DELEGATE (ATTENDEE Mailto:E@example.com) DECLINED YOURINVITATION +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-16-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-17" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-17 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-17 +Content-Type: text/calendar; method=CANCEL; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :CANCEL +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + :A@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'Mailto' +ATTENDEE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +COMMENT + :Mr. B cannot attend. It's raining. Lets cancel. +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :1 +STATUS + :CANCELLED +DTSTAMP + :19970613T190000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-17-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-18" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-18 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-18 +Content-Type: text/calendar; method=CANCEL; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :CANCEL +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + :mailto:B@example.com +COMMENT + :You're off the hook for this meeting +UID + :calsrv.example.com-873970198738777@example.com +DTSTAMP + :19970613T193000Z +SEQUENCE + :1 +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-18-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-19" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-19 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-19 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + :CR_Big@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=ROOM' +ATTENDEE + ;ROLE=NON-PARTICIPANT + ;RSVP=FALSE + :Mailto:E@example.com +DTSTAMP + :19970611T190000Z +DTSTART + :19970701T200000Z +DTEND + :19970701T203000Z +SUMMARY + :Phone Conference +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :2 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-19-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-20" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-20 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-20 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:B@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'STATUS=ACCEPTED' +ATTENDEE + :Mailto:C@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTAMP + :19970611T190000Z +DTSTART + :19970701T200000Z +DTEND + :19970701T203000Z +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=WEEKLY' +SUMMARY + :Phone Conference +UID + :123456@example.com +SEQUENCE + :1 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-20-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-21" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-21 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-21 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +VERSION + :2.0 +METHOD + :PUBLISH +BEGIN:VFREEBUSY +DTSTAMP + :19980101T124100Z +ORGANIZER + :MAILTO:A@Example.com +DTSTART + :19980101T124200Z +DTEND + :19980107T124200Z +FREEBUSY + :19980101T180000Z/19980101T190000Z +FREEBUSY + :19980103T020000Z/19980103T050000Z +FREEBUSY + :19980107T020000Z/19980107T050000Z +FREEBUSY + :19980113T000000Z/19980113T010000Z +FREEBUSY + :19980115T190000Z/19980115T200000Z +FREEBUSY + :19980115T220000Z/19980115T230000Z +FREEBUSY + :19980116T013000Z/19980116T043000Z +END:VFREEBUSY +END:VCALENDAR + +------------=_948951965-26278-21-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-22" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-22 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-22 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VFREEBUSY +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +DTSTAMP + :19970613T190000Z +DTSTART + :19970701T080000Z +DTEND + :19970701T200000 +UID + :calsrv.example.com-873970198738777@example.com +END:VFREEBUSY +END:VCALENDAR + +------------=_948951965-26278-22-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-23" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-23 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-23 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VFREEBUSY +ORGANIZER + :MAILTO:A@example.com +ATTENDEE + :Mailto:B@example.com +DTSTART + :19970701T080000Z +DTEND + :19970701T200000Z +UID + :calsrv.example.com-873970198738777@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as PERIOD value in FREEBUSY property. Removing entire + property: '19970701T090000Z/PT1H' +DTSTAMP + :19970613T190030Z +END:VFREEBUSY +END:VCALENDAR + +------------=_948951965-26278-23-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-24" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-24 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-24 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VTIMEZONE +TZID + :America-SanJose +TZURL + :http://zones.stds_r_us.net/tz/America-SanJose +BEGIN:STANDARD +DTSTART + :19671029T020000 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=YEARLY\;BYDAY=-1SU\;BYMONTH=10' +TZOFFSETFROM + :-070000 +TZOFFSETTO + :-080000 +TZNAME + :PST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART + :19870405T020000 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=YEARLY\;BYDAY=1SU\;BYMONTH=4' +TZOFFSETFROM + :-080000 +TZOFFSETTO + :-070000 +TZNAME + :PDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :A@example.COM +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :B@example.fr +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :c@example.jp +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTAMP + :19970613T190030Z +DTSTART + ;TZID=America-SanJose + :19970701T140000 +DTEND + ;TZID=America-SanJose + :19970701T150000 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=WEEKLY\;INTERVAL=20\;WKST=SU\;BYDAY=TU' +RDATE + ;TZID=America-SanJose + :19970910T140000 +EXDATE + ;TZID=America-SanJose + :19970909T140000 +EXDATE + ;TZID=America-SanJose + :19971028T140000 +SUMMARY + :Weekly Phone Conference +UID + :calsrv.example.com-873970198738777@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-24-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-25" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-25 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-25 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +SEQUENCE + :0 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=MONTHLY\;BYMONTHDAY=1\;UNTIL=19980901T210000Z' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +ATTENDEE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Conference Call +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970601T210000Z +DTEND + :19970601T220000Z +LOCATION + :Conference Call +DTSTAMP + :19970526T083000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-25-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-26" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-26 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-26 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1com +RECURRENCE-ID + :19970701T210000Z +SEQUENCE + :1 +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +ATTENDEE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Conference Call +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970703T210000Z +DTEND + :19970703T220000Z +LOCATION + :Conference Call +DTSTAMP + :19970626T093000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-26-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-27" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-27 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-27 +Content-Type: text/calendar; method=CANCEL; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :CANCEL +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +ATTENDEE + :Mailto:D@example.com +RECURRENCE-ID + :19970801T210000Z +SEQUENCE + :2 +STATUS + :CANCELLED +DTSTAMP + :19970721T093000Z +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-27-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-28" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-28 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-28 +Content-Type: text/calendar; method=CANCEL; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :CANCEL +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +ATTENDEE + :Mailto:D@example.com +DTSTAMP + :19970721T103000Z +STATUS + :CANCELLED +SEQUENCE + :3 +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-28-- + + +From eric@busboom.org Wed Jan 26 21:46:05 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-29" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-29 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-29 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +RECURRENCE-ID + :19970901T210000Z +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'THISANDFUTURE' +SEQUENCE + :3 +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Discussion +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970901T210000Z +DTEND + :19970901T220000Z +LOCATION + :Building 32 +LOCATION + : Microsoft +LOCATION + : Seattle +LOCATION + : WA +DTSTAMP + :19970526T083000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-29-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-30" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-30 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-30 +Content-Type: text/calendar; method=ADD; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :ADD +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :4 +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Conference Call +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970715T210000Z +DTEND + :19970715T220000Z +LOCATION + :Conference Call +DTSTAMP + :19970629T093000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-30-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951965-26278-31" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951965-26278-31 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951965-26278-31 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :0 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'WKST=SU\;BYDAY=TU\;FREQ=WEEKLY' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980303T210000Z +DTEND + :19980303T220000Z +LOCATION + :The White Room +DTSTAMP + :19980301T093000Z +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951965-26278-31-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-32" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-32 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-32 +Content-Type: text/calendar; method=ADD; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :ADD +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :7 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'WKST=SU\;BYDAY=TH\;FREQ=WEEKLY' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980303T210000Z +DTEND + :19980303T220000Z +DTSTAMP + :19980303T193000Z +LOCATION + :The Usual conference room +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-32-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-33" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-33 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-33 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :7 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'WKST=SU\;BYDAY=TU' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980303T210000Z +DTEND + :19980303T220000Z +DTSTAMP + :19980303T193000Z +LOCATION + :The White Room +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-33-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-34" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-34 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-34 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :0 +RDATE + :19980304T180000Z +RDATE + :19980311T180000Z +RDATE + :19980318T180000Z +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980304T180000Z +DTEND + :19980304T200000Z +DTSTAMP + :19980303T193000Z +LOCATION + :Conference Room A +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-34-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-35" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-35 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-35 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :1 +RECURRENCE-ID + :19980311T180000Z +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980311T160000Z +DTEND + :19980311T180000Z +DTSTAMP + :19980306T193000Z +LOCATION + :The Small conference room +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-35-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-36" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-36 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-36 +Content-Type: text/calendar; method=ADD; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :ADD +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :2 +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980315T180000Z +DTEND + :19980315T200000Z +DTSTAMP + :19980307T193000Z +LOCATION + :Conference Room A +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-36-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-37" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-37 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-37 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :123456789@host1.com +SEQUENCE + :2 +RDATE + :19980304T180000Z +RDATE + :19980311T160000Z +RDATE + :19980315T180000Z +X-LIC-ERROR + ;X-LIC-ERRORTYPE=COMPONENT_PARSE_ERROR + :Got a data line\, but could not find a property name or component + begin tag: 'Error! Bookmark not defined.' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +SUMMARY + :Review Accounts +DTSTART + :19980304T180000Z +DTEND + :19980304T200000Z +DTSTAMP + :19980303T193000Z +LOCATION + :Conference Room A +STATUS + :CONFIRMED +END:VEVENT +BEGIN:VEVENT +X-LIC-ERROR + ;X-LIC-ERRORTYPE=COMPONENT_PARSE_ERROR + :Got a data line\, but could not find a property name or component + begin tag: 'Error! Bookmark not defined.' +SEQUENCE + :2 +RECURRENCE-ID + :19980311T160000Z +X-LIC-ERROR + ;X-LIC-ERRORTYPE=COMPONENT_PARSE_ERROR + :Got a data line\, but could not find a property name or component + begin tag: 'Error! Bookmark not defined.' +ATTENDEE + :ROLE=CHAIR;Error! Bookmark not defined. +ATTENDEE + :Error! Bookmark not defined. +SUMMARY + :Review Accounts +DTSTART + :19980311T160000Z +DTEND + :19980304T180000Z +DTSTAMP + :19980306T193000Z +LOCATION + :The Small conference room +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-37-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-38" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-38 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-38 +Content-Type: text/calendar; method=COUNTER; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :COUNTER +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +RECURRENCE-ID + :19970715T210000Z +SEQUENCE + :4 +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;RSVP=TRUE + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Conference Call +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970715T220000Z +DTEND + :19970715T230000Z +LOCATION + :Conference Call +COMMENT + :May we bump this by an hour? I have a conflict +DTSTAMP + :19970629T094000Z +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-38-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-39" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-39 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-39 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :guid-1@host1.com +SEQUENCE + :0 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=MONTHLY\;BYMONTHDAY=1' +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +DESCRIPTION + :IETF-C&S Conference Call +CLASS + :PUBLIC +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970601T210000Z +DTEND + :19970601T220000Z +DTSTAMP + :19970602T094000Z +LOCATION + :Conference Call +STATUS + :CONFIRMED +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PROPERTY_PARSE_ERROR + :Parse error in property name: 'FOO' +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-39-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-40" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-40 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-40 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//RDU Software//NONSGML HandCal//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +REQUEST-STATUS + :2.8\;Repeating event ignored. Scheduled as a single event\;RRULE +REQUEST-STATUS + :3.0\;Invalid Property Name\;FOO +UID + :guid-1@host1.com +SEQUENCE + :0 +DTSTAMP + :19970603T094000Z +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-40-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-41" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-41 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-41 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:C@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +DTSTART + :19970701T170000Z +DUE + :19970722T170000Z +PRIORITY + :1 +SUMMARY + :Create the requirements document +UID + :calsrv.example.com-873970198738777-00@example.com +SEQUENCE + :0 +DTSTAMP + :19970717T200000Z +STATUS + :Needs Action +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-41-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-42" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-42 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-42 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;PARTSTAT=ACCEPTED + :Mailto:B@example.com +UID + :calsrv.example.com-873970198738777-00@example.com +COMMENT + :I'll send you my input by e-mail +SEQUENCE + :0 +DTSTAMP + :19970717T203000Z +REQUEST-STATUS + :2.0\;Success +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-42-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-43" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-43 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-43 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +UID + :calsrv.example.com-873970198738777-00@example.com +SUMMARY + :Create the requirements document +PRIORITY + :1 +SEQUENCE + :0 +STATUS + :IN-PROCESS +DTSTART + :19970701T170000Z +DTSTAMP + :19970717T230000Z +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-43-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-44" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-44 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-44 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :MAILTO:A@example.com +ATTENDEE + ;PARTSTAT=IN-PROCESS + :Mailto:B@example.com +PERCENT-COMPLETE + :75 +UID + :calsrv.example.com-873970198738777-00@example.com +DTSTAMP + :19970717T233000Z +SEQUENCE + :0 +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-44-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-45" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-45 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-45 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :MAILTO:A@example.com +ATTENDEE + ;PARTSTAT=COMPLETED + :Mailto:D@example.com +UID + :calsrv.example.com-873970198738777-00@example.com +DTSTAMP + :19970717T233000Z +SEQUENCE + :0 +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-45-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-46" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-46 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-46 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + ;PARTSTAT=ACCEPTED + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;PARTSTAT=IN-PROCESS + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +DTSTART + :19970701T170000Z +DUE + :19970722T170000Z +PRIORITY + :1 +SUMMARY + :Create the requirements document +UID + :calsrv.example.com-873970198738777-00@example.com +SEQUENCE + :1 +DTSTAMP + :19970718T100000Z +STATUS + :IN-PROGRESS +PERCENT-COMPLETE + :40 +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-46-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-47" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-47 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-47 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VTODO +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + :Mailto:A@example.com +ATTENDEE + ;RSVP=TRUE + :Mailto:B@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +ATTENDEE + ;RSVP=TRUE + :Mailto:D@example.com +X-LIC-ERROR + ;X-LIC-ERRORTYPE=PARAMETER_PARSE_ERROR + :Can't parse parameter name: 'TYPE=INDIVIDUAL' +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=MONTHLY\;COUNT=10\;BYDAY=1FR' +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as DATE-TIME value in DTSTART property. Removing entire + property: '19980101T100000-0700' +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as DATE-TIME value in DUE property. Removing entire property: + '19980103T100000-0700' +SUMMARY + :Send Status Reports to Area Managers +UID + :calsrv.example.com-873970198738777-00@example.com +SEQUENCE + :0 +DTSTAMP + :19970717T200000Z +STATUS + :NEEDS ACTION +PRIORITY + :1 +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-47-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-48" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-48 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-48 +Content-Type: text/calendar; method=REPLY; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//ACME/DesktopCalendar//EN +METHOD + :REPLY +VERSION + :2.0 +BEGIN:VTODO +ATTENDEE + ;PARTSTAT=IN-PROCESS + :Mailto:B@example.com +PERCENT-COMPLETE + :75 +UID + :calsrv.example.com-873970198738777-00@example.com +DTSTAMP + :19970717T233000Z +RECURRENCE-ID + :19980101T170000Z +SEQUENCE + :1 +END:VTODO +END:VCALENDAR + +------------=_948951966-26278-48-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-49" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-49 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-49 +Content-Type: text/calendar; method=PUBLISH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :PUBLISH +PRODID + :-//ACME/DesktopCalendar//EN +VERSION + :2.0 +BEGIN:VJOURNAL +DTSTART + :19971002T200000Z +ORGANIZER + :MAILTO:A@Example.com +SUMMARY + :Phone conference minutes +DESCRIPTION + :The editors meeting was held on October 1 +DESCRIPTION + : 1997. Details are in the attached document. +UID + :0981234-1234234-2410@example.com +RELATED-TO + :0981234-1234234-2402-35@example.com +ATTACH + :ftp://ftp.example.com/pub/ed/minutes100197.txt +END:VJOURNAL +END:VCALENDAR + +------------=_948951966-26278-49-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-50" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-50 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-50 +Content-Type: text/calendar; method=REFRESH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//RDU Software//NONSGML HandCal//EN +METHOD + :REFRESH +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +ATTENDEE + :Mailto:C@example.com +ATTENDEE + :Mailto:D@example.com +UID + : guid-1-12345@host1.com +DTSTAMP + :19970603T094000 +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-50-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-51" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-51 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-51 +Content-Type: text/calendar; method=REQUEST; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +METHOD + :REQUEST +PRODID + :-//RDU Software//NONSGML HandCal//EN +VERSION + :2.0 +BEGIN:VEVENT +UID + :acme-12345@host1.com +SEQUENCE + :3 +X-LIC-ERROR + ;X-LIC-ERRORTYPE=VALUE_PARSE_ERROR + :Can't parse as RECUR value in RRULE property. Removing entire property: + 'FREQ=WEEKLY' +RDATE + ;VALUE=PERIOD + :19970819T210000Z/19970081T220000Z +ORGANIZER + :Mailto:A@example.com +ATTENDEE + ;ROLE=CHAIR + ;PARTSTAT=ACCEPTED + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +DESCRIPTION + :IETF-C&S Conference Call +SUMMARY + :IETF Calendaring Working Group Meeting +DTSTART + :19970801T210000Z +DTEND + :19970801T220000Z +RECURRENCE-ID + :19970809T210000Z +DTSTAMP + :19970726T083000 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-51-- + + +From eric@busboom.org Wed Jan 26 21:46:06 2000 +Content-Type: multipart/mixed; boundary="----------=_948951966-26278-52" +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) +From: eric@busboom.org +To: alice +Subject: Hello, nurse! + +This is a multi-part message in MIME format... + +------------=_948951966-26278-52 +Content-Type: text/plain +Content-Disposition: inline + +Hey! Come to the meeting! +------------=_948951966-26278-52 +Content-Type: text/calendar; method=REFRESH; charset=US-ASCII +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 +X-Mailer: MIME-tools 4.104 (Entity 4.117) + +BEGIN:VCALENDAR +PRODID + :-//RDU Software//NONSGML HandCal//EN +METHOD + :REFRESH +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:A@example.com +ATTENDEE + :Mailto:B@example.com +UID + :acme-12345@host1.com +DTSTAMP + :19970603T094000 +END:VEVENT +END:VCALENDAR + +------------=_948951966-26278-52-- + + diff --git a/libical/src/Net-ICal-Libical/test-data/error b/libical/src/Net-ICal-Libical/test-data/error new file mode 100644 index 0000000000..aa0efce1b4 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/error @@ -0,0 +1,58 @@ +From foo6@example.com Sun Jan 16 17:34:23 2000 +From: foo6@example.com +MIME-Version: 1.0 +To: alice@agony +Subject: REQUEST - Phone Conference +Content-Type:multipart/related;boundary="--FEE3790DC7E35189CA67CE2C" + +----FEE3790DC7E35189CA67CE2C +Content-Type: multipart/alternative;boundary="--00FEE3790DC7E35189CA67CE2C00" + +----00FEE3790DC7E35189CA67CE2C00 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit + +When: 7/1/1997 10:00PM PDT- 7/1/97 10:30 PM PDT +Where: +Organizer: foo1@example.com +Summary: Let's discuss the attached document + +----00FEE3790DC7E35189CA67CE2C00 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII;Component=vevent +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="event.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:foo1@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo2@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo3@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970621T170000Z +DTEND:199706211T173000Z +SUMMARY:Let's discuss the attached document +UID:calsvr.example.com-873970198738777-8aa +ATTACH:cid:calsvr.example.com-12345aaa +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +----00FEE3790DC7E35189CA67CE2C00-- + +----FEE3790DC7E35189CA67CE2C +Content-Type: application/msword; name="FieldReport.doc" +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename="FieldReport.doc" +Content-ID: <calsvr.example.com-12345aaa> + + +R0lGODdhTAQZAJEAAFVVVd3d3e4AAP///ywAAAAATAQZAAAC/5yPOSLhD6OctNqLs94XqAG +4kiW5omm6sq27gvH8kzX9o1y+s73/g8MCofEovGITCoxKMbyCR16cNSq9YrNarfcrvdriIH +5LL5jE6rxc3G+v2cguf0uv2Oz+v38L7/DxgoOKjURnjIIbe3yNjo+AgZWYVIWWl5iZnJY6J. + +----FEE3790DC7E35189CA67CE2C-- diff --git a/libical/src/Net-ICal-Libical/test-data/mail-examples b/libical/src/Net-ICal-Libical/test-data/mail-examples new file mode 100644 index 0000000000..5fb7c55c82 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/mail-examples @@ -0,0 +1,262 @@ +From foo1@example.com Sun Jan 16 17:34:23 2000 +From: foo1@example.com +To: alice@agony +Subject: Phone Conference +Mime-Version: 1.0 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:sman@netscape.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:sman@netscape.com +ATTENDEE;RSVP=TRUE:mailto:stevesil@microsoft.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SUMMARY:Phone Conference +DESCRIPTION:Please review the attached document. +UID:calsvr.example.com-873970198738777 +ATTACH:ftp://ftp.bar.com/pub/docs/foo.doc +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +From foo2@example.com Sun Jan 16 17:34:23 2000 +From: foo2@example.com +To: alice@agony +Subject: Phone Conference +Mime-Version: 1.0 +Content-Type: multipart/alternative;boundary="01BD3665.3AF0D360" + +--01BD3665.3AF0D360 +Content-Type: text/plain;charset=us-ascii +Content-Transfer-Encoding: 7bit + +This is an alternative representation of a TEXT/CALENDAR MIME Object +When: 7/1/1997 10:00AM PDT - 7/1/97 10:30AM PDT +Where: +Organizer: foo1@example.com +Summary: Phone Conference + +--01BD3665.3AF0D360 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:foo1@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo2@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T170000Z +DTEND:19970701T173000Z +SUMMARY:Phone Conference +UID:calsvr.example.com-8739701987387771 +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +--01BD3665.3AF0D360-- + +From foo3@example.com Sun Jan 16 17:34:23 2000 +From: foo3@example.com +To: alice@agony +Subject: Phone Conference +Mime-Version: 1.0 +Content-Type: multipart/related; boundary="boundary-example-1";type=text/calendar + +--boundary-example-1 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="event.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:foo1@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo2@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T180000Z +DTEND:19970701T183000Z +SUMMARY:Phone Conference +UID:calsvr.example.com-8739701987387771 +ATTACH:cid:123456789@example.com +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +--boundary-example-1 +Content-Type: application/msword; name="FieldReport.doc" +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename="FieldReport.doc" +Content-ID: <123456789@example.com> + +0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAABAAAARAAAAAAA +AAAAEAAAQAAAAAEAAAD+////AAAAAEUAAAD///////////////////////////////// + +--boundary-example-1-- + +From foo4@example.com Sun Jan 16 17:34:23 2000 +From: foo4@example.com +To: alice@agony +Subject: Summer Company Holidays +Mime-Version: 1.0 +Content-Type:text/calendar; method=PUBLISH; charset=US-ASCII +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="event.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DESKTOPCALENDAR//EN +METHOD:PUBLISH +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:MAILTO:FOO1@EXAMPLE.COM +DTSTAMP:19970611T150000Z +DTSTART:19970701T150000Z +DTEND:19970701T230000Z +SUMMARY:Company Picnic +DESCRIPTION:Food and drink will be provided +UID:CALSVR.EXAMPLE.COM-873970198738777-1 +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +BEGIN:VEVENT +ORGANIZER:MAILTO:FOO1@EXAMPLE.COM +DTSTAMP:19970611T190000Z +DTSTART:19970715T150000Z +DTEND:19970715T230000Z +SUMMARY:Company Bowling Tournament +DESCRIPTION:We have 10 lanes reserved +UID:CALSVR.EXAMPLE.COM-873970198738777-2 +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +From foo5@example.com Sun Jan 16 17:34:23 2000 +From: foo5@example.com +To: alice@agony +Subject: Phone Conference +Mime-Version: 1.0 +Content-Type:multipart/mixed;boundary="--FEE3790DC7E35189CA67CE2C" + +This is a multi-part message in MIME format. + +----FEE3790DC7E35189CA67CE2C +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="event1.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:foo1@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo2@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SUMMARY:Phone Conference +DESCRIPTION:Discuss what happened at the last meeting +UID:calsvr.example.com-8739701987387772 +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +----FEE3790DC7E35189CA67CE2C +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding:7bit +Content-Disposition: attachment; filename="todo1.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTODO +DUE:19970701T090000 +ORGANIZER:mailto:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:foo1@example.com +ATTENDEE;RSVP=TRUE:mailto:foo2@example.com +SUMMARY:Phone Conference +DESCRIPTION:Discuss a new location for the company picnic +UID:calsvr.example.com-td-8739701987387773 +SEQUENCE:0 +STATUS:NEEDS ACTION +END:VEVENT +END:VCALENDAR + +----FEE3790DC7E35189CA67CE2C-- + +From foo6@example.com Sun Jan 16 17:34:23 2000 +From: foo6@example.com +MIME-Version: 1.0 +To: alice@agony +Subject: REQUEST - Phone Conference +Content-Type:multipart/related;boundary="--FEE3790DC7E35189CA67CE2C" + +----FEE3790DC7E35189CA67CE2C +Content-Type: multipart/alternative;boundary="--00FEE3790DC7E35189CA67CE2C00" + +----00FEE3790DC7E35189CA67CE2C00 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit + +When: 7/1/1997 10:00PM PDT- 7/1/97 10:30 PM PDT +Where: +Organizer: foo1@example.com +Summary: Let's discuss the attached document + +----00FEE3790DC7E35189CA67CE2C00 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII;Component=vevent +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; filename="event.vcs" + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:foo1@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:foo1@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo2@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:mailto:foo3@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970621T170000Z +DTEND:199706211T173000Z +SUMMARY:Let's discuss the attached document +UID:calsvr.example.com-873970198738777-8aa +ATTACH:cid:calsvr.example.com-12345aaa +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +----00FEE3790DC7E35189CA67CE2C00-- + +----FEE3790DC7E35189CA67CE2C +Content-Type: application/msword; name="FieldReport.doc" +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename="FieldReport.doc" +Content-ID: <calsvr.example.com-12345aaa> + + +R0lGODdhTAQZAJEAAFVVVd3d3e4AAP///ywAAAAATAQZAAAC/5yPOSLhD6OctNqLs94XqAG +4kiW5omm6sq27gvH8kzX9o1y+s73/g8MCofEovGITCoxKMbyCR16cNSq9YrNarfcrvdriIH +5LL5jE6rxc3G+v2cguf0uv2Oz+v38L7/DxgoOKjURnjIIbe3yNjo+AgZWYVIWWl5iZnJY6J. + +----FEE3790DC7E35189CA67CE2C--
\ No newline at end of file diff --git a/libical/src/Net-ICal-Libical/test-data/no-error b/libical/src/Net-ICal-Libical/test-data/no-error new file mode 100644 index 0000000000..f5b5ce995d --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/no-error @@ -0,0 +1,26 @@ +From foo1@example.com Sun Jan 16 17:34:23 2000 +From: foo1@example.com +To: alice@agony +Subject: Phone Conference +Mime-Version: 1.0 +Content-Type:text/calendar; method=REQUEST; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:sman@netscape.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:sman@netscape.com +ATTENDEE;RSVP=TRUE:mailto:stevesil@microsoft.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SUMMARY:Phone Conference +DESCRIPTION:Please review the attached document. +UID:calsvr.example.com-873970198738777 +ATTACH:ftp://ftp.bar.com/pub/docs/foo.doc +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR diff --git a/libical/src/Net-ICal-Libical/test-data/rfc2445.ics b/libical/src/Net-ICal-Libical/test-data/rfc2445.ics new file mode 100644 index 0000000000..f225f26331 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/rfc2445.ics @@ -0,0 +1,321 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//hacksw/handcal//NONSGML v1.0//EN +BEGIN:VEVENT +DTSTART:19970714T170000Z +DTEND:19970715T035959Z +SUMMARY:Bastille Day Party +END:VEVENT +END:VCALENDAR + +BEGIN:VEVENT +UID:19970901T130000Z-123401@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970903T163000Z +DTEND:19970903T190000Z +SUMMARY:Annual Employee Review +CLASS:PRIVATE +CATEGORIES:BUSINESS,HUMAN RESOURCES +END:VEVENT + +BEGIN:VEVENT +UID:19970901T130000Z-123402@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970401T163000Z +DTEND:19970402T010000Z +SUMMARY:Laurel is in sensitivity awareness class. +CLASS:PUBLIC +CATEGORIES:BUSINESS,HUMAN RESOURCES +TRANSP:TRANSPARENT +END:VEVENT + +BEGIN:VEVENT +UID:19970901T130000Z-123403@host.com +DTSTAMP:19970901T1300Z +DTSTART:19971102 +SUMMARY:Our Blissful Anniversary +CLASS:CONFIDENTIAL +CATEGORIES:ANNIVERSARY,PERSONAL,SPECIAL OCCASION +RRULE:FREQ=YEARLY +END:VEVENT + +BEGIN:VTODO +UID:19970901T130000Z-123404@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970415T133000Z +DUE:19970416T045959Z +SUMMARY:1996 Income Tax Preparation +CLASS:CONFIDENTIAL +CATEGORIES:FAMILY,FINANCE +PRIORITY:1 +STATUS:NEEDS-ACTION +END:VTODO +BEGIN:VJOURNAL +UID:19970901T130000Z-123405@host.com +DTSTAMP:19970901T1300Z +DTSTART;VALUE=DATE:19970317 +SUMMARY:Staff meeting minutes +DESCRIPTION:1. Staff meeting: Participants include Joe\, Lisa + and Bob. Aurora project plans were reviewed. There is currently + no budget reserves for this project. Lisa will escalate to + management. Next meeting on Tuesday.\n + 2. Telephone Conference: ABC Corp. sales representative called + to discuss new printer. Promised to get us a demo by Friday.\n + 3. Henry Miller (Handsoff Insurance): Car was totaled by tree. + Is looking into a loaner car. 654-2323 (tel). +END:VJOURNAL +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jane_doe@host1.com +ATTENDEE:MAILTO:john_public@host2.com +DTSTART:19971015T050000Z +DTEND:19971016T050000Z +DTSTAMP:19970901T083000Z +END:VFREEBUSY +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jane_doe@host1.com +ATTENDEE:MAILTO:john_public@host2.com +DTSTAMP:19970901T100000Z +FREEBUSY;VALUE=PERIOD:19971015T050000Z/PT8H30M, + 19971015T160000Z/PT5H30M,19971015T223000Z/PT6H30M +URL:http://host2.com/pub/busy/jpublic-01.ifb +COMMENT:This iCalendar file contains busy time information for + the next three months. +END:VFREEBUSY +BEGIN:VFREEBUSY +ORGANIZER:jsmith@host.com +DTSTART:19980313T141711Z +DTEND:19980410T141711Z +FREEBUSY:19980314T233000Z/19980315T003000Z +FREEBUSY:19980316T153000Z/19980316T163000Z +FREEBUSY:19980318T030000Z/19980318T040000Z +URL:http://www.host.com/calendar/busytime/jsmith.ifb +END:VFREEBUSY +BEGIN:VTIMEZONE +TZID:US-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTART:19971026T020000 +RDATE:19971026T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19971026T020000 +RDATE:19970406T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US-Eastern +LAST-MODIFIED:19870101T000000Z +TZURL:http://zones.stds_r_us.net/tz/US-Eastern +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US--Fictitious-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T070000Z +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US--Fictitious-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T070000Z +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +BEGIN:DAYLIGHT +DTSTART:19990424T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=4 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VALARM +TRIGGER;VALUE=DATE-TIME:19970317T133000Z +REPEAT:4 +DURATION:PT15M +ACTION:AUDIO +ATTACH;FMTTYPE=audio/basic:ftp://host.com/pub/sounds/bell-01.aud +END:VALARM +BEGIN:VALARM +TRIGGER:-PT30M +REPEAT:2 +DURATION:PT15M +ACTION:DISPLAY +DESCRIPTION:Breakfast meeting with executive\n + team at 8:30 AM EST. +END:VALARM +BEGIN:VALARM +TRIGGER:-P2D +ACTION:EMAIL +ATTENDEE:MAILTO:john_doe@host.com +SUMMARY:*** REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING *** +DESCRIPTION:A draft agenda needs to be sent out to the attendees + to the weekly managers meeting (MGR-LIST). Attached is a + pointer the document template for the agenda file. +ATTACH;FMTTYPE=application/binary:http://host.com/templates/agen + da.doc +END:VALARM +BEGIN:VALARM +TRIGGER;VALUE=DATE-TIME:19980101T050000Z +REPEAT:23 +DURATION:PT1H +ACTION:PROCEDURE +ATTACH;FMTTYPE=application/binary:ftp://host.com/novo- + procs/felizano.exe +END:VALARM +BEGIN:VCALENDAR +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:US-Eastern +BEGIN:STANDARD +DTSTART:19981025T020000 +RDATE:19981025T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19990404T020000 +RDATE:19990404T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +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 +CLASS:PUBLIC +CREATED:19980309T130000Z +SUMMARY:XYZ Project Review +DTSTART;TZID=US-Eastern:19980312T083000 +DTEND;TZID=US-Eastern:19980312T093000 +LOCATION:1CP Conference Room 4350 +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:PUBLISH +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VEVENT +DTSTAMP:19970324T1200Z +SEQUENCE:0 +UID:uid3@host1.com +ORGANIZER:MAILTO:jdoe@host1.com +DTSTART:19970324T123000Z +DTEND:19970324T210000Z +CATEGORIES:MEETING,PROJECT +CLASS:PUBLIC +SUMMARY:Calendaring Interoperability Planning Meeting +DESCRIPTION:Discuss how we can test c&s interoperability\n + using iCalendar and other IETF standards. +LOCATION:LDB Lobby +ATTACH;FMTTYPE=application/postscript:ftp://xyzCorp.com/pub/ + conf/bkgrnd.ps +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VTODO +DTSTAMP:19980130T134500Z +SEQUENCE:2 +UID:uid4@host1.com +ORGANIZER:MAILTO:unclesam@us.gov +ATTENDEE;PARTSTAT=ACCEPTED:MAILTO:jqpublic@host.com +DUE:19980415T235959 +STATUS:NEEDS-ACTION +SUMMARY:Submit Income Taxes +BEGIN:VALARM +ACTION:AUDIO +TRIGGER:19980403T120000 +ATTACH;FMTTYPE=audio/basic:http://host.com/pub/audio- + files/ssbanner.aud +REPEAT:4 +DURATION:PT1H +END:VALARM +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VJOURNAL +DTSTAMP:19970324T120000Z +UID:uid5@host1.com +ORGANIZER:MAILTO:jsmith@host.com +STATUS:DRAFT +CLASS:PUBLIC +CATEGORIES:Project Report, XYZ, Weekly Meeting +DESCRIPTION:Project xyz Review Meeting Minutes\n + Agenda\n1. Review of project version 1.0 requirements.\n2. + Definition + of project processes.\n3. Review of project schedule.\n + Participants: John Smith\, Jane Doe\, Jim Dandy\n-It was + decided that the requirements need to be signed off by + product marketing.\n-Project processes were accepted.\n + -Project schedule needs to account for scheduled holidays + and employee vacation time. Check with HR for specific + dates.\n-New schedule will be distributed by Friday.\n- + Next weeks meeting is cancelled. No meeting until 3/23. +END:VJOURNAL +END:VCALENDAR +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//RDU Software//NONSGML HandCal//EN +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jsmith@host.com +DTSTART:19980313T141711Z +DTEND:19980410T141711Z +FREEBUSY:19980314T233000Z/19980315T003000Z +FREEBUSY:19980316T153000Z/19980316T163000Z +FREEBUSY:19980318T030000Z/19980318T040000Z +URL:http://www.host.com/calendar/busytime/jsmith.ifb +END:VFREEBUSY +END:VCALENDAR diff --git a/libical/src/Net-ICal-Libical/test-data/rfc2446.ics b/libical/src/Net-ICal-Libical/test-data/rfc2446.ics new file mode 100644 index 0000000000..8bf5c7e8f3 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/rfc2446.ics @@ -0,0 +1,1004 @@ + +BEGIN:VCALENDAR +METHOD:PUBLISH +PRODID:-//ACME/DesktopCalendar//EN +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +DTSTART:19970701T200000Z +DTSTAMP:19970611T190000Z +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID:0981234-1234234-23@example.com +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +METHOD:PUBLISH +VERSION:2.0 +PRODID:-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +DTSTAMP:19970612T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SEQUENCE:1 +UID:0981234-1234234-23@example.com +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +METHOD:CANCEL +VERSION:2.0 +PRODID:-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +COMMENT:DUKES forfeit the game +SEQUENCE:2 +UID:0981234-1234234-23@example.com +DTSTAMP:19970613T190000Z +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:PUBLISH +CALSCALE:GREGORIAN +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:America-Chicago +TZURL:http://zones.stds_r_us.net/tz/America-Chicago +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0600 +TZNAME:CST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4 +TZOFFSETFROM:-0600 +TZOFFSETTO:-0500 +TZNAME:CDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +ATTACH:http://www.dukes.com/ +CATEGORIES:SPORTS EVENT,ENTERTAINMENT +CLASS:PRIVATE +DESCRIPTION:MIDWAY STADIUM\n + Big time game. MUST see.\n + Expected duration:2 hours\n +DTEND;TZID=America-Chicago:19970701T180000 +DTSTART;TZID=America-Chicago:19970702T160000 +DTSTAMP:19970614T190000Z +STATUS:CONFIRMED +LOCATION;VALUE=URI:http://www.midwaystadium.com/ +PRIORITY:2 +RESOURCES:SCOREBOARD +SEQUENCE:3 +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID:0981234-1234234-23@example.com +RELATED-TO:0981234-1234234-14@example.com +BEGIN:VALARM +TRIGGER:-PT2H +ACTION:DISPLAY +DESCRIPTION:You should be leaving for the game now. +END:VALARM +BEGIN:VALARM +TRIGGER:-PT30M +ACTION:AUDIO +END:VALARM +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:PUBLISH +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +DTSTAMP:19970614T190000Z +UID:0981234-1234234-23@example.com +DTSTART;VALUE=DATE:19970714 +RRULE:FREQ=YEARLY;INTERVAL=1 +SUMMARY: Bastille Day +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CN=BIG A:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL;CN=B:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL;CN=C:Mailto:C@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL;CN=Hal:Mailto:D@example.com +ATTENDEE;RSVP=FALSE;CUTYPE=ROOM:conf_Big@example.com +ATTENDEE;ROLE=NON-PARTICIPANT;RSVP=FALSE:Mailto:E@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T200000Z +DTEND:19970701T2000000Z +SUMMARY:Conference +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ATTENDEE;PARTSTAT=ACCEPTED:Mailto:B@example.com +ORGANIZER:MAILTO:A@example.com +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +REQUEST-STATUS:2.0;Success +DTSTAMP:19970612T190000Z +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL;CN=Hal:Mailto:D@example.com +ATTENDEE;ROLE=NON-PARTICIPANT;RSVP=FALSE; + CUTYPE=ROOM:Mailto:Conf@example.com +ATTENDEE;ROLE=NON-PARTICIPANT;RSVP=FALSE:Mailto:E@example.com +DTSTART:19970701T180000Z +DTEND:19970701T190000Z +SUMMARY:Phone Conference +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:1 +DTSTAMP:19970613T190000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +DTSTART:19970701T190000Z +DTEND:19970701T200000Z +SUMMARY:Discuss the Merits of the election results +LOCATION:Green Conference Room +UID:calsrv.example.com-873970198738777a@example.com +SEQUENCE:0 +DTSTAMP:19970611T190000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:COUNTER +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +DTSTART:19970701T160000Z +DTEND:19970701T190000Z +DTSTAMP:19970612T190000Z +SUMMARY:Discuss the Merits of the election results +LOCATION:Green Conference Room +COMMENT:This time works much better and I think the big conference + room is too big +UID:calsrv.example.com-873970198738777a@example.com +SEQUENCE:0 +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +DTSTAMP:19970613T190000Z +DTSTART:19970701T160000Z +DTEND:19970701T190000Z +SUMMARY:Discuss the Merits of the election results - changed to + meet B's schedule +LOCATION:Green Conference Room +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:1 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:DECLINECOUNTER +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +COMMENT:Sorry\, I cannot change this meeting time +UID:calsrv.example.com-873970198738777@example.com +DTSTAMP:19970614T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:MAILTO:A@Example.com +ATTENDEE;PARTSTAT=DELEGATED;DELEGATED- + TO="Mailto:E@example.com":Mailto:C@example.com +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +REQUEST-STATUS:2.0;Success +DTSTAMP:19970611T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;PARTSTAT=DELEGATED;DELEGATED- + TO="Mailto:E@example.com":Mailto:C@example.com +ATTENDEE;RSVP=TRUE; + DELEGATED-FROM="Mailto:C@example.com":Mailto:E@example.com +DTSTART:19970701T180000Z +DTEND:19970701T200000Z +SUMMARY:Phone Conference +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +STATUS:CONFIRMED +DTSTAMP:19970611T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:MAILTO:A@Example.com +ATTENDEE;PARTSTAT=ACCEPTED;DELEGATED- + FROM="Mailto:C@example.com":Mailto:E@example.com +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +REQUEST-STATUS:2.0;Success +DTSTAMP:19970614T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:MAILTO:A@Example.com +ATTENDEE;PARTSTAT=DELEGATED; + DELEGATED-TO="Mailto:E@example.com":Mailto:C@example.com +COMMENT:Sorry\, I will be out of town at that time. +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +REQUEST-STATUS:2.0;Success +DTSTAMP:19970614T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:MAILTO:A@Example.com +ATTENDEE;PARTSTAT=DECLINED; + DELEGATED-FROM="Mailto:C@example.com":Mailto:E@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +SUMMARY:Phone Conference +DTSTART:19970701T180000Z +DTEND:19970701T200000Z +DTSTAMP:19970614T200000Z +COMMENT:DELEGATE (ATTENDEE Mailto:E@example.com) DECLINED YOUR + INVITATION +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:CANCEL +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:A@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:D@example.com +COMMENT:Mr. B cannot attend. It's raining. Lets cancel. +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:1 +STATUS:CANCELLED +DTSTAMP:19970613T190000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:CANCEL +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE:mailto:B@example.com +COMMENT:You're off the hook for this meeting +UID:calsrv.example.com-873970198738777@example.com +DTSTAMP:19970613T193000Z +SEQUENCE:1 +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:D@example.com +ATTENDEE;CUTYPE=ROOM:CR_Big@example.com +ATTENDEE;ROLE=NON-PARTICIPANT; + RSVP=FALSE:Mailto:E@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T200000Z +DTEND:19970701T203000Z +SUMMARY:Phone Conference +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:2 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:B@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:B@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:C@example.com +ATTENDEE;CUTYPE=INDIVIDUAL:Mailto:D@example.com +DTSTAMP:19970611T190000Z +DTSTART:19970701T200000Z +DTEND:19970701T203000Z +RRULE:FREQ=WEEKLY +SUMMARY:Phone Conference +UID:123456@example.com +SEQUENCE:1 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +VERSION:2.0 +METHOD:PUBLISH +BEGIN:VFREEBUSY +DTSTAMP:19980101T124100Z +ORGANIZER:MAILTO:A@Example.com +DTSTART:19980101T124200Z +DTEND:19980107T124200Z +FREEBUSY:19980101T180000Z/19980101T190000Z +FREEBUSY:19980103T020000Z/19980103T050000Z +FREEBUSY:19980107T020000Z/19980107T050000Z +FREEBUSY:19980113T000000Z/19980113T010000Z +FREEBUSY:19980115T190000Z/19980115T200000Z +FREEBUSY:19980115T220000Z/19980115T230000Z +FREEBUSY:19980116T013000Z/19980116T043000Z +END:VFREEBUSY +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VFREEBUSY +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +ATTENDEE:Mailto:C@example.com +DTSTAMP:19970613T190000Z +DTSTART:19970701T080000Z +DTEND:19970701T200000 +UID:calsrv.example.com-873970198738777@example.com +END:VFREEBUSY +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:A@example.com +ATTENDEE:Mailto:B@example.com +DTSTART:19970701T080000Z +DTEND:19970701T200000Z +UID:calsrv.example.com-873970198738777@example.com +FREEBUSY:19970701T090000Z/PT1H,19970701T140000Z/PT30M +DTSTAMP:19970613T190030Z +END:VFREEBUSY +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:America-SanJose +TZURL:http://zones.stds_r_us.net/tz/America-SanJose +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0700 +TZOFFSETTO:-0800 +TZNAME:PST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4 +TZOFFSETFROM:-0800 +TZOFFSETTO:-0700 +TZNAME:PDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CUTYPE=INDIVIDUAL:A@example.COM +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:B@example.fr +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:c@example.jp +DTSTAMP:19970613T190030Z +DTSTART;TZID=America-SanJose:19970701T140000 +DTEND;TZID=America-SanJose:19970701T150000 +RRULE:FREQ=WEEKLY;INTERVAL=20;WKST=SU;BYDAY=TU +RDATE;TZID=America-SanJose:19970910T140000 +EXDATE;TZID=America-SanJose:19970909T140000 +EXDATE;TZID=America-SanJose:19971028T140000 +SUMMARY:Weekly Phone Conference +UID:calsrv.example.com-873970198738777@example.com +SEQUENCE:0 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +SEQUENCE:0 +RRULE:FREQ=MONTHLY;BYMONTHDAY=1;UNTIL=19980901T210000Z +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +ATTENDEE:Mailto:C@example.com +ATTENDEE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Conference Call +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970601T210000Z +DTEND:19970601T220000Z +LOCATION:Conference Call +DTSTAMP:19970526T083000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1com +RECURRENCE-ID:19970701T210000Z +SEQUENCE:1 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +ATTENDEE:Mailto:C@example.com +ATTENDEE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Conference Call +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970703T210000Z +DTEND:19970703T220000Z +LOCATION:Conference Call +DTSTAMP:19970626T093000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:CANCEL +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +ATTENDEE:Mailto:C@example.com +ATTENDEE:Mailto:D@example.com +RECURRENCE-ID:19970801T210000Z +SEQUENCE:2 +STATUS:CANCELLED +DTSTAMP:19970721T093000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:CANCEL +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +ATTENDEE:Mailto:C@example.com +ATTENDEE:Mailto:D@example.com +DTSTAMP:19970721T103000Z +STATUS:CANCELLED +SEQUENCE:3 +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +RECURRENCE-ID;RANGE=THISANDFUTURE:19970901T210000Z +SEQUENCE:3 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +ATTENDEE;RSVP=TRUE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Discussion +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970901T210000Z +DTEND:19970901T220000Z +LOCATION:Building 32\, Microsoft\, Seattle\, WA +DTSTAMP:19970526T083000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:ADD +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:4 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +ATTENDEE;RSVP=TRUE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Conference Call +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970715T210000Z +DTEND:19970715T220000Z +LOCATION:Conference Call +DTSTAMP:19970629T093000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:0 +RRULE:FREQ=WEEKLY;WKST=SU;BYDAY=TU +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980303T210000Z +DTEND:19980303T220000Z +LOCATION:The White Room +DTSTAMP:19980301T093000Z +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:ADD +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:7 +RRULE:FREQ=WEEKLY;WKST=SU;BYDAY=TH +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980303T210000Z +DTEND:19980303T220000Z +DTSTAMP:19980303T193000Z +LOCATION:The Usual conference room +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:7 +RRULE:FREQ=WEEKLY;WKST=SU;BYDAY=TU,TH +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980303T210000Z +DTEND:19980303T220000Z +DTSTAMP:19980303T193000Z +LOCATION:The White Room +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:0 +RDATE:19980304T180000Z +RDATE:19980311T180000Z +RDATE:19980318T180000Z +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980304T180000Z +DTEND:19980304T200000Z +DTSTAMP:19980303T193000Z +LOCATION:Conference Room A +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:1 +RECURRENCE-ID:19980311T180000Z +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980311T160000Z +DTEND:19980311T180000Z +DTSTAMP:19980306T193000Z +LOCATION:The Small conference room +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:ADD +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:2 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980315T180000Z +DTEND:19980315T200000Z +DTSTAMP:19980307T193000Z +LOCATION:Conference Room A +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:123456789@host1.com +SEQUENCE:2 +RDATE:19980304T180000Z +RDATE:19980311T160000Z +RDATE:19980315T180000Z +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980304T180000Z +DTEND:19980304T200000Z +DTSTAMP:19980303T193000Z +LOCATION:Conference Room A +STATUS:CONFIRMED +END:VEVENT +BEGIN:VEVENT +SEQUENCE:2 +RECURRENCE-ID:19980311T160000Z +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +SUMMARY:Review Accounts +DTSTART:19980311T160000Z +DTEND:19980304T180000Z +DTSTAMP:19980306T193000Z +ORGANIZER:Mailto:A@example.com +LOCATION:The Small conference room +UID:guid-1@host1.com +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:COUNTER +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +RECURRENCE-ID:19970715T210000Z +SEQUENCE:4 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;RSVP=TRUE:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +ATTENDEE;RSVP=TRUE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Conference Call +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970715T220000Z +DTEND:19970715T230000Z +LOCATION:Conference Call +COMMENT:May we bump this by an hour? I have a conflict +DTSTAMP:19970629T094000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:guid-1@host1.com +SEQUENCE:0 +RRULE:FREQ=MONTHLY;BYMONTHDAY=1 +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +ATTENDEE;RSVP=TRUE:Mailto:D@example.com +DESCRIPTION:IETF-C&S Conference Call +CLASS:PUBLIC +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970601T210000Z +DTEND:19970601T220000Z +DTSTAMP:19970602T094000Z +LOCATION:Conference Call +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//RDU Software//NONSGML HandCal//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +REQUEST-STATUS:2.8;Repeating event ignored. Scheduled as a single + event;RRULE +REQUEST-STATUS:3.0;Invalid Property Name;FOO +UID:guid-1@host1.com +SEQUENCE:0 +DTSTAMP:19970603T094000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR:Mailto:A@example.com +ATTENDEE;RSVP=TRUE:Mailto:B@example.com +ATTENDEE;RSVP=TRUE:Mailto:C@example.com +ATTENDEE;RSVP=TRUE:Mailto:D@example.com +DTSTART:19970701T170000Z +DUE:19970722T170000Z +PRIORITY:1 +SUMMARY:Create the requirements document +UID:calsrv.example.com-873970198738777-00@example.com +SEQUENCE:0 +DTSTAMP:19970717T200000Z +STATUS:Needs Action +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:Mailto:A@example.com +ATTENDEE;PARTSTAT=ACCEPTED:Mailto:B@example.com +UID:calsrv.example.com-873970198738777-00@example.com +COMMENT:I'll send you my input by e-mail +SEQUENCE:0 +DTSTAMP:19970717T203000Z +REQUEST-STATUS:2.0;Success +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:D@example.com +UID:calsrv.example.com-873970198738777-00@example.com +SUMMARY:Create the requirements document +PRIORITY:1 +SEQUENCE:0 +STATUS:IN-PROCESS +DTSTART:19970701T170000Z +DTSTAMP:19970717T230000Z +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:MAILTO:A@example.com +ATTENDEE;PARTSTAT=IN-PROCESS:Mailto:B@example.com +PERCENT-COMPLETE:75 +REQUEST-STATUS:2.0 +UID:calsrv.example.com-873970198738777-00@example.com +DTSTAMP:19970717T233000Z +SEQUENCE:0 +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:MAILTO:A@example.com +ATTENDEE;PARTSTAT=COMPLETED:Mailto:D@example.com +UID:calsrv.example.com-873970198738777-00@example.com +REQUEST-STATUS:2.0 +DTSTAMP:19970717T233000Z +SEQUENCE:0 +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE;PARTSTAT=ACCEPTED;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;PARTSTAT=IN-PROCESS;CUTYPE=INDIVIDUAL:Mailto:D@example.com +DTSTART:19970701T170000Z +DUE:19970722T170000Z +PRIORITY:1 +SUMMARY:Create the requirements document +UID:calsrv.example.com-873970198738777-00@example.com +SEQUENCE:1 +DTSTAMP:19970718T100000Z +STATUS:IN-PROGRESS +PERCENT-COMPLETE:40 +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VTODO +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR:Mailto:A@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:B@example.com +ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL:Mailto:D@example.com +RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR +DTSTART:19980101T100000 +DUE:19980103T100000 +SUMMARY:Send Status Reports to Area Managers +UID:calsrv.example.com-873970198738777-00@example.com +SEQUENCE:0 +DTSTAMP:19970717T200000Z +STATUS:NEEDS-ACTION +PRIORITY:1 +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//ACME/DesktopCalendar//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VTODO +ATTENDEE;PARTSTAT=IN-PROCESS:Mailto:B@example.com +PERCENT-COMPLETE:75 +UID:calsrv.example.com-873970198738777-00@example.com +DTSTAMP:19970717T233000Z +RECURRENCE-ID:19980101T170000Z +SEQUENCE:1 +ORGANIZER:MAILTO:A@Example.com +REQUEST-STATUS:2.0 +END:VTODO +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:PUBLISH +PRODID:-//ACME/DesktopCalendar//EN +VERSION:2.0 +BEGIN:VJOURNAL +DTSTART:19971002T200000Z +DTSTAMP:19971002T200000Z +ORGANIZER:MAILTO:A@Example.com +SUMMARY:Phone conference minutes +DESCRIPTION:The editors meeting was held on October 1\, 1997. + Details are in the attached document. +UID:0981234-1234234-2410@example.com +RELATED-TO:0981234-1234234-2402-35@example.com +ATTACH:ftp://ftp.example.com/pub/ed/minutes100197.txt +END:VJOURNAL +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//RDU Software//NONSGML HandCal//EN +METHOD:REFRESH +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +UID: guid-1-12345@host1.com +DTSTAMP:19970603T094000 +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VEVENT +UID:acme-12345@host1.com +SEQUENCE:3 +RRULE:FREQ=WEEKLY +RDATE;VALUE=PERIOD:19970819T210000Z/199700819T220000Z +ORGANIZER:Mailto:A@example.com +ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +DESCRIPTION:IETF-C&S Conference Call +SUMMARY:IETF Calendaring Working Group Meeting +DTSTART:19970801T210000Z +DTEND:19970801T220000Z +RECURRENCE-ID:19970809T210000Z +DTSTAMP:19970726T083000 +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +PRODID:-//RDU Software//NONSGML HandCal//EN +METHOD:REFRESH +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:Mailto:A@example.com +ATTENDEE:Mailto:B@example.com +UID:acme-12345@host1.com +DTSTAMP:19970603T094000 +END:VEVENT +END:VCALENDAR diff --git a/libical/src/Net-ICal-Libical/test-data/single-with-error b/libical/src/Net-ICal-Libical/test-data/single-with-error new file mode 100644 index 0000000000..6a368d9997 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test-data/single-with-error @@ -0,0 +1,39 @@ +BEGIN:VCALENDAR +PRODID:"-//RDU Software//NONSGML HandCal//EN" +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:US-Eastern +BEGIN:STANDARD +DTSTART:19981025T020000 +RDATE:19981025T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19990404T020000 +RDATE:19990404T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +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 +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:mailto:Employee-B@HOST.com +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MailTo:Eric@Agony.Qualcomm.com +DESCRIPTION:Project XYZ Review Meeting +CATEGORIES:MEETING +CLASS:PUBLIC +CREATED:19980309T130000Z +SUMMARY:XYZ Project Review +DTSTAR;TZID=US-Eastern:19980312T083000 +DTEND;TZID=US-Eastern:19980312T093000 +LOCATION:1CP Conference +Room 4350 +END:VEVENT +END:VCALENDAR + diff --git a/libical/src/Net-ICal-Libical/test/component.pl b/libical/src/Net-ICal-Libical/test/component.pl new file mode 100644 index 0000000000..2fdaf41d65 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test/component.pl @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +use lib "../blib/lib"; +use lib "../blib/arch"; +use lib "../"; + +use Time::Local; + +use Net::ICal::Libical; + +use POSIX; + + + my $comp_str=<<EOM; +BEGIN:VCALENDAR +METHOD + :PUBLISH +PRODID + :-//ACME/DesktopCalendar//EN +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :mailto:a\@example.com +ATTENDEE + ;RSVP=TRUE + ;ROLE=REQ-PARTICIPANT + ;CUTYPE=GROUP + :MAILTO:employee-A\@host.com +DTSTART + :19970701T200000Z +DURATION + :P3DT4H50M36S +DTSTAMP + :19970611T190000Z +SUMMARY + :ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID + :0981234-1234234-23\@example.com +END:VEVENT +END:VCALENDAR +EOM + +my $c; + +$c = new Net::ICal::Libical::Component($comp_str); + +my @props = $c->properties(); + +my $p; +foreach $p (@props) { + print $p->name()." ".$p->value()."\n"; + +} + +$inner = ($c->components())[0]; + +print "\n"; + +print " -------- Attendee \n"; + +$p = ($inner->properties('ATTENDEE'))[0]; + +print $p->as_ical_string(),"\n"; + +print $p->get_parameter('ROLE'),"\n"; + +die if $p->get_parameter('ROLE') ne 'REQ-PARTICIPANT'; + +$p->set_parameter('ROLE','INDIVIDUAL'); + +print $p->as_ical_string(),"\n"; + +print " -------- DTSTART \n"; + +$p = ($inner->properties('DTSTART'))[0]; + +print $p->as_ical_string()."\n"; +print $p->as_ical_string()."\n"; + +print "hour: ". $p->hour()." \n"; + +$p->hour($p->hour() - 10); + +print $p->hour(),"\n"; + +$p->timezone('America/Los_Angeles'); + +print $p->as_ical_string()."\n"; + + +print "----------- DURATION \n"; + +$p = ($inner->properties('DURATION'))[0]; + +print $p->as_ical_string()."\n"; + +print $p->seconds(),"\n"; + +$p->seconds(3630); + +print $p->as_ical_string()."\n"; +print $p->seconds(),"\n"; + + + diff --git a/libical/src/Net-ICal-Libical/test/libical.pl b/libical/src/Net-ICal-Libical/test/libical.pl new file mode 100755 index 0000000000..9499dd9850 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test/libical.pl @@ -0,0 +1,94 @@ +#!/usr/bin/perl + +use lib "../blib/lib"; +use lib "../blib/arch"; +use lib "../"; + +use Time::Local; + +use Net::ICal::Libical; + +use POSIX; + + +my $comp_str=<<EOM; +BEGIN:VCALENDAR +METHOD:PUBLISH +VERSION:2.0 +PRODID:-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER:mailto:a\@example.com +DTSTAMP:19970612T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SEQUENCE:1 +UID:0981234-1234234-23\@example.com +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT +END:VCALENDAR +EOM + +my $comp_str_error=<<EOM; +BEGIN:VCALENDAR +METHOD:REQUEST +VERSION:2.0 +PRODID:-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER:mailto:a\@example.com +DTSTAMP:19970612T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SEQENCE:1 +UID:0981234-1234234-23\@example.com +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT +END:VCALENDAR +EOM + +print "-- Good Component --\n"; +print Net::ICal::Libical::validate_component($comp_str); + +print "-- BadComponent --\n"; +print Net::ICal::Libical::validate_component($comp_str_error); + + +print "-- Generate Occurrences --\n"; +$rule = "FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA"; +$limit = 25; +$start = timelocal(0,0,9,5,8,1997); # 19970905T090000Z + +@occur = Net::ICal::Libical::generate_occurrences($rule,$start,$limit); + +print $rule."\n"; + +foreach $i (@occur){ + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($i); + + printf("%s %s %2d %02d:%02d:%02d %d\n", + (Sun,Mon,Tue,Wed,Thur,Fri,Sat)[$wday], + (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon], + $mday, + $hour,$min,$sec, + $year); + +} + +print "-- Interpret iCal data --\n"; + + +my $comp_str=<<EOM; +BEGIN:VEVENT +ORGANIZER:mailto:a\@example.com +DTSTAMP:19970612T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SEQUENCE:1 +UID:0981234-1234234-23\@example.com +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT + +EOM + + + diff --git a/libical/src/Net-ICal-Libical/test/swig.pl b/libical/src/Net-ICal-Libical/test/swig.pl new file mode 100755 index 0000000000..939f5ce936 --- /dev/null +++ b/libical/src/Net-ICal-Libical/test/swig.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use lib "../blib/lib"; +use lib "../blib/arch"; +use lib "../"; + +use Net::ICal::Libical; + + +my $comp_str=<<EOM; +BEGIN:VCALENDAR +METHOD:PUBLISH +VERSION:2.0 +PRODID:-//ACME/DesktopCalendar//EN +BEGIN:VEVENT +ORGANIZER:mailto:a\@example.com +DTSTAMP:19970612T190000Z +DTSTART:19970701T210000Z +DTEND:19970701T230000Z +SEQUENCE:1 +UID:0981234-1234234-23\@example.com +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +END:VEVENT +END:VCALENDAR +EOM + +$c = Net::ICal::Libical::icalparser_parse_string($comp_str); + +print Net::ICal::Libical::icalcomponent_as_ical_string($c)."\n"; diff --git a/libical/src/java/ICalDurationType.java b/libical/src/java/ICalDurationType.java new file mode 100644 index 0000000000..2dcc23442e --- /dev/null +++ b/libical/src/java/ICalDurationType.java @@ -0,0 +1,114 @@ +/*====================================================================== + FILE: ICalDurationType.java + CREATOR: structConverter 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +/** struct icaldurationtype */ +public class ICalDurationType +{ + /** + * Constructor for pre-existing native icaldurationtype. + * @param obj c++ pointer + */ + ICalDurationType(long obj) + { + init(obj); + } + + /** + * Constructor for default ICalDurationType + */ + public ICalDurationType() + { + } + + public void setIs_neg(int lcl_arg0) + { + is_neg = lcl_arg0; + } + public int getIs_neg() + { + return is_neg; + } + + public void setDays(long lcl_arg0) + { + days = lcl_arg0; + } + public long getDays() + { + return days; + } + + public void setWeeks(long lcl_arg0) + { + weeks = lcl_arg0; + } + public long getWeeks() + { + return weeks; + } + + public void setHours(long lcl_arg0) + { + hours = lcl_arg0; + } + public long getHours() + { + return hours; + } + + public void setMinutes(long lcl_arg0) + { + minutes = lcl_arg0; + } + public long getMinutes() + { + return minutes; + } + + public void setSeconds(long lcl_arg0) + { + seconds = lcl_arg0; + } + public long getSeconds() + { + return seconds; + } + + // -------------------------------------------------------- + // Initialization + // -------------------------------------------------------- + + /** + * native code inits from an existing struct. + */ + private native void init(long aDuration); + + /** + * optimization: init field id cache, + */ + private native static void initFIDs(); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + initFIDs(); + } + + // -------------------------------------------------------- + // Fields + // -------------------------------------------------------- + + private int is_neg; + private long days; // unsigned int + private long weeks; // unsigned int + private long hours; // unsigned int + private long minutes; // unsigned int + private long seconds; // unsigned int +} diff --git a/libical/src/java/ICalParameter.java b/libical/src/java/ICalParameter.java new file mode 100644 index 0000000000..74bf3db84e --- /dev/null +++ b/libical/src/java/ICalParameter.java @@ -0,0 +1,259 @@ +/*====================================================================== + FILE: ICalParameter.java + CREATOR: gnorman 01/09/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class ICalParameter +{ + /** It's not typesafe, but it's simple to understand! */ + public interface ICalParameterKind + { + // icalparameter_kind + int ICAL_ANY_PARAMETER = 0; + int ICAL_ALTREP_PARAMETER = 1; + int ICAL_CN_PARAMETER = 2; + int ICAL_CUTYPE_PARAMETER = 3; + int ICAL_DELEGATEDFROM_PARAMETER = 4; + int ICAL_DELEGATEDTO_PARAMETER = 5; + int ICAL_DIR_PARAMETER = 6; + int ICAL_ENCODING_PARAMETER = 7; + int ICAL_FBTYPE_PARAMETER = 8; + int ICAL_FMTTYPE_PARAMETER = 9; + int ICAL_LANGUAGE_PARAMETER = 10; + int ICAL_MEMBER_PARAMETER = 11; + int ICAL_PARTSTAT_PARAMETER = 12; + int ICAL_RANGE_PARAMETER = 13; + int ICAL_RELATED_PARAMETER = 14; + int ICAL_RELTYPE_PARAMETER = 15; + int ICAL_RIGHTREF_PARAMETER = 16; + int ICAL_ROLE_PARAMETER = 17; + int ICAL_RSVP_PARAMETER = 18; + int ICAL_SENTBY_PARAMETER = 19; + int ICAL_TZID_PARAMETER = 20; + int ICAL_VALUE_PARAMETER = 21; + int ICAL_WKST_PARAMETER = 22; + int ICAL_X_PARAMETER = 23; + int ICAL_XLICCOMPARETYPE_PARAMETER = 24; + int ICAL_XLICERRORTYPE_PARAMETER = 25; + int ICAL_NO_PARAMETER = 26; + } + + /** It's not typesafe, but it's simple to understand! */ + public interface ICalParameterEncoding + { + // icalparameter_encoding + int ICAL_ENCODING_X = 20007; + int ICAL_ENCODING_8BIT = 20008; + int ICAL_ENCODING_BASE64 = 20009; + int ICAL_ENCODING_NONE = 20010; + } + + public interface ICalParameterPartStat { + int ICAL_PARTSTAT_X = 20017; + int ICAL_PARTSTAT_NEEDSACTION = 20018; + int ICAL_PARTSTAT_ACCEPTED = 20019; + int ICAL_PARTSTAT_DECLINED = 20020; + int ICAL_PARTSTAT_TENTATIVE = 20021; + int ICAL_PARTSTAT_DELEGATED = 20022; + int ICAL_PARTSTAT_COMPLETED = 20023; + int ICAL_PARTSTAT_INPROCESS = 20024; + int ICAL_PARTSTAT_NONE = 20025; + } + + public interface ICalParameterRole { + int ICAL_ROLE_X = 20047; + int ICAL_ROLE_CHAIR = 20048; + int ICAL_ROLE_REQPARTICIPANT = 20049; + int ICAL_ROLE_OPTPARTICIPANT = 20050; + int ICAL_ROLE_NONPARTICIPANT = 20051; + int ICAL_ROLE_NONE = 20052; + } + + /** + * Constructor for ICalParameter + * @param obj c++ pointer + */ + private ICalParameter(long obj) + { + init(obj); + } + + /** + * Constructor for ICalParameter + */ + public ICalParameter() + { + init(); + } + + /** + * Create instance from a string of form "PARAMNAME=VALUE" + */ + public ICalParameter(String str) + { + init(str); + } + + /** + * Create from just the value, the part after the "=" + */ + public ICalParameter(/* ICalParameterKind */ int kind, String str) + { + init(kind,str); + } + + /** + * Create empty value for specified kind + */ + public ICalParameter(/* ICalParameterKind */ int kind) + { + init(kind); + } + + /** + * Return ical String representation + */ + public native String as_ical_string(); + + /** + * Return true if this instance is valid + */ + //public native boolean is_valid(); + + /** + * Return what kind of parameter this instance represents + */ + public native /* ICalParameterKind */ int isa(); + + /** + * Return true if this is a parameter + */ + public native boolean isa_parameter(Object parameter); + + /* Convert enumerations */ + //public native static String kind_to_string(/* ICalParameterKind */ int kind); + //public native static /* ICalParameterKind */ int string_to_kind(String str); + + /* DELEGATED-FROM */ + //public native String get_delegatedfrom(); + //public native void set_delegatedfrom(String v); + + /* RELATED */ + //public native icalparameter_related get_related(); + //public native void set_related(icalparameter_related v); + + /* SENT-BY */ + //public native String get_sentby(); + //public native void set_sentby(String v); + + /* LANGUAGE */ + public native String get_language(); + public native void set_language(String v); + + /* RELTYPE */ + //public native icalparameter_reltype get_reltype(); + //public native void set_reltype(icalparameter_reltype v); + + /* ENCODING */ + public native /* ICalParameterEncoding */ int get_encoding(); + public native void set_encoding(/* ICalParameterEncoding */ int v); + + /* ALTREP */ + //public native String get_altrep(); + //public native void set_altrep(String v); + + /* FMTTYPE */ + //public native String get_fmttype(); + //public native void set_fmttype(String v); + + /* FBTYPE */ + //public native icalparameter_fbtype get_fbtype(); + //public native void set_fbtype(icalparameter_fbtype v); + + /* RSVP */ + //public native icalparameter_rsvp get_rsvp(); + //public native void set_rsvp(icalparameter_rsvp v); + + /* RANGE */ + //public native icalparameter_range get_range(); + //public native void set_range(icalparameter_range v); + + /* DELEGATED-TO */ + //public native String get_delegatedto(); + //public native void set_delegatedto(String v); + + /* CN */ + //public native String get_cn(); + //public native void set_cn(String v); + + /* ROLE */ + public native /* ICalParameterRole */ int get_role(); + public native void set_role(/* ICalParameterRole */ int v); + + /* X-LIC-COMPARETYPE */ + //public native icalparameter_xliccomparetype get_xliccomparetype(); + //public native void set_xliccomparetype(icalparameter_xliccomparetype v); + + /* PARTSTAT */ + public native /* ICalParameterPartStat */ int get_partstat(); + public native void set_partstat(/* ICalParameterPartStat */ int v); + + /* X-LIC-ERRORTYPE */ + //public native icalparameter_xlicerrortype get_xlicerrortype(); + //public native void set_xlicerrortype(icalparameter_xlicerrortype v); + + /* MEMBER */ + //public native String get_member(); + //public native void set_member(String v); + + /* X */ + //public native String get_x(); + //public native void set_x(String v); + + /* CUTYPE */ + //public native icalparameter_cutype get_cutype(); + //public native void set_cutype(icalparameter_cutype v); + + /* TZID */ + //public native String get_tzid(); + //public native void set_tzid(String v); + + /* VALUE */ + //public native /* ICalParameterValue */ int get_value(); + //public native void set_value(/* ICalParameterValue */ int v); + + /* DIR */ + //public native String get_dir(); + //public native void set_dir(String v); + + /** + * init the native class + */ + private void init(long obj) + { + m_Obj = obj; + } + + private native void init(); + private native void init(String str); + private native void init(/* ICalParameterKind */ int kind, String str); + private native void init(/* ICalParameterKind */ int kind); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + } + + public static void main(String[] args) + { + System.out.println("*** ICalParameter main called ok."); + } + + /** pointer to C++ object */ + private long m_Obj = 0; +} diff --git a/libical/src/java/ICalPeriodType.java b/libical/src/java/ICalPeriodType.java new file mode 100644 index 0000000000..204ff2a141 --- /dev/null +++ b/libical/src/java/ICalPeriodType.java @@ -0,0 +1,71 @@ +/*====================================================================== + FILE: ICalPeriodType.java + CREATOR: structConverter 01/11/02 +======================================================================*/ + +package net.cp.jlibical; + +public class ICalPeriodType +{ + public ICalPeriodType(long obj) + { + init(obj); + } + + public ICalPeriodType() + { + } + + public ICalPeriodType(long aStart, long aEnd, long aDuration) + { + init(aStart, aEnd, aDuration); + } + + public void setStart(ICalTimeType lcl_arg0) + { + start = lcl_arg0; + } + public ICalTimeType getStart() + { + return start; + } + + public void setEnd(ICalTimeType lcl_arg0) + { + end = lcl_arg0; + } + public ICalTimeType getEnd() + { + return end; + } + + public void setDuration(ICalDurationType lcl_arg0) + { + duration = lcl_arg0; + } + public ICalDurationType getDuration() + { + return duration; + } + + private void init(long aStart, long aEnd, long aDuration) + { + start = new ICalTimeType(aStart); + end = new ICalTimeType(aEnd); + duration = new ICalDurationType(aDuration); + } + + private native void init(long obj); + + private native static void initFIDs(); + + static { + System.loadLibrary("ical_jni"); + initFIDs(); + } + + private ICalTimeType start = new ICalTimeType(); + private ICalTimeType end = new ICalTimeType(); + private ICalDurationType duration = new ICalDurationType(); +} + diff --git a/libical/src/java/ICalProperty.java b/libical/src/java/ICalProperty.java new file mode 100644 index 0000000000..02bb2912f1 --- /dev/null +++ b/libical/src/java/ICalProperty.java @@ -0,0 +1,507 @@ +/*====================================================================== + FILE: ICalProperty.java + CREATOR: gnorman 01/09/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class ICalProperty +{ + /** It's not typesafe, but it's simple to understand! */ + public interface ICalPropertyMethod + { + // icalproperty_method + int ICAL_METHOD_X = 10011; + int ICAL_METHOD_PUBLISH = 10012; + int ICAL_METHOD_REQUEST = 10013; + int ICAL_METHOD_REPLY = 10014; + int ICAL_METHOD_ADD = 10015; + int ICAL_METHOD_CANCEL = 10016; + int ICAL_METHOD_REFRESH = 10017; + int ICAL_METHOD_COUNTER = 10018; + int ICAL_METHOD_DECLINECOUNTER = 10019; + int ICAL_METHOD_CREATE = 10020; + int ICAL_METHOD_READ = 10021; + int ICAL_METHOD_RESPONSE = 10022; + int ICAL_METHOD_MOVE = 10023; + int ICAL_METHOD_MODIFY = 10024; + int ICAL_METHOD_GENERATEUID = 10025; + int ICAL_METHOD_DELETE = 10026; + int ICAL_METHOD_NONE = 10027; + } + + /** It's not typesafe, but it's simple to understand! */ + public interface ICalPropertyAction + { + // icalproperty_action + int ICAL_ACTION_X = 10000; + int ICAL_ACTION_AUDIO = 10001; + int ICAL_ACTION_DISPLAY = 10002; + int ICAL_ACTION_EMAIL = 10003; + int ICAL_ACTION_PROCEDURE = 10004; + int ICAL_ACTION_NONE = 10005; + } + + /** It's not typesafe, but it's simple to understand! */ + public interface ICalPropertyKind + { + // icalproperty_kind + int ICAL_ANY_PROPERTY = 0; + int ICAL_ACTION_PROPERTY=1; + int ICAL_ALLOWCONFLICT_PROPERTY=2; + int ICAL_ATTACH_PROPERTY=3; + int ICAL_ATTENDEE_PROPERTY=4; + int ICAL_CALID_PROPERTY=5; + int ICAL_CALMASTER_PROPERTY=6; + int ICAL_CALSCALE_PROPERTY=7; + int ICAL_CARID_PROPERTY=8; + int ICAL_CATEGORIES_PROPERTY=9; + int ICAL_CLASS_PROPERTY=10; + int ICAL_COMMENT_PROPERTY=11; + int ICAL_COMPLETED_PROPERTY=12; + int ICAL_CONTACT_PROPERTY=13; + int ICAL_CREATED_PROPERTY=14; + int ICAL_DATEFORMAT_PROPERTY=15; + int ICAL_DECREED_PROPERTY=16; + int ICAL_DEFAULTCHARSET_PROPERTY=17; + int ICAL_DEFAULTLOCALE_PROPERTY=18; + int ICAL_DEFAULTTZID_PROPERTY=19; + int ICAL_DESCRIPTION_PROPERTY=20; + int ICAL_DTEND_PROPERTY=21; + int ICAL_DTSTAMP_PROPERTY=22; + int ICAL_DTSTART_PROPERTY=23; + int ICAL_DUE_PROPERTY=24; + int ICAL_DURATION_PROPERTY=25; + int ICAL_EXDATE_PROPERTY=26; + int ICAL_EXPAND_PROPERTY=27; + int ICAL_EXRULE_PROPERTY=28; + int ICAL_FREEBUSY_PROPERTY=29; + int ICAL_GEO_PROPERTY=30; + int ICAL_GRANT_PROPERTY=31; + int ICAL_LASTMODIFIED_PROPERTY=32; + int ICAL_LOCATION_PROPERTY=33; + int ICAL_MAXRESULTS_PROPERTY=34; + int ICAL_MAXRESULTSSIZE_PROPERTY=35; + int ICAL_METHOD_PROPERTY=36; + int ICAL_ORGANIZER_PROPERTY=37; + int ICAL_OWNER_PROPERTY=38; + int ICAL_PERCENTCOMPLETE_PROPERTY=39; + int ICAL_PRIORITY_PROPERTY=40; + int ICAL_PRODID_PROPERTY=41; + int ICAL_QUERY_PROPERTY=42; + int ICAL_QUERYNAME_PROPERTY=43; + int ICAL_RDATE_PROPERTY=44; + int ICAL_RECURRENCEID_PROPERTY=45; + int ICAL_RELATEDTO_PROPERTY=46; + int ICAL_RELCALID_PROPERTY=47; + int ICAL_REPEAT_PROPERTY=48; + int ICAL_REQUESTSTATUS_PROPERTY=49; + int ICAL_RESOURCES_PROPERTY=50; + int ICAL_RRULE_PROPERTY=51; + int ICAL_SCOPE_PROPERTY=52; + int ICAL_SEQUENCE_PROPERTY=53; + int ICAL_STATUS_PROPERTY=54; + int ICAL_SUMMARY_PROPERTY=55; + int ICAL_TARGET_PROPERTY=56; + int ICAL_TIMEFORMAT_PROPERTY=57; + int ICAL_TRANSP_PROPERTY=58; + int ICAL_TRIGGER_PROPERTY=59; + int ICAL_TZID_PROPERTY=60; + int ICAL_TZNAME_PROPERTY=61; + int ICAL_TZOFFSETFROM_PROPERTY=62; + int ICAL_TZOFFSETTO_PROPERTY=63; + int ICAL_TZURL_PROPERTY=64; + int ICAL_UID_PROPERTY=65; + int ICAL_URL_PROPERTY=66; + int ICAL_VERSION_PROPERTY=67; + int ICAL_X_PROPERTY=68; + int ICAL_XLICCLASS_PROPERTY=69; + int ICAL_XLICCLUSTERCOUNT_PROPERTY=70; + int ICAL_XLICERROR_PROPERTY=71; + int ICAL_XLICMIMECHARSET_PROPERTY=72; + int ICAL_XLICMIMECID_PROPERTY=73; + int ICAL_XLICMIMECONTENTTYPE_PROPERTY=74; + int ICAL_XLICMIMEENCODING_PROPERTY=75; + int ICAL_XLICMIMEFILENAME_PROPERTY=76; + int ICAL_XLICMIMEOPTINFO_PROPERTY=77; + int ICAL_NO_PROPERTY=78; + } + + public interface ICalPropertyStatus + { + // icalproperty_status + int ICAL_STATUS_X = 10028; + int ICAL_STATUS_TENTATIVE = 10029; + int ICAL_STATUS_CONFIRMED = 10030; + int ICAL_STATUS_COMPLETED = 10031; + int ICAL_STATUS_NEEDSACTION = 10032; + int ICAL_STATUS_CANCELLED = 10033; + int ICAL_STATUS_INPROCESS = 10034; + int ICAL_STATUS_DRAFT = 10035; + int ICAL_STATUS_FINAL = 10036; + int ICAL_STATUS_NONE = 10037; + } + + /** + * Constructor for ICalProperty + * @param obj c++ pointer + */ + private ICalProperty(long obj) + { + init(obj); + } + + public ICalProperty() + { + init(); + } + + public ICalProperty(String str) + { + init(str); + } + + public ICalProperty(/* ICalPropertyKind */ int kind) + { + init(kind); + } + + public native String as_ical_string(); + public native /* ICalPropertyKind */ int isa(); + public native boolean isa_property(Object property); + + public native void add_parameter(ICalParameter parameter); + public native void set_parameter(ICalParameter parameter); + public native void set_parameter_from_string(String name, String val); + public native String get_parameter_as_string(String name); + public native void remove_parameter(/* ICalParameterKind */ int kind); + public native int count_parameters(); + + /* Iterate through the parameters */ + public native ICalParameter get_first_parameter(/* ICalParameterKind */ int kind); + public native ICalParameter get_next_parameter(/* ICalParameterKind */ int kind); + + /* Access the value of the property */ + public native void set_value(ICalValue val); + public native void set_value_from_string(String val, String kind); + + public native ICalValue get_value(); + public native String get_value_as_string(); + + /* Return the name of the property -- the type name converted to a + String, or the value of get_x_name if the type is X property + */ + public native String get_name(); + + /* Deal with X properties */ + //static void set_x_name(ICalProperty prop, String name); + //static String get_x_name(ICalProperty prop); + + //public native static /* ICalValueKind */ int icalparameter_value_to_value_kind(/* ICalParameterValue */ int val); + + /* Convert kinds to String and get default value type */ + //public native static /* ICalValueKind */ int kind_to_value_kind(/* ICalPropertyKind */ int kind); + //public native static /* ICalValueKind */ int value_kind_to_kind(/* ICalValueKind */ int kind); + //public native static String kind_to_string(/* ICalPropertyKind */ int kind); + //public native static /* ICalPropertyKind */ int string_to_kind(String str); + + //public native static /* ICalPropertyMethod */ int string_to_method(String str); + //public native static String method_to_string(/* ICalPropertyMethod */ int method); + + //public native static String enum_to_string(int e); + //public native static int string_to_enum(String str); + + //public native static String status_to_string(/* ICalPropertyStatus */ int status); + //public native static /* ICalPropertyStatus */ int string_to_status(String str); + + //public native static int enum_belongs_to_property(/* ICalPropertyKind */ int kind, int e); + + /* ACTION */ + public native void set_action(/* ICalPropertyAction */ int v); + public native /* ICalPropertyAction */ int get_action(); + + /* ATTACH */ + //void set_attach(struct icalattachtype v); + //struct icalattachtype get_attach(); + + /* ATTENDEE */ + public native void set_attendee(String val); + public native String get_attendee(); + + /* CALSCALE */ + //public native void set_calscale(String val); + //public native String get_calscale(); + + /* CATEGORIES */ + //public native void set_categories(String val); + //public native String get_categories(); + + /* CLASS */ + //public native void set_class(String val); + //public native String get_class(); + + /* COMMENT */ + public native void set_comment(String val); + public native String get_comment(); + + /* COMPLETED */ + //void set_completed(ICalTimeType val); + //ICalTimeType get_completed(); + + /* CONTACT */ + //public native void set_contact(String val); + //public native String get_contact(); + + /* CREATED */ + //void set_created(ICalTimeType val); + //ICalTimeType get_created(); + + /* DESCRIPTION */ + public native void set_description(String val); + public native String get_description(); + + /* DTEND */ + public native void set_dtend(ICalTimeType val); + public native ICalTimeType get_dtend(); + + /* DTSTAMP */ + public native void set_dtstamp(ICalTimeType val); + public native ICalTimeType get_dtstamp(); + + /* DTSTART */ + public native void set_dtstart(ICalTimeType val); + public native ICalTimeType get_dtstart(); + + /* DUE */ + public native void set_due(ICalTimeType val); + public native ICalTimeType get_due(); + + /* DURATION */ + public native void set_duration(ICalDurationType val); + public native ICalDurationType get_duration(); + + /* EXDATE */ + public native void set_exdate(ICalTimeType val); + public native ICalTimeType get_exdate(); + + /* EXRULE */ + public native void set_exrule(ICalRecurrenceType val); + public native ICalRecurrenceType get_exrule(); + + /* EXPAND */ + public void set_expand(int val) {} // @-@:p0 TMA TODO + public int get_expand() {return 0;} // @-@:p0 TMA TODO + + /* FREEBUSY */ + public native void set_freebusy(ICalPeriodType val); + public native ICalPeriodType get_freebusy(); + + /* GEO */ + //void set_geo(struct icalgeotype val); + //struct icalgeotype get_geo(); + + /* LAST-MODIFIED */ + //void set_lastmodified(ICalTimeType val); + //ICalTimeType get_lastmodified(); + + /* LOCATION */ + public native void set_location(String val); + public native String get_location(); + + /* MAXRESULTS */ + //public native void set_maxresults(int val); + //public native int get_maxresults(); + + /* MAXRESULTSSIZE */ + //public native void set_maxresultsize(int val); + //public native int get_maxresultsize(); + + /* METHOD */ + public native void set_method(/* ICalPropertyMethod */ int val); + public native /* ICalPropertyMethod */ int get_method(); + + /* ORGANIZER */ + public native void set_organizer(String val); + public native String get_organizer(); + + /* OWNER */ + public native void set_owner(String val); + public native String get_owner(); + + /* PERCENT-COMPLETE */ + //void set_percentcomplete(int val); + //int get_percentcomplete(); + + /* PRIORITY */ + //void set_priority(int val); + //int get_priority(); + + /* PRODID */ + public native void set_prodid(String val); + public native String get_prodid(); + + /* QUERY */ + public native void set_query(String val); + public native String get_query(); + + /* QUERYNAME */ + public native void set_queryname(String val); + public native String get_queryname(); + + /* RDATE */ + //void set_rdate(struct icaldatetimeperiodtype val); + //struct icaldatetimeperiodtype get_rdate(); + + /* RECURRENCE-ID */ + public native void set_recurrenceid(ICalTimeType val); + public native ICalTimeType get_recurrenceid(); + + /* RELATED-TO */ + //public native void set_relatedto(String val); + //public native String get_relatedto(); + + /* RELCALID */ + public native void set_relcalid(String val); + public native String get_relcalid(); + + /* REPEAT */ + public native void set_repeat(int val); + public native int get_repeat(); + + /* REQUEST-STATUS */ + //public native void set_requeststatus(String val); + //public native String get_requeststatus(); + + /* RESOURCES */ + //public native void set_resources(String val); + //public native String get_resources(); + + /* RRULE */ + public native void set_rrule(ICalRecurrenceType val); + public native ICalRecurrenceType get_rrule(); + + /* SCOPE */ + //public native void set_scope(String val); + //public native String get_scope(); + + /* SEQUENCE */ + //public native void set_sequence(int val); + //public native int get_sequence(); + + /* STATUS */ + public native void set_status(/* ICalPropertyStatus */ int val); + public native /* ICalPropertyStatus */ int get_status(); + + /* SUMMARY */ + public native void set_summary(String val); + public native String get_summary(); + + /* TARGET */ + public native void set_target(String val); + public native String get_target(); + + /* TRANSP */ + //public native void set_transp(String val); + //public native String get_transp(); + + /* TRIGGER */ + public native void set_trigger(ICalTriggerType val); + public native ICalTriggerType get_trigger(); + + /* TZID */ + public native void set_tzid(String val); + public native String get_tzid(); + + /* TZNAME */ + //public native void set_tzname(String val); + //public native String get_tzname(); + + /* TZOFFSETFROM */ + //public native void set_tzoffsetfrom(int val); + //public native int get_tzoffsetfrom(); + + + /* TZOFFSETTO */ + //public native void set_tzoffsetto(int val); + //public native int get_tzoffsetto(); + + /* TZURL */ + //public native void set_tzurl(String val); + //public native String get_tzurl(); + + /* UID */ + public native void set_uid(String val); + public native String get_uid(); + + /* URL */ + //public native void set_url(String val); + //public native String get_url(); + + /* VERSION */ + //public native void set_version(String val); + //public native String get_version(); + + /* X */ + //void set_x(String val); + //String get_x(); + + /* X-LIC-CLUSTERCOUNT */ + //void set_xlicclustercount(String val); + //String get_xlicclustercount(); + + /* X-LIC-ERROR */ + //void set_xlicerror(String val); + //String get_xlicerror(); + + /* X-LIC-MIMECHARSET */ + //void set_xlicmimecharset(String val); + //String get_xlicmimecharset(); + + /* X-LIC-MIMECID */ + //void set_xlicmimecid(String val); + //String get_xlicmimecid(); + + /* X-LIC-MIMECONTENTTYPE */ + //void set_xlicmimecontenttype(String val); + //String get_xlicmimecontenttype(); + + /* X-LIC-MIMEENCODING */ + //void set_xlicmimeencoding(String val); + //String get_xlicmimeencoding(); + + /* X-LIC-MIMEFILENAME */ + //void set_xlicmimefilename(String val); + //String get_xlicmimefilename(); + + /* X-LIC-MIMEOPTINFO */ + //void set_xlicmimeoptinfo(String val); + //String get_xlicmimeoptinfo(); + + /** + * init the native class + */ + private void init(long obj) + { + m_Obj = obj; + } + + private native void init(); + private native void init(String str); + private native void init(/* ICalPropertyKind */ int kind); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + } + + public static void main(String[] args) + { + System.out.println("*** ICalProperty main called ok."); + } + + /** pointer to C++ object */ + private long m_Obj = 0; +} diff --git a/libical/src/java/ICalRecurrenceType.java b/libical/src/java/ICalRecurrenceType.java new file mode 100644 index 0000000000..cfe27911ab --- /dev/null +++ b/libical/src/java/ICalRecurrenceType.java @@ -0,0 +1,284 @@ +/*====================================================================== + FILE: ICalRecurrenceType.java + CREATOR: structConverter 01/11/02 +======================================================================*/ + +package net.cp.jlibical; + +public class ICalRecurrenceType +{ + public interface ICalRecurrenceTypeFrequency + { + int ICAL_SECONDLY_RECURRENCE=0; + int ICAL_MINUTELY_RECURRENCE=1; + int ICAL_HOURLY_RECURRENCE=2; + int ICAL_DAILY_RECURRENCE=3; + int ICAL_WEEKLY_RECURRENCE=4; + int ICAL_MONTHLY_RECURRENCE=5; + int ICAL_YEARLY_RECURRENCE=6; + int ICAL_NO_RECURRENCE=7; + } + + public interface ICalRecurrenceTypeWeekday + { + int ICAL_NO_WEEKDAY=0; + int ICAL_SUNDAY_WEEKDAY=1; + int ICAL_MONDAY_WEEKDAY=2; + int ICAL_TUESDAY_WEEKDAY=3; + int ICAL_WEDNESDAY_WEEKDAY=4; + int ICAL_THURSDAY_WEEKDAY=5; + int ICAL_FRIDAY_WEEKDAY=6; + int ICAL_SATURDAY_WEEKDAY=7; + } + + ICalRecurrenceType(long obj) + { + init(obj); + } + + public ICalRecurrenceType() + { + } + + public void setUntil(ICalTimeType lcl_arg0) + { + until = lcl_arg0; + } + public ICalTimeType getUntil() + { + return until; + } + + public void setFreq(int lcl_arg0) + { + freq = lcl_arg0; + } + public int getFreq() + { + return freq; + } + + public void setWeek_start(int lcl_arg0) + { + week_start = lcl_arg0; + } + public int getWeek_start() + { + return week_start; + } + + public void setCount(int lcl_arg0) + { + count = lcl_arg0; + } + public int getCount() + { + return count; + } + + public void setInterval(short lcl_arg0) + { + interval = lcl_arg0; + } + public short getInterval() + { + return interval; + } + + public void setBy_second(short[] lcl_arg0) + { + by_second = lcl_arg0; + } + + public void setBy_secondIndexed(int ix,short lcl_arg0) + { + by_second[ix] = lcl_arg0; + } + public short[] getBy_second() + { + return by_second; + } + public short getBy_secondIndexed(int ix) + { + return by_second[ix]; + } + + public void setBy_minute(short[] lcl_arg0) + { + by_minute = lcl_arg0; + } + + public void setBy_minuteIndexed(int ix,short lcl_arg0) + { + by_minute[ix] = lcl_arg0; + } + public short[] getBy_minute() + { + return by_minute; + } + public short getBy_minuteIndexed(int ix) + { + return by_minute[ix]; + } + + public void setBy_hour(short[] lcl_arg0) + { + by_hour = lcl_arg0; + } + + public void setBy_hourIndexed(int ix,short lcl_arg0) + { + by_hour[ix] = lcl_arg0; + } + public short[] getBy_hour() + { + return by_hour; + } + public short getBy_hourIndexed(int ix) + { + return by_hour[ix]; + } + + public void setBy_day(short[] lcl_arg0) + { + by_day = lcl_arg0; + } + + public void setBy_dayIndexed(int ix,short lcl_arg0) + { + by_day[ix] = lcl_arg0; + } + public short[] getBy_day() + { + return by_day; + } + public short getBy_dayIndexed(int ix) + { + return by_day[ix]; + } + + public void setBy_month_day(short[] lcl_arg0) + { + by_month_day = lcl_arg0; + } + + public void setBy_month_dayIndexed(int ix,short lcl_arg0) + { + by_month_day[ix] = lcl_arg0; + } + public short[] getBy_month_day() + { + return by_month_day; + } + public short getBy_month_dayIndexed(int ix) + { + return by_month_day[ix]; + } + + public void setBy_year_day(short[] lcl_arg0) + { + by_year_day = lcl_arg0; + } + + public void setBy_year_dayIndexed(int ix,short lcl_arg0) + { + by_year_day[ix] = lcl_arg0; + } + public short[] getBy_year_day() + { + return by_year_day; + } + public short getBy_year_dayIndexed(int ix) + { + return by_year_day[ix]; + } + + public void setBy_week_no(short[] lcl_arg0) + { + by_week_no = lcl_arg0; + } + + public void setBy_week_noIndexed(int ix,short lcl_arg0) + { + by_week_no[ix] = lcl_arg0; + } + public short[] getBy_week_no() + { + return by_week_no; + } + public short getBy_week_noIndexed(int ix) + { + return by_week_no[ix]; + } + + public void setBy_month(short[] lcl_arg0) + { + by_month = lcl_arg0; + } + + public void setBy_monthIndexed(int ix,short lcl_arg0) + { + by_month[ix] = lcl_arg0; + } + public short[] getBy_month() + { + return by_month; + } + public short getBy_monthIndexed(int ix) + { + return by_month[ix]; + } + + public void setBy_set_pos(short[] lcl_arg0) + { + by_set_pos = lcl_arg0; + } + + public void setBy_set_posIndexed(int ix,short lcl_arg0) + { + by_set_pos[ix] = lcl_arg0; + } + public short[] getBy_set_pos() + { + return by_set_pos; + } + public short getBy_set_posIndexed(int ix) + { + return by_set_pos[ix]; + } + + private native void init(long obj); + + private native static void initFIDs(); + + static { + System.loadLibrary("ical_jni"); + initFIDs(); + } + + private /* ICalRecurrenceTypeFrequency */ int freq; + private /* ICalRecurrenceTypeWeekday */ int week_start; + private int count; + private short interval; + private short[] by_second = new short[ICAL_BY_SECOND_SIZE]; // Converted from short[61] + private short[] by_minute = new short[ICAL_BY_MINUTE_SIZE]; // Converted from short[61] + private short[] by_hour = new short[ICAL_BY_HOUR_SIZE]; // Converted from short[25] + private short[] by_day = new short[ICAL_BY_DAY_SIZE]; // Converted from short[364] + private short[] by_month_day = new short[ICAL_BY_MONTHDAY_SIZE]; // Converted from short[32] + private short[] by_year_day = new short[ICAL_BY_YEARDAY_SIZE]; // Converted from short[367] + private short[] by_week_no = new short[ICAL_BY_WEEKNO_SIZE]; // Converted from short[54] + private short[] by_month = new short[ICAL_BY_MONTH_SIZE]; // Converted from short[13] + private short[] by_set_pos = new short[ICAL_BY_SETPOS_SIZE]; // Converted from short[367] + private ICalTimeType until = new ICalTimeType(); + + public static final int ICAL_BY_SECOND_SIZE = 61; + public static final int ICAL_BY_MINUTE_SIZE = 61; + public static final int ICAL_BY_HOUR_SIZE = 25; + public static final int ICAL_BY_DAY_SIZE = 364; + public static final int ICAL_BY_MONTHDAY_SIZE = 32; + public static final int ICAL_BY_YEARDAY_SIZE = 367; + public static final int ICAL_BY_WEEKNO_SIZE = 54; + public static final int ICAL_BY_MONTH_SIZE = 13; + public static final int ICAL_BY_SETPOS_SIZE = 367; +} + diff --git a/libical/src/java/ICalTimeType.java b/libical/src/java/ICalTimeType.java new file mode 100644 index 0000000000..cf4ee40747 --- /dev/null +++ b/libical/src/java/ICalTimeType.java @@ -0,0 +1,145 @@ +/*====================================================================== + FILE: ICalTimeType.java + CREATOR: structConverter 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +/** struct icaltimetype */ +public class ICalTimeType +{ + /** + * Constructor for pre-existing native icaltimetype + * @param obj c++ pointer + */ + ICalTimeType(long obj) + { + init(obj); + } + + /** + * Constructor for default ICalTimeType + */ + public ICalTimeType() + { + } + + public void setYear(int lcl_arg0) + { + year = lcl_arg0; + } + public int getYear() + { + return year; + } + + public void setMonth(int lcl_arg0) + { + month = lcl_arg0; + } + public int getMonth() + { + return month; + } + + public void setDay(int lcl_arg0) + { + day = lcl_arg0; + } + public int getDay() + { + return day; + } + + public void setHour(int lcl_arg0) + { + hour = lcl_arg0; + } + public int getHour() + { + return hour; + } + + public void setMinute(int lcl_arg0) + { + minute = lcl_arg0; + } + public int getMinute() + { + return minute; + } + + public void setSecond(int lcl_arg0) + { + second = lcl_arg0; + } + public int getSecond() + { + return second; + } + + public void setIs_utc(boolean lcl_arg0) + { + is_utc = lcl_arg0 ? 1 : 0; + } + public boolean getIs_utc() + { + return is_utc == 0 ? false : true; + } + + public void setIs_date(boolean lcl_arg0) + { + is_date = lcl_arg0 ? 1 : 0; + } + public boolean getIs_date() + { + return is_date == 0 ? false : true; + } + + public void setZone(String lcl_arg0) + { + zone = lcl_arg0; + } + public String getZone() + { + return zone; + } + + // -------------------------------------------------------- + // Initialization + // -------------------------------------------------------- + + /** + * copy data from an existing struct. + */ + private native void init(long obj); + + /** + * optimization: init field id cache, + */ + private native static void initFIDs(); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + initFIDs(); + } + + // -------------------------------------------------------- + // Fields + // -------------------------------------------------------- + + private int month; + private int day; + private int year; + private int hour; + private int minute; + private int second; + private int is_utc; + private int is_date; + private String zone = new String(); // Converted from char* +} + diff --git a/libical/src/java/ICalTriggerType.java b/libical/src/java/ICalTriggerType.java new file mode 100644 index 0000000000..e2ef7a72e0 --- /dev/null +++ b/libical/src/java/ICalTriggerType.java @@ -0,0 +1,93 @@ +/*====================================================================== + FILE: ICalTriggerType.java + CREATOR: structConverter 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +/** struct icaltriggertype */ +public class ICalTriggerType +{ + /** + * Constructor for pre-existing native icaltriggertype + * @param obj c++ pointer + */ + ICalTriggerType(long obj) + { + init(obj); + } + + /** + * Constructor for pre-existing native icaltriggertype + * @param aTime c++ pointer + * @param aDuration c++ pointer + */ + ICalTriggerType(long aTime, long aDuration) + { + init(aTime, aDuration); + } + + /** + * Constructor for default ICalTriggerType + */ + public ICalTriggerType() + { + } + + public void setTime(ICalTimeType lcl_arg0) + { + time = lcl_arg0; + } + public ICalTimeType getTime() + { + return time; + } + + public void setDuration(ICalDurationType lcl_arg0) + { + duration = lcl_arg0; + } + public ICalDurationType getDuration() + { + return duration; + } + + // -------------------------------------------------------- + // Initialization + // -------------------------------------------------------- + + /** + * init with a native object + */ + private void init(long aTime, long aDuration) + { + time = new ICalTimeType(aTime); + duration = new ICalDurationType(aDuration); + } + + /** + * copy data from an existing struct. + */ + private native void init(long obj); + + /** + * optimization: init field id cache, + */ + private native static void initFIDs(); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + initFIDs(); + } + + // -------------------------------------------------------- + // Fields + // -------------------------------------------------------- + private ICalTimeType time = new ICalTimeType(); + private ICalDurationType duration = new ICalDurationType(); +} + diff --git a/libical/src/java/ICalValue.java b/libical/src/java/ICalValue.java new file mode 100644 index 0000000000..dbe2b8aeee --- /dev/null +++ b/libical/src/java/ICalValue.java @@ -0,0 +1,209 @@ +/*====================================================================== + FILE: ICalValue.java + CREATOR: gnorman 01/10/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class ICalValue +{ + /** It's not typesafe, but it's simple to understand! */ + public interface ICalValueKind + { + // icalvalue_kind + int ICAL_ANY_VALUE=5000; + int ICAL_BOOLEAN_VALUE=5001; + int ICAL_UTCOFFSET_VALUE=5002; + int ICAL_RECUR_VALUE=5003; + int ICAL_METHOD_VALUE=5004; + int ICAL_CALADDRESS_VALUE=5005; + int ICAL_PERIOD_VALUE=5006; + int ICAL_STATUS_VALUE=5007; + int ICAL_BINARY_VALUE=5008; + int ICAL_TEXT_VALUE=5009; + int ICAL_DATETIMEDATE_VALUE=5010; + int ICAL_DURATION_VALUE=5011; + int ICAL_DATETIMEPERIOD_VALUE=5012; + int ICAL_INTEGER_VALUE=5013; + int ICAL_TIME_VALUE=5014; + int ICAL_URI_VALUE=5015; + int ICAL_TRIGGER_VALUE=5016; + int ICAL_ATTACH_VALUE=5017; + int ICAL_CLASS_VALUE=5018; + int ICAL_FLOAT_VALUE=5019; + int ICAL_QUERY_VALUE=5020; + int ICAL_STRING_VALUE=5021; + int ICAL_TRANSP_VALUE=5022; + int ICAL_X_VALUE=5023; + int ICAL_DATETIME_VALUE=5024; + int ICAL_GEO_VALUE=5025; + int ICAL_DATE_VALUE=5026; + int ICAL_ACTION_VALUE=5027; + int ICAL_NO_VALUE=5028; + } + + /** + * Constructor for ICalValue + * @param obj c++ pointer + */ + private ICalValue(long obj) + { + init(obj); + } + + public ICalValue() + { + init(); + } + + public ICalValue(/* ICalValueKind */ int kind) + { + init(kind); + } + + public ICalValue(/* ICalValueKind */ int kind, String str) + { + init(kind,str); + } + + public native String as_ical_string(); + //public native boolean is_valid(); + public native /* ICalValueKind */ int isa(); + public native boolean isa_value(Object value); + + /* Special, non autogenerated value accessors */ + //void set_recur(struct icalrecurrencetype v); + //struct icalrecurrencetype get_recur(); + + public native void set_trigger(ICalTriggerType v); + public native ICalTriggerType get_trigger(); + + //void set_datetimeperiod(struct icaldatetimeperiodtype v); + //struct icaldatetimeperiodtype get_datetimeperiod(); + + //public native static /* ICalParameterXLicCompareType */ int compare(ICalValue a, ICalValue b); + + /* Convert enumerations */ + //public native static /* ICalValueKind */ int string_to_kind(String str); + //public native String kind_to_string(/* ICalValueKind */ int kind); + + /* BOOLEAN */ + //public native int get_boolean(); + //public native void set_boolean(int v); + + /* UTC-OFFSET */ + //public native int get_utcoffset(); + //public native void set_utcoffset(int v); + + /* METHOD */ + public native /* ICalPropertyMethod */ int get_method(); + public native void set_method(/* ICalPropertyMethod */ int v); + + /* CAL-ADDRESS */ + //public native String get_caladdress(); + //public native void set_caladdress(String v); + + /* PERIOD */ + //struct icalperiodtype get_period(); + //void set_period(struct icalperiodtype v); + + /* STATUS */ + //public native /* ICalPropertyStatus */ int get_status(); + //public native void set_status(/* ICalPropertyStatus */ int v); + + /* BINARY */ + //public native String get_binary(); + //public native void set_binary(String v); + + /* TEXT */ + public native String get_text(); + public native void set_text(String v); + + /* DATE-TIME-DATE */ + //ICalTimeType get_datetimedate(); + //void set_datetimedate(ICalTimeType v); + + /* DURATION */ + public native ICalDurationType get_duration(); + public native void set_duration(ICalDurationType v); + + /* INTEGER */ + //public native int get_integer(); + //public native void set_integer(int v); + + /* TIME */ + //ICalTimeType get_time(); + //void set_time(ICalTimeType v); + + /* URI */ + //public native String get_uri(); + //public native void set_uri(String v); + + /* ATTACH */ + //struct icalattachtype get_attach(); + //void set_attach(struct icalattachtype v); + + /* CLASS */ + //public native /* ICalPropertyClass */ int get_class(); + //public native void set_class(/* ICalPropertyClass */ int v); + + /* FLOAT */ + //public native float get_float(); + //public native void set_float(float v); + + /* QUERY */ + public native String get_query(); + public native void set_query(String v); + + /* STRING */ + //public native String get_string(); + //public native void set_string(String v); + + /* TRANSP */ + //public native /* ICalPropertyTransp */ int get_transp(); + //public native void set_transp(/* ICalPropertyTransp */ int v); + + /* DATE-TIME */ + public native ICalTimeType get_datetime(); + public native void set_datetime(ICalTimeType v); + + /* GEO */ + //struct icalgeotype get_geo(); + //void set_geo(struct icalgeotype v); + + /* DATE */ + //ICalTimeType get_date(); + //void set_date(ICalTimeType v); + + /* ACTION */ + public native /* ICalPropertyAction */ int get_action(); + public native void set_action(/* ICalPropertyAction */ int v); + + /** + * init the native class + */ + private void init(long obj) + { + m_Obj = obj; + } + + private native void init(); + private native void init(/* ICalValueKind */ int kind, String str); + private native void init(/* ICalValueKind */ int kind); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + } + + public static void main(String[] args) + { + System.out.println("*** ICalValue main called ok."); + } + + /** pointer to C++ object */ + private long m_Obj = 0; +} diff --git a/libical/src/java/Makefile.am b/libical/src/java/Makefile.am new file mode 100644 index 0000000000..6105b7ae5b --- /dev/null +++ b/libical/src/java/Makefile.am @@ -0,0 +1,51 @@ +lib_LTLIBRARIES = libical_jni.la + +INCLUDES = -I../libical -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(JAVA_PLATFORM) + +libical_jni_la_LDFLAGS = -no-defined -version-info 0:0:0 + +libical_jni_la_LIBADD = \ + ../libical/libical_cxx.la + +libical_jni_la_SOURCES = \ + jlibical_consts_cxx.h \ + jlibical_utils_cxx.cpp \ + jlibical_utils_cxx.h \ + jniICalDurationType_cxx.cpp \ + jniICalDurationType_cxx.h \ + jniICalPeriodType_cxx.cpp \ + jniICalPeriodType_cxx.h \ + jniICalRecurrenceType_cxx.cpp \ + jniICalRecurrenceType_cxx.h \ + jniICalTimeType_cxx.cpp \ + jniICalTimeType_cxx.h \ + jniICalTriggerType_cxx.cpp \ + jniICalTriggerType_cxx.h \ + net_cp_jlibical_ICalParameter_cxx.cpp \ + net_cp_jlibical_ICalParameter_cxx.h \ + net_cp_jlibical_ICalProperty_cxx.cpp \ + net_cp_jlibical_ICalProperty_cxx.h \ + net_cp_jlibical_ICalValue_cxx.cpp \ + net_cp_jlibical_ICalValue_cxx.h \ + net_cp_jlibical_VComponent_cxx.cpp \ + net_cp_jlibical_VComponent_cxx.h + +java_JAVA=\ +ICalDurationType.java ICalTriggerType.java VEvent.java\ +ICalParameter.java ICalValue.java VFreeBusy.java\ +ICalPeriodType.java VAgenda.java VQuery.java\ +ICalProperty.java VAlarm.java VToDo.java\ +ICalRecurrenceType.java VCalendar.java \ +ICalTimeType.java VComponent.java + +data_DATA = libical.jar + +libical.jar: classjava.stamp + (cd $(top_builddir); $(JAR) cf src/java/libical.jar net) + +jlibical_jniincludedir = $(includedir) + +TESTS = testjni.sh + +testjni.sh: + echo "$(JAVA) -Djava.library.path=@prefix@/lib -classpath $(JAVA_HOME)/lib/classes.zip:@prefix@/lib/libical.jar net.cp.jlibical.testjni" > testjni.sh && chmod a+x testjni.sh diff --git a/libical/src/java/VAgenda.java b/libical/src/java/VAgenda.java new file mode 100644 index 0000000000..8b85fe11c2 --- /dev/null +++ b/libical/src/java/VAgenda.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VAgenda.java + CREATOR: fnguyen 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VAgenda extends VComponent { + public VAgenda() + { + super(ICalComponentKind.ICAL_VAGENDA_COMPONENT); + } + + public VAgenda(long obj) + { + super(obj); + } + + public VAgenda(String str) + { + super(str); + } +} diff --git a/libical/src/java/VAlarm.java b/libical/src/java/VAlarm.java new file mode 100644 index 0000000000..d7693f7622 --- /dev/null +++ b/libical/src/java/VAlarm.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VAlarm.java + CREATOR: fnguyen 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VAlarm extends VComponent { + public VAlarm() + { + super(ICalComponentKind.ICAL_VALARM_COMPONENT); + } + + public VAlarm(long obj) + { + super(obj); + } + + public VAlarm(String str) + { + super(str); + } +} diff --git a/libical/src/java/VCalendar.java b/libical/src/java/VCalendar.java new file mode 100644 index 0000000000..4cfcad2709 --- /dev/null +++ b/libical/src/java/VCalendar.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VCalendar.java + CREATOR: echoi 01/28/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VCalendar extends VComponent { + public VCalendar() + { + super(ICalComponentKind.ICAL_VCALENDAR_COMPONENT); + } + + public VCalendar(long obj) + { + super(obj); + } + + public VCalendar(String str) + { + super(str); + } +} diff --git a/libical/src/java/VComponent.java b/libical/src/java/VComponent.java new file mode 100644 index 0000000000..70c5915c91 --- /dev/null +++ b/libical/src/java/VComponent.java @@ -0,0 +1,199 @@ +/*====================================================================== + FILE: VComponent.java + CREATOR: gnorman 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VComponent +{ + /** It's not typesafe, but it's simple to understand! */ + public interface ICalComponentKind + { + // icalcomponent_kind + int ICAL_NO_COMPONENT = 0; + int ICAL_ANY_COMPONENT = 1; + int ICAL_XROOT_COMPONENT = 2; + int ICAL_XATTACH_COMPONENT = 3; + int ICAL_VEVENT_COMPONENT = 4; + int ICAL_VTODO_COMPONENT = 5; + int ICAL_VJOURNAL_COMPONENT = 6; + int ICAL_VCALENDAR_COMPONENT = 7; + int ICAL_VAGENDA_COMPONENT = 8; + int ICAL_VFREEBUSY_COMPONENT = 9; + int ICAL_VALARM_COMPONENT = 10; + int ICAL_XAUDIOALARM_COMPONENT = 11; + int ICAL_XDISPLAYALARM_COMPONENT = 12; + int ICAL_XEMAILALARM_COMPONENT = 13; + int ICAL_XPROCEDUREALARM_COMPONENT = 14; + int ICAL_VTIMEZONE_COMPONENT = 15; + int ICAL_XSTANDARD_COMPONENT = 16; + int ICAL_XDAYLIGHT_COMPONENT = 17; + int ICAL_X_COMPONENT = 18; + int ICAL_VSCHEDULE_COMPONENT = 19; + int ICAL_VQUERY_COMPONENT = 20; + int ICAL_VCOMMAND_COMPONENT = 21; + int ICAL_XLICINVALID_COMPONENT = 22; + int ICAL_XLICMIMEPART_COMPONENT = 23; + int ICAL_XPREFERENCES_COMPONENT = 24; + } + + /** + * Constructor for VComponent + * @param obj c++ pointer + */ + protected VComponent(long obj) + { + init(obj); + } + + public VComponent() + { + init(); + } + + public VComponent(/* ICalComponentKind */ int kind) + { + init(kind); + } + + public VComponent(String str) + { + init(str); + } + + public native String as_ical_string(); + //public native boolean is_valid(); + public native /* ICalComponentKind */ int isa(); + public native boolean isa_component(Object component); + + /* Working with properties */ + public native void add_property(ICalProperty property); + public native void remove_property(ICalProperty property); + public native int count_properties(/* ICalPropertyKind */ int kind); + + /* Iterate through the properties */ + public native ICalProperty get_current_property(); + public native ICalProperty get_first_property(/* ICalPropertyKind */ int kind); + public native ICalProperty get_next_property(/* ICalPropertyKind */ int kind); + + /* Working with components */ + + /* Return the first VEVENT, VTODO or VJOURNAL sub-component if it is one of those types */ + public native VComponent get_inner(); + + public native void add_component(VComponent child); + public native void remove_component(VComponent child); + public native int count_components(/* ICalComponentKind */ int kind); + + /* Iteration Routines. There are two forms of iterators, internal and + external. The internal ones came first, and are almost completely + sufficient, but they fail badly when you want to construct a loop that + removes components from the container. + */ + + /* Iterate through components */ + public native VComponent get_current_component(); + public native VComponent get_first_component(/* ICalComponentKind */ int kind); + public native VComponent get_next_component(/* ICalComponentKind */ int kind); + + /* Using external iterators */ + //public native icalcompiter begin_component(/* ICalComponentKind */ int kind); + //public native icalcompiter end_component(/* ICalComponentKind */ int kind); + //public native VComponent next(icalcompiter i); + //public native VComponent prev(icalcompiter i); + //public native VComponent current(icalcompiter i); + + /* Working with embedded error properties */ + //public native int count_errors(); + + /* Remove all X-LIC-ERROR properties*/ + //public native void strip_errors(); + + /* Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/ + //public native void convert_errors(); + + /* Kind conversion routines */ + //public native static /* ICalComponentKind */ int string_to_kind(String str); + //public native static String kind_to_string(/* ICalComponentKind */ int kind); + + public native ICalTimeType get_dtstart(); + public native void set_dtstart(ICalTimeType v); + + /* For the icalcomponent routines only, dtend and duration are tied + together. If you call the set routine for one and the other exists, + the routine will calculate the change to the other. That is, if + there is a DTEND and you call set_duration, the routine will modify + DTEND to be the sum of DTSTART and the duration. If you call a get + routine for one and the other exists, the routine will calculate + the return value. If you call a set routine and neither exists, the + routine will create the apcompriate comperty */ + + public native ICalTimeType get_dtend(); + public native void set_dtend(ICalTimeType v); + + public native ICalDurationType get_duration(); + public native void set_duration(ICalDurationType v); + + public native /* ICalPropertyMethod */ int get_method(); + public native void set_method(/* ICalPropertyMethod */ int method); + + public native ICalTimeType get_dtstamp(); + public native void set_dtstamp(ICalTimeType v); + + public native String get_summary(); + public native void set_summary(String v); + + public native String get_location(); + public native void set_location(String v); + + public native String get_description(); + public native void set_description(String v); + + //public native String get_comment(); + //public native void set_comment(String v); + + public native String get_uid(); + public native void set_uid(String v); + + public native String get_relcalid(); + public native void set_relcalid(String v); + + public native ICalTimeType get_recurrenceid(); + public native void set_recurrenceid(ICalTimeType v); + + /* For VCOMPONENT: Return a reference to the first VEVENT, VTODO, or VJOURNAL */ + public native VComponent get_first_real_component(); + + /* For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the start and end + times of an event in UTC */ + //public native virtual struct icaltime_span get_span(); + + /** + * init the native class + */ + private void init(long obj) + { + m_Obj = obj; + } + + private native void init(); + private native void init(String str); + private native void init(/* ICalComponentKind */ int kind); + + /** + * load the jni library for this class + */ + static { + System.loadLibrary("ical_jni"); + } + + public static void main(String[] args) + { + System.out.println("*** VComponent main called ok."); + } + + /** pointer to C++ object */ + private long m_Obj = 0; +} diff --git a/libical/src/java/VEvent.java b/libical/src/java/VEvent.java new file mode 100644 index 0000000000..2017aa58ce --- /dev/null +++ b/libical/src/java/VEvent.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VEvent.java + CREATOR: fnguyen 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VEvent extends VComponent { + public VEvent() + { + super(ICalComponentKind.ICAL_VEVENT_COMPONENT); + } + + public VEvent(long obj) + { + super(obj); + } + + public VEvent(String str) + { + super(str); + } +} diff --git a/libical/src/java/VFreeBusy.java b/libical/src/java/VFreeBusy.java new file mode 100644 index 0000000000..a781edc59a --- /dev/null +++ b/libical/src/java/VFreeBusy.java @@ -0,0 +1,18 @@ +package net.cp.jlibical; + +public class VFreeBusy extends VComponent { + public VFreeBusy() + { + super(ICalComponentKind.ICAL_VFREEBUSY_COMPONENT); + } + + public VFreeBusy(long obj) + { + super(obj); + } + + public VFreeBusy(String str) + { + super(str); + } +} diff --git a/libical/src/java/VQuery.java b/libical/src/java/VQuery.java new file mode 100644 index 0000000000..e94a07327e --- /dev/null +++ b/libical/src/java/VQuery.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VQuery.java + CREATOR: fnguyen 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VQuery extends VComponent { + public VQuery() + { + super(ICalComponentKind.ICAL_VQUERY_COMPONENT); + } + + public VQuery(long obj) + { + super(obj); + } + + public VQuery(String str) + { + super(str); + } +} diff --git a/libical/src/java/VToDo.java b/libical/src/java/VToDo.java new file mode 100644 index 0000000000..9e4a06e1f0 --- /dev/null +++ b/libical/src/java/VToDo.java @@ -0,0 +1,24 @@ +/*====================================================================== + FILE: VToDo.java + CREATOR: fnguyen 01/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +package net.cp.jlibical; + +public class VToDo extends VComponent { + public VToDo() + { + super(ICalComponentKind.ICAL_VTODO_COMPONENT); + } + + public VToDo(long obj) + { + super(obj); + } + + public VToDo(String str) + { + super(str); + } +} diff --git a/libical/src/java/jlibical_consts_cxx.h b/libical/src/java/jlibical_consts_cxx.h new file mode 100644 index 0000000000..2cdf1f8b5a --- /dev/null +++ b/libical/src/java/jlibical_consts_cxx.h @@ -0,0 +1,42 @@ + +/*====================================================================== + FILE: jlibical_consts_cxx/h + CREATOR: Srinivasa Boppana/George Norman + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef JLIBICAL_CONSTS_CXX_H +#define JLIBICAL_CONSTS_CXX_H + +/* + * Error code constants. + */ +#define JLIBICAL_OK 0 /* good return code */ + +/* system/API errors */ +#define JLIBICAL_ERR_NETWORK 100 /* general network error */ +#define JLIBICAL_ERR_SERVER_INTERNAL 101 /* internal server error (database, file system, etc.) */ +#define JLIBICAL_ERR_CLIENT_INTERNAL 102 /* internal error in client API (memory, parsing errors, etc.)*/ +#define JLIBICAL_ERR_ILLEGAL_ARGUMENT 103 /* incorrect API use */ +#define JLIBICAL_ERR_API_NOT_INITED 104 /* either the InitModule API call was called prior to use of the API or it failed to initialize correctly */ +#define JLIBICAL_ERR_HOST_INVALID 105 /* the host name specified cannot be resolved */ + +/* Java classes */ +#define JLIBICAL_CLASS_ICALVALUE "net/cp/jlibical/ICalValue" +#define JLIBICAL_CLASS_VCOMPONENT "net/cp/jlibical/VComponent" +#define JLIBICAL_CLASS_VALARM "net/cp/jlibical/VAlarm" +#define JLIBICAL_CLASS_VCALENDAR "net/cp/jlibical/VCalendar" +#define JLIBICAL_CLASS_VAGENDA "net/cp/jlibical/VAgenda" +#define JLIBICAL_CLASS_VEVENT "net/cp/jlibical/VEvent" +#define JLIBICAL_CLASS_VQUERY "net/cp/jlibical/VQuery" +#define JLIBICAL_CLASS_VTODO "net/cp/jlibical/VToDo" +#define JLIBICAL_CLASS_ICALPARAMETER "net/cp/jlibical/ICalParameter" +#define JLIBICAL_CLASS_ICALPROPERTY "net/cp/jlibical/ICalProperty" + +#define JLIBICAL_CLASS_ICALDURATIONTYPE "net/cp/jlibical/ICalDurationType" +#define JLIBICAL_CLASS_ICALTIMETYPE "net/cp/jlibical/ICalTimeType" +#define JLIBICAL_CLASS_ICALTRIGGERTYPE "net/cp/jlibical/ICalTriggerType" +#define JLIBICAL_CLASS_ICALRECURRENCETYPE "net/cp/jlibical/ICalRecurrenceType" +#define JLIBICAL_CLASS_ICALPERIODTYPE "net/cp/jlibical/ICalPeriodType" + +#endif /* JLIBICAL_CONSTS_CXX_H */ diff --git a/libical/src/java/jlibical_utils_cxx.cpp b/libical/src/java/jlibical_utils_cxx.cpp new file mode 100644 index 0000000000..d06d4ba004 --- /dev/null +++ b/libical/src/java/jlibical_utils_cxx.cpp @@ -0,0 +1,458 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jlibical_utils_cxx.cpp + CREATOR: Srinivasa Boppana/George Norman + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef JLIBICAL_UTILS_CXX_H +#include "jlibical_utils_cxx.h" +#endif + +#ifndef JLIBICAL_CONSTS_CXX_H +#include "jlibical_consts_cxx.h" +#endif + +#ifndef ICALPARAMETER_CXX_H +#include "icalparameter_cxx.h" +#endif + +#ifndef VCOMPONENT_CXX_H +#include "vcomponent.h" +#endif + +#ifndef ICALPROPERTY_CXX_H +#include "icalproperty_cxx.h" +#endif + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +#ifndef _jni_ICalTimeType_H +#include "jniICalTimeType_cxx.h" +#endif + +#ifndef _jni_ICalTriggerType_H +#include "jniICalTriggerType_cxx.h" +#endif + +#ifndef _jni_ICalDurationType_H +#include "jniICalDurationType_cxx.h" +#endif + +#ifndef _jni_ICalRecurrenceType_H +#include "jniICalRecurrenceType_cxx.h" +#endif + +#ifndef _jni_ICalPeriodType_H +#include "jniICalPeriodType_cxx.h" +#endif + +//------------------------------------------------------- +// Returns a pointer to the subject (a c++ object) for the given surrogate (a java object) +//------------------------------------------------------- +void* getCObjectPtr(JNIEnv *env, jobject surrogate) +{ + void* result = 0; + jclass jcls = env->GetObjectClass(surrogate); + jfieldID fid = env->GetFieldID(jcls,"m_Obj","J"); + + if (fid == NULL) + { + // this should never happen. + throwException( env, JLIBICAL_ERR_CLIENT_INTERNAL ); + return(NULL); + } + + result = (void*)env->GetLongField(surrogate,fid); + if (result == NULL) + { + // the proxy object (java) has no subject (c++ object) + throwException( env, JLIBICAL_ERR_CLIENT_INTERNAL ); + return(NULL); + } + + return(result); +} + +//------------------------------------------------------- +// Set the subject (a c++ object) for the given surrogate (a java object). +// Throws exception if the m_Obj field can not be found. +//------------------------------------------------------- +void setCObjectPtr(JNIEnv *env, jobject surrogate, void* subject) +{ + jclass jcls = env->GetObjectClass(surrogate); + jfieldID fid = env->GetFieldID(jcls,"m_Obj","J"); + + if (fid == NULL) + { + throwException( env, JLIBICAL_ERR_CLIENT_INTERNAL ); + return; + } + + env->SetLongField(surrogate,fid,(long)subject); +} + +//------------------------------------------------------- +// Return the pointer to the subject (as an VComponent*) from the given surrogate. +// If the subject is not an VComponent type, or if the subject is NULL, then return NULL. +//------------------------------------------------------- +VComponent* getSubjectAsVComponent(JNIEnv *env, jobject surrogateComponent, int exceptionType) +{ + VComponent* result = (VComponent*)(getCObjectPtr(env,surrogateComponent)); + + if (result == NULL) + { + throwException(env, exceptionType ); + } + + return(result); +} + +//------------------------------------------------------- +// Return the pointer to the subject (as an ICalProperty*) from the given surrogate. +// If the subject is not an ICalProperty type, or if the subject is NULL, then return NULL. +//------------------------------------------------------- +ICalProperty* getSubjectAsICalProperty(JNIEnv *env, jobject surrogateProperty, int exceptionType) +{ + ICalProperty* result = (ICalProperty*)(getCObjectPtr(env,surrogateProperty)); + + if (result == NULL) + { + throwException(env, exceptionType ); + } + + return(result); +} + +//------------------------------------------------------- +// Return the pointer to the subject (as an ICalValue*) from the given surrogate. +// If the subject is not an ICalValue type, or if the subject is NULL, then return NULL. +//------------------------------------------------------- +ICalValue* getSubjectAsICalValue(JNIEnv *env, jobject surrogateValue, int exceptionType) +{ + ICalValue* result = (ICalValue*)(getCObjectPtr(env,surrogateValue)); + + if (result == NULL) + { + throwException( env, exceptionType ); + } + + return(result); +} + +//------------------------------------------------------- +// Return the pointer to the subject (as an ICalParameter*) from the given surrogate. +// If the subject is not an ICalParameter type, or if the subject is NULL, then return NULL. +//------------------------------------------------------- +ICalParameter* getSubjectAsICalParameter(JNIEnv *env, jobject surrogateParameter, int exceptionType) +{ + ICalParameter* result = (ICalParameter*)(getCObjectPtr(env,surrogateParameter)); + + if (result == NULL) + { + throwException( env, exceptionType ); + } + + return(result); +} + +//------------------------------------------------------- +// Copy the data from the src (a java ICalTimeType object) +// to the dest (a c struct icaltimetype*). +// Returns true if success. False if exception is thrown: +// - the src java object is not an ICalTimeType type +// - the dest c struct is null. +//------------------------------------------------------- +bool copyObjToicaltimetype(JNIEnv *env, jobject src, icaltimetype* dest) +{ + bool result = false; + + if (dest != NULL && env->IsInstanceOf(src,env->FindClass(JLIBICAL_CLASS_ICALTIMETYPE))) + { + jni_GetAll_from_ICalTimeType(dest, env, src); + result = true; + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } + + return(result); +} + +//------------------------------------------------------- +// Copy the data from the src (a java ICalTriggerType object) +// to the dest (a c struct icaltriggertype*). +// Returns true if success. False if exception is thrown: +// - the src java object is not an ICalTriggerType type +// - the dest c struct is null. +//------------------------------------------------------- +bool copyObjToicaltriggertype(JNIEnv *env, jobject src, icaltriggertype* dest) +{ + bool result = false; + + if (dest != NULL && env->IsInstanceOf(src,env->FindClass(JLIBICAL_CLASS_ICALTRIGGERTYPE))) + { + jni_GetAll_from_ICalTriggerType(dest, env, src); + result = true; + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } + + return(result); +} + +//------------------------------------------------------- +// Copy the data from the src (a java ICalDurationType object) +// to the dest (a c struct icaldurationtype*). +// Returns true if success. False if exception is thrown: +// - the src java object is not an ICalDurationType type +// - the dest c struct is null. +//------------------------------------------------------- +bool copyObjToicaldurationtype(JNIEnv *env, jobject src, icaldurationtype* dest) +{ + bool result = false; + + if (dest != NULL && env->IsInstanceOf(src,env->FindClass(JLIBICAL_CLASS_ICALDURATIONTYPE))) + { + jni_GetAll_from_ICalDurationType(dest, env, src); + result = true; + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } + + return(result); +} + +//------------------------------------------------------- +// Copy the data from the src (a java ICalRecurrenceType object) +// to the dest (a c struct icalrecurrencetype*). +// Returns true if success. False if exception is thrown: +// - the src java object is not an ICalRecurrenceType type +// - the dest c struct is null. +//------------------------------------------------------- +bool copyObjToicalrecurrencetype(JNIEnv *env, jobject src, icalrecurrencetype* dest) +{ + bool result = false; + + if (dest != NULL && env->IsInstanceOf(src,env->FindClass(JLIBICAL_CLASS_ICALRECURRENCETYPE))) + { + jni_GetAll_from_ICalRecurrenceType(dest, env, src); + result = true; + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } + + return(result); +} + +//------------------------------------------------------- +// Copy the data from the src (a java ICalPeriodType object) +// to the dest (a c struct icalperiodtype*). +// Returns true if success. False if exception is thrown: +// - the src java object is not an ICalPeriodType type +// - the dest c struct is null. +//------------------------------------------------------- +bool copyObjToicalperiodtype(JNIEnv *env, jobject src, icalperiodtype* dest) +{ + bool result = false; + + if (dest != NULL && env->IsInstanceOf(src,env->FindClass(JLIBICAL_CLASS_ICALPERIODTYPE))) + { + jni_GetAll_from_ICalPeriodType(dest, env, src); + result = true; + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } + + return(result); +} + +//------------------------------------------------------- +// Create a new VComponent surrogate for given subject. +// If subject is NULL, then returns NULL (will not create a +// surrogate to a NULL subject); +//------------------------------------------------------- +jobject createNewVComponentSurrogate(JNIEnv *env, VComponent* subject) +{ + char* classname = JLIBICAL_CLASS_VCOMPONENT; + if (dynamic_cast<VAlarm*>(subject)) + classname = JLIBICAL_CLASS_VALARM; + else if (dynamic_cast<VCalendar*>(subject)) + classname = JLIBICAL_CLASS_VCALENDAR; + else if (dynamic_cast<VEvent*>(subject)) + classname = JLIBICAL_CLASS_VEVENT; + else if (dynamic_cast<VQuery*>(subject)) + classname = JLIBICAL_CLASS_VQUERY; + else if (dynamic_cast<VToDo*>(subject)) + classname = JLIBICAL_CLASS_VTODO; + else if (dynamic_cast<VAgenda*>(subject)) + classname = JLIBICAL_CLASS_VAGENDA; + + return(doCreateNewSurrogate(env,env->FindClass(classname),(jlong)subject)); +} + +//------------------------------------------------------- +// Create a new ICalProperty surrogate for given subject. +// If subject is NULL, then returns NULL (will not create a +// surrogate to a NULL subject); +//------------------------------------------------------- +jobject createNewICalPropertySurrogate(JNIEnv *env, ICalProperty* subject) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALPROPERTY),(jlong)subject)); +} + +//------------------------------------------------------- +// Create a new ICalValue surrogate for given subject. +// If subject is NULL, then returns NULL (will not create a +// surrogate to a NULL subject); +//------------------------------------------------------- +jobject createNewICalValueSurrogate(JNIEnv *env, ICalValue* subject) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALVALUE),(jlong)subject)); +} + +//------------------------------------------------------- +// Create a new ICalParameter surrogate for given subject. +// If subject is NULL, then returns NULL (will not create a +// surrogate to a NULL subject); +//------------------------------------------------------- +jobject createNewICalParameterSurrogate(JNIEnv *env, ICalParameter* subject) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALPARAMETER),(jlong)subject)); +} + +//------------------------------------------------------- +// Create a new ICalTimeType object from the given source struct. +// A copy is made, . +// If source is NULL, then returns NULL (will not create an +// object to a NULL source); +//------------------------------------------------------- +jobject createNewICalTimeType(JNIEnv *env, icaltimetype* source) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALTIMETYPE),(jlong)source)); +} + +//------------------------------------------------------- +// Create a new ICalTriggerType object from the given source struct. +// A copy is made, . +// If source is NULL, then returns NULL (will not create an +// object to a NULL source); +//------------------------------------------------------- +jobject createNewICalTriggerType(JNIEnv *env, icaltriggertype* source) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALTRIGGERTYPE),(jlong)source)); +} + +//------------------------------------------------------- +// Create a new ICalDurationType object from the given source struct. +// A copy is made, . +// If source is NULL, then returns NULL (will not create an +// object to a NULL source); +//------------------------------------------------------- +jobject createNewICalDurationType(JNIEnv *env, icaldurationtype* source) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALDURATIONTYPE),(jlong)source)); +} + +//------------------------------------------------------- +// Create a new ICalRecurrenceType object from the given source struct. +// A copy is made, . +// If source is NULL, then returns NULL (will not create an +// object to a NULL source); +//------------------------------------------------------- +jobject createNewICalRecurrenceType(JNIEnv *env, icalrecurrencetype* source) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALRECURRENCETYPE),(jlong)source)); +} + +//------------------------------------------------------- +// Create a new ICalPeriodType object from the given source struct. +// A copy is made, . +// If source is NULL, then returns NULL (will not create an +// object to a NULL source); +//------------------------------------------------------- +jobject createNewICalPeriodType(JNIEnv *env, icalperiodtype* source) +{ + return(doCreateNewSurrogate(env,env->FindClass(JLIBICAL_CLASS_ICALPERIODTYPE),(jlong)source)); +} + +//------------------------------------------------------- +// Creat a new surrogate of the given type for the given subject. +//------------------------------------------------------- +jobject doCreateNewSurrogate(JNIEnv *env, jclass surrogateClass, jlong subject) +{ + jobject result = NULL; + + if (subject != NULL) + { + jmethodID jconstructorID = env->GetMethodID(surrogateClass, "<init>", "(J)V"); + + result = env->NewObject(surrogateClass, jconstructorID, subject); + } + + return(result); +} + + +//------------------------------------------------------- +// For the given cpErr, create a new Exception and send it to env. +// Note: Throw does not throw anything. It only sets the state. +// The JVM will check this and throw an exception later. +//------------------------------------------------------- +void throwException(JNIEnv *env, int cpErr) +{ + jclass jexceptionClass; + jthrowable jexceptionObj; + jmethodID jconstructorID; + const char* exClassName; + + if (env->ExceptionOccurred()) + { + return; + } + + switch ( cpErr ) + { + case JLIBICAL_ERR_NETWORK: + exClassName = "net.cp.jlibical/JLCNetworkException"; + break; + + case JLIBICAL_ERR_SERVER_INTERNAL: + exClassName = "net.cp.jlibical/JLCServerInternalException"; + break; + + case JLIBICAL_ERR_CLIENT_INTERNAL: + exClassName = "net.cp.jlibical/JLCClientInternalException"; + break; + + case JLIBICAL_ERR_ILLEGAL_ARGUMENT: + exClassName = "net.cp.jlibical/JLCIllegalArgumentException"; + break; + + case JLIBICAL_ERR_API_NOT_INITED: + exClassName = "net.cp.jlibical/JLCNotInitedException"; + break; + + case JLIBICAL_ERR_HOST_INVALID: + exClassName = "net.cp.jlibical/JLCHostInvalidException"; + break; + + default: + exClassName = "net.cp.jlibical/JLCClientInternalException"; + printf("*** JLIBICAL JNI throwException: unknown error code: %d\n", cpErr ); + break; + } + + env->ThrowNew(env->FindClass(exClassName),""); +} diff --git a/libical/src/java/jlibical_utils_cxx.h b/libical/src/java/jlibical_utils_cxx.h new file mode 100644 index 0000000000..a6cdbc56be --- /dev/null +++ b/libical/src/java/jlibical_utils_cxx.h @@ -0,0 +1,59 @@ + +/*====================================================================== + FILE: jlibical_utils_cxx.h + CREATOR: Srinivasa Boppana/George Norman + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef TEST_CXX_H +#define TEST_CXX_H + +#ifndef JNI_H +#include <jni.h> +#endif + +class VComponent; +class ICalProperty; +class ICalValue; +class ICalParameter; +struct icaltimetype; +struct icaltriggertype; +struct icaldurationtype; +struct icalrecurrencetype; +struct icalperiodtype; + +// get & set +void* getCObjectPtr(JNIEnv *env, jobject anObj); +void setCObjectPtr(JNIEnv *env, jobject anObj, void* val); + +// type-safe getters +VComponent* getSubjectAsVComponent(JNIEnv *env, jobject surrogateComponent, int exceptionType); +ICalProperty* getSubjectAsICalProperty(JNIEnv *env, jobject surrogateProperty, int exceptionType); +ICalValue* getSubjectAsICalValue(JNIEnv *env, jobject surrogateValue, int exceptionType); +ICalParameter* getSubjectAsICalParameter(JNIEnv *env, jobject surrogateParameter, int exceptionType); + +bool copyObjToicaltimetype(JNIEnv *env, jobject src, icaltimetype* dest); +bool copyObjToicaltriggertype(JNIEnv *env, jobject src, icaltriggertype* dest); +bool copyObjToicaldurationtype(JNIEnv *env, jobject src, icaldurationtype* dest); +bool copyObjToicalrecurrencetype(JNIEnv *env, jobject src, icalrecurrencetype* dest); +bool copyObjToicalperiodtype(JNIEnv *env, jobject src, icalperiodtype* dest); + +// exception handling +void throwException( JNIEnv *env, int cpErr ); + +// create objects +jobject createNewVComponentSurrogate(JNIEnv *env, VComponent* subject); +jobject createNewICalPropertySurrogate(JNIEnv *env, ICalProperty* subject); +jobject createNewICalValueSurrogate(JNIEnv *env, ICalValue* subject); +jobject createNewICalParameterSurrogate(JNIEnv *env, ICalParameter* subject); + +jobject createNewICalTimeType(JNIEnv *env, icaltimetype* source); +jobject createNewICalTriggerType(JNIEnv *env, icaltriggertype* source); +jobject createNewICalDurationType(JNIEnv *env, icaldurationtype* source); +jobject createNewICalRecurrenceType(JNIEnv *env, icalrecurrencetype* source); +jobject createNewICalPeriodType(JNIEnv *env, icalperiodtype* source); + +jobject doCreateNewSurrogate(JNIEnv *env, jclass surrogateClass, jlong subject); + + +#endif /*TEST_CXX_H*/ diff --git a/libical/src/java/jniICalDurationType_cxx.cpp b/libical/src/java/jniICalDurationType_cxx.cpp new file mode 100644 index 0000000000..e1e0204c46 --- /dev/null +++ b/libical/src/java/jniICalDurationType_cxx.cpp @@ -0,0 +1,130 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jniICalDurationType_cxx.cpp + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#include <jni.h> + +#include "jniICalDurationType_cxx.h" + +static jfieldID ICalDurationType_Is_neg_FID; +static jfieldID ICalDurationType_Days_FID; +static jfieldID ICalDurationType_Weeks_FID; +static jfieldID ICalDurationType_Hours_FID; +static jfieldID ICalDurationType_Minutes_FID; +static jfieldID ICalDurationType_Seconds_FID; + + +void initICalDurationTypeFieldIDs(JNIEnv* env, jclass clazz) +{ + ICalDurationType_Is_neg_FID = env->GetFieldID(clazz, "is_neg", "I"); + ICalDurationType_Days_FID = env->GetFieldID(clazz, "days", "J"); + ICalDurationType_Weeks_FID = env->GetFieldID(clazz, "weeks", "J"); + ICalDurationType_Hours_FID = env->GetFieldID(clazz, "hours", "J"); + ICalDurationType_Minutes_FID = env->GetFieldID(clazz, "minutes", "J"); + ICalDurationType_Seconds_FID = env->GetFieldID(clazz, "seconds", "J"); +} + +void jni_SetIs_neg_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetIntField(thisICalDurationType, ICalDurationType_Is_neg_FID, (jint) __ICalDurationType_->is_neg); +} + +void jni_GetIs_neg_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->is_neg = env->GetIntField(thisICalDurationType, ICalDurationType_Is_neg_FID); +} + +void jni_SetDays_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetLongField(thisICalDurationType, ICalDurationType_Days_FID, (jlong) __ICalDurationType_->days); +} + +void jni_GetDays_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->days = env->GetLongField(thisICalDurationType, ICalDurationType_Days_FID); +} + +void jni_SetWeeks_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetLongField(thisICalDurationType, ICalDurationType_Weeks_FID, (jlong) __ICalDurationType_->weeks); +} + +void jni_GetWeeks_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->weeks = env->GetLongField(thisICalDurationType, ICalDurationType_Weeks_FID); +} + +void jni_SetHours_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetLongField(thisICalDurationType, ICalDurationType_Hours_FID, (jlong) __ICalDurationType_->hours); +} + +void jni_GetHours_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->hours = env->GetLongField(thisICalDurationType, ICalDurationType_Hours_FID); +} + +void jni_SetMinutes_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetLongField(thisICalDurationType, ICalDurationType_Minutes_FID, (jlong) __ICalDurationType_->minutes); +} + +void jni_GetMinutes_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->minutes = env->GetLongField(thisICalDurationType, ICalDurationType_Minutes_FID); +} + +void jni_SetSeconds_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + env->SetLongField(thisICalDurationType, ICalDurationType_Seconds_FID, (jlong) __ICalDurationType_->seconds); +} + +void jni_GetSeconds_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType) +{ + __ICalDurationType_->seconds = env->GetLongField(thisICalDurationType, ICalDurationType_Seconds_FID); +} + +// copy all fields from the c struct (ICalDurationType) to the java object (thisICalDurationType). +void jni_SetAll_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv* env, jobject thisICalDurationType) +{ + jni_SetIs_neg_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_SetDays_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_SetWeeks_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_SetHours_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_SetMinutes_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_SetSeconds_in_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); +} + +// copy all fields from the java object (thisICalDurationType) to the c struct (__ICalDurationType_). +void jni_GetAll_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv* env, jobject thisICalDurationType) +{ + jni_GetIs_neg_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_GetDays_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_GetWeeks_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_GetHours_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_GetMinutes_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); + jni_GetSeconds_from_ICalDurationType(__ICalDurationType_, env, thisICalDurationType); +} +/* + * Class: net_cp_jlibical_ICalDurationType + * Method: init + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalDurationType_init__J + (JNIEnv *env, jobject thisICalDurationType, jlong data) +{ + // copy all fields from the c struct (data) to the java object (thisICalDurationType). + jni_SetAll_in_ICalDurationType((ICalDurationType*)data,env,thisICalDurationType); +} + +/* + * Class: net_cp_jlibical_ICalDurationType + * Method: initFIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalDurationType_initFIDs(JNIEnv *env, jclass clazz) { + initICalDurationTypeFieldIDs(env, clazz); +} diff --git a/libical/src/java/jniICalDurationType_cxx.h b/libical/src/java/jniICalDurationType_cxx.h new file mode 100644 index 0000000000..6ef1de1a09 --- /dev/null +++ b/libical/src/java/jniICalDurationType_cxx.h @@ -0,0 +1,47 @@ + +/*====================================================================== + FILE: jniICalDurationType_cxx.h + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _jni_ICalDurationType_H +#define _jni_ICalDurationType_H +#include <jni.h> + +// I forgot how to do this using a typedef in c++!!!! +#define ICalDurationType icaldurationtype + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ical.h" + +static void initICalDurationTypeFieldIDs(JNIEnv* env, jclass clazz); + +void jni_SetIs_neg_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetIs_neg_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetDays_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetDays_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetWeeks_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetWeeks_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetHours_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetHours_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetMinutes_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetMinutes_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetSeconds_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_GetSeconds_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv *env, jobject thisICalDurationType); +void jni_SetAll_in_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv* env, jobject thisICalDurationType); + +void jni_GetAll_from_ICalDurationType(struct ICalDurationType* __ICalDurationType_, JNIEnv* env, jobject thisICalDurationType); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalDurationType_initFIDs(JNIEnv *env, jclass clazz); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalDurationType_init__J(JNIEnv *env, jobject thisICalDurationType, jlong data); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libical/src/java/jniICalPeriodType_cxx.cpp b/libical/src/java/jniICalPeriodType_cxx.cpp new file mode 100644 index 0000000000..5a0b676915 --- /dev/null +++ b/libical/src/java/jniICalPeriodType_cxx.cpp @@ -0,0 +1,144 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jniICalPeriodType_cxx.cpp + CREATOR: structConverter +======================================================================*/ + +#include <jni.h> + +#include "jniICalPeriodType_cxx.h" +#include "jniICalTimeType_cxx.h" +#include "jniICalDurationType_cxx.h" + +static jfieldID ICalPeriodType_Start_FID; +static jfieldID ICalPeriodType_End_FID; +static jfieldID ICalPeriodType_Duration_FID; + + +void initICalPeriodTypeFieldIDs(JNIEnv* env, jclass clazz) +{ + ICalPeriodType_Start_FID = env->GetFieldID(clazz, "start", "Lnet/cp/jlibical/ICalTimeType;"); + ICalPeriodType_End_FID = env->GetFieldID(clazz, "end", "Lnet/cp/jlibical/ICalTimeType;"); + ICalPeriodType_Duration_FID = env->GetFieldID(clazz, "duration", "Lnet/cp/jlibical/ICalDurationType;"); +} + +void jni_SetStart_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_Start_FID); + jni_SetYear_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetMonth_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetDay_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetHour_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetMinute_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetSecond_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetIs_utc_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetIs_date_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_SetZone_in_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); +} + +void jni_GetStart_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_Start_FID); + jni_GetYear_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetMonth_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetDay_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetHour_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetMinute_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetSecond_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetIs_utc_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetIs_date_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); + jni_GetZone_from_ICalTimeType(&(__ICalPeriodType_->start), env, lcl_jobj0); +} + +void jni_SetEnd_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_End_FID); + jni_SetYear_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetMonth_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetDay_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetHour_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetMinute_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetSecond_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetIs_utc_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetIs_date_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_SetZone_in_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); +} + +void jni_GetEnd_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_End_FID); + jni_GetYear_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetMonth_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetDay_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetHour_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetMinute_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetSecond_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetIs_utc_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetIs_date_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); + jni_GetZone_from_ICalTimeType(&(__ICalPeriodType_->end), env, lcl_jobj0); +} + +void jni_SetDuration_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_Duration_FID); + jni_SetIs_neg_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_SetDays_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_SetWeeks_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_SetHours_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_SetMinutes_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_SetSeconds_in_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); +} + +void jni_GetDuration_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalPeriodType, ICalPeriodType_Duration_FID); + jni_GetIs_neg_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_GetDays_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_GetWeeks_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_GetHours_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_GetMinutes_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); + jni_GetSeconds_from_ICalDurationType(&(__ICalPeriodType_->duration), env, lcl_jobj0); +} + +// copy all fields from the c struct (__ICalPeriodType_) to the java object (thisICalPeriodType). +void jni_SetAll_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv* env, jobject thisICalPeriodType) +{ + jni_SetStart_in_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); + jni_SetEnd_in_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); + jni_SetDuration_in_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); +} + +// copy all fields from the java object (thisICalPeriodType) to the c struct (__ICalPeriodType_). +void jni_GetAll_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv* env, jobject thisICalPeriodType) +{ + jni_GetStart_from_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); + jni_GetEnd_from_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); + jni_GetDuration_from_ICalPeriodType(__ICalPeriodType_, env, thisICalPeriodType); +} + +/* + * Class: net_cp_jlibical_ICalPeriodType + * Method: init + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalPeriodType_init__J + (JNIEnv* env, jobject thisICalPeriodType, jlong data) +{ + // copy all fields from the c struct (data) to the java object (thisICalTimeType). + jni_SetAll_in_ICalPeriodType((ICalPeriodType*)data,env,thisICalPeriodType); +} + +/* + * Class: net_cp_jlibical_ICalPeriodType + * Method: initFIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalPeriodType_initFIDs(JNIEnv *env, jclass clazz) { + initICalPeriodTypeFieldIDs(env, clazz); +} diff --git a/libical/src/java/jniICalPeriodType_cxx.h b/libical/src/java/jniICalPeriodType_cxx.h new file mode 100644 index 0000000000..458e20a198 --- /dev/null +++ b/libical/src/java/jniICalPeriodType_cxx.h @@ -0,0 +1,42 @@ + +/*====================================================================== + FILE: jniICalPeriodType_cxx.h + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _jni_ICalPeriodType_H +#define _jni_ICalPeriodType_H +#include <jni.h> + +// I forgot how to do this using a typedef in c++!!!! +#define ICalPeriodType icalperiodtype + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ical.h" + +static void initICalPeriodTypeFieldIDs(JNIEnv* env, jclass clazz); + +void jni_SetStart_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); +void jni_GetStart_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); +void jni_SetEnd_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); +void jni_GetEnd_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); +void jni_SetDuration_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); +void jni_GetDuration_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv *env, jobject thisICalPeriodType); + +void jni_SetAll_in_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv* env, jobject thisICalPeriodType); +void jni_GetAll_from_ICalPeriodType(struct ICalPeriodType* __ICalPeriodType_, JNIEnv* env, jobject thisICalPeriodType); + +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalPeriodType_init__J(JNIEnv* env, jobject thisICalPeriodType, jlong data); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalPeriodType_initFIDs(JNIEnv *env, jclass clazz); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libical/src/java/jniICalRecurrenceType_cxx.cpp b/libical/src/java/jniICalRecurrenceType_cxx.cpp new file mode 100644 index 0000000000..48698b90f2 --- /dev/null +++ b/libical/src/java/jniICalRecurrenceType_cxx.cpp @@ -0,0 +1,347 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jniICalRecurrenceType_cxx.cpp + CREATOR: structConverter +======================================================================*/ + +#include <jni.h> + +#include "jniICalRecurrenceType_cxx.h" +#include "jniICalTimeType_cxx.h" + +static jfieldID ICalRecurrenceType_Until_FID; +static jfieldID ICalRecurrenceType_Freq_FID; +static jfieldID ICalRecurrenceType_Week_start_FID; + +static jfieldID ICalRecurrenceType_Count_FID; +static jfieldID ICalRecurrenceType_Interval_FID; +static jfieldID ICalRecurrenceType_By_second_FID; +static jfieldID ICalRecurrenceType_By_minute_FID; +static jfieldID ICalRecurrenceType_By_hour_FID; +static jfieldID ICalRecurrenceType_By_day_FID; +static jfieldID ICalRecurrenceType_By_month_day_FID; +static jfieldID ICalRecurrenceType_By_year_day_FID; +static jfieldID ICalRecurrenceType_By_week_no_FID; +static jfieldID ICalRecurrenceType_By_month_FID; +static jfieldID ICalRecurrenceType_By_set_pos_FID; + + +void initICalRecurrenceTypeFieldIDs(JNIEnv* env, jclass clazz) +{ + ICalRecurrenceType_Until_FID = env->GetFieldID(clazz, "until", "Lnet/cp/jlibical/ICalTimeType;"); + ICalRecurrenceType_Freq_FID = env->GetFieldID(clazz, "freq", "I"); + ICalRecurrenceType_Week_start_FID = env->GetFieldID(clazz, "week_start", "I"); + ICalRecurrenceType_Count_FID = env->GetFieldID(clazz, "count", "I"); + ICalRecurrenceType_Interval_FID = env->GetFieldID(clazz, "interval", "S"); + ICalRecurrenceType_By_second_FID = env->GetFieldID(clazz, "by_second", "[S"); + ICalRecurrenceType_By_minute_FID = env->GetFieldID(clazz, "by_minute", "[S"); + ICalRecurrenceType_By_hour_FID = env->GetFieldID(clazz, "by_hour", "[S"); + ICalRecurrenceType_By_day_FID = env->GetFieldID(clazz, "by_day", "[S"); + ICalRecurrenceType_By_month_day_FID = env->GetFieldID(clazz, "by_month_day", "[S"); + ICalRecurrenceType_By_year_day_FID = env->GetFieldID(clazz, "by_year_day", "[S"); + ICalRecurrenceType_By_week_no_FID = env->GetFieldID(clazz, "by_week_no", "[S"); + ICalRecurrenceType_By_month_FID = env->GetFieldID(clazz, "by_month", "[S"); + ICalRecurrenceType_By_set_pos_FID = env->GetFieldID(clazz, "by_set_pos", "[S"); +} + +void jni_SetUntil_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_Until_FID); + jni_SetYear_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetMonth_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetDay_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetHour_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetMinute_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetSecond_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetIs_utc_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetIs_date_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_SetZone_in_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); +} + +void jni_GetUntil_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_Until_FID); + jni_GetYear_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetMonth_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetDay_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetHour_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetMinute_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetSecond_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetIs_utc_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetIs_date_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); + jni_GetZone_from_ICalTimeType(&(__ICalRecurrenceType_->until), env, lcl_jobj0); +} + +void jni_SetFreq_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + env->SetIntField(thisICalRecurrenceType, ICalRecurrenceType_Freq_FID, (jint) __ICalRecurrenceType_->freq); +} + +void jni_GetFreq_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + __ICalRecurrenceType_->freq = (icalrecurrencetype_frequency) env->GetIntField(thisICalRecurrenceType, ICalRecurrenceType_Freq_FID); +} + +void jni_SetWeek_start_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + env->SetIntField(thisICalRecurrenceType, ICalRecurrenceType_Week_start_FID, (jint) __ICalRecurrenceType_->week_start); +} + +void jni_GetWeek_start_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + __ICalRecurrenceType_->week_start = (icalrecurrencetype_weekday) env->GetIntField(thisICalRecurrenceType, ICalRecurrenceType_Week_start_FID); +} + +void jni_SetCount_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + env->SetIntField(thisICalRecurrenceType, ICalRecurrenceType_Count_FID, (jint) __ICalRecurrenceType_->count); +} + +void jni_GetCount_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + __ICalRecurrenceType_->count = env->GetIntField(thisICalRecurrenceType, ICalRecurrenceType_Count_FID); +} + +void jni_SetInterval_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + env->SetShortField(thisICalRecurrenceType, ICalRecurrenceType_Interval_FID, (jshort) __ICalRecurrenceType_->interval); +} + +void jni_GetInterval_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + __ICalRecurrenceType_->interval = env->GetShortField(thisICalRecurrenceType, ICalRecurrenceType_Interval_FID); +} + +void jni_SetBy_second_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_second_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,61, (jshort*)&(__ICalRecurrenceType_->by_second[0])); +} + +void jni_GetBy_second_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_second_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,61, (jshort*)&(__ICalRecurrenceType_->by_second[0])); +} + +void jni_SetBy_minute_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_minute_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,61, (jshort*)&(__ICalRecurrenceType_->by_minute[0])); +} + +void jni_GetBy_minute_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_minute_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,61, (jshort*)&(__ICalRecurrenceType_->by_minute[0])); +} + +void jni_SetBy_hour_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_hour_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,25, (jshort*)&(__ICalRecurrenceType_->by_hour[0])); +} + +void jni_GetBy_hour_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_hour_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,25, (jshort*)&(__ICalRecurrenceType_->by_hour[0])); +} + +void jni_SetBy_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_day_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,364, (jshort*)&(__ICalRecurrenceType_->by_day[0])); +} + +void jni_GetBy_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_day_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,364, (jshort*)&(__ICalRecurrenceType_->by_day[0])); +} + +void jni_SetBy_month_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_month_day_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,32, (jshort*)&(__ICalRecurrenceType_->by_month_day[0])); +} + +void jni_GetBy_month_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_month_day_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,32, (jshort*)&(__ICalRecurrenceType_->by_month_day[0])); +} + +void jni_SetBy_year_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_year_day_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,367, (jshort*)&(__ICalRecurrenceType_->by_year_day[0])); +} + +void jni_GetBy_year_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_year_day_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,367, (jshort*)&(__ICalRecurrenceType_->by_year_day[0])); +} + +void jni_SetBy_week_no_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_week_no_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,54, (jshort*)&(__ICalRecurrenceType_->by_week_no[0])); +} + +void jni_GetBy_week_no_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_week_no_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,54, (jshort*)&(__ICalRecurrenceType_->by_week_no[0])); +} + +void jni_SetBy_month_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_month_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,13, (jshort*)&(__ICalRecurrenceType_->by_month[0])); +} + +void jni_GetBy_month_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_month_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,13, (jshort*)&(__ICalRecurrenceType_->by_month[0])); +} + +void jni_SetBy_set_pos_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_set_pos_FID); + env->SetShortArrayRegion((jshortArray)lcl_jobjA0, 0,367, (jshort*)&(__ICalRecurrenceType_->by_set_pos[0])); +} + +void jni_GetBy_set_pos_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType) +{ + jclass elem_clazz; + jboolean isCopy; + int ix0; + jobject lcl_jobj0; + jarray lcl_jobjA0; + lcl_jobjA0 = (jarray) env->GetObjectField(thisICalRecurrenceType, ICalRecurrenceType_By_set_pos_FID); + env->GetShortArrayRegion((jshortArray)lcl_jobjA0, 0,367, (jshort*)&(__ICalRecurrenceType_->by_set_pos[0])); +} +void jni_SetAll_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv* env, jobject thisICalRecurrenceType) +{ + jni_SetUntil_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetFreq_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetWeek_start_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetCount_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetInterval_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_second_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_minute_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_hour_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_day_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_month_day_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_year_day_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_week_no_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_month_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_SetBy_set_pos_in_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); +} +void jni_GetAll_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv* env, jobject thisICalRecurrenceType) +{ + jni_GetUntil_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetFreq_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetWeek_start_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetCount_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetInterval_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_second_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_minute_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_hour_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_day_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_month_day_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_year_day_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_week_no_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_month_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + jni_GetBy_set_pos_from_ICalRecurrenceType(__ICalRecurrenceType_, env, thisICalRecurrenceType); + +} + +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalRecurrenceType_init__J(JNIEnv* env, jobject thisICalRecurrenceType, jlong data) { + jni_SetAll_in_ICalRecurrenceType((ICalRecurrenceType*)data,env,thisICalRecurrenceType); +} + +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalRecurrenceType_initFIDs(JNIEnv *env, jclass clazz) { + initICalRecurrenceTypeFieldIDs(env, clazz); +} diff --git a/libical/src/java/jniICalRecurrenceType_cxx.h b/libical/src/java/jniICalRecurrenceType_cxx.h new file mode 100644 index 0000000000..2f0bf4bae5 --- /dev/null +++ b/libical/src/java/jniICalRecurrenceType_cxx.h @@ -0,0 +1,60 @@ + +/*====================================================================== + FILE: jniICalRecurrenceType_cxx.h + CREATOR: structConverter +======================================================================*/ + +#ifndef _jni_ICalRecurrenceType_H_ +#define _jni_ICalRecurrenceType_H_ +#include <jni.h> + +#define ICalRecurrenceType icalrecurrencetype + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ical.h" + +static void initICalRecurrenceTypeFieldIDs(JNIEnv* env, jclass clazz); + +void jni_SetUntil_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetUntil_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetFreq_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetFreq_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetWeek_start_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetWeek_start_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetCount_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetCount_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetInterval_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetInterval_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_second_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_second_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_minute_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_minute_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_hour_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_hour_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_month_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_month_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_year_day_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_year_day_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_week_no_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_week_no_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_month_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_month_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetBy_set_pos_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_GetBy_set_pos_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv *env, jobject thisICalRecurrenceType); +void jni_SetAll_in_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv* env, jobject thisICalRecurrenceType); + +void jni_GetAll_from_ICalRecurrenceType(struct ICalRecurrenceType* __ICalRecurrenceType_, JNIEnv* env, jobject thisICalRecurrenceType); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalRecurrenceType_init__J(JNIEnv* env, jobject thisICalRecurrenceType, jlong data); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalRecurrenceType_initFIDs(JNIEnv *env, jclass clazz); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libical/src/java/jniICalTimeType_cxx.cpp b/libical/src/java/jniICalTimeType_cxx.cpp new file mode 100644 index 0000000000..341ded7ed0 --- /dev/null +++ b/libical/src/java/jniICalTimeType_cxx.cpp @@ -0,0 +1,176 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jniICalTimeType_cxx.cpp + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#include <jni.h> + +#ifndef _jni_ICalTimeType_H +#include "jniICalTimeType_cxx.h" +#endif + +static jfieldID ICalTimeType_Year_FID; +static jfieldID ICalTimeType_Month_FID; +static jfieldID ICalTimeType_Day_FID; +static jfieldID ICalTimeType_Hour_FID; +static jfieldID ICalTimeType_Minute_FID; +static jfieldID ICalTimeType_Second_FID; +static jfieldID ICalTimeType_Is_utc_FID; +static jfieldID ICalTimeType_Is_date_FID; +static jfieldID ICalTimeType_Zone_FID; + + +void initICalTimeTypeFieldIDs(JNIEnv* env, jclass clazz) +{ + ICalTimeType_Year_FID = env->GetFieldID(clazz, "year", "I"); + ICalTimeType_Month_FID = env->GetFieldID(clazz, "month", "I"); + ICalTimeType_Day_FID = env->GetFieldID(clazz, "day", "I"); + ICalTimeType_Hour_FID = env->GetFieldID(clazz, "hour", "I"); + ICalTimeType_Minute_FID = env->GetFieldID(clazz, "minute", "I"); + ICalTimeType_Second_FID = env->GetFieldID(clazz, "second", "I"); + ICalTimeType_Is_utc_FID = env->GetFieldID(clazz, "is_utc", "I"); + ICalTimeType_Is_date_FID = env->GetFieldID(clazz, "is_date", "I"); + ICalTimeType_Zone_FID = env->GetFieldID(clazz, "zone", "Ljava/lang/String;"); +} + +void jni_SetYear_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Year_FID, (jint) __ICalTimeType_->year); +} + +void jni_GetYear_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->year = env->GetIntField(thisICalTimeType, ICalTimeType_Year_FID); +} + +void jni_SetMonth_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Month_FID, (jint) __ICalTimeType_->month); +} + +void jni_GetMonth_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->month = env->GetIntField(thisICalTimeType, ICalTimeType_Month_FID); +} + +void jni_SetDay_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Day_FID, (jint) __ICalTimeType_->day); +} + +void jni_GetDay_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->day = env->GetIntField(thisICalTimeType, ICalTimeType_Day_FID); +} + +void jni_SetHour_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Hour_FID, (jint) __ICalTimeType_->hour); +} + +void jni_GetHour_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->hour = env->GetIntField(thisICalTimeType, ICalTimeType_Hour_FID); +} + +void jni_SetMinute_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Minute_FID, (jint) __ICalTimeType_->minute); +} + +void jni_GetMinute_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->minute = env->GetIntField(thisICalTimeType, ICalTimeType_Minute_FID); +} + +void jni_SetSecond_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Second_FID, (jint) __ICalTimeType_->second); +} + +void jni_GetSecond_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->second = env->GetIntField(thisICalTimeType, ICalTimeType_Second_FID); +} + +void jni_SetIs_utc_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Is_utc_FID, (jint) __ICalTimeType_->is_utc); +} + +void jni_GetIs_utc_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->is_utc = env->GetIntField(thisICalTimeType, ICalTimeType_Is_utc_FID); +} + +void jni_SetIs_date_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetIntField(thisICalTimeType, ICalTimeType_Is_date_FID, (jint) __ICalTimeType_->is_date); +} + +void jni_GetIs_date_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->is_date = env->GetIntField(thisICalTimeType, ICalTimeType_Is_date_FID); +} + +void jni_SetZone_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + env->SetObjectField(thisICalTimeType, ICalTimeType_Zone_FID, env->NewStringUTF(icaltime_get_tzid(*__ICalTimeType_))); +} + +void jni_GetZone_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType) +{ + __ICalTimeType_->zone = icaltimezone_get_builtin_timezone_from_tzid((char*) env->GetStringUTFChars((jstring) env->GetObjectField(thisICalTimeType, ICalTimeType_Zone_FID), NULL)); +} + +// copy all fields from the c struct (__ICalTimeType_) to the java object (thisICalTimeType). +void jni_SetAll_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv* env, jobject thisICalTimeType) +{ + jni_SetYear_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetMonth_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetDay_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetHour_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetMinute_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetSecond_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetIs_utc_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetIs_date_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_SetZone_in_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); +} + +// copy all fields from the java object (thisICalTimeType) to the c struct (__ICalTimeType_). +void jni_GetAll_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv* env, jobject thisICalTimeType) +{ + jni_GetYear_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetMonth_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetDay_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetHour_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetMinute_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetSecond_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetIs_utc_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetIs_date_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); + jni_GetZone_from_ICalTimeType(__ICalTimeType_, env, thisICalTimeType); +} + +/* + * Class: net_cp_jlibical_ICalTimeType + * Method: init + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTimeType_init__J + (JNIEnv* env, jobject thisICalTimeType, jlong data) +{ + // copy all fields from the c struct (data) to the java object (thisICalTimeType). + jni_SetAll_in_ICalTimeType((ICalTimeType*)data,env,thisICalTimeType); +} + +/* + * Class: net_cp_jlibical_ICalTimeType + * Method: initFIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTimeType_initFIDs(JNIEnv *env, jclass clazz) +{ + initICalTimeTypeFieldIDs(env, clazz); +} diff --git a/libical/src/java/jniICalTimeType_cxx.h b/libical/src/java/jniICalTimeType_cxx.h new file mode 100644 index 0000000000..5d6f84cee7 --- /dev/null +++ b/libical/src/java/jniICalTimeType_cxx.h @@ -0,0 +1,52 @@ + +/*====================================================================== + FILE: jniICalTimeType_cxx.h + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _jni_ICalTimeType_H +#define _jni_ICalTimeType_H +#include <jni.h> + +// I forgot how to do this using a typedef in c++!!!! +#define ICalTimeType icaltimetype + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ical.h" + +static void initICalTimeTypeFieldIDs(JNIEnv* env, jclass clazz); + +void jni_SetYear_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetYear_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetMonth_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetMonth_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetDay_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetDay_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetHour_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetHour_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetMinute_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetMinute_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetSecond_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetSecond_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetIs_utc_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetIs_utc_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetIs_date_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetIs_date_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetZone_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_GetZone_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv *env, jobject thisICalTimeType); +void jni_SetAll_in_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv* env, jobject thisICalTimeType); + +void jni_GetAll_from_ICalTimeType(struct ICalTimeType* __ICalTimeType_, JNIEnv* env, jobject thisICalTimeType); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTimeType_initFIDs(JNIEnv *env, jclass clazz); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTimeType_init__J(JNIEnv* env, jobject thisICalTimeType, jlong data); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libical/src/java/jniICalTriggerType_cxx.cpp b/libical/src/java/jniICalTriggerType_cxx.cpp new file mode 100644 index 0000000000..b4140c8f1a --- /dev/null +++ b/libical/src/java/jniICalTriggerType_cxx.cpp @@ -0,0 +1,111 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: jniICalTriggerType_cxx.cpp + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#include <jni.h> + +#include "jniICalTriggerType_cxx.h" +#include "jniICalTimeType_cxx.h" +#include "jniICalDurationType_cxx.h" + +static jfieldID ICalTriggerType_Time_FID; +static jfieldID ICalTriggerType_Duration_FID; + + +void initICalTriggerTypeFieldIDs(JNIEnv* env, jclass clazz) +{ + ICalTriggerType_Time_FID = env->GetFieldID(clazz, "time", "Lnet/cp/jlibical/ICalTimeType;"); + ICalTriggerType_Duration_FID = env->GetFieldID(clazz, "duration", "Lnet/cp/jlibical/ICalDurationType;"); +} + +void jni_SetTime_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalTriggerType, ICalTriggerType_Time_FID); + jni_SetYear_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetMonth_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetDay_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetHour_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetMinute_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetSecond_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetIs_utc_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetIs_date_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_SetZone_in_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); +} + +void jni_GetTime_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalTriggerType, ICalTriggerType_Time_FID); + jni_GetYear_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetMonth_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetDay_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetHour_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetMinute_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetSecond_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetIs_utc_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetIs_date_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); + jni_GetZone_from_ICalTimeType(&(__ICalTriggerType_->time), env, lcl_jobj0); +} + +void jni_SetDuration_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalTriggerType, ICalTriggerType_Duration_FID); + jni_SetIs_neg_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_SetDays_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_SetWeeks_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_SetHours_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_SetMinutes_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_SetSeconds_in_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); +} + +void jni_GetDuration_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType) +{ + jobject lcl_jobj0; + lcl_jobj0 = env->GetObjectField(thisICalTriggerType, ICalTriggerType_Duration_FID); + jni_GetIs_neg_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_GetDays_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_GetWeeks_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_GetHours_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_GetMinutes_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); + jni_GetSeconds_from_ICalDurationType(&(__ICalTriggerType_->duration), env, lcl_jobj0); +} + +// copy all fields from the c struct (__ICalTriggerType_) to the java object (thisICalTriggerType). +void jni_SetAll_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv* env, jobject thisICalTriggerType) +{ + jni_SetTime_in_ICalTriggerType(__ICalTriggerType_, env, thisICalTriggerType); + jni_SetDuration_in_ICalTriggerType(__ICalTriggerType_, env, thisICalTriggerType); +} + +// copy all fields from the java object (thisICalTriggerType) to the c struct (__ICalTriggerType_). +void jni_GetAll_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv* env, jobject thisICalTriggerType) +{ + jni_GetTime_from_ICalTriggerType(__ICalTriggerType_, env, thisICalTriggerType); + jni_GetDuration_from_ICalTriggerType(__ICalTriggerType_, env, thisICalTriggerType); +} + +/* + * Class: net_cp_jlibical_ICalTriggerType + * Method: init + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTriggerType_init__J + (JNIEnv* env, jobject thisICalTriggerType, jlong data) +{ + // copy all fields from the c struct (data) to the java object (thisICalTimeType). + jni_SetAll_in_ICalTriggerType((ICalTriggerType*)data,env,thisICalTriggerType); +} + +/* + * Class: net_cp_jlibical_ICalTriggerType + * Method: initFIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTriggerType_initFIDs(JNIEnv *env, jclass clazz) { + initICalTriggerTypeFieldIDs(env, clazz); +} diff --git a/libical/src/java/jniICalTriggerType_cxx.h b/libical/src/java/jniICalTriggerType_cxx.h new file mode 100644 index 0000000000..62d6ec3e90 --- /dev/null +++ b/libical/src/java/jniICalTriggerType_cxx.h @@ -0,0 +1,39 @@ + +/*====================================================================== + FILE: jniICalTriggerType_cxx.h + CREATOR: structConverter + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _jni_ICalTriggerType_H +#define _jni_ICalTriggerType_H +#include <jni.h> + +// I forgot how to do this using a typedef in c++!!!! +#define ICalTriggerType icaltriggertype + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ical.h" + +static void initICalTriggerTypeFieldIDs(JNIEnv* env, jclass clazz); + +void jni_SetTime_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType); +void jni_GetTime_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType); +void jni_SetDuration_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType); +void jni_GetDuration_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv *env, jobject thisICalTriggerType); +void jni_SetAll_in_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv* env, jobject thisICalTriggerType); + +void jni_GetAll_from_ICalTriggerType(struct ICalTriggerType* __ICalTriggerType_, JNIEnv* env, jobject thisICalTriggerType); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTriggerType_init__J(JNIEnv* env, jobject thisICalTriggerType, jlong data); +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalTriggerType_initFIDs(JNIEnv *env, jclass clazz); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libical/src/java/net_cp_jlibical_ICalParameter_cxx.cpp b/libical/src/java/net_cp_jlibical_ICalParameter_cxx.cpp new file mode 100644 index 0000000000..2157473927 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalParameter_cxx.cpp @@ -0,0 +1,310 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: net_cp_jlibical_ICalParameter_cxx.cpp + CREATOR: gnorman 1/10/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef NET_CP_JLIBICAL_ICALPARAMETER_CXX_H +#include "net_cp_jlibical_ICalParameter_cxx.h" +#endif + +#ifndef JLIBICAL_CONSTS_CXX_H +#include "jlibical_consts_cxx.h" +#endif + +#ifndef JLIBICAL_UTILS_CXX_H +#include "jlibical_utils_cxx.h" +#endif + +#ifndef ICALPARAMETER_CXX_H +#include "icalparameter_cxx.h" +#endif + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalParameter_as_1ical_1string + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->as_ical_string(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_isa + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->isa(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: isa_parameter + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalParameter_isa_1parameter + (JNIEnv *env, jobject jobj, jobject arg) +{ + jboolean result = 0; + + // get the c++ object from the jobj + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the c++ object from the arg + void* argObjPtr = 0; + + if (arg != NULL) + { + argObjPtr = getCObjectPtr(env,arg); + } + + // get the result from the c++ object (candidateValue can be 0, it's cObj's responsibility to handle this if an error). + result = cObj->isa_parameter(argObjPtr) != 0; + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_language + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalParameter_get_1language + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_language(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_language + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1language + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_language((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_encoding + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1encoding + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_encoding(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_encoding + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1encoding + (JNIEnv *env, jobject jobj, jint value) +{ + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_encoding((icalparameter_encoding)value); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_role + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1role + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_role(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_role + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1role + (JNIEnv *env, jobject jobj, jint value) +{ + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_role((icalparameter_role)value); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_partstat + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1partstat + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_partstat(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_partstat + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1partstat + (JNIEnv *env, jobject jobj, jint value) +{ + ICalParameter* cObj = getSubjectAsICalParameter(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_partstat((icalparameter_partstat)value); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__ + (JNIEnv *env, jobject jobj) +{ + setCObjectPtr(env,jobj,new ICalParameter()); +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__Ljava_lang_String_2 + (JNIEnv *env, jobject jobj, jstring str) +{ + if (str != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + setCObjectPtr(env,jobj,new ICalParameter((char*)szTemp)); + env->ReleaseStringUTFChars(str,szTemp); + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__ILjava_lang_String_2 + (JNIEnv *env, jobject jobj, jint kind, jstring str) +{ + if (str != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + setCObjectPtr(env,jobj,new ICalParameter((icalparameter_kind)kind,(char*)szTemp)); + env->ReleaseStringUTFChars(str,szTemp); + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } +} + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__I + (JNIEnv *env, jobject jobj, jint kind) +{ + setCObjectPtr(env,jobj,new ICalParameter((icalparameter_kind)kind)); +} diff --git a/libical/src/java/net_cp_jlibical_ICalParameter_cxx.h b/libical/src/java/net_cp_jlibical_ICalParameter_cxx.h new file mode 100644 index 0000000000..f2fef299a4 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalParameter_cxx.h @@ -0,0 +1,143 @@ + +/*====================================================================== + FILE: net_cp_jlibical_ICalParameter_cxx.h + CREATOR: javah 1/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _Included_net_cp_jlibical_ICalParameter +#define _Included_net_cp_jlibical_ICalParameter + +#ifndef JNI_H +#include <jni.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalParameter_as_1ical_1string + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_isa + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: isa_parameter + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalParameter_isa_1parameter + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_language + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalParameter_get_1language + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_language + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1language + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_encoding + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1encoding + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_encoding + * Signature: (I)V + */ + +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1encoding + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_role + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1role + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_role + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1role + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: get_partstat + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalParameter_get_1partstat + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: set_partstat + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_set_1partstat + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__ + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__Ljava_lang_String_2 + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__ILjava_lang_String_2 + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: net_cp_jlibical_ICalParameter + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalParameter_init__I + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libical/src/java/net_cp_jlibical_ICalProperty_cxx.cpp b/libical/src/java/net_cp_jlibical_ICalProperty_cxx.cpp new file mode 100644 index 0000000000..4334354bd8 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalProperty_cxx.cpp @@ -0,0 +1,1690 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: net_cp_jlibical_ICalProperty_cxx.cpp + CREATOR: gnorman 1/10/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef NET_CP_JLIBICAL_ICALPROPERTY_CXX_H +#include "net_cp_jlibical_ICalProperty_cxx.h" +#endif + +#ifndef JLIBICAL_CONSTS_CXX_H +#include "jlibical_consts_cxx.h" +#endif + +#ifndef JLIBICAL_UTILS_CXX_H +#include "jlibical_utils_cxx.h" +#endif + +#ifndef ICALPROPERTY_CXX_H +#include "icalproperty_cxx.h" +#endif + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_as_1ical_1string + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->as_ical_string(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_isa + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->isa(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: isa_property + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalProperty_isa_1property + (JNIEnv *env, jobject jobj, jobject arg) +{ + jboolean result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + void* argObjPtr = 0; + + if (arg != NULL) + { + argObjPtr = getCObjectPtr(env,arg); + } + + // get the result from the c++ object (argObjPtr can be 0, it's cObj's responsibility to handle this if an error). + result = cObj->isa_property(argObjPtr) != 0; + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: add_parameter + * Signature: (Lnet/cp/jlibical/ICalParameter;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_add_1parameter + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + ICalParameter* icalparameter = getSubjectAsICalParameter(env,arg,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (icalparameter != NULL) + { + cObj->add_parameter(*icalparameter); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_parameter + * Signature: (Lnet/cp/jlibical/ICalParameter;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1parameter + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + ICalParameter* icalparameter = getSubjectAsICalParameter(env,arg,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (icalparameter != NULL) + { + cObj->set_parameter(*icalparameter); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_parameter_from_string + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1parameter_1from_1string + (JNIEnv *env, jobject jobj, jstring name, jstring value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szName = env->GetStringUTFChars(name,NULL); + const char* szValue = env->GetStringUTFChars(value,NULL); + + if (szName != NULL && szValue != NULL) + { + cObj->set_parameter_from_string((string)szName, (string)szValue); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_parameter_as_string + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1parameter_1as_1string + (JNIEnv *env, jobject jobj, jstring name) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szName = env->GetStringUTFChars(name,NULL); + + if (szName != NULL) + { + char* szValue = cObj->get_parameter_as_string((string)szName); + + if (szValue == NULL) + { + szValue = ""; + } + + result = env->NewStringUTF(szValue); + } + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: remove_parameter + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_remove_1parameter + (JNIEnv *env, jobject jobj, jint kind) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->remove_parameter((icalparameter_kind)kind); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: count_parameters + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_count_1parameters + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->count_parameters(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_first_parameter + * Signature: (I)Lnet/cp/jlibical/ICalParameter; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1first_1parameter + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first parameter from CObj + ICalParameter* aParameter = cObj->get_first_parameter((icalparameter_kind)kind); + + // create a new surrogate, using aParameter as the subject (returns NULL if subject is NULL). + result = createNewICalParameterSurrogate(env,aParameter); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_next_parameter + * Signature: (I)Lnet/cp/jlibical/ICalParameter; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1next_1parameter + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first parameter from CObj + ICalParameter* aParameter = cObj->get_next_parameter((icalparameter_kind)kind); + + // create a new surrogate, using aParameter as the subject (returns NULL if subject is NULL). + result = createNewICalParameterSurrogate(env,aParameter); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_value + * Signature: (Lnet/cp/jlibical/ICalValue;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1value + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + ICalValue* aValue = getSubjectAsICalValue(env,arg,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + cObj->set_value(*aValue); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_value_from_string + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1value_1from_1string + (JNIEnv *env, jobject jobj, jstring name, jstring value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szName = env->GetStringUTFChars(name,NULL); + const char* szValue = env->GetStringUTFChars(value,NULL); + + if (szName != NULL && szValue != NULL) + { + cObj->set_value_from_string((string)szName, (string)szValue); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_value + * Signature: ()Lnet/cp/jlibical/ICalValue; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1value + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first value from CObj + ICalValue* aValue = cObj->get_value(); + + // create a new surrogate, using aValue as the subject (returns NULL if subject is NULL). + result = createNewICalValueSurrogate(env,aValue); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_value_as_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1value_1as_1string + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_value_as_string(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_name + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1name + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_name(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_action + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1action + (JNIEnv *env, jobject jobj, jint value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_action((icalproperty_action)value); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_action + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1action + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_action(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_attendee + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1attendee + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_attendee((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_attendee + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1attendee + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_attendee(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_comment + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1comment + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_comment((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_comment + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1comment + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* commentStr = cObj->get_comment(); + + if (commentStr == NULL) + { + commentStr = ""; + } + + result = env->NewStringUTF(commentStr); + } + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_description + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1description + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_description((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_description + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1description + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_description(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtend + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtend + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aTime; + + if (copyObjToicaltimetype(env,arg,&aTime)) + { + cObj->set_dtend(aTime); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtend + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtend + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaltimetype aTime = cObj->get_dtend(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTimeType(env,&aTime); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtstamp + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtstamp + (JNIEnv *env, jobject jobj, jobject dtstamp) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aDTStamp; + + if (copyObjToicaltimetype(env,dtstamp,&aDTStamp)) + { + cObj->set_dtstamp(aDTStamp); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtstamp + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtstamp + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtstamp time from CObj + icaltimetype aDTStamp = cObj->get_dtstamp(); + + // create a new surrogate, using aDTStamp as the subject. + result = createNewICalTimeType(env,&aDTStamp); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtstart + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtstart + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aTime; + + if (copyObjToicaltimetype(env,arg,&aTime)) + { + cObj->set_dtstart(aTime); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtstart + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtstart + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaltimetype aTime = cObj->get_dtstart(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTimeType(env,&aTime); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_due + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1due + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aTime; + + if (copyObjToicaltimetype(env,arg,&aTime)) + { + cObj->set_due(aTime); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_due + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1due + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaltimetype aTime = cObj->get_due(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTimeType(env,&aTime); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1duration + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaldurationtype aDuration; + + if (copyObjToicaldurationtype(env,arg,&aDuration)) + { + cObj->set_duration(aDuration); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1duration + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaldurationtype aDuration = cObj->get_duration(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalDurationType(env,&aDuration); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_location + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1location + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_location((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_location + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1location + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_location(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1method + (JNIEnv *env, jobject jobj, jint value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_method((icalproperty_method)value); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1method + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_method(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_organizer + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1organizer + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_organizer((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_organizer + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1organizer + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* organizerStr = cObj->get_organizer(); + + if (organizerStr == NULL) + { + organizerStr = ""; + } + + result = env->NewStringUTF(organizerStr); + } + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_owner + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1owner + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_owner((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_owner + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1owner + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_owner(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_prodid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1prodid + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_prodid((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_prodid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1prodid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_prodid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_query + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1query + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_query((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_query + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1query + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_query(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_queryname + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1queryname + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_queryname((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_queryname + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1queryname + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_queryname(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_repeat + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1repeat + (JNIEnv *env, jobject jobj, jint value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_repeat(value); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_repeat + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1repeat + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_repeat(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_summary + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1summary + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_summary((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_summary + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1summary + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_summary(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_target + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1target + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_target((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_target + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1target + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_target(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_trigger + * Signature: (Lnet/cp/jlibical/ICalTriggerType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1trigger + (JNIEnv *env, jobject jobj, jobject arg) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltriggertype aTrigger; + + if (copyObjToicaltriggertype(env,arg,&aTrigger)) + { + cObj->set_trigger(aTrigger); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_trigger + * Signature: ()Lnet/cp/jlibical/ICalTriggerType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1trigger + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaltriggertype aTrigger = cObj->get_trigger(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTriggerType(env,&aTrigger); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_tzid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1tzid + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_tzid((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_tzid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1tzid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_tzid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_uid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1uid + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_uid((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_uid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1uid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_uid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__ + (JNIEnv *env, jobject jobj) +{ + setCObjectPtr(env,jobj,new ICalProperty()); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__Ljava_lang_String_2 + (JNIEnv *env, jobject jobj, jstring str) +{ + if (str != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + setCObjectPtr(env,jobj,new ICalProperty((char*)szTemp)); + env->ReleaseStringUTFChars(str,szTemp); + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__I + (JNIEnv *env, jobject jobj, jint kind) +{ + setCObjectPtr(env,jobj,new ICalProperty((icalproperty_kind)kind)); +} + + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_status + * Signature: (I)V + */ + +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1status + (JNIEnv *env, jobject jobj, jint value) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_status((icalproperty_status)value); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_status + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1status + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_status(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_relcalid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1relcalid + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_relcalid((char *)szTemp); + + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_relcalid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1relcalid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_relcalid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_exdate + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1exdate + (JNIEnv *env, jobject jobj, jobject exdate) +{ + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aExDate; + + if (copyObjToicaltimetype(env,exdate,&aExDate)) + { + cObj->set_exdate(aExDate); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_exdate + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1exdate + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the exdate from CObj + icaltimetype aExDate = cObj->get_exdate(); + + // create a new surrogate, using aRecurrenceId as the subject. + result = createNewICalTimeType(env,&aExDate); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_exrule + * Signature: (Lnet/cp/jlibical/ICalRecurrenceType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1exrule + (JNIEnv *env, jobject jobj, jobject exrule) +{ + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + icalrecurrencetype aExRule; + if (copyObjToicalrecurrencetype(env,exrule,&aExRule)) + { + cObj->set_exrule(aExRule); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_exrule + * Signature: ()Lnet/cp/jlibical/ICalRecurrenceType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1exrule + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the exrule from CObj + icalrecurrencetype aExRule = cObj->get_exrule(); + + // create a new surrogate, using aExRule as the subject. + result = createNewICalRecurrenceType(env,&aExRule); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_freebusy + * Signature: (Lnet/cp/jlibical/ICalPeriodType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1freebusy + (JNIEnv *env, jobject jobj, jobject period) +{ + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icalperiodtype aPeriod; + + if (copyObjToicalperiodtype(env,period,&aPeriod)) + { + cObj->set_freebusy(aPeriod); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_freebusy + * Signature: ()Lnet/cp/jlibical/ICalPeriodType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1freebusy + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the period from CObj + icalperiodtype aPeriod = cObj->get_freebusy(); + + // create a new surrogate, using aPeriod as the subject. + result = createNewICalPeriodType(env,&aPeriod); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_recurrenceid + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1recurrenceid + (JNIEnv *env, jobject jobj, jobject recurrenceid) +{ + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aRecurrenceId; + + if (copyObjToicaltimetype(env,recurrenceid,&aRecurrenceId)) + { + cObj->set_recurrenceid(aRecurrenceId); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_recurrenceid + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1recurrenceid + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the exdate from CObj + icaltimetype aRecurrenceId = cObj->get_recurrenceid(); + + // create a new surrogate, using aRecurrenceId as the subject. + result = createNewICalTimeType(env,&aRecurrenceId); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_rrule + * Signature: (Lnet/cp/jlibical/ICalRecurrenceType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1rrule + (JNIEnv *env, jobject jobj, jobject rrule) +{ + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icalrecurrencetype aRRule; + + if (copyObjToicalrecurrencetype(env,rrule,&aRRule)) + { + cObj->set_rrule(aRRule); + } + } +} + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_rrule + * Signature: ()Lnet/cp/jlibical/ICalRecurrenceType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1rrule + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the ICalProperty c++ object from jobj + ICalProperty* cObj = getSubjectAsICalProperty(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the rrule from CObj + icalrecurrencetype aRRule = cObj->get_rrule(); + + // create a new surrogate, using aExRule as the subject. + result = createNewICalRecurrenceType(env,&aRRule); + } + + return(result); +} diff --git a/libical/src/java/net_cp_jlibical_ICalProperty_cxx.h b/libical/src/java/net_cp_jlibical_ICalProperty_cxx.h new file mode 100644 index 0000000000..686ae9a0e8 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalProperty_cxx.h @@ -0,0 +1,654 @@ + +/*====================================================================== + FILE: net_cp_jlibical_ICalProperty_cxx.h + CREATOR: javah 1/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _Included_net_cp_jlibical_ICalProperty +#define _Included_net_cp_jlibical_ICalProperty + +#ifndef JNI_H +#include <jni.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_as_1ical_1string + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_isa + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: isa_property + * Signature: (Ljava/lang/Object;)I + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalProperty_isa_1property + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: add_parameter + * Signature: (Lnet/cp/jlibical/ICalParameter;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_add_1parameter + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_parameter + * Signature: (Lnet/cp/jlibical/ICalParameter;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1parameter + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_parameter_from_string + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1parameter_1from_1string + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_parameter_as_string + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1parameter_1as_1string + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: remove_parameter + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_remove_1parameter + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: count_parameters + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_count_1parameters + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_first_parameter + * Signature: (I)Lnet/cp/jlibical/ICalParameter; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1first_1parameter + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_next_parameter + * Signature: (I)Lnet/cp/jlibical/ICalParameter; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1next_1parameter + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_value + * Signature: (Lnet/cp/jlibical/ICalValue;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1value + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_value_from_string + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1value_1from_1string + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_value + * Signature: ()Lnet/cp/jlibical/ICalValue; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1value + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_value_as_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1value_1as_1string + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_name + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1name + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: icalparameter_value_to_value_kind + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_icalparameter_1value_1to_1value_1kind + (JNIEnv *, jclass, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_action + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1action + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_action + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1action + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_attendee + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1attendee + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_attendee + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1attendee + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_comment + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1comment + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_comment + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1comment + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_description + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1description + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_description + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1description + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtend + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtend + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtend + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtend + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtstamp + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtstamp + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtstamp + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtstamp + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_dtstart + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1dtstart + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_dtstart + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1dtstart + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_due + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1due + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_due + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1due + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1duration + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1duration + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_location + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1location + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_location + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1location + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1method + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1method + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_organizer + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1organizer + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_organizer + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1organizer + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_owner + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1owner + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_owner + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1owner + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_prodid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1prodid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_prodid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1prodid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_query + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1query + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_query + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1query + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_queryname + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1queryname + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_queryname + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1queryname + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_repeat + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1repeat + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_repeat + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1repeat + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_summary + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1summary + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_summary + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1summary + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_target + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1target + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_target + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1target + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_trigger + * Signature: (Lnet/cp/jlibical/ICalTriggerType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1trigger + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_trigger + * Signature: ()Lnet/cp/jlibical/ICalTriggerType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1trigger + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_tzid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1tzid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_tzid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1tzid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_uid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1uid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_uid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1uid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__ + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__Ljava_lang_String_2 + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__ILjava_lang_String_2 + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_init__I + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_status + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1status + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_status + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalProperty_get_1status + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_relcalid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1relcalid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_relcalid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalProperty_get_1relcalid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_exdate + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1exdate + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_exdate + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1exdate + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_exrule + * Signature: (Lnet/cp/jlibical/ICalRecurrenceType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1exrule + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_exrule + * Signature: ()Lnet/cp/jlibical/ICalRecurrenceType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1exrule + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_freebusy + * Signature: (Lnet/cp/jlibical/ICalPeriodType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1freebusy + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_freebusy + * Signature: ()Lnet/cp/jlibical/ICalPeriodType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1freebusy + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_recurrenceid + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1recurrenceid + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_recurrenceid + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1recurrenceid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: set_rrule + * Signature: (Lnet/cp/jlibical/ICalRecurrenceType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalProperty_set_1rrule + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalProperty + * Method: get_rrule + * Signature: ()Lnet/cp/jlibical/ICalRecurrenceType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalProperty_get_1rrule + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libical/src/java/net_cp_jlibical_ICalValue_cxx.cpp b/libical/src/java/net_cp_jlibical_ICalValue_cxx.cpp new file mode 100644 index 0000000000..de2adac88f --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalValue_cxx.cpp @@ -0,0 +1,436 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: net_cp_jlibical_ICalValue_cxx.cpp + CREATOR: gnorman 1/10/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef NET_CP_JLIBICAL_ICALVALUE_CXX_H +#include "net_cp_jlibical_ICalValue_cxx.h" +#endif + +#ifndef JLIBICAL_CONSTS_CXX_H +#include "jlibical_consts_cxx.h" +#endif + +#ifndef JLIBICAL_UTILS_CXX_H +#include "jlibical_utils_cxx.h" +#endif + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +/* + * Class: net_cp_jlibical_ICalValue + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_as_1ical_1string + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->as_ical_string(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_isa + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->isa(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: isa_value + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalValue_isa_1value + (JNIEnv *env, jobject jobj, jobject arg) +{ + jboolean result = 0; + + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the c++ object from arg + void* argObjPtr = 0; + + if (arg != NULL) + { + argObjPtr = getCObjectPtr(env,jobj); + } + + // get the result from the c++ object + result = cObj->isa_value(argObjPtr) != 0; + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_trigger + * Signature: (Lnet/cp/jlibical/ICalTriggerType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1trigger + (JNIEnv *env, jobject jobj, jobject arg) +{ + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + icaltriggertype aTrigger; + + if (copyObjToicaltriggertype(env,arg,&aTrigger)) + { + cObj->set_trigger(aTrigger); + } + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_trigger + * Signature: ()Lnet/cp/jlibical/ICalTriggerType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1trigger + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the trigger from CObj + icaltriggertype aTrigger = cObj->get_trigger(); + + // create a new surrogate, using aTrigger as the subject. + result = createNewICalTriggerType(env,&aTrigger); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1method + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_method(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1method + (JNIEnv *env, jobject jobj, jint value) +{ + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_method((icalproperty_method)value); + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_text + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1text + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_text(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_text + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1text + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_text((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1duration + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the duration from CObj + icaldurationtype aDuration = cObj->get_duration(); + + // create a new surrogate, using aDuration as the subject. + result = createNewICalDurationType(env,&aDuration); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1duration + (JNIEnv *env, jobject jobj, jobject arg) +{ + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaldurationtype aDuration; + + if (copyObjToicaldurationtype(env,arg,&aDuration)) + { + cObj->set_duration(aDuration); + } + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_query + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1query + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_query(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_query + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1query + (JNIEnv *env, jobject jobj, jstring str) +{ + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_query((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_datetime + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1datetime + (JNIEnv *env, jobject jobj) +{ + jobject result = NULL; + + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aTime = cObj->get_datetime(); + result = createNewICalTimeType(env,&aTime); + } + + return (result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_datetime + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1datetime + (JNIEnv *env, jobject jobj, jobject arg) +{ + // get the c++ object from the jobj + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aTime; + + if (copyObjToicaltimetype(env,arg,&aTime)) + { + cObj->set_datetime(aTime); + } + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_action + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1action + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_action(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_action + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1action + (JNIEnv *env, jobject jobj, jint value) +{ + ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_action((icalproperty_action)value); + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__ + (JNIEnv *env, jobject jobj) +{ + setCObjectPtr(env,jobj,new ICalValue()); +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__ILjava_lang_String_2 + (JNIEnv *env, jobject jobj, jint kind, jstring str) +{ + if (str != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + setCObjectPtr(env,jobj,new ICalValue((icalvalue_kind)kind,(char*)szTemp)); + env->ReleaseStringUTFChars(str,szTemp); + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } +} + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__I + (JNIEnv *env, jobject jobj, jint kind) +{ + setCObjectPtr(env,jobj,new ICalValue((icalvalue_kind)kind)); +} diff --git a/libical/src/java/net_cp_jlibical_ICalValue_cxx.h b/libical/src/java/net_cp_jlibical_ICalValue_cxx.h new file mode 100644 index 0000000000..989cf59a99 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_ICalValue_cxx.h @@ -0,0 +1,182 @@ + +/*====================================================================== + FILE: net_cp_jlibical_ICalValue_cxx.h + CREATOR: javah 1/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _Included_net_cp_jlibical_ICalValue +#define _Included_net_cp_jlibical_ICalValue + +#ifndef JNI_H +#include <jni.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_cp_jlibical_ICalValue + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_as_1ical_1string + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_isa + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: isa_value + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalValue_isa_1value + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_trigger + * Signature: (Lnet/cp/jlibical/ICalTriggerType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1trigger + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_trigger + * Signature: ()Lnet/cp/jlibical/ICalTriggerType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1trigger + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1method + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1method + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_text + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1text + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_text + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1text + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1duration + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1duration + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_query + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1query + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_query + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1query + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_datetime + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1datetime + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_datetime + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1datetime + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: get_action + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1action + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: set_action + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1action + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__ + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__ILjava_lang_String_2 + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: net_cp_jlibical_ICalValue + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__I + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libical/src/java/net_cp_jlibical_VComponent_cxx.cpp b/libical/src/java/net_cp_jlibical_VComponent_cxx.cpp new file mode 100644 index 0000000000..e9dc6a4cc8 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_VComponent_cxx.cpp @@ -0,0 +1,956 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: net_cp_jlibical_VComponent_cxx.cpp + CREATOR: gnorman 1/10/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef NET_CP_JLIBICAL_VCOMPONENT_CXX_H +#include "net_cp_jlibical_VComponent_cxx.h" +#endif + +#ifndef JLIBICAL_CONSTS_CXX_H +#include "jlibical_consts_cxx.h" +#endif + +#ifndef JLIBICAL_UTILS_CXX_H +#include "jlibical_utils_cxx.h" +#endif + +#ifndef VCOMPONENT_CXX_H +#include "vcomponent.h" +#endif + +#ifndef ICALPROPERTY_CXX_H +#include "icalproperty_cxx.h" +#endif + +/* + * Class: net_cp_jlibical_VComponent + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_as_1ical_1string + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->as_ical_string(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_isa + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->isa(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: isa_component + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_VComponent_isa_1component + (JNIEnv *env, jobject jobj, jobject candidateObj) +{ + jboolean result = 0; + + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + void* candidateValue = 0; + + if (candidateObj != NULL) + { + // get the c++ object from candidateObj (as long) + candidateValue = getCObjectPtr(env,candidateObj); + } + + // get the result from the c++ object (candidateValue can be 0, it's cObj's responsibility to handle this if an error). + result = cObj->isa_component(candidateValue) != 0; + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: add_property + * Signature: (Lnet/cp/jlibical/ICalProperty;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_add_1property + (JNIEnv *env, jobject jobj, jobject jprop) +{ + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the ICalProperty c++ object from jprop + ICalProperty* icalProperty = getSubjectAsICalProperty(env,jprop,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (icalProperty != NULL) + { + cObj->add_property(icalProperty); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: remove_property + * Signature: (Lnet/cp/jlibical/ICalProperty;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_remove_1property + (JNIEnv *env, jobject jobj, jobject jprop) +{ + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the ICalProperty c++ object from jprop + ICalProperty* icalProperty = getSubjectAsICalProperty(env,jprop,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (icalProperty != NULL) + { + cObj->remove_property(icalProperty); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: count_properties + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_count_1properties + (JNIEnv *env, jobject jobj, jint kind) +{ + jint result = 0; + + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + result = cObj->count_properties((icalproperty_kind)kind); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_current_property + * Signature: ()Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1current_1property + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the current property from CObj + ICalProperty* aProperty = cObj->get_current_property(); + + // create a new surrogate, using aProperty as the subject (returns NULL if subject is NULL). + result = createNewICalPropertySurrogate(env,aProperty); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_property + * Signature: (I)Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1property + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first property from CObj + ICalProperty* aProperty = cObj->get_first_property((icalproperty_kind)kind); + + // create a new surrogate, using aProperty as the subject (returns NULL if subject is NULL). + result = createNewICalPropertySurrogate(env,aProperty); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_next_property + * Signature: (I)Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1next_1property + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the next property from CObj + ICalProperty* aProperty = cObj->get_next_property((icalproperty_kind)kind); + + // create a new surrogate, using aProperty as the subject (returns NULL if subject is NULL). + result = createNewICalPropertySurrogate(env,aProperty); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_inner + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1inner + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the next property from CObj + VComponent* inner = cObj->get_inner(); + + // create a new surrogate, using inner as the subject (returns NULL if subject is NULL). + result = createNewVComponentSurrogate(env,inner); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: add_component + * Signature: (Lnet/cp/jlibical/VComponent;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_add_1component + (JNIEnv *env, jobject jobj, jobject jcomp) +{ + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the VComponent c++ object from jcomp + VComponent* aComponent = getSubjectAsVComponent(env,jcomp,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (aComponent != NULL) + { + cObj->add_component(aComponent); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: remove_component + * Signature: (Lnet/cp/jlibical/VComponent;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_remove_1component + (JNIEnv *env, jobject jobj, jobject jcomp) +{ + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + // get the VComponent c++ object from jcomp + VComponent* aComponent = getSubjectAsVComponent(env,jcomp,JLIBICAL_ERR_ILLEGAL_ARGUMENT); + + if (aComponent != NULL) + { + cObj->remove_component(aComponent); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: count_components + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_count_1components + (JNIEnv *env, jobject jobj, jint kind) +{ + jint result = 0; + + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + if (cObj != NULL) + { + result = cObj->count_components((icalcomponent_kind)kind); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_current_component + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1current_1component + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the next property from CObj + VComponent* aComponent = cObj->get_current_component(); + + // create a new surrogate, using aComponent as the subject (returns NULL if subject is NULL). + result = createNewVComponentSurrogate(env,aComponent); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_component + * Signature: (I)Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1component + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first component from CObj + VComponent* aComponent = cObj->get_first_component((icalcomponent_kind)kind); + + // create a new surrogate, using aComponent as the subject (returns NULL if subject is NULL). + result = createNewVComponentSurrogate(env,aComponent); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_next_component + * Signature: (I)Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1next_1component + (JNIEnv *env, jobject jobj, jint kind) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first component from CObj + VComponent* aComponent = cObj->get_next_component((icalcomponent_kind)kind); + + // create a new surrogate, using aComponent as the subject (returns NULL if subject is NULL). + result = createNewVComponentSurrogate(env,aComponent); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtstart + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtstart + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtstart time from CObj + icaltimetype aTime = cObj->get_dtstart(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTimeType(env,&aTime); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtstart + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtstart + (JNIEnv *env, jobject jobj, jobject dtstart) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aStartTime; + + if (copyObjToicaltimetype(env,dtstart,&aStartTime)) + { + cObj->set_dtstart(aStartTime); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtend + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtend + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the dtend time from CObj + icaltimetype aTime = cObj->get_dtend(); + + // create a new surrogate, using aTime as the subject. + result = createNewICalTimeType(env,&aTime); + + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtend + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtend + (JNIEnv *env, jobject jobj, jobject dtend) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype anEndTime; + + if (copyObjToicaltimetype(env,dtend,&anEndTime)) + { + cObj->set_dtend(anEndTime); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1duration + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the duration time from CObj + icaldurationtype aDuration = cObj->get_duration(); + + // create a new surrogate, using aDuration as the subject. + result = createNewICalDurationType(env,&aDuration); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1duration + (JNIEnv *env, jobject jobj, jobject duration) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaldurationtype aDuration; + + if (copyObjToicaldurationtype(env,duration,&aDuration)) + { + cObj->set_duration(aDuration); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_get_1method + (JNIEnv *env, jobject jobj) +{ + jint result = 0; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + result = cObj->get_method(); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1method + (JNIEnv *env, jobject jobj, jint value) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + cObj->set_method((icalproperty_method)value); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_summary + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1summary + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_summary(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_summary + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1summary + (JNIEnv *env, jobject jobj, jstring str) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_summary((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtstamp + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtstamp + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the recurrenceid from CObj + icaltimetype aDTStamp = cObj->get_dtstamp(); + + // create a new surrogate, using aRecurrenceId as the subject. + result = createNewICalTimeType(env,&aDTStamp); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtstamp + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtstamp + (JNIEnv *env, jobject jobj, jobject dtstamp) +{ + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aDTStamp; + + if (copyObjToicaltimetype(env,dtstamp,&aDTStamp)) + { + cObj->set_dtstamp(aDTStamp); + } + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_location + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1location + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_location(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_location + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1location + (JNIEnv *env, jobject jobj, jstring str) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_summary((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_description + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1description + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_description(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_description + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1description + (JNIEnv *env, jobject jobj, jstring str) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_summary((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} +/* + * Class: net_cp_jlibical_VComponent + * Method: get_uid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1uid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_uid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_uid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1uid + (JNIEnv *env, jobject jobj, jstring str) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_uid((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_real_component + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1real_1component + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the first component from CObj + VComponent* aComponent = cObj->get_first_real_component(); + + // create a new surrogate, using aComponent as the subject (returns NULL if subject is NULL). + result = createNewVComponentSurrogate(env,aComponent); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__ + (JNIEnv *env, jobject jobj) +{ + setCObjectPtr(env,jobj,new VComponent()); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__Ljava_lang_String_2 + (JNIEnv *env, jobject jobj, jstring str) +{ + if (str != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + setCObjectPtr(env,jobj,new VComponent((char*)szTemp)); + env->ReleaseStringUTFChars(str,szTemp); + } + else + { + throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT ); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__I + (JNIEnv *env, jobject jobj, jint kind) +{ + setCObjectPtr(env,jobj,new VComponent((icalcomponent_kind)kind)); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_relcalid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1relcalid + (JNIEnv *env, jobject jobj, jstring str) +{ + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + const char* szTemp = env->GetStringUTFChars(str,NULL); + + cObj->set_relcalid((char*)szTemp); + env->ReleaseStringUTFChars(str,szTemp); + } +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_relcalid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1relcalid + (JNIEnv *env, jobject jobj) +{ + jstring result = NULL; + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + char* icalStr = cObj->get_relcalid(); + + if (icalStr == NULL) + { + icalStr = ""; + } + + result = env->NewStringUTF(icalStr); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_recurrenceid + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1recurrenceid + (JNIEnv *env, jobject jobj) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + // get the recurrenceid from CObj + icaltimetype aRecurrenceId = cObj->get_recurrenceid(); + + // create a new surrogate, using aRecurrenceId as the subject. + result = createNewICalTimeType(env,&aRecurrenceId); + } + + return(result); +} + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_recurrenceid + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1recurrenceid + (JNIEnv *env, jobject jobj, jobject recurrenceid) +{ + jobject result = 0; + // get the VComponent c++ object from jobj + VComponent* cObj = getSubjectAsVComponent(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL); + + if (cObj != NULL) + { + icaltimetype aRecurrenceId; + + if (copyObjToicaltimetype(env,recurrenceid,&aRecurrenceId)) + { + cObj->set_recurrenceid(aRecurrenceId); + } + } +} diff --git a/libical/src/java/net_cp_jlibical_VComponent_cxx.h b/libical/src/java/net_cp_jlibical_VComponent_cxx.h new file mode 100644 index 0000000000..ad2dfb60a4 --- /dev/null +++ b/libical/src/java/net_cp_jlibical_VComponent_cxx.h @@ -0,0 +1,358 @@ + +/*====================================================================== + FILE: net_cp_jlibical_VComponent_cxx.h + CREATOR: javah 1/11/02 + (C) COPYRIGHT 2002, Critical Path +======================================================================*/ + +#ifndef _Included_net_cp_jlibical_VComponent +#define _Included_net_cp_jlibical_VComponent + +#ifndef JNI_H +#include <jni.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: net_cp_jlibical_VComponent + * Method: as_ical_string + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_as_1ical_1string + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: isa + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_isa + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: isa_component + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_VComponent_isa_1component + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: add_property + * Signature: (Lnet/cp/jlibical/ICalProperty;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_add_1property + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: remove_property + * Signature: (Lnet/cp/jlibical/ICalProperty;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_remove_1property + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: count_properties + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_count_1properties + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_current_property + * Signature: ()Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1current_1property + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_property + * Signature: (I)Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1property + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_next_property + * Signature: (I)Lnet/cp/jlibical/ICalProperty; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1next_1property + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_inner + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1inner + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: add_component + * Signature: (Lnet/cp/jlibical/VComponent;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_add_1component + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: remove_component + * Signature: (Lnet/cp/jlibical/VComponent;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_remove_1component + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: count_components + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_count_1components + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_current_component + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1current_1component + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_component + * Signature: (I)Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1component + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_next_component + * Signature: (I)Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1next_1component + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtstart + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtstart + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtstart + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtstart + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtend + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtend + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtend + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtend + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_duration + * Signature: ()Lnet/cp/jlibical/ICalDurationType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1duration + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_duration + * Signature: (Lnet/cp/jlibical/ICalDurationType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1duration + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_method + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_cp_jlibical_VComponent_get_1method + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_method + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1method + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_summary + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1summary + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_summary + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1summary + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_dtstamp + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1dtstamp + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_dtstamp + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1dtstamp + (JNIEnv *, jobject, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_location + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1location + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_location + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1location + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_description + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1description + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_description + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1description + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_uid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1uid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_uid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1uid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_first_real_component + * Signature: ()Lnet/cp/jlibical/VComponent; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1first_1real_1component + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__ + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__Ljava_lang_String_2 + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: init + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_init__I + (JNIEnv *, jobject, jint); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_relcalid + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_cp_jlibical_VComponent_get_1relcalid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_relcalid + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1relcalid + (JNIEnv *, jobject, jstring); + +/* + * Class: net_cp_jlibical_VComponent + * Method: get_recurrenceid + * Signature: ()Lnet/cp/jlibical/ICalTimeType; + */ +JNIEXPORT jobject JNICALL Java_net_cp_jlibical_VComponent_get_1recurrenceid + (JNIEnv *, jobject); + +/* + * Class: net_cp_jlibical_VComponent + * Method: set_recurrenceid + * Signature: (Lnet/cp/jlibical/ICalTimeType;)V + */ +JNIEXPORT void JNICALL Java_net_cp_jlibical_VComponent_set_1recurrenceid + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libical/src/java/testjni.java b/libical/src/java/testjni.java new file mode 100644 index 0000000000..a7eb5886a1 --- /dev/null +++ b/libical/src/java/testjni.java @@ -0,0 +1,377 @@ +package net.cp.jlibical; + +import java.lang.String; + +public class testjni +{ + static final String content = "BEGIN:VCALENDAR\nVERSION:2.1\nBEGIN:VEVENT\nUID:abcd12345\nDTSTART:20020307T180000Z\nDTEND:20020307T190000Z\nSUMMARY:Important Meeting\nEND:VEVENT\nEND:VCALENDAR"; + public static void main(String[] args) + { + // VAGENDA test case + + ICalProperty calidProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RELCALID_PROPERTY); + ICalProperty ownerProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_OWNER_PROPERTY); + + calidProp.set_relcalid("1212"); + ownerProp.set_owner("Bill Smith"); + + VAgenda vAgenda = new VAgenda(); + vAgenda.add_property(calidProp); + vAgenda.add_property(ownerProp); + + System.out.println("VAgenda:\n" + vAgenda.as_ical_string()); + + // VEVENT test case + + ICalProperty summProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_SUMMARY_PROPERTY); + ICalProperty startProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTSTART_PROPERTY); + ICalProperty endProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTEND_PROPERTY); + + ICalProperty locationProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_LOCATION_PROPERTY); + ICalProperty descProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DESCRIPTION_PROPERTY); + + ICalTimeType starttime = new ICalTimeType(); + starttime.setYear(2001); + starttime.setMonth(12); + starttime.setDay(21); + starttime.setHour(18); + starttime.setMinute(0); + starttime.setSecond(0); + starttime.setIs_utc(true); + System.out.println("done creating starttime"); + + ICalTimeType endtime = new ICalTimeType(); + endtime.setYear(2002); + endtime.setMonth(1); + endtime.setDay(1); + endtime.setHour(8); + endtime.setMinute(0); + endtime.setSecond(0); + endtime.setIs_utc(true); + System.out.println("done creating endtime"); + + + // START - get, set_exdate + ICalProperty property_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_EXDATE_PROPERTY); + property_tma.set_exdate(starttime); + ICalTimeType starttime_return = property_tma.get_exdate(); + System.out.println("****** property - exdate ******"); + System.out.println("setYear=" + starttime_return.getYear()); + System.out.println("setMonth=" + starttime_return.getMonth()); + System.out.println("setDay=" + starttime_return.getDay()); + System.out.println("setHour=" + starttime_return.getHour()); + System.out.println("setMinute=" + starttime_return.getMinute()); + System.out.println("setSecond=" + starttime_return.getSecond()); + System.out.println("******* property - exdate *****"); + + // END - get, set exdate + + // START - get, set exrule + ICalProperty property_exrule_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_EXRULE_PROPERTY); + ICalRecurrenceType exrule_tma = new ICalRecurrenceType(); + exrule_tma.setUntil(starttime); + exrule_tma.setFreq(ICalRecurrenceType.ICalRecurrenceTypeFrequency.ICAL_MINUTELY_RECURRENCE); + exrule_tma.setWeek_start(ICalRecurrenceType.ICalRecurrenceTypeWeekday.ICAL_SUNDAY_WEEKDAY); + short test_tma[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61}; + + exrule_tma.setBy_second(test_tma); + exrule_tma.setBy_minute(test_tma); + property_exrule_tma.set_exrule(exrule_tma); + + ICalRecurrenceType recurence_tma_return = property_exrule_tma.get_exrule(); + System.out.println("****** property - exrule ******"); + System.out.println("setFreq=" + recurence_tma_return.getFreq()); + System.out.println("setWeek_start=" + recurence_tma_return.getWeek_start()); + System.out.println("setBy_second[30]=" + recurence_tma_return.getBy_secondIndexed(30)); + System.out.println("setBy_minute[28]=" + recurence_tma_return.getBy_minuteIndexed(28)); + System.out.println("****** property - exrule ******"); + + // END - get, set exrule + + // START - get, set recurrenceid + ICalProperty property_recurrenceid_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RECURRENCEID_PROPERTY); + property_recurrenceid_tma.set_recurrenceid(starttime); + ICalTimeType recurrenceid_return = property_recurrenceid_tma.get_recurrenceid(); + System.out.println("****** property - recurrenceid ******"); + System.out.println("setYear=" + recurrenceid_return.getYear()); + System.out.println("setMonth=" + recurrenceid_return.getMonth()); + System.out.println("setDay=" + recurrenceid_return.getDay()); + System.out.println("setHour=" + recurrenceid_return.getHour()); + System.out.println("setMinute=" + recurrenceid_return.getMinute()); + System.out.println("setSecond=" + recurrenceid_return.getSecond()); + System.out.println("******* property - recurrenceid *****"); + + // END - get, set recurrenceid + + // START - get, set rrule + ICalProperty property_rrule_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RRULE_PROPERTY); + ICalRecurrenceType rrule_tma = new ICalRecurrenceType(); + rrule_tma.setUntil(starttime); + rrule_tma.setFreq(ICalRecurrenceType.ICalRecurrenceTypeFrequency.ICAL_MINUTELY_RECURRENCE); + rrule_tma.setWeek_start(ICalRecurrenceType.ICalRecurrenceTypeWeekday.ICAL_SUNDAY_WEEKDAY); + short test_hour_tma[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}; + rrule_tma.setBy_hour(test_hour_tma); + property_rrule_tma.set_rrule(rrule_tma); + + ICalRecurrenceType rrule_tma_return = property_rrule_tma.get_rrule(); + System.out.println("****** property - rrule ******"); + System.out.println("setFreq=" + rrule_tma_return.getFreq()); + System.out.println("setWeek_start=" + rrule_tma_return.getWeek_start()); + System.out.println("setBy_hour[11]=" + rrule_tma_return.getBy_hourIndexed(11)); + System.out.println("****** property - rrule ******"); + // END - get, set rrule + + // START - get, set freebusy + ICalProperty property_freebusy_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_FREEBUSY_PROPERTY); + ICalPeriodType period_tma = new ICalPeriodType(); + ICalDurationType duration_tma = new ICalDurationType(); + duration_tma.setDays((long) 0); + duration_tma.setHours((long) 10); + duration_tma.setMinutes((long) 15); + + period_tma.setStart(starttime); + period_tma.setEnd(endtime); + period_tma.setDuration(duration_tma); + + property_freebusy_tma.set_freebusy(period_tma); + + ICalPeriodType period_tma_return = property_freebusy_tma.get_freebusy(); + ICalTimeType start_tma_return = period_tma_return.getStart(); + ICalTimeType end_tma_return = period_tma_return.getEnd(); + ICalDurationType duration_tma_return = period_tma_return.getDuration(); + + System.out.println("****** property - freebusy - start ******"); + System.out.println("setYear=" + start_tma_return.getYear()); + System.out.println("setMonth=" + start_tma_return.getMonth()); + System.out.println("setDay=" + start_tma_return.getDay()); + System.out.println("setHour=" + start_tma_return.getHour()); + System.out.println("setMinute=" + start_tma_return.getMinute()); + System.out.println("setSecond=" + start_tma_return.getSecond()); + System.out.println("******* property - freebusy - start *****"); + + System.out.println("****** property - freebusy - end ******"); + System.out.println("setYear=" + end_tma_return.getYear()); + System.out.println("setMonth=" + end_tma_return.getMonth()); + System.out.println("setDay=" + end_tma_return.getDay()); + System.out.println("setHour=" + end_tma_return.getHour()); + System.out.println("setMinute=" + end_tma_return.getMinute()); + System.out.println("setSecond=" + end_tma_return.getSecond()); + System.out.println("******* property - freebusy - end *****"); + + System.out.println("****** property - freebusy - duration ******"); + System.out.println("setYear=" + duration_tma_return.getDays()); + System.out.println("setMonth=" + duration_tma_return.getHours()); + System.out.println("setDay=" + duration_tma_return.getMinutes()); + System.out.println("******* property - freebusy - duration *****"); + + // END - get, set freebusy + + // START - get, set dtstamp + ICalProperty property_dtstamp_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTSTAMP_PROPERTY); + property_dtstamp_tma.set_dtstamp(starttime); + ICalTimeType dtstamp_tma_return = property_dtstamp_tma.get_dtstamp(); + System.out.println("****** property - dtstamp ******"); + System.out.println("setYear=" + dtstamp_tma_return.getYear()); + System.out.println("setMonth=" + dtstamp_tma_return.getMonth()); + System.out.println("setDay=" + dtstamp_tma_return.getDay()); + System.out.println("setHour=" + dtstamp_tma_return.getHour()); + System.out.println("setMinute=" + dtstamp_tma_return.getMinute()); + System.out.println("setSecond=" + dtstamp_tma_return.getSecond()); + System.out.println("******* property - dtstamp *****"); + // END - get, set dtstamp + // START - get, set attendee + ICalProperty property_attendee_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ATTENDEE_PROPERTY); + property_attendee_tma.set_attendee("John"); + String attendee_tma_return = property_attendee_tma.get_attendee(); + System.out.println("****** property - attendee ******"); + System.out.println("setAttendee=" + attendee_tma_return); + System.out.println("****** property - attendee ******"); + // END - get, set attendee + // START - get, set comment + ICalProperty property_comment_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_COMMENT_PROPERTY); + property_comment_tma.set_comment("John"); + String comment_tma_return = property_comment_tma.get_comment(); + System.out.println("****** property - comment ******"); + System.out.println("setComment=" + comment_tma_return); + System.out.println("****** property - comment ******"); + // END - get, set comment + // START - get, set organizer + ICalProperty property_organizer_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ORGANIZER_PROPERTY); + property_organizer_tma.set_organizer("John"); + String organizer_tma_return = property_organizer_tma.get_organizer(); + System.out.println("****** property - organizer ******"); + System.out.println("setOrganizer=" + organizer_tma_return); + System.out.println("****** property - organizer ******"); + // END - get, set organizer + + summProp.set_summary("New Year's Eve Party, and more"); + System.out.println("done setting summProp"); + startProp.set_dtstart(starttime); + System.out.println("done setting startProp"); + endProp.set_dtend(endtime); + System.out.println("done setting endProp"); + locationProp.set_location("Bothin, Marin County, CA, USA"); + System.out.println("done setting locationProp\n"); + descProp.set_description("Drive carefully; come to have fun!"); + System.out.println("done setting descProp\n"); + + VEvent vEvent = new VEvent(); + vEvent.add_property(summProp); + vEvent.add_property(startProp); + vEvent.add_property(endProp); + vEvent.add_property(locationProp); + vEvent.add_property(descProp); + + ICalTimeType sTime = vEvent.get_dtstart(); + ICalTimeType eTime = vEvent.get_dtend(); + + //System.out.println("VEvent:\n" + vEvent.as_ical_string()); + System.out.println("Summary: \n" + vEvent.get_summary()); + System.out.println("DTSTART: \n" + sTime.getYear() + sTime.getMonth() + sTime.getDay() + + sTime.getHour() + sTime.getMinute() + sTime.getSecond()); + System.out.println("DTEND: \n" + eTime.getYear() + eTime.getMonth() + eTime.getDay() + + eTime.getHour() + eTime.getMinute() + eTime.getSecond()); + System.out.println("Location: \n" + vEvent.get_location()); + System.out.println("Description: \n" +vEvent.get_description()); + + VComponent ic = new VComponent(content); + if (ic == null) + System.err.println("Failed to parse component"); + System.out.println("VComponent:\n" + ic.as_ical_string()); + + // component is wrapped within BEGIN:VCALENDAR END:VCALENDAR + // we need to unwrap it. + VEvent sub_ic = (VEvent)ic.get_first_component(VComponent.ICalComponentKind.ICAL_VEVENT_COMPONENT); + if (sub_ic == null) + System.out.println("Failed to get subcomponent"); + while (sub_ic != null) + { + System.out.println("subcomponent:\n" + sub_ic.as_ical_string()); + sub_ic = (VEvent)ic.get_next_component(VComponent.ICalComponentKind.ICAL_VEVENT_COMPONENT); + } + + // START - get, set recurrenceid + ICalTimeType time_tma = new ICalTimeType(); + time_tma.setYear(2002); + time_tma.setMonth(2); + time_tma.setDay(2); + time_tma.setHour(2); + time_tma.setMinute(2); + time_tma.setSecond(2); + time_tma.setIs_utc(true); + + ic.set_recurrenceid(time_tma); + + ICalTimeType time_tma_return = new ICalTimeType(); + time_tma_return = ic.get_recurrenceid(); + System.out.println("****** vcomponent - recurrenceid ******"); + System.out.println("setYear=" + time_tma_return.getYear()); + System.out.println("setMonth=" + time_tma_return.getMonth()); + System.out.println("setDay=" + time_tma_return.getDay()); + System.out.println("setHour=" + time_tma_return.getHour()); + System.out.println("setMinute=" + time_tma_return.getMinute()); + System.out.println("setSecond=" + time_tma_return.getSecond()); + System.out.println("****** vcomponent - recurrenceid ******"); + // END - get, set recurrenceid + // START - get, set dtstamp + ic.set_dtstamp(time_tma); + ICalTimeType vcomponent_dtstamp_tma_return = ic.get_dtstamp(); + System.out.println("****** vcomponent - dtstamp ******"); + System.out.println("setYear=" + vcomponent_dtstamp_tma_return.getYear()); + System.out.println("setMonth=" + vcomponent_dtstamp_tma_return.getMonth()); + System.out.println("setDay=" + vcomponent_dtstamp_tma_return.getDay()); + System.out.println("setHour=" + vcomponent_dtstamp_tma_return.getHour()); + System.out.println("setMinute=" + vcomponent_dtstamp_tma_return.getMinute()); + System.out.println("setSecond=" + vcomponent_dtstamp_tma_return.getSecond()); + System.out.println("****** vcomponent - dtstamp ******"); + + // END - get, set dtstamp + + // VTODO test cases + + ICalProperty statusProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_STATUS_PROPERTY); + ICalProperty dueProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DUE_PROPERTY); + + ICalTimeType duetime = new ICalTimeType(); + duetime.setYear(2002); + duetime.setMonth(12); + duetime.setDay(21); + duetime.setHour(18); + duetime.setMinute(0); + duetime.setSecond(0); + duetime.setIs_utc(true); + System.out.println("done creating duetime"); + + statusProp.set_status(ICalProperty.ICalPropertyStatus.ICAL_STATUS_COMPLETED); + dueProp.set_due(duetime); + + VToDo vtodo = new VToDo(); + + vtodo.add_property(statusProp); + vtodo.add_property(dueProp); + + System.out.println("VToDo:\n" + vtodo.as_ical_string()); + + // VALARM test cases + + VAlarm valarm = new VAlarm(); + System.out.println("created valarm"); + + // 1. Create a ICAL_DURATION_PROPERTY using the TimePeriod. + ICalDurationType duration = new ICalDurationType(); + duration.setDays((long) 0); + duration.setHours((long) 0); + duration.setMinutes((long) 15); + System.out.println("created duration object"); + + // Since we want to trigger before the event or task, + // we always want to set this to 1. If we say this is not + // a negative duration, that means the alarm will trigger + // AFTER the event or task start or due date, which is useless. + duration.setIs_neg(1); + + // 2. Create a ICalTriggerType oject and set the duration on it. + ICalTriggerType trigger = new ICalTriggerType(); + trigger.setDuration(duration); + System.out.println("set trigger to duration object"); + + // 3. Create a trigger ICalProperty and set the trigger on it. + ICalProperty triggerProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_TRIGGER_PROPERTY); + System.out.println("created trigger property"); + triggerProp.set_trigger(trigger); + System.out.println("set trigger property"); + trigger = triggerProp.get_trigger(); + System.out.println("get trigger property"); + + // 4. set the trigger property on the Valarm object. + valarm.add_property(triggerProp); + System.out.println("VAlarm:\n" + valarm.as_ical_string()); + + // 5. create attendee property + String userEmail = "userid@domain"; + ICalProperty attendeeProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ATTENDEE_PROPERTY); + attendeeProp.set_attendee("MAILTO:" + userEmail); + System.out.println("set attendee property"); + userEmail = attendeeProp.get_attendee(); + System.out.println("get attendee property"); + valarm.add_property(attendeeProp); + System.out.println("VAlarm:\n" + valarm.as_ical_string()); + + // START - get, set_role + ICalParameter parameter_role_tma = new ICalParameter(ICalParameter.ICalParameterKind.ICAL_ROLE_PARAMETER); + parameter_role_tma.set_role(ICalParameter.ICalParameterRole.ICAL_ROLE_REQPARTICIPANT); + int role_tma_return = parameter_role_tma.get_role(); + System.out.println("******* parameter - role *****"); + System.out.println("setRole=" + role_tma_return); + System.out.println("******* parameter - role *****"); + // END - get, set_role + // START - get, set_partstat + ICalParameter parameter_partstat_tma = new ICalParameter(ICalParameter.ICalParameterKind.ICAL_PARTSTAT_PARAMETER); + parameter_partstat_tma.set_partstat(ICalParameter.ICalParameterPartStat.ICAL_PARTSTAT_DECLINED); + int partstat_tma_return = parameter_partstat_tma.get_partstat(); + System.out.println("******* parameter - partstat *****"); + System.out.println("setPartstat=" + partstat_tma_return); + System.out.println("******* parameter - partstat *****"); + // END - get, set_partstat + } +} diff --git a/libical/src/libical/.cvsignore b/libical/src/libical/.cvsignore index ef04480fde..921e7a4e38 100644 --- a/libical/src/libical/.cvsignore +++ b/libical/src/libical/.cvsignore @@ -1,22 +1,27 @@ -Makefile -Makefile.in -icalitipy.c -icalitipy.h -icalitipl.c -icallexer.c -icalyacc.c icalyacc.h +icalyacc.c +icallexer.c y.output +Makefile +icalversion.h +.deps +.libs *.lo *.la -.libs -.deps -icalversion.h ical.h +icalyacc.output +icalproperty.c +icalproperty.h +icalvalue.h +icalvalue.c +icalparameter.h +icalparameter.c +icalrestriction.c icalderivedparameter.c icalderivedparameter.h icalderivedproperty.c icalderivedproperty.h -icalderivedvalue.h icalderivedvalue.c -icalrestriction.c +icalderivedvalue.h +icallexer.c +y.output diff --git a/libical/src/libical/Makefile.am b/libical/src/libical/Makefile.am index b818f2bb13..2249db8602 100644 --- a/libical/src/libical/Makefile.am +++ b/libical/src/libical/Makefile.am @@ -2,7 +2,7 @@ # FILE: Makefile.am # CREATOR: eric # -# $Id: Makefile.am,v 1.35 2003/02/10 15:53:20 ettore Exp $ +# $Id: Makefile.am,v 1.36 2003/09/11 22:04:19 hansp Exp $ # # # (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -18,7 +18,7 @@ # The Mozilla Public License Version 1.0. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # -# The original code is icalcomponent.c +# # #====================================================================== @@ -26,21 +26,23 @@ DESIGNDATA = $(top_srcdir)/design-data ICALSCRIPTS = $(top_srcdir)/scripts -privlib_LTLIBRARIES = libical-evolution.la +if WITH_CXX +cxx_lib=libical_cxx.la +cxx_headers=vcomponent.h icalparameter_cxx.h icalproperty_cxx.h icalvalue_cxx.h icptrholder.h +else +cxx_lib= +cxx_headers= +endif + +lib_LTLIBRARIES = libical.la $(cxx_lib) noinst_LTLIBRARIES = libical-static.la -libical_static_la_SOURCES = $(libical_evolution_la_SOURCES) +libical_static_la_SOURCES = $(libical_la_SOURCES) libical_static_la_LDFLAGS = --all-static -# Make sure libical-evolution.la and libical-static.la are not built in -# parallel when using a parallel make; libtool can't handle that. -libical_static_la_DEPENDENCIES = libical-evolution.la +CPPFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/$(PACKAGE)"\" -YFLAGS = -d -v -t -pical_yy -LFLAGS = -Pical_yy -LEX_OUTPUT_ROOT = lex.ical_yy - -CPPFLAGS = -DPACKAGE_DATA_DIR=\""$(privdatadir)"\" +# CFLAGS = -g all: ical.h @@ -50,21 +52,22 @@ INCLUDES = \ -I$(top_builddir)/src \ -I$(srcdir) -libical_evolution_la_LDFLAGS = -version-info 0:0:0 +libical_la_LDFLAGS = -version-info 0:0:0 + -libical_evolution_la_SOURCES = \ +libical_la_SOURCES = \ $(BUILT_SOURCES) \ icalarray.c \ icalarray.h \ - icalattendee.h \ - icalattendee.c \ + icalattach.h \ + icalattachimpl.h \ + icalattach.c \ icalcomponent.c \ icalcomponent.h \ icalenums.c \ icalenums.h \ icalerror.c \ icalerror.h \ - icallexer.l \ icalmemory.c \ icalmemory.h \ icalmime.c \ @@ -92,24 +95,38 @@ libical_evolution_la_SOURCES = \ icalvalue.c \ icalvalue.h \ icalvalueimpl.h \ - icalyacc.h \ - icalyacc.y \ pvl.c \ pvl.h \ sspm.c \ sspm.h \ vsnprintf.c \ icallangbind.h \ - icallangbind.c - -#libicalincludedir = $(includedir)/$(PACKAGE) -libicalincludedir = $(privincludedir) - -libicalinclude_HEADERS = ical.h + icallangbind.c \ + caldate.c \ + astime.h + +if WITH_CXX +libical_cxx_la_SOURCES = \ + $(libical_la_SOURCES) \ + vcomponent.h \ + vcomponent.cpp \ + icalproperty_cxx.h \ + icalproperty_cxx.cpp \ + icalparameter_cxx.h \ + icalparameter_cxx.cpp \ + icalvalue_cxx.h \ + icalvalue_cxx.cpp \ + icptrholder.h +endif + +libicalincludedir = $(includedir) + +libicalinclude_HEADERS = ical.h icalmemory.h icalerror.h $(cxx_headers) # ORDERING OF HEADERS IS SIGNIFICANT. Don't change this ordering. It # is required to make the combined header ical.h properly COMBINEDHEADERS = \ + $(top_builddir)/config.h \ $(top_builddir)/src/libical/icalversion.h \ $(top_srcdir)/src/libical/icaltime.h \ $(top_srcdir)/src/libical/icalduration.h \ @@ -117,13 +134,13 @@ COMBINEDHEADERS = \ $(top_srcdir)/src/libical/icalenums.h \ $(top_srcdir)/src/libical/icaltypes.h \ $(top_srcdir)/src/libical/icalrecur.h \ + $(top_srcdir)/src/libical/icalattach.h \ icalderivedvalue.h \ icalderivedparameter.h \ $(top_srcdir)/src/libical/icalvalue.h \ $(top_srcdir)/src/libical/icalparameter.h \ icalderivedproperty.h \ $(top_srcdir)/src/libical/icalproperty.h \ - $(top_srcdir)/src/libical/icalattendee.h \ $(top_srcdir)/src/libical/pvl.h \ $(top_srcdir)/src/libical/icalarray.h \ $(top_srcdir)/src/libical/icalcomponent.h \ @@ -149,11 +166,20 @@ BUILT_SOURCES = \ icalderivedvalue.c ical.h: $(COMBINEDHEADERS) + echo '#ifdef __cplusplus' > ical.h + echo 'extern "C" {' >> ical.h + echo '#endif' >> ical.h + echo '/*' >> ical.h + echo ' $$''Id''$$' >> ical.h + echo '*/' >> ical.h cat $(COMBINEDHEADERS) \ | egrep -v "#include.*\"ical" \ - | egrep -v "#include.*\"pvl\.h\"" > ical.h - -icallexer.c : icalyacc.h + | egrep -v "#include.*\"config" \ + | egrep -v "#include.*\"pvl\.h\"" \ + | egrep -v '\$$(Id|Locker): .+\$$'>> ical.h + echo '#ifdef __cplusplus' >> ical.h + echo '};' >> ical.h + echo '#endif' >> ical.h # parameters @@ -206,7 +232,7 @@ icalrestriction.c: $(RESTRICTIONDEPS) VALUEDEPS = \ $(ICALSCRIPTS)/mkderivedvalues.pl \ $(DESIGNDATA)/value-types.csv \ - icalderivedvalue.c.in \ + icalderivedvalue.c.in \ icalderivedvalue.h.in icalderivedvalue.h: $(VALUEDEPS) @@ -217,16 +243,21 @@ icalderivedvalue.c: $(VALUEDEPS) $(BUILT_COMBINEDHEADERS) $(PERL) -I$(ICALSCRIPTS) $(ICALSCRIPTS)/mkderivedvalues.pl \ -i $(srcdir)/icalderivedvalue.c.in -c $(DESIGNDATA)/value-types.csv > icalderivedvalue.c +# c++ needs ical.h auto-generated. +icalparameter_cxx.lo: ical.h +icalproperty_cxx.lo: ical.h +icalvalue_cxx.lo: ical.h +vcomponent.lo: ical.h # housekeeping CONFIG_CLEAN_FILES = y.output -CLEANFILES = $(BUILT_SOURCES) ical.h +CLEANFILES = $(BUILT_SOURCES) $(BUILT_COMBINEDHEADERS) dist-hook: cd $(distdir); rm -f $(BUILT_SOURCES) - cd $(distdir); rm -f ical.h + cd $(distdir); rm -f ical.h icalversion.h EXTRA_DIST = \ icalderivedparameter.c.in \ @@ -236,7 +267,18 @@ EXTRA_DIST = \ icalrestriction.c.in \ icalderivedvalue.c.in \ icalderivedvalue.h.in \ - icalversion.h.in \ - icallexer.c \ - icalyacc.c - + icalversion.h.in + +$(srcdir)/icalcomponent.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +icalderivedparameter.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +icalderivedproperty.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +icalderivedvalue.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalduration.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icallangbind.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalmime.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalparameter.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalparser.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalproperty.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalrestriction.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icaltime.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h +$(srcdir)/icalvalue.c: icalderivedvalue.h icalderivedproperty.h icalderivedparameter.h diff --git a/libical/src/libical/astime.h b/libical/src/libical/astime.h new file mode 100644 index 0000000000..6962c060a8 --- /dev/null +++ b/libical/src/libical/astime.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1986-2000, Hiram Clawson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * Neither name of The Museum of Hiram nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file astime.h + * @brief contains definitions of structures used for time calculations. + */ + +#ifndef _astime_h_ +#define _astime_h_ + +typedef struct ut_instant { + double j_date; /**< julian decimal date, 0 = 01 Jan 4713 BC 12 HR UT */ + long year; /**< year, valid range [-4,713, +2,147,483,647] */ + int month; /**< [1-12] */ + int day; /**< [1-31] */ + int i_hour; /**< [0-23] */ + int i_minute; /**< [0-59] */ + int i_second; /**< [0-59] */ + double d_hour; /**< [0.0-23.9999] includes minute and second */ + double d_minute; /**< [0.0-59.9999] includes second */ + double d_second; /**< [0.0-59.9999] */ + int weekday; /**< [0-6] */ + int day_of_year; /**< [1-366] */ +} UTinstant, * UTinstantPtr; + +/* Functions in caldate.c */ + +long caldat( UTinstantPtr ); /** converts julian date to year,mo,da */ +double juldat( UTinstantPtr ); /** returns julian day from year,mo,da */ + +#endif /* _astime_h_ */ diff --git a/libical/src/libical/caldate.c b/libical/src/libical/caldate.c new file mode 100644 index 0000000000..f5554f66f8 --- /dev/null +++ b/libical/src/libical/caldate.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 1986-2000, Hiram Clawson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * Neither name of The Museum of Hiram nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "astime.h" /* time structures */ + +/** + * caldat computes the day of the week, the day of the year + * the gregorian (or julian) calendar date and the universal + * time from the julian decimal date. + * for astronomical purposes, The Gregorian calendar reform occurred + * on 15 Oct. 1582. This is 05 Oct 1582 by the julian calendar. + + * Input: a ut_instant structure pointer, where the j_date element + * has been set. ( = 0 for 01 Jan 4713 B.C. 12 HR UT ) + * + * output: will set all the other elements of the structure. + * As a convienence, the function will also return the year. + * + * Reference: Astronomial formulae for calculators, meeus, p 23 + * from fortran program by F. Espenak - April 1982 Page 277, + * 50 Year canon of solar eclipses: 1986-2035 + * + */ + +long caldat( date ) +struct ut_instant * date; +{ + double frac; + long jd; + long ka; + long kb; + long kc; + long kd; + long ke; + long ialp; + + jd = (long) (date->j_date + 0.5); /* integer julian date */ + frac = date->j_date + 0.5 - (double) jd + 1.0e-10; /* day fraction */ + ka = (long) jd; + if ( jd >= 2299161L ) + { + ialp = ( (double) jd - 1867216.25 ) / ( 36524.25 ); + ka = jd + 1L + ialp - ( ialp >> 2 ); + } + kb = ka + 1524L; + kc = ( (double) kb - 122.1 ) / 365.25; + kd = (double) kc * 365.25; + ke = (double) ( kb - kd ) / 30.6001; + date->day = kb - kd - ((long) ( (double) ke * 30.6001 )); + if ( ke > 13L ) + date->month = ke - 13L; + else + date->month = ke - 1L; + if ( (date->month == 2) && (date->day > 28) ) + date->day = 29; + if ( (date->month == 2) && (date->day == 29) && (ke == 3L) ) + date->year = kc - 4716L; + else if ( date->month > 2 ) + date->year = kc - 4716L; + else + date->year = kc - 4715L; + date->i_hour = date->d_hour = frac * 24.0; /* hour */ + date->i_minute = date->d_minute = + ( date->d_hour - (double) date->i_hour ) * 60.0; /* minute */ + date->i_second = date->d_second = + ( date->d_minute - (double) date->i_minute ) * 60.0;/* second */ + date->weekday = (jd + 1L) % 7L; /* day of week */ + if ( date->year == ((date->year >> 2) << 2) ) + date->day_of_year = + ( ( 275 * date->month ) / 9) + - ((date->month + 9) / 12) + + date->day - 30; + else + date->day_of_year = + ( ( 275 * date->month ) / 9) + - (((date->month + 9) / 12) << 1) + + date->day - 30; + return( date->year ); +} + +/** + * juldat computes the julian decimal date (j_date) from + * the gregorian (or Julian) calendar date. + * for astronomical purposes, The Gregorian calendar reform occurred + * on 15 Oct. 1582. This is 05 Oct 1582 by the julian calendar. + * Input: a ut_instant structure pointer where Day, Month, Year and + * i_hour, i_minute, d_second have been set for the date + * in question. + * + * Output: the j_date and weekday elements of the structure will be set. + * Also, the return value of the function will be the j_date too. + * + * Reference: Astronomial formulae for calculators, meeus, p 23 + * from fortran program by F. Espenak - April 1982 Page 276, + * 50 Year canon of solar eclipses: 1986-2035 + */ + +double juldat( date ) +struct ut_instant * date; +{ + double frac, gyr; + long iy0, im0; + long ia, ib; + long jd; + + /* decimal day fraction */ + frac = (( double)date->i_hour/ 24.0) + + ((double) date->i_minute / 1440.0) + + (date->d_second / 86400.0); + /* convert date to format YYYY.MMDDdd */ + gyr = (double) date->year + + (0.01 * (double) date->month) + + (0.0001 * (double) date->day) + + (0.0001 * frac) + 1.0e-9; + /* conversion factors */ + if ( date->month <= 2 ) + { + iy0 = date->year - 1L; + im0 = date->month + 12; + } + else + { + iy0 = date->year; + im0 = date->month; + } + ia = iy0 / 100L; + ib = 2L - ia + (ia >> 2); + /* calculate julian date */ + if ( date->year < 0L ) + jd = (long) ((365.25 * (double) iy0) - 0.75) + + (long) (30.6001 * (im0 + 1L) ) + + (long) date->day + 1720994L; + else + jd = (long) (365.25 * (double) iy0) + + (long) (30.6001 * (double) (im0 + 1L)) + + (long) date->day + 1720994L; + if ( gyr >= 1582.1015 ) /* on or after 15 October 1582 */ + jd += ib; + date->j_date = (double) jd + frac + 0.5; + jd = (long) (date->j_date + 0.5); + date->weekday = (jd + 1L) % 7L; + return( date->j_date ); +} /* end of double juldat( date ) */ diff --git a/libical/src/libical/icalarray.c b/libical/src/libical/icalarray.c index 9aea671b64..78e1adaef6 100644 --- a/libical/src/libical/icalarray.c +++ b/libical/src/libical/icalarray.c @@ -22,6 +22,12 @@ ======================================================================*/ +/** @file icalarray.c + * + * @brief An array of arbitrarily-sized elements which grows + * dynamically as elements are added. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -36,6 +42,8 @@ static void icalarray_expand (icalarray *array, int space_needed); +/** @brief Constructor + */ icalarray* icalarray_new (int element_size, @@ -58,6 +66,8 @@ icalarray_new (int element_size, return array; } +/** @brief Destructor + */ void icalarray_free (icalarray *array) @@ -75,7 +85,7 @@ icalarray_append (icalarray *array, if (array->num_elements >= array->space_allocated) icalarray_expand (array, 1); - memcpy (array->data + array->num_elements * array->element_size, element, + memcpy ((char *)(array->data) + ( array->num_elements * array->element_size ), element, array->element_size); array->num_elements++; } @@ -88,7 +98,7 @@ icalarray_element_at (icalarray *array, assert (position >= 0); assert (position < array->num_elements); - return array->data + position * array->element_size; + return (char *)(array->data) + (position * array->element_size); } @@ -102,11 +112,11 @@ icalarray_remove_element_at (icalarray *array, assert (position >= 0); assert (position < array->num_elements); - dest = array->data + position * array->element_size; + dest = (char *)array->data + (position * array->element_size); elements_to_move = array->num_elements - position - 1; if (elements_to_move > 0) - memmove (dest, dest + array->element_size, + memmove (dest, (char *)dest + array->element_size, elements_to_move * array->element_size); array->num_elements--; @@ -134,8 +144,14 @@ icalarray_expand (icalarray *array, if (space_needed > array->increment_size) new_space_allocated += space_needed; + /* new_data = realloc (array->data, new_space_allocated * array->element_size); + */ + new_data = malloc(new_space_allocated * array->element_size); + memcpy(new_data,array->data,array->element_size*array->space_allocated); + free(array->data); + if (new_data) { array->data = new_data; array->space_allocated = new_space_allocated; diff --git a/libical/src/libical/icalarray.h b/libical/src/libical/icalarray.h index cbf72688da..e265167a0a 100644 --- a/libical/src/libical/icalarray.h +++ b/libical/src/libical/icalarray.h @@ -27,17 +27,19 @@ #ifndef ICALARRAY_H #define ICALARRAY_H -/* An array of arbitrarily-sized elements which grows dynamically as elements - are added. */ - +/** @file icalarray.h + * + * @brief An array of arbitrarily-sized elements which grows + * dynamically as elements are added. + */ typedef struct _icalarray icalarray; struct _icalarray { - int element_size; - int increment_size; - int num_elements; - int space_allocated; - void *data; + unsigned int element_size; + unsigned int increment_size; + unsigned int num_elements; + unsigned int space_allocated; + void *data; }; diff --git a/libical/src/libical/icalattach.c b/libical/src/libical/icalattach.c new file mode 100644 index 0000000000..8da9d4320d --- /dev/null +++ b/libical/src/libical/icalattach.c @@ -0,0 +1,139 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalattach.c + CREATOR: acampi 28 May 02 + + $Id$ + $Locker$ + + + (C) COPYRIGHT 2000, Andrea Campi + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icaltypes.c + + ======================================================================*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "icaltypes.h" +#include "icalerror.h" +#include "icalmemory.h" +#include "icalattachimpl.h" +#include <stdlib.h> /* for malloc and abs() */ +#include <errno.h> /* for errno */ +#include <string.h> /* for icalmemory_strdup */ +#include <assert.h> + +icalattach * +icalattach_new_from_url (const char *url) +{ + icalattach *attach; + char *url_copy; + + icalerror_check_arg_rz ((url != NULL), "url"); + + if ((attach = malloc (sizeof (icalattach))) == NULL) { + errno = ENOMEM; + return NULL; + } + + if ((url_copy = strdup (url)) == NULL) { + free (attach); + errno = ENOMEM; + return NULL; + } + + attach->refcount = 1; + attach->is_url = 1; + attach->u.url.url = url_copy; + + return attach; +} + +icalattach * +icalattach_new_from_data (unsigned char *data, icalattach_free_fn_t free_fn, + void *free_fn_data) +{ + icalattach *attach; + + icalerror_check_arg_rz ((data != NULL), "data"); + + if ((attach = malloc (sizeof (icalattach))) == NULL) { + errno = ENOMEM; + return NULL; + } + + attach->refcount = 1; + attach->is_url = 0; + attach->u.data.data = data; + attach->u.data.free_fn = free_fn; + attach->u.data.free_fn_data = free_fn_data; + + return attach; +} + +void +icalattach_ref (icalattach *attach) +{ + icalerror_check_arg_rv ((attach != NULL), "attach"); + icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0"); + + attach->refcount++; +} + +void +icalattach_unref (icalattach *attach) +{ + icalerror_check_arg_rv ((attach != NULL), "attach"); + icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0"); + + attach->refcount--; + + if (attach->refcount != 0) + return; + + if (attach->is_url) + free (attach->u.url.url); + else if (attach->u.data.free_fn) + (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data); + + free (attach); +} + +int +icalattach_get_is_url (icalattach *attach) +{ + icalerror_check_arg_rz ((attach != NULL), "attach"); + + return attach->is_url ? 1 : 0; +} + +const char * +icalattach_get_url (icalattach *attach) +{ + icalerror_check_arg_rz ((attach != NULL), "attach"); + icalerror_check_arg_rz ((attach->is_url), "attach->is_url"); + + return attach->u.url.url; +} + +unsigned char * +icalattach_get_data (icalattach *attach) +{ + icalerror_check_arg_rz ((attach != NULL), "attach"); + icalerror_check_arg_rz ((!attach->is_url), "!attach->is_url"); + + return attach->u.data.data; +} diff --git a/libical/src/libical/icalattach.h b/libical/src/libical/icalattach.h new file mode 100644 index 0000000000..ba4488dd2d --- /dev/null +++ b/libical/src/libical/icalattach.h @@ -0,0 +1,60 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalattach.h + CREATOR: acampi 28 May 02 + + + (C) COPYRIGHT 2002, Andrea Campi + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalattach.h + +======================================================================*/ + +#ifndef ICALATTACH_H +#define ICALATTACH_H + + +typedef struct icalattach_impl icalattach; + +typedef void (* icalattach_free_fn_t) (unsigned char *data, void *user_data); + +icalattach *icalattach_new_from_url (const char *url); +icalattach *icalattach_new_from_data (unsigned char *data, + icalattach_free_fn_t free_fn, void *free_fn_data); + +void icalattach_ref (icalattach *attach); +void icalattach_unref (icalattach *attach); + +int icalattach_get_is_url (icalattach *attach); +const char *icalattach_get_url (icalattach *attach); +unsigned char *icalattach_get_data (icalattach *attach); + +struct icalattachtype* icalattachtype_new(void); +void icalattachtype_add_reference(struct icalattachtype* v); +void icalattachtype_free(struct icalattachtype* v); + +void icalattachtype_set_url(struct icalattachtype* v, char* url); +char* icalattachtype_get_url(struct icalattachtype* v); + +void icalattachtype_set_base64(struct icalattachtype* v, char* base64, + int owns); +char* icalattachtype_get_base64(struct icalattachtype* v); + +void icalattachtype_set_binary(struct icalattachtype* v, char* binary, + int owns); +void* icalattachtype_get_binary(struct icalattachtype* v); + + + +#endif /* !ICALATTACH_H */ diff --git a/libical/src/libical/icalattachimpl.h b/libical/src/libical/icalattachimpl.h new file mode 100644 index 0000000000..b8abe6396b --- /dev/null +++ b/libical/src/libical/icalattachimpl.h @@ -0,0 +1,59 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalattachimpl.h + CREATOR: acampi 28 May 02 + + $Id$ + + + (C) COPYRIGHT 2000, Andrea Campi + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The original code is icalattachimpl.h + + +======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef ICALATTACHIMPL_H +#define ICALATTACHIMPL_H + +#include "icalattach.h" + +/* Private structure for ATTACH values */ +struct icalattach_impl { + /* Reference count */ + int refcount; + + union { + /* URL attachment data */ + struct { + char *url; + } url; + + /* Inline data */ + struct { + unsigned char *data; + icalattach_free_fn_t free_fn; + void *free_fn_data; + } data; + } u; + + /* TRUE if URL, FALSE if inline data */ + unsigned int is_url : 1; +}; + +#endif diff --git a/libical/src/libical/icalcomponent.c b/libical/src/libical/icalcomponent.c index 6c222f01a9..a892128a0e 100644 --- a/libical/src/libical/icalcomponent.c +++ b/libical/src/libical/icalcomponent.c @@ -4,7 +4,6 @@ $Id$ - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org This program is free software; you can redistribute it and/or modify @@ -38,6 +37,7 @@ #include "icalduration.h" #include "icalperiod.h" #include "icalparser.h" +#include "icalrestriction.h" #include <stdlib.h> /* for malloc */ #include <stdarg.h> /* for va_list, etc */ @@ -45,8 +45,7 @@ #include <assert.h> #include <stdio.h> /* for fprintf */ #include <string.h> /* for strdup */ - -#define MAX_TMP 1024 +#include <limits.h> /* for INT_MAX */ struct icalcomponent_impl { @@ -59,7 +58,7 @@ struct icalcomponent_impl pvl_elem component_iterator; icalcomponent* parent; - /* An array of icaltimezone structs. We use this so we can do fast + /** An array of icaltimezone structs. We use this so we can do fast lookup of timezones using binary searches. timezones_sorted is set to 0 whenever we add a timezone, so we remember to sort the array before doing a binary search. */ @@ -71,9 +70,8 @@ struct icalcomponent_impl void icalproperty_set_parent(icalproperty* property, icalcomponent* component); icalcomponent* icalproperty_get_parent(icalproperty* property); -void icalcomponent_add_children(struct icalcomponent_impl *impl,va_list args); -icalcomponent* icalcomponent_new_impl (icalcomponent_kind kind); -int icalcomponent_property_sorter(void *a, void *b); +void icalcomponent_add_children(icalcomponent *impl,va_list args); +static icalcomponent* icalcomponent_new_impl (icalcomponent_kind kind); static void icalcomponent_merge_vtimezone (icalcomponent *comp, icalcomponent *vtimezone, @@ -83,7 +81,7 @@ static void icalcomponent_handle_conflicting_vtimezones (icalcomponent *comp, icalproperty *tzid_prop, const char *tzid, icalarray *tzids_to_rename); -static int icalcomponent_get_tzid_prefix_len (const char *tzid); +static unsigned int icalcomponent_get_tzid_prefix_len (const char *tzid); static void icalcomponent_rename_tzids(icalcomponent* comp, icalarray* rename_table); static void icalcomponent_rename_tzids_callback(icalparameter *param, @@ -94,7 +92,7 @@ static int icalcomponent_compare_timezone_fn (const void *elem1, const void *elem2); -void icalcomponent_add_children(struct icalcomponent_impl *impl,va_list args) +void icalcomponent_add_children(icalcomponent *impl, va_list args) { void* vp; @@ -104,25 +102,23 @@ void icalcomponent_add_children(struct icalcomponent_impl *impl,va_list args) icalproperty_isa_property(vp) != 0 ) ; if (icalcomponent_isa_component(vp) != 0 ){ - - icalcomponent_add_component((icalcomponent*)impl, - (icalcomponent*)vp); + icalcomponent_add_component(impl, (icalcomponent*)vp); } else if (icalproperty_isa_property(vp) != 0 ){ - - icalcomponent_add_property((icalcomponent*)impl, - (icalproperty*)vp); + icalcomponent_add_property(impl, (icalproperty*)vp); } } } -icalcomponent* +static icalcomponent* icalcomponent_new_impl (icalcomponent_kind kind) { - struct icalcomponent_impl* comp; + icalcomponent* comp; + + if (!icalcomponent_kind_is_valid(kind)) + return NULL; - if ( ( comp = (struct icalcomponent_impl*) - malloc(sizeof(struct icalcomponent_impl))) == 0) { + if ( ( comp = (icalcomponent*) malloc(sizeof(icalcomponent))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } @@ -142,18 +138,22 @@ icalcomponent_new_impl (icalcomponent_kind kind) return comp; } +/** @brief Constructor + */ icalcomponent* icalcomponent_new (icalcomponent_kind kind) { - return (icalcomponent*)icalcomponent_new_impl(kind); + return icalcomponent_new_impl(kind); } +/** @brief Constructor + */ icalcomponent* icalcomponent_vanew (icalcomponent_kind kind, ...) { va_list args; - struct icalcomponent_impl *impl = icalcomponent_new_impl(kind); + icalcomponent *impl = icalcomponent_new_impl(kind); if (impl == 0){ return 0; @@ -163,23 +163,26 @@ icalcomponent_vanew (icalcomponent_kind kind, ...) icalcomponent_add_children(impl, args); va_end(args); - return (icalcomponent*) impl; + return impl; } +/** @brief Constructor + */ icalcomponent* icalcomponent_new_from_string(char* str) { return icalparser_parse_string(str); } -icalcomponent* icalcomponent_new_clone(icalcomponent* component) +/** @brief Constructor + */ +icalcomponent* icalcomponent_new_clone(icalcomponent* old) { - struct icalcomponent_impl *old = (struct icalcomponent_impl*)component; - struct icalcomponent_impl *new; + icalcomponent *new; icalproperty *p; icalcomponent *c; pvl_elem itr; - icalerror_check_arg_rz( (component!=0), "component"); + icalerror_check_arg_rz( (old!=0), "component"); new = icalcomponent_new_impl(old->kind); @@ -193,8 +196,7 @@ icalcomponent* icalcomponent_new_clone(icalcomponent* component) itr = pvl_next(itr)) { p = (icalproperty*)pvl_data(itr); - if (p != 0) - icalcomponent_add_property(new,icalproperty_new_clone(p)); + icalcomponent_add_property(new,icalproperty_new_clone(p)); } @@ -210,15 +212,15 @@ icalcomponent* icalcomponent_new_clone(icalcomponent* component) } - +/*** @brief Destructor + */ void -icalcomponent_free (icalcomponent* component) +icalcomponent_free (icalcomponent* c) { icalproperty* prop; icalcomponent* comp; - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - icalerror_check_arg_rv( (component!=0), "component"); + icalerror_check_arg_rv( (c!=0), "component"); #ifdef ICAL_FREE_ON_LIST_IS_ERROR icalerror_assert( (c->parent ==0),"Tried to free a component that is still attached to a parent component"); @@ -228,19 +230,22 @@ icalcomponent_free (icalcomponent* component) } #endif - if(component != 0 ){ + if(c != 0 ){ - while( (prop=pvl_pop(c->properties)) != 0){ - assert(prop != 0); - icalproperty_set_parent(prop,0); - icalproperty_free(prop); - } - - pvl_free(c->properties); + if ( c->properties != 0 ) + { + while( (prop=pvl_pop(c->properties)) != 0){ + assert(prop != 0); + icalproperty_set_parent(prop,0); + icalproperty_free(prop); + } + pvl_free(c->properties); + } + while( (comp=pvl_data(pvl_head(c->components))) != 0){ assert(comp!=0); - icalcomponent_remove_component(component,comp); + icalcomponent_remove_component(c,comp); icalcomponent_free(comp); } @@ -264,38 +269,40 @@ icalcomponent_free (icalcomponent* component) free(c); } - } char* -icalcomponent_as_ical_string (icalcomponent* component) +icalcomponent_as_ical_string (icalcomponent* impl) { char* buf, *out_buf; - char* tmp_buf; + const char* tmp_buf; size_t buf_size = 1024; char* buf_ptr = 0; pvl_elem itr; - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; +/* WIN32 automatically adds the \r, Anybody else need it? #ifdef ICAL_UNIX_NEWLINE +*/ char newline[] = "\n"; +/* #else char newline[] = "\r\n"; #endif +*/ icalcomponent *c; icalproperty *p; - icalcomponent_kind kind = icalcomponent_isa(component); + icalcomponent_kind kind = icalcomponent_isa(impl); const char* kind_string; buf = icalmemory_new_buffer(buf_size); buf_ptr = buf; - icalerror_check_arg_rz( (component!=0), "component"); + icalerror_check_arg_rz( (impl!=0), "component"); icalerror_check_arg_rz( (kind!=ICAL_NO_COMPONENT), "component kind is ICAL_NO_COMPONENT"); - kind_string = icalenum_component_kind_to_string(kind); + kind_string = icalcomponent_kind_to_string(kind); icalerror_check_arg_rz( (kind_string!=0),"Unknown kind of component"); @@ -332,7 +339,7 @@ icalcomponent_as_ical_string (icalcomponent* component) icalmemory_append_string(&buf, &buf_ptr, &buf_size, "END:"); icalmemory_append_string(&buf, &buf_ptr, &buf_size, - icalenum_component_kind_to_string(kind)); + icalcomponent_kind_to_string(kind)); icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline); out_buf = icalmemory_tmp_copy(buf); @@ -345,11 +352,8 @@ icalcomponent_as_ical_string (icalcomponent* component) int icalcomponent_is_valid (icalcomponent* component) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl *)component; - - - if ( (strcmp(impl->id,"comp") == 0) && - impl->kind != ICAL_NO_COMPONENT){ + if ( (strcmp(component->id,"comp") == 0) && + component->kind != ICAL_NO_COMPONENT){ return 1; } else { return 0; @@ -359,14 +363,13 @@ icalcomponent_is_valid (icalcomponent* component) icalcomponent_kind -icalcomponent_isa (icalcomponent* component) +icalcomponent_isa (const icalcomponent* component) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl *)component; - icalerror_check_arg_rz( (component!=0), "component"); + icalerror_check_arg_rx( (component!=0), "component", ICAL_NO_COMPONENT); if(component != 0) { - return impl->kind; + return component->kind; } return ICAL_NO_COMPONENT; @@ -376,7 +379,7 @@ icalcomponent_isa (icalcomponent* component) int icalcomponent_isa_component (void* component) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl *)component; + icalcomponent *impl = component; icalerror_check_arg_rz( (component!=0), "component"); @@ -388,63 +391,32 @@ icalcomponent_isa_component (void* component) } -int icalcomponent_property_sorter(void *a, void *b) -{ - icalproperty_kind kinda, kindb; - const char *ksa, *ksb; - - kinda = icalproperty_isa((icalproperty*)a); - kindb = icalproperty_isa((icalproperty*)b); - - ksa = icalenum_property_kind_to_string(kinda); - ksb = icalenum_property_kind_to_string(kindb); - - return strcmp(ksa,ksb); -} - - void icalcomponent_add_property (icalcomponent* component, icalproperty* property) { - struct icalcomponent_impl *impl; - icalerror_check_arg_rv( (component!=0), "component"); icalerror_check_arg_rv( (property!=0), "property"); - impl = (struct icalcomponent_impl*)component; - icalerror_assert( (!icalproperty_get_parent(property)),"The property has already been added to a component. Remove the property with icalcomponent_remove_property before calling icalcomponent_add_property"); icalproperty_set_parent(property,component); -#ifdef ICAL_INSERT_ORDERED - pvl_insert_ordered(impl->properties, - icalcomponent_property_sorter,property); -#else - pvl_push(impl->properties,property); -#endif - + pvl_push(component->properties,property); } void icalcomponent_remove_property (icalcomponent* component, icalproperty* property) { - struct icalcomponent_impl *impl; pvl_elem itr, next_itr; - struct icalproperty_impl *pimpl; icalerror_check_arg_rv( (component!=0), "component"); icalerror_check_arg_rv( (property!=0), "property"); - impl = (struct icalcomponent_impl*)component; - - pimpl = (struct icalproperty_impl*)property; - icalerror_assert( (icalproperty_get_parent(property)),"The property is not a member of a component"); - for( itr = pvl_head(impl->properties); + for( itr = pvl_head(component->properties); itr != 0; itr = next_itr) { @@ -452,11 +424,11 @@ icalcomponent_remove_property (icalcomponent* component, icalproperty* property) if( pvl_data(itr) == (void*)property ){ - if (impl->property_iterator == itr){ - impl->property_iterator = pvl_next(itr); + if (component->property_iterator == itr){ + component->property_iterator = pvl_next(itr); } - pvl_remove( impl->properties, itr); + pvl_remove( component->properties, itr); icalproperty_set_parent(property,0); } } @@ -468,11 +440,10 @@ icalcomponent_count_properties (icalcomponent* component, { int count=0; pvl_elem itr; - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; icalerror_check_arg_rz( (component!=0), "component"); - for( itr = pvl_head(impl->properties); + for( itr = pvl_head(component->properties); itr != 0; itr = pvl_next(itr)) { @@ -489,23 +460,19 @@ icalcomponent_count_properties (icalcomponent* component, icalproperty* icalcomponent_get_current_property (icalcomponent* component) { - - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; icalerror_check_arg_rz( (component!=0),"component"); - if ((c->property_iterator==0)){ + if ((component->property_iterator==0)){ return 0; } - return (icalproperty*) pvl_data(c->property_iterator); - + return (icalproperty*) pvl_data(component->property_iterator); } icalproperty* -icalcomponent_get_first_property (icalcomponent* component, icalproperty_kind kind) +icalcomponent_get_first_property (icalcomponent* c, icalproperty_kind kind) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - icalerror_check_arg_rz( (component!=0),"component"); + icalerror_check_arg_rz( (c!=0),"component"); for( c->property_iterator = pvl_head(c->properties); c->property_iterator != 0; @@ -522,10 +489,9 @@ icalcomponent_get_first_property (icalcomponent* component, icalproperty_kind ki } icalproperty* -icalcomponent_get_next_property (icalcomponent* component, icalproperty_kind kind) +icalcomponent_get_next_property (icalcomponent* c, icalproperty_kind kind) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - icalerror_check_arg_rz( (component!=0),"component"); + icalerror_check_arg_rz( (c!=0),"component"); if (c->property_iterator == 0){ return 0; @@ -554,31 +520,28 @@ icalcomponent_get_properties (icalcomponent* component, icalproperty_kind kind); void icalcomponent_add_component (icalcomponent* parent, icalcomponent* child) { - struct icalcomponent_impl *impl, *cimpl; - icalerror_check_arg_rv( (parent!=0), "parent"); icalerror_check_arg_rv( (child!=0), "child"); - impl = (struct icalcomponent_impl*)parent; - cimpl = (struct icalcomponent_impl*)child; - - icalerror_assert( (cimpl->parent ==0),"The child component has already been added to a parent component. Remove the component with icalcomponent_remove_component before calling icalcomponent_add_component"); + if (child->parent !=0) { + icalerror_set_errno(ICAL_USAGE_ERROR); + } - cimpl->parent = parent; + child->parent = parent; - pvl_push(impl->components,child); + pvl_push(parent->components,child); /* If the new component is a VTIMEZONE, add it to our array. */ - if (cimpl->kind == ICAL_VTIMEZONE_COMPONENT) { + if (child->kind == ICAL_VTIMEZONE_COMPONENT) { /* FIXME: Currently we are also creating this array when loading in a builtin VTIMEZONE, when we don't need it. */ - if (!impl->timezones) - impl->timezones = icaltimezone_array_new (); + if (!parent->timezones) + parent->timezones = icaltimezone_array_new (); - icaltimezone_array_append_from_vtimezone (impl->timezones, child); + icaltimezone_array_append_from_vtimezone (parent->timezones, child); /* Flag that we need to sort it before doing any binary searches. */ - impl->timezones_sorted = 0; + parent->timezones_sorted = 0; } } @@ -586,32 +549,28 @@ icalcomponent_add_component (icalcomponent* parent, icalcomponent* child) void icalcomponent_remove_component (icalcomponent* parent, icalcomponent* child) { - struct icalcomponent_impl *impl,*cimpl; pvl_elem itr, next_itr; icalerror_check_arg_rv( (parent!=0), "parent"); icalerror_check_arg_rv( (child!=0), "child"); - impl = (struct icalcomponent_impl*)parent; - cimpl = (struct icalcomponent_impl*)child; - /* If the component is a VTIMEZONE, remove it from our array as well. */ - if (cimpl->kind == ICAL_VTIMEZONE_COMPONENT) { + if (child->kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; int i, num_elements; - num_elements = impl->timezones ? impl->timezones->num_elements : 0; + num_elements = parent->timezones ? parent->timezones->num_elements : 0; for (i = 0; i < num_elements; i++) { - zone = icalarray_element_at (impl->timezones, i); + zone = icalarray_element_at (parent->timezones, i); if (icaltimezone_get_component (zone) == child) { icaltimezone_free (zone, 0); - icalarray_remove_element_at (impl->timezones, i); + icalarray_remove_element_at (parent->timezones, i); break; } } } - for( itr = pvl_head(impl->components); + for( itr = pvl_head(parent->components); itr != 0; itr = next_itr) { @@ -619,16 +578,16 @@ icalcomponent_remove_component (icalcomponent* parent, icalcomponent* child) if( pvl_data(itr) == (void*)child ){ - if (impl->component_iterator == itr){ + if (parent->component_iterator == itr){ /* Don't let the current iterator become invalid */ /* HACK. The semantics for this are troubling. */ - impl->component_iterator = - pvl_next(impl->component_iterator); + parent->component_iterator = + pvl_next(parent->component_iterator); } - pvl_remove( impl->components, itr); - cimpl->parent = 0; + pvl_remove( parent->components, itr); + child->parent = 0; break; } } @@ -641,11 +600,10 @@ icalcomponent_count_components (icalcomponent* component, { int count=0; pvl_elem itr; - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; icalerror_check_arg_rz( (component!=0), "component"); - for( itr = pvl_head(impl->components); + for( itr = pvl_head(component->components); itr != 0; itr = pvl_next(itr)) { @@ -661,24 +619,20 @@ icalcomponent_count_components (icalcomponent* component, icalcomponent* icalcomponent_get_current_component(icalcomponent* component) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - icalerror_check_arg_rz( (component!=0),"component"); - if (c->component_iterator == 0){ + if (component->component_iterator == 0){ return 0; } - return (icalcomponent*) pvl_data(c->component_iterator); + return (icalcomponent*) pvl_data(component->component_iterator); } icalcomponent* -icalcomponent_get_first_component (icalcomponent* component, +icalcomponent_get_first_component (icalcomponent* c, icalcomponent_kind kind) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - - icalerror_check_arg_rz( (component!=0),"component"); + icalerror_check_arg_rz( (c!=0),"component"); for( c->component_iterator = pvl_head(c->components); c->component_iterator != 0; @@ -697,11 +651,9 @@ icalcomponent_get_first_component (icalcomponent* component, icalcomponent* -icalcomponent_get_next_component (icalcomponent* component, icalcomponent_kind kind) +icalcomponent_get_next_component (icalcomponent* c, icalcomponent_kind kind) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - - icalerror_check_arg_rz( (component!=0),"component"); + icalerror_check_arg_rz( (c!=0),"component"); if (c->component_iterator == 0){ return 0; @@ -734,31 +686,54 @@ icalcomponent* icalcomponent_get_first_real_component(icalcomponent *c) if(kind == ICAL_VEVENT_COMPONENT || kind == ICAL_VTODO_COMPONENT || - kind == ICAL_VJOURNAL_COMPONENT ){ + kind == ICAL_VJOURNAL_COMPONENT || + kind == ICAL_VFREEBUSY_COMPONENT || + kind == ICAL_VQUERY_COMPONENT || + kind == ICAL_VREPLY_COMPONENT || + kind == ICAL_VAGENDA_COMPONENT){ return comp; } } return 0; } -struct icaltime_span icalcomponent_get_span(icalcomponent* comp) + +/** @brief Get the timespan covered by this component, in UTC + * (deprecated) + * + * see icalcomponent_foreach_recurrence() for a better way to + * extract spans from an component. + * + * This method can be called on either a VCALENDAR or any real + * component. If the VCALENDAR contains no real component, but + * contains a VTIMEZONE, we return that span instead. + * This might not be a desirable behavior; we keep it for now + * for backward compatibility, but it might be deprecated at a + * future time. + * + * FIXME this API needs to be clarified. DTEND is defined as the + * first available time after the end of this event, so the span + * should actually end 1 second before DTEND. + */ + +icaltime_span icalcomponent_get_span(icalcomponent* comp) { icalcomponent *inner; - icalproperty *p, *duration; icalcomponent_kind kind; - struct icaltime_span span; - struct icaltimetype start; + icaltime_span span; + struct icaltimetype start, end; span.start = 0; span.end = 0; span.is_busy= 1; /* initial Error checking */ + if (comp == NULL) { + return span; + } -/* icalerror_check_arg_rz( (comp!=0),"comp");*/ - + /* FIXME this might go away */ kind = icalcomponent_isa(comp); - if(kind == ICAL_VCALENDAR_COMPONENT){ inner = icalcomponent_get_first_real_component(comp); @@ -790,73 +765,330 @@ struct icaltime_span icalcomponent_get_span(icalcomponent* comp) } + /* Get to work. starting with DTSTART */ + start = icalcomponent_get_dtstart(comp); + if (icaltime_is_null_time(start)) { + return span; + } + span.start = icaltime_as_timet_with_zone(start, + icaltimezone_get_utc_timezone()); + /* The end time could be specified as either a DTEND or a DURATION */ + /* icalcomponent_get_dtend takes care of these cases. */ + end = icalcomponent_get_dtend(comp); + if (icaltime_is_null_time(end)) { + if (!icaltime_is_date(start)) { + /* If dtstart is a DATE-TIME and there is no DTEND nor DURATION + it takes no time */ + span.start = 0; + return span; + } else { + end = start; + } + } - /* Get to work. starting with DTSTART */ + span.end = icaltime_as_timet_with_zone(end, + icaltimezone_get_utc_timezone()); + if (icaltime_is_date(start)) { + /* Until the end of the day*/ + span.end += 60*60*24 - 1; + } - p = icalcomponent_get_first_property(inner, ICAL_DTSTART_PROPERTY); + return span; - if (p ==0 ) { - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - /*icalerror_warn("icalcomponent_get_span: component has no DTSTART time");*/ - return span; +} + +/** + * Decide if this recurrance is acceptable + * + * @param comp A valid icalcomponent. + * @param dtstart The base dtstart value for this component. + * @param recurtime The time to test against. + * + * @return true if the recurrence value is excluded, false otherwise. + * + * This function decides if a specific recurrence value is + * excluded by EXRULE or EXDATE properties. + * + * It's not the most efficient code. You might get better performance + * if you assume that recurtime is always increasing for each + * call. Then you could: + * + * - sort the EXDATE values + * - save the state of each EXRULE iterator for the next call. + * + * In this case though you don't need to worry how you call this + * function. It will always return the correct result. + */ + +int icalproperty_recurrence_is_excluded(icalcomponent *comp, + struct icaltimetype *dtstart, + struct icaltimetype *recurtime) { + icalproperty *exdate, *exrule; + + if (comp == NULL || + dtstart == NULL || + recurtime == NULL || + icaltime_is_null_time(*recurtime)) + /* BAD DATA */ + return 1; + + /** first test against the exdate values **/ + for (exdate = icalcomponent_get_first_property(comp,ICAL_EXDATE_PROPERTY); + exdate != NULL; + exdate = icalcomponent_get_next_property(comp,ICAL_EXDATE_PROPERTY)) { + + struct icaltimetype exdatetime = icalproperty_get_exdate(exdate); + + if (icaltime_compare(*recurtime, exdatetime) == 0) { + /** MATCHED **/ + return 1; } + } + /** Now test against the EXRULEs **/ + for (exrule = icalcomponent_get_first_property(comp,ICAL_EXRULE_PROPERTY); + exdate != NULL; + exdate = icalcomponent_get_next_property(comp,ICAL_EXRULE_PROPERTY)) { + + struct icalrecurrencetype recur = icalproperty_get_exrule(exrule); + icalrecur_iterator *exrule_itr = icalrecur_iterator_new(recur, *dtstart); + struct icaltimetype exrule_time; + + while (1) { + int result; + exrule_time = icalrecur_iterator_next(exrule_itr); + + if (icaltime_is_null_time(exrule_time)) + break; + + result = icaltime_compare(*recurtime, exrule_time); + if (result == 0) { + icalrecur_iterator_free(exrule_itr); + return 1; /** MATCH **/ + } + if (result == 1) + break; /** exrule_time > recurtime **/ + } - start = icalproperty_get_dtstart(p); + icalrecur_iterator_free(exrule_itr); + } - icalerror_clear_errno(); + return 0; /** no matches **/ +} - /* FIXME: Needs updating to new icaltimezone functions. */ -#if 0 - span.start = icalcomponent_convert_time(p); -#endif +/** + * @brief Return the busy status based on the TRANSP property. + * + * @param comp A valid icalcomponent. + * + * @return 1 if the event is a busy item, 0 if it is not. + */ -#ifdef TEST_CONVERT_TIME - printf("convert time:\n %s %s", - icalproperty_as_ical_string(p), ctime(&span.start)); -#endif +static int icalcomponent_is_busy(icalcomponent *comp) { + icalproperty *transp; + enum icalproperty_status status; + int ret = 1; - if(icalerrno != ICAL_NO_ERROR){ - span.start = 0; - return span; + /** @todo check access control here, converting busy->free if the + permissions do not allow access... */ + + /* Is this a busy time? Check the TRANSP property */ + transp = icalcomponent_get_first_property(comp, ICAL_TRANSP_PROPERTY); + + if (transp) { + icalvalue *transp_val = icalproperty_get_value(transp); + + switch (icalvalue_get_transp(transp_val)) { + case ICAL_TRANSP_OPAQUE: + case ICAL_TRANSP_OPAQUENOCONFLICT: + case ICAL_TRANSP_NONE: + ret = 1; + break; + case ICAL_TRANSP_TRANSPARENT: + case ICAL_TRANSP_TRANSPARENTNOCONFLICT: + ret = 0; + break; + default: + ret = 0; + break; + } + } + status = icalcomponent_get_status(comp); + if (ret && status) { + switch (status) { + case ICAL_STATUS_CANCELLED: + case ICAL_STATUS_TENTATIVE: + ret = 0; + break; + default: + break; } + } + return(ret); +} - /* The end time could be specified as either a DTEND or a DURATION */ - p = icalcomponent_get_first_property(inner, ICAL_DTEND_PROPERTY); - duration = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY); - if (p==0 && duration == 0 && start.is_date != 1) { - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - /*icalerror_warn("icalcomponent_get_span: component has neither DTEND nor DURATION time");*/ - span.start = 0; - return span; - } - if (p!=0){ - /* FIXME: Needs updating to new icaltimezone functions. */ -#if 0 - span.end = icalcomponent_convert_time(p); -#endif - } else if (start.is_date == 1) { - /* Duration is all day */ - span.end = span.start + 60*60*24; - } else { - /* Use the duration */ - struct icaldurationtype dur; - time_t durt; - - - dur = icalproperty_get_duration(duration); - durt = icaldurationtype_as_int(dur); - span.end = span.start+durt; +/** + * @brief cycle through all recurrances of an event + * + * @param comp A valid VEVENT component + * @param start Ignore timespans before this + * @param end Ignore timespans after this + * @param callback Function called for each timespan within the range + * @param callback_data Pointer passed back to the callback function + * + * This function will call the specified callback function for once + * for the base value of DTSTART, and foreach recurring date/time + * value. + * + * It will filter out events that are specified as an EXDATE or an EXRULE. + * + * @todo We do not filter out duplicate RRULES/RDATES + * @todo We do not handle RDATEs with explicit periods + */ + +void icalcomponent_foreach_recurrence(icalcomponent* comp, + struct icaltimetype start, + struct icaltimetype end, + void (*callback)(icalcomponent *comp, + struct icaltime_span *span, + void *data), + void *callback_data) +{ + struct icaltimetype dtstart, dtend; + icaltime_span recurspan, basespan, limit_span; + time_t limit_start, limit_end; + int dtduration; + icalproperty *rrule, *rdate; + struct icaldurationtype dur; + pvl_elem property_iterator; /* for saving the iterator */ + + if (comp == NULL || callback == NULL) + return; + + dtstart = icalcomponent_get_dtstart(comp); + + if (icaltime_is_null_time(dtstart)) + return; + + + /* The end time could be specified as either a DTEND or a DURATION */ + /* icalcomponent_get_dtend takes care of these cases. */ + dtend = icalcomponent_get_dtend(comp); + + /* Now set up the base span for this item, corresponding to the + base DTSTART and DTEND */ + basespan = icaltime_span_new(dtstart, dtend, 1); + + basespan.is_busy = icalcomponent_is_busy(comp); + + + /** Calculate the ceiling and floor values.. **/ + limit_start = icaltime_as_timet_with_zone(start, icaltimezone_get_utc_timezone()); + if (!icaltime_is_null_time(end)) + limit_end = icaltime_as_timet_with_zone(end, icaltimezone_get_utc_timezone()); + else + limit_end = INT_MAX; /* max 32 bit time_t */ + + limit_span.start = limit_start; + limit_span.end = limit_end; + + + /* Do the callback for the initial DTSTART entry */ + + if (!icalproperty_recurrence_is_excluded(comp, &dtstart, &dtstart)) { + /** call callback action **/ + if (icaltime_span_overlaps(&basespan, &limit_span)) + (*callback) (comp, &basespan, callback_data); + } + + recurspan = basespan; + dtduration = basespan.end - basespan.start; + + /* Now cycle through the rrule entries */ + for (rrule = icalcomponent_get_first_property(comp,ICAL_RRULE_PROPERTY); + rrule != NULL; + rrule = icalcomponent_get_next_property(comp,ICAL_RRULE_PROPERTY)) { + + struct icalrecurrencetype recur = icalproperty_get_rrule(rrule); + icalrecur_iterator *rrule_itr = icalrecur_iterator_new(recur, dtstart); + struct icaltimetype rrule_time; + + while (1) { + rrule_time = icalrecur_iterator_next(rrule_itr); + + if (icaltime_is_null_time(rrule_time)) + break; + + if (!icaltime_compare(rrule_time, dtstart)) + continue; + + dur = icaltime_subtract(rrule_time, dtstart); + + recurspan.start = basespan.start + icaldurationtype_as_int(dur); + recurspan.end = recurspan.start + dtduration; + + /** save the iterator ICK! **/ + property_iterator = comp->property_iterator; + + if (!icalproperty_recurrence_is_excluded(comp, &dtstart, &rrule_time)) { + /** call callback action **/ + if (icaltime_span_overlaps(&recurspan, &limit_span)) + (*callback) (comp, &recurspan, callback_data); + } + comp->property_iterator = property_iterator; + } /* end of iteration over a specific RRULE */ + + icalrecur_iterator_free(rrule_itr); + } /* end of RRULE loop */ + + + /** Now process RDATE entries **/ + for (rdate = icalcomponent_get_first_property(comp,ICAL_RDATE_PROPERTY); + rdate != NULL; + rdate = icalcomponent_get_next_property(comp,ICAL_RDATE_PROPERTY)) { + + struct icaldatetimeperiodtype rdate_period = icalproperty_get_rdate(rdate); + + /** RDATES can specify raw datetimes, periods, or dates. + we only support raw datetimes for now.. + + @todo Add support for other types **/ + + if (icaltime_is_null_time(rdate_period.time)) + continue; + + dur = icaltime_subtract(rdate_period.time, dtstart); + + recurspan.start = basespan.start + icaldurationtype_as_int(dur); + recurspan.end = recurspan.start + dtduration; + + /** save the iterator ICK! **/ + property_iterator = comp->property_iterator; + + if (!icalproperty_recurrence_is_excluded(comp, &dtstart, &rdate_period.time)) { + /** call callback action **/ + (*callback) (comp, &recurspan, callback_data); } + comp->property_iterator = property_iterator; + } +} + - return span; +int icalcomponent_check_restrictions(icalcomponent* comp){ + icalerror_check_arg_rz(comp!=0,"comp"); + return icalrestriction_check(comp); } +/** @brief returns the number of errors encountered parsing the data + * + * This function counts the number times the X-LIC-ERROR occurs + * in the data structure. + */ int icalcomponent_count_errors(icalcomponent* component) { @@ -864,9 +1096,8 @@ int icalcomponent_count_errors(icalcomponent* component) icalproperty *p; icalcomponent *c; pvl_elem itr; - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; - for( itr = pvl_head(impl->properties); + for( itr = pvl_head(component->properties); itr != 0; itr = pvl_next(itr)) { @@ -879,7 +1110,7 @@ int icalcomponent_count_errors(icalcomponent* component) } - for( itr = pvl_head(impl->components); + for( itr = pvl_head(component->components); itr != 0; itr = pvl_next(itr)) { @@ -898,9 +1129,8 @@ void icalcomponent_strip_errors(icalcomponent* component) icalproperty *p; icalcomponent *c; pvl_elem itr, next_itr; - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; - for( itr = pvl_head(impl->properties); + for( itr = pvl_head(component->properties); itr != 0; itr = next_itr) { @@ -913,7 +1143,7 @@ void icalcomponent_strip_errors(icalcomponent* component) } } - for( itr = pvl_head(impl->components); + for( itr = pvl_head(component->components); itr != 0; itr = pvl_next(itr)) { @@ -967,16 +1197,14 @@ void icalcomponent_convert_errors(icalcomponent* component) } default: { + break; } } if (rst.code != ICAL_UNKNOWN_STATUS){ rst.debug = icalproperty_get_xlicerror(p); icalcomponent_add_property(component, - icalproperty_new_requeststatus( - icalreqstattype_as_string(rst) - ) - ); + icalproperty_new_requeststatus(rst)); icalcomponent_remove_property(component,p); } @@ -994,16 +1222,12 @@ void icalcomponent_convert_errors(icalcomponent* component) icalcomponent* icalcomponent_get_parent(icalcomponent* component) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - - return c->parent; + return component->parent; } void icalcomponent_set_parent(icalcomponent* component, icalcomponent* parent) { - struct icalcomponent_impl *c = (struct icalcomponent_impl*)component; - - c->parent = parent; + component->parent = parent; } icalcompiter icalcompiter_null = {ICAL_NO_COMPONENT,0}; @@ -1022,6 +1246,7 @@ static struct icalcomponent_kind_map component_map[] = { ICAL_VTODO_COMPONENT, "VTODO" }, { ICAL_VJOURNAL_COMPONENT, "VJOURNAL" }, { ICAL_VCALENDAR_COMPONENT, "VCALENDAR" }, + { ICAL_VAGENDA_COMPONENT, "VAGENDA" }, { ICAL_VFREEBUSY_COMPONENT, "VFREEBUSY" }, { ICAL_VTIMEZONE_COMPONENT, "VTIMEZONE" }, { ICAL_VALARM_COMPONENT, "VALARM" }, @@ -1031,9 +1256,10 @@ static struct icalcomponent_kind_map component_map[] = { ICAL_VSCHEDULE_COMPONENT, "SCHEDULE" }, /* CAP components */ - { ICAL_VQUERY_COMPONENT, "VQUERY" }, { ICAL_VCAR_COMPONENT, "VCAR" }, { ICAL_VCOMMAND_COMPONENT, "VCOMMAND" }, + { ICAL_VQUERY_COMPONENT, "VQUERY" }, + { ICAL_VREPLY_COMPONENT, "VREPLY" }, /* libical private components */ { ICAL_XLICINVALID_COMPONENT, "X-LIC-UNKNOWN" }, @@ -1046,6 +1272,16 @@ static struct icalcomponent_kind_map component_map[] = }; +int icalcomponent_kind_is_valid(const icalcomponent_kind kind) +{ + int i = 0; + do { + if (component_map[i].kind == kind) + return 1; + } while (component_map[i++].kind != ICAL_NO_COMPONENT); + + return 0; +} const char* icalcomponent_kind_to_string(icalcomponent_kind kind) { @@ -1083,15 +1319,15 @@ icalcomponent_kind icalcomponent_string_to_kind(const char* string) icalcompiter icalcomponent_begin_component(icalcomponent* component,icalcomponent_kind kind) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; icalcompiter itr; pvl_elem i; itr.kind = kind; + itr.iter = NULL; - icalerror_check_arg_re( (component!=0),"component",icalcompiter_null); + icalerror_check_arg_re(component!=0,"component",icalcompiter_null); - for( i = pvl_head(impl->components); i != 0; i = pvl_next(i)) { + for( i = pvl_head(component->components); i != 0; i = pvl_next(i)) { icalcomponent *c = (icalcomponent*) pvl_data(i); @@ -1109,15 +1345,14 @@ icalcomponent_begin_component(icalcomponent* component,icalcomponent_kind kind) icalcompiter icalcomponent_end_component(icalcomponent* component,icalcomponent_kind kind) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)component; icalcompiter itr; pvl_elem i; itr.kind = kind; - icalerror_check_arg_re( (component!=0),"component",icalcompiter_null); + icalerror_check_arg_re(component!=0,"component",icalcompiter_null); - for( i = pvl_tail(impl->components); i != 0; i = pvl_prior(i)) { + for( i = pvl_tail(component->components); i != 0; i = pvl_prior(i)) { icalcomponent *c = (icalcomponent*) pvl_data(i); @@ -1198,140 +1433,240 @@ icalcomponent* icalcomponent_get_inner(icalcomponent* comp) } } +/** @brief sets the METHOD property to the given method + */ -void icalcomponent_set_dtstart(icalcomponent* comp, struct icaltimetype v) +void icalcomponent_set_method(icalcomponent* comp, icalproperty_method method) { + icalproperty *prop + = icalcomponent_get_first_property(comp, ICAL_METHOD_PROPERTY); - icalcomponent *inner = icalcomponent_get_inner(comp); + + if (prop == 0){ + prop = icalproperty_new_method(method); + icalcomponent_add_property(comp, prop); + } + + icalproperty_set_method(prop,method); + +} + +/** @brief returns the METHOD property + */ + +icalproperty_method icalcomponent_get_method(icalcomponent* comp) +{ icalproperty *prop - = icalcomponent_get_first_property(inner, ICAL_DTSTART_PROPERTY); + = icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY); + if (prop == 0){ + return ICAL_METHOD_NONE; + } + + return icalproperty_get_method(prop); +} + +#define ICALSETUPSET(p_kind) \ + icalcomponent *inner; \ + icalproperty *prop; \ + icalerror_check_arg_rv(comp!=0,"comp");\ + inner = icalcomponent_get_inner(comp); \ + if(inner == 0){\ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);\ + return;\ + }\ + prop = icalcomponent_get_first_property(inner, p_kind); + + +/** @brief Set DTSTART property to given icaltime + * + * This method respects the icaltime type (DATE vs DATE-TIME) and + * timezone (or lack thereof). + */ +void icalcomponent_set_dtstart(icalcomponent* comp, struct icaltimetype v) +{ + char *tzid; + ICALSETUPSET(ICAL_DTSTART_PROPERTY); if (prop == 0){ prop = icalproperty_new_dtstart(v); icalcomponent_add_property(inner, prop); + } else { + icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER); } icalproperty_set_dtstart(prop,v); + if ((tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) { + icalproperty_add_parameter(prop, icalparameter_new_tzid(tzid)); + } } +/** @brief Get a DATE or DATE-TIME property as an icaltime + * + * If the property is a DATE-TIME with a timezone parameter and a + * corresponding VTIMEZONE is present in the component, the + * returned component will already be in the correct timezone; + * otherwise the caller is responsible for converting it. + * + * FIXME this is useless until we can flag the failure + */ +static struct icaltimetype +icalcomponent_get_datetime(icalcomponent *comp, icalproperty *prop) { + + icalcomponent *c; + icalparameter *param; + struct icaltimetype ret; + + ret = icalvalue_get_datetime(icalproperty_get_value(prop)); + + if ((param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER)) + != NULL) { + const char *tzid = icalparameter_get_tzid(param); + icaltimezone *tz = NULL; + + for (c = comp; c != NULL; c = icalcomponent_get_parent(c)) { + tz = icalcomponent_get_timezone(c, tzid); + if (tz != NULL) + break; + } + + if (tz == NULL) + tz = icaltimezone_get_builtin_timezone(tzid); + if (tz != NULL) + ret = icaltime_set_timezone(&ret, tz); + } + + return ret; +} + +/** @brief Get DTSTART property as an icaltime + * + * If DTSTART is a DATE-TIME with a timezone parameter and a + * corresponding VTIMEZONE is present in the component, the + * returned component will already be in the correct timezone; + * otherwise the caller is responsible for converting it. + * + * FIXME this is useless until we can flag the failure + */ struct icaltimetype icalcomponent_get_dtstart(icalcomponent* comp) { icalcomponent *inner = icalcomponent_get_inner(comp); - icalproperty *prop - = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY); + icalproperty *prop; + prop = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY); if (prop == 0){ return icaltime_null_time(); } - - return icalproperty_get_dtstart(prop); -} + return icalcomponent_get_datetime(comp, prop); +} +/** @brief Get DTEND property as an icaltime + * + * If a DTEND property is not present but a DURATION is, we use + * that to determine the proper end. + * + * If DTSTART is a DATE-TIME with a timezone parameter and a + * corresponding VTIMEZONE is present in the component, the + * returned component will already be in the correct timezone; + * otherwise the caller is responsible for converting it. + * + * FIXME this is useless until we can flag the failure + */ struct icaltimetype icalcomponent_get_dtend(icalcomponent* comp) { icalcomponent *inner = icalcomponent_get_inner(comp); - icalproperty *end_prop = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY); - icalproperty *dur_prop = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY); + struct icaltimetype ret = icaltime_null_time(); - - if( end_prop == 0 && dur_prop == 0){ - return icaltime_null_time(); - } else if ( end_prop != 0) { - return icalproperty_get_dtend(end_prop); + if ( end_prop != 0) { + ret = icalcomponent_get_datetime(comp, end_prop); } else if ( dur_prop != 0) { - + struct icaltimetype start = icalcomponent_get_dtstart(inner); struct icaldurationtype duration = icalproperty_get_duration(dur_prop); - - struct icaltimetype end = icaltime_add(start,duration); - return end; - - } else { - /* Error, both duration and dtend have been specified */ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return icaltime_null_time(); + struct icaltimetype end = icaltime_add(start,duration); + ret = end; } - -} + return ret; +} +/** @brief Set DTEND property to given icaltime + * + * This method respects the icaltime type (DATE vs DATE-TIME) and + * timezone (or lack thereof). + * + * This also checks that a DURATION property isn't already there, + * and returns an error if it is. It's the caller's responsibility + * to remove it. + */ void icalcomponent_set_dtend(icalcomponent* comp, struct icaltimetype v) { - icalcomponent *inner = icalcomponent_get_inner(comp); - - icalproperty *end_prop - = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY); + char *tzid; + ICALSETUPSET(ICAL_DTEND_PROPERTY); - icalproperty *dur_prop - = icalcomponent_get_first_property(inner,ICAL_DURATION_PROPERTY); - - - if( end_prop == 0 && dur_prop == 0){ - end_prop = icalproperty_new_dtend(v); - icalcomponent_add_property(inner,end_prop); - } else if ( end_prop != 0) { - icalproperty_set_dtend(end_prop,v); - } else if ( dur_prop != 0) { - struct icaltimetype start = - icalcomponent_get_dtstart(inner); - - struct icaltimetype end = - icalcomponent_get_dtend(inner); + if (icalcomponent_get_first_property(inner,ICAL_DURATION_PROPERTY) + != NULL) { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return; + } - struct icaldurationtype dur - = icaltime_subtract(end,start); + if (prop == 0) { + prop = icalproperty_new_dtend(v); + icalcomponent_add_property(inner, prop); + } else { + icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER); + } - icalproperty_set_duration(dur_prop,dur); + icalproperty_set_dtend(prop,v); - } else { - /* Error, both duration and dtend have been specified */ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + if ((tzid = icaltime_get_tzid(v)) != NULL && !icaltime_is_utc(v)) { + icalproperty_add_parameter(prop, icalparameter_new_tzid(tzid)); } } +/** @brief Set DURATION property to given icalduration + * + * This method respects the icaltime type (DATE vs DATE-TIME) and + * timezone (or lack thereof). + * + * This also checks that a DTEND property isn't already there, + * and returns an error if it is. It's the caller's responsibility + * to remove it. + */ void icalcomponent_set_duration(icalcomponent* comp, struct icaldurationtype v) { - icalcomponent *inner = icalcomponent_get_inner(comp); - - icalproperty *end_prop - = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY); - - icalproperty *dur_prop - = icalcomponent_get_first_property(inner,ICAL_DURATION_PROPERTY); - - - if( end_prop == 0 && dur_prop == 0){ - dur_prop = icalproperty_new_duration(v); - icalcomponent_add_property(inner, dur_prop); - } else if ( end_prop != 0) { - struct icaltimetype start = - icalcomponent_get_dtstart(inner); - - struct icaltimetype new_end = icaltime_add(start,v); + ICALSETUPSET(ICAL_DURATION_PROPERTY); - icalproperty_set_dtend(end_prop,new_end); + if (icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY) != NULL) { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return; + } - } else if ( dur_prop != 0) { - icalproperty_set_duration(dur_prop,v); + if (prop == 0) { + prop = icalproperty_new_duration(v); + icalcomponent_add_property(inner, prop); } else { - /* Error, both duration and dtend have been specified */ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + icalproperty_set_duration(prop,v); } } +/** @brief Get DURATION property as an icalduration + * + * If a DURATION property is not present but a DTEND is, we use + * that to determine the proper end. + */ struct icaldurationtype icalcomponent_get_duration(icalcomponent* comp) { icalcomponent *inner = icalcomponent_get_inner(comp); @@ -1342,65 +1677,34 @@ struct icaldurationtype icalcomponent_get_duration(icalcomponent* comp) icalproperty *dur_prop = icalcomponent_get_first_property(inner,ICAL_DURATION_PROPERTY); - struct icaldurationtype null_duration; - memset(&null_duration,0,sizeof(struct icaldurationtype)); + struct icaldurationtype ret = icaldurationtype_null_duration(); + if ( dur_prop != 0 && end_prop == 0) { + ret = icalproperty_get_duration(dur_prop); - if( end_prop == 0 && dur_prop == 0){ - return null_duration; - } else if ( end_prop != 0) { + } else if ( end_prop != 0 && dur_prop == 0) { + /** + * FIXME + * We assume DTSTART and DTEND are not in different time zones. + * Does the standard actually guarantee this? + */ struct icaltimetype start = icalcomponent_get_dtstart(inner); - time_t startt = icaltime_as_timet(start); - struct icaltimetype end = icalcomponent_get_dtend(inner); - time_t endt = icaltime_as_timet(end); - - return icaldurationtype_from_int(endt-startt); - } else if ( dur_prop != 0) { - return icalproperty_get_duration(dur_prop); + + ret = icaltime_subtract(end, start); } else { /* Error, both duration and dtend have been specified */ icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return null_duration; - } -} - -void icalcomponent_set_method(icalcomponent* comp, icalproperty_method method) -{ - icalproperty *prop - = icalcomponent_get_first_property(comp, ICAL_METHOD_PROPERTY); - - - if (prop == 0){ - prop = icalproperty_new_method(method); - icalcomponent_add_property(comp, prop); - } - - icalproperty_set_method(prop,method); - -} - -icalproperty_method icalcomponent_get_method(icalcomponent* comp) -{ - icalproperty *prop - = icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY); - - if (prop == 0){ - return ICAL_METHOD_NONE; } - - return icalproperty_get_method(prop); + return ret; } void icalcomponent_set_dtstamp(icalcomponent* comp, struct icaltimetype v) { - icalcomponent *inner = icalcomponent_get_inner(comp); - icalproperty *prop - = icalcomponent_get_first_property(inner, ICAL_DTSTAMP_PROPERTY); - + ICALSETUPSET(ICAL_DTSTAMP_PROPERTY); if (prop == 0){ prop = icalproperty_new_dtstamp(v); @@ -1428,10 +1732,8 @@ struct icaltimetype icalcomponent_get_dtstamp(icalcomponent* comp) void icalcomponent_set_summary(icalcomponent* comp, const char* v) { - icalcomponent *inner = icalcomponent_get_inner(comp); - icalproperty *prop - = icalcomponent_get_first_property(inner, ICAL_SUMMARY_PROPERTY); - + ICALSETUPSET(ICAL_SUMMARY_PROPERTY) + if (prop == 0){ prop = icalproperty_new_summary(v); icalcomponent_add_property(inner, prop); @@ -1443,9 +1745,18 @@ void icalcomponent_set_summary(icalcomponent* comp, const char* v) const char* icalcomponent_get_summary(icalcomponent* comp) { - icalcomponent *inner = icalcomponent_get_inner(comp); - icalproperty *prop - = icalcomponent_get_first_property(inner,ICAL_SUMMARY_PROPERTY); + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_SUMMARY_PROPERTY); if (prop == 0){ return 0; @@ -1455,41 +1766,240 @@ const char* icalcomponent_get_summary(icalcomponent* comp) } -void icalcomponent_set_comment(icalcomponent* comp, const char* v); -const char* icalcomponent_get_comment(icalcomponent* comp); +void icalcomponent_set_comment(icalcomponent* comp, const char* v) +{ + ICALSETUPSET(ICAL_COMMENT_PROPERTY); + + if (prop == 0){ + prop = icalproperty_new_comment(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_summary(prop,v); + +} +const char* icalcomponent_get_comment(icalcomponent* comp){ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_COMMENT_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_comment(prop); +} void icalcomponent_set_uid(icalcomponent* comp, const char* v) { - icalcomponent *inner = icalcomponent_get_inner (comp); - icalproperty *prop - = icalcomponent_get_first_property (inner, ICAL_UID_PROPERTY); + ICALSETUPSET(ICAL_UID_PROPERTY); - if (prop == 0) { - prop = icalproperty_new_uid (v); - icalcomponent_add_property (inner, prop); - } + if (prop == 0){ + prop = icalproperty_new_uid(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_summary(prop,v); - icalproperty_set_uid (prop, v); } +const char* icalcomponent_get_uid(icalcomponent* comp){ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); -const char* icalcomponent_get_uid(icalcomponent* comp) + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_uid(prop); +} + +void icalcomponent_set_recurrenceid(icalcomponent* comp, struct icaltimetype v) { - icalcomponent *inner = icalcomponent_get_inner (comp); - icalproperty *prop = icalcomponent_get_first_property (inner, ICAL_UID_PROPERTY); + ICALSETUPSET(ICAL_RECURRENCEID_PROPERTY); - if (prop == 0) { - return 0; - } + if (prop == 0){ + prop = icalproperty_new_recurrenceid(v); + icalcomponent_add_property(inner, prop); + } - return icalproperty_get_uid (prop); + icalproperty_set_recurrenceid(prop,v); } +struct icaltimetype icalcomponent_get_recurrenceid(icalcomponent* comp) +{ + icalcomponent *inner; + icalproperty *prop; + if (comp == 0) { + icalerror_set_errno(ICAL_BADARG_ERROR); + return icaltime_null_time(); + } -void icalcomponent_set_recurrenceid(icalcomponent* comp, - struct icaltimetype v); -struct icaltimetype icalcomponent_get_recurrenceid(icalcomponent* comp); + inner = icalcomponent_get_inner(comp); + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return icaltime_null_time(); + } + + prop= icalcomponent_get_first_property(inner, ICAL_RECURRENCEID_PROPERTY); + + if (prop == 0){ + return icaltime_null_time(); + } + + return icalproperty_get_recurrenceid(prop); +} + +void icalcomponent_set_description(icalcomponent* comp, const char* v) +{ + ICALSETUPSET(ICAL_DESCRIPTION_PROPERTY); + + if (prop == 0){ + prop = icalproperty_new_description(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_description(prop,v); +} +const char* icalcomponent_get_description(icalcomponent* comp) +{ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_DESCRIPTION_PROPERTY); + + if (prop == 0){ + return 0; + } + return icalproperty_get_description(prop); +} + +void icalcomponent_set_location(icalcomponent* comp, const char* v) +{ + ICALSETUPSET(ICAL_LOCATION_PROPERTY) + if (prop == 0){ + prop = icalproperty_new_location(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_location(prop,v); +} +const char* icalcomponent_get_location(icalcomponent* comp) +{ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_LOCATION_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_location(prop); +} + +void icalcomponent_set_sequence(icalcomponent* comp, int v) +{ + ICALSETUPSET(ICAL_SEQUENCE_PROPERTY); + + if (prop == 0){ + prop = icalproperty_new_sequence(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_sequence(prop,v); + +} +int icalcomponent_get_sequence(icalcomponent* comp){ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_SEQUENCE_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_sequence(prop); +} + + +void icalcomponent_set_status(icalcomponent* comp, enum icalproperty_status v) +{ + ICALSETUPSET(ICAL_STATUS_PROPERTY); + + if (prop == 0){ + prop = icalproperty_new_status(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_status(prop,v); + +} +enum icalproperty_status icalcomponent_get_status(icalcomponent* comp){ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_STATUS_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_status(prop); +} icalcomponent* icalcomponent_new_vcalendar() { @@ -1527,15 +2037,29 @@ icalcomponent* icalcomponent_new_xdaylight() { return icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT); } - +icalcomponent* icalcomponent_new_vagenda() +{ + return icalcomponent_new(ICAL_VAGENDA_COMPONENT); +} +icalcomponent* icalcomponent_new_vquery() +{ + return icalcomponent_new(ICAL_VQUERY_COMPONENT); +} +icalcomponent* icalcomponent_new_vreply() +{ + return icalcomponent_new(ICAL_VREPLY_COMPONENT); +} /* * Timezone stuff. */ -/* This takes 2 VCALENDAR components and merges the second one into the first, - resolving any problems with conflicting TZIDs. comp_to_merge will no - longer exist after calling this function. */ + +/** + * This takes 2 VCALENDAR components and merges the second one into the first, + * resolving any problems with conflicting TZIDs. comp_to_merge will no + * longer exist after calling this function. + */ void icalcomponent_merge_component(icalcomponent* comp, icalcomponent* comp_to_merge) { @@ -1602,8 +2126,7 @@ static void icalcomponent_merge_vtimezone (icalcomponent *comp, icalproperty *tzid_prop; const char *tzid; char *tzid_copy; - icaltimezone *existing_zone; - icalcomponent *existing_vtimezone; + icaltimezone *existing_vtimezone; /* Get the TZID of the VTIMEZONE. */ tzid_prop = icalcomponent_get_first_property (vtimezone, ICAL_TZID_PROPERTY); @@ -1615,11 +2138,11 @@ static void icalcomponent_merge_vtimezone (icalcomponent *comp, return; /* See if there is already a VTIMEZONE in comp with the same TZID. */ - existing_zone = icalcomponent_get_timezone (comp, tzid); + existing_vtimezone = icalcomponent_get_timezone (comp, tzid); /* If there is no existing VTIMEZONE with the same TZID, we can just move the VTIMEZONE to comp and return. */ - if (!existing_zone) { + if (!existing_vtimezone) { icalcomponent_remove_component (icalcomponent_get_parent (vtimezone), vtimezone); icalcomponent_add_component (comp, vtimezone); @@ -1641,8 +2164,7 @@ static void icalcomponent_merge_vtimezone (icalcomponent *comp, return; } - existing_vtimezone = icaltimezone_get_component (existing_zone); - if (!icalcomponent_compare_vtimezones (existing_vtimezone, vtimezone)) { + if (!icalcomponent_compare_vtimezones (comp, vtimezone)) { /* FIXME: Handle possible NEWFAILED error. */ /* Now we have two different VTIMEZONEs with the same TZID. */ @@ -1660,8 +2182,8 @@ icalcomponent_handle_conflicting_vtimezones (icalcomponent *comp, const char *tzid, icalarray *tzids_to_rename) { - struct icalcomponent_impl *impl = (struct icalcomponent_impl*)comp; - int tzid_len, i, suffix, max_suffix = 1, num_elements; + int i, suffix, max_suffix = 0, num_elements; + unsigned int tzid_len; char *tzid_copy, *new_tzid, suffix_buf[32]; /* Find the length of the TZID without any trailing digits. */ @@ -1674,13 +2196,13 @@ icalcomponent_handle_conflicting_vtimezones (icalcomponent *comp, same prefix (e.g. 'London'). If it matches any of those, we have to rename the TZIDs to that TZID, else we rename to a new TZID, using the biggest numeric suffix found + 1. */ - num_elements = impl->timezones ? impl->timezones->num_elements : 0; + num_elements = comp->timezones ? comp->timezones->num_elements : 0; for (i = 0; i < num_elements; i++) { icaltimezone *zone; char *existing_tzid, *existing_tzid_copy; - int existing_tzid_len; + unsigned int existing_tzid_len; - zone = icalarray_element_at (impl->timezones, i); + zone = icalarray_element_at (comp->timezones, i); existing_tzid = icaltimezone_get_tzid (zone); /* Find the length of the TZID without any trailing digits. */ @@ -1733,7 +2255,7 @@ icalcomponent_handle_conflicting_vtimezones (icalcomponent *comp, /* Returns the length of the TZID, without any trailing digits. */ -static int icalcomponent_get_tzid_prefix_len (const char *tzid) +static unsigned int icalcomponent_get_tzid_prefix_len (const char *tzid) { int len; const char *p; @@ -1749,9 +2271,11 @@ static int icalcomponent_get_tzid_prefix_len (const char *tzid) } -/* Renames all references to the given TZIDs to a new name. rename_table - contains pairs of strings - a current TZID, and the new TZID to rename it - to. */ +/** + * Renames all references to the given TZIDs to a new name. rename_table + * contains pairs of strings - a current TZID, and the new TZID to rename it + * to. + */ static void icalcomponent_rename_tzids(icalcomponent* comp, icalarray* rename_table) { @@ -1781,7 +2305,9 @@ static void icalcomponent_rename_tzids_callback(icalparameter *param, void *data } -/* Calls the given function for each TZID parameter found in the component. */ +/** + * Calls the given function for each TZID parameter found in the component. + */ void icalcomponent_foreach_tzid(icalcomponent* comp, void (*callback)(icalparameter *param, void *data), void *callback_data) @@ -1819,33 +2345,32 @@ void icalcomponent_foreach_tzid(icalcomponent* comp, -/* Returns the icaltimezone from the component corresponding to the given - TZID, or NULL if the component does not have a corresponding VTIMEZONE. */ +/** + * Returns the icaltimezone from the component corresponding to the given + * TZID, or NULL if the component does not have a corresponding VTIMEZONE. + */ icaltimezone* icalcomponent_get_timezone(icalcomponent* comp, const char *tzid) { - struct icalcomponent_impl *impl; icaltimezone *zone; int lower, upper, middle, cmp; char *zone_tzid; - impl = (struct icalcomponent_impl*)comp; - - if (!impl->timezones) + if (!comp->timezones) return NULL; /* Sort the array if necessary (by the TZID string). */ - if (!impl->timezones_sorted) { - icalarray_sort (impl->timezones, icalcomponent_compare_timezone_fn); - impl->timezones_sorted = 1; + if (!comp->timezones_sorted) { + icalarray_sort (comp->timezones, icalcomponent_compare_timezone_fn); + comp->timezones_sorted = 1; } /* Do a simple binary search. */ lower = middle = 0; - upper = impl->timezones->num_elements; + upper = comp->timezones->num_elements; while (lower < upper) { middle = (lower + upper) >> 1; - zone = icalarray_element_at (impl->timezones, middle); + zone = icalarray_element_at (comp->timezones, middle); zone_tzid = icaltimezone_get_tzid (zone); cmp = strcmp (tzid, zone_tzid); if (cmp == 0) @@ -1860,13 +2385,14 @@ icaltimezone* icalcomponent_get_timezone(icalcomponent* comp, const char *tzid) } -/* A function to compare 2 icaltimezone elements, used for qsort(). */ +/** + * A function to compare 2 icaltimezone elements, used for qsort(). + */ static int icalcomponent_compare_timezone_fn (const void *elem1, const void *elem2) { icaltimezone *zone1, *zone2; const char *zone1_tzid, *zone2_tzid; - int retval; zone1 = (icaltimezone*) elem1; zone2 = (icaltimezone*) elem2; @@ -1878,14 +2404,16 @@ static int icalcomponent_compare_timezone_fn (const void *elem1, } -/* Compares 2 VTIMEZONE components to see if they match, ignoring their TZIDs. - It returns 1 if they match, 0 if they don't, or -1 on error. */ +/** + * Compares 2 VTIMEZONE components to see if they match, ignoring their TZIDs. + * It returns 1 if they match, 0 if they don't, or -1 on error. + */ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1, icalcomponent *vtimezone2) { icalproperty *prop1, *prop2; const char *tzid1, *tzid2; - char *tzid2_copy, *string1, *string2, *string1_copy; + char *tzid2_copy, *string1, *string2; int cmp; /* Get the TZID property of the first VTIMEZONE. */ @@ -1893,7 +2421,6 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1, if (!prop1) return -1; - /* This returns the pointer to the actual string in the property. */ tzid1 = icalproperty_get_tzid (prop1); if (!tzid1) return -1; @@ -1903,7 +2430,6 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1, if (!prop2) return -1; - /* This returns the pointer to the actual string in the property. */ tzid2 = icalproperty_get_tzid (prop2); if (!tzid2) return -1; @@ -1921,32 +2447,21 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1, /* Now convert both VTIMEZONEs to strings and compare them. */ string1 = icalcomponent_as_ical_string (vtimezone1); if (!string1) { - /* Try to reset the property. Though this may not work if we are low - on memory. */ - icalproperty_set_tzid (prop2, tzid2_copy); - free (tzid2_copy); - return -1; - } - - /* Copy the string, since it is in a temporary buffer which may get freed - during the next call. */ - string1_copy = strdup (string1); - if (!string1_copy) { - icalproperty_set_tzid (prop2, tzid2_copy); free (tzid2_copy); return -1; } string2 = icalcomponent_as_ical_string (vtimezone2); if (!string2) { - icalproperty_set_tzid (prop2, tzid2_copy); + free (string1); free (tzid2_copy); return -1; } - cmp = strcmp (string1_copy, string2); + cmp = strcmp (string1, string2); - free (string1_copy); + free (string1); + free (string2); /* Now reset the second TZID. */ icalproperty_set_tzid (prop2, tzid2_copy); @@ -1954,3 +2469,143 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1, return (cmp == 0) ? 1 : 0; } + + + + + + +/** + * @brief set the RELCALID property of a component. + * + * @param comp Valid calendar component. + * @param v Relcalid URL value + */ + +void icalcomponent_set_relcalid(icalcomponent* comp, const char* v) +{ + ICALSETUPSET(ICAL_RELCALID_PROPERTY); + + if (prop == 0){ + prop = icalproperty_new_relcalid(v); + icalcomponent_add_property(inner, prop); + } + + icalproperty_set_relcalid(prop,v); + +} + + +/** + * @brief get the RELCALID property of a component. + * + * @param comp Valid calendar component. + */ + +const char* icalcomponent_get_relcalid(icalcomponent* comp){ + icalcomponent *inner; + icalproperty *prop; + icalerror_check_arg_rz(comp!=0,"comp"); + + inner = icalcomponent_get_inner(comp); + + if(inner == 0){ + return 0; + } + + prop= icalcomponent_get_first_property(inner,ICAL_RELCALID_PROPERTY); + + if (prop == 0){ + return 0; + } + + return icalproperty_get_relcalid(prop); +} + + +/** @brief Return the time a TODO task is DUE. + * + * @param comp Valid calendar component. + * + * Uses the DUE: property if it exists, otherwise we calculate the DUE + * value by adding the task's duration to the DTSTART time + */ + +struct icaltimetype icalcomponent_get_due(icalcomponent* comp) +{ + icalcomponent *inner = icalcomponent_get_inner(comp); + + icalproperty *due_prop + = icalcomponent_get_first_property(inner,ICAL_DUE_PROPERTY); + + icalproperty *dur_prop + = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY); + + if( due_prop == 0 && dur_prop == 0){ + return icaltime_null_time(); + } else if ( due_prop != 0) { + return icalproperty_get_due(due_prop); + } else if ( dur_prop != 0) { + + struct icaltimetype start = + icalcomponent_get_dtstart(inner); + struct icaldurationtype duration = + icalproperty_get_duration(dur_prop); + + struct icaltimetype due = icaltime_add(start,duration); + + return due; + + } else { + /* Error, both duration and due have been specified */ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return icaltime_null_time(); + + } + +} + +/** @brief Set the due date of a VTODO task. + * + * @param comp Valid VTODO component. + * @param v Valid due date time. + * + * - If no duration or due properties then set the DUE property. + * - If a DUE property is already set, then reset it to the value v. + * - If a DURATION property is already set, then calculate the new + * duration based on the supplied value of v. + */ + +void icalcomponent_set_due(icalcomponent* comp, struct icaltimetype v) +{ + icalcomponent *inner = icalcomponent_get_inner(comp); + + icalproperty *due_prop + = icalcomponent_get_first_property(inner,ICAL_DUE_PROPERTY); + + icalproperty *dur_prop + = icalcomponent_get_first_property(inner,ICAL_DURATION_PROPERTY); + + + if( due_prop == 0 && dur_prop == 0){ + due_prop = icalproperty_new_due(v); + icalcomponent_add_property(inner,due_prop); + } else if ( due_prop != 0) { + icalproperty_set_due(due_prop,v); + } else if ( dur_prop != 0) { + struct icaltimetype start = + icalcomponent_get_dtstart(inner); + + struct icaltimetype due = + icalcomponent_get_due(inner); + + struct icaldurationtype dur + = icaltime_subtract(due,start); + + icalproperty_set_duration(dur_prop,dur); + + } else { + /* Error, both duration and due have been specified */ + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + } +} diff --git a/libical/src/libical/icalcomponent.h b/libical/src/libical/icalcomponent.h index 55c0592bb2..be9bf8cc17 100644 --- a/libical/src/libical/icalcomponent.h +++ b/libical/src/libical/icalcomponent.h @@ -27,15 +27,15 @@ #include "icalproperty.h" #include "icalvalue.h" #include "icalenums.h" /* defines icalcomponent_kind */ -#include "icalattendee.h" #include "pvl.h" -typedef void icalcomponent; +typedef struct icalcomponent_impl icalcomponent; -/* An opaque struct representing a timezone. We declare this here to avoid - a circular dependancy. */ -#ifndef ICALTIMEONE_DEFINED -#define ICALTIMEONE_DEFINED +#ifndef ICALTIMEZONE_DEFINED +#define ICALTIMEZONE_DEFINED +/** @brief An opaque struct representing a timezone. + * We declare this here to avoid a circular dependancy. + */ typedef struct _icaltimezone icaltimezone; #endif @@ -59,7 +59,7 @@ char* icalcomponent_as_ical_string(icalcomponent* component); int icalcomponent_is_valid(icalcomponent* component); -icalcomponent_kind icalcomponent_isa(icalcomponent* component); +icalcomponent_kind icalcomponent_isa(const icalcomponent* component); int icalcomponent_isa_component (void* component); @@ -105,7 +105,8 @@ void icalcomponent_remove_component(icalcomponent* parent, int icalcomponent_count_components(icalcomponent* component, icalcomponent_kind kind); -/* This takes 2 VCALENDAR components and merges the second one into the first, +/** + This takes 2 VCALENDAR components and merges the second one into the first, resolving any problems with conflicting TZIDs. comp_to_merge will no longer exist after calling this function. */ void icalcomponent_merge_component(icalcomponent* comp, @@ -136,16 +137,20 @@ icalcomponent* icalcompiter_prior(icalcompiter* i); icalcomponent* icalcompiter_deref(icalcompiter* i); +/* Working with embedded error properties */ +/* Check the component against itip rules and insert error properties*/ /* Working with embedded error properties */ +int icalcomponent_check_restrictions(icalcomponent* comp); +/** Count embedded errors. */ int icalcomponent_count_errors(icalcomponent* component); -/* Remove all X-LIC-ERROR properties*/ +/** Remove all X-LIC-ERROR properties*/ void icalcomponent_strip_errors(icalcomponent* component); -/* Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/ +/** Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/ void icalcomponent_convert_errors(icalcomponent* component); /* Internal operations. They are private, and you should not be using them. */ @@ -153,7 +158,9 @@ icalcomponent* icalcomponent_get_parent(icalcomponent* component); void icalcomponent_set_parent(icalcomponent* component, icalcomponent* parent); -/* Kind conversion routiens */ +/* Kind conversion routines */ + +int icalcomponent_kind_is_valid(const icalcomponent_kind kind); icalcomponent_kind icalcomponent_string_to_kind(const char* string); @@ -166,11 +173,11 @@ If the code was in an OO language, the remaining routines would be members of classes derived from icalcomponent. Don't call them on the wrong component subtypes. */ -/* For VCOMPONENT: Return a reference to the first VEVENT, VTODO or +/** For VCOMPONENT: Return a reference to the first VEVENT, VTODO or VJOURNAL */ icalcomponent* icalcomponent_get_first_real_component(icalcomponent *c); -/* For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the start and end +/** For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the start and end times of an event in UTC */ struct icaltime_span icalcomponent_get_span(icalcomponent* comp); @@ -192,6 +199,9 @@ struct icaltimetype icalcomponent_get_dtstart(icalcomponent* comp); struct icaltimetype icalcomponent_get_dtend(icalcomponent* comp); void icalcomponent_set_dtend(icalcomponent* comp, struct icaltimetype v); +struct icaltimetype icalcomponent_get_due(icalcomponent* comp); +void icalcomponent_set_due(icalcomponent* comp, struct icaltimetype v); + void icalcomponent_set_duration(icalcomponent* comp, struct icaldurationtype v); struct icaldurationtype icalcomponent_get_duration(icalcomponent* comp); @@ -202,7 +212,6 @@ icalproperty_method icalcomponent_get_method(icalcomponent* comp); struct icaltimetype icalcomponent_get_dtstamp(icalcomponent* comp); void icalcomponent_set_dtstamp(icalcomponent* comp, struct icaltimetype v); - void icalcomponent_set_summary(icalcomponent* comp, const char* v); const char* icalcomponent_get_summary(icalcomponent* comp); @@ -212,37 +221,49 @@ const char* icalcomponent_get_comment(icalcomponent* comp); void icalcomponent_set_uid(icalcomponent* comp, const char* v); const char* icalcomponent_get_uid(icalcomponent* comp); +void icalcomponent_set_relcalid(icalcomponent* comp, const char* v); +const char* icalcomponent_get_relcalid(icalcomponent* comp); + void icalcomponent_set_recurrenceid(icalcomponent* comp, struct icaltimetype v); struct icaltimetype icalcomponent_get_recurrenceid(icalcomponent* comp); +void icalcomponent_set_description(icalcomponent* comp, const char* v); +const char* icalcomponent_get_description(icalcomponent* comp); -void icalcomponent_set_organizer(icalcomponent* comp, - struct icalorganizertype org); - struct icalorganizertype icalcomponent_get_organizer(icalcomponent* comp); - +void icalcomponent_set_location(icalcomponent* comp, const char* v); +const char* icalcomponent_get_location(icalcomponent* comp); -void icalcomponent_add_attendee(icalcomponent *comp, - struct icalattendeetype attendee); +void icalcomponent_set_sequence(icalcomponent* comp, int v); +int icalcomponent_get_sequence(icalcomponent* comp); -int icalcomponent_remove_attendee(icalcomponent *comp, char* cuid); +void icalcomponent_set_status(icalcomponent* comp, enum icalproperty_status v); +enum icalproperty_status icalcomponent_get_status(icalcomponent* comp); -/* Get the Nth attendee. Out of range indices return an attendee - with cuid == 0 */ -struct icalattendeetype icalcomponent_get_attendee(icalcomponent *comp, - int index); -/* Calls the given function for each TZID parameter found in the component, - and any subcomponents. */ +/** Calls the given function for each TZID parameter found in the + component, and any subcomponents. */ void icalcomponent_foreach_tzid(icalcomponent* comp, void (*callback)(icalparameter *param, void *data), void *callback_data); -/* Returns the icaltimezone in the component corresponding to the TZID, or NULL - if it can't be found. */ +/** Returns the icaltimezone in the component corresponding to the + TZID, or NULL if it can't be found. */ icaltimezone* icalcomponent_get_timezone(icalcomponent* comp, const char *tzid); +int icalproperty_recurrence_is_excluded(icalcomponent *comp, + struct icaltimetype *dtstart, + struct icaltimetype *recurtime); + +void icalcomponent_foreach_recurrence(icalcomponent* comp, + struct icaltimetype start, + struct icaltimetype end, + void (*callback)(icalcomponent *comp, + struct icaltime_span *span, + void *data), + void *callback_data); + /*************** Type Specific routines ***************/ @@ -255,10 +276,7 @@ icalcomponent* icalcomponent_new_vfreebusy(); icalcomponent* icalcomponent_new_vtimezone(); icalcomponent* icalcomponent_new_xstandard(); icalcomponent* icalcomponent_new_xdaylight(); - - +icalcomponent* icalcomponent_new_vagenda(); +icalcomponent* icalcomponent_new_vquery(); #endif /* !ICALCOMPONENT_H */ - - - diff --git a/libical/src/libical/icalderivedparameter.c.in b/libical/src/libical/icalderivedparameter.c.in index 4af6e95c0e..b41587e0de 100644 --- a/libical/src/libical/icalderivedparameter.c.in +++ b/libical/src/libical/icalderivedparameter.c.in @@ -3,7 +3,7 @@ FILE: icalderivedparameters.{c,h} CREATOR: eric 09 May 1999 - $Id: icalderivedparameter.c.in,v 1.1 2001/04/17 17:23:17 jpr Exp $ + $Id: icalderivedparameter.c.in,v 1.2 2003/09/11 22:04:19 hansp Exp $ $Locker: $ @@ -55,8 +55,25 @@ struct icalparameter_kind_map { }; -extern struct icalparameter_kind_map parameter_map[]; +/* This map associates the enumerations for the VALUE parameter with + the kinds of VALUEs. */ + +struct icalparameter_value_kind_map { + icalparameter_value value; + icalvalue_kind kind; +}; +/* This map associates the parameter enumerations with a specific parameter and the string representation of the enumeration */ + +struct icalparameter_map { + icalparameter_kind kind; + int enumeration; + const char* str; +}; + + + +<insert_code_here> const char* icalparameter_kind_to_string(icalparameter_kind kind) { @@ -94,16 +111,6 @@ icalparameter_kind icalparameter_string_to_kind(const char* string) return ICAL_NO_PARAMETER; } -/* This map associates the enumerations for the VALUE parameter with - the kinds of VALUEs. */ - -struct icalparameter_value_kind_map { - icalparameter_value value; - icalvalue_kind kind; -}; - -extern struct icalparameter_value_kind_map value_kind_map[]; - icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value) { @@ -120,18 +127,6 @@ icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value) } -/* This map associates the parameter enumerations with a specific parameter and the string representation of the enumeration */ - -struct icalparameter_map { - icalparameter_kind kind; - int enumeration; - const char* str; -}; - - -extern struct icalparameter_map icalparameter_map[]; - - const char* icalparameter_enum_to_string(int e) { int i; @@ -208,4 +203,3 @@ icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalderivedparameter.h.in b/libical/src/libical/icalderivedparameter.h.in index e9fdd19fa7..a8f3a36085 100644 --- a/libical/src/libical/icalderivedparameter.h.in +++ b/libical/src/libical/icalderivedparameter.h.in @@ -4,7 +4,7 @@ CREATOR: eric 20 March 1999 - $Id: icalderivedparameter.h.in,v 1.1 2001/04/17 17:23:17 jpr Exp $ + $Id: icalderivedparameter.h.in,v 1.2 2003/09/11 22:04:19 hansp Exp $ $Locker: $ @@ -30,8 +30,9 @@ #define ICALDERIVEDPARAMETER_H -typedef void icalparameter; +typedef struct icalparameter_impl icalparameter; const char* icalparameter_enum_to_string(int e); int icalparameter_string_to_enum(const char* str); +<insert_code_here> diff --git a/libical/src/libical/icalderivedproperty.c.in b/libical/src/libical/icalderivedproperty.c.in index ceec0b797d..36ddc846ae 100644 --- a/libical/src/libical/icalderivedproperty.c.in +++ b/libical/src/libical/icalderivedproperty.c.in @@ -4,7 +4,7 @@ FILE: icalderivedproperty.c CREATOR: eric 15 Feb 2001 - $Id: icalderivedproperty.c.in,v 1.1 2001/04/17 17:23:17 jpr Exp $ + $Id: icalderivedproperty.c.in,v 1.2 2003/09/11 22:04:19 hansp Exp $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -43,10 +43,9 @@ #include <stdio.h> /* for printf */ #include <stdarg.h> /* for va_list, va_start, etc. */ -#define TMP_BUF_SIZE 1024 - struct icalproperty_impl* icalproperty_new_impl (icalproperty_kind kind); +void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args); /* This map associates the property kinds with the string representation of the property name and the kind of VALUE that the @@ -59,7 +58,29 @@ struct icalproperty_map { }; -extern struct icalproperty_map property_map[]; +/* This map associates the property enumerations with the king of + property that they are used in and the string representation of the + enumeration */ + +struct icalproperty_enum_map { + icalproperty_kind prop; + int prop_enum; + const char* str; +}; + + +<insert_code_here> + +int icalproperty_kind_is_valid(const icalproperty_kind kind) +{ + int i = 0; + do { + if (property_map[i].kind == kind) + return 1; + } while (property_map[i++].kind != ICAL_NO_PROPERTY); + + return 0; +} const char* icalproperty_kind_to_string(icalproperty_kind kind) { @@ -100,7 +121,7 @@ icalproperty_kind icalproperty_string_to_kind(const char* string) } -icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind) +icalproperty_kind icalproperty_value_kind_to_kind(icalvalue_kind kind) { int i; @@ -110,7 +131,7 @@ icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind) } } - return ICAL_NO_VALUE; + return ICAL_NO_PROPERTY; } @@ -129,19 +150,6 @@ icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind) } -/* This map associates the property enumerations with the king of - property that they are used in and the string representation of the - enumeration */ - -struct icalproperty_enum_map { - icalproperty_kind prop; - int prop_enum; - const char* str; -}; - -extern struct icalproperty_enum_map enum_map[]; - - const char* icalproperty_enum_to_string(int e) { icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e"); @@ -150,6 +158,37 @@ const char* icalproperty_enum_to_string(int e) return enum_map[e-ICALPROPERTY_FIRST_ENUM].str; } +int icalproperty_kind_and_string_to_enum(const int kind, const char* str) +{ + icalproperty_kind pkind; + int i; + + icalerror_check_arg_rz(str!=0,"str") + + if ((pkind = icalproperty_value_kind_to_kind(kind)) == ICAL_NO_VALUE) + return 0; + + while(*str == ' '){ + str++; + } + + for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) { + if (enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind) + break; + } + if (i == ICALPROPERTY_LAST_ENUM) + return 0; + + for (; i != ICALPROPERTY_LAST_ENUM; i++) { + if ( strcmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) { + return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum; + } + } + + return 0; +} + +/** @deprecated please use icalproperty_kind_and_string_to_enum instead */ int icalproperty_string_to_enum(const char* str) { int i; @@ -237,14 +276,10 @@ icalproperty_status icalenum_string_to_status(const char* str) i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM; i++) { if ( strcmp(enum_map[i].str, str) == 0) { - return (icalproperty_method)enum_map[i].prop_enum; + return (icalproperty_status)enum_map[i].prop_enum; } } return ICAL_STATUS_NONE; } - - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalderivedproperty.h.in b/libical/src/libical/icalderivedproperty.h.in index 6ce34afafb..eda95ee031 100644 --- a/libical/src/libical/icalderivedproperty.h.in +++ b/libical/src/libical/icalderivedproperty.h.in @@ -3,7 +3,7 @@ FILE: icalderivedproperties.{c,h} CREATOR: eric 09 May 1999 - $Id: icalderivedproperty.h.in,v 1.1 2001/04/17 17:23:17 jpr Exp $ + $Id: icalderivedproperty.h.in,v 1.2 2003/09/11 22:04:19 hansp Exp $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org ======================================================================*/ @@ -17,7 +17,6 @@ #include "icalderivedvalue.h" #include "icalrecur.h" -typedef void icalproperty; +typedef struct icalproperty_impl icalproperty; - -/* Everything below this line is machine generated. Do not edit. */ +<insert_code_here> diff --git a/libical/src/libical/icalderivedvalue.c.in b/libical/src/libical/icalderivedvalue.c.in index 3c4e73066b..d96461e2b7 100644 --- a/libical/src/libical/icalderivedvalue.c.in +++ b/libical/src/libical/icalderivedvalue.c.in @@ -3,7 +3,7 @@ FILE: icalvalue.c CREATOR: eric 02 May 1999 - $Id: icalderivedvalue.c.in,v 1.3 2002/10/16 21:41:39 rodrigo Exp $ + $Id: icalderivedvalue.c.in,v 1.4 2003/09/11 22:04:19 hansp Exp $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -47,10 +47,6 @@ #include <stdlib.h> /* for atoi and atof */ #include <limits.h> /* for SHRT_MAX */ - - -#define TMP_BUF_SIZE 1024 - struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind); /* This map associates each of the value types with its string @@ -60,9 +56,21 @@ struct icalvalue_kind_map { char name[20]; }; -extern struct icalvalue_kind_map value_map[]; +<insert_code_here> + + +int icalvalue_kind_is_valid(const icalvalue_kind kind) +{ + int i = 0; + do { + if (value_map[i].kind == kind) + return 1; + } while (value_map[i++].kind != ICAL_NO_VALUE); + + return 0; +} -const char* icalvalue_kind_to_string(icalvalue_kind kind) +const char* icalvalue_kind_to_string(const icalvalue_kind kind) { int i; @@ -96,12 +104,10 @@ icalvalue* icalvalue_new_x (const char* v){ icalvalue_set_x((icalvalue*)impl,v); return (icalvalue*)impl; } -void icalvalue_set_x(icalvalue* value, const char* v) { - struct icalvalue_impl* impl; - icalerror_check_arg_rv( (value!=0),"value"); +void icalvalue_set_x(icalvalue* impl, const char* v) { + icalerror_check_arg_rv( (impl!=0),"value"); icalerror_check_arg_rv( (v!=0),"v"); - impl = (struct icalvalue_impl*)value; if(impl->x_value!=0) {free((void*)impl->x_value);} impl->x_value = icalmemory_strdup(v); @@ -111,11 +117,11 @@ void icalvalue_set_x(icalvalue* value, const char* v) { } } -const char* icalvalue_get_x(icalvalue* value) { +const char* icalvalue_get_x(const icalvalue* value) { - icalerror_check_arg_rz( (value!=0),"value"); + icalerror_check_arg( (value!=0),"value"); icalerror_check_value_type(value, ICAL_X_VALUE); - return ((struct icalvalue_impl*)value)->x_value; + return value->x_value; } /* Recur is a special case, so it is not auto generated. */ @@ -130,15 +136,11 @@ icalvalue_new_recur (struct icalrecurrencetype v) } void -icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v) +icalvalue_set_recur(icalvalue* impl, struct icalrecurrencetype v) { - struct icalvalue_impl* impl; - - icalerror_check_arg_rv( (value!=0),"value"); + icalerror_check_arg_rv( (impl!=0),"value"); icalerror_check_value_type(value, ICAL_RECUR_VALUE); - impl = (struct icalvalue_impl*)value; - if (impl->data.v_recur != 0){ free(impl->data.v_recur); impl->data.v_recur = 0; @@ -156,12 +158,12 @@ icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v) } struct icalrecurrencetype -icalvalue_get_recur(icalvalue* value) +icalvalue_get_recur(const icalvalue* value) { icalerror_check_arg( (value!=0),"value"); icalerror_check_value_type(value, ICAL_RECUR_VALUE); - return *(((struct icalvalue_impl*)value)->data.v_recur); + return *(value->data.v_recur); } @@ -180,30 +182,24 @@ icalvalue_new_trigger (struct icaltriggertype v) void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v) { - struct icalvalue_impl* impl; - icalerror_check_arg_rv( (value!=0),"value"); - impl = (struct icalvalue_impl*)value; - if(!icaltime_is_null_time(v.time)){ - icalvalue_set_datetime((icalvalue*)impl,v.time); - impl->kind = ICAL_DATETIME_VALUE; + icalvalue_set_datetime(value,v.time); + value->kind = ICAL_DATETIME_VALUE; } else { - icalvalue_set_duration((icalvalue*)impl,v.duration); - impl->kind = ICAL_DURATION_VALUE; + icalvalue_set_duration(value,v.duration); + value->kind = ICAL_DURATION_VALUE; } - } struct icaltriggertype -icalvalue_get_trigger(icalvalue* value) +icalvalue_get_trigger(const icalvalue* impl) { - struct icalvalue_impl *impl = (struct icalvalue_impl*)value; struct icaltriggertype tr; - icalerror_check_arg( (value!=0),"value"); - icalerror_check_arg( (value!=0),"value"); + icalerror_check_arg( (impl!=0),"value"); + icalerror_check_arg( (impl!=0),"value"); if(impl->kind == ICAL_DATETIME_VALUE){ tr.duration = icaldurationtype_from_int(0); @@ -227,17 +223,15 @@ icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v) { struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIMEPERIOD_VALUE); - icalvalue_set_datetimeperiod((icalvalue*)impl,v); + icalvalue_set_datetimeperiod(impl,v); return (icalvalue*)impl; } void -icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v) +icalvalue_set_datetimeperiod(icalvalue* impl, struct icaldatetimeperiodtype v) { - struct icalvalue_impl* impl = (struct icalvalue_impl*)value; - - icalerror_check_arg_rv( (value!=0),"value"); + icalerror_check_arg_rv( (impl!=0),"value"); icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE); @@ -261,12 +255,11 @@ icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v) } struct icaldatetimeperiodtype -icalvalue_get_datetimeperiod(icalvalue* value) +icalvalue_get_datetimeperiod(const icalvalue* impl) { struct icaldatetimeperiodtype dtp; - struct icalvalue_impl* impl = (struct icalvalue_impl*)value; - icalerror_check_arg( (value!=0),"value"); + icalerror_check_arg( (impl!=0),"value"); icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE); if(impl->kind == ICAL_DATETIME_VALUE){ @@ -284,6 +277,8 @@ icalvalue_get_datetimeperiod(icalvalue* value) return dtp; } + + icalvalue * icalvalue_new_attach (icalattach *attach) { @@ -305,35 +300,36 @@ void icalvalue_set_attach (icalvalue *value, icalattach *attach) { struct icalvalue_impl *impl; - + icalerror_check_arg_rv ((value != NULL), "value"); icalerror_check_value_type (value, ICAL_ATTACH_VALUE); icalerror_check_arg_rv ((attach != NULL), "attach"); - + impl = (struct icalvalue_impl *) value; - + icalattach_ref (attach); if (impl->data.v_attach) icalattach_unref (impl->data.v_attach); - + impl->data.v_attach = attach; } icalattach * -icalvalue_get_attach (icalvalue *value) +icalvalue_get_attach (const icalvalue *value) { - struct icalvalue_impl *impl; - icalerror_check_arg_rz ((value != NULL), "value"); icalerror_check_value_type (value, ICAL_ATTACH_VALUE); - impl = (struct icalvalue_impl *) value; - - return impl->data.v_attach; + return value->data.v_attach; } + + + + + /* The remaining interfaces are 'new', 'set' and 'get' for each of the value types */ diff --git a/libical/src/libical/icalderivedvalue.h.in b/libical/src/libical/icalderivedvalue.h.in index d043ac4048..1df5e5126e 100644 --- a/libical/src/libical/icalderivedvalue.h.in +++ b/libical/src/libical/icalderivedvalue.h.in @@ -4,7 +4,7 @@ CREATOR: eric 20 March 1999 - $Id: icalderivedvalue.h.in,v 1.2 2001/09/10 21:54:44 federico Exp $ + $Id: icalderivedvalue.h.in,v 1.3 2003/09/11 22:04:19 hansp Exp $ $Locker: $ @@ -34,28 +34,32 @@ #include "icaltime.h" #include "icalduration.h" #include "icalperiod.h" +#include "icalattach.h" -typedef void icalvalue; +typedef struct icalvalue_impl icalvalue; + void icalvalue_set_x(icalvalue* value, const char* v); icalvalue* icalvalue_new_x(const char* v); -const char* icalvalue_get_x(icalvalue* value); +const char* icalvalue_get_x(const icalvalue* value); icalvalue* icalvalue_new_recur (struct icalrecurrencetype v); void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); -struct icalrecurrencetype icalvalue_get_recur(icalvalue* value); +struct icalrecurrencetype icalvalue_get_recur(const icalvalue* value); icalvalue* icalvalue_new_trigger (struct icaltriggertype v); void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v); -struct icaltriggertype icalvalue_get_trigger(icalvalue* value); +struct icaltriggertype icalvalue_get_trigger(const icalvalue* value); icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v); void icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v); -struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(icalvalue* value); +struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(const icalvalue* value); icalvalue *icalvalue_new_attach (icalattach *attach); void icalvalue_set_attach (icalvalue *value, icalattach *attach); -icalattach *icalvalue_get_attach (icalvalue *value); +icalattach *icalvalue_get_attach (const icalvalue *value); + +void icalvalue_reset_kind(icalvalue* value); -/* Everything below this line is machine generated. Do not edit. */ +<insert_code_here> diff --git a/libical/src/libical/icalduration.c b/libical/src/libical/icalduration.c index 250cd6e3d6..821a3b7688 100644 --- a/libical/src/libical/icalduration.c +++ b/libical/src/libical/icalduration.c @@ -36,14 +36,9 @@ #include <stdlib.h> #include <stdio.h> -#ifdef ICAL_NO_LIBICAL -#define icalerror_set_errno(x) -#define icalerror_check_arg_rv(x,y) -#define icalerror_check_arg_re(x,y,z) -#else #include "icalerror.h" #include "icalmemory.h" -#endif +#include "icalvalue.h" @@ -51,31 +46,32 @@ /* From Seth Alves, <alves@hungry.com> */ struct icaldurationtype icaldurationtype_from_int(int t) { - struct icaldurationtype dur; - int used = 0; - - dur = icaldurationtype_null_duration(); - - if(t < 0){ - dur.is_neg = 1; - t = -t; - } - - dur.weeks = (t - used) / (60 * 60 * 24 * 7); - used += dur.weeks * (60 * 60 * 24 * 7); - dur.days = (t - used) / (60 * 60 * 24); - used += dur.days * (60 * 60 * 24); - dur.hours = (t - used) / (60 * 60); - used += dur.hours * (60 * 60); - dur.minutes = (t - used) / (60); - used += dur.minutes * (60); - dur.seconds = (t - used); + struct icaldurationtype dur; + int used = 0; + + dur = icaldurationtype_null_duration(); + + if(t < 0){ + dur.is_neg = 1; + t = -t; + } + + if (t % (60 * 60 * 24 * 7) == 0) { + dur.weeks = t / (60 * 60 * 24 * 7); + } else { + used += dur.weeks * (60 * 60 * 24 * 7); + dur.days = (t - used) / (60 * 60 * 24); + used += dur.days * (60 * 60 * 24); + dur.hours = (t - used) / (60 * 60); + used += dur.hours * (60 * 60); + dur.minutes = (t - used) / (60); + used += dur.minutes * (60); + dur.seconds = (t - used); + } - return dur; + return dur; } -#ifndef ICAL_NO_LIBICAL -#include "icalvalue.h" struct icaldurationtype icaldurationtype_from_string(const char* str) { @@ -135,7 +131,7 @@ struct icaldurationtype icaldurationtype_from_string(const char* str) if (begin_flag == 0) goto error; /* Get all of the digits, not one at a time */ - scan_size = sscanf((char*)(str+i),"%d",&digits); + scan_size = sscanf(&str[i],"%d",&digits); if(scan_size == 0) goto error; break; } @@ -184,12 +180,11 @@ struct icaldurationtype icaldurationtype_from_string(const char* str) error: icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - memset(&d, 0, sizeof(struct icaldurationtype)); - return d; - + return icaldurationtype_bad_duration(); } #define TMP_BUF_SIZE 1024 +static void append_duration_segment(char** buf, char** buf_ptr, size_t* buf_size, char* sep, unsigned int value) { @@ -250,7 +245,7 @@ char* icaldurationtype_as_ical_string(struct icaldurationtype d) } } else { - icalmemory_append_string(&buf, &buf_ptr, &buf_size, d.is_neg ? "-PT0S" : "PT0S"); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, "PT0S"); } output_line = icalmemory_tmp_copy(buf); @@ -260,8 +255,6 @@ char* icaldurationtype_as_ical_string(struct icaldurationtype d) } -#endif - /* From Russel Steinthal */ int icaldurationtype_as_int(struct icaldurationtype dur) @@ -292,6 +285,25 @@ int icaldurationtype_is_null_duration(struct icaldurationtype d) } } +/* in icalvalue_new_from_string_with_error, we should not call + icaldurationtype_is_null_duration() to see if there is an error + condition. Null duration is perfectly valid for an alarm. + We cannot depend on the caller to check icalerrno either, + following the philosophy of unix errno. we set the is_neg + to -1 to indicate that this is a bad duration. +*/ +struct icaldurationtype icaldurationtype_bad_duration() +{ + struct icaldurationtype d; + memset(&d,0,sizeof(struct icaldurationtype)); + d.is_neg = -1; + return d; +} + +int icaldurationtype_is_bad_duration(struct icaldurationtype d) +{ + return (d.is_neg == -1); +} struct icaltimetype icaltime_add(struct icaltimetype t, @@ -313,7 +325,7 @@ struct icaldurationtype icaltime_subtract(struct icaltimetype t1, time_t t1t = icaltime_as_timet(t1); time_t t2t = icaltime_as_timet(t2); - return icaldurationtype_from_int(t1t-t2t); + return icaldurationtype_from_int((int)(t1t-t2t)); } diff --git a/libical/src/libical/icalduration.h b/libical/src/libical/icalduration.h index 0450a081d3..0e64cad9cd 100644 --- a/libical/src/libical/icalduration.h +++ b/libical/src/libical/icalduration.h @@ -46,7 +46,9 @@ struct icaldurationtype icaldurationtype_from_string(const char*); int icaldurationtype_as_int(struct icaldurationtype duration); char* icaldurationtype_as_ical_string(struct icaldurationtype d); struct icaldurationtype icaldurationtype_null_duration(void); +struct icaldurationtype icaldurationtype_bad_duration(void); int icaldurationtype_is_null_duration(struct icaldurationtype d); +int icaldurationtype_is_bad_duration(struct icaldurationtype d); struct icaltimetype icaltime_add(struct icaltimetype t, struct icaldurationtype d); diff --git a/libical/src/libical/icalenums.c b/libical/src/libical/icalenums.c index 6751933c3e..66c5ccd0cf 100644 --- a/libical/src/libical/icalenums.c +++ b/libical/src/libical/icalenums.c @@ -34,10 +34,11 @@ #include <stdio.h> /* For stderr */ #include <string.h> /* For strncmp */ #include <assert.h> +#include "icalmemory.h" - - -struct { +/*** @brief Allowed request status values + */ +static struct { enum icalrequeststatus kind; int major; int minor; @@ -70,18 +71,25 @@ struct { {ICAL_3_12_UNKCOMP_STATUS, 3,12,"Unknown component or property found."}, {ICAL_3_13_BADCOMP_STATUS, 3,13,"Unsupported component or property found"}, {ICAL_3_14_NOCAP_STATUS, 3,14,"Unsupported capability."}, + {ICAL_3_15_INVCOMMAND, 3,15,"Invalid command."}, {ICAL_4_0_BUSY_STATUS, 4,0,"Event conflict. Date/time is busy."}, + {ICAL_4_1_STORE_ACCESS_DENIED, 4,1,"Store Access Denied."}, + {ICAL_4_2_STORE_FAILED, 4,2,"Store Failed."}, + {ICAL_4_3_STORE_NOT_FOUND, 4,3,"Store not found."}, {ICAL_5_0_MAYBE_STATUS, 5,0,"Request MAY supported."}, {ICAL_5_1_UNAVAIL_STATUS, 5,1,"Service unavailable."}, {ICAL_5_2_NOSERVICE_STATUS, 5,2,"Invalid calendar service."}, {ICAL_5_3_NOSCHED_STATUS, 5,3,"No scheduling support for user."}, + {ICAL_6_1_CONTAINER_NOT_FOUND, 6,1,"Container not found."}, + {ICAL_9_0_UNRECOGNIZED_COMMAND, 9,0,"An unrecognized command was received."}, {ICAL_UNKNOWN_STATUS, 0,0,"Error: Unknown request status"} }; +/*** @brief Return the descriptive text for a request status + */ const char* icalenum_reqstat_desc(icalrequeststatus stat) { - int i; for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { @@ -93,7 +101,26 @@ const char* icalenum_reqstat_desc(icalrequeststatus stat) return 0; } +/*** @brief Return the code for a request status + */ +char* icalenum_reqstat_code(icalrequeststatus stat) +{ + int i, major, minor; + char tmpbuf[36]; + + for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) { + if ( request_status_map[i].kind == stat) { + major = request_status_map[i].major; + minor = request_status_map[i].minor; + sprintf(tmpbuf, "%i.%i", major, minor); + return icalmemory_tmp_copy(tmpbuf); + } + } + return NULL; +} +/*** @brief Return the major number for a request status + */ short icalenum_reqstat_major(icalrequeststatus stat) { int i; @@ -106,6 +133,8 @@ short icalenum_reqstat_major(icalrequeststatus stat) return -1; } +/*** @brief Return the minor number for a request status + */ short icalenum_reqstat_minor(icalrequeststatus stat) { int i; @@ -119,6 +148,8 @@ short icalenum_reqstat_minor(icalrequeststatus stat) } +/*** @brief Return a request status for major/minor status numbers + */ icalrequeststatus icalenum_num_to_reqstat(short major, short minor) { int i; diff --git a/libical/src/libical/icalenums.h b/libical/src/libical/icalenums.h index 21031dd20e..dde5e5afb6 100644 --- a/libical/src/libical/icalenums.h +++ b/libical/src/libical/icalenums.h @@ -43,6 +43,7 @@ typedef enum icalcomponent_kind { ICAL_VTODO_COMPONENT, ICAL_VJOURNAL_COMPONENT, ICAL_VCALENDAR_COMPONENT, + ICAL_VAGENDA_COMPONENT, ICAL_VFREEBUSY_COMPONENT, ICAL_VALARM_COMPONENT, ICAL_XAUDIOALARM_COMPONENT, @@ -55,6 +56,7 @@ typedef enum icalcomponent_kind { ICAL_X_COMPONENT, ICAL_VSCHEDULE_COMPONENT, ICAL_VQUERY_COMPONENT, + ICAL_VREPLY_COMPONENT, ICAL_VCAR_COMPONENT, ICAL_VCOMMAND_COMPONENT, ICAL_XLICINVALID_COMPONENT, @@ -98,11 +100,17 @@ typedef enum icalrequeststatus { ICAL_3_12_UNKCOMP_STATUS, ICAL_3_13_BADCOMP_STATUS, ICAL_3_14_NOCAP_STATUS, + ICAL_3_15_INVCOMMAND, ICAL_4_0_BUSY_STATUS, + ICAL_4_1_STORE_ACCESS_DENIED, + ICAL_4_2_STORE_FAILED, + ICAL_4_3_STORE_NOT_FOUND, ICAL_5_0_MAYBE_STATUS, ICAL_5_1_UNAVAIL_STATUS, ICAL_5_2_NOSERVICE_STATUS, - ICAL_5_3_NOSCHED_STATUS + ICAL_5_3_NOSCHED_STATUS, + ICAL_6_1_CONTAINER_NOT_FOUND, + ICAL_9_0_UNRECOGNIZED_COMMAND } icalrequeststatus; @@ -110,6 +118,7 @@ const char* icalenum_reqstat_desc(icalrequeststatus stat); short icalenum_reqstat_major(icalrequeststatus stat); short icalenum_reqstat_minor(icalrequeststatus stat); icalrequeststatus icalenum_num_to_reqstat(short major, short minor); +char* icalenum_reqstat_code(icalrequeststatus stat); /*********************************************************************** * Conversion functions diff --git a/libical/src/libical/icalerror.c b/libical/src/libical/icalerror.c index 05191defb9..61043b2fce 100644 --- a/libical/src/libical/icalerror.c +++ b/libical/src/libical/icalerror.c @@ -29,11 +29,53 @@ #include "config.h" #endif +#include <stdlib.h> /* for malloc() */ +#include <string.h> /* for strcmp */ #include "icalerror.h" -icalerrorenum icalerrno; +#ifdef HAVE_PTHREAD +#include <pthread.h> + +static pthread_key_t icalerrno_key; +static pthread_once_t icalerrno_key_once = PTHREAD_ONCE_INIT; + +static void icalerrno_destroy(void* buf) { + free(buf); + pthread_setspecific(icalerrno_key, NULL); +} + +static void icalerrno_key_alloc(void) { + pthread_key_create(&icalerrno_key, icalerrno_destroy); +} + +icalerrorenum *icalerrno_return(void) { + icalerrorenum *_errno; + + pthread_once(&icalerrno_key_once, icalerrno_key_alloc); + + _errno = (icalerrorenum*) pthread_getspecific(icalerrno_key); + + if (!_errno) { + _errno = malloc(sizeof(icalerrorenum)); + *_errno = ICAL_NO_ERROR; + pthread_setspecific(icalerrno_key, _errno); + } + return _errno; +} + +#else + +static icalerrorenum icalerrno_storage = ICAL_NO_ERROR; + +icalerrorenum *icalerrno_return(void) { + return &icalerrno_storage; +} + +#endif + + +static int foo; -int foo; void icalerror_stop_here(void) { foo++; /* Keep optimizers from removing routine */ @@ -47,6 +89,19 @@ void icalerror_crash_here(void) assert( *p); } +#ifdef ICAL_SETERROR_ISFUNC +void icalerror_set_errno(icalerrorenum x) +{ + icalerrno = x; + if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || + (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && + icalerror_errors_are_fatal == 1 )){ + icalerror_warn(icalerror_strerror(x)); + assert(0); + } + +} +#endif void icalerror_clear_errno() { @@ -64,10 +119,11 @@ struct icalerror_state { icalerrorstate state; }; -struct icalerror_state error_state_map[] = +static struct icalerror_state error_state_map[] = { { ICAL_BADARG_ERROR,ICAL_ERROR_DEFAULT}, { ICAL_NEWFAILED_ERROR,ICAL_ERROR_DEFAULT}, + { ICAL_ALLOCATION_ERROR,ICAL_ERROR_DEFAULT}, { ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT}, { ICAL_PARSE_ERROR,ICAL_ERROR_DEFAULT}, { ICAL_INTERNAL_ERROR,ICAL_ERROR_DEFAULT}, @@ -89,6 +145,7 @@ static struct icalerror_string_map string_map[] = { {"BADARG",ICAL_BADARG_ERROR,"BADARG: Bad argument to function"}, { "NEWFAILED",ICAL_NEWFAILED_ERROR,"NEWFAILED: Failed to create a new object via a *_new() routine"}, + { "ALLOCATION",ICAL_ALLOCATION_ERROR,"ALLOCATION: Failed to allocate new memory"}, {"MALFORMEDDATA",ICAL_MALFORMEDDATA_ERROR,"MALFORMEDDATA: An input string was not correctly formed or a component has missing or extra properties"}, { "PARSE",ICAL_PARSE_ERROR,"PARSE: Failed to parse a part of an iCal component"}, {"INTERNAL",ICAL_INTERNAL_ERROR,"INTERNAL: Random internal error. This indicates an error in the library code, not an error in use"}, @@ -153,7 +210,7 @@ void icalerror_set_error_state( icalerrorenum error, { int i; - for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){ + for(i = 0; error_state_map[i].error!= ICAL_NO_ERROR;i++){ if(error_state_map[i].error == error){ error_state_map[i].state = state; } @@ -164,7 +221,7 @@ icalerrorstate icalerror_get_error_state( icalerrorenum error) { int i; - for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){ + for(i = 0; error_state_map[i].error!= ICAL_NO_ERROR;i++){ if(error_state_map[i].error == error){ return error_state_map[i].state; } diff --git a/libical/src/libical/icalerror.h b/libical/src/libical/icalerror.h index 790fa90f22..7826041855 100644 --- a/libical/src/libical/icalerror.h +++ b/libical/src/libical/icalerror.h @@ -35,8 +35,10 @@ #include "config.h" #endif +#define ICAL_SETERROR_ISFUNC -/* This routine is called before any error is triggered. It is called + +/** This routine is called before any error is triggered. It is called by icalerror_set_errno, so it does not appear in all of the macros below */ void icalerror_stop_here(void); @@ -44,7 +46,7 @@ void icalerror_stop_here(void); void icalerror_crash_here(void); typedef enum icalerrorenum { - + ICAL_NO_ERROR, /* icalerrno may not be initialized - put it first so and pray that the compiler initialize things to zero */ ICAL_BADARG_ERROR, ICAL_NEWFAILED_ERROR, ICAL_ALLOCATION_ERROR, @@ -54,15 +56,18 @@ typedef enum icalerrorenum { ICAL_FILE_ERROR, ICAL_USAGE_ERROR, ICAL_UNIMPLEMENTED_ERROR, - ICAL_UNKNOWN_ERROR, /* Used for problems in input to icalerror_strerror()*/ - ICAL_NO_ERROR + ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror()*/ } icalerrorenum; -/* The libical error enumeration, like errno*/ -extern icalerrorenum icalerrno; +icalerrorenum * icalerrno_return(void); +#define icalerrno (*(icalerrno_return())) -/* If true, libicl aborts after a call to icalerror_set_error*/ +/** If true, libicl aborts after a call to icalerror_set_error + * + * @warning NOT THREAD SAFE -- recommended that you do not change + * this in a multithreaded program. + */ extern int icalerror_errors_are_fatal; /* Warning messages */ @@ -90,7 +95,7 @@ char* icalerror_perror(); void icalerror_set_error_state( icalerrorenum error, icalerrorstate); icalerrorstate icalerror_get_error_state( icalerrorenum error); - +#ifndef ICAL_SETERROR_ISFUNC #define icalerror_set_errno(x) \ icalerrno = x; \ if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \ @@ -99,7 +104,9 @@ if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \ icalerror_warn(icalerror_strerror(x)); \ assert(0); \ } - +#else +void icalerror_set_errno(icalerrorenum x); +#endif #ifdef ICAL_ERRORS_ARE_FATAL #undef NDEBUG diff --git a/libical/src/libical/icallangbind.c b/libical/src/libical/icallangbind.c index c78638985f..1a3ad48a31 100644 --- a/libical/src/libical/icallangbind.c +++ b/libical/src/libical/icallangbind.c @@ -22,9 +22,15 @@ #include "icalproperty.h" #include "icalerror.h" #include "icalmemory.h" +#include "icalvalue.h" #include <stdlib.h> #include <string.h> +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + int* icallangbind_new_array(int size){ int* p = (int*)malloc(size*sizeof(int)); return p; /* Caller handles failures */ @@ -38,11 +44,28 @@ int icallangbind_access_array(int* array, int index) { return array[index]; } +/** Iterators to fetch parameters given property */ + +icalparameter* icallangbind_get_first_parameter(icalproperty *prop) +{ + icalparameter_kind kind = ICAL_ANY_PARAMETER; + + return icalproperty_get_first_parameter(prop,kind); +} -/* LIke icalcomponent_get_first_component, buut takes a string for the +icalparameter* icallangbind_get_next_parameter(icalproperty *prop) +{ + icalparameter_kind kind = ICAL_ANY_PARAMETER; + + return icalproperty_get_next_parameter(prop,kind); +} + + +/** Like icalcomponent_get_first_component(), but takes a string for the kind and can iterate over X properties as if each X name was a seperate kind */ + icalproperty* icallangbind_get_first_property(icalcomponent *c, const char* prop) { @@ -129,6 +152,7 @@ icalcomponent* icallangbind_get_next_component(icalcomponent *c, #define APPENDC(x) icalmemory_append_char(&buf, &buf_ptr, &buf_size, x); + const char* icallangbind_property_eval_string(icalproperty* prop, char* sep) { char tmp[25]; @@ -150,14 +174,14 @@ const char* icallangbind_property_eval_string(icalproperty* prop, char* sep) APPENDS(" 'name' "); APPENDS(sep); APPENDC('\''); - APPENDS(icalenum_property_kind_to_string(icalproperty_isa(prop))); + APPENDS(icalproperty_kind_to_string(icalproperty_isa(prop))); APPENDC('\''); if(value){ APPENDS(", 'value_type' "); APPENDS(sep); APPENDC('\''); - APPENDS(icalenum_value_kind_to_string(icalvalue_isa(value))); + APPENDS(icalvalue_kind_to_string(icalvalue_isa(value))); APPENDC('\''); } @@ -266,7 +290,23 @@ int icallangbind_string_to_open_flag(const char* str) if (strcmp(str,"r") == 0) {return O_RDONLY;} else if (strcmp(str,"r+") == 0) {return O_RDWR;} else if (strcmp(str,"w") == 0) {return O_WRONLY;} + else if (strcmp(str,"w+") == 0) {return O_RDWR|O_CREAT;} else if (strcmp(str,"a") == 0) {return O_WRONLY|O_APPEND;} else return -1; } + +const char* icallangbind_quote_as_ical(const char* str) +{ + size_t buf_size = 2 * strlen(str); + + /* assume every char could be quoted */ + char* buf = icalmemory_new_buffer(buf_size); + int result; + + result = icalvalue_encode_ical_string(str, buf, buf_size); + + icalmemory_add_tmp_buffer(buf); + + return buf; +} diff --git a/libical/src/libical/icallangbind.h b/libical/src/libical/icallangbind.h index 2ed50038eb..fed3626c32 100644 --- a/libical/src/libical/icallangbind.h +++ b/libical/src/libical/icallangbind.h @@ -41,9 +41,14 @@ icalcomponent* icallangbind_get_first_component(icalcomponent *c, icalcomponent* icallangbind_get_next_component(icalcomponent *c, const char* comp); +icalparameter* icallangbind_get_first_parameter(icalproperty *prop); + +icalparameter* icallangbind_get_next_parameter(icalproperty *prop); const char* icallangbind_property_eval_string(icalproperty* prop, char* sep); int icallangbind_string_to_open_flag(const char* str); + +const char* icallangbind_quote_as_ical(const char* str); #endif /*__ICALLANGBIND_H__*/ diff --git a/libical/src/libical/icalmemory.c b/libical/src/libical/icalmemory.c index 297ead8826..058ef3791f 100644 --- a/libical/src/libical/icalmemory.c +++ b/libical/src/libical/icalmemory.c @@ -32,7 +32,11 @@ ======================================================================*/ -/* libical often passes strings back to the caller. To make these +/** + * @file icalmemory.c + * @brief Common memory management routines. + * + * libical often passes strings back to the caller. To make these * interfaces simple, I did not want the caller to have to pass in a * memory buffer, but having libical pass out newly allocated memory * makes it difficult to de-allocate the memory. @@ -41,7 +45,8 @@ * out references to memory which the caller does not own, and be able * to de-allocate the memory later. The ring allows libical to have * several buffers active simultaneously, which is handy when creating - * string representations of components. */ + * string representations of components. + */ #define ICALMEMORY_C @@ -60,47 +65,116 @@ #include <stdlib.h> /* for malloc, realloc */ #include <string.h> /* for memset(), strdup */ -#define BUFFER_RING_SIZE 25 +#ifdef WIN32 +#include <windows.h> +#endif + +#define BUFFER_RING_SIZE 2500 #define MIN_BUFFER_SIZE 200 + +/* HACK. Not threadsafe */ + +typedef struct { + int pos; + void *ring[BUFFER_RING_SIZE]; +} buffer_ring; + void icalmemory_free_tmp_buffer (void* buf); +void icalmemory_free_ring_byval(buffer_ring *br); +static buffer_ring* global_buffer_ring = 0; -/* HACK. Not threadsafe */ -void* buffer_ring[BUFFER_RING_SIZE]; -int buffer_pos = -1; -int initialized = 0; +#ifdef HAVE_PTHREAD +#include <pthread.h> -/* Add an existing buffer to the buffer ring */ -void icalmemory_add_tmp_buffer(void* buf) -{ - /* I don't think I need this -- I think static arrays are - initialized to 0 as a standard part of C, but I am not sure. */ - if (initialized == 0){ +static pthread_key_t ring_key; +static pthread_once_t ring_key_once = PTHREAD_ONCE_INIT; + +static void ring_destroy(void * buf) { + if (buf) icalmemory_free_ring_byval((buffer_ring *) buf); + pthread_setspecific(ring_key, NULL); +} + +static void ring_key_alloc(void) { + pthread_key_create(&ring_key, ring_destroy); +} +#endif + + +static buffer_ring * buffer_ring_new(void) { + buffer_ring *br; int i; + + br = (buffer_ring *)malloc(sizeof(buffer_ring)); + for(i=0; i<BUFFER_RING_SIZE; i++){ - buffer_ring[i] = 0; + br->ring[i] = 0; } - initialized = 1; + br->pos = 0; + return(br); +} + + +#ifdef HAVE_PTHREAD +static buffer_ring* get_buffer_ring_pthread(void) { + buffer_ring *br; + + pthread_once(&ring_key_once, ring_key_alloc); + + br = pthread_getspecific(ring_key); + + if (!br) { + br = buffer_ring_new(); + pthread_setspecific(ring_key, br); } + return(br); +} +#endif + +/* get buffer ring via a single global for a non-threaded program */ +static buffer_ring* get_buffer_ring_global(void) { + if (global_buffer_ring == 0) { + global_buffer_ring = buffer_ring_new(); + } + return(global_buffer_ring); +} + +static buffer_ring *get_buffer_ring(void) { +#ifdef HAVE_PTHREAD + return(get_buffer_ring_pthread()); +#else + return get_buffer_ring_global(); +#endif +} + + +/** Add an existing buffer to the buffer ring */ +void icalmemory_add_tmp_buffer(void* buf) +{ + buffer_ring *br = get_buffer_ring(); + /* Wrap around the ring */ - if(++buffer_pos == BUFFER_RING_SIZE){ - buffer_pos = 0; + if(++(br->pos) == BUFFER_RING_SIZE){ + br->pos = 0; } /* Free buffers as their slots are overwritten */ - if ( buffer_ring[buffer_pos] != 0){ - free( buffer_ring[buffer_pos]); - buffer_ring[buffer_pos] = 0; + if ( br->ring[br->pos] != 0){ + free( br->ring[br->pos]); } /* Assign the buffer to a slot */ - buffer_ring[buffer_pos] = buf; + br->ring[br->pos] = buf; } -/* Create a new temporary buffer on the ring. Libical owns these and - wil deallocate them. */ + +/** + * Create a new temporary buffer on the ring. Libical owns these and + * will deallocate them. + */ + void* icalmemory_tmp_buffer (size_t size) { @@ -124,24 +198,28 @@ icalmemory_tmp_buffer (size_t size) return buf; } -void icalmemory_free_ring() -{ - +/** get rid of this buffer ring */ +void icalmemory_free_ring_byval(buffer_ring *br) { int i; for(i=0; i<BUFFER_RING_SIZE; i++){ - if ( buffer_ring[i] != 0){ - free( buffer_ring[i]); + if ( br->ring[i] != 0){ + free( br->ring[i]); } - buffer_ring[i] = 0; - } + } + free(br); +} - initialized = 1; +void icalmemory_free_ring() +{ + buffer_ring *br; + br = get_buffer_ring(); + icalmemory_free_ring_byval(br); } -/* Like strdup, but the buffer is on the ring. */ +/** Like strdup, but the buffer is on the ring. */ char* icalmemory_tmp_copy(const char* str) { @@ -170,8 +248,10 @@ icalmemory_free_tmp_buffer (void* buf) } -/* These buffer routines create memory the old fashioned way -- so the - caller will have to delocate the new memory */ +/* + * These buffer routines create memory the old fashioned way -- so the + * caller will have to deallocate the new memory + */ void* icalmemory_new_buffer(size_t size) { diff --git a/libical/src/libical/icalmemory.h b/libical/src/libical/icalmemory.h index 52364e289f..7c42566eb5 100644 --- a/libical/src/libical/icalmemory.h +++ b/libical/src/libical/icalmemory.h @@ -26,8 +26,11 @@ #ifndef ICALMEMORY_H #define ICALMEMORY_H +#ifndef WIN32 #include <sys/types.h> /* for size_t */ - +#else +#include <stddef.h> +#endif /* Tmp buffers are managed by ical. References can be returned to the caller, although the caller will not own the memory. */ @@ -35,11 +38,11 @@ void* icalmemory_tmp_buffer(size_t size); char* icalmemory_tmp_copy(const char* str); -/* Add an externally allocated buffer to the ring. */ +/** Add an externally allocated buffer to the ring. */ void icalmemory_add_tmp_buffer(void*); -/* Free all memory used in the ring */ +/** Free all memory used in the ring */ void icalmemory_free_ring(void); /* Non-tmp buffers must be freed. These are mostly wrappers around @@ -50,7 +53,8 @@ void* icalmemory_new_buffer(size_t size); void* icalmemory_resize_buffer(void* buf, size_t size); void icalmemory_free_buffer(void* buf); -/* icalmemory_append_string will copy the string 'string' to the +/** + icalmemory_append_string will copy the string 'string' to the buffer 'buf' starting at position 'pos', reallocing 'buf' if it is too small. 'buf_size' is the size of 'buf' and will be changed if 'buf' is reallocated. 'pos' will point to the last byte of the new @@ -66,12 +70,12 @@ void icalmemory_free_buffer(void* buf); void icalmemory_append_string(char** buf, char** pos, size_t* buf_size, const char* string); -/* icalmemory_append_char is similar, but is appends a character instead of a string */ +/** icalmemory_append_char is similar, but is appends a character instead of a string */ void icalmemory_append_char(char** buf, char** pos, size_t* buf_size, char ch); -/* A wrapper around strdup. Partly to trap calls to strdup, partly - because in -ansi, gcc on Red Hat claims that strudup is undeclared */ +/** A wrapper around strdup. Partly to trap calls to strdup, partly + because in -ansi, gcc on Red Hat claims that strdup is undeclared */ char* icalmemory_strdup(const char *s); #endif /* !ICALMEMORY_H */ diff --git a/libical/src/libical/icalmime.c b/libical/src/libical/icalmime.c index 6e11e9e326..e5d1c90601 100644 --- a/libical/src/libical/icalmime.c +++ b/libical/src/libical/icalmime.c @@ -38,6 +38,10 @@ #include "dmalloc.h" #endif +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif /* These *_part routines are called by the MIME parser via the local_action_map */ @@ -205,8 +209,12 @@ icalcomponent* icalmime_parse(char* (*get_string)(char *s, size_t size, } if(parts[i].header.error!=SSPM_NO_ERROR){ - char *str; - char* temp[256]; + char *str = "Unknown error"; + char temp[256]; + + if(parts[i].header.error==SSPM_MALFORMED_HEADER_ERROR){ + str = "Malformed header, possibly due to input not in MIME format"; + } if(parts[i].header.error==SSPM_UNEXPECTED_BOUNDARY_ERROR){ str = "Got an unexpected boundary, possibly due to a MIME header for a MULTIPART part that is missing the Content-Type line"; @@ -227,16 +235,16 @@ line between the header and the previous boundary\?"; } if(parts[i].header.error_text != 0){ - snprintf((char*)temp,256, + snprintf(temp,sizeof(temp), "%s: %s",str,parts[i].header.error_text); } else { - strcpy((char*)temp,str); + strcpy(temp,str); } icalcomponent_add_property (comp, icalproperty_vanew_xlicerror( - (char*)temp, + temp, icalparameter_new_xlicerrortype( ICAL_XLICERRORTYPE_MIMEPARSEERROR), 0)); diff --git a/libical/src/libical/icalparameter.c b/libical/src/libical/icalparameter.c index c5eae775a6..9c55419021 100644 --- a/libical/src/libical/icalparameter.c +++ b/libical/src/libical/icalparameter.c @@ -78,53 +78,48 @@ icalparameter_new (icalparameter_kind kind) } void -icalparameter_free (icalparameter* parameter) +icalparameter_free (icalparameter* param) { - struct icalparameter_impl * impl; - - impl = (struct icalparameter_impl*)parameter; /* HACK. This always triggers, even when parameter is non-zero icalerror_check_arg_rv((parameter==0),"parameter");*/ #ifdef ICAL_FREE_ON_LIST_IS_ERROR - icalerror_assert( (impl->parent ==0),"Tried to free a parameter that is still attached to a component. "); + icalerror_assert( (param->parent ==0),"Tried to free a parameter that is still attached to a component. "); #else - if(impl->parent !=0){ + if(param->parent !=0){ return; } #endif - if (impl->string != 0){ - free ((void*)impl->string); + if (param->string != 0){ + free ((void*)param->string); } - if (impl->x_name != 0){ - free ((void*)impl->x_name); + if (param->x_name != 0){ + free ((void*)param->x_name); } - memset(impl,0,sizeof(impl)); + memset(param,0,sizeof(param)); - impl->parent = 0; - impl->id[0] = 'X'; - free(impl); + param->parent = 0; + param->id[0] = 'X'; + free(param); } icalparameter* -icalparameter_new_clone(icalparameter* param) +icalparameter_new_clone(icalparameter* old) { - struct icalparameter_impl *old; struct icalparameter_impl *new; - old = (struct icalparameter_impl *)param; new = icalparameter_new_impl(old->kind); - icalerror_check_arg_rz((param!=0),"param"); + icalerror_check_arg_rz((old!=0),"param"); if (new == 0){ return 0; @@ -197,17 +192,27 @@ icalparameter* icalparameter_new_from_string(const char *str) } +/** + * Return a string representation of the parameter according to RFC2445. + * + * param = param-name "=" param-value + * param-name = iana-token / x-token + * param-value = paramtext /quoted-string + * paramtext = *SAFE-SHARE + * quoted-string= DQUOTE *QSAFE-CHARE DQUOTE + * QSAFE-CHAR = any character except CTLs and DQUOTE + * SAFE-CHAR = any character except CTLs, DQUOTE. ";", ":", "," + */ char* -icalparameter_as_ical_string (icalparameter* parameter) +icalparameter_as_ical_string (icalparameter* param) { - struct icalparameter_impl* impl; size_t buf_size = 1024; char* buf; char* buf_ptr; char *out_buf; const char *kind_string; - icalerror_check_arg_rz( (parameter!=0), "parameter"); + icalerror_check_arg_rz( (param!=0), "parameter"); /* Create new buffer that we can append names, parameters and a value to, and reallocate as needed. Later, this buffer will be @@ -217,19 +222,18 @@ icalparameter_as_ical_string (icalparameter* parameter) buf = icalmemory_new_buffer(buf_size); buf_ptr = buf; - impl = (struct icalparameter_impl*)parameter; - if(impl->kind == ICAL_X_PARAMETER) { + if(param->kind == ICAL_X_PARAMETER) { icalmemory_append_string(&buf, &buf_ptr, &buf_size, - icalparameter_get_xname(impl)); + icalparameter_get_xname(param)); } else { - kind_string = icalparameter_kind_to_string(impl->kind); + kind_string = icalparameter_kind_to_string(param->kind); - if (impl->kind == ICAL_NO_PARAMETER || - impl->kind == ICAL_ANY_PARAMETER || + if (param->kind == ICAL_NO_PARAMETER || + param->kind == ICAL_ANY_PARAMETER || kind_string == 0) { icalerror_set_errno(ICAL_BADARG_ERROR); @@ -244,20 +248,20 @@ icalparameter_as_ical_string (icalparameter* parameter) icalmemory_append_string(&buf, &buf_ptr, &buf_size, "="); - if(impl->string !=0){ + if(param->string !=0){ int qm = 0; /* Encapsulate the property in quotes if necessary */ - if (strpbrk(impl->string, ";:,") != 0) { + if (strpbrk(param->string, ";:,") != 0) { icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"'); qm = 1; } - icalmemory_append_string(&buf, &buf_ptr, &buf_size, impl->string); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, param->string); if (qm == 1) { icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"'); } - } else if (impl->data != 0){ - const char* str = icalparameter_enum_to_string(impl->data); + } else if (param->data != 0){ + const char* str = icalparameter_enum_to_string(param->data); icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); } else { icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); @@ -267,9 +271,7 @@ icalparameter_as_ical_string (icalparameter* parameter) /* Now, copy the buffer to a tmp_buffer, which is safe to give to the caller without worring about de-allocating it. */ - out_buf = icalmemory_tmp_buffer(strlen(buf)); - strcpy(out_buf, buf); - + out_buf = icalmemory_tmp_copy(buf); icalmemory_free_buffer(buf); return out_buf; @@ -288,7 +290,7 @@ icalparameter_isa (icalparameter* parameter) return ICAL_NO_PARAMETER; } - return ((struct icalparameter_impl *)parameter)->kind; + return parameter->kind; } @@ -312,17 +314,16 @@ icalparameter_isa_parameter (void* parameter) void icalparameter_set_xname (icalparameter* param, const char* v) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; icalerror_check_arg_rv( (param!=0),"param"); icalerror_check_arg_rv( (v!=0),"v"); - if (impl->x_name != 0){ - free((void*)impl->x_name); + if (param->x_name != 0){ + free((void*)param->x_name); } - impl->x_name = icalmemory_strdup(v); + param->x_name = icalmemory_strdup(v); - if (impl->x_name == 0){ + if (param->x_name == 0){ errno = ENOMEM; } @@ -331,27 +332,24 @@ icalparameter_set_xname (icalparameter* param, const char* v) const char* icalparameter_get_xname (icalparameter* param) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; icalerror_check_arg_rz( (param!=0),"param"); - return impl->x_name; + return param->x_name; } void icalparameter_set_xvalue (icalparameter* param, const char* v) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rv( (param!=0),"param"); icalerror_check_arg_rv( (v!=0),"v"); - if (impl->string != 0){ - free((void*)impl->string); + if (param->string != 0){ + free((void*)param->string); } - impl->string = icalmemory_strdup(v); + param->string = icalmemory_strdup(v); - if (impl->string == 0){ + if (param->string == 0){ errno = ENOMEM; } @@ -360,31 +358,24 @@ icalparameter_set_xvalue (icalparameter* param, const char* v) const char* icalparameter_get_xvalue (icalparameter* param) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rz( (param!=0),"param"); - return impl->string; - + return param->string; } void icalparameter_set_parent(icalparameter* param, icalproperty* property) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rv( (param!=0),"param"); - impl->parent = property; + param->parent = property; } icalproperty* icalparameter_get_parent(icalparameter* param) { - struct icalparameter_impl *impl = (struct icalparameter_impl*)param; - icalerror_check_arg_rz( (param!=0),"param"); - return impl->parent; + return param->parent; } diff --git a/libical/src/libical/icalparameter.h b/libical/src/libical/icalparameter.h index 3f3b59f049..f3d64ab9e5 100644 --- a/libical/src/libical/icalparameter.h +++ b/libical/src/libical/icalparameter.h @@ -32,7 +32,7 @@ #include "icalderivedparameter.h" /* Declared in icalderivedparameter.h */ -/*typedef void icalparameter;*/ +/*typedef struct icalparameter_impl icalparameter;*/ icalparameter* icalparameter_new(icalparameter_kind kind); icalparameter* icalparameter_new_clone(icalparameter* p); diff --git a/libical/src/libical/icalparameter_cxx.cpp b/libical/src/libical/icalparameter_cxx.cpp new file mode 100644 index 0000000000..4b54a69991 --- /dev/null +++ b/libical/src/libical/icalparameter_cxx.cpp @@ -0,0 +1,289 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icalparameter_cxx.cpp + * @author fnguyen (12/10/01) + * @brief Implementation of C++ Wrapper for icalparameter.c + * + * (C) COPYRIGHT 2001, Critical Path + */ + +#ifndef ICALPARAMETER_CXX_H +#include "icalparameter_cxx.h" +#endif + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +typedef char* string; // Will use the string library from STL + +ICalParameter::ICalParameter() throw(icalerrorenum) : imp(icalparameter_new(ICAL_ANY_PARAMETER)){ +} + +ICalParameter::ICalParameter(const ICalParameter& v) throw(icalerrorenum) { + imp = icalparameter_new_clone(v.imp); + if (!imp) throw icalerrno; +} + +ICalParameter& ICalParameter::operator=(const ICalParameter& v) throw(icalerrorenum) { + if (this == &v) return *this; + + if (imp != NULL) + { + icalparameter_free(imp); + imp = icalparameter_new_clone(v.imp); + if (!imp) throw icalerrno; + } + + return *this; +} + +ICalParameter::~ICalParameter(){ + if (imp != NULL) icalparameter_free(imp); +} + +ICalParameter::ICalParameter(icalparameter* v) throw(icalerrorenum) : imp(v){ +} + +/// Create from string of form "PARAMNAME=VALUE" +ICalParameter::ICalParameter(string str) throw(icalerrorenum) { + imp = icalparameter_new_from_string(str); + if (!imp) throw icalerrno; +} + +/// Create from just the value, the part after the "=" +ICalParameter::ICalParameter(icalparameter_kind kind, string str) throw(icalerrorenum) { + imp = icalparameter_new_from_value_string(kind, str); + if (!imp) throw icalerrno; +} + +ICalParameter::ICalParameter(icalparameter_kind kind) throw(icalerrorenum) { + imp = icalparameter_new(kind); + if (!imp) throw icalerrno; +} + +string ICalParameter::as_ical_string() throw(icalerrorenum) { + char *str = icalparameter_as_ical_string(imp); + + if (!str) throw icalerrno; + + return str; +} + +bool ICalParameter::is_valid(){ + if (imp == NULL) return false; + return (icalparameter_isa_parameter((void*)imp) ? true : false); +} +icalparameter_kind ICalParameter::isa(){ + return icalparameter_isa(imp); +} +int ICalParameter::isa_parameter(void* param){ + return icalparameter_isa_parameter(param); +} + +/* Acess the name of an X parameer */ +void ICalParameter::set_xname(ICalParameter ¶m, string v){ + icalparameter_set_xname(param, v); +} +string ICalParameter::get_xname(ICalParameter ¶m){ + return (string)icalparameter_get_xname(param); +} +void ICalParameter::set_xvalue (ICalParameter ¶m, string v){ + icalparameter_set_xvalue(param, v); +} +string ICalParameter::get_xvalue(ICalParameter ¶m){ + return (string)icalparameter_get_xvalue(param); +} + +/* Convert enumerations */ +string ICalParameter::kind_to_string(icalparameter_kind kind){ + return (string)icalparameter_kind_to_string(kind); +} +icalparameter_kind ICalParameter::string_to_kind(string str){ + return icalparameter_string_to_kind(str); +} + +/* DELEGATED-FROM */ +string ICalParameter::get_delegatedfrom(){ + return (string)icalparameter_get_delegatedfrom(imp); +} +void ICalParameter::set_delegatedfrom(string v){ + icalparameter_set_delegatedfrom(imp, v); +} + +/* RELATED */ +icalparameter_related ICalParameter::get_related(){ + return icalparameter_get_related(imp); +} +void ICalParameter::set_related(icalparameter_related v){ + icalparameter_set_related(imp, v); +} + +/* SENT-BY */ +string ICalParameter::get_sentby(){ + return (string)icalparameter_get_sentby(imp); +} +void ICalParameter::set_sentby(string v){ + icalparameter_set_sentby(imp, v); +} + +/* LANGUAGE */ +string ICalParameter::get_language(){ + return (string)icalparameter_get_language(imp); +} +void ICalParameter::set_language(string v){ + icalparameter_set_language(imp, v); +} + +/* RELTYPE */ +icalparameter_reltype ICalParameter::get_reltype(){ + return icalparameter_get_reltype(imp); +} +void ICalParameter::set_reltype(icalparameter_reltype v){ + icalparameter_set_reltype(imp, v); +} + +/* ENCODING */ +icalparameter_encoding ICalParameter::get_encoding(){ + return icalparameter_get_encoding(imp); +} +void ICalParameter::set_encoding(icalparameter_encoding v){ + icalparameter_set_encoding(imp, v); +} + +/* ALTREP */ +string ICalParameter::get_altrep(){ + return (string)icalparameter_get_language(imp); +} +void ICalParameter::set_altrep(string v){ + icalparameter_set_altrep(imp, v); +} + +/* FMTTYPE */ +string ICalParameter::get_fmttype(){ + return (string)icalparameter_get_fmttype(imp); +} +void ICalParameter::set_fmttype(string v){ + icalparameter_set_fmttype(imp, v); +} + +/* FBTYPE */ +icalparameter_fbtype ICalParameter::get_fbtype(){ + return icalparameter_get_fbtype(imp); +} +void ICalParameter::set_fbtype(icalparameter_fbtype v){ + icalparameter_set_fbtype(imp, v); +} + +/* RSVP */ +icalparameter_rsvp ICalParameter::get_rsvp(){ + return icalparameter_get_rsvp(imp); +} +void ICalParameter::set_rsvp(icalparameter_rsvp v){ + icalparameter_set_rsvp(imp, v); +} + +/* RANGE */ +icalparameter_range ICalParameter::get_range(){ + return icalparameter_get_range(imp); +} +void ICalParameter::set_range(icalparameter_range v){ + icalparameter_set_range(imp, v); +} + +/* DELEGATED-TO */ +string ICalParameter::get_delegatedto(){ + return (string)icalparameter_get_delegatedto(imp); +} +void ICalParameter::set_delegatedto(string v){ + icalparameter_set_delegatedto(imp, v); +} + +/* CN */ +string ICalParameter::get_cn(){ + return (string)icalparameter_get_cn(imp); +} +void ICalParameter::set_cn(string v){ + icalparameter_set_cn(imp, v); +} + +/* ROLE */ +icalparameter_role ICalParameter::get_role(){ + return icalparameter_get_role(imp); +} +void ICalParameter::set_role(icalparameter_role v){ + icalparameter_set_role(imp, v); +} + +/* X-LIC-COMPARETYPE */ +icalparameter_xliccomparetype ICalParameter::get_xliccomparetype(){ + return icalparameter_get_xliccomparetype(imp); +} +void ICalParameter::set_xliccomparetype(icalparameter_xliccomparetype v){ + icalparameter_set_xliccomparetype(imp, v); +} + +/* PARTSTAT */ +icalparameter_partstat ICalParameter::get_partstat(){ + return icalparameter_get_partstat(imp); +} +void ICalParameter::set_partstat(icalparameter_partstat v){ + icalparameter_set_partstat(imp, v); +} + +/* X-LIC-ERRORTYPE */ +icalparameter_xlicerrortype ICalParameter::get_xlicerrortype(){ + return icalparameter_get_xlicerrortype(imp); +} +void ICalParameter::set_xlicerrortype(icalparameter_xlicerrortype v){ + icalparameter_set_xlicerrortype(imp, v); +} + +/* MEMBER */ +string ICalParameter::get_member(){ + return (string)icalparameter_get_member(imp); +} +void ICalParameter::set_member(string v){ + icalparameter_set_member(imp, v); +} + +/* X */ +string ICalParameter::get_x(){ + return (string)icalparameter_get_x(imp); +} +void ICalParameter::set_x(string v){ + icalparameter_set_x(imp, v); +} + +/* CUTYPE */ +icalparameter_cutype ICalParameter::get_cutype(){ + return icalparameter_get_cutype(imp); +} +void ICalParameter::set_cutype(icalparameter_cutype v){ + icalparameter_set_cutype(imp, v); +} + +/* TZID */ +string ICalParameter::get_tzid(){ + return (string)icalparameter_get_tzid(imp); +} +void ICalParameter::set_tzid(string v){ + icalparameter_set_tzid(imp, v); +} + +/* VALUE */ +icalparameter_value ICalParameter::get_value(){ + return icalparameter_get_value(imp); +} +void ICalParameter::set_value(icalparameter_value v){ + icalparameter_set_value(imp, v); +} + +/* DIR */ +string ICalParameter::get_dir(){ + return (string)icalparameter_get_dir(imp); +} +void ICalParameter::set_dir(string v){ + icalparameter_set_dir(imp, v); +} diff --git a/libical/src/libical/icalparameter_cxx.h b/libical/src/libical/icalparameter_cxx.h new file mode 100644 index 0000000000..fe35d6d4ed --- /dev/null +++ b/libical/src/libical/icalparameter_cxx.h @@ -0,0 +1,159 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icalparameter_cxx.h + * @author fnguyen (12/10/01) + * @brief Definition of C++ Wrapper for icalparameter.c + * + * (C) COPYRIGHT 2001, Critical Path + */ + + +#ifndef ICALPARAMETER_CXX_H +#define ICALPARAMETER_CXX_H + +extern "C" { +#include "ical.h" +}; + +#include "icptrholder.h" + +typedef char* string; // Will use the string library from STL + +class ICalParameter { +public: + ICalParameter() throw(icalerrorenum); + ICalParameter(const ICalParameter&) throw(icalerrorenum); + ICalParameter& operator=(const ICalParameter&) throw(icalerrorenum); + ~ICalParameter(); + + ICalParameter(icalparameter* v) throw(icalerrorenum); + + // Create from string of form "PARAMNAME=VALUE" + ICalParameter(string str) throw(icalerrorenum); + + // Create from just the value, the part after the "=" + ICalParameter(icalparameter_kind kind, string str) throw(icalerrorenum); + ICalParameter(icalparameter_kind kind) throw(icalerrorenum); + + operator icalparameter*() { return imp; } + + void detach() { + imp = NULL; + } + +public: + string as_ical_string() throw(icalerrorenum); + bool is_valid(); + icalparameter_kind isa( ); + int isa_parameter(void* param); + +public: + /* Acess the name of an X parameer */ + static void set_xname (ICalParameter ¶m, string v); + static string get_xname(ICalParameter ¶m); + static void set_xvalue (ICalParameter ¶m, string v); + static string get_xvalue(ICalParameter ¶m); + + /* Convert enumerations */ + static string kind_to_string(icalparameter_kind kind); + static icalparameter_kind string_to_kind(string str); + +public: + /* DELEGATED-FROM */ + string get_delegatedfrom(); + void set_delegatedfrom(string v); + + /* RELATED */ + icalparameter_related get_related(); + void set_related(icalparameter_related v); + + /* SENT-BY */ + string get_sentby(); + void set_sentby(string v); + + /* LANGUAGE */ + string get_language(); + void set_language(string v); + + /* RELTYPE */ + icalparameter_reltype get_reltype(); + void set_reltype(icalparameter_reltype v); + + /* ENCODING */ + icalparameter_encoding get_encoding(); + void set_encoding(icalparameter_encoding v); + + /* ALTREP */ + string get_altrep(); + void set_altrep(string v); + + /* FMTTYPE */ + string get_fmttype(); + void set_fmttype(string v); + + /* FBTYPE */ + icalparameter_fbtype get_fbtype(); + void set_fbtype(icalparameter_fbtype v); + + /* RSVP */ + icalparameter_rsvp get_rsvp(); + void set_rsvp(icalparameter_rsvp v); + + /* RANGE */ + icalparameter_range get_range(); + void set_range(icalparameter_range v); + + /* DELEGATED-TO */ + string get_delegatedto(); + void set_delegatedto(string v); + + /* CN */ + string get_cn(); + void set_cn(string v); + + /* ROLE */ + icalparameter_role get_role(); + void set_role(icalparameter_role v); + + /* X-LIC-COMPARETYPE */ + icalparameter_xliccomparetype get_xliccomparetype(); + void set_xliccomparetype(icalparameter_xliccomparetype v); + + /* PARTSTAT */ + icalparameter_partstat get_partstat(); + void set_partstat(icalparameter_partstat v); + + /* X-LIC-ERRORTYPE */ + icalparameter_xlicerrortype get_xlicerrortype(); + void set_xlicerrortype(icalparameter_xlicerrortype v); + + /* MEMBER */ + string get_member(); + void set_member(string v); + + /* X */ + string get_x(); + void set_x(string v); + + /* CUTYPE */ + icalparameter_cutype get_cutype(); + void set_cutype(icalparameter_cutype v); + + /* TZID */ + string get_tzid(); + void set_tzid(string v); + + /* VALUE */ + icalparameter_value get_value(); + void set_value(icalparameter_value v); + + /* DIR */ + string get_dir(); + void set_dir(string v); + +private: + icalparameter* imp; +}; + +#endif diff --git a/libical/src/libical/icalparser.c b/libical/src/libical/icalparser.c index 4a389540f0..0090cf9568 100644 --- a/libical/src/libical/icalparser.c +++ b/libical/src/libical/icalparser.c @@ -38,9 +38,7 @@ #endif -#include "icalparser.h" #include "pvl.h" -#include "icalmemory.h" #include "icalerror.h" #include "icalvalue.h" #include "icalderivedparameter.h" @@ -52,10 +50,34 @@ #include <stdio.h> /* For FILE and fgets and sprintf */ #include <stdlib.h> /* for free */ +#include "icalmemory.h" +#include "icalparser.h" -extern icalvalue* icalparser_yy_value; -void set_parser_value_state(icalvalue_kind kind); -int ical_yyparse(void); +#ifdef WIN32 +#define HAVE_CTYPE_H +#define HAVE_ISWSPACE +#endif + +#ifdef HAVE_WCTYPE_H +#include <wctype.h> +#endif + +#ifdef HAVE_CTYPE_H +#include <ctype.h> +#endif + +#ifndef HAVE_ISWSPACE +#ifdef HAVE_ISSPACE +# define iswspace isspace +#else +#error "You don't have isspace. Please report the error to libical@softwarestudio.org." +#endif +#endif + +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif char* icalparser_get_next_char(char c, char *str, int qm); char* icalparser_get_next_parameter(char* line,char** end); @@ -80,7 +102,7 @@ struct icalparser_impl pvl_list components; void *line_gen_data; - + }; @@ -97,12 +119,11 @@ icalparser* icalparser_new(void) impl->components = pvl_newlist(); impl->level = 0; impl->state = ICALPARSER_SUCCESS; - impl->tmp_buf_size = TMP_BUF_SIZE; impl->buffer_full = 0; - impl->continuation_line = 0; + impl->continuation_line = 0; impl->lineno = 0; - + impl->continuation_line = 0; memset(impl->temp,0, TMP_BUF_SIZE); return (icalparser*)impl; @@ -111,27 +132,24 @@ icalparser* icalparser_new(void) void icalparser_free(icalparser* parser) { - struct icalparser_impl* impl = (struct icalparser_impl*)parser; icalcomponent *c; - if (impl->root_component != 0){ - icalcomponent_free(impl->root_component); + if (parser->root_component != 0){ + icalcomponent_free(parser->root_component); } - while( (c=pvl_pop(impl->components)) != 0){ + while( (c=pvl_pop(parser->components)) != 0){ icalcomponent_free(c); } - pvl_free(impl->components); + pvl_free(parser->components); - free(impl); + free(parser); } void icalparser_set_gen_data(icalparser* parser, void* data) { - struct icalparser_impl* impl = (struct icalparser_impl*)parser; - - impl->line_gen_data = data; + parser->line_gen_data = data; } @@ -145,33 +163,34 @@ char* icalparser_get_next_char(char c, char *str, int qm) { int quote_mode = 0; char* p; - for(p=str; *p!=0; p++){ if (qm == 1) { - if ( quote_mode == 0 && *p=='"' && *(p-1) != '\\' ){ - quote_mode =1; - continue; - } - - if ( quote_mode == 1 && *p=='"' && *(p-1) != '\\' ){ - quote_mode =0; - continue; - } + if ( quote_mode == 0 && *p=='"' && *(p-1) != '\\' ){ + quote_mode =1; + continue; + } + + if ( quote_mode == 1 && *p=='"' && *(p-1) != '\\' ){ + quote_mode =0; + continue; + } } - + if (quote_mode == 0 && *p== c && *(p-1) != '\\' ){ return p; - } + } + } return 0; } -/* make a new tmp buffer out of a substring */ -char* make_segment(char* start, char* end) + +/** make a new tmp buffer out of a substring */ +static char* make_segment(char* start, char* end) { - char *buf; + char *buf, *tmp; size_t size = (size_t)end - (size_t)start; buf = icalmemory_tmp_buffer(size+1); @@ -179,63 +198,17 @@ char* make_segment(char* start, char* end) strncpy(buf,start,size); *(buf+size) = 0; + + tmp = (buf+size); + while ( *tmp == '\0' || iswspace(*tmp) ) + { + *tmp = 0; + tmp--; + } return buf; - } -const char* input_buffer; -const char* input_buffer_p; -#define min(a,b) ((a) < (b) ? (a) : (b)) - -int icalparser_flex_input(char* buf, int max_size) -{ - int n = min(max_size,strlen(input_buffer_p)); - - if (n > 0){ - memcpy(buf, input_buffer_p, n); - input_buffer_p += n; - return n; - } else { - return 0; - } -} - -void icalparser_clear_flex_input(void) -{ - input_buffer_p = input_buffer+strlen(input_buffer); -} - -/* Call the flex/bison parser to parse a complex value */ - -icalvalue* icalparser_parse_value(icalvalue_kind kind, - const char* str, icalproperty** error) -{ - int r; - input_buffer_p = input_buffer = str; - - set_parser_value_state(kind); - icalparser_yy_value = 0; - - r = ical_yyparse(); - - /* Error. Parse failed */ - if( icalparser_yy_value == 0 || r != 0){ - - if(icalparser_yy_value !=0){ - icalvalue_free(icalparser_yy_value); - icalparser_yy_value = 0; - } - - return 0; - } - - if (error != 0){ - *error = 0; - } - - return icalparser_yy_value; -} char* icalparser_get_prop_name(char* line, char** end) { @@ -262,11 +235,10 @@ char* icalparser_get_prop_name(char* line, char** end) return str; } + char* icalparser_get_param_name(char* line, char **end) { - char* next; - char* quote; char *str; next = icalparser_get_next_char('=',line,1); @@ -288,12 +260,11 @@ char* icalparser_get_param_name(char* line, char **end) } return str; - } + char* icalparser_get_next_paramvalue(char* line, char **end) { - char* next; char *str; @@ -310,10 +281,11 @@ char* icalparser_get_next_paramvalue(char* line, char **end) *end = next+1; return str; } - } -/* A property may have multiple values, if the values are seperated by + +/** + A property may have multiple values, if the values are seperated by commas in the content line. This routine will look for the next comma after line and will set the next place to start searching in end. */ @@ -351,6 +323,15 @@ char* icalparser_get_next_value(char* line, char **end, icalvalue_kind kind) continue; } } + /* ignore all , for query value. select dtstart, dtend etc ... */ + else if( kind == ICAL_QUERY_VALUE) { + if ( next != 0) { + p = next+1; + continue; + } + else + break; + } /* If the comma is preceeded by a '\', then it is a literal and not a value seperator*/ @@ -410,23 +391,23 @@ char* icalparser_get_next_parameter(char* line,char** end) } } -/* Get a single property line, from the property name through the - final new line, and include any continuation lines */ +/** + * Get a single property line, from the property name through the + * final new line, and include any continuation lines + */ char* icalparser_get_line(icalparser *parser, char* (*line_gen_func)(char *s, size_t size, void *d)) { char *line; char *line_p; - struct icalparser_impl* impl = (struct icalparser_impl*)parser; - size_t buf_size = impl->tmp_buf_size; - + size_t buf_size = parser->tmp_buf_size; line_p = line = icalmemory_new_buffer(buf_size); line[0] = '\0'; /* Read lines by calling line_gen_func and putting the data into - impl->temp. If the line is a continuation line ( begins with a + parser->temp. If the line is a continuation line ( begins with a space after a newline ) then append the data onto line and read again. Otherwise, exit the loop. */ @@ -440,23 +421,23 @@ char* icalparser_get_line(icalparser *parser, /* The tmp buffer is not clear, so transfer the data in it to the output. This may be left over from a previous call */ - if (impl->temp[0] != '\0' ) { + if (parser->temp[0] != '\0' ) { /* If the last position in the temp buffer is occupied, mark the buffer as full. The means we will do another read later, because the line is not finished */ - if (impl->temp[impl->tmp_buf_size-1] == 0 && - impl->temp[impl->tmp_buf_size-2] != '\n'&& - impl->temp[impl->tmp_buf_size-2] != 0 ){ - impl->buffer_full = 1; + if (parser->temp[parser->tmp_buf_size-1] == 0 && + parser->temp[parser->tmp_buf_size-2] != '\n'&& + parser->temp[parser->tmp_buf_size-2] != 0 ){ + parser->buffer_full = 1; } else { - impl->buffer_full = 0; + parser->buffer_full = 0; } /* Copy the temp to the output and clear the temp buffer. */ - if(impl->continuation_line==1){ + if(parser->continuation_line==1){ /* back up the pointer to erase the continuation characters */ - impl->continuation_line = 0; + parser->continuation_line = 0; line_p--; if ( *(line_p-1) == '\r'){ @@ -465,24 +446,24 @@ char* icalparser_get_line(icalparser *parser, /* copy one space up to eliminate the leading space*/ icalmemory_append_string(&line,&line_p,&buf_size, - impl->temp+1); + parser->temp+1); } else { - icalmemory_append_string(&line,&line_p,&buf_size,impl->temp); + icalmemory_append_string(&line,&line_p,&buf_size,parser->temp); } - impl->temp[0] = '\0' ; + parser->temp[0] = '\0' ; } - impl->temp[impl->tmp_buf_size-1] = 1; /* Mark end of buffer */ + parser->temp[parser->tmp_buf_size-1] = 1; /* Mark end of buffer */ /****** Here is where the routine gets string data ******************/ - if ((*line_gen_func)(impl->temp,impl->tmp_buf_size,impl->line_gen_data) + if ((*line_gen_func)(parser->temp,parser->tmp_buf_size,parser->line_gen_data) ==0){/* Get more data */ /* If the first position is clear, it means we didn't get any more data from the last call to line_ge_func*/ - if (impl->temp[0] == '\0'){ + if (parser->temp[0] == '\0'){ if(line[0] != '\0'){ /* There is data in the output, so fall trhough and process it*/ @@ -501,11 +482,11 @@ char* icalparser_get_line(icalparser *parser, begins with a ' ', then the buffer holds a continuation line, so keep reading. */ - if ( line_p > line+1 && *(line_p-1) == '\n' && impl->temp[0] == ' ') { + if ( line_p > line+1 && *(line_p-1) == '\n' && parser->temp[0] == ' ') { - impl->continuation_line = 1; + parser->continuation_line = 1; - } else if ( impl->buffer_full == 1 ) { + } else if ( parser->buffer_full == 1 ) { /* The buffer was filled on the last read, so read again */ @@ -529,11 +510,17 @@ char* icalparser_get_line(icalparser *parser, *(line_p) = '\0'; } + while ( (*line_p == '\0' || iswspace(*line_p)) && line_p > line ) + { + *line_p = '\0'; + line_p--; + } + return line; } -void insert_error(icalcomponent* comp, char* text, +static void insert_error(icalcomponent* comp, char* text, char* message, icalparameter_xlicerrortype type) { char temp[1024]; @@ -552,7 +539,8 @@ void insert_error(icalcomponent* comp, char* text, 0)); } -int line_is_blank(char* line){ + +static int line_is_blank(char* line){ int i=0; for(i=0; *(line+i)!=0; i++){ @@ -574,8 +562,8 @@ icalcomponent* icalparser_parse(icalparser *parser, char* line; icalcomponent *c=0; icalcomponent *root=0; - struct icalparser_impl *impl = (struct icalparser_impl*)parser; icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); + int cont; icalerror_check_arg_rz((parser !=0),"parser"); @@ -590,8 +578,8 @@ icalcomponent* icalparser_parse(icalparser *parser, /* This is bad news... assert? */ } - assert(impl->root_component == 0); - assert(pvl_count(impl->components) ==0); + assert(parser->root_component == 0); + assert(pvl_count(parser->components) ==0); if (root == 0){ /* Just one component */ @@ -616,10 +604,12 @@ icalcomponent* icalparser_parse(icalparser *parser, c = 0; } + cont = 0; if(line != 0){ - free(line); + icalmemory_free_buffer(line); + cont = 1; } - } while ( line != 0); + } while ( cont ); icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); @@ -631,7 +621,6 @@ icalcomponent* icalparser_parse(icalparser *parser, icalcomponent* icalparser_add_line(icalparser* parser, char* line) { - char *p; char *str; char *end; int vcount = 0; @@ -641,13 +630,12 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalvalue_kind value_kind = ICAL_NO_VALUE; - struct icalparser_impl *impl = (struct icalparser_impl*)parser; icalerror_check_arg_rz((parser != 0),"parser"); if (line == 0) { - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } @@ -665,7 +653,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, if (str == 0 || strlen(str) == 0 ){ /* Could not get a property name */ - icalcomponent *tail = pvl_data(pvl_tail(impl->components)); + icalcomponent *tail = pvl_data(pvl_tail(parser->components)); if (tail){ insert_error(tail,line, @@ -673,7 +661,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); } tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } @@ -683,17 +671,22 @@ icalcomponent* icalparser_add_line(icalparser* parser, /* If the property name is BEGIN or END, we are actually starting or ending a new component */ + if(strcmp(str,"BEGIN") == 0){ icalcomponent *c; icalcomponent_kind comp_kind; - impl->level++; + + parser->level++; str = icalparser_get_next_value(end,&end, value_kind); comp_kind = icalenum_string_to_component_kind(str); + if (comp_kind == ICAL_NO_COMPONENT){ + + c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT); insert_error(c,str,"Parse error in component name", ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); @@ -707,48 +700,48 @@ icalcomponent* icalparser_add_line(icalparser* parser, ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); } - pvl_push(impl->components,c); + pvl_push(parser->components,c); - impl->state = ICALPARSER_BEGIN_COMP; + parser->state = ICALPARSER_BEGIN_COMP; return 0; } else if (strcmp(str,"END") == 0 ) { icalcomponent* tail; - impl->level--; + parser->level--; str = icalparser_get_next_value(end,&end, value_kind); /* Pop last component off of list and add it to the second-to-last*/ - impl->root_component = pvl_pop(impl->components); + parser->root_component = pvl_pop(parser->components); - tail = pvl_data(pvl_tail(impl->components)); + tail = pvl_data(pvl_tail(parser->components)); if(tail != 0){ - icalcomponent_add_component(tail,impl->root_component); + icalcomponent_add_component(tail,parser->root_component); } tail = 0; /* Return the component if we are back to the 0th level */ - if (impl->level == 0){ + if (parser->level == 0){ icalcomponent *rtrn; - if(pvl_count(impl->components) != 0){ + if(pvl_count(parser->components) != 0){ /* There are still components on the stack -- this means that one of them did not have a proper "END" */ - pvl_push(impl->components,impl->root_component); - icalparser_clean(parser); /* may reset impl->root_component*/ + pvl_push(parser->components,parser->root_component); + icalparser_clean(parser); /* may reset parser->root_component*/ } - assert(pvl_count(impl->components) == 0); + assert(pvl_count(parser->components) == 0); - impl->state = ICALPARSER_SUCCESS; - rtrn = impl->root_component; - impl->root_component = 0; + parser->state = ICALPARSER_SUCCESS; + rtrn = parser->root_component; + parser->root_component = 0; return rtrn; } else { - impl->state = ICALPARSER_END_COMP; + parser->state = ICALPARSER_END_COMP; return 0; } } @@ -757,8 +750,8 @@ icalcomponent* icalparser_add_line(icalparser* parser, /* There is no point in continuing if we have not seen a component yet */ - if(pvl_data(pvl_tail(impl->components)) == 0){ - impl->state = ICALPARSER_ERROR; + if(pvl_data(pvl_tail(parser->components)) == 0){ + parser->state = ICALPARSER_ERROR; return 0; } @@ -777,7 +770,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, prop = icalproperty_new(prop_kind); if (prop != 0){ - icalcomponent *tail = pvl_data(pvl_tail(impl->components)); + icalcomponent *tail = pvl_data(pvl_tail(parser->components)); if(prop_kind==ICAL_X_PROPERTY){ icalproperty_set_x_name(prop,str); @@ -790,13 +783,13 @@ icalcomponent* icalparser_add_line(icalparser* parser, value_kind = icalproperty_kind_to_value_kind(icalproperty_isa(prop)); } else { - icalcomponent* tail = pvl_data(pvl_tail(impl->components)); + icalcomponent* tail = pvl_data(pvl_tail(parser->components)); insert_error(tail,str,"Parse error in property name", ICAL_XLICERRORTYPE_PROPERTYPARSEERROR); tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } @@ -806,7 +799,6 @@ icalcomponent* icalparser_add_line(icalparser* parser, /* Now, add any parameters to the last property */ - p = 0; while(1) { if (*(end-1) == ':'){ @@ -824,7 +816,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalparameter *param = 0; icalparameter_kind kind; - icalcomponent *tail = pvl_data(pvl_tail(impl->components)); + icalcomponent *tail = pvl_data(pvl_tail(parser->components)); name = icalparser_get_param_name(str,&pvalue); @@ -855,7 +847,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, insert_error(tail, str, "Cant parse parameter name", ICAL_XLICERRORTYPE_PARAMETERNAMEPARSEERROR); tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } @@ -865,7 +857,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR); tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; continue; } @@ -895,7 +887,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalparameter_free(param); tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } } @@ -929,7 +921,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, if (vcount > 0){ /* Actually, only clone after the second value */ icalproperty* clone = icalproperty_new_clone(prop); - icalcomponent* tail = pvl_data(pvl_tail(impl->components)); + icalcomponent* tail = pvl_data(pvl_tail(parser->components)); icalcomponent_add_property(tail, clone); prop = clone; @@ -943,7 +935,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, char temp[200]; /* HACK */ icalproperty_kind prop_kind = icalproperty_isa(prop); - icalcomponent* tail = pvl_data(pvl_tail(impl->components)); + icalcomponent* tail = pvl_data(pvl_tail(parser->components)); sprintf(temp,"Cant parse as %s value in %s property. Removing entire property", icalvalue_kind_to_string(value_kind), @@ -957,7 +949,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalproperty_free(prop); prop = 0; tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } else { @@ -971,7 +963,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, char temp[200]; /* HACK */ icalproperty_kind prop_kind = icalproperty_isa(prop); - icalcomponent *tail = pvl_data(pvl_tail(impl->components)); + icalcomponent *tail = pvl_data(pvl_tail(parser->components)); sprintf(temp,"No value for %s property. Removing entire property", icalproperty_kind_to_string(prop_kind)); @@ -984,7 +976,7 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalproperty_free(prop); prop = 0; tail = 0; - impl->state = ICALPARSER_ERROR; + parser->state = ICALPARSER_ERROR; return 0; } else { @@ -997,14 +989,14 @@ icalcomponent* icalparser_add_line(icalparser* parser, * End of component parsing. *****************************************************************/ - if (pvl_data(pvl_tail(impl->components)) == 0 && - impl->level == 0){ + if (pvl_data(pvl_tail(parser->components)) == 0 && + parser->level == 0){ /* HACK. Does this clause ever get executed? */ - impl->state = ICALPARSER_SUCCESS; + parser->state = ICALPARSER_SUCCESS; assert(0); - return impl->root_component; + return parser->root_component; } else { - impl->state = ICALPARSER_IN_PROGRESS; + parser->state = ICALPARSER_IN_PROGRESS; return 0; } @@ -1012,14 +1004,12 @@ icalcomponent* icalparser_add_line(icalparser* parser, icalparser_state icalparser_get_state(icalparser* parser) { - struct icalparser_impl* impl = (struct icalparser_impl*) parser; - return impl->state; + return parser->state; } icalcomponent* icalparser_clean(icalparser* parser) { - struct icalparser_impl* impl = (struct icalparser_impl*) parser; icalcomponent *tail; icalerror_check_arg_rz((parser != 0 ),"parser"); @@ -1027,27 +1017,27 @@ icalcomponent* icalparser_clean(icalparser* parser) /* We won't get a clean exit if some components did not have an "END" tag. Clear off any component that may be left in the list */ - while((tail=pvl_data(pvl_tail(impl->components))) != 0){ + while((tail=pvl_data(pvl_tail(parser->components))) != 0){ insert_error(tail," ", "Missing END tag for this component. Closing component at end of input.", ICAL_XLICERRORTYPE_COMPONENTPARSEERROR); - impl->root_component = pvl_pop(impl->components); - tail=pvl_data(pvl_tail(impl->components)); + parser->root_component = pvl_pop(parser->components); + tail=pvl_data(pvl_tail(parser->components)); if(tail != 0){ - if(icalcomponent_get_parent(impl->root_component)!=0){ + if(icalcomponent_get_parent(parser->root_component)!=0){ icalerror_warn("icalparser_clean is trying to attach a component for the second time"); } else { - icalcomponent_add_component(tail,impl->root_component); + icalcomponent_add_component(tail,parser->root_component); } } } - return impl->root_component; + return parser->root_component; } @@ -1056,7 +1046,8 @@ struct slg_data { const char* str; }; -char* string_line_generator(char *out, size_t buf_size, void *d) + +char* icalparser_string_line_generator(char *out, size_t buf_size, void *d) { char *n; size_t size; @@ -1100,7 +1091,7 @@ icalcomponent* icalparser_parse_string(const char* str) struct slg_data d; icalparser *p; - icalerrorstate es = icalerror_get_error_state(ICAL_PARSE_ERROR); + icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); d.pos = 0; d.str = str; @@ -1108,11 +1099,11 @@ icalcomponent* icalparser_parse_string(const char* str) p = icalparser_new(); icalparser_set_gen_data(p,&d); - icalerror_set_error_state(ICAL_PARSE_ERROR,ICAL_ERROR_NONFATAL); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); - c = icalparser_parse(p,string_line_generator); + c = icalparser_parse(p,icalparser_string_line_generator); - icalerror_set_error_state(ICAL_PARSE_ERROR,es); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); icalparser_free(p); diff --git a/libical/src/libical/icalparser.h b/libical/src/libical/icalparser.h index 5e1c88ffc0..7773af4d1f 100644 --- a/libical/src/libical/icalparser.h +++ b/libical/src/libical/icalparser.h @@ -33,16 +33,17 @@ #include <stdio.h> /* For FILE* */ -typedef void* icalparser; +typedef struct icalparser_impl icalparser; -/*********************************************************************** - * Line-oriented parsing. +/** + * @file icalparser.h + * @brief Line-oriented parsing. * - * Create a new parser via icalparse_new_parser, then add ines one at + * Create a new parser via icalparse_new_parser, then add lines one at * a time with icalparse_add_line(). icalparser_add_line() will return * non-zero when it has finished with a component. - ***********************************************************************/ + */ typedef enum icalparser_state { ICALPARSER_ERROR, @@ -59,18 +60,20 @@ icalparser_state icalparser_get_state(icalparser* parser); void icalparser_free(icalparser* parser); -/*********************************************************************** +/** * Message oriented parsing. icalparser_parse takes a string that * holds the text ( in RFC 2445 format ) and returns a pointer to an * icalcomponent. The caller owns the memory. line_gen_func is a * pointer to a function that returns one content line per invocation - **********************************************************************/ + */ icalcomponent* icalparser_parse(icalparser *parser, - char* (*line_gen_func)(char *s, size_t size, void *d)); + char* (*line_gen_func)(char *s, size_t size, void *d)); -/* Set the data that icalparser_parse will give to the line_gen_func - as the parameter 'd'*/ +/** + Set the data that icalparser_parse will give to the line_gen_func + as the parameter 'd' + */ void icalparser_set_gen_data(icalparser* parser, void* data); @@ -81,13 +84,13 @@ icalcomponent* icalparser_parse_string(const char* str); * Parser support functions ***********************************************************************/ -/* Use the flex/bison parser to turn a string into a value type */ +/** Use the flex/bison parser to turn a string into a value type */ icalvalue* icalparser_parse_value(icalvalue_kind kind, const char* str, icalcomponent** errors); -/* Given a line generator function, return a single iCal content line.*/ +/** Given a line generator function, return a single iCal content line.*/ char* icalparser_get_line(icalparser* parser, char* (*line_gen_func)(char *s, size_t size, void *d)); -char* string_line_generator(char *out, size_t buf_size, void *d); +char* icalparser_string_line_generator(char *out, size_t buf_size, void *d); #endif /* !ICALPARSE_H */ diff --git a/libical/src/libical/icalperiod.c b/libical/src/libical/icalperiod.c index b8c8cad1a5..0dfbe81bfc 100644 --- a/libical/src/libical/icalperiod.c +++ b/libical/src/libical/icalperiod.c @@ -36,14 +36,8 @@ #include <stdlib.h> #include <stdio.h> -#ifdef ICAL_NO_LIBICAL -#define icalerror_set_errno(x) -#define icalerror_check_arg_rv(x,y) -#define icalerror_check_arg_re(x,y,z) -#else #include "icalerror.h" #include "icalmemory.h" -#endif @@ -96,15 +90,16 @@ struct icalperiodtype icalperiodtype_from_string (const char* str) } icalerrno = e; - - icalmemory_free_buffer (s); + + icalmemory_free_buffer(s); + return p; error: icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); if (s) - icalmemory_free_buffer (s); + icalmemory_free_buffer (s); return null_p; } @@ -137,14 +132,14 @@ const char* icalperiodtype_as_ical_string(struct icalperiodtype p) icalmemory_append_string(&buf, &buf_ptr, &buf_size, end); - buf_ptr = icalmemory_tmp_copy (buf); - icalmemory_free_buffer (buf); - return buf_ptr; + icalmemory_add_tmp_buffer(buf); + + return buf; } -struct icalperiodtype icalperiodtype_null_period() { +struct icalperiodtype icalperiodtype_null_period(void) { struct icalperiodtype p; p.start = icaltime_null_time(); p.end = icaltime_null_time(); diff --git a/libical/src/libical/icalperiod.h b/libical/src/libical/icalperiod.h index 64d53237ad..5f07dd4a88 100644 --- a/libical/src/libical/icalperiod.h +++ b/libical/src/libical/icalperiod.h @@ -42,12 +42,12 @@ struct icalperiodtype struct icalperiodtype icalperiodtype_from_string (const char* str); const char* icalperiodtype_as_ical_string(struct icalperiodtype p); -struct icalperiodtype icalperiodtype_null_period(); -int icalperiodtype_is_null_period(struct icalperiodtype p); -int icalperiodtype_is_valid_period(struct icalperiodtype p); +struct icalperiodtype icalperiodtype_null_period(void); +int icalperiodtype_is_null_period(struct icalperiodtype p); +int icalperiodtype_is_valid_period(struct icalperiodtype p); #endif /* !ICALTIME_H */ diff --git a/libical/src/libical/icalproperty.c b/libical/src/libical/icalproperty.c index 8cd34f1413..16378c6da8 100644 --- a/libical/src/libical/icalproperty.c +++ b/libical/src/libical/icalproperty.c @@ -23,7 +23,6 @@ The original code is icalproperty.c ======================================================================*/ -/*#line 27 "icalproperty.c.in"*/ #ifdef HAVE_CONFIG_H #include <config.h> @@ -45,7 +44,10 @@ #include <stdio.h> /* for printf */ #include <stdarg.h> /* for va_list, va_start, etc. */ -#define TMP_BUF_SIZE 1024 +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif /* Private routines for icalproperty */ void icalvalue_set_parent(icalvalue* value, @@ -57,7 +59,7 @@ void icalparameter_set_parent(icalparameter* param, icalproperty* icalparameter_get_parent(icalparameter* value); -void icalproperty_set_x_name(icalproperty* prop, char* name); +void icalproperty_set_x_name(icalproperty* prop, const char* name); struct icalproperty_impl { @@ -70,37 +72,34 @@ struct icalproperty_impl icalcomponent *parent; }; -void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args) +void icalproperty_add_parameters(icalproperty* prop, va_list args) { - void* vp; - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - while((vp = va_arg(args, void*)) != 0) { if (icalvalue_isa_value(vp) != 0 ){ } else if (icalparameter_isa_parameter(vp) != 0 ){ - icalproperty_add_parameter((icalproperty*)impl, + icalproperty_add_parameter((icalproperty*)prop, (icalparameter*)vp); } else { - assert(0); + icalerror_set_errno(ICAL_BADARG_ERROR); } } - - } -struct icalproperty_impl* -icalproperty_new_impl (icalproperty_kind kind) +icalproperty* +icalproperty_new_impl(icalproperty_kind kind) { - struct icalproperty_impl* prop; + icalproperty* prop; - if ( ( prop = (struct icalproperty_impl*) - malloc(sizeof(struct icalproperty_impl))) == 0) { + if (!icalproperty_kind_is_valid(kind)) + return NULL; + + if ( ( prop = (icalproperty*) malloc(sizeof(icalproperty))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } @@ -121,7 +120,7 @@ icalproperty_new_impl (icalproperty_kind kind) icalproperty* icalproperty_new (icalproperty_kind kind) { - if(kind == ICAL_NO_PROPERTY){ + if (kind == ICAL_NO_PROPERTY){ return 0; } @@ -130,13 +129,11 @@ icalproperty_new (icalproperty_kind kind) icalproperty* -icalproperty_new_clone(icalproperty* prop) +icalproperty_new_clone(icalproperty* old) { - struct icalproperty_impl *old = (struct icalproperty_impl*)prop; - struct icalproperty_impl *new = icalproperty_new_impl(old->kind); + icalproperty *new = icalproperty_new_impl(old->kind); pvl_elem p; - icalerror_check_arg_rz((prop!=0),"Prop"); icalerror_check_arg_rz((old!=0),"old"); icalerror_check_arg_rz((new!=0),"new"); @@ -172,7 +169,7 @@ icalproperty_new_clone(icalproperty* prop) } -icalproperty* icalproperty_new_from_string(char* str) +icalproperty* icalproperty_new_from_string(const char* str) { size_t buf_size = 1024; @@ -217,15 +214,11 @@ icalproperty* icalproperty_new_from_string(char* str) } void -icalproperty_free (icalproperty* prop) +icalproperty_free (icalproperty* p) { - struct icalproperty_impl *p; - icalparameter* param; - icalerror_check_arg_rv((prop!=0),"prop"); - - p = (struct icalproperty_impl*)prop; + icalerror_check_arg_rv((p!=0),"prop"); #ifdef ICAL_FREE_ON_LIST_IS_ERROR icalerror_assert( (p->parent ==0),"Tried to free a property that is still attached to a component. "); @@ -281,8 +274,7 @@ get_next_line_start (char *line_start, int chars_left) /* Now we jump to the last possible character of the line, and step back trying to find a ';' ':' or ' '. If we find one, we return the character - after it. If not, we break at 74 chars (the 75th char is the space at - the start of the line). */ + after it. */ pos = line_start + MAX_LINE_LEN - 2; while (pos > line_start) { if (*pos == ';' || *pos == ':' || *pos == ' ') { @@ -290,16 +282,36 @@ get_next_line_start (char *line_start, int chars_left) } pos--; } + /* Now try to split on a UTF-8 boundary defined as a 7-bit + value or as a byte with the two high-most bits set: + 11xxxxxx. See http://czyborra.com/utf/ */ + + pos = line_start + MAX_LINE_LEN - 1; + while (pos > line_start) { + /* plain ascii */ + if ((*pos & 128) == 0) + return pos; + + /* utf8 escape byte */ + if ((*pos & 192) == 192) + return pos; + + pos--; + } + + /* Give up, just break at 74 chars (the 75th char is the space at + the start of the line). */ return line_start + MAX_LINE_LEN - 1; } -/* This splits the property into lines less than 75 octects long (as specified - in RFC2445). It tries to split after a ';' if it can. - It returns a tmp buffer. - NOTE: I'm not sure if it matters if we split a line in the middle of a - UTF-8 character. It probably won't look nice in a text editor. */ +/** This splits the property into lines less than 75 octects long (as + * specified in RFC2445). It tries to split after a ';' if it can. + * It returns a tmp buffer. NOTE: I'm not sure if it matters if we + * split a line in the middle of a UTF-8 character. It probably won't + * look nice in a text editor. + */ static char* fold_property_line (char *text) { @@ -354,69 +366,25 @@ fold_property_line (char *text) } -char* -icalproperty_as_ical_string (icalproperty* prop) -{ - icalparameter *param; - - /* Create new buffer that we can append names, parameters and a - value to, and reallocate as needed. Later, this buffer will be - copied to a icalmemory_tmp_buffer, which is managed internally - by libical, so it can be given to the caller without fear of - the caller forgetting to free it */ - - const char* property_name = 0; - size_t buf_size = 1024; - char* buf = icalmemory_new_buffer(buf_size); - char* buf_ptr = buf; - icalvalue* value; - char *out_buf; - - char newline[] = "\n"; - - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); - - - /* Append property name */ - - if (impl->kind == ICAL_X_PROPERTY && impl->x_name != 0){ - property_name = impl->x_name; - } else { - property_name = icalproperty_kind_to_string(impl->kind); - } - - if (property_name == 0 ) { - icalerror_warn("Got a property of an unknown kind."); - icalmemory_free_buffer(buf); - return 0; - - } - - - icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); - /* Outlook doesn't like a newline here. */ - /*icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);*/ - - - /* Determine what VALUE parameter to include. The VALUE parameters - are ignored in the normal parameter printing ( the block after - this one, so we need to do it here */ - { +/* Determine what VALUE parameter to include. The VALUE parameters + are ignored in the normal parameter printing ( the block after + this one, so we need to do it here */ +static const char * +icalproperty_get_value_kind(icalproperty *prop) +{ const char* kind_string = 0; icalparameter *orig_val_param = icalproperty_get_first_parameter(prop,ICAL_VALUE_PARAMETER); - icalvalue *value = icalproperty_get_value(impl); + icalvalue *value = icalproperty_get_value(prop); icalvalue_kind orig_kind = ICAL_NO_VALUE; icalvalue_kind this_kind = ICAL_NO_VALUE; icalvalue_kind default_kind - = icalproperty_kind_to_value_kind(impl->kind); + = icalproperty_kind_to_value_kind(prop->kind); if(orig_val_param){ orig_kind = (icalvalue_kind)icalparameter_get_value(orig_val_param); @@ -443,17 +411,55 @@ icalproperty_as_ical_string (icalproperty* prop) /* Don'tinclude the VALUE parameter at all */ } - if(kind_string!=0){ - /* We aren't outputting a newline, so we don't want a space. */ - /*icalmemory_append_string(&buf, &buf_ptr, &buf_size, " ;");*/ - /*icalmemory_append_string(&buf, &buf_ptr, &buf_size, "VALUE=");*/ - icalmemory_append_string(&buf, &buf_ptr, &buf_size, ";VALUE="); - icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); - /* No newline again. */ - /*icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);*/ - } + return kind_string; +} + +const char* +icalproperty_as_ical_string (icalproperty* prop) +{ + icalparameter *param; + + /* Create new buffer that we can append names, parameters and a + value to, and reallocate as needed. Later, this buffer will be + copied to a icalmemory_tmp_buffer, which is managed internally + by libical, so it can be given to the caller without fear of + the caller forgetting to free it */ + + const char* property_name = 0; + size_t buf_size = 1024; + char* buf = icalmemory_new_buffer(buf_size); + char* buf_ptr = buf; + icalvalue* value; + char *out_buf; + const char* kind_string = 0; + + char newline[] = "\n"; + + + icalerror_check_arg_rz( (prop!=0),"prop"); + + + /* Append property name */ + + if (prop->kind == ICAL_X_PROPERTY && prop->x_name != 0){ + property_name = prop->x_name; + } else { + property_name = icalproperty_kind_to_string(prop->kind); + } + + if (property_name == 0 ) { + icalerror_warn("Got a property of an unknown kind."); + icalmemory_free_buffer(buf); + return 0; + } + icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name); + + kind_string = icalproperty_get_value_kind(prop); + if(kind_string!=0){ + icalmemory_append_string(&buf, &buf_ptr, &buf_size, ";VALUE="); + icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string); } /* Append parameters */ @@ -461,17 +467,17 @@ icalproperty_as_ical_string (icalproperty* prop) param != 0; param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { - char* kind_string = icalparameter_as_ical_string(param); icalparameter_kind kind = icalparameter_isa(param); + kind_string = icalparameter_as_ical_string(param); if(kind==ICAL_VALUE_PARAMETER){ continue; } if (kind_string == 0 ) { - char temp[TMP_BUF_SIZE]; - snprintf(temp, TMP_BUF_SIZE,"Got a parameter of unknown kind in %s property",property_name); - icalerror_warn(temp); + icalerror_warn("Got a parameter of unknown kind for the following property"); + + icalerror_warn((property_name) ? property_name : "(NULL)"); continue; } @@ -502,16 +508,6 @@ icalproperty_as_ical_string (icalproperty* prop) /* We now use a function to fold the line properly every 75 characters. */ out_buf = fold_property_line (buf); - /* This is useful for testing. It outputs the property before and after - folding, but only if it was changed. */ -#if 0 - if (strcmp (buf, out_buf)) - printf ("Property:\n%sFolded:\n%s", buf, out_buf); -#endif - - /*out_buf = icalmemory_tmp_buffer(strlen(buf)+1);*/ - /*strcpy(out_buf, buf);*/ - icalmemory_free_buffer(buf); return out_buf; @@ -520,11 +516,9 @@ icalproperty_as_ical_string (icalproperty* prop) icalproperty_kind -icalproperty_isa (icalproperty* property) +icalproperty_isa (icalproperty* p) { - struct icalproperty_impl *p = (struct icalproperty_impl*)property; - - if(property != 0){ + if(p != 0){ return p->kind; } @@ -534,10 +528,9 @@ icalproperty_isa (icalproperty* property) int icalproperty_isa_property (void* property) { - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; + icalproperty *impl = (icalproperty *) property; icalerror_check_arg_rz( (property!=0), "property"); - if (strcmp(impl->id,"prop") == 0) { return 1; } else { @@ -547,11 +540,9 @@ icalproperty_isa_property (void* property) void -icalproperty_add_parameter (icalproperty* prop,icalparameter* parameter) +icalproperty_add_parameter (icalproperty* p,icalparameter* parameter) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv( (prop!=0),"prop"); + icalerror_check_arg_rv( (p!=0),"prop"); icalerror_check_arg_rv( (parameter!=0),"parameter"); pvl_push(p->parameters, parameter); @@ -567,8 +558,11 @@ icalproperty_set_parameter (icalproperty* prop,icalparameter* parameter) icalerror_check_arg_rv( (parameter!=0),"parameter"); kind = icalparameter_isa(parameter); - - icalproperty_remove_parameter(prop,kind); + if (kind != ICAL_X_PARAMETER) + icalproperty_remove_parameter_by_kind(prop,kind); + else + icalproperty_remove_parameter_by_name(prop, + icalparameter_get_xname(parameter)); icalproperty_add_parameter(prop,parameter); } @@ -590,7 +584,7 @@ void icalproperty_set_parameter_from_string(icalproperty* prop, icalerror_set_errno(ICAL_BADARG_ERROR); return; } - + param = icalparameter_new_from_value_string(kind,value); if (param == 0){ @@ -598,6 +592,10 @@ void icalproperty_set_parameter_from_string(icalproperty* prop, return; } + if(kind == ICAL_X_PARAMETER){ + icalparameter_set_xname(param, name); + } + icalproperty_set_parameter(prop,param); } @@ -615,17 +613,28 @@ const char* icalproperty_get_parameter_as_string(icalproperty* prop, kind = icalparameter_string_to_kind(name); - if(kind == ICAL_NO_PROPERTY){ + if(kind == ICAL_NO_PARAMETER){ /* icalenum_string_to_parameter_kind will set icalerrno */ return 0; } + + for(param = icalproperty_get_first_parameter(prop,kind); + param != 0; + param = icalproperty_get_next_parameter(prop,kind)) { + if (kind != ICAL_X_PARAMETER) { + break; + } - param = icalproperty_get_first_parameter(prop,kind); + if (strcmp(icalparameter_get_xname(param),name)==0) { + break; + } + } if (param == 0){ return 0; } + str = icalparameter_as_ical_string(param); pv = strchr(str,'='); @@ -639,31 +648,133 @@ const char* icalproperty_get_parameter_as_string(icalproperty* prop, } +/** @see icalproperty_remove_parameter_by_kind() + * + * @deprecated Please use icalproperty_remove_parameter_by_kind() + * instead. + */ + void -icalproperty_remove_parameter (icalproperty* prop, icalparameter_kind kind) +icalproperty_remove_parameter(icalproperty* prop, icalparameter_kind kind) +{ + icalproperty_remove_parameter_by_kind(prop, kind); +} + + +/** @brief Remove all parameters with the specified kind. + * + * @param prop A valid icalproperty. + * @param kind The kind to remove (ex. ICAL_TZID_PARAMETER) + * + * See icalproperty_remove_parameter_by_name() and + * icalproperty_remove_parameter_by_ref() for alternate ways of + * removing parameters + */ + +void +icalproperty_remove_parameter_by_kind(icalproperty* prop, icalparameter_kind kind) { pvl_elem p; - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; icalerror_check_arg_rv((prop!=0),"prop"); - for(p=pvl_head(impl->parameters);p != 0; p = pvl_next(p)){ + for(p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)){ icalparameter* param = (icalparameter *)pvl_data (p); if (icalparameter_isa(param) == kind) { - pvl_remove (impl->parameters, p); + pvl_remove (prop->parameters, p); + icalparameter_free(param); break; } } } -int -icalproperty_count_parameters (icalproperty* prop) +/** @brief Remove all parameters with the specified name. + * + * @param prop A valid icalproperty. + * @param name The name of the parameter to remove + * + * This function removes paramters with the given name. The name + * corresponds to either a built-in name (TZID, etc.) or the name of + * an extended parameter (X-FOO) + * + * See icalproperty_remove_parameter_by_kind() and + * icalproperty_remove_parameter_by_ref() for alternate ways of removing + * parameters + */ + + +void +icalproperty_remove_parameter_by_name(icalproperty* prop, const char *name) +{ + pvl_elem p; + + icalerror_check_arg_rv((prop!=0),"prop"); + + for(p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)){ + icalparameter* param = (icalparameter *)pvl_data (p); + const char * kind_string; + + if (icalparameter_isa(param) == ICAL_X_PARAMETER) + kind_string = icalparameter_get_xname(param); + else + kind_string = icalparameter_kind_to_string(icalparameter_isa(param)); + + if (!kind_string) + continue; + + if (0 == strcmp(kind_string, name)) { + pvl_remove (prop->parameters, p); + break; + } + } +} + + +/** @brief Remove the specified parameter reference from the property. + * + * @param prop A valid icalproperty. + * @param parameter A reference to a specific icalparameter. + * + * This function removes the specified parameter reference from the + * property. + */ + +void +icalproperty_remove_parameter_by_ref(icalproperty* prop, icalparameter* parameter) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; + pvl_elem p; + icalparameter_kind kind; + const char *name; + + icalerror_check_arg_rv((prop!=0),"prop"); + icalerror_check_arg_rv((parameter!=0),"parameter"); + + kind = icalparameter_isa(parameter); + name = icalparameter_get_xname(parameter); + + /* + * FIXME If it's an X- parameter, also compare the names. It would be nice + * to have a better abstraction like icalparameter_equals() + */ + for(p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)){ + icalparameter* p_param = (icalparameter *)pvl_data (p); + if (icalparameter_isa(p_param) == kind && + (kind != ICAL_X_PARAMETER || + !strcmp(icalparameter_get_xname(p_param), name))) { + pvl_remove (prop->parameters, p); + icalparameter_free(p_param); + break; + } + } +} + +int +icalproperty_count_parameters (const icalproperty* prop) +{ if(prop != 0){ - return pvl_count(p->parameters); + return pvl_count(prop->parameters); } icalerror_set_errno(ICAL_USAGE_ERROR); @@ -672,11 +783,9 @@ icalproperty_count_parameters (icalproperty* prop) icalparameter* -icalproperty_get_first_parameter (icalproperty* prop, icalparameter_kind kind) +icalproperty_get_first_parameter(icalproperty* p, icalparameter_kind kind) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); + icalerror_check_arg_rz( (p!=0),"prop"); p->parameter_iterator = pvl_head(p->parameters); @@ -700,11 +809,9 @@ icalproperty_get_first_parameter (icalproperty* prop, icalparameter_kind kind) icalparameter* -icalproperty_get_next_parameter (icalproperty* prop, icalparameter_kind kind) +icalproperty_get_next_parameter (icalproperty* p, icalparameter_kind kind) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rz( (prop!=0),"prop"); + icalerror_check_arg_rz( (p!=0),"prop"); if (p->parameter_iterator == 0) { return 0; @@ -726,11 +833,9 @@ icalproperty_get_next_parameter (icalproperty* prop, icalparameter_kind kind) } void -icalproperty_set_value (icalproperty* prop, icalvalue* value) +icalproperty_set_value (icalproperty* p, icalvalue* value) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - - icalerror_check_arg_rv((prop !=0),"prop"); + icalerror_check_arg_rv((p !=0),"prop"); icalerror_check_arg_rv((value !=0),"value"); if (p->value != 0){ @@ -741,7 +846,7 @@ icalproperty_set_value (icalproperty* prop, icalvalue* value) p->value = value; - icalvalue_set_parent(value,prop); + icalvalue_set_parent(value,p); } @@ -789,60 +894,50 @@ void icalproperty_set_value_from_string(icalproperty* prop,const char* str, } icalvalue* -icalproperty_get_value (icalproperty* prop) +icalproperty_get_value(const icalproperty* prop) { - struct icalproperty_impl *p = (struct icalproperty_impl*)prop; - icalerror_check_arg_rz( (prop!=0),"prop"); - return p->value; + return prop->value; } -const char* icalproperty_get_value_as_string(icalproperty* prop) +const char* icalproperty_get_value_as_string(const icalproperty* prop) { icalvalue *value; - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - icalerror_check_arg_rz( (prop!=0),"prop"); - value = impl->value; + value = prop->value; return icalvalue_as_ical_string(value); } -void icalproperty_set_x_name(icalproperty* prop, char* name) +void icalproperty_set_x_name(icalproperty* prop, const char* name) { - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - icalerror_check_arg_rv( (name!=0),"name"); icalerror_check_arg_rv( (prop!=0),"prop"); - if (impl->x_name != 0) { - free(impl->x_name); + if (prop->x_name != 0) { + free(prop->x_name); } - impl->x_name = icalmemory_strdup(name); + prop->x_name = icalmemory_strdup(name); - if(impl->x_name == 0){ + if(prop->x_name == 0){ icalerror_set_errno(ICAL_NEWFAILED_ERROR); } } -char* icalproperty_get_x_name(icalproperty* prop){ - - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - +const char* icalproperty_get_x_name(icalproperty* prop){ icalerror_check_arg_rz( (prop!=0),"prop"); - return impl->x_name; + return prop->x_name; } -/* From Jonathan Yue <jonathan.yue@cp.net> */ -char* icalproperty_get_name (icalproperty* prop) +const char* icalproperty_get_property_name(const icalproperty* prop) { const char* property_name = 0; @@ -850,14 +945,12 @@ char* icalproperty_get_name (icalproperty* prop) char* buf = icalmemory_new_buffer(buf_size); char* buf_ptr = buf; - struct icalproperty_impl *impl = (struct icalproperty_impl*)prop; - icalerror_check_arg_rz( (prop!=0),"prop"); - if (impl->kind == ICAL_X_PROPERTY && impl->x_name != 0){ - property_name = impl->x_name; + if (prop->kind == ICAL_X_PROPERTY && prop->x_name != 0){ + property_name = prop->x_name; } else { - property_name = icalproperty_kind_to_string(impl->kind); + property_name = icalproperty_kind_to_string(prop->kind); } if (property_name == 0 ) { @@ -883,26 +976,14 @@ char* icalproperty_get_name (icalproperty* prop) void icalproperty_set_parent(icalproperty* property, icalcomponent* component) { - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; - icalerror_check_arg_rv( (property!=0),"property"); - impl->parent = component; + property->parent = component; } -icalcomponent* icalproperty_get_parent(icalproperty* property) +icalcomponent* icalproperty_get_parent(const icalproperty* property) { - struct icalproperty_impl *impl = (struct icalproperty_impl*)property; - icalerror_check_arg_rz( (property!=0),"property"); - return impl->parent; + return property->parent; } - - - - - - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalproperty.h b/libical/src/libical/icalproperty.h index 6f5f1bfaef..472adb9585 100644 --- a/libical/src/libical/icalproperty.h +++ b/libical/src/libical/icalproperty.h @@ -31,7 +31,7 @@ #define ICALPROPERTY_H #include <time.h> - +#include <stdarg.h> /* for va_... */ #include "icalderivedparameter.h" @@ -39,7 +39,7 @@ #include "icalrecur.h" /* Actually in icalderivedproperty.h: - typedef void icalproperty; */ + typedef struct icalproperty_impl icalproperty; */ #include "icalderivedproperty.h" /* To get icalproperty_kind enumerations */ @@ -47,15 +47,16 @@ icalproperty* icalproperty_new(icalproperty_kind kind); icalproperty* icalproperty_new_clone(icalproperty * prop); -icalproperty* icalproperty_new_from_string(char* str); +icalproperty* icalproperty_new_from_string(const char* str); -char* icalproperty_as_ical_string(icalproperty* prop); +const char* icalproperty_as_ical_string(icalproperty* prop); void icalproperty_free(icalproperty* prop); icalproperty_kind icalproperty_isa(icalproperty* property); int icalproperty_isa_property(void* property); +void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args); void icalproperty_add_parameter(icalproperty* prop,icalparameter* parameter); void icalproperty_set_parameter(icalproperty* prop,icalparameter* parameter); void icalproperty_set_parameter_from_string(icalproperty* prop, @@ -66,7 +67,18 @@ const char* icalproperty_get_parameter_as_string(icalproperty* prop, void icalproperty_remove_parameter(icalproperty* prop, icalparameter_kind kind); -int icalproperty_count_parameters(icalproperty* prop); +void icalproperty_remove_parameter_by_kind(icalproperty* prop, + icalparameter_kind kind); + +void icalproperty_remove_parameter_by_name(icalproperty* prop, + const char *name); + +void icalproperty_remove_parameter_by_ref(icalproperty* prop, + icalparameter *param); + + + +int icalproperty_count_parameters(const icalproperty* prop); /* Iterate through the parameters */ icalparameter* icalproperty_get_first_parameter(icalproperty* prop, @@ -77,33 +89,39 @@ icalparameter* icalproperty_get_next_parameter(icalproperty* prop, void icalproperty_set_value(icalproperty* prop, icalvalue* value); void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char* kind); -icalvalue* icalproperty_get_value(icalproperty* prop); -const char* icalproperty_get_value_as_string(icalproperty* prop); +icalvalue* icalproperty_get_value(const icalproperty* prop); +const char* icalproperty_get_value_as_string(const icalproperty* prop); /* Deal with X properties */ -void icalproperty_set_x_name(icalproperty* prop, char* name); -char* icalproperty_get_x_name(icalproperty* prop); +void icalproperty_set_x_name(icalproperty* prop, const char* name); +const char* icalproperty_get_x_name(icalproperty* prop); -/* Return the name of the property -- the type name converted to a - string, or the value of _get_x_name if the type is and X property */ -char* icalproperty_get_name (icalproperty* prop); +/** Return the name of the property -- the type name converted to a + * string, or the value of _get_x_name if the type is and X + * property + */ +const char* icalproperty_get_property_name (const icalproperty* prop); icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value); /* Convert kinds to string and get default value type */ icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind); -icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind); +icalproperty_kind icalproperty_value_kind_to_kind(icalvalue_kind kind); const char* icalproperty_kind_to_string(icalproperty_kind kind); icalproperty_kind icalproperty_string_to_kind(const char* string); +/** Check validity of a specific icalproperty_kind **/ +int icalproperty_kind_is_valid(const icalproperty_kind kind); + icalproperty_method icalproperty_string_to_method(const char* str); const char* icalproperty_method_to_string(icalproperty_method method); const char* icalproperty_enum_to_string(int e); int icalproperty_string_to_enum(const char* str); +int icalproperty_kind_and_string_to_enum(const int kind, const char* str); const char* icalproperty_status_to_string(icalproperty_status); icalproperty_status icalproperty_string_to_status(const char* string); diff --git a/libical/src/libical/icalproperty_cxx.cpp b/libical/src/libical/icalproperty_cxx.cpp new file mode 100644 index 0000000000..fcd4de5719 --- /dev/null +++ b/libical/src/libical/icalproperty_cxx.cpp @@ -0,0 +1,702 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icalproperty_cxx.cpp + * @author fnguyen (12/10/01) + * @brief Implementation of C++ Wrapper for icalproperty.c + * + * (C) COPYRIGHT 2001, Critical Path + */ + + +#ifndef ICALPROPERTY_CXX_H +#include "icalproperty_cxx.h" +#endif + +#ifndef ICALPARAMETER_CXX_H +#include "icalparameter_cxx.h" +#endif + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +ICalProperty::ICalProperty() : imp(icalproperty_new(ICAL_ANY_PROPERTY)){ +} + +ICalProperty::ICalProperty(const ICalProperty& v) throw(icalerrorenum){ + imp = icalproperty_new_clone(v.imp); + if (!imp) throw icalerrno; +} + +ICalProperty& ICalProperty::operator=(const ICalProperty& v) throw(icalerrorenum) { + if (this == &v) return *this; + + if (imp != NULL) + { + icalproperty_free(imp); + imp = icalproperty_new_clone(v.imp); + if (!imp) throw icalerrno; + } + + return *this; +} +ICalProperty::~ICalProperty(){ + if (imp != NULL) icalproperty_free(imp); +} + +ICalProperty::ICalProperty(icalproperty* v) : imp(v) { +} + +ICalProperty::ICalProperty(string str){ + imp = icalproperty_new_from_string(str); +} + +ICalProperty::ICalProperty(icalproperty_kind kind){ + imp = icalproperty_new(kind); +} + +string ICalProperty::as_ical_string(){ + return (string)icalproperty_as_ical_string(imp); +} +icalproperty_kind ICalProperty::isa(){ + return icalproperty_isa(imp); +} +int ICalProperty::isa_property(void* property){ + return icalproperty_isa_property(property); +} + +int ICalProperty::operator==(ICalProperty& rhs){ + icalparameter_xliccomparetype result; + ICalValue* thisPropValue = this->get_value(); + ICalValue* rhsPropValue = rhs.get_value(); + result = icalvalue_compare((icalvalue*)*thisPropValue, (icalvalue*)*rhsPropValue); + return (result == ICAL_XLICCOMPARETYPE_EQUAL); +} + +void ICalProperty::add_parameter(ICalParameter& parameter){ + icalproperty_add_parameter(imp, parameter); +} +void ICalProperty::set_parameter(ICalParameter ¶meter){ + icalproperty_set_parameter(imp, parameter); +} +void ICalProperty::set_parameter_from_string(string name, string val){ + icalproperty_set_parameter_from_string(imp, name, val); +} +string ICalProperty::get_parameter_as_string(string name){ + return (string)icalproperty_get_parameter_as_string(imp, name); +} +void ICalProperty::remove_parameter(icalparameter_kind kind){ + icalproperty_remove_parameter(imp, kind); +} +int ICalProperty::count_parameters(){ + return icalproperty_count_parameters(imp); +} + +/** Iterate through the parameters */ +ICalParameter* ICalProperty::get_first_parameter(icalparameter_kind kind){ + return new ICalParameter(icalproperty_get_first_parameter(imp, kind)); +} +ICalParameter* ICalProperty::get_next_parameter(icalparameter_kind kind){ + return new ICalParameter(icalproperty_get_next_parameter(imp, kind)); +} + +/** Access the value of the property */ +void ICalProperty::set_value(const ICalValue& val){ + icalproperty_set_value(imp, (ICalValue&)val); +} +void ICalProperty::set_value_from_string(string val, string kind){ + icalproperty_set_value_from_string(imp, val, kind); +} + +ICalValue* ICalProperty::get_value(){ + return new ICalValue(icalproperty_get_value(imp)); +} +string ICalProperty::get_value_as_string(){ + return (string)icalproperty_get_value_as_string(imp); +} + +/** Return the name of the property -- the type name converted to a + * string, or the value of get_x_name if the type is X property + */ +string ICalProperty::get_name(){ + return (string)icalproperty_get_property_name(imp); +} + +/* Deal with X properties */ +void ICalProperty::set_x_name(ICalProperty &prop, string name){ + icalproperty_set_x_name(prop, name); +} +string ICalProperty::get_x_name(ICalProperty &prop){ + return (string)icalproperty_get_x_name(prop); +} + +icalvalue_kind ICalProperty::icalparameter_value_to_value_kind(icalparameter_value val){ + return icalparameter_value_to_value_kind(val); +} + +/* Convert kinds to string and get default value type */ +icalvalue_kind ICalProperty::kind_to_value_kind(icalproperty_kind kind){ + return icalproperty_kind_to_value_kind(kind); +} +icalproperty_kind ICalProperty::value_kind_to_kind(icalvalue_kind kind){ + return icalproperty_value_kind_to_kind(kind); +} +string ICalProperty::kind_to_string(icalproperty_kind kind){ + return (string)icalproperty_kind_to_string(kind); +} +icalproperty_kind ICalProperty::string_to_kind(string str){ + return icalproperty_string_to_kind(str); +} + +string ICalProperty::method_to_string(icalproperty_method method){ + return (string)icalproperty_method_to_string(method); +} +icalproperty_method ICalProperty::string_to_method(string str){ + return icalproperty_string_to_method(str); +} + +string ICalProperty::enum_to_string(int e){ + return (string)icalproperty_enum_to_string(e); +} +int ICalProperty::string_to_enum(string str){ + return icalproperty_string_to_enum(str); +} + +string ICalProperty::status_to_string(icalproperty_status s){ + return (string)icalproperty_status_to_string(s); +} +icalproperty_status ICalProperty::string_to_status(string str){ + return icalproperty_string_to_status(str); +} + +int ICalProperty::enum_belongs_to_property(icalproperty_kind kind, int e){ + return icalproperty_enum_belongs_to_property(kind, e); +} + +/* ACTION */ +void ICalProperty::set_action(enum icalproperty_action val){ + icalproperty_set_action(imp, val); +} +enum icalproperty_action ICalProperty::get_action(){ + return icalproperty_get_action(imp); +} + +/* ATTACH */ +void ICalProperty::set_attach(icalattach *val){ + icalproperty_set_attach(imp, val); +} +icalattach * ICalProperty::get_attach(){ + return icalproperty_get_attach(imp); +} + +/* ATTENDEE */ +void ICalProperty::set_attendee(string val){ + icalproperty_set_attendee(imp, val); +} +string ICalProperty::get_attendee(){ + return (string)icalproperty_get_attendee(imp); +} + +/* CALSCALE */ +void ICalProperty::set_calscale(string val){ + icalproperty_set_calscale(imp, val); +} +string ICalProperty::get_calscale(){ + return (string)icalproperty_get_calscale(imp); +} + +/* CATEGORIES */ +void ICalProperty::set_categories(string val){ + icalproperty_set_categories(imp, val); +} +string ICalProperty::get_categories(){ + return (string)icalproperty_get_categories(imp); +} + +/* CLASS */ +void ICalProperty::set_class(enum icalproperty_class val){ + icalproperty_set_class(imp, val); +} +enum icalproperty_class ICalProperty::get_class(){ + return (enum icalproperty_class)icalproperty_get_class(imp); +} + +/* COMMENT */ +void ICalProperty::set_comment(string val){ + icalproperty_set_comment(imp, val); +} +string ICalProperty::get_comment(){ + return (string)icalproperty_get_comment(imp); +} + +/* COMPLETED */ +void ICalProperty::set_completed(struct icaltimetype val){ + icalproperty_set_completed(imp, val); +} +struct icaltimetype ICalProperty::get_completed(){ + return icalproperty_get_completed(imp); +} + +/* CONTACT */ +void ICalProperty::set_contact(string val){ + icalproperty_set_contact(imp, val); +} +string ICalProperty::get_contact(){ + return (string)icalproperty_get_contact(imp); +} + +/* CREATED */ +void ICalProperty::set_created(struct icaltimetype val){ + icalproperty_set_created(imp, val); +} +struct icaltimetype ICalProperty::get_created(){ + return icalproperty_get_created(imp); +} + +/* DESCRIPTION */ +void ICalProperty::set_description(string val){ + icalproperty_set_description(imp, val); +} +string ICalProperty::get_description(){ + return (string)icalproperty_get_description(imp); +} + +/* DTEND */ +void ICalProperty::set_dtend(struct icaltimetype val){ + icalproperty_set_dtend(imp, val); +} +struct icaltimetype ICalProperty::get_dtend(){ + return icalproperty_get_dtend(imp); +} + +/* DTSTAMP */ +void ICalProperty::set_dtstamp(struct icaltimetype val){ + icalproperty_set_dtstamp(imp, val); +} +struct icaltimetype ICalProperty::get_dtstamp(){ + return icalproperty_get_dtstamp(imp); +} + +/* DTSTART */ +void ICalProperty::set_dtstart(struct icaltimetype val){ + icalproperty_set_dtstart(imp, val); +} +struct icaltimetype ICalProperty::get_dtstart(){ + return icalproperty_get_dtstart(imp); +} + +/* DUE */ +void ICalProperty::set_due(struct icaltimetype val){ + icalproperty_set_due(imp, val); +} +struct icaltimetype ICalProperty::get_due(){ + return icalproperty_get_due(imp); +} + +/* DURATION */ +void ICalProperty::set_duration(struct icaldurationtype val){ + icalproperty_set_duration(imp, val); +} +struct icaldurationtype ICalProperty::get_duration(){ + return icalproperty_get_duration(imp); +} + +/* EXDATE */ +void ICalProperty::set_exdate(struct icaltimetype val){ + icalproperty_set_exdate(imp, val); +} +struct icaltimetype ICalProperty::get_exdate(){ + return icalproperty_get_exdate(imp); +} + +/* EXPAND */ +void ICalProperty::set_expand(int val){ + icalproperty_set_expand(imp, val); +} +int ICalProperty::get_expand(){ + return icalproperty_get_expand(imp); +} + +/* EXRULE */ +void ICalProperty::set_exrule(struct icalrecurrencetype val){ + icalproperty_set_exrule(imp, val); +} +struct icalrecurrencetype ICalProperty::get_exrule(){ + return icalproperty_get_exrule(imp); +} + +/* FREEBUSY */ +void ICalProperty::set_freebusy(struct icalperiodtype val){ + icalproperty_set_freebusy(imp, val); +} +struct icalperiodtype ICalProperty::get_freebusy(){ + return icalproperty_get_freebusy(imp); +} + +/* GEO */ +void ICalProperty::set_geo(struct icalgeotype val){ + icalproperty_set_geo(imp, val); +} +struct icalgeotype ICalProperty::get_geo(){ + return icalproperty_get_geo(imp); +} + +/* LAST-MODIFIED */ +void ICalProperty::set_lastmodified(struct icaltimetype val){ + icalproperty_set_lastmodified(imp, val); +} +struct icaltimetype ICalProperty::get_lastmodified(){ + return icalproperty_get_lastmodified(imp); +} + +/* LOCATION */ +void ICalProperty::set_location(string val){ + icalproperty_set_location(imp, val); +} +string ICalProperty::get_location(){ + return (string)icalproperty_get_location(imp); +} + +/* MAXRESULTS */ +void ICalProperty::set_maxresults(int val){ + icalproperty_set_maxresults(imp, val); +} +int ICalProperty::get_maxresults(){ + return icalproperty_get_maxresults(imp); +} + +/* MAXRESULTSSIZE */ +void ICalProperty::set_maxresultsize(int val){ + icalproperty_set_maxresultssize(imp, val); +} +int ICalProperty::get_maxresultsize(){ + return icalproperty_get_maxresultssize(imp); +} + +/* METHOD */ +void ICalProperty::set_method(enum icalproperty_method val){ + icalproperty_set_method(imp, val); +} +enum icalproperty_method ICalProperty::get_method(){ + return icalproperty_get_method(imp); +} + +/* ORGANIZER */ +void ICalProperty::set_organizer(string val){ + icalproperty_set_organizer(imp, val); +} +string ICalProperty::get_organizer(){ + return (string)icalproperty_get_organizer(imp); +} + +/* OWNER */ +void ICalProperty::set_owner(string val){ + icalproperty_set_owner(imp, val); +} +string ICalProperty::get_owner(){ + return (string)icalproperty_get_owner(imp); +} + +/* PERCENT-COMPLETE */ +void ICalProperty::set_percentcomplete(int val){ + icalproperty_set_percentcomplete(imp, val); +} +int ICalProperty::get_percentcomplete(){ + return icalproperty_get_percentcomplete(imp); +} + +/* PRIORITY */ +void ICalProperty::set_priority(int val){ + icalproperty_set_priority(imp, val); +} +int ICalProperty::get_priority(){ + return icalproperty_get_priority(imp); +} + +/* PRODID */ +void ICalProperty::set_prodid(string val){ + icalproperty_set_prodid(imp, val); +} +string ICalProperty::get_prodid(){ + return (string)icalproperty_get_prodid(imp); +} + +/* QUERY */ +void ICalProperty::set_query(string val){ + icalproperty_set_query(imp, val); +} +string ICalProperty::get_query(){ + return (string)icalproperty_get_query(imp); +} + +/* QUERYNAME */ +void ICalProperty::set_queryname(string val){ + icalproperty_set_queryname(imp, val); +} +string ICalProperty::get_queryname(){ + return (string)icalproperty_get_queryname(imp); +} + +/* RDATE */ +void ICalProperty::set_rdate(struct icaldatetimeperiodtype val){ + icalproperty_set_rdate(imp, val); +} +struct icaldatetimeperiodtype ICalProperty::get_rdate(){ + return icalproperty_get_rdate(imp); +} + +/* RECURRENCE-ID */ +void ICalProperty::set_recurrenceid(struct icaltimetype val){ + icalproperty_set_recurrenceid(imp, val); +} +struct icaltimetype ICalProperty::get_recurrenceid(){ + return icalproperty_get_recurrenceid(imp); +} + +/* RELATED-TO */ +void ICalProperty::set_relatedto(string val){ + icalproperty_set_relatedto(imp, val); +} +string ICalProperty::get_relatedto(){ + return (string)icalproperty_get_relatedto(imp); +} + +/* RELCALID */ +void ICalProperty::set_relcalid(string val){ + icalproperty_set_relcalid(imp, val); +} +string ICalProperty::get_relcalid(){ + return (string)icalproperty_get_relcalid(imp); +} + +/* REPEAT */ +void ICalProperty::set_repeat(int val){ + icalproperty_set_repeat(imp, val); +} +int ICalProperty::get_repeat(){ + return icalproperty_get_repeat(imp); +} + +/* REQUEST-STATUS */ +void ICalProperty::set_requeststatus(string val){ + icalreqstattype v; + + v = icalreqstattype_from_string((char*)val); + + icalproperty_set_requeststatus(imp, v); +} + +string ICalProperty::get_requeststatus(){ + icalreqstattype v; + v = icalproperty_get_requeststatus(imp); + return (string)(icalreqstattype_as_string(v)); +} + +/* RESOURCES */ +void ICalProperty::set_resources(string val){ + icalproperty_set_resources(imp, val); +} +string ICalProperty::get_resources(){ + return (string)icalproperty_get_resources(imp); +} + +/* RRULE */ +void ICalProperty::set_rrule(struct icalrecurrencetype val){ + icalproperty_set_rrule(imp, val); +} +struct icalrecurrencetype ICalProperty::get_rrule(){ + return icalproperty_get_rrule(imp); +} + +/* SCOPE */ +void ICalProperty::set_scope(string val){ + icalproperty_set_scope(imp, val); +} +string ICalProperty::get_scope(){ + return (string)icalproperty_get_scope(imp); +} + +/* SEQUENCE */ +void ICalProperty::set_sequence(int val){ + icalproperty_set_sequence(imp, val); +} +int ICalProperty::get_sequence(){ + return icalproperty_get_sequence(imp); +} + +/* STATUS */ +void ICalProperty::set_status(enum icalproperty_status val){ + icalproperty_set_status(imp, val); +} +enum icalproperty_status ICalProperty::get_status(){ + return icalproperty_get_status(imp); +} + +/* SUMMARY */ +void ICalProperty::set_summary(string val){ + icalproperty_set_summary(imp, val); +} +string ICalProperty::get_summary(){ + return (string)icalproperty_get_summary(imp); +} + +/* TARGET */ +void ICalProperty::set_target(string val){ + icalproperty_set_target(imp, val); +} +string ICalProperty::get_target(){ + return (string)icalproperty_get_target(imp); +} + +/* TRANSP */ +void ICalProperty::set_transp(enum icalproperty_transp val){ + icalproperty_set_transp(imp, val); +} +enum icalproperty_transp ICalProperty::get_transp(){ + return icalproperty_get_transp(imp); +} + +/* TRIGGER */ +void ICalProperty::set_trigger(struct icaltriggertype val){ + icalproperty_set_trigger(imp, val); +} +struct icaltriggertype ICalProperty::get_trigger(){ + return icalproperty_get_trigger(imp); +} + +/* TZID */ +void ICalProperty::set_tzid(string val){ + icalproperty_set_tzid(imp, val); +} +string ICalProperty::get_tzid(){ + return (string)icalproperty_get_tzid(imp); +} + +/* TZNAME */ +void ICalProperty::set_tzname(string val){ + icalproperty_set_tzname(imp, val); +} +string ICalProperty::get_tzname(){ + return (string)icalproperty_get_tzname(imp); +} + +/* TZOFFSETFROM */ +void ICalProperty::set_tzoffsetfrom(int val){ + icalproperty_set_tzoffsetfrom(imp, val); +} +int ICalProperty::get_tzoffsetfrom(){ + return icalproperty_get_tzoffsetfrom(imp); +} + +/* TZOFFSETTO */ +void ICalProperty::set_tzoffsetto(int val){ + icalproperty_set_tzoffsetto(imp, val); +} +int ICalProperty::get_tzoffsetto(){ + return icalproperty_get_tzoffsetto(imp); +} + +/* TZURL */ +void ICalProperty::set_tzurl(string val){ + icalproperty_set_tzurl(imp, val); +} +string ICalProperty::get_tzurl(){ + return (string)icalproperty_get_tzurl(imp); +} + +/* UID */ +void ICalProperty::set_uid(string val){ + icalproperty_set_uid(imp, val); +} +string ICalProperty::get_uid(){ + return (string)icalproperty_get_uid(imp); +} + +/* URL */ +void ICalProperty::set_url(string val){ + icalproperty_set_url(imp, val); +} +string ICalProperty::get_url(){ + return (string)icalproperty_get_url(imp); +} + +/* VERSION */ +void ICalProperty::set_version(string val){ + icalproperty_set_version(imp, val); +} +string ICalProperty::get_version(){ + return (string)icalproperty_get_version(imp); +} + +/* X */ +void ICalProperty::set_x(string val){ + icalproperty_set_x(imp, val); +} +string ICalProperty::get_x(){ + return (string)icalproperty_get_x(imp); +} + +/* X-LIC-CLUSTERCOUNT */ +void ICalProperty::set_xlicclustercount(string val){ + icalproperty_set_xlicclustercount(imp, val); +} +string ICalProperty::get_xlicclustercount(){ + return (string)icalproperty_get_xlicclustercount(imp); +} + +/* X-LIC-ERROR */ +void ICalProperty::set_xlicerror(string val){ + icalproperty_set_xlicerror(imp, val); +} +string ICalProperty::get_xlicerror(){ + return (string)icalproperty_get_xlicerror(imp); +} + +/* X-LIC-MIMECHARSET */ +void ICalProperty::set_xlicmimecharset(string val){ + icalproperty_set_xlicmimecharset(imp, val); +} +string ICalProperty::get_xlicmimecharset(){ + return (string)icalproperty_get_xlicmimecharset(imp); +} + +/* X-LIC-MIMECID */ +void ICalProperty::set_xlicmimecid(string val){ + icalproperty_set_xlicmimecid(imp, val); +} +string ICalProperty::get_xlicmimecid(){ + return (string)icalproperty_get_xlicmimecid(imp); +} + +/* X-LIC-MIMECONTENTTYPE */ +void ICalProperty::set_xlicmimecontenttype(string val){ + icalproperty_set_xlicmimecontenttype(imp, val); +} +string ICalProperty::get_xlicmimecontenttype(){ + return (string)icalproperty_get_xlicmimecontenttype(imp); +} + +/* X-LIC-MIMEENCODING */ +void ICalProperty::set_xlicmimeencoding(string val){ + icalproperty_set_xlicmimeencoding(imp, val); +} +string ICalProperty::get_xlicmimeencoding(){ + return (string)icalproperty_get_xlicmimeencoding(imp); +} + +/* X-LIC-MIMEFILENAME */ +void ICalProperty::set_xlicmimefilename(string val){ + icalproperty_set_xlicmimefilename(imp, val); +} +string ICalProperty::get_xlicmimefilename(){ + return (string)icalproperty_get_xlicmimefilename(imp); +} + +/* X-LIC-MIMEOPTINFO */ +void ICalProperty::set_xlicmimeoptinfo(string val){ + icalproperty_set_xlicmimeoptinfo(imp, val); +} +string ICalProperty::get_xlicmimeoptinfo(){ + return (string)icalproperty_get_xlicmimeoptinfo(imp); +} diff --git a/libical/src/libical/icalproperty_cxx.h b/libical/src/libical/icalproperty_cxx.h new file mode 100644 index 0000000000..27b0fd1a65 --- /dev/null +++ b/libical/src/libical/icalproperty_cxx.h @@ -0,0 +1,365 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icalproperty_cxx.h + * @author fnguyen (12/10/01) + * @brief Definition of C++ Wrapper for icalproperty.c + * + * (C) COPYRIGHT 2001, Critical Path + */ + +#ifndef ICALPROPERTY_CXX_H +#define ICALPROPERTY_CXX_H + +#include "ical.h" +#include "icptrholder.h" + +typedef char* string; // Will use the string library from STL + +class ICalParameter; +class ICalValue; + +class ICalProperty { +public: + ICalProperty(); + ICalProperty(const ICalProperty&) throw(icalerrorenum); + ICalProperty& operator=(const ICalProperty&) throw(icalerrorenum); + ~ICalProperty(); + + ICalProperty(icalproperty* v); + ICalProperty(string str); + ICalProperty(icalproperty_kind kind); + ICalProperty(icalproperty_kind kind, string str); + + operator icalproperty*() {return imp;} + int operator==(ICalProperty& rhs); + + void detach() { + imp = NULL; + } + +public: + string as_ical_string(); + icalproperty_kind isa(); + int isa_property(void* property); + + void add_parameter(ICalParameter& parameter); + void set_parameter(ICalParameter& parameter); + void set_parameter_from_string(string name, string val); + string get_parameter_as_string(string name); + void remove_parameter(icalparameter_kind kind); + int count_parameters(); + + /** Iterate through the parameters */ + ICalParameter* get_first_parameter(icalparameter_kind kind); + ICalParameter* get_next_parameter(icalparameter_kind kind); + + /** Access the value of the property */ + void set_value(const ICalValue& val); + void set_value_from_string(string val, string kind); + + ICalValue* get_value(); + string get_value_as_string(); + + /** Return the name of the property -- the type name converted + * to a string, or the value of get_x_name if the type is X + * property + */ + string get_name(); + +public: + /* Deal with X properties */ + static void set_x_name(ICalProperty &prop, string name); + static string get_x_name(ICalProperty &prop); + + static icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value val); + + /* Convert kinds to string and get default value type */ + static icalvalue_kind kind_to_value_kind(icalproperty_kind kind); + static icalproperty_kind value_kind_to_kind(icalvalue_kind kind); + static string kind_to_string(icalproperty_kind kind); + static icalproperty_kind string_to_kind(string str); + + static icalproperty_method string_to_method(string str); + static string method_to_string(icalproperty_method method); + + static string enum_to_string(int e); + static int string_to_enum(string str); + + static string status_to_string(icalproperty_status); + static icalproperty_status string_to_status(string str); + + static int enum_belongs_to_property(icalproperty_kind kind, int e); + +public: + /* ACTION */ + void set_action(enum icalproperty_action v); + enum icalproperty_action get_action(); + + /* ATTACH */ + void set_attach(icalattach *v); + icalattach *get_attach(); + + /* ATTENDEE */ + void set_attendee(string val); + string get_attendee(); + + /* CALSCALE */ + void set_calscale(string val); + string get_calscale(); + + /* CATEGORIES */ + void set_categories(string val); + string get_categories(); + + /* CLASS */ + void set_class(enum icalproperty_class val); + enum icalproperty_class get_class(); + + /* COMMENT */ + void set_comment(string val); + string get_comment(); + + /* COMPLETED */ + void set_completed(struct icaltimetype val); + struct icaltimetype get_completed(); + + /* CONTACT */ + void set_contact(string val); + string get_contact(); + + /* CREATED */ + void set_created(struct icaltimetype val); + struct icaltimetype get_created(); + + /* DESCRIPTION */ + void set_description(string val); + string get_description(); + + /* DTEND */ + void set_dtend(struct icaltimetype val); + struct icaltimetype get_dtend(); + + /* DTSTAMP */ + void set_dtstamp(struct icaltimetype val); + struct icaltimetype get_dtstamp(); + + /* DTSTART */ + void set_dtstart(struct icaltimetype val); + struct icaltimetype get_dtstart(); + + /* DUE */ + void set_due(struct icaltimetype val); + struct icaltimetype get_due(); + + /* DURATION */ + void set_duration(struct icaldurationtype val); + struct icaldurationtype get_duration(); + + /* EXDATE */ + void set_exdate(struct icaltimetype val); + struct icaltimetype get_exdate(); + + /* EXPAND */ + void set_expand(int val); + int get_expand(); + + /* EXRULE */ + void set_exrule(struct icalrecurrencetype val); + struct icalrecurrencetype get_exrule(); + + /* FREEBUSY */ + void set_freebusy(struct icalperiodtype val); + struct icalperiodtype get_freebusy(); + + /* GEO */ + void set_geo(struct icalgeotype val); + struct icalgeotype get_geo(); + + /* GRANT */ + void set_grant(string val); + string get_grant(); + + /* LAST-MODIFIED */ + void set_lastmodified(struct icaltimetype val); + struct icaltimetype get_lastmodified(); + + /* LOCATION */ + void set_location(string val); + string get_location(); + + /* MAXRESULTS */ + void set_maxresults(int val); + int get_maxresults(); + + /* MAXRESULTSSIZE */ + void set_maxresultsize(int val); + int get_maxresultsize(); + + /* METHOD */ + void set_method(enum icalproperty_method val); + enum icalproperty_method get_method(); + + /* OWNER */ + void set_owner(string val); + string get_owner(); + + /* ORGANIZER */ + void set_organizer(string val); + string get_organizer(); + + /* PERCENT-COMPLETE */ + void set_percentcomplete(int val); + int get_percentcomplete(); + + /* PRIORITY */ + void set_priority(int val); + int get_priority(); + + /* PRODID */ + void set_prodid(string val); + string get_prodid(); + + /* QUERY */ + void set_query(string val); + string get_query(); + + /* QUERYNAME */ + void set_queryname(string val); + string get_queryname(); + + /* RDATE */ + void set_rdate(struct icaldatetimeperiodtype val); + struct icaldatetimeperiodtype get_rdate(); + + /* RECURRENCE-ID */ + void set_recurrenceid(struct icaltimetype val); + struct icaltimetype get_recurrenceid(); + + /* RELATED-TO */ + void set_relatedto(string val); + string get_relatedto(); + + /* RELCALID */ + void set_relcalid(string val); + string get_relcalid(); + + /* REPEAT */ + void set_repeat(int val); + int get_repeat(); + + /* REQUEST-STATUS */ + void set_requeststatus(string val); + string get_requeststatus(); + + /* RESOURCES */ + void set_resources(string val); + string get_resources(); + + /* RRULE */ + void set_rrule(struct icalrecurrencetype val); + struct icalrecurrencetype get_rrule(); + + /* SCOPE */ + void set_scope(string val); + string get_scope(); + + /* SEQUENCE */ + void set_sequence(int val); + int get_sequence(); + + /* STATUS */ + void set_status(enum icalproperty_status val); + enum icalproperty_status get_status(); + + /* SUMMARY */ + void set_summary(string val); + string get_summary(); + + /* TARGET */ + void set_target(string val); + string get_target(); + + /* TRANSP */ + void set_transp(enum icalproperty_transp val); + enum icalproperty_transp get_transp(); + + /* TRIGGER */ + void set_trigger(struct icaltriggertype val); + struct icaltriggertype get_trigger(); + + /* TZID */ + void set_tzid(string val); + string get_tzid(); + + /* TZNAME */ + void set_tzname(string val); + string get_tzname(); + + /* TZOFFSETFROM */ + void set_tzoffsetfrom(int val); + int get_tzoffsetfrom(); + + /* TZOFFSETTO */ + void set_tzoffsetto(int val); + int get_tzoffsetto(); + + /* TZURL */ + void set_tzurl(string val); + string get_tzurl(); + + /* UID */ + void set_uid(string val); + string get_uid(); + + /* URL */ + void set_url(string val); + string get_url(); + + /* VERSION */ + void set_version(string val); + string get_version(); + + /* X */ + void set_x(string val); + string get_x(); + + /* X-LIC-CLUSTERCOUNT */ + void set_xlicclustercount(string val); + string get_xlicclustercount(); + + /* X-LIC-ERROR */ + void set_xlicerror(string val); + string get_xlicerror(); + + /* X-LIC-MIMECHARSET */ + void set_xlicmimecharset(string val); + string get_xlicmimecharset(); + + /* X-LIC-MIMECID */ + void set_xlicmimecid(string val); + string get_xlicmimecid(); + + /* X-LIC-MIMECONTENTTYPE */ + void set_xlicmimecontenttype(string val); + string get_xlicmimecontenttype(); + + /* X-LIC-MIMEENCODING */ + void set_xlicmimeencoding(string val); + string get_xlicmimeencoding(); + + /* X-LIC-MIMEFILENAME */ + void set_xlicmimefilename(string val); + string get_xlicmimefilename(); + + /* X-LIC-MIMEOPTINFO */ + void set_xlicmimeoptinfo(string val); + string get_xlicmimeoptinfo(); + +private: + icalproperty* imp; /**< The actual C based icalproperty */ +}; + +typedef ICPointerHolder<ICalProperty> ICalPropertyTmpPtr; /* see icptrholder.h for comments */ + +#endif /* ICalProperty_H */ diff --git a/libical/src/libical/icalrecur.c b/libical/src/libical/icalrecur.c index b12dbabca2..5c687fc6f3 100644 --- a/libical/src/libical/icalrecur.c +++ b/libical/src/libical/icalrecur.c @@ -19,7 +19,11 @@ The Mozilla Public License Version 1.0. You may obtain a copy of the License at http://www.mozilla.org/MPL/ +*/ +/** + @file icalrecur.c + @brief Implementation of routines for dealing with recurring time How this code works: @@ -130,15 +134,20 @@ #include "config.h" #endif +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif + +#ifndef HAVE_INTPTR_T +#ifdef WIN32 +typedef long intptr_t; +#endif +#endif + #include "icalrecur.h" -#ifdef ICAL_NO_LIBICAL -#define icalerror_set_errno(x) -#define icalerror_check_arg_rv(x,y) -#else #include "icalerror.h" #include "icalmemory.h" -#endif #include <stdlib.h> /* for malloc */ #include <errno.h> /* for errno */ @@ -148,8 +157,8 @@ #include "pvl.h" -/* This is the last year we will go up to, since 32-bit time_t values only - go up to the start of 2038. */ +/** This is the last year we will go up to, since 32-bit time_t values + only go up to the start of 2038. */ #define MAX_TIME_T_YEAR 2037 #define TEMP_MAX 1024 @@ -174,7 +183,6 @@ const char* icalrecur_weekday_to_string(icalrecurrencetype_weekday kind); icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str); - /*********************** Rule parsing routines ************************/ struct icalrecur_parser { @@ -257,7 +265,7 @@ void icalrecur_add_byrules(struct icalrecur_parser *parser, short *array, char *t, *n; int i=0; int sign = 1; - short v; + int v; n = vals; @@ -291,13 +299,45 @@ void icalrecur_add_byrules(struct icalrecur_parser *parser, short *array, v = atoi(t) * sign ; - array[i++] = v; + array[i++] = (short)v; array[i] = ICAL_RECURRENCE_ARRAY_MAX; } } +/* + * Days in the BYDAY rule are expected by the code to be sorted, and while + * this may be the common case, the RFC doesn't actually mandate it. This + * function sorts the days taking into account the first day of week. + */ +static void +sort_bydayrules(struct icalrecur_parser *parser) +{ + short *array; + int week_start, one, two, i, j; + + array = parser->rt.by_day; + week_start = parser->rt.week_start; + + for (i=0; + i<ICAL_BY_DAY_SIZE && array[i] != ICAL_RECURRENCE_ARRAY_MAX; + i++) { + for (j=0; j<i; j++) { + one = icalrecurrencetype_day_day_of_week(array[j]) - week_start; + if (one < 0) one += 7; + two = icalrecurrencetype_day_day_of_week(array[i]) - week_start; + if (two < 0) two += 7; + + if (one > two) { + short tmp = array[j]; + array[j] = array[i]; + array[i] = tmp; + } + } + } +} + void icalrecur_add_bydayrules(struct icalrecur_parser *parser, const char* vals) { @@ -349,13 +389,14 @@ void icalrecur_add_bydayrules(struct icalrecur_parser *parser, const char* vals) wd = icalrecur_string_to_weekday(t); - array[i++] = sign* ((int)wd + 8*weekno); + array[i++] = (short)(sign* (wd + 8*weekno)); array[i] = ICAL_RECURRENCE_ARRAY_MAX; } free(vals_copy); + sort_bydayrules(parser); } @@ -390,6 +431,7 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str) if(name == 0){ icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); icalrecurrencetype_clear(&parser.rt); + free(parser.copy); return parser.rt; } @@ -400,9 +442,10 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str) } else if (strcmp(name,"UNTIL") == 0){ parser.rt.until = icaltime_from_string(value); } else if (strcmp(name,"INTERVAL") == 0){ - parser.rt.interval = atoi(value); + parser.rt.interval = (short)atoi(value); } else if (strcmp(name,"WKST") == 0){ parser.rt.week_start = icalrecur_string_to_weekday(value); + sort_bydayrules(&parser); } else if (strcmp(name,"BYSECOND") == 0){ icalrecur_add_byrules(&parser,parser.rt.by_second, ICAL_BY_SECOND_SIZE,value); @@ -432,6 +475,7 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str) } else { icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); icalrecurrencetype_clear(&parser.rt); + free(parser.copy); return parser.rt; } @@ -443,9 +487,7 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str) } -#ifndef ICAL_NO_LIBICAL - -struct { char* str;size_t offset; short limit; } recurmap[] = +static struct { char* str;size_t offset; int limit; } recurmap[] = { {";BYSECOND=",offsetof(struct icalrecurrencetype,by_second),60}, {";BYMINUTE=",offsetof(struct icalrecurrencetype,by_minute),60}, @@ -508,7 +550,7 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur) for(j =0; recurmap[j].str != 0; j++){ short* array = (short*)(recurmap[j].offset+ (size_t)recur); - short limit = recurmap[j].limit; + int limit = recurmap[j].limit; /* Skip unused arrays */ if( array[0] != ICAL_RECURRENCE_ARRAY_MAX ) { @@ -519,9 +561,9 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur) i< limit && array[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){ if (j == 3) { /* BYDAY */ - short dow = icalrecurrencetype_day_day_of_week(array[i]); - const char *daystr = icalrecur_weekday_to_string(dow); - short pos; + const char *daystr = icalrecur_weekday_to_string( + icalrecurrencetype_day_day_of_week(array[i])); + int pos; pos = icalrecurrencetype_day_position(array[i]); @@ -545,10 +587,15 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur) } } + /* If week start is not monday (the default per RFC2445) append WKST */ + if (recur->week_start != ICAL_MONDAY_WEEKDAY) { + sprintf(temp,"%s", icalrecur_weekday_to_string(recur->week_start)); + icalmemory_append_string(&str,&str_p,&buf_sz,";WKST="); + icalmemory_append_string(&str,&str_p,&buf_sz, temp); + } + return str; } -#endif - /************************* occurrence iteration routiens ******************/ @@ -580,13 +627,15 @@ struct icalrecur_iterator_impl { enum byrule byrule; short by_indices[9]; - short orig_data[9]; /* 1 if there was data in the byrule */ + short orig_data[9]; /**< 1 if there was data in the byrule */ - short *by_ptrs[9]; /* Pointers into the by_* array elements of the rule */ + short *by_ptrs[9]; /**< Pointers into the by_* array elements of the rule */ }; +static void increment_year(icalrecur_iterator* impl, int inc); + int icalrecur_iterator_sizeof_byarray(short* byarray) { int array_itr; @@ -606,10 +655,13 @@ enum expand_table { ILLEGAL=3 }; -/* The split map indicates, for a particular interval, wether a BY_* - rule part expands the number of instances in the occcurrence set or - contracts it. 1=> contract, 2=>expand, and 3 means the pairing is - not allowed. */ +/** + * The split map indicates, for a particular interval, wether a BY_* + * rule part expands the number of instances in the occcurrence set or + * contracts it. 1=> contract, 2=>expand, and 3 means the pairing is + * not allowed. + */ + struct expand_split_map_struct { icalrecurrencetype_frequency frequency; @@ -620,7 +672,7 @@ struct expand_split_map_struct short map[8]; }; -struct expand_split_map_struct expand_map[] = +static struct expand_split_map_struct expand_map[] = { {ICAL_SECONDLY_RECURRENCE,{1,1,1,1,1,1,1,1}}, {ICAL_MINUTELY_RECURRENCE,{2,1,1,1,1,1,1,1}}, @@ -635,15 +687,16 @@ struct expand_split_map_struct expand_map[] = -/* Check that the rule has only the two given interday byrule parts. */ -int icalrecur_two_byrule(struct icalrecur_iterator_impl* impl, +/** Check that the rule has only the two given interday byrule parts. */ +static +int icalrecur_two_byrule(icalrecur_iterator* impl, enum byrule one,enum byrule two) { short test_array[9]; enum byrule itr; int passes = 0; - memset(test_array,0,sizeof (test_array)); + memset(test_array,0,sizeof(test_array)); test_array[one] = 1; test_array[two] = 1; @@ -666,8 +719,8 @@ int icalrecur_two_byrule(struct icalrecur_iterator_impl* impl, } -/* Check that the rule has only the one given interdat byrule parts. */ -int icalrecur_one_byrule(struct icalrecur_iterator_impl* impl,enum byrule one) +/** Check that the rule has only the one given interdat byrule parts. */ +static int icalrecur_one_byrule(icalrecur_iterator* impl,enum byrule one) { int passes = 1; enum byrule itr; @@ -683,7 +736,7 @@ int icalrecur_one_byrule(struct icalrecur_iterator_impl* impl,enum byrule one) return passes; } -int count_byrules(struct icalrecur_iterator_impl* impl) +static int count_byrules(icalrecur_iterator* impl) { int count = 0; enum byrule itr; @@ -698,9 +751,9 @@ int count_byrules(struct icalrecur_iterator_impl* impl) } -void setup_defaults(struct icalrecur_iterator_impl* impl, +static void setup_defaults(icalrecur_iterator* impl, enum byrule byrule, icalrecurrencetype_frequency req, - short deftime, int *timepart) + int deftime, int *timepart) { icalrecurrencetype_frequency freq; @@ -711,7 +764,7 @@ void setup_defaults(struct icalrecur_iterator_impl* impl, if(impl->by_ptrs[byrule][0] == ICAL_RECURRENCE_ARRAY_MAX && expand_map[freq].map[byrule] != CONTRACT){ - impl->by_ptrs[byrule][0] = deftime; + impl->by_ptrs[byrule][0] = (short)deftime; } /* Initialize the first occurence */ @@ -722,35 +775,28 @@ void setup_defaults(struct icalrecur_iterator_impl* impl, } -int has_by_data(struct icalrecur_iterator_impl* impl, enum byrule byrule){ +static int has_by_data(icalrecur_iterator* impl, enum byrule byrule){ return (impl->orig_data[byrule] == 1); } -void increment_year(struct icalrecur_iterator_impl* impl, int inc) -{ - impl->last.year+=inc; -} - -int expand_year_days(struct icalrecur_iterator_impl* impl,short year); +static int expand_year_days(icalrecur_iterator* impl, int year); icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, struct icaltimetype dtstart) { - struct icalrecur_iterator_impl* impl; + icalrecur_iterator* impl; icalrecurrencetype_frequency freq; - short days_in_month; - - if ( ( impl = (struct icalrecur_iterator_impl *) - malloc(sizeof(struct icalrecur_iterator_impl))) == 0) { + if ( ( impl = (icalrecur_iterator*) + malloc(sizeof(icalrecur_iterator))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } - memset(impl,0,sizeof(struct icalrecur_iterator_impl)); + memset(impl,0,sizeof(icalrecur_iterator)); impl->rule = rule; impl->last = dtstart; @@ -772,7 +818,7 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, impl->by_ptrs[BY_SECOND]=impl->rule.by_second; impl->by_ptrs[BY_SET_POS]=impl->rule.by_set_pos; - memset(impl->orig_data,0,9); + memset(impl->orig_data,0,9*sizeof(short)); /* Note which by rules had data in them when the iterator was created. We can't use the actuall by_x arrays, because the @@ -780,23 +826,23 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, routine. The orig_data array will be used later in has_by_data */ impl->orig_data[BY_MONTH] - = (impl->rule.by_month[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_month[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_WEEK_NO] - =(impl->rule.by_week_no[0]!=ICAL_RECURRENCE_ARRAY_MAX); + =(short)(impl->rule.by_week_no[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_YEAR_DAY] - =(impl->rule.by_year_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); + =(short)(impl->rule.by_year_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_MONTH_DAY] - =(impl->rule.by_month_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); + =(short)(impl->rule.by_month_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_DAY] - = (impl->rule.by_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_day[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_HOUR] - = (impl->rule.by_hour[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_hour[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_MINUTE] - = (impl->rule.by_minute[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_minute[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_SECOND] - = (impl->rule.by_second[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_second[0]!=ICAL_RECURRENCE_ARRAY_MAX); impl->orig_data[BY_SET_POS] - = (impl->rule.by_set_pos[0]!=ICAL_RECURRENCE_ARRAY_MAX); + = (short)(impl->rule.by_set_pos[0]!=ICAL_RECURRENCE_ARRAY_MAX); /* Check if the recurrence rule is legal */ @@ -864,19 +910,24 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, BY_* array is empty */ - setup_defaults(impl,BY_SECOND,ICAL_SECONDLY_RECURRENCE,impl->dtstart.second, + setup_defaults(impl,BY_SECOND,ICAL_SECONDLY_RECURRENCE, + impl->dtstart.second, &(impl->last.second)); - setup_defaults(impl,BY_MINUTE,ICAL_MINUTELY_RECURRENCE,impl->dtstart.minute, + setup_defaults(impl,BY_MINUTE,ICAL_MINUTELY_RECURRENCE, + impl->dtstart.minute, &(impl->last.minute)); - setup_defaults(impl,BY_HOUR,ICAL_HOURLY_RECURRENCE,impl->dtstart.hour, + setup_defaults(impl,BY_HOUR,ICAL_HOURLY_RECURRENCE, + impl->dtstart.hour, &(impl->last.hour)); - setup_defaults(impl,BY_MONTH_DAY,ICAL_DAILY_RECURRENCE,impl->dtstart.day, + setup_defaults(impl,BY_MONTH_DAY,ICAL_DAILY_RECURRENCE, + impl->dtstart.day, &(impl->last.day)); - setup_defaults(impl,BY_MONTH,ICAL_MONTHLY_RECURRENCE,impl->dtstart.month, + setup_defaults(impl,BY_MONTH,ICAL_MONTHLY_RECURRENCE, + impl->dtstart.month, &(impl->last.month)); @@ -886,7 +937,7 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, /* Weekly recurrences with no BY_DAY data should occur on the same day of the week as the start time . */ - impl->by_ptrs[BY_DAY][0] = icaltime_day_of_week(impl->dtstart); + impl->by_ptrs[BY_DAY][0] = (short)icaltime_day_of_week(impl->dtstart); } else { /* If there is BY_DAY data, then we need to move the initial @@ -896,32 +947,29 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, monday. Otherwise, jumping to the next week ( jumping 7 days ahead ) will skip over some occurrences in the second week. */ - - /* This is probably a HACK. There should be some more - general way to solve this problem */ - - short dow = impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last); - if(dow < 0) { - /* initial time is after first day of BY_DAY data */ - - impl->last.day += dow; - impl->last = icaltime_normalize(impl->last); - } + /* This depends on impl->by_ptrs[BY_DAY] being correctly sorted by + * day. This should probably be abstracted to make such assumption + * more explicit. */ + short dow = (short)(impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last)); + if (dow > impl->rule.week_start-1) dow -= 7; + impl->last.day += dow; + impl->last = icaltime_normalize(impl->last); } } - /* For YEARLY rule, begin by setting up the year days array */ + /* For YEARLY rule, begin by setting up the year days array . The + YEARLY rules work by expanding one year at a time. */ if(impl->rule.freq == ICAL_YEARLY_RECURRENCE){ struct icaltimetype next; for (;;) { - expand_year_days(impl,impl->last.year); + expand_year_days(impl, impl->last.year); if (impl->days[0] != ICAL_RECURRENCE_ARRAY_MAX) - break; + break; /* break when no days are expanded */ increment_year(impl,impl->rule.interval); } @@ -936,16 +984,16 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, /* If this is a monthly interval with by day data, then we need to set the last value to the appropriate day of the month */ - if(impl->rule.freq == ICAL_MONTHLY_RECURRENCE && - has_by_data(impl,BY_DAY)) { + if(impl->rule.freq == ICAL_MONTHLY_RECURRENCE) + if (has_by_data(impl,BY_DAY)) { - short dow = icalrecurrencetype_day_day_of_week( + int dow = icalrecurrencetype_day_day_of_week( impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]); - short pos = icalrecurrencetype_day_position( + int pos = icalrecurrencetype_day_position( impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]); - short poscount = 0; - days_in_month = + int poscount = 0; + int days_in_month = icaltime_days_in_month(impl->last.month, impl->last.year); if(pos >= 0){ @@ -984,6 +1032,8 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, return 0; } + } else if (has_by_data(impl,BY_MONTH_DAY)) { + impl->last = icaltime_normalize(impl->last); } @@ -994,21 +1044,21 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, void icalrecur_iterator_free(icalrecur_iterator* i) { + icalerror_check_arg_rv((i!=0),"impl"); - struct icalrecur_iterator_impl* impl = - (struct icalrecur_iterator_impl*)i; - - icalerror_check_arg_rv((impl!=0),"impl"); - - free(impl); + free(i); } +static void increment_year(icalrecur_iterator* impl, int inc) +{ + impl->last.year+=inc; +} -/* Increment month is different that the other incement_* routines -- +/** Increment month is different that the other incement_* routines -- it figures out the interval for itself, and uses BYMONTH data if available. */ -void increment_month(struct icalrecur_iterator_impl* impl) +static void increment_month(icalrecur_iterator* impl) { int years; @@ -1055,14 +1105,14 @@ void increment_month(struct icalrecur_iterator_impl* impl) } } -void increment_monthday(struct icalrecur_iterator_impl* impl, int inc) +static void increment_monthday(icalrecur_iterator* impl, int inc) { int i; for(i=0; i<inc; i++){ - short days_in_month = - icaltime_days_in_month(impl->last.month,impl->last.year); + int days_in_month = + icaltime_days_in_month(impl->last.month, impl->last.year); impl->last.day++; @@ -1074,9 +1124,9 @@ void increment_monthday(struct icalrecur_iterator_impl* impl, int inc) } -void increment_hour(struct icalrecur_iterator_impl* impl, int inc) +static void increment_hour(icalrecur_iterator* impl, int inc) { - short days; + int days; impl->last.hour+=inc; @@ -1088,9 +1138,9 @@ void increment_hour(struct icalrecur_iterator_impl* impl, int inc) } } -void increment_minute(struct icalrecur_iterator_impl* impl, int inc) +static void increment_minute(icalrecur_iterator* impl, int inc) { - short hours; + int hours; impl->last.minute+=inc; @@ -1103,9 +1153,9 @@ void increment_minute(struct icalrecur_iterator_impl* impl, int inc) } -void increment_second(struct icalrecur_iterator_impl* impl, int inc) +static void increment_second(icalrecur_iterator* impl, int inc) { - short minutes; + int minutes; impl->last.second+=inc; @@ -1122,7 +1172,7 @@ void increment_second(struct icalrecur_iterator_impl* impl, int inc) #include "ical.h" void test_increment() { - struct icalrecur_iterator_impl impl; + icalrecur_iterator impl; impl.last = icaltime_from_string("20000101T000000Z"); @@ -1152,17 +1202,17 @@ void test_increment() #endif -short next_second(struct icalrecur_iterator_impl* impl) +static int next_second(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_SECOND][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short this_frequency = (impl->rule.freq == ICAL_SECONDLY_RECURRENCE); + int has_by_second = (impl->by_ptrs[BY_SECOND][0]!=ICAL_RECURRENCE_ARRAY_MAX); + int this_frequency = (impl->rule.freq == ICAL_SECONDLY_RECURRENCE); - short end_of_data = 0; + int end_of_data = 0; - assert(has_by_data || this_frequency); + assert(has_by_second || this_frequency); - if( has_by_data ){ + if( has_by_second ){ /* Ignore the frequency and use the byrule data */ impl->by_indices[BY_SECOND]++; @@ -1179,7 +1229,7 @@ short next_second(struct icalrecur_iterator_impl* impl) impl->by_ptrs[BY_SECOND][impl->by_indices[BY_SECOND]]; - } else if( !has_by_data && this_frequency ){ + } else if( !has_by_second && this_frequency ){ /* Compute the next value from the last time and the frequency interval*/ increment_second(impl, impl->rule.interval); @@ -1188,7 +1238,7 @@ short next_second(struct icalrecur_iterator_impl* impl) /* If we have gone through all of the seconds on the BY list, then we need to move to the next minute */ - if(has_by_data && end_of_data && this_frequency ){ + if(has_by_second && end_of_data && this_frequency ){ increment_minute(impl,1); } @@ -1196,22 +1246,22 @@ short next_second(struct icalrecur_iterator_impl* impl) } -int next_minute(struct icalrecur_iterator_impl* impl) +static int next_minute(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_MINUTE][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short this_frequency = (impl->rule.freq == ICAL_MINUTELY_RECURRENCE); + int has_by_minute = (impl->by_ptrs[BY_MINUTE][0]!=ICAL_RECURRENCE_ARRAY_MAX); + int this_frequency = (impl->rule.freq == ICAL_MINUTELY_RECURRENCE); - short end_of_data = 0; + int end_of_data = 0; - assert(has_by_data || this_frequency); + assert(has_by_minute || this_frequency); if (next_second(impl) == 0){ return 0; } - if( has_by_data ){ + if( has_by_minute ){ /* Ignore the frequency and use the byrule data */ impl->by_indices[BY_MINUTE]++; @@ -1227,7 +1277,7 @@ int next_minute(struct icalrecur_iterator_impl* impl) impl->last.minute = impl->by_ptrs[BY_MINUTE][impl->by_indices[BY_MINUTE]]; - } else if( !has_by_data && this_frequency ){ + } else if( !has_by_minute && this_frequency ){ /* Compute the next value from the last time and the frequency interval*/ increment_minute(impl,impl->rule.interval); } @@ -1235,28 +1285,28 @@ int next_minute(struct icalrecur_iterator_impl* impl) /* If we have gone through all of the minutes on the BY list, then we need to move to the next hour */ - if(has_by_data && end_of_data && this_frequency ){ + if(has_by_minute && end_of_data && this_frequency ){ increment_hour(impl,1); } return end_of_data; } -int next_hour(struct icalrecur_iterator_impl* impl) +static int next_hour(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_HOUR][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short this_frequency = (impl->rule.freq == ICAL_HOURLY_RECURRENCE); + int has_by_hour = (impl->by_ptrs[BY_HOUR][0]!=ICAL_RECURRENCE_ARRAY_MAX); + int this_frequency = (impl->rule.freq == ICAL_HOURLY_RECURRENCE); - short end_of_data = 0; + int end_of_data = 0; - assert(has_by_data || this_frequency); + assert(has_by_hour || this_frequency); if (next_minute(impl) == 0){ return 0; } - if( has_by_data ){ + if( has_by_hour ){ /* Ignore the frequency and use the byrule data */ impl->by_indices[BY_HOUR]++; @@ -1271,7 +1321,7 @@ int next_hour(struct icalrecur_iterator_impl* impl) impl->last.hour = impl->by_ptrs[BY_HOUR][impl->by_indices[BY_HOUR]]; - } else if( !has_by_data && this_frequency ){ + } else if( !has_by_hour && this_frequency ){ /* Compute the next value from the last time and the frequency interval*/ increment_hour(impl,impl->rule.interval); @@ -1280,7 +1330,7 @@ int next_hour(struct icalrecur_iterator_impl* impl) /* If we have gone through all of the hours on the BY list, then we need to move to the next day */ - if(has_by_data && end_of_data && this_frequency ){ + if(has_by_hour && end_of_data && this_frequency ){ increment_monthday(impl,1); } @@ -1288,13 +1338,13 @@ int next_hour(struct icalrecur_iterator_impl* impl) } -int next_day(struct icalrecur_iterator_impl* impl) +static int next_day(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short this_frequency = (impl->rule.freq == ICAL_DAILY_RECURRENCE); + int has_by_day = (impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX); + int this_frequency = (impl->rule.freq == ICAL_DAILY_RECURRENCE); - assert(has_by_data || this_frequency); + assert(has_by_day || this_frequency); if (next_hour(impl) == 0){ return 0; @@ -1316,14 +1366,14 @@ int next_day(struct icalrecur_iterator_impl* impl) } -int next_yearday(struct icalrecur_iterator_impl* impl) +static int next_yearday(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_YEAR_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX); + int has_by_yearday = (impl->by_ptrs[BY_YEAR_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short end_of_data = 0; + int end_of_data = 0; - assert(has_by_data ); + assert(has_by_yearday ); if (next_hour(impl) == 0){ return 0; @@ -1341,7 +1391,7 @@ int next_yearday(struct icalrecur_iterator_impl* impl) impl->last.day = impl->by_ptrs[BY_YEAR_DAY][impl->by_indices[BY_YEAR_DAY]]; - if(has_by_data && end_of_data){ + if(has_by_yearday && end_of_data){ increment_year(impl,1); } @@ -1349,62 +1399,15 @@ int next_yearday(struct icalrecur_iterator_impl* impl) } -/* This routine is only called by next_week. It is certain that BY_DAY -has data */ - -int next_weekday_by_week(struct icalrecur_iterator_impl* impl) -{ - - short end_of_data = 0; - short start_of_week, dow; - struct icaltimetype next; - - if (next_hour(impl) == 0){ - return 0; - } - - assert( impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX); - - while(1) { - - impl->by_indices[BY_DAY]++; /* Look at next elem in BYDAY array */ - - /* Are we at the end of the BYDAY array? */ - if (impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]] - ==ICAL_RECURRENCE_ARRAY_MAX){ - - impl->by_indices[BY_DAY] = 0; /* Reset to 0 */ - end_of_data = 1; /* Signal that we're at the end */ - } - - /* Add the day of week offset to to the start of this week, and use - that to get the next day */ - dow = impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]; - start_of_week = icaltime_start_doy_of_week(impl->last); - - dow--; /*Sun is 1, not 0 */ - - if(dow+start_of_week <1 && !end_of_data){ - /* The selected date is in the previous year. */ - continue; - } - next = icaltime_from_day_of_year(start_of_week + dow,impl->last.year); - - impl->last.day = next.day; - impl->last.month = next.month; - impl->last.year = next.year; - - return end_of_data; - } - -} +/* Returns the day of the month for the current month of t that is the + pos'th instance of the day-of-week dow */ -int nth_weekday(short dow, short pos, struct icaltimetype t){ +static int nth_weekday(int dow, int pos, struct icaltimetype t){ - short days_in_month = icaltime_days_in_month(t.month,t.year); - short end_dow, start_dow; - short wd; + int days_in_month = icaltime_days_in_month(t.month, t.year); + int end_dow, start_dow; + int wd; if(pos >= 0){ t.day = 1; @@ -1448,12 +1451,29 @@ int nth_weekday(short dow, short pos, struct icaltimetype t){ return wd; } +static int is_day_in_byday(icalrecur_iterator* impl,struct icaltimetype tt){ + + int idx; -int next_month(struct icalrecur_iterator_impl* impl) + for(idx = 0; BYDAYPTR[idx] != ICAL_RECURRENCE_ARRAY_MAX; idx++){ + int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]); + int pos = icalrecurrencetype_day_position(BYDAYPTR[idx]); + int this_dow = icaltime_day_of_week(tt); + + if( (pos == 0 && dow == this_dow ) || /* Just a dow, like "TU" or "FR" */ + (nth_weekday(dow,pos,tt) == tt.day)){ /*pos+wod: "3FR" or -1TU" */ + return 1; + } + } + + return 0; +} + +static int next_month(icalrecur_iterator* impl) { int data_valid = 1; - short this_frequency = (impl->rule.freq == ICAL_MONTHLY_RECURRENCE); + int this_frequency = (impl->rule.freq == ICAL_MONTHLY_RECURRENCE); assert( has_by_data(impl,BY_MONTH) || this_frequency); @@ -1465,14 +1485,17 @@ int next_month(struct icalrecur_iterator_impl* impl) return data_valid; /* Signal that the data is valid */ } - /* Now iterate through the occurrences within a month -- by days, weeks or weekdays. */ + + /* + * Case 1: + * Rules Like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR;BYMONTHDAY=13 + */ if(has_by_data(impl,BY_DAY) && has_by_data(impl,BY_MONTH_DAY)){ - /* Cases like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR;BYMONTHDAY=13 */ - short day, idx,j; - short days_in_month = icaltime_days_in_month(impl->last.month, + int day, idx,j; + int days_in_month = icaltime_days_in_month(impl->last.month, impl->last.year); /* Iterate through the remaining days in the month and check if each day is listed in the BY_DAY array and in the BY_MONTHDAY @@ -1483,11 +1506,11 @@ int next_month(struct icalrecur_iterator_impl* impl) for(day = impl->last.day+1; day <= days_in_month; day++){ for(idx = 0; BYDAYPTR[idx] != ICAL_RECURRENCE_ARRAY_MAX; idx++){ for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){ - short dow = + int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]); - short pos = icalrecurrencetype_day_position(BYDAYPTR[idx]); - short mday = BYMDPTR[j]; - short this_dow; + int pos = icalrecurrencetype_day_position(BYDAYPTR[idx]); + int mday = BYMDPTR[j]; + int this_dow; impl->last.day = day; this_dow = icaltime_day_of_week(impl->last); @@ -1508,51 +1531,57 @@ int next_month(struct icalrecur_iterator_impl* impl) data_valid = 0; /* signal that impl->last is invalid */ } - + + /* + * Case 2: + * Rules Like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR + */ + } else if(has_by_data(impl,BY_DAY)){ - /* Cases like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR */ /* For this case, the weekdays are relative to the month. BYDAY=FR -> First Friday in month, etc. */ - short day, idx; - short days_in_month = icaltime_days_in_month(impl->last.month, - impl->last.year); + /* This code iterates through the remaining days in the month + and checks if each day is listed in the BY_DAY array. This + seems very inneficient, but I think it is the simplest way to + account for both BYDAY=1FR (First friday in month) and + BYDAY=FR ( every friday in month ) */ + int day; + int days_in_month = icaltime_days_in_month(impl->last.month, + impl->last.year); assert( BYDAYPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX); - /* Iterate through the remaining days in the month and check if - each day is listed in the BY_DAY array. This seems very - inneficient, but I think it is the simplest way to account - for both BYDAY=1FR (First friday in month) and BYDAY=FR ( - every friday in month ) */ - for(day = impl->last.day+1; day <= days_in_month; day++){ - for(idx = 0; BYDAYPTR[idx] != ICAL_RECURRENCE_ARRAY_MAX; idx++){ - short dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]); - short pos = icalrecurrencetype_day_position(BYDAYPTR[idx]); - short this_dow; - - impl->last.day = day; - this_dow = icaltime_day_of_week(impl->last); - - if( (pos == 0 && dow == this_dow ) || - (nth_weekday(dow,pos,impl->last) == day)){ - goto DEND; - } + impl->last.day = day; + if(is_day_in_byday(impl,impl->last)){ + data_valid = 1; + break; } } - DEND: - if ( day > days_in_month){ impl->last.day = 1; increment_month(impl); - data_valid = 0; /* signal that impl->last is invalid */ + + /* Did moving to the next month put us on a valid date? if + so, note that the new data is valid, if, not, mark it + invalid */ + + if(is_day_in_byday(impl,impl->last)){ + data_valid = 1; + } else { + data_valid = 0; /* signal that impl->last is invalid */ + } } + /* + * Case 3 + * Rules Like: FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-3 + */ + } else if (has_by_data(impl,BY_MONTH_DAY)) { - /* Cases like: FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-3 */ - short day; + int day, days_in_month; assert( BYMDPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX); @@ -1565,32 +1594,105 @@ int next_month(struct icalrecur_iterator_impl* impl) increment_month(impl); } + days_in_month = icaltime_days_in_month(impl->last.month, + impl->last.year); + day = BYMDPTR[BYMDIDX]; if (day < 0) { - day = icaltime_days_in_month(impl->last.month,impl->last.year)+ - day + 1; + day = icaltime_days_in_month(impl->last.month, impl->last.year) + day + 1; } - + + if ( day > days_in_month){ + impl->last.day = 1; + + /* Did moving to the next month put us on a valid date? if + so, note that the new data is valid, if, not, mark it + invalid */ + + if(is_day_in_byday(impl,impl->last)){ + data_valid = 1; + } else { + data_valid = 0; /* signal that impl->last is invalid */ + } + } + impl->last.day = day; } else { + int days_in_month; + increment_month(impl); + + days_in_month = icaltime_days_in_month(impl->last.month, + impl->last.year); + if (impl->last.day > days_in_month){ + data_valid = 0; /* signal that impl->last is invalid */ + } } - return data_valid; /* Signal that the data is valid */ + return data_valid; } - -int next_week(struct icalrecur_iterator_impl* impl) +static int next_weekday_by_week(icalrecur_iterator* impl) { - short has_by_data = (impl->by_ptrs[BY_WEEK_NO][0]!=ICAL_RECURRENCE_ARRAY_MAX); - short this_frequency = (impl->rule.freq == ICAL_WEEKLY_RECURRENCE); - short end_of_data = 0; + int end_of_data = 0; + int start_of_week, dow; + struct icaltimetype next; + + if (next_hour(impl) == 0){ + return 0; + } - /* Increment to the next week day */ + if(!has_by_data(impl,BY_DAY)){ + return 1; + } + + /* If we get here, we need to step to tne next day */ + + for (;;) { + BYDAYIDX++; /* Look at next elem in BYDAY array */ + + /* Are we at the end of the BYDAY array? */ + if (BYDAYPTR[BYDAYIDX]==ICAL_RECURRENCE_ARRAY_MAX){ + BYDAYIDX = 0; /* Reset to 0 */ + end_of_data = 1; /* Signal that we're at the end */ + } + + /* Add the day of week offset to to the start of this week, and use + that to get the next day */ + /* ignore position of dow ("4FR"), only use dow ("FR")*/ + dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[BYDAYIDX]); + dow -= impl->rule.week_start; /* Set Sunday to be 0 */ + if (dow < 0) dow += 7; + + start_of_week = icaltime_start_doy_week(impl->last, impl->rule.week_start); + + if(dow+start_of_week <1){ + /* The selected date is in the previous year. */ + if(!end_of_data){ + continue; + } + } + + next = icaltime_from_day_of_year(start_of_week + dow,impl->last.year); + + impl->last.day = next.day; + impl->last.month = next.month; + impl->last.year = next.year; + + return end_of_data; + } + +} + +static int next_week(icalrecur_iterator* impl) +{ + int end_of_data = 0; + + /* Increment to the next week day, if there is data at a level less than a week */ if (next_weekday_by_week(impl) == 0){ return 0; /* Have not reached end of week yet */ } @@ -1598,8 +1700,8 @@ int next_week(struct icalrecur_iterator_impl* impl) /* If we get here, we have incremented through the entire week, and can increment to the next week */ - - if( has_by_data){ + if( has_by_data(impl,BY_WEEK_NO)){ + /*FREQ=WEEKLY;BYWEEK=20*/ /* Use the Week Number byrule data */ int week_no; struct icaltimetype t; @@ -1623,13 +1725,12 @@ int next_week(struct icalrecur_iterator_impl* impl) impl->last = icaltime_normalize(impl->last); - } else if( !has_by_data && this_frequency ){ - /* If there is no BY_WEEK_NO data, just jump forward 7 days. */ + } else { + /* Jump to the next week */ increment_monthday(impl,7*impl->rule.interval); } - - if(has_by_data && end_of_data && this_frequency ){ + if( has_by_data(impl,BY_WEEK_NO) && end_of_data){ increment_year(impl,1); } @@ -1637,15 +1738,14 @@ int next_week(struct icalrecur_iterator_impl* impl) } - -/* Expand the BYDAY rule part and return a pointer to a newly allocated list of days. */ -pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year) +/** Expand the BYDAY rule part and return a pointer to a newly allocated list of days. */ +static pvl_list expand_by_day(icalrecur_iterator* impl, int year) { /* Try to calculate each of the occurrences. */ int i; pvl_list days_list = pvl_newlist(); - short start_dow, end_dow, end_year_day; + int start_dow, end_dow, end_year_day; struct icaltimetype tmp = impl->last; tmp.year= year; @@ -1661,26 +1761,26 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year) tmp.month = 12; tmp.day = 31; tmp.is_date = 1; - + end_dow = icaltime_day_of_week(tmp); end_year_day = icaltime_day_of_year(tmp); - + for(i = 0; BYDAYPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){ /* This is 1 (Sun) to 7 (Sat). */ - short dow = + int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[i]); - short pos = icalrecurrencetype_day_position(BYDAYPTR[i]); + int pos = icalrecurrencetype_day_position(BYDAYPTR[i]); if(pos == 0){ /* The day was specified without a position -- it is just a bare day of the week ( BYDAY=SU) so add all of the days of the year with this day-of-week*/ int doy, tmp_start_doy; - + tmp_start_doy = ((dow + 7 - start_dow) % 7) + 1; for (doy = tmp_start_doy; doy <= end_year_day; doy += 7) - pvl_push(days_list,(void*)(int)doy); + pvl_push(days_list,(void*)(int)doy); } else if ( pos > 0) { int first; @@ -1690,14 +1790,24 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year) } else { first = dow - start_dow + 8; } - + + /* Then just multiple the position times 7 to get the pos'th day in the year */ pvl_push(days_list,(void*)(first+ (pos-1) * 7)); } else { /* pos < 0 */ - icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); + int last; + pos = -pos; + + /* last occurrence of dow in year */ + if( dow <= end_dow) { + last = end_year_day - end_dow + dow; + } else { + last = end_year_day - end_dow + dow - 7; + } + + pvl_push(days_list,(void*)(last - (pos-1) * 7)); } } - return days_list; } @@ -1706,22 +1816,23 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year) list all of the days of the current year that are specified in this rule. */ -int expand_year_days(struct icalrecur_iterator_impl* impl,short year) +static int expand_year_days(icalrecur_iterator* impl, int year) { int j,k; int days_index=0; struct icaltimetype t; int flags; - t = icaltime_null_time(); + t = icaltime_null_date(); #define HBD(x) has_by_data(impl,x) - t.is_date = 1; /* Needed to make day_of_year routines work property */ - - memset(&t,0,sizeof(t)); memset(impl->days,ICAL_RECURRENCE_ARRAY_MAX_BYTE,sizeof(impl->days)); + /* The flags and the following switch statement select which code + to use to expand the yers days, based on which BY-rules are + present. */ + flags = (HBD(BY_DAY) ? 1<<BY_DAY : 0) + (HBD(BY_WEEK_NO) ? 1<<BY_WEEK_NO : 0) + (HBD(BY_MONTH_DAY) ? 1<<BY_MONTH_DAY : 0) + @@ -1733,26 +1844,19 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case 0: { /* FREQ=YEARLY; */ - - short doy; - t = impl->dtstart; - t.year = year; - t.is_date = 1; - - doy = icaltime_day_of_year(t); - - impl->days[days_index++] = doy; + t.year = impl->last.year; + impl->days[days_index++] = (short)icaltime_day_of_year(t); + break; } case 1<<BY_MONTH: { /* FREQ=YEARLY; BYMONTH=3,11*/ for(j=0;impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){ - struct icaltimetype t; - short month = impl->by_ptrs[BY_MONTH][j]; - short doy; + int month = impl->by_ptrs[BY_MONTH][j]; + int doy; t = impl->dtstart; t.year = year; @@ -1761,7 +1865,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) doy = icaltime_day_of_year(t); - impl->days[days_index++] = doy; + impl->days[days_index++] = (short)doy; } break; @@ -1771,8 +1875,8 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) /* FREQ=YEARLY; BYMONTHDAY=1,15*/ for(k=0;impl->by_ptrs[BY_MONTH_DAY][k]!=ICAL_RECURRENCE_ARRAY_MAX;k++) { - short month_day = impl->by_ptrs[BY_MONTH_DAY][k]; - short doy; + int month_day = impl->by_ptrs[BY_MONTH_DAY][k]; + int doy; t = impl->dtstart; t.day = month_day; @@ -1781,7 +1885,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) doy = icaltime_day_of_year(t); - impl->days[days_index++] = doy; + impl->days[days_index++] = (short)doy; } break; @@ -1793,9 +1897,9 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) for(j=0;impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){ for(k=0;impl->by_ptrs[BY_MONTH_DAY][k]!=ICAL_RECURRENCE_ARRAY_MAX;k++) { - short month = impl->by_ptrs[BY_MONTH][j]; - short month_day = impl->by_ptrs[BY_MONTH_DAY][k]; - short doy; + int month = impl->by_ptrs[BY_MONTH][j]; + int month_day = impl->by_ptrs[BY_MONTH_DAY][k]; + int doy; t.day = month_day; t.month = month; @@ -1803,7 +1907,8 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) t.is_date = 1; doy = icaltime_day_of_year(t); - impl->days[days_index++] = doy; + + impl->days[days_index++] = (short)doy; } } @@ -1814,8 +1919,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case 1<<BY_WEEK_NO: { /* FREQ=YEARLY; BYWEEKNO=20,50 */ - struct icaltimetype t; - short dow; + int dow; t.day = impl->dtstart.day; t.month = impl->dtstart.month; @@ -1838,13 +1942,12 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case 1<<BY_DAY: { /*FREQ=YEARLY; BYDAY=TH,20MO,-10FR*/ - int days_index = 0; pvl_elem i; pvl_list days = expand_by_day(impl,year); for(i=pvl_head(days);i!=0;i=pvl_next(i)){ - short day = (short)(int)pvl_data(i); + short day = (short)(intptr_t)pvl_data(i); impl->days[days_index++] = day; } @@ -1858,23 +1961,21 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) for(j=0;impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){ - short month = impl->by_ptrs[BY_MONTH][j]; - short days_in_month = icaltime_days_in_month(month,year); - short first_dow, last_dow, doy_offset; - - struct icaltimetype t; - memset(&t,0,sizeof(struct icaltimetype)); + int month = impl->by_ptrs[BY_MONTH][j]; + int days_in_month = icaltime_days_in_month(month,year); + int first_dow, last_dow, doy_offset; + t.year = year; t.month = month; t.day = 1; t.is_date = 1; - + first_dow = icaltime_day_of_week(t); /* This holds the day offset used to calculate the day of the year from the month day. Just add the month day to this. */ doy_offset = icaltime_day_of_year(t) - 1; - + t.day = days_in_month; last_dow = icaltime_day_of_week(t); @@ -1882,8 +1983,8 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) short day_coded = impl->by_ptrs[BY_DAY][k]; enum icalrecurrencetype_weekday dow = icalrecurrencetype_day_day_of_week(day_coded); - short pos = icalrecurrencetype_day_position(day_coded); - short first_matching_day, last_matching_day, day, month_day; + int pos = icalrecurrencetype_day_position(day_coded); + int first_matching_day, last_matching_day, day, month_day; /* Calculate the first day in the month with the given weekday, and the last day. */ @@ -1893,21 +1994,21 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) if (pos == 0) { /* Add all of instances of the weekday within the month. */ for (day = first_matching_day; day <= days_in_month; day += 7) - impl->days[days_index++] = doy_offset + day; + impl->days[days_index++] = (short)(doy_offset + day); } else if (pos > 0) { /* Add the nth instance of the weekday within the month. */ month_day = first_matching_day + (pos - 1) * 7; if (month_day <= days_in_month) - impl->days[days_index++] = doy_offset + month_day; + impl->days[days_index++] = (short)(doy_offset + month_day); } else { /* Add the -nth instance of the weekday within the month.*/ month_day = last_matching_day + (pos + 1) * 7; if (month_day > 0) - impl->days[days_index++] = doy_offset + month_day; + impl->days[days_index++] = (short)(doy_offset + month_day); } } } @@ -1917,19 +2018,17 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case (1<<BY_DAY) + (1<<BY_MONTH_DAY) : { /*FREQ=YEARLY; BYDAY=TH,20MO,-10FR; BYMONTHDAY=1,15*/ - int days_index = 0; pvl_elem itr; pvl_list days = expand_by_day(impl,year); for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){ - short day = (short)(int)pvl_data(itr); + short day = (short)(intptr_t)pvl_data(itr); struct icaltimetype tt; - short i,j; tt = icaltime_from_day_of_year(day,year); for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){ - short mday = BYMDPTR[j]; + int mday = BYMDPTR[j]; if(tt.day == mday){ impl->days[days_index++] = day; @@ -1946,21 +2045,20 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case (1<<BY_DAY) + (1<<BY_MONTH_DAY) + (1<<BY_MONTH): { /*FREQ=YEARLY; BYDAY=TH,20MO,-10FR; BYMONTHDAY=10; MYMONTH=6,11*/ - int days_index = 0; pvl_elem itr; pvl_list days = expand_by_day(impl,year); for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){ - short day = (short)(int)pvl_data(itr); + short day = (short)(intptr_t)pvl_data(itr); struct icaltimetype tt; - short i,j; + int i; tt = icaltime_from_day_of_year(day,year); for(i = 0; BYMONPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){ for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){ - short mday = BYMDPTR[j]; - short month = BYMONPTR[i]; + int mday = BYMDPTR[j]; + int month = BYMONPTR[i]; if(tt.month == month && tt.day == mday){ impl->days[days_index++] = day; @@ -1979,21 +2077,20 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case (1<<BY_DAY) + (1<<BY_WEEK_NO) : { /*FREQ=YEARLY; BYDAY=TH,20MO,-10FR; WEEKNO=20,50*/ - int days_index = 0; pvl_elem itr; pvl_list days = expand_by_day(impl,year); for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){ - short day = (short)(int)pvl_data(itr); + short day = (short)(intptr_t)pvl_data(itr); struct icaltimetype tt; - short i; + int i; tt = icaltime_from_day_of_year(day,year); for(i = 0; BYWEEKPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){ - short weekno = BYWEEKPTR[i]; - - if(weekno== icaltime_week_number(tt)){ + int weekno = BYWEEKPTR[i]; + int this_weekno = icaltime_week_number(tt); + if(weekno== this_weekno){ impl->days[days_index++] = day; } } @@ -2012,8 +2109,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) case 1<<BY_YEAR_DAY: { for(j=0;impl->by_ptrs[BY_YEAR_DAY][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){ - short doy = impl->by_ptrs[BY_YEAR_DAY][j]; - impl->days[days_index++] = doy; + impl->days[days_index++] = impl->by_ptrs[BY_YEAR_DAY][j]; } break; } @@ -2029,7 +2125,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year) } -int next_year(struct icalrecur_iterator_impl* impl) +static int next_year(icalrecur_iterator* impl) { struct icaltimetype next; @@ -2041,20 +2137,14 @@ int next_year(struct icalrecur_iterator_impl* impl) impl->days_index = 0; for (;;) { - increment_year(impl,impl->rule.interval); - - /* Make sure we don't go past the max time_t year, or any calls to - mktime() etc. will fail. */ - if (impl->last.year > MAX_TIME_T_YEAR) - return 1; - - expand_year_days(impl,impl->last.year); + increment_year(impl,impl->rule.interval); + expand_year_days(impl,impl->last.year); if (impl->days[0] != ICAL_RECURRENCE_ARRAY_MAX) break; - } + } } - next = icaltime_from_day_of_year(impl->days[impl->days_index],impl->last.year); + next = icaltime_from_day_of_year(impl->days[impl->days_index], impl->last.year); impl->last.day = next.day; impl->last.month = next.month; @@ -2062,8 +2152,8 @@ int next_year(struct icalrecur_iterator_impl* impl) return 1; } -int icalrecur_check_rulepart(struct icalrecur_iterator_impl* impl, - short v, enum byrule byrule) +int icalrecur_check_rulepart(icalrecur_iterator* impl, + int v, enum byrule byrule) { int itr; @@ -2078,8 +2168,8 @@ int icalrecur_check_rulepart(struct icalrecur_iterator_impl* impl, return 0; } -int check_contract_restriction(struct icalrecur_iterator_impl* impl, - enum byrule byrule, short v) +static int check_contract_restriction(icalrecur_iterator* impl, + enum byrule byrule, int v) { int pass = 0; int itr; @@ -2103,22 +2193,22 @@ int check_contract_restriction(struct icalrecur_iterator_impl* impl, } -int check_contracting_rules(struct icalrecur_iterator_impl* impl) +static int check_contracting_rules(icalrecur_iterator* impl) { - int day_of_week=0; - int week_no=0; - int year_day=0; + int day_of_week = icaltime_day_of_week(impl->last); + int week_no = icaltime_week_number(impl->last); + int year_day = icaltime_day_of_year(impl->last); if ( - check_contract_restriction(impl,BY_SECOND,impl->last.second) && - check_contract_restriction(impl,BY_MINUTE,impl->last.minute) && - check_contract_restriction(impl,BY_HOUR,impl->last.hour) && - check_contract_restriction(impl,BY_DAY,day_of_week) && - check_contract_restriction(impl,BY_WEEK_NO,week_no) && - check_contract_restriction(impl,BY_MONTH_DAY,impl->last.day) && - check_contract_restriction(impl,BY_MONTH,impl->last.month) && - check_contract_restriction(impl,BY_YEAR_DAY,year_day) ) + check_contract_restriction(impl,BY_SECOND, impl->last.second) && + check_contract_restriction(impl,BY_MINUTE, impl->last.minute) && + check_contract_restriction(impl,BY_HOUR, impl->last.hour) && + check_contract_restriction(impl,BY_DAY, day_of_week) && + check_contract_restriction(impl,BY_WEEK_NO, week_no) && + check_contract_restriction(impl,BY_MONTH_DAY, impl->last.day) && + check_contract_restriction(impl,BY_MONTH, impl->last.month) && + check_contract_restriction(impl,BY_YEAR_DAY, year_day) ) { return 1; @@ -2127,11 +2217,9 @@ int check_contracting_rules(struct icalrecur_iterator_impl* impl) } } -struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *itr) +struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *impl) { int valid = 1; - struct icalrecur_iterator_impl* impl = - (struct icalrecur_iterator_impl*)itr; if( (impl->rule.count!=0 &&impl->occurrence_no >= impl->rule.count) || (!icaltime_is_null_time(impl->rule.until) && @@ -2184,7 +2272,7 @@ struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *itr) } } - if(impl->last.year > MAX_TIME_T_YEAR ){ + if(impl->last.year >= 2038 ){ /* HACK */ return icaltime_null_time(); } @@ -2221,16 +2309,15 @@ void icalrecurrencetype_clear(struct icalrecurrencetype *recur) recur->count = 0; } -/* The 'day' element of icalrecurrencetype_weekday is encoded to allow -reporesentation of both the day of the week ( Monday, Tueday), but -also the Nth day of the week ( First tuesday of the month, last -thursday of the year) These routines decode the day values. - -The day's position in the period ( Nth-ness) and the numerical value -of the day are encoded together as: pos*7 + dow - -A position of 0 means 'any' or 'every' - +/** The 'day' element of icalrecurrencetype_weekday is encoded to + * allow representation of both the day of the week ( Monday, Tueday), + * but also the Nth day of the week ( First tuesday of the month, last + * thursday of the year) These routines decode the day values. + * + * The day's position in the period ( Nth-ness) and the numerical + * value of the day are encoded together as: pos*7 + dow + * + * A position of 0 means 'any' or 'every' */ enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day) @@ -2238,9 +2325,9 @@ enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day) return abs(day)%8; } -short icalrecurrencetype_day_position(short day) +int icalrecurrencetype_day_position(short day) { - short wd, pos; + int wd, pos; wd = icalrecurrencetype_day_day_of_week(day); @@ -2253,7 +2340,7 @@ short icalrecurrencetype_day_position(short day) /****************** Enumeration Routines ******************/ -struct {icalrecurrencetype_weekday wd; const char * str; } +static struct {icalrecurrencetype_weekday wd; const char * str; } wd_map[] = { {ICAL_SUNDAY_WEEKDAY,"SU"}, {ICAL_MONDAY_WEEKDAY,"MO"}, @@ -2293,7 +2380,7 @@ icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str) -struct { +static struct { icalrecurrencetype_frequency kind; const char* str; } freq_map[] = { @@ -2331,10 +2418,11 @@ icalrecurrencetype_frequency icalrecur_string_to_freq(const char* str) return ICAL_NO_RECURRENCE; } -/* Fill an array with the 'count' number of occurrences generated by - the rrule. Note that the times are returned in UTC, but the times - are calculated in local time. YOu will have to convert the results - back into local time before using them. */ +/** Fill an array with the 'count' number of occurrences generated by + * the rrule. Note that the times are returned in UTC, but the times + * are calculated in local time. YOu will have to convert the results + * back into local time before using them. + */ int icalrecur_expand_recurrence(char* rule, time_t start, int count, time_t* array) @@ -2347,7 +2435,7 @@ int icalrecur_expand_recurrence(char* rule, time_t start, memset(array, 0, count*sizeof(time_t)); - icstart = icaltime_from_timet(start,0); + icstart = icaltime_from_timet_with_zone(start,0,0); recur = icalrecurrencetype_from_string(rule); diff --git a/libical/src/libical/icalrecur.h b/libical/src/libical/icalrecur.h index 5fcdc15a8c..45bdd21b65 100644 --- a/libical/src/libical/icalrecur.h +++ b/libical/src/libical/icalrecur.h @@ -16,10 +16,17 @@ The Mozilla Public License Version 1.0. You may obtain a copy of the License at http://www.mozilla.org/MPL/ +*/ + +/** +@file icalrecur.h +@brief Routines for dealing with recurring time How to use: 1) Get a rule and a start time from a component + +@code icalproperty rrule; struct icalrecurrencetype recur; struct icaltimetype dtstart; @@ -27,26 +34,36 @@ How to use: rrule = icalcomponent_get_first_property(comp,ICAL_RRULE_PROPERTY); recur = icalproperty_get_rrule(rrule); start = icalproperty_get_dtstart(dtstart); +@endcode Or, just make them up: + +@code recur = icalrecurrencetype_from_string("FREQ=YEARLY;BYDAY=SU,WE"); dtstart = icaltime_from_string("19970101T123000") +@endcode 2) Create an iterator + +@code icalrecur_iterator* ritr; ritr = icalrecur_iterator_new(recur,start); +@endcode 3) Iterator over the occurrences + +@code struct icaltimetype next; while (next = icalrecur_iterator_next(ritr) && !icaltime_is_null_time(next){ Do something with next } +@endcode Note that that the time returned by icalrecur_iterator_next is in whatever timezone that dtstart is in. -======================================================================*/ +*/ #ifndef ICALRECUR_H #define ICALRECUR_H @@ -54,9 +71,9 @@ whatever timezone that dtstart is in. #include <time.h> #include "icaltime.h" -/*********************************************************************** +/* * Recurrance enumerations -**********************************************************************/ + */ typedef enum icalrecurrencetype_frequency { @@ -93,7 +110,9 @@ enum { -/********************** Recurrence type routines **************/ +/** + * Recurrence type routines + */ /* See RFC 2445 Section 4.3.10, RECUR Value, for an explaination of the values and fields in struct icalrecurrencetype */ @@ -108,7 +127,7 @@ enum { #define ICAL_BY_MONTH_SIZE 13 #define ICAL_BY_SETPOS_SIZE 367 -/* Main struct for holding digested recurrence rules */ +/** Main struct for holding digested recurrence rules */ struct icalrecurrencetype { icalrecurrencetype_frequency freq; @@ -145,43 +164,50 @@ struct icalrecurrencetype void icalrecurrencetype_clear(struct icalrecurrencetype *r); -/* The 'day' element of the by_day array is encoded to allow -representation of both the day of the week ( Monday, Tueday), but also -the Nth day of the week ( First tuesday of the month, last thursday of -the year) These routines decode the day values */ +/** + * Array Encoding + * + * The 'day' element of the by_day array is encoded to allow + * representation of both the day of the week ( Monday, Tueday), but also + * the Nth day of the week ( First tuesday of the month, last thursday of + * the year) These routines decode the day values + */ -/* 1 == Monday, etc. */ +/** 1 == Monday, etc. */ enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day); -/* 0 == any of day of week. 1 == first, 2 = second, -2 == second to last, etc */ -short icalrecurrencetype_day_position(short day); +/** 0 == any of day of week. 1 == first, 2 = second, -2 == second to last, etc */ +int icalrecurrencetype_day_position(short day); +icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str); -/*********************************************************************** - * Recurrance rule parser -**********************************************************************/ +/** Recurrance rule parser */ -/* Convert between strings ans recurrencetype structures. */ +/** Convert between strings and recurrencetype structures. */ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str); char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur); -/********** recurrence iteration routines ********************/ +/** Recurrence iteration routines */ -typedef void icalrecur_iterator; +typedef struct icalrecur_iterator_impl icalrecur_iterator; -/* Create a new recurrence rule iterator */ +/** Create a new recurrence rule iterator */ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, struct icaltimetype dtstart); -/* Get the next occurrence from an iterator */ +/** Get the next occurrence from an iterator */ struct icaltimetype icalrecur_iterator_next(icalrecur_iterator*); -/* Free the iterator */ +void icalrecur_iterator_decrement_count(icalrecur_iterator*); + +/** Free the iterator */ void icalrecur_iterator_free(icalrecur_iterator*); -/* Fills array up with at most 'count' time_t values, each - representing an occurrence time in seconds past the POSIX epoch */ +/** + * Fills array up with at most 'count' time_t values, each + * representing an occurrence time in seconds past the POSIX epoch + */ int icalrecur_expand_recurrence(char* rule, time_t start, int count, time_t* array); diff --git a/libical/src/libical/icalrestriction.c.in b/libical/src/libical/icalrestriction.c.in index 454442531f..05cdc9d413 100644 --- a/libical/src/libical/icalrestriction.c.in +++ b/libical/src/libical/icalrestriction.c.in @@ -19,6 +19,11 @@ #define TMP_BUF_SIZE 1024 +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + /* Define the structs for the restrictions. these data are filled out in machine generated code below */ @@ -61,7 +66,7 @@ icalrestriction_property_record null_prop_record = {ICAL_METHOD_NONE,ICAL_NO_C icalrestriction_component_record null_comp_record = {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_COMPONENT,ICAL_RESTRICTION_UNKNOWN,0}; -/* The each row gives the result of comparing a restriction against a +/** The each row gives the result of comparing a restriction against a count. The columns in each row represent 0,1,2+. '-1' indicates 'invalid, 'don't care' or 'needs more analysis' So, for ICAL_RESTRICTION_ONE, if there is 1 of a property with that @@ -219,7 +224,7 @@ char* icalrestriction_must_have_duration(icalrestriction_property_record *rec, if( !icalcomponent_get_first_property(comp,ICAL_DURATION_PROPERTY)){ - return "Failed iTIP restrictions for STATUS property. This component must have a DURATION property"; + return "Failed iTIP restrictions. This component must have a DURATION property"; } @@ -230,7 +235,7 @@ char* icalrestriction_must_have_repeat(icalrestriction_property_record *rec, icalproperty* prop){ if( !icalcomponent_get_first_property(comp,ICAL_REPEAT_PROPERTY)){ - return "Failed iTIP restrictions for STATUS property. This component must have a REPEAT property"; + return "Failed iTIP restrictions. This component must have a REPEAT property"; } @@ -247,9 +252,9 @@ char* icalrestriction_no_dtend(icalrestriction_property_record *rec, icalcomponent* comp, icalproperty* prop){ - if( !icalcomponent_get_first_property(comp,ICAL_DTEND_PROPERTY)){ + if( icalcomponent_get_first_property(comp,ICAL_DTEND_PROPERTY)){ - return "Failed iTIP restrictions for STATUS property. The component must not have both DURATION and DTEND"; + return "Failed iTIP restrictions. The component must not have both DURATION and DTEND"; } @@ -262,7 +267,21 @@ char* icalrestriction_no_duration(icalrestriction_property_record *rec, /* _no_dtend takes care of this one */ return 0; } +char* icalrestriction_must_be_email( + icalrestriction_property_record *rec, + icalcomponent* comp, + icalproperty* prop) +{ + icalproperty_status stat = icalproperty_get_action(prop); + if( !( stat == ICAL_ACTION_EMAIL)){ + + return "Failed iTIP restrictions for ACTION property. Value must be EMAIL."; + + } + + return 0; +} int icalrestriction_check_component(icalproperty_method method, icalcomponent* comp) @@ -271,7 +290,6 @@ int icalrestriction_check_component(icalproperty_method method, icalcomponent_kind comp_kind; icalrestriction_kind restr; icalrestriction_property_record *prop_record; - icalrestriction_component_record *comp_record; char* funcr = 0; icalproperty *prop; diff --git a/libical/src/libical/icalrestriction.h b/libical/src/libical/icalrestriction.h index 6d414db4af..409334cf28 100644 --- a/libical/src/libical/icalrestriction.h +++ b/libical/src/libical/icalrestriction.h @@ -6,7 +6,6 @@ $Id$ - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org This program is free software; you can redistribute it and/or modify diff --git a/libical/src/libical/icaltime.c b/libical/src/libical/icaltime.c index d28dbb215c..371d679f7d 100644 --- a/libical/src/libical/icaltime.c +++ b/libical/src/libical/icaltime.c @@ -34,250 +34,298 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <time.h> + +#include "astime.h" /* Julian data handling routines */ -#ifdef ICAL_NO_LIBICAL -#define icalerror_set_errno(x) -#define icalerror_check_arg_rv(x,y) -#define icalerror_check_arg_re(x,y,z) -#else #include "icalerror.h" #include "icalmemory.h" -#endif #include "icaltimezone.h" +#include "icalvalue.h" +#ifdef WIN32 +#include <Windows.h> -struct icaltimetype -icaltime_from_timet(time_t tm, int is_date) +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + +/* + * Function to convert a struct tm time specification + * to an ANSI time_t using the specified time zone. + * This is different from the standard mktime() function + * in that we dont want the automatic adjustments for + * local daylight savings time applied to the result. + * This function expects well-formed input. + */ +static time_t make_time(struct tm *tm, int tzm) { - struct icaltimetype tt = icaltime_null_time(); - struct tm t; + time_t tim; - t = *(gmtime(&tm)); - - if(is_date == 0){ - tt.second = t.tm_sec; - tt.minute = t.tm_min; - tt.hour = t.tm_hour; - } else { - tt.second = tt.minute =tt.hour = 0 ; - } + static int days[] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }; - tt.day = t.tm_mday; - tt.month = t.tm_mon + 1; - tt.year = t.tm_year+ 1900; - - tt.is_utc = 1; - tt.is_date = is_date; + /* check that year specification within range */ - return tt; -} + if (tm->tm_year < 70 || tm->tm_year > 138) + return((time_t) -1); -/* Note that DATE values and floating values do not have their own timezones, - so you should use the default or current timezone in that case. - This assumes that if is_date is set, the time_t points to the start of the - day in the given zone, so be very careful about using it. */ -struct icaltimetype -icaltime_from_timet_with_zone(time_t tm, int is_date, icaltimezone *zone) -{ - struct icaltimetype tt; - struct tm t; - icaltimezone *utc_zone; + /* check that month specification within range */ - utc_zone = icaltimezone_get_utc_timezone (); + if (tm->tm_mon < 0 || tm->tm_mon > 11) + return((time_t) -1); - /* Convert the time_t to a struct tm in UTC time. We can trust gmtime - for this. */ - t = *(gmtime(&tm)); - - tt.year = t.tm_year + 1900; - tt.month = t.tm_mon + 1; - tt.day = t.tm_mday; - tt.hour = t.tm_hour; - tt.minute = t.tm_min; - tt.second = t.tm_sec; - tt.is_date = 0; - tt.is_utc = (zone == utc_zone) ? 1 : 0; - tt.is_daylight = 0; - tt.zone = NULL; + /* check for upper bound of Jan 17, 2038 (to avoid possibility of + 32-bit arithmetic overflow) */ + + if (tm->tm_year == 138) { + if (tm->tm_mon > 0) + return((time_t) -1); + else if (tm->tm_mday > 17) + return((time_t) -1); + } - /* Use our timezone functions to convert to the required timezone. */ - icaltimezone_convert_time (&tt, utc_zone, zone); + /* + * calculate elapsed days since start of the epoch (midnight Jan + * 1st, 1970 UTC) 17 = number of leap years between 1900 and 1970 + * (number of leap days to subtract) + */ - tt.is_date = is_date; + tim = (tm->tm_year - 70) * 365 + ((tm->tm_year - 1) / 4) - 17; - /* If it is a DATE value, make sure hour, minute & second are 0. */ - if (is_date) { - tt.hour = 0; - tt.minute = 0; - tt.second = 0; - } + /* add number of days elapsed in the current year */ - return tt; -} + tim += days[tm->tm_mon]; -/* Returns the current time in the given timezone, as an icaltimetype. */ -struct icaltimetype icaltime_current_time_with_zone(icaltimezone *zone) -{ - return icaltime_from_timet_with_zone (time (NULL), 0, zone); -} + /* check and adjust for leap years (the leap year check only valid + during the 32-bit era */ -/* Returns the current day as an icaltimetype, with is_date set. */ -struct icaltimetype icaltime_today(void) -{ - return icaltime_from_timet_with_zone (time (NULL), 1, NULL); -} + if ((tm->tm_year & 3) == 0 && tm->tm_mon > 1) + tim += 1; + /* elapsed days to current date */ -/* Structure used by set_tz to hold an old value of TZ, and the new - value, which is in memory we will have to free in unset_tz */ -/* This will hold the last "TZ=XXX" string we used with putenv(). After we - call putenv() again to set a new TZ string, we can free the previous one. - As far as I know, no libc implementations actually free the memory used in - the environment variables (how could they know if it is a static string or - a malloc'ed string?), so we have to free it ourselves. */ -static char* saved_tz = NULL; + tim += tm->tm_mday; + + + /* calculate elapsed hours since start of the epoch */ + + tim = tim * 24 + tm->tm_hour; + + /* calculate elapsed minutes since start of the epoch */ + + tim = tim * 60 + tm->tm_min; + + /* adjust per time zone specification */ + + tim -= tzm; + + /* calculate elapsed seconds since start of the epoch */ + + tim = tim * 60 + tm->tm_sec; + + /* return number of seconds since start of the epoch */ + + return(tim); +} +/** @brief Constructor (deprecated). + * + * Convert seconds past UNIX epoch to a timetype. + * + * @deprecated This constructor is deprecated and shouldn't be used in + * new software. Use icaltime_from_timet_with_zone(time_t, int, + * icaltimezone *) instead. In the meantime, calls to this method + * return a floating time, which can always be converted to a local + * time with an appropriate call to icaltime_convert_to_zone(). + */ -/* If you use set_tz(), you must call unset_tz() some time later to restore the - original TZ. Pass unset_tz() the string that set_tz() returns. */ -char* set_tz(const char* tzid) +struct icaltimetype +icaltime_from_timet(const time_t tm, const int is_date) { - char *old_tz, *old_tz_copy = NULL, *new_tz; +#ifndef NO_WARN_DEPRECATED + icalerror_warn("icaltime_from_timet() is DEPRECATED, use icaltime_from_timet_with_zone() instead"); +#endif - /* Get the old TZ setting and save a copy of it to return. */ - old_tz = getenv("TZ"); - if(old_tz){ - old_tz_copy = (char*)malloc(strlen (old_tz) + 4); + return icaltime_from_timet_with_zone(tm, is_date, 0); +} - if(old_tz_copy == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - strcpy (old_tz_copy, "TZ="); - strcpy (old_tz_copy + 3, old_tz); +/** @brief Constructor. + * + * @param tm The time + * @param is_date Boolean: 1 means we should treat tm as a DATE + * @param zone The timezone tm is in, NULL means to treat tm as a + * floating time + * + * Return a new icaltime instance, initialized to the given time + * expressed as seconds past UNIX epoch, optionally using the given + * timezone. + * + * If the caller specifies the is_date param as TRUE, the returned + * object is of DATE type, otherwise the input is meant to be of + * DATE-TIME type. + * If the zone is not specified (NULL zone param) the time is taken + * to be floating, that is, valid in any timezone. Note that, in + * addition to the uses specified in [RFC2445], this can be used + * when doing simple math on couples of times. + * If the zone is specified (UTC or otherwise), it's stored in the + * object and it's used as the native timezone for this object. + * This means that the caller can convert this time to a different + * target timezone with no need to store the source timezone. + * + */ +struct icaltimetype +icaltime_from_timet_with_zone(const time_t tm, const int is_date, + const icaltimezone *zone) +{ + struct icaltimetype tt = icaltime_null_time(); + struct tm t; + icaltimezone *utc_zone; + + /* Convert the time_t to a struct tm. We can trust gmtime for this. */ +#ifdef HAVE_GMTIME_R + gmtime_r(&tm, &t); +#else + { + struct tm *t_ptr = gmtime(&tm); + t = *t_ptr; } +#endif - /* Create the new TZ string. */ - new_tz = (char*)malloc(strlen (tzid) + 4); + tt.year = t.tm_year + 1900; + tt.month = t.tm_mon + 1; + tt.day = t.tm_mday; - if(new_tz == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; + if (is_date) { + tt.is_date = 1; + return tt; } - strcpy (new_tz, "TZ="); - strcpy (new_tz + 3, tzid); - - /* Add the new TZ to the environment. */ - putenv(new_tz); + tt.hour = t.tm_hour; + tt.minute = t.tm_min; + tt.second = t.tm_sec; - /* Free any previous TZ environment string we have used. */ - if (saved_tz) - free (saved_tz); + /* If it's a floating time, we don't do any conversion. */ + if (zone == NULL) { + return tt; + } - /* Save a pointer to the TZ string we just set, so we can free it later. */ - saved_tz = new_tz; + utc_zone = icaltimezone_get_utc_timezone (); + tt.is_utc = (zone == utc_zone) ? 1 : 0; + tt.zone = zone; - return old_tz_copy; /* This will be zero if the TZ env var was not set */ + return tt; } -void unset_tz(char *tzstr) +/** @brief Constructor. + * + * Returns an icaltimetype representing the current time in the given timezone. + */ +struct icaltimetype icaltime_current_time_with_zone(const icaltimezone *zone) { - /* restore the original environment */ - - if(tzstr!=0){ - putenv(tzstr); - } else { - putenv("TZ"); /* Delete from environment */ - } - - /* Free any previous TZ environment string we have used. */ - if (saved_tz) - free (saved_tz); + return icaltime_from_timet_with_zone (time (NULL), 0, zone); +} - /* Save a pointer to the TZ string we just set, so we can free it later. - (This can possibly be NULL if there was no TZ to restore.) */ - saved_tz = tzstr; +/** @brief Constructor. + * + * Returns an icaltimetype representing the current day. + */ +struct icaltimetype icaltime_today(void) +{ + return icaltime_from_timet_with_zone (time (NULL), 1, NULL); } -time_t icaltime_as_timet(struct icaltimetype tt) +/** @brief Return the time as seconds past the UNIX epoch + * + * While this function is not currently deprecated, it probably won't do + * what you expect, unless you know what you're doing. In particular, you + * should only pass an icaltime in UTC, since no conversion is done. Even + * in that case, it's probably better to just use + * icaltime_as_timet_with_zone(). + */ +time_t icaltime_as_timet(const struct icaltimetype tt) { struct tm stm; time_t t; - memset(&stm,0,sizeof( struct tm)); - - if(icaltime_is_null_time(tt)) { + /* If the time is the special null time, return 0. */ + if (icaltime_is_null_time(tt)) { return 0; } - stm.tm_sec = tt.second; - stm.tm_min = tt.minute; - stm.tm_hour = tt.hour; + /* Copy the icaltimetype to a struct tm. */ + memset (&stm, 0, sizeof (struct tm)); + + if (icaltime_is_date(tt)) { + stm.tm_sec = stm.tm_min = stm.tm_hour = 0; + } else { + stm.tm_sec = tt.second; + stm.tm_min = tt.minute; + stm.tm_hour = tt.hour; + } + stm.tm_mday = tt.day; stm.tm_mon = tt.month-1; stm.tm_year = tt.year-1900; stm.tm_isdst = -1; - if(tt.is_utc == 1 || tt.is_date == 1){ - char *old_tz = set_tz("UTC"); - t = mktime(&stm); - unset_tz(old_tz); - } else { - t = mktime(&stm); - } + t = make_time(&stm, 0); return t; } -/* Note that DATE values and floating values do not have their own timezones, - so you should use the default or current timezone in that case. - If is_date is set, the time_t returned points to the start of the day in - the given zone. */ -time_t -icaltime_as_timet_with_zone(struct icaltimetype tt, icaltimezone *zone) +/** Return the time as seconds past the UNIX epoch, using the + * given timezone. + * + * This convenience method combines a call to icaltime_convert_to_zone() + * with a call to icaltime_as_timet(). + * If the input timezone is null, no conversion is done; that is, the + * time is simply returned as time_t in its native timezone. + */ +time_t icaltime_as_timet_with_zone(const struct icaltimetype _tt, + const icaltimezone *zone) { - icaltimezone *utc_zone; + struct icaltimetype tt = _tt; struct tm stm; time_t t; - char *old_tz; - - utc_zone = icaltimezone_get_utc_timezone (); /* If the time is the special null time, return 0. */ if (icaltime_is_null_time(tt)) { return 0; } - /* Clear the is_date flag, so we can convert the time. */ - tt.is_date = 0; - - /* Use our timezone functions to convert to UTC. */ - icaltimezone_convert_time (&tt, zone, utc_zone); + if (zone != NULL) { + tt = icaltime_convert_to_zone(_tt, zone); + } /* Copy the icaltimetype to a struct tm. */ memset (&stm, 0, sizeof (struct tm)); - stm.tm_sec = tt.second; - stm.tm_min = tt.minute; - stm.tm_hour = tt.hour; + if (icaltime_is_date(tt)) { + stm.tm_sec = stm.tm_min = stm.tm_hour = 0; + } else { + stm.tm_sec = tt.second; + stm.tm_min = tt.minute; + stm.tm_hour = tt.hour; + } + stm.tm_mday = tt.day; stm.tm_mon = tt.month-1; stm.tm_year = tt.year-1900; stm.tm_isdst = -1; - /* Set TZ to UTC and use mktime to convert to a time_t. */ - old_tz = set_tz ("UTC"); - t = mktime (&stm); - unset_tz (old_tz); + t = make_time(&stm, 0); return t; } -char* icaltime_as_ical_string(struct icaltimetype tt) +/** + * Return a string represention of the time, in RFC2445 format. The + * string is owned by libical + */ +const char* icaltime_as_ical_string(const struct icaltimetype tt) { size_t size = 17; char* buf = icalmemory_new_buffer(size); @@ -301,19 +349,33 @@ char* icaltime_as_ical_string(struct icaltimetype tt) } - -/* Normalize the icaltime, so that all fields are within the normal range. */ - -struct icaltimetype icaltime_normalize(struct icaltimetype tt) +/** + * Reset all of the time components to be in their normal ranges. For + * instance, given a time with minutes=70, the minutes will be reduces + * to 10, and the hour incremented. This allows the caller to do + * arithmetic on times without worrying about overflow or + * underflow. + * + * Implementation note: we call icaltime_adjust() with no adjustment. + */ +struct icaltimetype icaltime_normalize(const struct icaltimetype tt) { - icaltime_adjust (&tt, 0, 0, 0, 0); - return tt; + struct icaltimetype ret = tt; + icaltime_adjust(&ret, 0, 0, 0, 0); + return ret; } -#ifndef ICAL_NO_LIBICAL -#include "icalvalue.h" +/** @brief Contructor. + * + * Create a time from an ISO format string. + * + * @todo If the given string specifies a DATE-TIME not in UTC, there + * is no way to know if this is a floating time or really refers to a + * timezone. We should probably add a new constructor: + * icaltime_from_string_with_zone() + */ struct icaltimetype icaltime_from_string(const char* str) { struct icaltimetype tt = icaltime_null_time(); @@ -327,225 +389,208 @@ struct icaltimetype icaltime_from_string(const char* str) tt.is_utc = 0; tt.is_date = 0; } else if (size == 16) { /* UTC time, ends in 'Z'*/ + if(str[15] != 'Z') + goto FAIL; + tt.is_utc = 1; + tt.zone = icaltimezone_get_utc_timezone(); tt.is_date = 0; - - if(str[15] != 'Z'){ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return icaltime_null_time(); - } - } else if (size == 8) { /* A DATE */ - tt.is_utc = 0; + tt.is_utc = 1; tt.is_date = 1; } else { /* error */ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return icaltime_null_time(); + goto FAIL; } if(tt.is_date == 1){ - sscanf(str,"%04d%02d%02d",&tt.year,&tt.month,&tt.day); + if (sscanf(str,"%04d%02d%02d",&tt.year,&tt.month,&tt.day) < 3) + goto FAIL; } else { char tsep; - sscanf(str,"%04d%02d%02d%c%02d%02d%02d",&tt.year,&tt.month,&tt.day, - &tsep,&tt.hour,&tt.minute,&tt.second); - - if(tsep != 'T'){ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return icaltime_null_time(); - } + if (sscanf(str,"%04d%02d%02d%c%02d%02d%02d",&tt.year,&tt.month,&tt.day, + &tsep,&tt.hour,&tt.minute,&tt.second) < 7) + goto FAIL; + if(tsep != 'T') + goto FAIL; } return tt; + +FAIL: + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return icaltime_null_time(); } -#endif -char ctime_str[20]; -char* icaltime_as_ctime(struct icaltimetype t) -{ - time_t tt; - - tt = icaltime_as_timet(t); - sprintf(ctime_str,"%s",ctime(&tt)); - ctime_str[strlen(ctime_str)-1] = 0; +/* Returns whether the specified year is a leap year. Year is the normal year, + e.g. 2001. */ +int +icaltime_is_leap_year (const int year) +{ - return ctime_str; + if (year <= 1752) + return (year % 4 == 0); + else + return ( (year % 4==0) && (year % 100 !=0 )) || (year % 400 == 0); } +static int _days_in_month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; -short days_in_month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; - -short icaltime_days_in_month(short month,short year) +int icaltime_days_in_month(const int month, const int year) { - int is_leap =0; - int days = days_in_month[month]; + int days = _days_in_month[month]; assert(month > 0); assert(month <= 12); - if( (year % 4 == 0 && year % 100 != 0) || - year % 400 == 0){ - is_leap =1; - } - if( month == 2){ - days += is_leap; + days += icaltime_is_leap_year(year); } return days; } -/* Returns whether the specified year is a leap year. Year is the normal year, - e.g. 2001. */ -int -icaltime_is_leap_year (int year) -{ - if (year <= 1752) - return !(year % 4); - else - return (!(year % 4) && (year % 100)) || !(year % 400); -} - /* 1-> Sunday, 7->Saturday */ -short icaltime_day_of_week(struct icaltimetype t){ - struct tm stm; - - stm.tm_year = t.year - 1900; - stm.tm_mon = t.month - 1; - stm.tm_mday = t.day; - stm.tm_hour = 12; - stm.tm_min = 0; - stm.tm_sec = 0; - stm.tm_isdst = -1; +int icaltime_day_of_week(const struct icaltimetype t){ + UTinstant jt; - mktime (&stm); + memset(&jt,0,sizeof(UTinstant)); - if (stm.tm_year != t.year - 1900 - || stm.tm_mon != t.month - 1 - || stm.tm_mday != t.day) - printf ("WARNING: icaltime_day_of_week: mktime() changed our date!!\n"); + jt.year = t.year; + jt.month = t.month; + jt.day = t.day; + jt.i_hour = 0; + jt.i_minute = 0; + jt.i_second = 0; -#if 0 - printf ("Day of week %i/%i/%i (%i/%i/%i) -> %i (0=Sun 6=Sat)\n", - t.day, t.month, t.year, - stm.tm_mday, stm.tm_mon + 1, stm.tm_year + 1900, - stm.tm_wday); -#endif + juldat(&jt); - return stm.tm_wday + 1; + return jt.weekday + 1; } -/* Day of the year that the first day of the week (Sunday) is on. - FIXME: Doesn't take into account different week start days. */ -short icaltime_start_doy_of_week(struct icaltimetype t){ - struct tm stm; +/** Day of the year that the first day of the week (Sunday) is on. + */ +int icaltime_start_doy_week(const struct icaltimetype t, int fdow){ + UTinstant jt; + int delta; - stm.tm_year = t.year - 1900; - stm.tm_mon = t.month - 1; - stm.tm_mday = t.day; - stm.tm_hour = 12; - stm.tm_min = 0; - stm.tm_sec = 0; - stm.tm_isdst = -1; + memset(&jt,0,sizeof(UTinstant)); - mktime (&stm); + jt.year = t.year; + jt.month = t.month; + jt.day = t.day; + jt.i_hour = 0; + jt.i_minute = 0; + jt.i_second = 0; - /* Move back to the start of the week. */ - stm.tm_mday -= stm.tm_wday; + juldat(&jt); + caldat(&jt); - mktime (&stm); + delta = jt.weekday - (fdow - 1); + if (delta < 0) delta += 7; + return jt.day_of_year - delta; +} - /* If we are still in the same year as the original date, we just return - the day of the year. */ - if (t.year - 1900 == stm.tm_year){ - return stm.tm_yday+1; - } else { - /* return negative to indicate that start of week is in - previous year. */ - int is_leap = 0; - int year = stm.tm_year; - - if( (year % 4 == 0 && year % 100 != 0) || - year % 400 == 0){ - is_leap =1; - } +/** Day of the year that the first day of the week (Sunday) is on. + * + * @deprecated Doesn't take into account different week start days. + */ +int icaltime_start_doy_of_week(const struct icaltimetype t){ - return (stm.tm_yday+1)-(365+is_leap); - } - +#ifndef NO_WARN_DEPRECATED + icalerror_warn("icaltime_start_doy_of_week() is DEPRECATED, use\ + icaltime_start_doy_week() instead"); +#endif + + return icaltime_start_doy_week(t, 1); } -/* FIXME: Doesn't take into account the start day of the week. strftime assumes - that weeks start on Monday. */ -short icaltime_week_number(struct icaltimetype ictt) +/** + * @todo Doesn't take into account the start day of the + * week. strftime assumes that weeks start on Monday. + */ +int icaltime_week_number(const struct icaltimetype ictt) { - struct tm stm; - int week_no; - char str[8]; - - stm.tm_year = ictt.year - 1900; - stm.tm_mon = ictt.month - 1; - stm.tm_mday = ictt.day; - stm.tm_hour = 12; - stm.tm_min = 0; - stm.tm_sec = 0; - stm.tm_isdst = -1; + UTinstant jt; - mktime (&stm); - - strftime(str,5,"%V", &stm); + memset(&jt,0,sizeof(UTinstant)); - week_no = atoi(str); + jt.year = ictt.year; + jt.month = ictt.month; + jt.day = ictt.day; + jt.i_hour = 0; + jt.i_minute = 0; + jt.i_second = 0; - return week_no; + juldat(&jt); + caldat(&jt); + + return (jt.day_of_year - jt.weekday) / 7; } -static const short days_in_year[2][13] = +/* The first array is for non-leap years, the second for leap years*/ +static const int days_in_year[2][13] = { /* jan feb mar apr may jun jul aug sep oct nov dec */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; -/* Returns the day of the year, counting from 1 (Jan 1st). */ -short icaltime_day_of_year(struct icaltimetype t){ - int is_leap = 0; - - if (icaltime_is_leap_year (t.year)) - is_leap = 1; +/** + * Returns the day of the year, counting from 1 (Jan 1st). + */ +int icaltime_day_of_year(const struct icaltimetype t){ + int is_leap = icaltime_is_leap_year (t.year); return days_in_year[is_leap][t.month - 1] + t.day; } - +/** @brief Contructor. + * + * Create a new time, given a day of year and a year. + */ /* Jan 1 is day #1, not 0 */ -struct icaltimetype icaltime_from_day_of_year(short doy, short year) +struct icaltimetype icaltime_from_day_of_year(const int _doy, const int _year) { - struct icaltimetype tt = { 0 }; - int is_leap = 0, month; + struct icaltimetype tt = icaltime_null_date(); + int is_leap; + int month; + int doy = _doy; + int year = _year; + + is_leap = icaltime_is_leap_year(year); + + /* Zero and neg numbers represent days of the previous year */ + if(doy <1){ + year--; + is_leap = icaltime_is_leap_year(year); + doy += days_in_year[is_leap][12]; + } else if(doy > days_in_year[is_leap][12]){ + /* Move on to the next year*/ + is_leap = icaltime_is_leap_year(year); + doy -= days_in_year[is_leap][12]; + year++; + } tt.year = year; - if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) - is_leap = 1; - - assert(doy > 0); - assert(doy <= days_in_year[is_leap][12]); for (month = 11; month >= 0; month--) { if (doy > days_in_year[is_leap][month]) { tt.month = month + 1; tt.day = doy - days_in_year[is_leap][month]; - return tt; + break; } } - /* Shouldn't reach here. */ - assert (0); + return tt; } -struct icaltimetype icaltime_null_time() +/** @brief Constructor. + * + * Return a null time, which is guaranteed not to be equal to any other time. + */ +struct icaltimetype icaltime_null_time(void) { struct icaltimetype t; memset(&t,0,sizeof(struct icaltimetype)); @@ -553,8 +598,35 @@ struct icaltimetype icaltime_null_time() return t; } +/** @brief Constructor. + * + * Return a null date. + */ +struct icaltimetype icaltime_null_date(void) +{ + struct icaltimetype t; + memset(&t,0,sizeof(struct icaltimetype)); + + t.is_date = 1; -int icaltime_is_valid_time(struct icaltimetype t){ + /* + * Init to -1 to match what icalyacc.y used to do. + * Does anything depend on this? + */ + t.hour = -1; + t.minute = -1; + t.second = -1; + + return t; +} + + +/** + * Returns false if the time is clearly invalid, but is not null. This + * is usually the result of creating a new time type buy not clearing + * it, or setting one of the flags to an illegal value. + */ +int icaltime_is_valid_time(const struct icaltimetype t){ if(t.is_utc > 1 || t.is_utc < 0 || t.year < 0 || t.year > 3000 || t.is_date > 1 || t.is_date < 0){ @@ -565,7 +637,26 @@ int icaltime_is_valid_time(struct icaltimetype t){ } -int icaltime_is_null_time(struct icaltimetype t) +/** @brief Returns true if time is a DATE + */ +int icaltime_is_date(const struct icaltimetype t) { + + return t.is_date; +} + +/** @brief Returns true if time is relative to UTC zone + * + * @todo We should only check the zone + */ +int icaltime_is_utc(const struct icaltimetype t) { + + return t.is_utc; +} + +/** + * Return true if the time is null. + */ +int icaltime_is_null_time(const struct icaltimetype t) { if (t.second +t.minute+t.hour+t.day+t.month+t.year == 0){ return 1; @@ -575,9 +666,19 @@ int icaltime_is_null_time(struct icaltimetype t) } -int icaltime_compare(struct icaltimetype a, struct icaltimetype b) +/** + * Return -1, 0, or 1 to indicate that a<b, a==b, or a>b. + * This calls icaltime_compare function after converting them to the utc + * timezone. + */ + +int icaltime_compare(const struct icaltimetype a_in, const struct icaltimetype b_in) { - int retval; + int retval = 0; + struct icaltimetype a, b; + + a = icaltime_convert_to_zone(a_in, icaltimezone_get_utc_timezone()); + b = icaltime_convert_to_zone(b_in, icaltimezone_get_utc_timezone()); if (a.year > b.year) retval = 1; @@ -594,6 +695,21 @@ int icaltime_compare(struct icaltimetype a, struct icaltimetype b) else if (a.day < b.day) retval = -1; + /* if both are dates, we are done */ + if (a.is_date && b.is_date) + return retval; + + /* else, if we already found a difference, we are done */ + else if (retval != 0) + return retval; + + /* else, if only one is a date (and we already know the date part is equal), + then the other is greater */ + else if (b.is_date) + retval = 1; + else if (a.is_date) + retval = -1; + else if (a.hour > b.hour) retval = 1; else if (a.hour < b.hour) @@ -609,16 +725,21 @@ int icaltime_compare(struct icaltimetype a, struct icaltimetype b) else if (a.second < b.second) retval = -1; - else - retval = 0; - return retval; } +/** + * like icaltime_compare, but only use the date parts. + */ + int -icaltime_compare_date_only (struct icaltimetype a, struct icaltimetype b) +icaltime_compare_date_only(const struct icaltimetype a_in, const struct icaltimetype b_in) { int retval; + struct icaltimetype a, b; + + a = icaltime_convert_to_zone(a_in, icaltimezone_get_utc_timezone()); + b = icaltime_convert_to_zone(b_in, icaltimezone_get_utc_timezone()); if (a.year > b.year) retval = 1; @@ -650,20 +771,24 @@ struct icaldurationtype icaltime_subtract(struct icaltimetype t1, -/* Adds (or subtracts) a time from a icaltimetype. - NOTE: This function is exactly the same as icaltimezone_adjust_change() - except for the type of the first parameter. */ +/** @brief Internal, shouldn't be part of the public API + * + * Adds (or subtracts) a time from a icaltimetype. + * NOTE: This function is exactly the same as icaltimezone_adjust_change() + * except for the type of the first parameter. + */ void -icaltime_adjust (struct icaltimetype *tt, - int days, - int hours, - int minutes, - int seconds) -{ +icaltime_adjust(struct icaltimetype *tt, const int days, const int hours, + const int minutes, const int seconds) { + int second, minute, hour, day; - int minutes_overflow, hours_overflow, days_overflow, years_overflow; + int minutes_overflow, hours_overflow, days_overflow = 0, years_overflow; int days_in_month; + /* If we are passed a date make sure to ignore hour minute and second */ + if (tt->is_date) + goto IS_DATE; + /* Add on the seconds. */ second = tt->second + seconds; tt->second = second % 60; @@ -691,6 +816,7 @@ icaltime_adjust (struct icaltimetype *tt, days_overflow--; } +IS_DATE: /* Normalize the month. We do this before handling the day since we may need to know what month it is to get the number of days in it. Note that months are 1 to 12, so we have to be a bit careful. */ @@ -735,3 +861,190 @@ icaltime_adjust (struct icaltimetype *tt, } tt->day = day; } + +/** @brief Convert time to a given timezone + * + * Convert a time from its native timezone to a given timezone. + * + * If tt is a date, the returned time is an exact + * copy of the input. If it's a floating time, the returned object + * represents the same time translated to the given timezone. + * Otherwise the time will be converted to the new + * time zone, and its native timezone set to the right timezone. + */ +struct icaltimetype icaltime_convert_to_zone(const struct icaltimetype tt, + icaltimezone *zone) { + + struct icaltimetype ret = tt; + + /* If it's a date do nothing */ + if (tt.is_date) { + return ret; + } + + if (tt.zone == zone) { + return ret; + } + + /* If it's a floating time we don't want to adjust the time */ + if (tt.zone != NULL) { + icaltimezone_convert_time(&ret, tt.zone, zone); + } + + ret.zone = zone; + if (zone == icaltimezone_get_utc_timezone()) { + ret.is_utc = 1; + } else { + ret.is_utc = 0; + } + + return ret; +} + +const icaltimezone * +icaltime_get_timezone(const struct icaltimetype t) { + + return t.zone; +} + +char * +icaltime_get_tzid(const struct icaltimetype t) { + + if (t.zone != NULL) { + return icaltimezone_get_tzid(t.zone); + } else { + return NULL; + } +} + +/** @brief Set the timezone + * + * Force the icaltime to be interpreted relative to another timezone. + * If you need to do timezone conversion, applying offset adjustments, + * then you should use icaltime_convert_to_timezone instead. + */ +struct icaltimetype +icaltime_set_timezone(struct icaltimetype *t, const icaltimezone *zone) { + + /* If it's a date do nothing */ + if (t->is_date) { + return *t; + } + + if (t->zone == zone) { + return *t; + } + + t->zone = zone; + if (zone == icaltimezone_get_utc_timezone()) { + t->is_utc = 1; + } else { + t->is_utc = 0; + } + + return *t; +} + + +/** + * @brief builds an icaltimespan given a start time, end time and busy value. + * + * @param dtstart The beginning time of the span, can be a date-time + * or just a date. + * @param dtend The end time of the span. + * @param is_busy A boolean value, 0/1. + * @return A span using the supplied values. + * + * returned span contains times specified in UTC. + */ + +icaltime_span icaltime_span_new(struct icaltimetype dtstart, + struct icaltimetype dtend, + int is_busy) +{ + icaltime_span span; + + span.is_busy = is_busy; + + span.start = icaltime_as_timet_with_zone(dtstart, + icaltimezone_get_utc_timezone()); + + if (icaltime_is_null_time(dtend)) { + if (!icaltime_is_date(dtstart)) { + /* If dtstart is a DATE-TIME and there is no DTEND nor DURATION + it takes no time */ + span.end = span.start; + return span; + } else { + dtend = dtstart; + } + } + + span.end = icaltime_as_timet_with_zone(dtend, icaltimezone_get_utc_timezone()); + + if (icaltime_is_date(dtstart)) { + /* no time specified, go until the end of the day..*/ + span.end += 60*60*24 - 1; + } + return span; +} + + +/** @brief Returns true if the two spans overlap + * + * @param s1 1st span to test + * @param s2 2nd span to test + * @return boolean value + * + * The result is calculated by testing if the start time of s1 is contained + * by the s2 span, or if the end time of s1 is contained by the s2 span. + * + * Also returns true if the spans are equal. + * + * Note, this will return false if the spans are adjacent. + */ + +int icaltime_span_overlaps(icaltime_span *s1, + icaltime_span *s2) +{ + /* s1->start in s2 */ + if (s1->start > s2->start && s1->start < s2->end) + return 1; + + /* s1->end in s2 */ + if (s1->end > s2->start && s1->end < s2->end) + return 1; + + /* s2->start in s1 */ + if (s2->start > s1->start && s2->start < s1->end) + return 1; + + /* s2->end in s1 */ + if (s2->end > s1->start && s2->end < s1->end) + return 1; + + if (s1->start == s2->start && s1->end == s2->end) + return 1; + + return 0; +} + +/** @brief Returns true if the span is totally within the containing + * span + * + * @param s The span to test for. + * @param container The span to test against. + * @return boolean value. + * + */ + +int icaltime_span_contains(icaltime_span *s, + icaltime_span *container) +{ + + if ((s->start >= container->start && s->start < container->end) && + (s->end <= container->end && s->end > container->start)) + return 1; + + return 0; +} diff --git a/libical/src/libical/icaltime.h b/libical/src/libical/icaltime.h index b2a536b2b5..7b7374f5df 100644 --- a/libical/src/libical/icaltime.h +++ b/libical/src/libical/icaltime.h @@ -26,6 +26,70 @@ ======================================================================*/ +/** @file icaltime.h + * @brief struct icaltimetype is a pseudo-object that abstracts time + * handling. + * + * It can represent either a DATE or a DATE-TIME (floating, UTC or in a + * given timezone), and it keeps track internally of its native timezone. + * + * The typical usage is to call the correct constructor specifying the + * desired timezone. If this is not known until a later time, the + * correct behavior is to specify a NULL timezone and call + * icaltime_convert_to_zone() at a later time. + * + * There are several ways to create a new icaltimetype: + * + * - icaltime_null_time() + * - icaltime_null_date() + * - icaltime_current_time_with_zone() + * - icaltime_today() + * - icaltime_from_timet_with_zone(time_t tm, int is_date, + * icaltimezone *zone) + * - icaltime_from_string_with_zone(const char* str, icaltimezone *zone) + * - icaltime_from_day_of_year(int doy, int year) + * - icaltime_from_week_number(int week_number, int year) + * + * italtimetype objects can be converted to different formats: + * + * - icaltime_as_timet(struct icaltimetype tt) + * - icaltime_as_timet_with_zone(struct icaltimetype tt, + * icaltimezone *zone) + * - icaltime_as_ical_string(struct icaltimetype tt) + * + * Accessor methods include: + * + * - icaltime_get_timezone(struct icaltimetype t) + * - icaltime_get_tzid(struct icaltimetype t) + * - icaltime_set_timezone(struct icaltimetype t, const icaltimezone *zone) + * - icaltime_day_of_year(struct icaltimetype t) + * - icaltime_day_of_week(struct icaltimetype t) + * - icaltime_start_doy_week(struct icaltimetype t, int fdow) + * - icaltime_week_number(struct icaltimetype t) + * + * Query methods include: + * + * - icaltime_is_null_time(struct icaltimetype t) + * - icaltime_is_valid_time(struct icaltimetype t) + * - icaltime_is_date(struct icaltimetype t) + * - icaltime_is_utc(struct icaltimetype t) + * - icaltime_is_floating(struct icaltimetype t) + * + * Modify, compare and utility methods include: + * + * - icaltime_add(struct icaltimetype t, struct icaldurationtype d) + * - icaltime_subtract(struct icaltimetype t1, struct icaltimetype t2) + * - icaltime_compare_with_zone(struct icaltimetype a,struct icaltimetype b) + * - icaltime_compare(struct icaltimetype a,struct icaltimetype b) + * - icaltime_compare_date_only(struct icaltimetype a, + * struct icaltimetype b) + * - icaltime_adjust(struct icaltimetype *tt, int days, int hours, + * int minutes, int seconds); + * - icaltime_normalize(struct icaltimetype t); + * - icaltime_convert_to_zone(const struct icaltimetype tt, + * icaltimezone *zone); + */ + #ifndef ICALTIME_H #define ICALTIME_H @@ -33,124 +97,181 @@ /* An opaque struct representing a timezone. We declare this here to avoid a circular dependancy. */ -#ifndef ICALTIMEONE_DEFINED -#define ICALTIMEONE_DEFINED +#ifndef ICALTIMEZONE_DEFINED +#define ICALTIMEZONE_DEFINED typedef struct _icaltimezone icaltimezone; #endif -/* icaltime_span is returned by icalcomponent_get_span() */ +/** icaltime_span is returned by icalcomponent_get_span() */ struct icaltime_span { - time_t start; /* in UTC */ - time_t end; /* in UTC */ - int is_busy; /* 1->busy time, 0-> free time */ + time_t start; /**< in UTC */ + time_t end; /**< in UTC */ + int is_busy; /**< 1->busy time, 0-> free time */ }; +typedef struct icaltime_span icaltime_span; +/* + * FIXME + * + * is_utc is redundant, and might be considered a minor optimization. + * It might be deprecated, so you should use icaltime_is_utc() instead. + */ struct icaltimetype { - int year; /* Actual year, e.g. 2001. */ - int month; /* 1 (Jan) to 12 (Dec). */ + int year; /**< Actual year, e.g. 2001. */ + int month; /**< 1 (Jan) to 12 (Dec). */ 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. */ + int is_utc; /**< 1-> time is in UTC timezone */ - int is_daylight; /* 1 -> time is in daylight savings time. */ + int is_date; /**< 1 -> interpret this as date. */ - const char* zone; /*Ptr to Olsen placename. Libical does not own mem*/ + int is_daylight; /**< 1 -> time is in daylight savings time. */ + + const icaltimezone *zone; /**< timezone */ }; -/* Convert seconds past UNIX epoch to a timetype*/ -struct icaltimetype icaltime_from_timet(time_t v, int is_date); +typedef struct icaltimetype icaltimetype; -/* Newer version of above, using timezones. */ -struct icaltimetype icaltime_from_timet_with_zone(time_t tm, int is_date, - icaltimezone *zone); +/** Return a null time, which indicates no time has been set. + This time represent the beginning of the epoch */ +struct icaltimetype icaltime_null_time(void); -/* Returns the current time in the given timezone, as an icaltimetype. */ -struct icaltimetype icaltime_current_time_with_zone(icaltimezone *zone); +/** Return a null date */ +struct icaltimetype icaltime_null_date(void); -/* Returns the current day as an icaltimetype, with is_date set. */ +/** Returns the current time in the given timezone, as an icaltimetype. */ +struct icaltimetype icaltime_current_time_with_zone(const icaltimezone *zone); + +/** Returns the current day as an icaltimetype, with is_date set. */ struct icaltimetype icaltime_today(void); -/* Return the time as seconds past the UNIX epoch */ -time_t icaltime_as_timet(struct icaltimetype); +/** Convert seconds past UNIX epoch to a timetype*/ +struct icaltimetype icaltime_from_timet(const time_t v, const int is_date); + +/** Convert seconds past UNIX epoch to a timetype, using timezones. */ +struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, + const int is_date, const icaltimezone *zone); -/* Newer version of above, using timezones. */ -time_t icaltime_as_timet_with_zone(struct icaltimetype tt, icaltimezone *zone); +/** create a time from an ISO format string */ +struct icaltimetype icaltime_from_string(const char* str); -/* Return a string represention of the time, in RFC2445 format. The +/** create a time from an ISO format string */ +struct icaltimetype icaltime_from_string_with_zone(const char* str, + const icaltimezone *zone); + +/** Create a new time, given a day of year and a year. */ +struct icaltimetype icaltime_from_day_of_year(const int doy, + const int year); + +/** @brief Contructor (TODO). + * Create a new time from a weeknumber and a year. */ +struct icaltimetype icaltime_from_week_number(const int week_number, + const int year); + +/** Return the time as seconds past the UNIX epoch */ +time_t icaltime_as_timet(const struct icaltimetype); + +/** Return the time as seconds past the UNIX epoch, using timezones. */ +time_t icaltime_as_timet_with_zone(const struct icaltimetype tt, + const icaltimezone *zone); + +/** Return a string represention of the time, in RFC2445 format. The string is owned by libical */ -char* icaltime_as_ical_string(struct icaltimetype tt); +const char* icaltime_as_ical_string(const struct icaltimetype tt); -/* Like icaltime_from_timet(), except that the input may be in seconds - past the epoch in floating time. This routine is deprecated */ -struct icaltimetype icaltime_from_int(int v, int is_date, int is_utc); +/** @brief Return the timezone */ +const icaltimezone *icaltime_get_timezone(const struct icaltimetype t); -/* Like icaltime_as_timet, but in a floating epoch. This routine is deprecated */ -int icaltime_as_int(struct icaltimetype); +/** @brief Return the tzid, or NULL for a floating time */ +char *icaltime_get_tzid(const struct icaltimetype t); -/* create a time from an ISO format string */ -struct icaltimetype icaltime_from_string(const char* str); +/** @brief Set the timezone */ +struct icaltimetype icaltime_set_timezone(struct icaltimetype *t, + const icaltimezone *zone); -/* Return a null time, which indicates no time has been set. This time represent the beginning of the epoch */ -struct icaltimetype icaltime_null_time(void); +/** Return the day of the year of the given time */ +int icaltime_day_of_year(const struct icaltimetype t); + +/** Return the day of the week of the given time. Sunday is 1 */ +int icaltime_day_of_week(const struct icaltimetype t); + +/** Return the day of the year for the Sunday of the week that the + given time is within. */ +int icaltime_start_doy_of_week(const struct icaltimetype t); + +/** Return the day of the year for the first day of the week that the + given time is within. */ +int icaltime_start_doy_week(const struct icaltimetype t, int fdow); -/* Return true of the time is null. */ -int icaltime_is_null_time(struct icaltimetype t); +/** Return the week number for the week the given time is within */ +int icaltime_week_number(const struct icaltimetype t); -/* Returns false if the time is clearly invalid, but is not null. This +/** Return true of the time is null. */ +int icaltime_is_null_time(const struct icaltimetype t); + +/** Returns false if the time is clearly invalid, but is not null. This is usually the result of creating a new time type buy not clearing it, or setting one of the flags to an illegal value. */ -int icaltime_is_valid_time(struct icaltimetype t); +int icaltime_is_valid_time(const struct icaltimetype t); -/* Reset all of the time components to be in their normal ranges. For - instance, given a time with minutes=70, the minutes will be reduces - to 10, and the hour incremented. This allows the caller to do - arithmetic on times without worrying about overflow or - underflow. */ -struct icaltimetype icaltime_normalize(struct icaltimetype t); +/** @brief Returns true if time is of DATE type, false if DATE-TIME */ +int icaltime_is_date(const struct icaltimetype t); -/* Return the day of the year of the given time */ -short icaltime_day_of_year(struct icaltimetype t); +/** @brief Returns true if time is relative to UTC zone */ +int icaltime_is_utc(const struct icaltimetype t); -/* Create a new time, given a day of year and a year. */ -struct icaltimetype icaltime_from_day_of_year(short doy, short year); +/** @brief Returns true if time is a floating time */ +int icaltime_is_floating(const struct icaltimetype t); -/* Return the day of the week of the given time. Sunday is 1 */ -short icaltime_day_of_week(struct icaltimetype t); +/** Return -1, 0, or 1 to indicate that a<b, a==b or a>b */ +int icaltime_compare_with_zone(const struct icaltimetype a, + const struct icaltimetype b); -/* Return the day of the year for the Sunday of the week that the - given time is within. */ -short icaltime_start_doy_of_week(struct icaltimetype t); +/** Return -1, 0, or 1 to indicate that a<b, a==b or a>b */ +int icaltime_compare(const struct icaltimetype a, + const struct icaltimetype b); -/* Return a string with the time represented in the same format as ctime(). THe string is owned by libical */ -char* icaltime_as_ctime(struct icaltimetype); +/** like icaltime_compare, but only use the date parts. */ +int icaltime_compare_date_only(const struct icaltimetype a, + const struct icaltimetype b); -/* Return the week number for the week the given time is within */ -short icaltime_week_number(struct icaltimetype t); +/** Adds or subtracts a number of days, hours, minutes and seconds. */ +void icaltime_adjust(struct icaltimetype *tt, const int days, + const int hours, const int minutes, const int seconds); -/* Create a new time from a weeknumber and a year. */ -struct icaltimetype icaltime_from_week_number(short week_number, short year); +/** Normalize the icaltime, so that all fields are within the normal range. */ +struct icaltimetype icaltime_normalize(const struct icaltimetype t); -/* Return -1, 0, or 1 to indicate that a<b, a==b or a>b */ -int icaltime_compare(struct icaltimetype a,struct icaltimetype b); +/** convert tt, of timezone tzid, into a utc time. Does nothing if the + time is already UTC. */ +struct icaltimetype icaltime_convert_to_zone(const struct icaltimetype tt, + icaltimezone *zone); -/* like icaltime_compare, but only use the date parts. */ -int icaltime_compare_date_only(struct icaltimetype a, struct icaltimetype b); +/** Return the number of days in the given month */ +int icaltime_days_in_month(const int month, const int year); -/* Return the number of days in the given month */ -short icaltime_days_in_month(short month,short year); -/* Adds or subtracts a number of days, hours, minutes and seconds. */ -void icaltime_adjust(struct icaltimetype *tt, int days, int hours, - int minutes, int seconds); +/** @brief calculate an icaltimespan given a start and end time. */ +struct icaltime_span icaltime_span_new(struct icaltimetype dtstart, + struct icaltimetype dtend, + int is_busy); -#endif /* !ICALTIME_H */ +/** @brief Returns true if the two spans overlap **/ +int icaltime_span_overlaps(icaltime_span *s1, + icaltime_span *s2); +/** @brief Returns true if the span is totally within the containing + * span + */ +int icaltime_span_contains(icaltime_span *s, + icaltime_span *container); + + +#endif /* !ICALTIME_H */ diff --git a/libical/src/libical/icaltimezone.c b/libical/src/libical/icaltimezone.c index 8841584d9e..c1c5e52785 100644 --- a/libical/src/libical/icaltimezone.c +++ b/libical/src/libical/icaltimezone.c @@ -1,9 +1,8 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /*====================================================================== - FILE: icaltimezone.h + FILE: icaltimezone.c CREATOR: Damon Chaplin 15 March 2001 - $Id$ $Locker$ @@ -23,6 +22,10 @@ ======================================================================*/ +/** @file icaltimezone.c + * @brief implementation of timezone handling routines + **/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -36,104 +39,109 @@ #include "icalparser.h" #include "icaltimezone.h" -/* This is the toplevel directory where the timezone data is installed in. */ +#ifdef WIN32 +#define snprintf _snprintf +#define PACKAGE_DATA_DIR "/Projects/libical" +#endif + +/** This is the toplevel directory where the timezone data is installed in. */ #define ZONEINFO_DIRECTORY PACKAGE_DATA_DIR "/zoneinfo" -/* The prefix we use to uniquely identify TZIDs. */ +/** The prefix we use to uniquely identify TZIDs. */ #define TZID_PREFIX "/softwarestudio.org/" #define TZID_PREFIX_LEN 20 -/* This is the filename of the file containing the city names and coordinates - of all the builtin timezones. */ +/** This is the filename of the file containing the city names and + coordinates of all the builtin timezones. */ #define ZONES_TAB_FILENAME "zones.tab" -/* This is the number of years of extra coverage we do when expanding the - timezone changes. */ +/** This is the number of years of extra coverage we do when expanding + the timezone changes. */ #define ICALTIMEZONE_EXTRA_COVERAGE 5 -/* This is the maximum year we will expand to. time_t values only go up to - somewhere around 2037. */ -#define ICALTIMEZONE_MAX_YEAR 2037 - +/** This is the maximum year we will expand to. time_t values only go up to + somewhere around 2037. */ +#define ICALTIMEZONE_MAX_YEAR 2035 struct _icaltimezone { - /* The unique ID of this timezone, - e.g. "/softwarestudio.org/Olson_20010601_1/Africa/Banjul". - This should only be used to identify a VTIMEZONE. It is not meant to - be displayed to the user in any form. */ char *tzid; + /**< The unique ID of this timezone, + e.g. "/softwarestudio.org/Olson_20010601_1/Africa/Banjul". + This should only be used to identify a VTIMEZONE. It is not + meant to be displayed to the user in any form. */ - /* The location for the timezone, e.g. "Africa/Accra" for the Olson - database. We look for this in the "LOCATION" or "X-LIC-LOCATION" - properties of the VTIMEZONE component. It isn't a standard property - yet. This will be NULL if no location is found in the VTIMEZONE. */ char *location; + /**< The location for the timezone, e.g. "Africa/Accra" for the + Olson database. We look for this in the "LOCATION" or + "X-LIC-LOCATION" properties of the VTIMEZONE component. It + isn't a standard property yet. This will be NULL if no location + is found in the VTIMEZONE. */ - /* This will be set to a combination of the TZNAME properties from the last - STANDARD and DAYLIGHT components in the VTIMEZONE, e.g. "EST/EDT". - If they both use the same TZNAME, or only one type of component is - found, then only one TZNAME will appear, e.g. "AZOT". If no TZNAME - is found this will be NULL. */ char *tznames; + /**< This will be set to a combination of the TZNAME properties + from the last STANDARD and DAYLIGHT components in the + VTIMEZONE, e.g. "EST/EDT". If they both use the same TZNAME, + or only one type of component is found, then only one TZNAME + will appear, e.g. "AZOT". If no TZNAME is found this will be + NULL. */ - /* The coordinates of the city, in degrees. */ double latitude; double longitude; + /**< The coordinates of the city, in degrees. */ - /* The toplevel VTIMEZONE component loaded from the .ics file for this - timezone. If we need to regenerate the changes data we need this. */ icalcomponent *component; + /**< The toplevel VTIMEZONE component loaded from the .ics file for this + timezone. If we need to regenerate the changes data we need this. */ - /* If this is not NULL it points to the builtin icaltimezone that the - above TZID refers to. This icaltimezone should be used instead when - accessing the timezone changes data, so that the expanded timezone - changes data is shared between calendar components. (I don't think - we actually use this at present.) */ icaltimezone *builtin_timezone; + /**< If this is not NULL it points to the builtin icaltimezone + that the above TZID refers to. This icaltimezone should be used + instead when accessing the timezone changes data, so that the + expanded timezone changes data is shared between calendar + components. */ - /* This is the last year for which we have expanded the data to. + int end_year; + /**< This is the last year for which we have expanded the data to. If we need to calculate a date past this we need to expand the timezone component data from scratch. */ - int end_year; - /* A dynamically-allocated array of time zone changes, sorted by the + icalarray *changes; + /**< A dynamically-allocated array of time zone changes, sorted by the time of the change in local time. So we can do fast binary-searches to convert from local time to UTC. */ - icalarray *changes; }; - typedef struct _icaltimezonechange icaltimezonechange; struct _icaltimezonechange { - /* The offset to add to UTC to get local time, in seconds. */ int utc_offset; + /**< The offset to add to UTC to get local time, in seconds. */ - /* The offset to add to UTC, before this change, in seconds. */ int prev_utc_offset; - - /* The time that the change came into effect, in UTC. + /**< The offset to add to UTC, before this change, in seconds. */ + + int year; /**< Actual year, e.g. 2001. */ + int month; /**< 1 (Jan) to 12 (Dec). */ + int day; + int hour; + int minute; + int second; + /**< The time that the change came into effect, in UTC. Note that the prev_utc_offset applies to this local time, since we haven't changed to the new offset yet. */ - int year; /* Actual year, e.g. 2001. */ - char month; /* 1 (Jan) to 12 (Dec). */ - char day; - char hour; - char minute; - char second; - - /* Whether this is STANDARD or DAYLIGHT time. */ - char is_daylight; -}; + int is_daylight; + /**< Whether this is STANDARD or DAYLIGHT time. */ +}; -/* An array of icaltimezones for the builtin timezones. */ -icalarray *builtin_timezones = NULL; -/* This is the special UTC timezone, which isn't in builtin_timezones. */ -icaltimezone utc_timezone = { 0 }; +/** An array of icaltimezones for the builtin timezones. */ +static icalarray *builtin_timezones = NULL; +/** This is the special UTC timezone, which isn't in builtin_timezones. */ +static icaltimezone utc_timezone = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static char* zone_files_directory = NULL; static void icaltimezone_reset (icaltimezone *zone); static char* icaltimezone_get_location_from_vtimezone (icalcomponent *component); @@ -157,7 +165,7 @@ static void icaltimezone_adjust_change (icaltimezonechange *tt, static void icaltimezone_init (icaltimezone *zone); -/* Gets the TZID, LOCATION/X-LIC-LOCATION, and TZNAME properties from the +/** Gets the TZID, LOCATION/X-LIC-LOCATION, and TZNAME properties from the VTIMEZONE component and places them in the icaltimezone. It returns 1 on success, or 0 if the TZID can't be found. */ static int icaltimezone_get_vtimezone_properties (icaltimezone *zone, @@ -181,8 +189,10 @@ static char* icaltimezone_load_get_line_fn (char *s, static void format_utc_offset (int utc_offset, char *buffer); +static char* get_zone_directory(void); + -/* Creates a new icaltimezone. */ +/** Creates a new icaltimezone. */ icaltimezone* icaltimezone_new (void) { @@ -191,7 +201,7 @@ icaltimezone_new (void) zone = (icaltimezone*) malloc (sizeof (icaltimezone)); if (!zone) { icalerror_set_errno (ICAL_NEWFAILED_ERROR); - return; + return NULL; } icaltimezone_init (zone); @@ -200,7 +210,7 @@ icaltimezone_new (void) } -/* Frees all memory used for the icaltimezone. */ +/** Frees all memory used for the icaltimezone. */ void icaltimezone_free (icaltimezone *zone, int free_struct) @@ -211,26 +221,26 @@ icaltimezone_free (icaltimezone *zone, } -/* Resets the icaltimezone to the initial state, freeing most of the fields. */ +/** Resets the icaltimezone to the initial state, freeing most of the fields. */ static void icaltimezone_reset (icaltimezone *zone) { if (zone->tzid) - free (zone->tzid); + free (zone->tzid); if (zone->location) - free (zone->location); + free (zone->location); if (zone->tznames) - free (zone->tznames); + free (zone->tznames); if (zone->component) - icalcomponent_free (zone->component); + icalcomponent_free (zone->component); if (zone->changes) - icalarray_free (zone->changes); - + icalarray_free (zone->changes); + icaltimezone_init (zone); } -/* Initializes an icaltimezone. */ +/** Initializes an icaltimezone. */ static void icaltimezone_init (icaltimezone *zone) { @@ -246,17 +256,17 @@ icaltimezone_init (icaltimezone *zone) } -/* Gets the TZID, LOCATION/X-LIC-LOCATION and TZNAME properties of the - VTIMEZONE component and stores them in the icaltimezone. - It returns 1 on success, or 0 if the TZID can't be found. - Note that it expects the zone to be initialized or reset - it doesn't free +/** Gets the TZID, LOCATION/X-LIC-LOCATION and TZNAME properties of + the VTIMEZONE component and stores them in the icaltimezone. It + returns 1 on success, or 0 if the TZID can't be found. Note that + it expects the zone to be initialized or reset - it doesn't free any old values. */ static int icaltimezone_get_vtimezone_properties (icaltimezone *zone, icalcomponent *component) { icalproperty *prop; - const char *tzid, *location; + const char *tzid; prop = icalcomponent_get_first_property (component, ICAL_TZID_PROPERTY); if (!prop) @@ -267,25 +277,22 @@ icaltimezone_get_vtimezone_properties (icaltimezone *zone, if (!tzid) return 0; - if (zone->location) - free (zone->location); - zone->tzid = strdup (tzid); zone->component = component; + if ( zone->location != 0 ) free ( zone->location ); zone->location = icaltimezone_get_location_from_vtimezone (component); zone->tznames = icaltimezone_get_tznames_from_vtimezone (component); return 1; } -/* Gets the LOCATION or X-LIC-LOCATION property from a VTIMEZONE. */ +/** Gets the LOCATION or X-LIC-LOCATION property from a VTIMEZONE. */ static char* icaltimezone_get_location_from_vtimezone (icalcomponent *component) { icalproperty *prop; const char *location; - char *name; - int found_location = 0; + const char *name; prop = icalcomponent_get_first_property (component, ICAL_LOCATION_PROPERTY); @@ -311,10 +318,11 @@ icaltimezone_get_location_from_vtimezone (icalcomponent *component) } -/* Gets the TZNAMEs used for the last STANDARD & DAYLIGHT components in a - VTIMEZONE. If both STANDARD and DAYLIGHT components use the same TZNAME, - it returns that. If they use different TZNAMEs, it formats them like - "EST/EDT". The returned string should be freed by the caller. */ +/** Gets the TZNAMEs used for the last STANDARD & DAYLIGHT components + in a VTIMEZONE. If both STANDARD and DAYLIGHT components use the + same TZNAME, it returns that. If they use different TZNAMEs, it + formats them like "EST/EDT". The returned string should be freed by + the caller. */ static char* icaltimezone_get_tznames_from_vtimezone (icalcomponent *component) { @@ -328,6 +336,9 @@ icaltimezone_get_tznames_from_vtimezone (icalcomponent *component) struct icaltimetype standard_max_date, daylight_max_date; struct icaltimetype current_max_date; + standard_max_date = icaltime_null_time(); + daylight_max_date = icaltime_null_time(); + /* Step through the STANDARD & DAYLIGHT subcomponents. */ comp = icalcomponent_get_first_component (component, ICAL_ANY_COMPONENT); while (comp) { @@ -399,7 +410,7 @@ icaltimezone_get_tznames_from_vtimezone (icalcomponent *component) /* If both standard and daylight TZNAMEs were found, if they are the same we return just one, else we format them like "EST/EDT". */ if (standard_tzname && daylight_tzname) { - int standard_len, daylight_len; + unsigned int standard_len, daylight_len; char *tznames; if (!strcmp (standard_tzname, daylight_tzname)) @@ -436,12 +447,8 @@ icaltimezone_ensure_coverage (icaltimezone *zone, icaltimezone_load_builtin_timezone (zone); if (icaltimezone_minimum_expansion_year == -1) { - struct tm *tmp_tm; - time_t t; - - t = time (NULL); - tmp_tm = localtime (&t); - icaltimezone_minimum_expansion_year = tmp_tm->tm_year + 1900; + struct icaltimetype today = icaltime_today(); + icaltimezone_minimum_expansion_year = today.year; } changes_end_year = end_year; @@ -598,7 +605,7 @@ icaltimezone_expand_vtimezone (icalcomponent *comp, change.day = rdate.time.day; /* RDATEs with a DATE value inherit the time from the DTSTART. */ - if (rdate.time.is_date) { + if (icaltime_is_date(rdate.time)) { change.hour = dtstart.hour; change.minute = dtstart.minute; change.second = dtstart.second; @@ -610,7 +617,7 @@ icaltimezone_expand_vtimezone (icalcomponent *comp, /* The spec was a bit vague about whether RDATEs were in local time or UTC so we support both to be safe. So if it is in UTC we have to add the UTC offset to get a local time. */ - if (!rdate.time.is_utc) + if (!icaltime_is_utc(rdate.time)) icaltimezone_adjust_change (&change, 0, 0, 0, -change.prev_utc_offset); } @@ -678,7 +685,7 @@ icaltimezone_expand_vtimezone (icalcomponent *comp, } -/* A function to compare 2 icaltimezonechange elements, used for qsort(). */ +/** A function to compare 2 icaltimezonechange elements, used for qsort(). */ static int icaltimezone_compare_change_fn (const void *elem1, const void *elem2) @@ -736,7 +743,7 @@ icaltimezone_convert_time (struct icaltimetype *tt, /* If the time is a DATE value or both timezones are the same, or we are converting a floating time, we don't need to do anything. */ - if (tt->is_date || from_zone == to_zone || from_zone == NULL) + if (icaltime_is_date(*tt) || from_zone == to_zone || from_zone == NULL) return; /* Convert the time to UTC by getting the UTC offset and subtracting it. */ @@ -754,10 +761,12 @@ icaltimezone_convert_time (struct icaltimetype *tt, - -/* Calculates the UTC offset of a given local time in the given timezone. - It is the number of seconds to add to UTC to get local time. - The is_daylight flag is set to 1 if the time is in daylight-savings time. */ +/** @deprecated This API wasn't updated when we changed icaltimetype to contain its own + timezone. Also, this takes a pointer instead of the struct. */ +/* Calculates the UTC offset of a given local time in the given + timezone. It is the number of seconds to add to UTC to get local + time. The is_daylight flag is set to 1 if the time is in + daylight-savings time. */ int icaltimezone_get_utc_offset (icaltimezone *zone, struct icaltimetype *tt, @@ -766,7 +775,10 @@ icaltimezone_get_utc_offset (icaltimezone *zone, icaltimezonechange *zone_change, *prev_zone_change, tt_change, tmp_change; int change_num, step, utc_offset_change, cmp; int change_num_to_use; - char want_daylight; + int want_daylight; + + if (tt == NULL) + return 0; if (is_daylight) *is_daylight = 0; @@ -842,18 +854,16 @@ icaltimezone_get_utc_offset (icaltimezone *zone, /* If we are stepping backwards through the changes and we have found a change that applies, then we know this is the change to use so we exit the loop. */ - if (step == -1) { - if (change_num_to_use != -1) - break; - - /* If we go past the start of the changes array, then return the - TZOFFSETFROM of the first change.. */ - if (change_num == 0) - return zone_change->prev_utc_offset; - } + if (step == -1 && change_num_to_use != -1) + break; change_num += step; + /* If we go past the start of the changes array, then we have no data + for this time so we return a UTC offset of 0. */ + if (change_num < 0) + return 0; + if (change_num >= zone->changes->num_elements) break; @@ -878,28 +888,24 @@ icaltimezone_get_utc_offset (icaltimezone *zone, /* The time is in the overlapped region, so we may need to use either the current zone_change or the previous one. If the time has the is_daylight field set we use the matching change, - else we use the change with standard time. Note that iCalendar - doesn't let us distinguish between the different possible - choices here, so it isn't very reliable. Currently the main - use of the is_daylight flag is for testing. */ + else we use the change with standard time. */ prev_zone_change = icalarray_element_at (zone->changes, change_num_to_use - 1); - /* If both possible changes have the same is_daylight setting, - then we choose the last one for now. It looks like the standard - Unix functions choose the each one half the time, so we may - want to try to figure out the rule for doing that. */ - if (zone_change->is_daylight == prev_zone_change->is_daylight) { + /* I was going to add an is_daylight flag to struct icaltimetype, + but iCalendar doesn't let us distinguish between standard and + daylight time anyway, so there's no point. So we just use the + standard time instead. */ + want_daylight = (tt->is_daylight == 1) ? 1 : 0; + #if 0 - printf (" **** Same is_daylight setting (%i). Choosing last change.\n", zone_change->is_daylight); + if (zone_change->is_daylight == prev_zone_change->is_daylight) + printf (" **** Same is_daylight setting\n"); #endif - } else { - want_daylight = (tt->is_daylight == 1) ? 1 : 0; - if (zone_change->is_daylight != want_daylight - && prev_zone_change->is_daylight == want_daylight) - zone_change = prev_zone_change; - } + if (zone_change->is_daylight != want_daylight + && prev_zone_change->is_daylight == want_daylight) + zone_change = prev_zone_change; } } @@ -911,9 +917,12 @@ icaltimezone_get_utc_offset (icaltimezone *zone, } -/* Calculates the UTC offset of a given UTC time in the given timezone. - It is the number of seconds to add to UTC to get local time. - The is_daylight flag is set to 1 if the time is in daylight-savings time. */ +/** @deprecated This API wasn't updated when we changed icaltimetype to contain its own + timezone. Also, this takes a pointer instead of the struct. */ +/** Calculates the UTC offset of a given UTC time in the given + timezone. It is the number of seconds to add to UTC to get local + time. The is_daylight flag is set to 1 if the time is in + daylight-savings time. */ int icaltimezone_get_utc_offset_of_utc_time (icaltimezone *zone, struct icaltimetype *tt, @@ -980,18 +989,16 @@ icaltimezone_get_utc_offset_of_utc_time (icaltimezone *zone, /* If we are stepping backwards through the changes and we have found a change that applies, then we know this is the change to use so we exit the loop. */ - if (step == -1) { - if (change_num_to_use != -1) - break; - - /* If we go past the start of the changes array, then return the - TZOFFSETFROM of the first change.. */ - if (change_num == 0) - return zone_change->prev_utc_offset; - } + if (step == -1 && change_num_to_use != -1) + break; change_num += step; + /* If we go past the start of the changes array, then we have no data + for this time so we return a UTC offset of 0. */ + if (change_num < 0) + return 0; + if (change_num >= zone->changes->num_elements) break; @@ -1012,8 +1019,8 @@ icaltimezone_get_utc_offset_of_utc_time (icaltimezone *zone, } -/* Returns the index of a timezone change which is close to the time given - in change. */ +/** Returns the index of a timezone change which is close to the time + given in change. */ static int icaltimezone_find_nearby_change (icaltimezone *zone, icaltimezonechange *change) @@ -1026,7 +1033,7 @@ icaltimezone_find_nearby_change (icaltimezone *zone, upper = zone->changes->num_elements; while (lower < upper) { - middle = (lower + upper) >> 1; + middle = (lower + upper) / 2; zone_change = icalarray_element_at (zone->changes, middle); cmp = icaltimezone_compare_change_fn (change, zone_change); if (cmp == 0) @@ -1043,9 +1050,9 @@ icaltimezone_find_nearby_change (icaltimezone *zone, -/* Adds (or subtracts) a time from a icaltimezonechange. - NOTE: This function is exactly the same as icaltime_adjust() - except for the type of the first parameter. */ +/** Adds (or subtracts) a time from a icaltimezonechange. NOTE: This + function is exactly the same as icaltime_adjust() except for the + type of the first parameter. */ static void icaltimezone_adjust_change (icaltimezonechange *tt, int days, @@ -1123,12 +1130,7 @@ icaltimezone_get_tzid (icaltimezone *zone) if (!zone) return NULL; - /* Initialize the builtin timezones, to ensure that the UTC timezone has - its TZID set. */ - if (!builtin_timezones) - icaltimezone_init_builtin_timezones (); - - if (!zone->component) + if (!zone->tzid) icaltimezone_load_builtin_timezone (zone); return zone->tzid; @@ -1162,7 +1164,7 @@ icaltimezone_get_tznames (icaltimezone *zone) } -/* Returns the latitude of a builtin timezone. */ +/** Returns the latitude of a builtin timezone. */ double icaltimezone_get_latitude (icaltimezone *zone) { @@ -1176,7 +1178,7 @@ icaltimezone_get_latitude (icaltimezone *zone) } -/* Returns the longitude of a builtin timezone. */ +/** Returns the longitude of a builtin timezone. */ double icaltimezone_get_longitude (icaltimezone *zone) { @@ -1190,7 +1192,7 @@ icaltimezone_get_longitude (icaltimezone *zone) } -/* Returns the VTIMEZONE component of a timezone. */ +/** Returns the VTIMEZONE component of a timezone. */ icalcomponent* icaltimezone_get_component (icaltimezone *zone) { @@ -1205,9 +1207,9 @@ icaltimezone_get_component (icaltimezone *zone) } -/* Sets the VTIMEZONE component of an icaltimezone, initializing the tzid, - location & tzname fields. It returns 1 on success or 0 on failure, i.e. - no TZID was found. */ +/** Sets the VTIMEZONE component of an icaltimezone, initializing the + tzid, location & tzname fields. It returns 1 on success or 0 on + failure, i.e. no TZID was found. */ int icaltimezone_set_component (icaltimezone *zone, icalcomponent *comp) @@ -1279,12 +1281,15 @@ icaltimezone_array_free (icalarray *timezones) icaltimezone *zone; int i; - for (i = 0; i < timezones->num_elements; i++) { - zone = icalarray_element_at (timezones, i); - icaltimezone_free (zone, 0); - } + if ( timezones ) + { + for (i = 0; i < timezones->num_elements; i++) { + zone = icalarray_element_at (timezones, i); + icaltimezone_free (zone, 0); + } - icalarray_free (timezones); + icalarray_free (timezones); + } } @@ -1293,9 +1298,10 @@ icaltimezone_array_free (icalarray *timezones) */ -/* Returns an icalarray of icaltimezone structs, one for each builtin timezone. - This will load and parse the zones.tab file to get the timezone names and - their coordinates. It will not load the VTIMEZONE data for any timezones. */ +/** Returns an icalarray of icaltimezone structs, one for each builtin + timezone. This will load and parse the zones.tab file to get the + timezone names and their coordinates. It will not load the + VTIMEZONE data for any timezones. */ icalarray* icaltimezone_get_builtin_timezones (void) { @@ -1305,8 +1311,15 @@ icaltimezone_get_builtin_timezones (void) return builtin_timezones; } +/** Release builtin timezone memory */ +void +icaltimezone_free_builtin_timezones(void) +{ + icaltimezone_array_free(builtin_timezones); +} + -/* Returns a single builtin timezone, given its Olson city name. */ +/** Returns a single builtin timezone, given its Olson city name. */ icaltimezone* icaltimezone_get_builtin_timezone (const char *location) { @@ -1328,7 +1341,7 @@ icaltimezone_get_builtin_timezone (const char *location) upper = builtin_timezones->num_elements; while (lower < upper) { - middle = (lower + upper) >> 1; + middle = (lower + upper) / 2; zone = icalarray_element_at (builtin_timezones, middle); zone_location = icaltimezone_get_location (zone); cmp = strcmp (location, zone_location); @@ -1344,7 +1357,7 @@ icaltimezone_get_builtin_timezone (const char *location) } -/* Returns a single builtin timezone, given its TZID. */ +/** Returns a single builtin timezone, given its TZID. */ icaltimezone* icaltimezone_get_builtin_timezone_from_tzid (const char *tzid) { @@ -1390,18 +1403,21 @@ icaltimezone_get_builtin_timezone_from_tzid (const char *tzid) } -/* Returns the special UTC timezone. */ +/** Returns the special UTC timezone. */ icaltimezone* icaltimezone_get_utc_timezone (void) { + if (!builtin_timezones) + icaltimezone_init_builtin_timezones (); + return &utc_timezone; } -/* This initializes the builtin timezone data, i.e. the builtin_timezones - array and the special UTC timezone. It should be called before any - code that uses the timezone functions. */ +/** This initializes the builtin timezone data, i.e. the + builtin_timezones array and the special UTC timezone. It should be + called before any code that uses the timezone functions. */ static void icaltimezone_init_builtin_timezones (void) { @@ -1412,12 +1428,13 @@ icaltimezone_init_builtin_timezones (void) } -/* This parses the zones.tab file containing the names and locations of the - builtin timezones. It creates the builtin_timezones array which is an - icalarray of icaltimezone structs. It only fills in the location, latitude - and longtude fields; the rest are left blank. The VTIMEZONE component is - loaded later if it is needed. The timezones in the zones.tab file are - sorted by their name, which is useful for binary searches. */ +/** This parses the zones.tab file containing the names and locations + of the builtin timezones. It creates the builtin_timezones array + which is an icalarray of icaltimezone structs. It only fills in the + location, latitude and longtude fields; the rest are left + blank. The VTIMEZONE component is loaded later if it is needed. The + timezones in the zones.tab file are sorted by their name, which is + useful for binary searches. */ static void icaltimezone_parse_zone_tab (void) { @@ -1425,7 +1442,7 @@ icaltimezone_parse_zone_tab (void) FILE *fp; char buf[1024]; /* Used to store each line of zones.tab as it is read. */ char location[1024]; /* Stores the city name when parsing buf. */ - int filename_len; + unsigned int filename_len; int latitude_degrees, latitude_minutes, latitude_seconds; int longitude_degrees, longitude_minutes, longitude_seconds; icaltimezone zone; @@ -1435,7 +1452,7 @@ icaltimezone_parse_zone_tab (void) builtin_timezones = icalarray_new (sizeof (icaltimezone), 32); - filename_len = strlen (ZONEINFO_DIRECTORY) + strlen (ZONES_TAB_FILENAME) + filename_len = strlen (get_zone_directory()) + strlen (ZONES_TAB_FILENAME) + 2; filename = (char*) malloc (filename_len); @@ -1444,7 +1461,7 @@ icaltimezone_parse_zone_tab (void) return; } - snprintf (filename, filename_len, "%s/%s", ZONEINFO_DIRECTORY, + snprintf (filename, filename_len, "%s/%s", get_zone_directory(), ZONES_TAB_FILENAME); fp = fopen (filename, "r"); @@ -1463,7 +1480,7 @@ icaltimezone_parse_zone_tab (void) &latitude_seconds, &longitude_degrees, &longitude_minutes, &longitude_seconds, - &location) != 7) { + location) != 7) { fprintf (stderr, "Invalid timezone description line: %s\n", buf); continue; } @@ -1501,21 +1518,21 @@ icaltimezone_parse_zone_tab (void) } -/* Loads the builtin VTIMEZONE data for the given timezone. */ +/** Loads the builtin VTIMEZONE data for the given timezone. */ static void icaltimezone_load_builtin_timezone (icaltimezone *zone) { char *filename; - int filename_len; + unsigned int filename_len; FILE *fp; icalparser *parser; icalcomponent *comp, *subcomp; - /* If the location isn't set, it isn't a builtin timezone. */ + /* If the location isn't set, it isn't a builtin timezone. */ if (!zone->location || !zone->location[0]) return; - filename_len = strlen (ZONEINFO_DIRECTORY) + strlen (zone->location) + 6; + filename_len = strlen (get_zone_directory()) + strlen (zone->location) + 6; filename = (char*) malloc (filename_len); if (!filename) { @@ -1523,7 +1540,7 @@ icaltimezone_load_builtin_timezone (icaltimezone *zone) return; } - snprintf (filename, filename_len, "%s/%s.ics", ZONEINFO_DIRECTORY, + snprintf (filename, filename_len, "%s/%s.ics", get_zone_directory(), zone->location); fp = fopen (filename, "r"); @@ -1533,12 +1550,20 @@ icaltimezone_load_builtin_timezone (icaltimezone *zone) return; } + + /* ##### B.# Sun, 11 Nov 2001 04:04:29 +1100 + this is where the MALFORMEDDATA error is being set, after the call to 'icalparser_parse' + fprintf(stderr, "** WARNING ** %s: %d %s\n", __FILE__, __LINE__, icalerror_strerror(icalerrno)); + */ + parser = icalparser_new (); - icalparser_set_gen_data (parser, fp); - comp = icalparser_parse (parser, icaltimezone_load_get_line_fn); + icalparser_set_gen_data (parser, fp); + comp = icalparser_parse (parser, icaltimezone_load_get_line_fn); icalparser_free (parser); - fclose (fp); + fclose (fp); + + /* Find the VTIMEZONE component inside the VCALENDAR. There should be 1. */ subcomp = icalcomponent_get_first_component (comp, ICAL_VTIMEZONE_COMPONENT); @@ -1548,10 +1573,15 @@ icaltimezone_load_builtin_timezone (icaltimezone *zone) } icaltimezone_get_vtimezone_properties (zone, subcomp); + + icalcomponent_remove_component(comp,subcomp); + + icalcomponent_free(comp); + } -/* Callback used from icalparser_parse() */ +/** Callback used from icalparser_parse() */ static char * icaltimezone_load_get_line_fn (char *s, size_t size, @@ -1567,7 +1597,7 @@ icaltimezone_load_get_line_fn (char *s, * DEBUGGING */ -/* +/** * This outputs a list of timezone changes for the given timezone to the * given file, up to the maximum year given. We compare this output with the * output from 'vzic --dump-changes' to make sure that we are consistent. @@ -1600,32 +1630,6 @@ icaltimezone_dump_changes (icaltimezone *zone, printf ("Num changes: %i\n", zone->changes->num_elements); #endif - /* This shouldn't happen. */ - if (zone->changes->num_elements == 0) { - fprintf (fp, "%s\tNO CHANGES", zone->location); - return; - } - - zone_change = icalarray_element_at (zone->changes, 0); - - /* If there is just one change, and the TZOFFSETFROM and TZOFFSETTO are - the same, meaning the zone just uses the same offset forever, we output - the special '1 Jan 0001' date instead and return. */ - if (zone->changes->num_elements == 1 - && zone_change->prev_utc_offset == zone_change->utc_offset - && (zone_change->year == 1600 || zone_change->year == 1601)) { - fprintf (fp, "%s\t 1 Jan 0001\t 0:00:00", zone->location); - format_utc_offset (zone_change->utc_offset, buffer); - fprintf (fp, "\t%s\n", buffer); - return; - } - - /* Output the special 1 Jan 0001 change here, using the TZOFFSET_FROM - field of the first change. */ - fprintf (fp, "%s\t 1 Jan 0001\t 0:00:00", zone->location); - format_utc_offset (zone_change->prev_utc_offset, buffer); - fprintf (fp, "\t%s\n", buffer); - change_num = 0; for (change_num = 0; change_num < zone->changes->num_elements; change_num++) { zone_change = icalarray_element_at (zone->changes, change_num); @@ -1641,12 +1645,15 @@ icaltimezone_dump_changes (icaltimezone *zone, /* Wall Clock Time offset from UTC. */ format_utc_offset (zone_change->utc_offset, buffer); - fprintf (fp, "\t%s\n", buffer); + fprintf (fp, "\t%s", buffer); + + fprintf (fp, "\n"); } + return 1; } -/* This formats a UTC offset as "+HHMM" or "+HHMMSS". +/** This formats a UTC offset as "+HHMM" or "+HHMMSS". buffer should have space for 8 characters. */ static void format_utc_offset (int utc_offset, @@ -1678,3 +1685,25 @@ format_utc_offset (int utc_offset, else sprintf (buffer, "%s%02i%02i%02i", sign, hours, minutes, seconds); } + +static char* get_zone_directory(void) +{ + return zone_files_directory == NULL ? ZONEINFO_DIRECTORY : zone_files_directory; +} + +void set_zone_directory(char *path) +{ + zone_files_directory = malloc(strlen(path)+1); + if ( zone_files_directory != NULL ) + { + strcpy(zone_files_directory,path); + } +} + +void free_zone_directory(void) +{ + if ( zone_files_directory != NULL ) + { + free(zone_files_directory); + } +} diff --git a/libical/src/libical/icaltimezone.h b/libical/src/libical/icaltimezone.h index 2a692c441b..b5e9aaa009 100644 --- a/libical/src/libical/icaltimezone.h +++ b/libical/src/libical/icaltimezone.h @@ -22,7 +22,10 @@ ======================================================================*/ - +/** + * @file icaltimezone.h + * @brief timezone handling routines + */ #ifndef ICALTIMEZONE_H #define ICALTIMEZONE_H @@ -33,92 +36,100 @@ #include "icalcomponent.h" -/* - * Creating/Destroying individual icaltimezones. +#ifndef ICALTIMEZONE_DEFINED +#define ICALTIMEZONE_DEFINED +/** @brief An opaque struct representing a timezone. + * We declare this here to avoid a circular dependancy. + */ +typedef struct _icaltimezone icaltimezone; +#endif + +/** + * @par Creating/Destroying individual icaltimezones. */ -/* Creates a new icaltimezone. */ +/** Creates a new icaltimezone. */ icaltimezone *icaltimezone_new (void); -/* Frees all memory used for the icaltimezone. Set free_struct to free the +/** Frees all memory used for the icaltimezone. Set free_struct to free the icaltimezone struct as well. */ void icaltimezone_free (icaltimezone *zone, int free_struct); -/* - * Accessing timezones. +/** + * @par Accessing timezones. */ -/* Returns the array of builtin icaltimezones. */ +/** Free any builtin timezone information **/ +void icaltimezone_free_builtin_timezones(void); + +/** Returns the array of builtin icaltimezones. */ icalarray* icaltimezone_get_builtin_timezones (void); -/* Returns a single builtin timezone, given its Olson city name. */ +/** Returns a single builtin timezone, given its Olson city name. */ icaltimezone* icaltimezone_get_builtin_timezone (const char *location); -/* Returns a single builtin timezone, given its TZID. */ +/** Returns a single builtin timezone, given its TZID. */ icaltimezone* icaltimezone_get_builtin_timezone_from_tzid (const char *tzid); -/* Returns the UTC timezone. */ +/** Returns the UTC timezone. */ icaltimezone* icaltimezone_get_utc_timezone (void); -/* Returns the TZID of a timezone. */ +/** Returns the TZID of a timezone. */ char* icaltimezone_get_tzid (icaltimezone *zone); -/* Returns the city name of a timezone. */ +/** Returns the city name of a timezone. */ char* icaltimezone_get_location (icaltimezone *zone); -/* Returns the TZNAME properties used in the latest STANDARD and DAYLIGHT +/** Returns the TZNAME properties used in the latest STANDARD and DAYLIGHT components. If they are the same it will return just one, e.g. "LMT". If they are different it will format them like "EST/EDT". Note that this may also return NULL. */ char* icaltimezone_get_tznames (icaltimezone *zone); -/* Returns a string suitable for displaying to the user. If there is a - LOCATION property it returns that, else the TZNAMEs, else the TZID. */ -char* icaltimezone_get_display_name (icaltimezone *zone); - -/* Returns the latitude of a builtin timezone. */ +/** Returns the latitude of a builtin timezone. */ double icaltimezone_get_latitude (icaltimezone *zone); -/* Returns the longitude of a builtin timezone. */ +/** Returns the longitude of a builtin timezone. */ double icaltimezone_get_longitude (icaltimezone *zone); -/* Returns the VTIMEZONE component of a timezone. */ +/** Returns the VTIMEZONE component of a timezone. */ icalcomponent* icaltimezone_get_component (icaltimezone *zone); -/* Sets the VTIMEZONE component of an icaltimezone, initializing the tzid, +/** Sets the VTIMEZONE component of an icaltimezone, initializing the tzid, location & tzname fields. It returns 1 on success or 0 on failure, i.e. no TZID was found. */ int icaltimezone_set_component (icaltimezone *zone, icalcomponent *comp); -/* - * Converting times between timezones. +char* icaltimezone_get_display_name (icaltimezone *zone); + +/** + * @par Converting times between timezones. */ -/* This converts the icaltimetype from one timezone to another. Note that it - does not convert DATE values. If you need to do that, you should clear the - is_date field first. */ void icaltimezone_convert_time (struct icaltimetype *tt, icaltimezone *from_zone, icaltimezone *to_zone); -/* - * Getting offsets from UTC. +/** + * @par Getting offsets from UTC. */ -/* Calculates the UTC offset of a given local time in the given timezone. - It is the number of seconds to add to UTC to get local time. - The is_daylight flag is set to 1 if the time is in daylight-savings time. */ +/** Calculates the UTC offset of a given local time in the given + timezone. It is the number of seconds to add to UTC to get local + time. The is_daylight flag is set to 1 if the time is in + daylight-savings time. */ int icaltimezone_get_utc_offset (icaltimezone *zone, struct icaltimetype *tt, int *is_daylight); -/* Calculates the UTC offset of a given UTC time in the given timezone. - It is the number of seconds to add to UTC to get local time. - The is_daylight flag is set to 1 if the time is in daylight-savings time. */ +/** Calculates the UTC offset of a given UTC time in the given + timezone. It is the number of seconds to add to UTC to get local + time. The is_daylight flag is set to 1 if the time is in + daylight-savings time. */ int icaltimezone_get_utc_offset_of_utc_time (icaltimezone *zone, struct icaltimetype *tt, int *is_daylight); @@ -135,12 +146,21 @@ void icaltimezone_array_append_from_vtimezone (icalarray *timezones, void icaltimezone_array_free (icalarray *timezones); +/* + * @par Handling the default location the timezone files + */ + +/** Set the directory to look for the zonefiles */ +void set_zone_directory(char *path); + +/** Free memory dedicated to the zonefile directory */ +void free_zone_directory(void); /* - * Debugging Output. + * @par Debugging Output. */ -/* Dumps information about changes in the timezone up to and including +/** Dumps information about changes in the timezone up to and including max_year. */ int icaltimezone_dump_changes (icaltimezone *zone, int max_year, diff --git a/libical/src/libical/icaltypes.c b/libical/src/libical/icaltypes.c index cbb574992b..19719f8aa7 100644 --- a/libical/src/libical/icaltypes.c +++ b/libical/src/libical/icaltypes.c @@ -30,123 +30,55 @@ #include "icaltypes.h" #include "icalerror.h" #include "icalmemory.h" -#include "icalvalueimpl.h" #include <stdlib.h> /* for malloc and abs() */ #include <errno.h> /* for errno */ #include <string.h> /* for icalmemory_strdup */ #include <assert.h> -#define TEMP_MAX 1024 - -icalattach * -icalattach_new_from_url (const char *url) -{ - icalattach *attach; - char *url_copy; - - icalerror_check_arg_rz ((url != NULL), "url"); - - if ((attach = malloc (sizeof (icalattach))) == NULL) { - errno = ENOMEM; - return NULL; - } +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif - if ((url_copy = strdup (url)) == NULL) { - free (attach); - errno = ENOMEM; - return NULL; - } +#define TEMP_MAX 1024 - attach->refcount = 1; - attach->is_url = 1; - attach->u.url.url = url_copy; - return attach; -} - -icalattach * -icalattach_new_from_data (const unsigned char *data, icalattach_free_fn_t free_fn, - void *free_fn_data) +int icaltriggertype_is_null_trigger(struct icaltriggertype tr) { - icalattach *attach; - - icalerror_check_arg_rz ((data != NULL), "data"); - - if ((attach = malloc (sizeof (icalattach))) == NULL) { - errno = ENOMEM; - return NULL; + if(icaltime_is_null_time(tr.time) && + icaldurationtype_is_null_duration(tr.duration)){ + return 1; } - attach->refcount = 1; - attach->is_url = 0; - attach->u.data.data = (unsigned char *) data; - attach->u.data.free_fn = free_fn; - attach->u.data.free_fn_data = free_fn_data; - - return attach; -} - -void -icalattach_ref (icalattach *attach) -{ - icalerror_check_arg_rv ((attach != NULL), "attach"); - icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0"); - - attach->refcount++; -} - -void -icalattach_unref (icalattach *attach) -{ - icalerror_check_arg_rv ((attach != NULL), "attach"); - icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0"); - - attach->refcount--; - - if (attach->refcount != 0) - return; - - if (attach->is_url) - free (attach->u.url.url); - else if (attach->u.data.free_fn) - (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data); - - free (attach); + return 0; } - -int -icalattach_get_is_url (icalattach *attach) + +int icaltriggertype_is_bad_trigger(struct icaltriggertype tr) { - icalerror_check_arg_rz ((attach != NULL), "attach"); + if(icaldurationtype_is_bad_duration(tr.duration)){ + return 1; + } - return attach->is_url ? 1 : 0; + return 0; } -const char * -icalattach_get_url (icalattach *attach) +struct icaltriggertype icaltriggertype_from_int(const int reltime) { - icalerror_check_arg_rz ((attach != NULL), "attach"); - icalerror_check_arg_rz ((attach->is_url), "attach->is_url"); + struct icaltriggertype tr; - return attach->u.url.url; -} + tr.time = icaltime_null_time(); + tr.duration = icaldurationtype_from_int(reltime); -unsigned char * -icalattach_get_data (icalattach *attach) -{ - icalerror_check_arg_rz ((attach != NULL), "attach"); - icalerror_check_arg_rz ((!attach->is_url), "!attach->is_url"); - - return attach->u.data.data; + return tr; } - struct icaltriggertype icaltriggertype_from_string(const char* str) { struct icaltriggertype tr, null_tr; - int old_ieaf = icalerror_errors_are_fatal; + icalerrorstate es; + icalerrorenum e; tr.time= icaltime_null_time(); tr.duration = icaldurationtype_from_int(0); @@ -155,34 +87,38 @@ struct icaltriggertype icaltriggertype_from_string(const char* str) if(str == 0) goto error; - - icalerror_errors_are_fatal = 0; + /* Suppress errors so a failure in icaltime_from_string() does not cause an abort */ + es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); + e = icalerrno; + icalerror_set_errno(ICAL_NO_ERROR); tr.time = icaltime_from_string(str); - icalerror_errors_are_fatal = old_ieaf; - if (icaltime_is_null_time(tr.time)){ tr.duration = icaldurationtype_from_string(str); - if(icaldurationtype_as_int(tr.duration) == 0) goto error; + if (icaldurationtype_is_bad_duration(tr.duration)) goto error; } + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); + icalerror_set_errno(e); return tr; error: + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return null_tr; + return tr; } -struct icalreqstattype icalreqstattype_from_string(char* str) +struct icalreqstattype icalreqstattype_from_string(const char* str) { - char *p1,*p2; + const char *p1,*p2; struct icalreqstattype stat; - int major, minor; + short major=0, minor=0; icalerror_check_arg((str != 0),"str"); @@ -192,17 +128,17 @@ struct icalreqstattype icalreqstattype_from_string(char* str) /* Get the status numbers */ - sscanf(str, "%d.%d",&major, &minor); + sscanf(str, "%hd.%hd",&major, &minor); if (major <= 0 || minor < 0){ - icalerror_set_errno(ICAL_BADARG_ERROR); + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); return stat; } stat.code = icalenum_num_to_reqstat(major, minor); if (stat.code == ICAL_UNKNOWN_STATUS){ - icalerror_set_errno(ICAL_BADARG_ERROR); + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); return stat; } @@ -228,7 +164,7 @@ struct icalreqstattype icalreqstattype_from_string(char* str) } -char* icalreqstattype_as_string(struct icalreqstattype stat) +const char* icalreqstattype_as_string(struct icalreqstattype stat) { char *temp; diff --git a/libical/src/libical/icaltypes.h b/libical/src/libical/icaltypes.h index 916fef7323..1e5c5e09bb 100644 --- a/libical/src/libical/icaltypes.h +++ b/libical/src/libical/icaltypes.h @@ -30,38 +30,6 @@ #include "icalduration.h" #include "icalperiod.h" -typedef struct icalattach_impl icalattach; - -typedef void (* icalattach_free_fn_t) (unsigned char *data, void *user_data); - -/* converts base64 to binary, fetches url and stores as binary, or - just returns data */ - -icalattach *icalattach_new_from_url (const char *url); -icalattach *icalattach_new_from_data (const unsigned char *data, icalattach_free_fn_t free_fn, - void *free_fn_data); - -void icalattach_ref (icalattach *attach); -void icalattach_unref (icalattach *attach); - -int icalattach_get_is_url (icalattach *attach); -const char *icalattach_get_url (icalattach *attach); -unsigned char *icalattach_get_data (icalattach *attach); - -struct icalattachtype* icalattachtype_new(void); -void icalattachtype_add_reference(struct icalattachtype* v); -void icalattachtype_free(struct icalattachtype* v); - -void icalattachtype_set_url(struct icalattachtype* v, char* url); -char* icalattachtype_get_url(struct icalattachtype* v); - -void icalattachtype_set_base64(struct icalattachtype* v, char* base64, - int owns); -char* icalattachtype_get_base64(struct icalattachtype* v); - -void icalattachtype_set_binary(struct icalattachtype* v, char* binary, - int owns); -void* icalattachtype_get_binary(struct icalattachtype* v); struct icalgeotype { @@ -83,8 +51,12 @@ struct icaltriggertype struct icaldurationtype duration; }; +struct icaltriggertype icaltriggertype_from_int(const int reltime); struct icaltriggertype icaltriggertype_from_string(const char* str); +int icaltriggertype_is_null_trigger(struct icaltriggertype tr); +int icaltriggertype_is_bad_trigger(struct icaltriggertype tr); + /* struct icalreqstattype. This struct contains two string pointers, but don't try to free either of them. The "desc" string is a pointer to a static table inside the library. Don't try to free it. The @@ -103,8 +75,8 @@ struct icalreqstattype { const char* debug; }; -struct icalreqstattype icalreqstattype_from_string(char* str); -char* icalreqstattype_as_string(struct icalreqstattype); +struct icalreqstattype icalreqstattype_from_string(const char* str); +const char* icalreqstattype_as_string(struct icalreqstattype); diff --git a/libical/src/libical/icalvalue.c b/libical/src/libical/icalvalue.c index e708c35ac3..2e52670c61 100644 --- a/libical/src/libical/icalvalue.c +++ b/libical/src/libical/icalvalue.c @@ -1,4 +1,5 @@ -/* -*- Mode: C -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vi:set ts=4 sts=4 sw=4 expandtab : */ /*====================================================================== FILE: icalvalue.c CREATOR: eric 02 May 1999 @@ -46,22 +47,29 @@ #include <stdlib.h> /* for atoi and atof */ #include <limits.h> /* for SHRT_MAX */ +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + #if _MAC_OS_ #include "icalmemory_strdup.h" #endif #define TMP_BUF_SIZE 1024 -void print_datetime_to_string(char* str, struct icaltimetype *data); -void print_date_to_string(char* str, struct icaltimetype *data); -void print_time_to_string(char* str, struct icaltimetype *data); -void print_recur_to_string(char* str, struct icaltimetype *data); +void print_datetime_to_string(char* str, const struct icaltimetype *data); +void print_date_to_string(char* str, const struct icaltimetype *data); +void print_time_to_string(char* str, const struct icaltimetype *data); struct icalvalue_impl* icalvalue_new_impl(icalvalue_kind kind){ struct icalvalue_impl* v; + if (!icalvalue_kind_is_valid(kind)) + return NULL; + if ( ( v = (struct icalvalue_impl*) malloc(sizeof(struct icalvalue_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); @@ -88,11 +96,8 @@ icalvalue_new (icalvalue_kind kind) return (icalvalue*)icalvalue_new_impl(kind); } -icalvalue* -icalvalue_new_clone(icalvalue* value) -{ +icalvalue* icalvalue_new_clone(const icalvalue* old) { struct icalvalue_impl* new; - struct icalvalue_impl* old = (struct icalvalue_impl*)value; new = icalvalue_new_impl(old->kind); @@ -100,7 +105,6 @@ icalvalue_new_clone(icalvalue* value) return 0; } - strcpy(new->id, old->id); new->kind = old->kind; new->size = old->size; @@ -119,7 +123,7 @@ icalvalue_new_clone(icalvalue* value) break; } - + case ICAL_QUERY_VALUE: case ICAL_STRING_VALUE: case ICAL_TEXT_VALUE: case ICAL_CALADDRESS_VALUE: @@ -150,6 +154,19 @@ icalvalue_new_clone(icalvalue* value) break; } + case ICAL_X_VALUE: + { + if (old->x_value != 0) { + new->x_value=icalmemory_strdup(old->x_value); + + if (new->x_value == 0) { + return 0; + } + } + + break; + } + default: { /* all of the other types are stored as values, not @@ -242,9 +259,16 @@ static char* icalmemory_strdup_and_dequote(const char* str) return out; } +/* + * FIXME + * + * This is a bad API, as it forces callers to specify their own X type. + * This function should take care of this by itself. + */ +static icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) { - int e = icalproperty_string_to_enum(str); + int e = icalproperty_kind_and_string_to_enum(kind, str); struct icalvalue_impl *value; if(e != 0 && icalproperty_enum_belongs_to_property( @@ -263,8 +287,7 @@ icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str) } -icalvalue* -icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) +icalvalue* icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalproperty** error) { struct icalvalue_impl *value = 0; @@ -276,6 +299,7 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro } switch (kind){ + case ICAL_ATTACH_VALUE: { icalattach *attach; @@ -298,7 +322,7 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro if (error != 0){ char temp[TMP_BUF_SIZE]; sprintf(temp,"%s Values are not implemented", - icalparameter_kind_to_string(kind)); + icalvalue_kind_to_string(kind)); *error = icalproperty_vanew_xlicerror( temp, icalparameter_new_xlicerrortype( @@ -310,37 +334,60 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro case ICAL_TRANSP_VALUE: - value = icalvalue_new_enum(kind, ICAL_TRANSP_X,str); + value = icalvalue_new_enum(kind, (int)ICAL_TRANSP_X,str); break; case ICAL_METHOD_VALUE: - value = icalvalue_new_enum(kind, ICAL_METHOD_X,str); + value = icalvalue_new_enum(kind, (int)ICAL_METHOD_X,str); break; case ICAL_STATUS_VALUE: - value = icalvalue_new_enum(kind, ICAL_STATUS_X,str); + value = icalvalue_new_enum(kind, (int)ICAL_STATUS_X,str); break; case ICAL_ACTION_VALUE: - value = icalvalue_new_enum(kind, ICAL_ACTION_X,str); + value = icalvalue_new_enum(kind, (int)ICAL_ACTION_X,str); break; + + case ICAL_QUERY_VALUE: + value = icalvalue_new_query(str); + break; + case ICAL_CLASS_VALUE: - value = icalvalue_new_enum(kind, ICAL_CLASS_X,str); + value = icalvalue_new_enum(kind, (int)ICAL_CLASS_X,str); + break; + + case ICAL_CMD_VALUE: + value = icalvalue_new_enum(kind, ICAL_CMD_X,str); + break; + case ICAL_QUERYLEVEL_VALUE: + value = icalvalue_new_enum(kind, ICAL_QUERYLEVEL_X,str); + break; + case ICAL_CARLEVEL_VALUE: + value = icalvalue_new_enum(kind, ICAL_CARLEVEL_X,str); break; case ICAL_INTEGER_VALUE: - { value = icalvalue_new_integer(atoi(str)); break; - } case ICAL_FLOAT_VALUE: - { - value = icalvalue_new_float(atof(str)); + value = icalvalue_new_float((float)atof(str)); break; - } - + case ICAL_UTCOFFSET_VALUE: { - value = icalparser_parse_value(kind,str,(icalcomponent*)0); + int t,utcoffset, hours, minutes, seconds; + /* treat the UTCOFSET string a a decimal number, disassemble its digits + and reconstruct it as sections */ + t = strtol(str,0,10); + /* add phantom seconds field */ + if(abs(t)<9999){t *= 100; } + hours = (t/10000); + minutes = (t-hours*10000)/100; + seconds = (t-hours*10000-minutes*100); + utcoffset = hours*3600+minutes*60+seconds; + + value = icalvalue_new_utcoffset(utcoffset); + break; } @@ -352,28 +399,19 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro break; } - case ICAL_STRING_VALUE: - { value = icalvalue_new_string(str); break; - } case ICAL_CALADDRESS_VALUE: - { value = icalvalue_new_caladdress(str); break; - } case ICAL_URI_VALUE: - { value = icalvalue_new_uri(str); break; - } - case ICAL_GEO_VALUE: - { value = 0; /* HACK */ @@ -390,31 +428,33 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro /*icalerror_warn("Parsing GEO properties is unimplmeneted");*/ break; - } - - case ICAL_RECUR_VALUE: + + case ICAL_RECUR_VALUE: { struct icalrecurrencetype rt; rt = icalrecurrencetype_from_string(str); - value = icalvalue_new_recur(rt); + if(rt.freq != ICAL_NO_RECURRENCE){ + value = icalvalue_new_recur(rt); + } break; } - - case ICAL_TIME_VALUE: - case ICAL_DATE_VALUE: - case ICAL_DATETIME_VALUE: - case ICAL_DATETIMEDATE_VALUE: + + case ICAL_DATE_VALUE: + case ICAL_DATETIME_VALUE: { struct icaltimetype tt; + tt = icaltime_from_string(str); if(!icaltime_is_null_time(tt)){ value = icalvalue_new_impl(kind); value->data.v_time = tt; + + icalvalue_reset_kind(value); } break; } - - case ICAL_DATETIMEPERIOD_VALUE: + + case ICAL_DATETIMEPERIOD_VALUE: { struct icaltimetype tt; struct icalperiodtype p; @@ -432,43 +472,61 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro break; } - - case ICAL_DURATION_VALUE: + + case ICAL_DURATION_VALUE: { struct icaldurationtype dur = icaldurationtype_from_string(str); - - if (icalerrno == ICAL_MALFORMEDDATA_ERROR) - value = 0; - else + + if (!icaldurationtype_is_bad_duration(dur)) { /* failed to parse */ value = icalvalue_new_duration(dur); - + } + break; } - - case ICAL_PERIOD_VALUE: + + case ICAL_PERIOD_VALUE: { - struct icalperiodtype p; - p = icalperiodtype_from_string(str); - - if(!icalperiodtype_is_null_period(p)){ - value = icalvalue_new_period(p); - } - break; + struct icalperiodtype p; + p = icalperiodtype_from_string(str); + + if(!icalperiodtype_is_null_period(p)){ + value = icalvalue_new_period(p); + } + break; } - case ICAL_TRIGGER_VALUE: + case ICAL_TRIGGER_VALUE: { struct icaltriggertype tr = icaltriggertype_from_string(str); - value = icalvalue_new_trigger(tr); + if (!icaltriggertype_is_bad_trigger(tr)) { + value = icalvalue_new_trigger(tr); + } break; } + + case ICAL_REQUESTSTATUS_VALUE: + { + struct icalreqstattype rst = icalreqstattype_from_string(str); + if(rst.code != ICAL_UNKNOWN_STATUS){ + value = icalvalue_new_requeststatus(rst); + } + break; - default: - { + } - if (error != 0 ){ - char temp[TMP_BUF_SIZE]; + case ICAL_X_VALUE: + { + char* dequoted_str = icalmemory_strdup_and_dequote(str); + value = icalvalue_new_x(dequoted_str); + free(dequoted_str); + } + break; + default: + { + if (error != 0 ){ + char temp[TMP_BUF_SIZE]; + snprintf(temp,TMP_BUF_SIZE,"Unknown type for \'%s\'",str); *error = icalproperty_vanew_xlicerror( @@ -503,17 +561,15 @@ icalvalue_new_from_string_with_error(icalvalue_kind kind,const char* str,icalpro icalvalue* icalvalue_new_from_string(icalvalue_kind kind,const char* str) { - return icalvalue_new_from_string_with_error(kind,str,(icalproperty*)0); + return icalvalue_new_from_string_with_error(kind,str,(icalproperty**)0); } void -icalvalue_free (icalvalue* value) +icalvalue_free (icalvalue* v) { - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - icalerror_check_arg_rv((value != 0),"value"); + icalerror_check_arg_rv((v != 0),"value"); #ifdef ICAL_FREE_ON_LIST_IS_ERROR icalerror_assert( (v->parent ==0),"This value is still attached to a property"); @@ -541,6 +597,7 @@ icalvalue_free (icalvalue* value) case ICAL_TEXT_VALUE: case ICAL_CALADDRESS_VALUE: case ICAL_URI_VALUE: + case ICAL_QUERY_VALUE: { if (v->data.v_string != 0) { free((void*)v->data.v_string); @@ -572,10 +629,8 @@ icalvalue_free (icalvalue* value) } int -icalvalue_is_valid (icalvalue* value) +icalvalue_is_valid (const icalvalue* value) { - /*struct icalvalue_impl* v = (struct icalvalue_impl*)value;*/ - if(value == 0){ return 0; } @@ -583,7 +638,7 @@ icalvalue_is_valid (icalvalue* value) return 1; } -char* icalvalue_binary_as_ical_string(icalvalue* value) { +static char* icalvalue_binary_as_ical_string(const icalvalue* value) { const char* data; char* str; @@ -599,8 +654,8 @@ char* icalvalue_binary_as_ical_string(icalvalue* value) { #define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ -char* icalvalue_int_as_ical_string(icalvalue* value) { +static char* icalvalue_int_as_ical_string(const icalvalue* value) { int data; char* str = (char*)icalmemory_tmp_buffer(MAX_INT_DIGITS); @@ -613,7 +668,7 @@ char* icalvalue_int_as_ical_string(icalvalue* value) { return str; } -char* icalvalue_utcoffset_as_ical_string(icalvalue* value) +static char* icalvalue_utcoffset_as_ical_string(const icalvalue* value) { int data,h,m,s; char sign; @@ -629,32 +684,24 @@ char* icalvalue_utcoffset_as_ical_string(icalvalue* value) sign = '-'; } - /* We add 30 to +ve values or -29 to -ve values, since we will round to - the nearest minute, so we compatable with Outlook. */ - if (data >= 0) - data += 30; - else - data -= 29; - h = data/3600; m = (data - (h*3600))/ 60; - /*s = (data - (h*3600) - (m*60));*/ - s = 0; + s = (data - (h*3600) - (m*60)); - if (s == 0) - sprintf(str,"%c%02d%02d",sign,abs(h),abs(m)); + if (s > 0) + sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); else - sprintf(str,"%c%02d%02d%02d",sign,abs(h),abs(m),abs(s)); + sprintf(str,"%c%02d%02d",sign,abs(h),abs(m)); return str; } -char* icalvalue_string_as_ical_string(icalvalue* value) { +static char* icalvalue_string_as_ical_string(const icalvalue* value) { const char* data; char* str = 0; icalerror_check_arg_rz( (value!=0),"value"); - data = ((struct icalvalue_impl*)value)->data.v_string; + data = value->data.v_string; str = (char*)icalmemory_tmp_buffer(strlen(data)+1); @@ -664,26 +711,27 @@ char* icalvalue_string_as_ical_string(icalvalue* value) { } -char* icalvalue_recur_as_ical_string(icalvalue* value) +static char* icalvalue_recur_as_ical_string(const icalvalue* value) { - struct icalvalue_impl *impl = (struct icalvalue_impl*)value; - struct icalrecurrencetype *recur = impl->data.v_recur; + struct icalrecurrencetype *recur = value->data.v_recur; return icalrecurrencetype_as_string(recur); } -char* icalvalue_text_as_ical_string(icalvalue* value) { + /* @todo This is not RFC2445 compliant. + * The RFC only allows: + * TSAFE-CHAR = %x20-21 / %x23-2B / %x2D-39 / %x3C-5B / %x5D-7E / NON-US-ASCII + * As such, \t\r\b\f are not allowed, not even escaped + */ +static char* icalvalue_text_as_ical_string(const icalvalue* value) { char *str; char *str_p; char *rtrn; const char *p; size_t buf_sz; - int line_length; - - line_length = 0; - buf_sz = strlen(((struct icalvalue_impl*)value)->data.v_string)+1; + buf_sz = strlen(value->data.v_string)+1; str_p = str = (char*)icalmemory_new_buffer(buf_sz); @@ -691,33 +739,28 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { return 0; } - for(p=((struct icalvalue_impl*)value)->data.v_string; *p!=0; p++){ + for(p=value->data.v_string; *p!=0; p++){ switch(*p){ case '\n': { icalmemory_append_string(&str,&str_p,&buf_sz,"\\n"); - line_length+=3; break; } case '\t': { icalmemory_append_string(&str,&str_p,&buf_sz,"\\t"); - line_length+=3; break; } case '\r': { icalmemory_append_string(&str,&str_p,&buf_sz,"\\r"); - line_length+=3; break; } case '\b': { icalmemory_append_string(&str,&str_p,&buf_sz,"\\b"); - line_length+=3; break; } case '\f': { icalmemory_append_string(&str,&str_p,&buf_sz,"\\f"); - line_length+=3; break; } @@ -727,32 +770,13 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { case '\\':{ icalmemory_append_char(&str,&str_p,&buf_sz,'\\'); icalmemory_append_char(&str,&str_p,&buf_sz,*p); - line_length+=3; break; } default: { icalmemory_append_char(&str,&str_p,&buf_sz,*p); - line_length++; } } - - - /* We don't do folding here any more. We do it in - icalproperty_as_ical_string(). */ -#if 0 - if (line_length > 65 && *p == ' '){ - icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); - line_length=0; - } - - - if (line_length > 75){ - icalmemory_append_string(&str,&str_p,&buf_sz,"\n "); - line_length=0; - } -#endif - } /* Assume the last character is not a '\0' and add one. We could @@ -770,8 +794,8 @@ char* icalvalue_text_as_ical_string(icalvalue* value) { } -char* -icalvalue_attach_as_ical_string(icalvalue* value) +static char* +icalvalue_attach_as_ical_string(const icalvalue* value) { icalattach *a; char * str; @@ -792,7 +816,7 @@ icalvalue_attach_as_ical_string(icalvalue* value) } -char* icalvalue_duration_as_ical_string(icalvalue* value) { +static char* icalvalue_duration_as_ical_string(const icalvalue* value) { struct icaldurationtype data; @@ -802,11 +826,11 @@ char* icalvalue_duration_as_ical_string(icalvalue* value) { return icaldurationtype_as_ical_string(data); } -void print_time_to_string(char* str, struct icaltimetype *data) +void print_time_to_string(char* str, const struct icaltimetype *data) { char temp[20]; - if (data->is_utc == 1){ + if (icaltime_is_utc(*data)){ sprintf(temp,"%02d%02d%02dZ",data->hour,data->minute,data->second); } else { sprintf(temp,"%02d%02d%02d",data->hour,data->minute,data->second); @@ -816,22 +840,7 @@ void print_time_to_string(char* str, struct icaltimetype *data) } -char* icalvalue_time_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - char* str; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_time(value); - - str = (char*)icalmemory_tmp_buffer(8); - - str[0] = 0; - print_time_to_string(str,&data); - - return str; -} - -void print_date_to_string(char* str, struct icaltimetype *data) +void print_date_to_string(char* str, const struct icaltimetype *data) { char temp[20]; @@ -840,7 +849,7 @@ void print_date_to_string(char* str, struct icaltimetype *data) strcat(str,temp); } -char* icalvalue_date_as_ical_string(icalvalue* value) { +static char* icalvalue_date_as_ical_string(const icalvalue* value) { struct icaltimetype data; char* str; @@ -855,14 +864,14 @@ char* icalvalue_date_as_ical_string(icalvalue* value) { return str; } -void print_datetime_to_string(char* str, struct icaltimetype *data) +void print_datetime_to_string(char* str, const struct icaltimetype *data) { print_date_to_string(str,data); strcat(str,"T"); print_time_to_string(str,data); } -const char* icalvalue_datetime_as_ical_string(icalvalue* value) { +static const char* icalvalue_datetime_as_ical_string(const icalvalue* value) { struct icaltimetype data; char* str; @@ -871,10 +880,7 @@ const char* icalvalue_datetime_as_ical_string(icalvalue* value) { icalerror_check_arg_rz( (value!=0),"value"); - if( !(kind == ICAL_DATETIMEDATE_VALUE || - kind == ICAL_DATE_VALUE || - kind == ICAL_DATETIME_VALUE || - kind == ICAL_TIME_VALUE)) + if( !(kind == ICAL_DATE_VALUE || kind == ICAL_DATETIME_VALUE )) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0; @@ -892,22 +898,7 @@ const char* icalvalue_datetime_as_ical_string(icalvalue* value) { } - -const char* icalvalue_datetimedate_as_ical_string(icalvalue* value) { - - struct icaltimetype data; - icalerror_check_arg_rz( (value!=0),"value"); - data = icalvalue_get_datetime(value); - - if (data.is_date == 1){ - return icalvalue_date_as_ical_string(value); - } else { - return icalvalue_datetime_as_ical_string(value); - } -} - - -char* icalvalue_float_as_ical_string(icalvalue* value) { +static char* icalvalue_float_as_ical_string(const icalvalue* value) { float data; char* str; @@ -921,7 +912,7 @@ char* icalvalue_float_as_ical_string(icalvalue* value) { return str; } -char* icalvalue_geo_as_ical_string(icalvalue* value) { +static char* icalvalue_geo_as_ical_string(const icalvalue* value) { struct icalgeotype data; char* str; @@ -936,7 +927,7 @@ char* icalvalue_geo_as_ical_string(icalvalue* value) { return str; } -const char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { +static const char* icalvalue_datetimeperiod_as_ical_string(const icalvalue* value) { struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value); icalerror_check_arg_rz( (value!=0),"value"); @@ -948,7 +939,7 @@ const char* icalvalue_datetimeperiod_as_ical_string(icalvalue* value) { } } -const char* icalvalue_period_as_ical_string(icalvalue* value) { +static const char* icalvalue_period_as_ical_string(const icalvalue* value) { struct icalperiodtype data; icalerror_check_arg_rz( (value!=0),"value"); data = icalvalue_get_period(value); @@ -957,7 +948,7 @@ const char* icalvalue_period_as_ical_string(icalvalue* value) { } -char* icalvalue_trigger_as_ical_string(icalvalue* value) { +static const char* icalvalue_trigger_as_ical_string(const icalvalue* value) { struct icaltriggertype data; @@ -973,17 +964,13 @@ char* icalvalue_trigger_as_ical_string(icalvalue* value) { } const char* -icalvalue_as_ical_string (icalvalue* value) +icalvalue_as_ical_string(const icalvalue* value) { - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - v=v; - if(value == 0){ return 0; } - switch (v->kind){ + switch (value->kind){ case ICAL_ATTACH_VALUE: return icalvalue_attach_as_ical_string(value); @@ -1001,6 +988,9 @@ icalvalue_as_ical_string (icalvalue* value) case ICAL_TEXT_VALUE: return icalvalue_text_as_ical_string(value); + case ICAL_QUERY_VALUE: + return icalvalue_string_as_ical_string(value); + case ICAL_STRING_VALUE: case ICAL_URI_VALUE: case ICAL_CALADDRESS_VALUE: @@ -1010,12 +1000,8 @@ icalvalue_as_ical_string (icalvalue* value) return icalvalue_date_as_ical_string(value); case ICAL_DATETIME_VALUE: return icalvalue_datetime_as_ical_string(value); - case ICAL_DATETIMEDATE_VALUE: - return icalvalue_datetimedate_as_ical_string(value); case ICAL_DURATION_VALUE: return icalvalue_duration_as_ical_string(value); - case ICAL_TIME_VALUE: - return icalvalue_time_as_ical_string(value); case ICAL_PERIOD_VALUE: return icalvalue_period_as_ical_string(value); @@ -1033,20 +1019,29 @@ icalvalue_as_ical_string (icalvalue* value) case ICAL_TRIGGER_VALUE: return icalvalue_trigger_as_ical_string(value); + + case ICAL_REQUESTSTATUS_VALUE: + return icalreqstattype_as_string(value->data.v_requeststatus); case ICAL_ACTION_VALUE: + case ICAL_CMD_VALUE: + case ICAL_QUERYLEVEL_VALUE: + case ICAL_CARLEVEL_VALUE: case ICAL_METHOD_VALUE: case ICAL_STATUS_VALUE: case ICAL_TRANSP_VALUE: case ICAL_CLASS_VALUE: - if(v->x_value !=0){ - return icalmemory_tmp_copy(v->x_value); + if(value->x_value !=0){ + return icalmemory_tmp_copy(value->x_value); } - return icalproperty_enum_to_string(v->data.v_enum); + return icalproperty_enum_to_string(value->data.v_enum); case ICAL_X_VALUE: - return icalmemory_tmp_copy(v->x_value); + if (value->x_value != 0) + return icalmemory_tmp_copy(value->x_value); + + /* FALLTHRU */ case ICAL_NO_VALUE: default: @@ -1058,15 +1053,13 @@ icalvalue_as_ical_string (icalvalue* value) icalvalue_kind -icalvalue_isa (icalvalue* value) +icalvalue_isa (const icalvalue* value) { - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - if(value == 0){ return ICAL_NO_VALUE; } - return v->kind; + return value->kind; } @@ -1085,13 +1078,11 @@ icalvalue_isa_value (void* value) } -int icalvalue_is_time(icalvalue* a) { +static int icalvalue_is_time(const icalvalue* a) { icalvalue_kind kind = icalvalue_isa(a); - if(kind == ICAL_DATETIMEDATE_VALUE || - kind == ICAL_DATETIME_VALUE || - kind == ICAL_DATE_VALUE || - kind == ICAL_TIME_VALUE ){ + if(kind == ICAL_DATETIME_VALUE || + kind == ICAL_DATE_VALUE ){ return 1; } @@ -1099,11 +1090,14 @@ int icalvalue_is_time(icalvalue* a) { } +/* + * In case of error, this function returns 0. This is partly bogus, as 0 is + * not part of the returned enum. + * FIXME We should probably add an error value to the enum. + */ icalparameter_xliccomparetype -icalvalue_compare(icalvalue* a, icalvalue *b) +icalvalue_compare(const icalvalue* a, const icalvalue *b) { - struct icalvalue_impl *impla = (struct icalvalue_impl *)a; - struct icalvalue_impl *implb = (struct icalvalue_impl *)b; icalerror_check_arg_rz( (a!=0), "a"); icalerror_check_arg_rz( (b!=0), "b"); @@ -1115,10 +1109,27 @@ icalvalue_compare(icalvalue* a, icalvalue *b) } switch (icalvalue_isa(a)){ + case ICAL_ATTACH_VALUE: + { + if (icalattach_get_is_url(a->data.v_attach) && + icalattach_get_is_url(b->data.v_attach)) { + if (strcasecmp(icalattach_get_url(a->data.v_attach), + icalattach_get_url(b->data.v_attach)) == 0) + return ICAL_XLICCOMPARETYPE_EQUAL; + else + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + else { + if (a->data.v_attach == b->data.v_attach) + return ICAL_XLICCOMPARETYPE_EQUAL; + else + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + } case ICAL_BINARY_VALUE: { - if (impla->data.v_attach == implb->data.v_attach) + if (a->data.v_attach == b->data.v_attach) return ICAL_XLICCOMPARETYPE_EQUAL; else return ICAL_XLICCOMPARETYPE_NOTEQUAL; @@ -1135,9 +1146,9 @@ icalvalue_compare(icalvalue* a, icalvalue *b) case ICAL_FLOAT_VALUE: { - if (impla->data.v_float > implb->data.v_float){ + if (a->data.v_float > b->data.v_float){ return ICAL_XLICCOMPARETYPE_GREATER; - } else if (impla->data.v_float < implb->data.v_float){ + } else if (a->data.v_float < b->data.v_float){ return ICAL_XLICCOMPARETYPE_LESS; } else { return ICAL_XLICCOMPARETYPE_EQUAL; @@ -1147,9 +1158,9 @@ icalvalue_compare(icalvalue* a, icalvalue *b) case ICAL_INTEGER_VALUE: case ICAL_UTCOFFSET_VALUE: { - if (impla->data.v_int > implb->data.v_int){ + if (a->data.v_int > b->data.v_int){ return ICAL_XLICCOMPARETYPE_GREATER; - } else if (impla->data.v_int < implb->data.v_int){ + } else if (a->data.v_int < b->data.v_int){ return ICAL_XLICCOMPARETYPE_LESS; } else { return ICAL_XLICCOMPARETYPE_EQUAL; @@ -1158,12 +1169,12 @@ icalvalue_compare(icalvalue* a, icalvalue *b) case ICAL_DURATION_VALUE: { - int a = icaldurationtype_as_int(impla->data.v_duration); - int b = icaldurationtype_as_int(implb->data.v_duration); + int dur_a = icaldurationtype_as_int(a->data.v_duration); + int dur_b = icaldurationtype_as_int(b->data.v_duration); - if (a > b){ + if (dur_a > dur_b){ return ICAL_XLICCOMPARETYPE_GREATER; - } else if (a < b){ + } else if (dur_a < dur_b){ return ICAL_XLICCOMPARETYPE_LESS; } else { return ICAL_XLICCOMPARETYPE_EQUAL; @@ -1177,9 +1188,9 @@ icalvalue_compare(icalvalue* a, icalvalue *b) case ICAL_TRIGGER_VALUE: case ICAL_DATE_VALUE: case ICAL_DATETIME_VALUE: - case ICAL_DATETIMEDATE_VALUE: - case ICAL_TIME_VALUE: case ICAL_DATETIMEPERIOD_VALUE: + case ICAL_QUERY_VALUE: + case ICAL_RECUR_VALUE: { int r; @@ -1217,40 +1228,95 @@ icalvalue_compare(icalvalue* a, icalvalue *b) } + case ICAL_TRANSP_VALUE: + { + if (icalvalue_get_transp(a) == icalvalue_get_transp(b)){ + return ICAL_XLICCOMPARETYPE_EQUAL; + } else { + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + } + + case ICAL_ACTION_VALUE: + { + if (icalvalue_get_action(a) == icalvalue_get_action(b)){ + return ICAL_XLICCOMPARETYPE_EQUAL; + } else { + return ICAL_XLICCOMPARETYPE_NOTEQUAL; + } + } + case ICAL_PERIOD_VALUE: case ICAL_GEO_VALUE: - case ICAL_RECUR_VALUE: case ICAL_NO_VALUE: default: { icalerror_warn("Comparison not implemented for value type"); - return ICAL_XLICCOMPARETYPE_REGEX+1; /* HACK */ + return 0; } } } +/** Examine the value and possibly change the kind to agree with the + * value + */ + +void icalvalue_reset_kind(icalvalue* value) +{ + if( (value->kind==ICAL_DATETIME_VALUE || value->kind==ICAL_DATE_VALUE )&& + !icaltime_is_null_time(value->data.v_time) ) { + + if(icaltime_is_date(value->data.v_time)){ + value->kind = ICAL_DATE_VALUE; + } else { + value->kind = ICAL_DATETIME_VALUE; + } + } + +} + void icalvalue_set_parent(icalvalue* value, icalproperty* property) { - struct icalvalue_impl* v = (struct icalvalue_impl*)value; - - v->parent = property; - + value->parent = property; } icalproperty* icalvalue_get_parent(icalvalue* value) { - struct icalvalue_impl* v = (struct icalvalue_impl*)value; + return value->parent; +} - return v->parent; -} +int icalvalue_encode_ical_string(const char *szText, char *szEncText, int nMaxBufferLen) +{ + char *ptr; + icalvalue *value = 0; + + if ((szText == 0) || (szEncText == 0)) + return 0; + + value = icalvalue_new_from_string(ICAL_STRING_VALUE, szText); + + if (value == 0) + return 0; + + ptr = icalvalue_text_as_ical_string(value); + if (ptr == 0) + return 0; + + if ((int)strlen(ptr) >= nMaxBufferLen) + { + icalvalue_free (value); + return 0; + } + strcpy(szEncText, ptr); + icalvalue_free ((icalvalue*)value); + + return 1; +} /* The remaining interfaces are 'new', 'set' and 'get' for each of the value types */ - - -/* Everything below this line is machine generated. Do not edit. */ diff --git a/libical/src/libical/icalvalue.h b/libical/src/libical/icalvalue.h index 6983c23275..851e7234bc 100644 --- a/libical/src/libical/icalvalue.h +++ b/libical/src/libical/icalvalue.h @@ -7,8 +7,6 @@ $Id$ $Locker$ - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org This program is free software; you can redistribute it and/or modify @@ -40,46 +38,51 @@ #include "icalderivedvalue.h" /* Defined in icalderivedvalue.h */ -/*typedef void icalvalue;*/ +/*typedef struct icalvalue_impl icalvalue;*/ icalvalue* icalvalue_new(icalvalue_kind kind); -icalvalue* icalvalue_new_clone(icalvalue* value); +icalvalue* icalvalue_new_clone(const icalvalue* value); icalvalue* icalvalue_new_from_string(icalvalue_kind kind, const char* str); void icalvalue_free(icalvalue* value); -int icalvalue_is_valid(icalvalue* value); +int icalvalue_is_valid(const icalvalue* value); -const char* icalvalue_as_ical_string(icalvalue* value); +const char* icalvalue_as_ical_string(const icalvalue* value); -icalvalue_kind icalvalue_isa(icalvalue* value); +icalvalue_kind icalvalue_isa(const icalvalue* value); int icalvalue_isa_value(void*); -icalparameter_xliccomparetype icalvalue_compare(icalvalue* a, icalvalue *b); +icalparameter_xliccomparetype icalvalue_compare(const icalvalue* a, const icalvalue *b); /* Special, non autogenerated value accessors */ icalvalue* icalvalue_new_recur (struct icalrecurrencetype v); void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); -struct icalrecurrencetype icalvalue_get_recur(icalvalue* value); +struct icalrecurrencetype icalvalue_get_recur(const icalvalue* value); icalvalue* icalvalue_new_trigger (struct icaltriggertype v); void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v); -struct icaltriggertype icalvalue_get_trigger(icalvalue* value); +struct icaltriggertype icalvalue_get_trigger(const icalvalue* value); icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v); void icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v); -struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(icalvalue* value); +struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(const icalvalue* value); /* Convert enumerations */ icalvalue_kind icalvalue_string_to_kind(const char* str); -const char* icalvalue_kind_to_string(icalvalue_kind kind); +const char* icalvalue_kind_to_string(const icalvalue_kind kind); + +/** Check validity of a specific icalvalue_kind **/ +int icalvalue_kind_is_valid(const icalvalue_kind kind); +/** Encode a character string in ical format, esacpe certain characters, etc. */ +int icalvalue_encode_ical_string(const char *szText, char *szEncText, int MaxBufferLen); #endif /*ICALVALUE_H*/ diff --git a/libical/src/libical/icalvalue_cxx.cpp b/libical/src/libical/icalvalue_cxx.cpp new file mode 100644 index 0000000000..a1db030c33 --- /dev/null +++ b/libical/src/libical/icalvalue_cxx.cpp @@ -0,0 +1,262 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalvalue_cxx.cpp + CREATOR: fnguyen 12/21/01 + (C) COPYRIGHT 2001, Critical Path +======================================================================*/ + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +typedef char* string; // Will use the string library from STL + +ICalValue::ICalValue() throw(icalerrorenum) : imp(icalvalue_new(ICAL_ANY_VALUE)){} + +ICalValue::ICalValue(const ICalValue& v) throw (icalerrorenum) { + imp = icalvalue_new_clone(v.imp); + if (!imp) throw icalerrno; +} +ICalValue& ICalValue::operator=(const ICalValue& v) throw(icalerrorenum) { + if (this == &v) return *this; + + if (imp != NULL) + { + icalvalue_free(imp); + imp = icalvalue_new_clone(v.imp); + if (!imp) throw icalerrno; + } + + return *this; +} + +ICalValue::~ICalValue(){ + if (imp != NULL) icalvalue_free(imp); +} + +ICalValue::ICalValue(icalvalue* v) throw(icalerrorenum) : imp(v){ +} + +ICalValue::ICalValue(icalvalue_kind kind) throw(icalerrorenum) { + imp = icalvalue_new(kind); + if (!imp) throw icalerrno; +} + +ICalValue::ICalValue(icalvalue_kind kind, string str) throw(icalerrorenum) { + imp = icalvalue_new_from_string(kind, str); + if (!imp) throw icalerrno; +} + +string ICalValue::as_ical_string(){ + return (string)icalvalue_as_ical_string(imp); +} +bool ICalValue::is_valid(){ + if (imp == NULL) return false; + return (icalvalue_is_valid(imp) ? true : false); +} +icalvalue_kind ICalValue::isa(){ + return icalvalue_isa(imp); +} +int ICalValue::isa_value(void* value){ + return icalvalue_isa_value(value); +} + +/* Special, non autogenerated value accessors */ +void ICalValue::set_recur(struct icalrecurrencetype v){ + icalvalue_set_recur(imp, v); +} +struct icalrecurrencetype ICalValue::get_recur(){ + return icalvalue_get_recur(imp); +} + +void ICalValue::set_trigger(struct icaltriggertype v){} +struct icaltriggertype ICalValue::get_trigger(){ + return icalvalue_get_trigger(imp); +} + +void ICalValue::set_datetimeperiod(struct icaldatetimeperiodtype v){ + icalvalue_set_datetimeperiod(imp, v); +} +struct icaldatetimeperiodtype ICalValue::get_datetimeperiod(){ + return icalvalue_get_datetimeperiod(imp); +} + +icalparameter_xliccomparetype ICalValue::compare(ICalValue& a, ICalValue& b){ + return icalvalue_compare(a, b); +} + +/* Convert enumerations */ +icalvalue_kind ICalValue::string_to_kind(string str){ + return icalvalue_string_to_kind(str); +} +string ICalValue::kind_to_string(icalvalue_kind kind){ + return (string)icalvalue_kind_to_string(kind); +} + +/* BOOLEAN */ +int ICalValue::get_boolean(){ + return icalvalue_get_boolean(imp); +} +void ICalValue::set_boolean(int v){ + icalvalue_set_boolean(imp, v); +} + +/* UTC-OFFSET */ +int ICalValue::get_utcoffset(){ + return icalvalue_get_utcoffset(imp); +} +void ICalValue::set_utcoffset(int v){ + icalvalue_set_utcoffset(imp, v); +} + +/* METHOD */ +enum icalproperty_method ICalValue::get_method(){ + return icalvalue_get_method(imp); +} +void ICalValue::set_method(enum icalproperty_method v){ + icalvalue_set_method(imp, v); +} + +/* CAL-ADDRESS */ +string ICalValue::get_caladdress(){ + return (string)icalvalue_get_caladdress(imp); +} +void ICalValue::set_caladdress(string v){ + icalvalue_set_caladdress(imp, v); +} + +/* PERIOD */ +struct icalperiodtype ICalValue::get_period(){ + return icalvalue_get_period(imp); +} +void ICalValue::set_period(struct icalperiodtype v){ + icalvalue_set_period(imp, v); +} + +/* STATUS */ +enum icalproperty_status ICalValue::get_status(){ + return icalvalue_get_status(imp); +} +void ICalValue::set_status(enum icalproperty_status v){ + icalvalue_set_status(imp, v); +} + +/* BINARY */ +string ICalValue::get_binary(){ + return (string)icalvalue_get_binary(imp); +} +void ICalValue::set_binary(string v){ + icalvalue_set_binary(imp, v); +} + +/* TEXT */ +string ICalValue::get_text(){ + return (string)icalvalue_get_text(imp); +} +void ICalValue::set_text(string v){ + icalvalue_set_text(imp, v); +} + +/* DURATION */ +struct icaldurationtype ICalValue::get_duration(){ + return icalvalue_get_duration(imp); +} +void ICalValue::set_duration(struct icaldurationtype v){ + icalvalue_set_duration(imp, v); +} + +/* INTEGER */ +int ICalValue::get_integer(){ + return icalvalue_get_integer(imp); +} +void ICalValue::set_integer(int v){ + icalvalue_set_integer(imp, v); +} + +/* URI */ +string ICalValue::get_uri(){ + return (string)icalvalue_get_uri(imp); +} +void ICalValue::set_uri(string v){ + icalvalue_set_uri(imp, v); +} + +/* ATTACH */ +icalattach *ICalValue::get_attach(){ + return icalvalue_get_attach(imp); +} +void ICalValue::set_attach(icalattach *v){ + icalvalue_set_attach(imp, v); +} + +/* CLASS */ +enum icalproperty_class ICalValue::get_class(){ + return icalvalue_get_class(imp); +} +void ICalValue::set_class(enum icalproperty_class v){ + icalvalue_set_class(imp, v); +} + +/* FLOAT */ +float ICalValue::get_float(){ + return icalvalue_get_float(imp); +} +void ICalValue::set_float(float v){ + icalvalue_set_float(imp, v); +} + +/* QUERY */ +string ICalValue::get_query(){ + return (string)icalvalue_get_query(imp); +} +void ICalValue::set_query(string v){ + icalvalue_set_query(imp, v); +} + +/* STRING */ +string ICalValue::get_string(){ + return (string)icalvalue_get_string(imp); +} +void ICalValue::set_string(string v){ + icalvalue_set_string(imp, v); +} + +/* TRANSP */ +enum icalproperty_transp ICalValue::get_transp(){ + return icalvalue_get_transp(imp); +} +void ICalValue::set_transp(enum icalproperty_transp v){ + icalvalue_set_transp(imp, v); +} + +/* DATE-TIME */ +struct icaltimetype ICalValue::get_datetime(){ + return icalvalue_get_datetime(imp); +} +void ICalValue::set_datetime(struct icaltimetype v){ + icalvalue_set_datetime(imp, v); +} + +/* GEO */ +struct icalgeotype ICalValue::get_geo(){ + return icalvalue_get_geo(imp); +} +void ICalValue::set_geo(struct icalgeotype v){ + icalvalue_set_geo(imp, v); +} + +/* DATE */ +struct icaltimetype ICalValue::get_date(){ + return icalvalue_get_date(imp); +} +void ICalValue::set_date(struct icaltimetype v){ + icalvalue_set_date(imp, v); +} + +/* ACTION */ +enum icalproperty_action ICalValue::get_action(){ + return icalvalue_get_action(imp); +} +void ICalValue::set_action(enum icalproperty_action v){ + icalvalue_set_action(imp, v); +} diff --git a/libical/src/libical/icalvalue_cxx.h b/libical/src/libical/icalvalue_cxx.h new file mode 100644 index 0000000000..0023e84764 --- /dev/null +++ b/libical/src/libical/icalvalue_cxx.h @@ -0,0 +1,151 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalvalue_cxx.h + CREATOR: fnguyen 12/13/01 + (C) COPYRIGHT 2001, Critical Path +======================================================================*/ + +#ifndef CP_ICALVALUE_H +#define CP_ICALVALUE_H + +extern "C" { +#include "ical.h" +}; + +#include "icptrholder.h" + +typedef char* string; // Will use the string library from STL + +class ICalValue { +public: + ICalValue() throw(icalerrorenum); + ICalValue(const ICalValue&) throw(icalerrorenum); + ICalValue& operator=(const ICalValue&) throw(icalerrorenum); + ~ICalValue(); + + ICalValue(icalvalue*) throw(icalerrorenum); + ICalValue(icalvalue_kind kind) throw(icalerrorenum); + ICalValue(icalvalue_kind kind, string str) throw(icalerrorenum); + + operator icalvalue* () { return imp; } + + void detach() { + imp = NULL; + } + +public: + string as_ical_string(); + bool is_valid(); + icalvalue_kind isa(); + int isa_value(void*); + + /* Special, non autogenerated value accessors */ + void set_recur(struct icalrecurrencetype v); + struct icalrecurrencetype get_recur(); + + void set_trigger(struct icaltriggertype v); + struct icaltriggertype get_trigger(); + + void set_datetimeperiod(struct icaldatetimeperiodtype v); + struct icaldatetimeperiodtype get_datetimeperiod(); + +public: + static icalparameter_xliccomparetype compare(ICalValue& a, ICalValue& b); + + /* Convert enumerations */ + static icalvalue_kind string_to_kind(string str); + string kind_to_string(icalvalue_kind kind); + +public: + /* BOOLEAN */ + int get_boolean(); + void set_boolean(int v); + + /* UTC-OFFSET */ + int get_utcoffset(); + void set_utcoffset(int v); + + /* METHOD */ + enum icalproperty_method get_method(); + void set_method(enum icalproperty_method v); + + /* CAL-ADDRESS */ + string get_caladdress(); + void set_caladdress(string v); + + /* PERIOD */ + struct icalperiodtype get_period(); + void set_period(struct icalperiodtype v); + + /* STATUS */ + enum icalproperty_status get_status(); + void set_status(enum icalproperty_status v); + + /* BINARY */ + string get_binary(); + void set_binary(string v); + + /* TEXT */ + string get_text(); + void set_text(string v); + + /* DURATION */ + struct icaldurationtype get_duration(); + void set_duration(struct icaldurationtype v); + + /* INTEGER */ + int get_integer(); + void set_integer(int v); + + /* URI */ + string get_uri(); + void set_uri(string v); + + /* ATTACH */ + icalattach *get_attach(); + void set_attach(icalattach *v); + + /* CLASS */ + enum icalproperty_class get_class(); + void set_class(enum icalproperty_class v); + + /* FLOAT */ + float get_float(); + void set_float(float v); + + /* QUERY */ + string get_query(); + void set_query(string v); + + /* STRING */ + string get_string(); + void set_string(string v); + + /* TRANSP */ + enum icalproperty_transp get_transp(); + void set_transp(enum icalproperty_transp v); + + /* DATE-TIME */ + struct icaltimetype get_datetime(); + void set_datetime(struct icaltimetype v); + + /* GEO */ + struct icalgeotype get_geo(); + void set_geo(struct icalgeotype v); + + /* DATE */ + struct icaltimetype get_date(); + void set_date(struct icaltimetype v); + + /* ACTION */ + enum icalproperty_action get_action(); + void set_action(enum icalproperty_action v); + +private: + icalvalue* imp; +}; + + +typedef ICPointerHolder<ICalValue> ICalValueTmpPtr; /* see icptrholder.h for comments */ + +#endif /*ICALVALUE_H*/ diff --git a/libical/src/libical/icalvalueimpl.h b/libical/src/libical/icalvalueimpl.h index 8d39e6ca7f..d1ba7863ef 100644 --- a/libical/src/libical/icalvalueimpl.h +++ b/libical/src/libical/icalvalueimpl.h @@ -35,31 +35,9 @@ #define ICALVALUEIMPL_H #include "icalenums.h" +#include "icalproperty.h" #include "icalderivedvalue.h" -#include "icalderivedproperty.h" - -/* Private structure for ATTACH values */ -struct icalattach_impl { - /* Reference count */ - int refcount; - - union { - /* URL attachment data */ - struct { - char *url; - } url; - - /* Inline data */ - struct { - unsigned char *data; - icalattach_free_fn_t free_fn; - void *free_fn_data; - } data; - } u; - - /* TRUE if URL, FALSE if inline data */ - unsigned int is_url : 1; -}; + struct icalvalue_impl { icalvalue_kind kind; /*this is the kind that is visible from the outside*/ @@ -67,10 +45,10 @@ struct icalvalue_impl { char id[5]; int size; icalproperty* parent; - const char* x_value; + char* x_value; union data { - icalattach *v_attach; + icalattach *v_attach; /* void *v_binary; */ /* use v_attach */ const char *v_string; /*char *v_text;*/ @@ -92,6 +70,8 @@ struct icalvalue_impl { /*struct icaltimetype v_datetime;*/ /*struct icaltimetype v_datetimedate;*/ + struct icalreqstattype v_requeststatus; + /* struct icalrecurrencetype was once included directly ( not referenced ) in this union, but it contributes 2000 bytes to every value, so now it is @@ -112,6 +92,4 @@ struct icalvalue_impl { } data; }; -struct icalvalue_impl *icalvalue_new_impl(icalvalue_kind kind); - #endif diff --git a/libical/src/libical/icptrholder.h b/libical/src/libical/icptrholder.h new file mode 100644 index 0000000000..4161604951 --- /dev/null +++ b/libical/src/libical/icptrholder.h @@ -0,0 +1,93 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icptrholder.h + * @author wyau (08/29/02) + * @brief C++ template classes for managing C++ pointers returned by VComponent::get_..._component, + * VComponent::get_..._property, ICalPropety::get_..._value. + * @remarks VComponent::get... functions returns a C++ oject that wraps the libical implementation. + * It is important to note that the wrapped implementation still belongs to the orginal + * component. To stop memory leak, caller must delete the pointer. However, the destructor + * will call the appropriate free function. eg. ~VComponent calls icalcomponent_free(imp). + * As stated previously, imp stil belongs to the original component. To avoid freeing the + * wrapped "imp", caller must set the "imp" to null before deleting the pointer. + * + * The template class relieves the burden of memory management when used as a stack based + * object. The class holds a pointer to the C++ Wrapper. The destructor set the imp to + * null before deleting the pointer. + * + * Each C++ Wrapper instantiates a template class in it's corresponding .h file. + * + * Usage example: + * VComponentTmpPtr p; // VComponentTmpPtr is an instantiation of this template + * for (p=component.get_first_component; p!= NULL; p=component.get_next_component) { + * + * (C) COPYRIGHT 2001, Critical Path + */ + +#ifndef __ICPTRHOLDER_H__ +#define __ICPTRHOLDER_H__ + +template<class T> class ICPointerHolder { +public: + ICPointerHolder() { ptr = NULL; } + ICPointerHolder(T* p) { ptr = p; } + + // copy constructor to support assignment + ICPointerHolder(const ICPointerHolder& ip) { + ptr = ip.ptr; + + // We need to transfer ownership of ptr to this object by setting + // ip's ptr to null. Otherwise, ptr will de deleted twice. + // const ugliness requires us to do the const_cast. + ICPointerHolder *ipp = const_cast<ICPointerHolder*>(&ip); + ipp->ptr = NULL; + }; + + ~ICPointerHolder() { + release(); + } + + ICPointerHolder& operator=(T* p) { + this->release(); + ptr = p; + return *this; + } + + ICPointerHolder& operator=(ICPointerHolder& p) { + this->release(); + ptr = p.ptr; // this transfer ownership of the pointer + p.ptr = NULL; // set it to null so the pointer won't get delete twice. + return *this; + } + + int operator!=(T* p) {return (ptr != p);} + int operator==(T* p) {return (ptr == p);} + + operator T*() const { + return ptr; + } + + T* operator->() const { + assert(ptr); + return ptr; + } + + T& operator*() { + assert(ptr); + return *ptr; + } + +private: + void release() { + if (ptr != NULL) { + ptr->detach(); + delete ptr; + ptr = NULL; + } + } + + T* ptr; +}; + +#endif diff --git a/libical/src/libical/pvl.c b/libical/src/libical/pvl.c index 2a733e8aa9..9c271ce953 100644 --- a/libical/src/libical/pvl.c +++ b/libical/src/libical/pvl.c @@ -15,9 +15,7 @@ #include <assert.h> #include <stdlib.h> - - -/* +/** struct pvl_list_t The list structure. This is the hanlde for the entire list @@ -28,35 +26,30 @@ typedef struct pvl_list_t { - int MAGIC; /* Magic Identifier */ - struct pvl_elem_t *head; /* Head of list */ - struct pvl_elem_t *tail; /* Tail of list */ - int count; /* Number of items in the list */ - struct pvl_elem_t *p; /* Pointer used for iterators */ + int MAGIC; /**< Magic Identifier */ + struct pvl_elem_t *head; /**< Head of list */ + struct pvl_elem_t *tail; /**< Tail of list */ + int count; /**< Number of items in the list */ + struct pvl_elem_t *p; /**< Pointer used for iterators */ } pvl_list_t; -/* This global is incremented for each call to pvl_new_element(); it gives each - * list a unique identifer */ +/** + * This global is incremented for each call to pvl_new_element(); it gives each + * list a unique identifer + */ int pvl_elem_count = 0; int pvl_list_count = 0; -/*---------------------------------------------------------------------- - Function: pvl_list pvl_newlist() - - Purpose: - - Creates a new list, clears the pointers and assigns a magic number - - Returns: - - Pointer to the new list - 0 if there is no available memory. - *----------------------------------------------------------------------*/ +/** + * @brief Creates a new list, clears the pointers and assigns a magic number + * + * @return Pointer to the new list, 0 if there is no available memory. + */ pvl_list pvl_newlist() @@ -89,32 +82,23 @@ pvl_free(pvl_list l) free(L); } -/*---------------------------------------------------------------------- - Function: pvl_new_element(void *d, struct pvl_elem_t *next,struct pvl_elem_t *prior) - - Purpose: - Creates a new list element, assigns a magic number, and assigns - the next and previous pointers. - - Passing in the next and previous points may seem odd, but it allos the user - to set them while keeping the internal data hidden. In nearly all cases, - the user is the pvl library itself. - - Parameters: - - d The data item to be stored in the list - next Pointer value to assign to the member "next" - prior Pointer value to assign to the member "prior" - - Returns: - - A pointer to the new element. - 0 if there is no memory available. - - *----------------------------------------------------------------------*/ +/** + * @brief Creates a new list element, assigns a magic number, and assigns + * the next and previous pointers. + * + * Passing in the next and previous points may seem odd, but it allos the user + * to set them while keeping the internal data hidden. In nearly all cases, + * the user is the pvl library itself. + * + * @param d The data item to be stored in the list + * @param next Pointer value to assign to the member "next" + * @param prior Pointer value to assign to the member "prior" + * + * @return A pointer to the new element, 0 if there is no memory available. + */ pvl_elem -pvl_new_element(void *d, pvl_elem next,pvl_elem prior) +pvl_new_element(void *d, pvl_elem next, pvl_elem prior) { struct pvl_elem_t *E; @@ -132,25 +116,16 @@ pvl_new_element(void *d, pvl_elem next,pvl_elem prior) return (pvl_elem)E; } -/*---------------------------------------------------------------------- - Function: pvl_unshift(pvl_list l,void *d) - - Purpose: - - Add a new element to the from of the list - - Parameters: - - l The list to add the item to - d Pointer to the item to add - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Add a new element to the from of the list + * + * @param L The list to add the item to + * @param d Pointer to the item to add + */ void -pvl_unshift(pvl_list l,void *d) +pvl_unshift(pvl_list L,void *d) { - struct pvl_list_t *L = (struct pvl_list_t *)l; struct pvl_elem_t *E = pvl_new_element(d,L->head,0); if (E->next != 0) @@ -172,53 +147,37 @@ pvl_unshift(pvl_list l,void *d) L->count++; } -/*---------------------------------------------------------------------- - Function: pvl_shift(pvl_list l) - - Purpose: - - Remove an element from the front of the list - - Parameters: - - l The list to operate on - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Remove an element from the front of the list + * + * @param L The list to operate on + * + * @return the entry on the front of the list + */ void* -pvl_shift(pvl_list l) +pvl_shift(pvl_list L) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - if (L->head == 0) { return 0; } - return pvl_remove(l,(void*)L->head); + return pvl_remove(L,(void*)L->head); } -/*---------------------------------------------------------------------- - Function: void pvl_push(pvl_list l,void *d) - - Purpose: - - Add a new item to the tail of the list - - Paramters: - - l The list to operate on - d Pointer to the item to add - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Add a new item to the tail of the list + * + * @param L The list to operate on + * @param d Pointer to the item to add + * + */ void -pvl_push(pvl_list l,void *d) +pvl_push(pvl_list L,void *d) { - struct pvl_list_t *L = (struct pvl_list_t *)l; struct pvl_elem_t *E = pvl_new_element(d,0,L->tail); /* These are done in pvl_new_element @@ -242,59 +201,37 @@ pvl_push(pvl_list l,void *d) } -/*---------------------------------------------------------------------- - Function: void* pvl_pop(pvl_list l) - - Purpose: - - Remove an element from the tail of the list - - Paramters: - - l The list to operate on - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Remove an element from the tail of the list + * + * @param L The list to operate on + */ void* -pvl_pop(pvl_list l) +pvl_pop(pvl_list L) { - - struct pvl_list_t *L = (struct pvl_list_t *)l; - if ( L->tail == 0) { return 0; } - return pvl_remove(l,(void*) L->tail);; + return pvl_remove(L,(void*) L->tail);; } -/*---------------------------------------------------------------------- - Function: void pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) - - Purpose: - - Add a new item to a list that is ordered by a comparison function. - This routine assumes that the list is properly ordered. - - l The list to operate on - f Pointer to a comparison function - d Pointer to data to pass to the comparison function - - Returns: - - void - - *----------------------------------------------------------------------*/ +/** + * Add a new item to a list that is ordered by a comparison function. + * This routine assumes that the list is properly ordered. + * + * @param L The list to operate on + * @param f Pointer to a comparison function + * @param d Pointer to data to pass to the comparison function + */ void -pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) +pvl_insert_ordered(pvl_list L,pvl_comparef f,void *d) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - struct pvl_elem_t *P; L->count++; @@ -303,7 +240,7 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) if(L->head == 0) { - pvl_unshift(l,d); + pvl_unshift(L,d); return; } @@ -311,14 +248,14 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) if ( ((*f)(d,L->head->d)) <= 0) { - pvl_unshift(l,d); + pvl_unshift(L,d); return; } /* larger than tail, add to tail */ if ( (*f)(d,L->tail->d) >= 0) { - pvl_push(l,d); + pvl_push(L,d); return; } @@ -329,48 +266,34 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) { if ( (*f)(P->d,d) >= 0) { - pvl_insert_before(l,P,d); + pvl_insert_before(L,P,d); return; } } /* badness, choke */ - +#ifndef lint assert(0); - +#endif } -/*---------------------------------------------------------------------- - Function: void pvl_insert_after(pvl_list l,pvl_elem p,void *d) - - Purpose: - - Add a new item after the referenced element. - - Parameters: - - l The list to operate on - p The list element to add the item after - d Pointer to the item to add. - - Returns: - - void - - *----------------------------------------------------------------------*/ +/** + * @brief Add a new item after the referenced element. + * @param L The list to operate on + * @param P The list element to add the item after + * @param d Pointer to the item to add. + */ void -pvl_insert_after(pvl_list l,pvl_elem p,void *d) +pvl_insert_after(pvl_list L,pvl_elem P,void *d) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - struct pvl_elem_t *P = (struct pvl_elem_t *)p; struct pvl_elem_t *E = 0; L->count++; if (P == 0) { - pvl_unshift(l,d); + pvl_unshift(L,d); return; } @@ -388,34 +311,24 @@ pvl_insert_after(pvl_list l,pvl_elem p,void *d) } } -/*---------------------------------------------------------------------- - Function: void pvl_insert_before(pvl_list l,pvl_elem p,void *d) - - Purpose: - - Add an item after a referenced item - - Parameters: - - l The list to operate on - p The list element to add the item before - d Pointer to the data to be added. - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Add an item after a referenced item + * + * @param L The list to operate on + * @param P The list element to add the item before + * @param d Pointer to the data to be added. + */ void -pvl_insert_before(pvl_list l,pvl_elem p,void *d) +pvl_insert_before(pvl_list L,pvl_elem P,void *d) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - struct pvl_elem_t *P = (struct pvl_elem_t *)p; struct pvl_elem_t *E = 0; L->count++; if (P == 0) { - pvl_unshift(l,d); + pvl_unshift(L,d); return; } @@ -433,29 +346,19 @@ pvl_insert_before(pvl_list l,pvl_elem p,void *d) } } -/*---------------------------------------------------------------------- - Function: void pvl_remove(pvl_list l,pvl_elem e) - - Purpose: - - Remove the referenced item from the list - - This routine will free the element, but not the data item that the - element contains. - - Parameters: - - l The list to operate on - e The element to remove. - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Remove the referenced item from the list. + * + * This routine will free the element, but not the data item that the + * element contains. + * + * @param L The list to operate on + * @param E The element to remove. + */ void* -pvl_remove(pvl_list l,pvl_elem e) +pvl_remove(pvl_list L,pvl_elem E) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - struct pvl_elem_t *E = (struct pvl_elem_t *)e; void* data; if (E == L->head) @@ -504,28 +407,19 @@ pvl_remove(pvl_list l,pvl_elem e) } -/*---------------------------------------------------------------------- - Function: pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v) - - Purpose: - - Return a pointer to data that satisfies a function - - This routine will interate through the entire list and call the - find function for each item. It will break and return a pointer to the - data that causes the find function to return 1. - - Parameters: - - l The list to operate on - f Pointer to the find function - v Pointer to constant data to pass into the function - - Returns: - - Pointer to the element that the find function found. - - *----------------------------------------------------------------------*/ +/** + * @brief Return a pointer to data that satisfies a function. + * + * This routine will interate through the entire list and call the + * find function for each item. It will break and return a pointer to the + * data that causes the find function to return 1. + * + * @param l The list to operate on + * @param f Pointer to the find function + * @param v Pointer to constant data to pass into the function + * + * @return Pointer to the element that the find function found. + */ pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v) @@ -545,25 +439,17 @@ pvl_find(pvl_list l,pvl_findf f,void* v) return 0; } -/*---------------------------------------------------------------------- - Function: void* pvl_find_next(pvl_list l,pvl_findf f,void* v) - - Purpose: - - Like pvl_find(), but continues the search where the last find() or - find_next() left off - Parameters: - - l The list to operate on - f Pointer to the find function - v Pointer to constant data to pass into the function - - Returns: - - Pointer to the element that the find function found. - - *----------------------------------------------------------------------*/ +/** + * @brief Like pvl_find(), but continues the search where the last find() or + * find_next() left off. + * + * @param l The list to operate on + * @param f Pointer to the find function + * @param v Pointer to constant data to pass into the function + * + * @return Pointer to the element that the find function found. + */ pvl_elem pvl_find_next(pvl_list l,pvl_findf f,void* v) @@ -585,17 +471,10 @@ pvl_find_next(pvl_list l,pvl_findf f,void* v) } -/*---------------------------------------------------------------------- - Function: void pvl_clear(pvl_list l) - - Purpose: - - Remove the all the elements in the list. The does not free the data items - the elements hold. - - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Remove the all the elements in the list. The does not free + * the data items the elements hold. + */ void pvl_clear(pvl_list l) @@ -615,39 +494,25 @@ pvl_clear(pvl_list l) } } -/*---------------------------------------------------------------------- - Function: int pvl_count(pvl_list l) - - Purpose: - - Returns the number of items in the list. - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Returns the number of items in the list. + */ int -pvl_count(pvl_list l) +pvl_count(pvl_list L) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - return L->count; } -/*---------------------------------------------------------------------- - Function: pvl_elem pvl_next(pvl_elem e) - - Purpose: - Returns a pointer to the given element - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Returns a pointer to the given element + */ pvl_elem -pvl_next(pvl_elem e) +pvl_next(pvl_elem E) { - struct pvl_elem_t *E = (struct pvl_elem_t *)e; - if (E == 0){ return 0; } @@ -655,74 +520,42 @@ pvl_next(pvl_elem e) return (pvl_elem)E->next; } -/*---------------------------------------------------------------------- - Function: pvl_elem pvl_prior(pvl_elem e) - Purpose: - - Returns a pointer to the element previous to the element given. - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Returns a pointer to the element previous to the element given. + */ pvl_elem -pvl_prior(pvl_elem e) +pvl_prior(pvl_elem E) { - struct pvl_elem_t *E = (struct pvl_elem_t *)e; - return (pvl_elem)E->prior; } -/*---------------------------------------------------------------------- - Function: pvl_elem pvl_head(pvl_list l ) - - Purpose: - - Returns a pointer to the first item in the list. - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Returns a pointer to the first item in the list. + */ + pvl_elem -pvl_head(pvl_list l ) +pvl_head(pvl_list L ) { - struct pvl_list_t *L = (struct pvl_list_t *)l; - return (pvl_elem)L->head; } -/*---------------------------------------------------------------------- - Function: pvl_elem pvl_tail(pvl_list l) - - Purpose: - - Returns a pointer to the last item in the list. - - Returns: - *----------------------------------------------------------------------*/ +/** + * @brief Returns a pointer to the last item in the list. + */ pvl_elem -pvl_tail(pvl_list l) +pvl_tail(pvl_list L) { - struct pvl_list_t *L = (struct pvl_list_t *)l; return (pvl_elem)L->tail; } -/*---------------------------------------------------------------------- - Function: - - - Purpose: - - - Returns: - *----------------------------------------------------------------------*/ - #ifndef PVL_USE_MACROS void* -pvl_data(pvl_elem e) +pvl_data(pvl_elem E) { - struct pvl_elem_t *E = (struct pvl_elem_t *)e; - - if ( e == 0){ + if ( E == 0){ return 0; } @@ -730,23 +563,13 @@ pvl_data(pvl_elem e) } #endif -/*---------------------------------------------------------------------- - Function: void pvl_apply(pvl_list l,pvl_applyf f, void *v) - - Purpose: - - Call a function for every item in the list. - - Paramters: - - l The list to operate on - f Pointer to the function to call - v Data to pass to the function on every iteration - - Returns: - - void - *----------------------------------------------------------------------*/ +/** + * @brief Call a function for every item in the list. + * + * @param l The list to operate on + * @param f Pointer to the function to call + * @param v Data to pass to the function on every iteration + */ void pvl_apply(pvl_list l,pvl_applyf f, void *v) diff --git a/libical/src/libical/pvl.h b/libical/src/libical/pvl.h index 14a15a15eb..92ec546479 100644 --- a/libical/src/libical/pvl.h +++ b/libical/src/libical/pvl.h @@ -10,29 +10,29 @@ #ifndef __PVL_H__ #define __PVL_H__ -typedef void* pvl_list; -typedef void* pvl_elem; +typedef struct pvl_list_t* pvl_list; +typedef struct pvl_elem_t* pvl_elem; -/* - struct pvl_elem_t +/** + * This type is private. Always use pvl_elem instead. The struct would + * not even appear in this header except to make code in the USE_MACROS + * blocks work + */ - This type is private. Always use pvl_elem instead. The struct would - not even appear in this header except to make code in the USE_MACROS - blocks work - - */ typedef struct pvl_elem_t { - int MAGIC; /* Magic Identifier */ - void *d; /* Pointer to data user is storing */ - struct pvl_elem_t *next; /* Next element */ - struct pvl_elem_t *prior; /* prior element */ + int MAGIC; /**< Magic Identifier */ + void *d; /**< Pointer to data user is storing */ + struct pvl_elem_t *next; /**< Next element */ + struct pvl_elem_t *prior; /**< Prior element */ } pvl_elem_t; -/* This global is incremented for each call to pvl_new_element(); it gives each - * list a unique identifer */ +/** + * This global is incremented for each call to pvl_new_element(); it gives each + * list a unique identifer + */ extern int pvl_elem_count; extern int pvl_list_count; @@ -81,8 +81,11 @@ typedef int (*pvl_findf)(void* a, void* b); /*a is list elem, b is other data*/ pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v); pvl_elem pvl_find_next(pvl_list l,pvl_findf f,void* v); -/* Pass each element in the list to a function */ -typedef void (*pvl_applyf)(void* a, void* b); /*a is list elem, b is other data*/ +/** + * Pass each element in the list to a function + * a is list elem, b is other data + */ +typedef void (*pvl_applyf)(void* a, void* b); void pvl_apply(pvl_list l,pvl_applyf f, void *v); diff --git a/libical/src/libical/sspm.c b/libical/src/libical/sspm.c index 311747c8f5..c6647d37af 100644 --- a/libical/src/libical/sspm.c +++ b/libical/src/libical/sspm.c @@ -45,6 +45,11 @@ #include "dmalloc.h" #endif +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + #define TMP_BUF_SIZE 1024 @@ -85,7 +90,7 @@ char* sspm_strdup(char* str){ } -struct major_content_type_map +static struct major_content_type_map { enum sspm_major_type type; char* str; @@ -104,7 +109,7 @@ struct major_content_type_map {SSPM_UNKNOWN_MAJOR_TYPE,"" }, }; -struct minor_content_type_map +static struct minor_content_type_map { enum sspm_minor_type type; char* str; @@ -233,7 +238,7 @@ char* sspm_value(char* line) } -char *mime_headers[] = { +static char *mime_headers[] = { "Content-Type", "Content-Transfer-Encoding", "Content-Disposition", @@ -358,7 +363,7 @@ enum line_type { }; -enum line_type get_line_type(char* line){ +static enum line_type get_line_type(char* line){ if (line == 0){ return EMPTY; @@ -382,7 +387,7 @@ enum line_type get_line_type(char* line){ } -struct sspm_action_map get_action(struct mime_impl *impl, +static struct sspm_action_map get_action(struct mime_impl *impl, enum sspm_major_type major, enum sspm_minor_type minor) { @@ -948,7 +953,8 @@ void sspm_read_header(struct mime_impl *impl,struct sspm_header *header) assert(strlen(buf) < BUF_SIZE); - strcpy(header_lines[current_line],buf); + strncpy(header_lines[current_line],buf,BUF_SIZE-1); + header_lines[current_line][BUF_SIZE-1] = '\0'; break; } @@ -983,7 +989,7 @@ void sspm_read_header(struct mime_impl *impl,struct sspm_header *header) assert( strlen(buf_start) + strlen(last_line) < BUF_SIZE); - strcat(last_line,buf_start); + strncat(last_line,buf_start,BUF_SIZE-strlen(last_line)-1); break; } @@ -1163,7 +1169,7 @@ char *decode_base64(char *dest, char *src, size_t *size) { - int cc; + int cc = 0; char buf[4] = {0,0,0,0}; int p = 0; int valid_data = 0; diff --git a/libical/src/libical/vcomponent.cpp b/libical/src/libical/vcomponent.cpp new file mode 100644 index 0000000000..27ea61a7f8 --- /dev/null +++ b/libical/src/libical/vcomponent.cpp @@ -0,0 +1,817 @@ +/** + * @file vcomponent.cpp + * @author fnguyen (12/10/01) + * @brief Implemenation of C++ Wrapper for icalcomponent.c + * + * (C) COPYRIGHT 2001, Critical Path + */ + +#ifndef VCOMPONENT_H +#include "vcomponent.h" +#endif + +#ifndef ICALVALUE_CXX_H +#include "icalvalue_cxx.h" +#endif + +#ifndef ICALPROPERTY_CXX_H +#include "icalproperty_cxx.h" +#endif + +#ifndef ICALPARAMETER_CXX_H +#include "icalparameter_cxx.h" +#endif +#include <stdlib.h> +#include <string.h> + +#include <exception> + +VComponent::VComponent() throw(icalerrorenum) : imp(icalcomponent_new(ICAL_ANY_COMPONENT)) { +} +VComponent::VComponent(const VComponent& v) throw(icalerrorenum) { + imp = icalcomponent_new_clone(v.imp); + if (!imp) throw icalerrno; +} + +VComponent& VComponent::operator=(const VComponent& v) throw(icalerrorenum) { + if (this == &v) return *this; + + if (imp != NULL) + { + icalcomponent_free(imp); + imp = icalcomponent_new_clone(v.imp); + if (!imp) throw icalerrno; + } + + return *this; +} + +VComponent::~VComponent(){ + if (imp) + icalcomponent_free(imp); +} + +VComponent::VComponent(icalcomponent* v) throw (icalerrorenum) : imp(v){ +} + +/* char* returned is in the ring buffer. caller doesn't have to free it */ +char* VComponent::quote_ical_string(char *str){ + const char* p; + size_t buf_sz; + buf_sz = strlen(str) * 2; /* assume worse case scenarios. otherwise, we have to parse the string and count \ */ + char* out = (char*)icalmemory_new_buffer(buf_sz); /* memory is from the ring buffer */ + char* pout; + + if (out == 0){ + return 0; + } + + pout = out; + + for (p = str; *p!=0; p++){ + + if( *p == '\\'){ + *pout++ = '\\'; + } + *pout++ = *p; + + } + *pout++ = '\0'; + + return out; +} + +/** + * @brief Constructor + * + * Create a new VComponent from a string. + * + * @exception ICAL_MALFORMEDDATA_ERROR + * Catch this error if you + * + */ +VComponent::VComponent(string str) throw (icalerrorenum) { + // Fix for BUG #15647, but breaks fix for BUG #15596. Attempting a UI fix for cal-4.0. + //char* quoted_str = quote_ical_string((char *)str); + //imp = icalcomponent_new_from_string(quoted_str); + imp = icalcomponent_new_from_string(str); + + if (!imp) throw icalerrno; +} + +VComponent::VComponent(icalcomponent_kind kind) throw(icalerrorenum) { + imp = icalcomponent_new(kind); + + if (!imp) throw icalerrno; +} + + +string VComponent::as_ical_string() throw(icalerrorenum) { + char *str = icalcomponent_as_ical_string(imp); + + if (!str) throw icalerrno; + + return(str); +} + + +bool VComponent::is_valid(){ + if (imp == NULL) return false; + return (icalcomponent_is_valid(imp) ? true : false); +} + +icalcomponent_kind VComponent::isa(){ + return icalcomponent_isa(imp); +} + +int VComponent::isa_component(void* component){ + return icalcomponent_isa_component(component); +} + +void VComponent::new_from_string(string str){ + if (imp != NULL) icalcomponent_free(imp); + imp = icalcomponent_new_from_string(str); +} + +/* Working with properties */ +void VComponent::add_property(ICalProperty* property){ + icalcomponent_add_property(imp, *property); +} +void VComponent::remove_property(ICalProperty* property){ + icalcomponent_remove_property(imp, *property); + icalproperty_free(*property); + property->detach(); // set imp to null, it's free already. +} +int VComponent::count_properties(icalproperty_kind kind){ + return icalcomponent_count_properties(imp, kind); +} + +/* Iterate through the properties */ +ICalProperty* VComponent::get_current_property(){ + icalproperty* t = icalcomponent_get_current_property(imp); + return ((t != NULL) ? new ICalProperty(t) : NULL); +} + +ICalProperty* VComponent::get_first_property(icalproperty_kind kind){ + icalproperty* t = icalcomponent_get_first_property(imp, kind); + return ((t != NULL) ? new ICalProperty(t) : NULL); +} + +ICalProperty* VComponent::get_next_property(icalproperty_kind kind){ + icalproperty* t = icalcomponent_get_next_property(imp, kind); + return ((t != NULL) ? new ICalProperty(t) : NULL); +} + +/* Working with components */ +/* Return the first VEVENT, VTODO or VJOURNAL sub-component if it is one of those types */ +VComponent* VComponent::get_inner(){ + return new VComponent(icalcomponent_get_inner(imp)); +} + +void VComponent::add_component(VComponent* child){ + icalcomponent_add_component(imp, *child); +} +void VComponent::remove_component(VComponent* child){ + icalcomponent_remove_component(imp, *child); +} +int VComponent::count_components(icalcomponent_kind kind){ + return icalcomponent_count_components(imp, kind); +} + +/* Iteration Routines. There are two forms of iterators, internal and + external. The internal ones came first, and are almost completely + sufficient, but they fail badly when you want to construct a loop that + removes components from the container. +*/ + +/* Iterate through components */ +VComponent* VComponent::get_current_component(){ + icalcomponent* t = icalcomponent_get_current_component(imp); + return ((t != NULL) ? new VComponent(t) : NULL); +} +VComponent* VComponent::get_first_component(icalcomponent_kind kind){ + VComponent* result = NULL; + icalcomponent* t = icalcomponent_get_first_component(imp, kind); + if (t != NULL) { + switch (kind) { + case ICAL_VALARM_COMPONENT: + result = new VAlarm(t); + break; + case ICAL_VCALENDAR_COMPONENT: + result = new VCalendar(t); + break; + case ICAL_VEVENT_COMPONENT: + result = new VEvent(t); + break; + case ICAL_VQUERY_COMPONENT: + result = new VQuery(t); + break; + case ICAL_VTODO_COMPONENT: + result = new VToDo(t); + break; + case ICAL_VAGENDA_COMPONENT: + result = new VAgenda(t); + break; + default: + result = new VComponent(t); + } + } + + return (result); +} +VComponent* VComponent::get_next_component(icalcomponent_kind kind){ + VComponent* result = NULL; + icalcomponent* t = icalcomponent_get_next_component(imp, kind); + if (t != NULL) { + switch (kind) { + case ICAL_VALARM_COMPONENT: + result = new VAlarm(t); + break; + case ICAL_VCALENDAR_COMPONENT: + result = new VCalendar(t); + break; + case ICAL_VEVENT_COMPONENT: + result = new VEvent(t); + break; + case ICAL_VQUERY_COMPONENT: + result = new VQuery(t); + break; + case ICAL_VTODO_COMPONENT: + result = new VToDo(t); + break; + case ICAL_VAGENDA_COMPONENT: + result = new VAgenda(t); + break; + default: + result = new VComponent(t); + } + } + + return (result); +} + +/* Using external iterators */ +icalcompiter VComponent::begin_component(icalcomponent_kind kind){ + return icalcomponent_begin_component(imp, kind); +} +icalcompiter VComponent::end_component(icalcomponent_kind kind){ + return icalcomponent_end_component(imp, kind); +} +VComponent* VComponent::next(icalcompiter* i){ + return (VComponent*)icalcompiter_next(i); +} +VComponent* VComponent::prev(icalcompiter* i){ + return (VComponent*)icalcompiter_prior(i); +} +VComponent* VComponent::current(icalcompiter* i){ + return (VComponent*)icalcompiter_deref(i); +} + +/* Working with embedded error properties */ +int VComponent::count_errors(){ + return icalcomponent_count_errors(imp); +} + +/* Remove all X-LIC-ERROR properties*/ +void VComponent::strip_errors(){ + icalcomponent_strip_errors(imp); +} + +/* Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/ +void VComponent::convert_errors(){ + icalcomponent_convert_errors(imp); +} + +/* Kind conversion routines */ +icalcomponent_kind VComponent::string_to_kind(string str){ + return icalcomponent_string_to_kind(str); +} +string VComponent::kind_to_string(icalcomponent_kind kind){ + return (string)icalcomponent_kind_to_string(kind); +} + +struct icaltimetype VComponent::get_dtstart(){ + return icalcomponent_get_dtstart(imp); +} +void VComponent::set_dtstart(struct icaltimetype v){ + icalcomponent_set_dtstart(imp, v); +} + +/* For the icalcomponent routines only, dtend and duration are tied + together. If you call the set routine for one and the other exists, + the routine will calculate the change to the other. That is, if + there is a DTEND and you call set_duration, the routine will modify + DTEND to be the sum of DTSTART and the duration. If you call a get + routine for one and the other exists, the routine will calculate + the return value. If you call a set routine and neither exists, the + routine will create the apcompriate comperty. +*/ + +struct icaltimetype VComponent::get_dtend(){ + return icalcomponent_get_dtend(imp); +} + +void VComponent::set_dtend(struct icaltimetype v){ + icalcomponent_set_dtend(imp, v); +} + +struct icaltimetype VComponent::get_due(){ + return icalcomponent_get_due(imp); +} +void VComponent::set_due(struct icaltimetype v){ + icalcomponent_set_due(imp, v); +} + +struct icaldurationtype VComponent::get_duration(){ + return icalcomponent_get_duration(imp); +} +void VComponent::set_duration(struct icaldurationtype v){ + icalcomponent_set_duration(imp, v); +} + +icalproperty_method VComponent::get_method(){ + return icalcomponent_get_method(imp); +} +void VComponent::set_method(icalproperty_method method){ + icalcomponent_set_method(imp, method); +} + +struct icaltimetype VComponent::get_dtstamp(){ + return icalcomponent_get_dtstamp(imp); +} +void VComponent::set_dtstamp(struct icaltimetype v){ + icalcomponent_set_dtstamp(imp, v); +} + +string VComponent::get_summary(){ + return (string)icalcomponent_get_summary(imp); +} +void VComponent::set_summary(string v){ + icalcomponent_set_summary(imp, v); +} + +string VComponent::get_location(){ + return (string)icalcomponent_get_location(imp); +} +void VComponent::set_location(string v){ + icalcomponent_set_location(imp, v); +} + + +string VComponent::get_description(){ + return (string)icalcomponent_get_description(imp); +} +void VComponent::set_description(string v){ + icalcomponent_set_description(imp, v); +} +string VComponent::get_comment(){ + return (string)icalcomponent_get_comment(imp); +} +void VComponent::set_comment(string v){ + icalcomponent_set_comment(imp, v); +} + +string VComponent::get_uid(){ + return (string)icalcomponent_get_uid(imp); +} +void VComponent::set_uid(string v){ + icalcomponent_set_uid(imp, v); +} + +string VComponent::get_relcalid(){ + return (string)icalcomponent_get_relcalid(imp); +} +void VComponent::set_relcalid(string v){ + icalcomponent_set_relcalid(imp, v); +} + +struct icaltimetype VComponent::get_recurrenceid(){ + return icalcomponent_get_recurrenceid(imp); +} +void VComponent::set_recurrenceid(struct icaltimetype v){ + icalcomponent_set_recurrenceid(imp, v); +} + +int VComponent::get_sequence(){ + return (int)icalcomponent_get_sequence(imp); +} +void VComponent::set_sequence(int v){ + icalcomponent_set_sequence(imp, v); +} + +int VComponent::get_status(){ + return (int)icalcomponent_get_status(imp); +} +void VComponent::set_status(int v){ + icalcomponent_set_status(imp, v); +} + +/* For VCOMPONENT: Return a reference to the first VEVENT, VTODO, or VJOURNAL */ +VComponent* VComponent::get_first_real_component(){ + return (VComponent*)icalcomponent_get_first_real_component(imp); +} + +/* For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the start and end + times of an event in UTC */ +struct icaltime_span VComponent::get_span(){ + return icalcomponent_get_span(imp); +} + +int VComponent::recurrence_is_excluded( struct icaltimetype *dtstart, + struct icaltimetype *recurtime){ + return icalproperty_recurrence_is_excluded(imp, dtstart, recurtime); +} + + +/* Internal operations. They are private, and you should not be using them. */ +VComponent* VComponent::get_parent() { + return new VComponent(icalcomponent_get_parent(imp)); +} +void VComponent::set_parent(VComponent *parent){ + icalcomponent_set_parent(imp, *parent); +} + +/* ignoreValue means remove properties even if the data doesn't match */ +bool VComponent::remove(VComponent& fromVC, bool ignoreValue){ + + /* the two components must be the same kind */ + if (this->isa() != fromVC.isa()) return false; + + /* properties first */ + ICalPropertyTmpPtr propToBeRemoved; + for (propToBeRemoved=fromVC.get_first_property(ICAL_ANY_PROPERTY); propToBeRemoved != NULL; + propToBeRemoved=fromVC.get_next_property(ICAL_ANY_PROPERTY)) { + + /* loop through properties from this component */ + ICalPropertyTmpPtr next; + ICalPropertyTmpPtr p; + for (p=this->get_first_property(propToBeRemoved->isa()); p != NULL; p=next) { + next = this->get_next_property(propToBeRemoved->isa()); + if (ignoreValue) + this->remove_property(p); + else { + if (*p == *propToBeRemoved) { + this->remove_property(p); + break; + } + } + } + } + + /* components next - should remove by UID */ + VComponentTmpPtr comp; + for (comp=fromVC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL; + comp=fromVC.get_next_component(ICAL_ANY_COMPONENT)) { + const char* fromCompUid = comp->get_uid(); + VComponentTmpPtr c; + for (c=this->get_first_component(comp->isa()); c != NULL; + c=this->get_next_component(comp->isa())) { + const char* thisCompUid = c->get_uid(); + if (strcmp(fromCompUid, thisCompUid) == 0) { + // recursively go down the components + c->remove(*comp, ignoreValue); + // if all properties are removed and there is no sub-components, then + // remove this compoent + if ((c->count_properties(ICAL_ANY_PROPERTY) == 0) && + (c->count_components(ICAL_ANY_COMPONENT) == 0)) { + this->remove_component(c); + } + break; + } + } + } + + return true; +} +/* removeMissing == true: remove properties that are missing from fromC */ +/* todo: only change the first occurence of the property */ +/* todo: removeMissing is not implemented */ +bool VComponent::update(VComponent& fromC, bool removeMissing){ + + /* make sure they are the same kind */ + if (this->isa() != fromC.isa()) return false; + + /* property first */ + ICalPropertyTmpPtr prop; + for (prop=fromC.get_first_property(ICAL_ANY_PROPERTY); prop != NULL; + prop=fromC.get_next_property(ICAL_ANY_PROPERTY)) { + ICalPropertyTmpPtr thisProp; + thisProp = this->get_first_property(prop->isa()); + if (thisProp == NULL) { + thisProp = new ICalProperty(prop->isa()); + this->add_property(thisProp); + } + ICalValue *value = new ICalValue(*(prop->get_value())); // clone the value + thisProp->set_value(*value); + } + + /* recursively updating sub-components */ + VComponentTmpPtr comp; + for (comp=fromC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL; + comp=fromC.get_next_component(ICAL_ANY_COMPONENT)) { + VComponentTmpPtr thisComp; + thisComp = this->get_first_component(comp->isa()); + if (thisComp == NULL) { + thisComp = new VComponent(comp->isa()); + this->add_component(thisComp); + } + bool err = thisComp->update(*comp, removeMissing); + if (!err) return false; + } + return true; +} +/* add components and property. recursively goes down child components */ +bool VComponent::add(VComponent& fromC){ + /* make sure the kind are the same */ + if (this->isa() != fromC.isa()) return false; + + /* properties first */ + ICalPropertyTmpPtr prop; + for (prop=fromC.get_first_property(ICAL_ANY_PROPERTY); prop != NULL; + prop=fromC.get_next_property(ICAL_ANY_PROPERTY)) { + /* clone another property */ + ICalProperty *p = new ICalProperty(*prop); + add_property(p); + } + + /* sub-components next */ + bool err = false; + VComponentTmpPtr comp; + for (comp=fromC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL; + comp=fromC.get_next_component(ICAL_ANY_COMPONENT)) { + VComponent *c = new VComponent(comp->isa()); + err = c->add(*comp); + add_component(c); + } + + return true; +} + +VCalendar::VCalendar() : VComponent(icalcomponent_new_vcalendar()){ +} +VCalendar::VCalendar(const VCalendar& v) : VComponent(v) {} +VCalendar& VCalendar::operator=(const VCalendar& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VCalendar::~VCalendar(){} + +VCalendar::VCalendar(icalcomponent* v) : VComponent(v){} +VCalendar::VCalendar(string str) : VComponent(str){} + + +/* VEvent */ + +VEvent::VEvent() : VComponent(icalcomponent_new_vevent()){} +VEvent::VEvent(const VEvent& v) : VComponent(v) {} +VEvent& VEvent::operator=(const VEvent& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VEvent::~VEvent(){} + +VEvent::VEvent(icalcomponent* v) : VComponent(v){} +VEvent::VEvent(string str) : VComponent(str){} + + +/* VTodo */ + +VToDo::VToDo() : VComponent(icalcomponent_new_vtodo()){} +VToDo::VToDo(const VToDo& v) : VComponent(v) {} +VToDo& VToDo::operator=(const VToDo& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VToDo::~VToDo(){} + +VToDo::VToDo(icalcomponent* v) : VComponent(v){} +VToDo::VToDo(string str) : VComponent(str){} + + +/* VAgenda */ + +VAgenda::VAgenda() : VComponent(icalcomponent_new_vagenda()){} +VAgenda::VAgenda(const VAgenda& v) : VComponent(v) {} +VAgenda& VAgenda::operator=(const VAgenda& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VAgenda::~VAgenda(){} + +VAgenda::VAgenda(icalcomponent* v) : VComponent(v){} +VAgenda::VAgenda(string str) : VComponent(str){} + + +/* VQuery */ + +VQuery::VQuery() : VComponent(icalcomponent_new_vquery()){} +VQuery::VQuery(const VQuery& v) : VComponent(v) {} +VQuery& VQuery::operator=(const VQuery& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VQuery::~VQuery(){} + +VQuery::VQuery(icalcomponent* v) : VComponent(v){} +VQuery::VQuery(string str) : VComponent(str){} + + +/* VJournal */ + +VJournal::VJournal() : VComponent(icalcomponent_new_vjournal()){} +VJournal::VJournal(const VJournal& v) : VComponent(v) {} +VJournal& VJournal::operator=(const VJournal& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VJournal::~VJournal(){} + +VJournal::VJournal(icalcomponent* v) : VComponent(v){} +VJournal::VJournal(string str) : VComponent(str){} + + +/* VAlarm */ + +VAlarm::VAlarm() : VComponent(icalcomponent_new_valarm()){} +VAlarm::VAlarm(const VAlarm& v) : VComponent(v) {} +VAlarm& VAlarm::operator=(const VAlarm& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VAlarm::~VAlarm(){} + +VAlarm::VAlarm(icalcomponent* v) : VComponent(v){} +VAlarm::VAlarm(string str) : VComponent(str){} + +icalrequeststatus +VAlarm::getTriggerTime(VComponent &c, struct icaltriggertype *tr) +{ + struct icaltimetype tt; + ICalParameter *related_param; + + ICalPropertyTmpPtr trigger_prop = this->get_first_property(ICAL_TRIGGER_PROPERTY); + + // all VALARMs must have a TRIGGER + if (trigger_prop == NULL) + return ICAL_3_1_INVPROPVAL_STATUS; + + *tr = trigger_prop->get_trigger(); + + tt = icaltime_null_time(); + + if (icaltime_is_null_time(tr->time)) { + + // relative time trigger + + // TRIGGER;RELATED=END:P5M 5 minutes after END + // TRIGGER;RELATED=START:-P15M 15 minutes before START + // get RELATED parameter + + related_param = trigger_prop->get_first_parameter(ICAL_RELATED_PARAMETER); + + if (related_param && related_param->is_valid()) { + + // get RELATED parameter value + icalparameter_related related = related_param->get_related(); + + if(related) { + switch(related) { + case ICAL_RELATED_END: + if (c.isa() == ICAL_VEVENT_COMPONENT) { + tt = c.get_dtend(); + + // If a recurrenceid exists, use that to calculate the + // dtend from the dtstart. + struct icaltimetype recur_time = c.get_recurrenceid(); + if (!(icaltime_is_null_time(recur_time))) { + struct icaldurationtype dur = icaltime_subtract(c.get_dtstart(), tt); + tt = icaltime_add(recur_time, dur); + } + } + else if (c.isa() == ICAL_VTODO_COMPONENT) { + tt = c.get_due(); + struct icaltimetype recur_time = c.get_recurrenceid(); + if (!(icaltime_is_null_time(recur_time))) { + tt = recur_time; + } + } + // @@@ TODO: if not DTEND or DUE, then DTSTART and DURATION must be present + break; + case ICAL_RELATED_START: + case ICAL_RELATED_X: + case ICAL_RELATED_NONE: + default: + tt = c.get_dtstart(); + struct icaltimetype recur_time = c.get_recurrenceid(); + if (!(icaltime_is_null_time(recur_time))) { + tt = recur_time; + } + break; + } + + } + } + else { // no RELATED explicity specified, the default is + // relative to the start of an event or to-do, rfc2445 + // if no RELATED, we are forced to use dtstart for VEVENT, + // due for VTODO to calculate trigger time. + // If a recur time exists, use that. Recur time trumps dtstart or due. + struct icaltimetype recur_time = c.get_recurrenceid(); + if (!(icaltime_is_null_time(recur_time))) { + tt = recur_time; + } + else if (c.isa() == ICAL_VEVENT_COMPONENT) + tt = c.get_dtstart(); + else if (c.isa() == ICAL_VTODO_COMPONENT) + tt = c.get_due(); + } + + // malformed? encapsulating VEVENT or VTODO MUST have DTSTART/DTEND + if(icaltime_is_null_time(tt)) + return ICAL_3_1_INVPROPVAL_STATUS;; + + // now offset using tr.duration + tr->time = icaltime_add(tt, tr->duration); + } + // else absolute time trigger + + return ICAL_2_0_SUCCESS_STATUS; +} + + +/* VFreeBusy */ + +VFreeBusy::VFreeBusy() : VComponent(icalcomponent_new_vfreebusy()){} +VFreeBusy::VFreeBusy(const VFreeBusy& v) : VComponent(v) {} +VFreeBusy& VFreeBusy::operator=(const VFreeBusy& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VFreeBusy::~VFreeBusy(){} + +VFreeBusy::VFreeBusy(icalcomponent* v) : VComponent(v){} +VFreeBusy::VFreeBusy(string str) : VComponent(str){} + + +/* VTimezone */ + +VTimezone::VTimezone() : VComponent(icalcomponent_new_vtimezone()){} +VTimezone::VTimezone(const VTimezone& v) : VComponent(v) {} +VTimezone& VTimezone::operator=(const VTimezone& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +VTimezone::~VTimezone(){} + +VTimezone::VTimezone(icalcomponent* v) : VComponent(v){} +VTimezone::VTimezone(string str) : VComponent(str){} + + +/* XStandard */ + +XStandard::XStandard() : VComponent(icalcomponent_new_xstandard()){} +XStandard::XStandard(const XStandard& v) : VComponent(v) {} +XStandard& XStandard::operator=(const XStandard& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +XStandard::~XStandard(){} + +XStandard::XStandard(icalcomponent* v) : VComponent(v){} +XStandard::XStandard(string str) : VComponent(str){} + + +/* XDaylight */ + +XDaylight::XDaylight() : VComponent(icalcomponent_new_xdaylight()){} +XDaylight::XDaylight(const XDaylight& v) : VComponent(v) {} +XDaylight& XDaylight::operator=(const XDaylight& v){ + if (this == &v) return *this; + VComponent::operator=(v); + + return *this; +} +XDaylight::~XDaylight(){} + +XDaylight::XDaylight(icalcomponent* v) : VComponent(v){} +XDaylight::XDaylight(string str) : VComponent(str){} diff --git a/libical/src/libical/vcomponent.h b/libical/src/libical/vcomponent.h new file mode 100644 index 0000000000..fb128adc1c --- /dev/null +++ b/libical/src/libical/vcomponent.h @@ -0,0 +1,340 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file vcomponent.h + * @author fnguyen (12/10/01) + * @brief C++ classes for the icalcomponent wrapper (VToDo VEvent, etc..). + * + * (C) COPYRIGHT 2001, Critical Path + */ + +#ifndef VCOMPONENT_H +#define VCOMPONENT_H + +#include "ical.h" +#include "icptrholder.h" + +typedef char* string; // Will use the string library from STL + +class ICalProperty; + +/** + * @class VComponent + * @brief A class wrapping the libical icalcomponent functions + * + * @exception icalerrorenum Any errors generated in libical are + * propogated via this exception type. + */ + +class VComponent { +public: + VComponent() throw (icalerrorenum); + VComponent(const VComponent&) throw (icalerrorenum); + VComponent& operator=(const VComponent&) throw (icalerrorenum); + virtual ~VComponent(); + + VComponent(icalcomponent* v) throw (icalerrorenum); + VComponent(string str) throw (icalerrorenum); + VComponent(icalcomponent_kind kind) throw (icalerrorenum);; + + operator icalcomponent* () { return imp; } + + void new_from_string(string str); + + // detach imp to this object. use with caution. it would cause + // memory leak if you are not careful. + void detach() { + imp = NULL; + } + +public: + string as_ical_string() throw (icalerrorenum); + bool is_valid(); + icalcomponent_kind isa(); + int isa_component(void* component); + + /// Working with properties + void add_property(ICalProperty* property); + void remove_property(ICalProperty* property); + int count_properties(icalproperty_kind kind); + + // Iterate through the properties + ICalProperty* get_current_property(); + ICalProperty* get_first_property(icalproperty_kind kind); + ICalProperty* get_next_property(icalproperty_kind kind); + + // Working with components + + /** + * Return the first VEVENT, VTODO or VJOURNAL sub-component if + * it is one of those types + */ + + VComponent* get_inner(); + + void add_component(VComponent* child); + void remove_component(VComponent* child); + int count_components(icalcomponent_kind kind); + + /** + * Iteration Routines. There are two forms of iterators, + * internal and external. The internal ones came first, and + * are almost completely sufficient, but they fail badly when + * you want to construct a loop that removes components from + * the container. + */ + + /// Iterate through components + VComponent* get_current_component(); + VComponent* get_first_component(icalcomponent_kind kind); + VComponent* get_next_component(icalcomponent_kind kind); + + /// Using external iterators + icalcompiter begin_component(icalcomponent_kind kind); + icalcompiter end_component(icalcomponent_kind kind); + VComponent* next(icalcompiter* i); + VComponent* prev(icalcompiter* i); + VComponent* current(icalcompiter* i); + + /// Working with embedded error properties + int count_errors(); + + /// Remove all X-LIC-ERROR properties + void strip_errors(); + + /// Convert some X-LIC-ERROR properties into RETURN-STATUS properties + void convert_errors(); + + /// Kind conversion routines + static icalcomponent_kind string_to_kind(string str); + static string kind_to_string(icalcomponent_kind kind); + +public: + struct icaltimetype get_dtstart(); + void set_dtstart(struct icaltimetype v); + + /** For the icalcomponent routines only, dtend and duration + * are tied together. If you call the set routine for one and + * the other exists, the routine will calculate the change to + * the other. That is, if there is a DTEND and you call + * set_duration, the routine will modify DTEND to be the sum + * of DTSTART and the duration. If you call a get routine for + * one and the other exists, the routine will calculate the + * return value. If you call a set routine and neither + * exists, the routine will create the apropriate property + */ + + struct icaltimetype get_dtend(); + void set_dtend(struct icaltimetype v); + + struct icaltimetype get_due(); + void set_due(struct icaltimetype v); + + struct icaldurationtype get_duration(); + void set_duration(struct icaldurationtype v); + + icalproperty_method get_method(); + void set_method(icalproperty_method method); + + struct icaltimetype get_dtstamp(); + void set_dtstamp(struct icaltimetype v); + + string get_summary(); + void set_summary(string v); + + string get_location(); + void set_location(string v); + + string get_description(); + void set_description(string v); + + string get_comment(); + void set_comment(string v); + + string get_uid(); + void set_uid(string v); + + string get_relcalid(); + void set_relcalid(string v); + + struct icaltimetype get_recurrenceid(); + void set_recurrenceid(struct icaltimetype v); + + int get_sequence(); + void set_sequence(int v); + + int get_status(); + void set_status(int v); + + +public: + /** + * For VCOMPONENT: Return a reference to the first VEVENT, + * VTODO, or VJOURNAL + */ + VComponent* get_first_real_component(); + + /** + * For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the + * start and end times of an event in UTC + */ + virtual struct icaltime_span get_span(); + + int recurrence_is_excluded(struct icaltimetype *dtstart, + struct icaltimetype *recurtime); + + +public: + /** + helper functions for adding/removing/updating property and + sub-components */ + + /// Note: the VComponent kind have to be the same + + bool remove(VComponent&, bool ignoreValue); + bool update(VComponent&, bool removeMissing); + bool add(VComponent&); + +private: + /* Internal operations. They are private, and you should not be using them. */ + VComponent* get_parent(); + void set_parent(VComponent *parent); + + char* quote_ical_string(char* str); + +private: + icalcomponent* imp; +}; + +class VCalendar : public VComponent { +public: + VCalendar(); + VCalendar(const VCalendar&); + VCalendar& operator=(const VCalendar&); + ~VCalendar(); + + VCalendar(icalcomponent* v); + VCalendar(string str); +}; + + +class VEvent : public VComponent { +public: + VEvent(); + VEvent(const VEvent&); + VEvent& operator=(const VEvent&); + ~VEvent(); + + VEvent(icalcomponent* v); + VEvent(string str); +}; + +class VToDo : public VComponent { +public: + VToDo(); + VToDo(const VToDo&); + VToDo& operator=(const VToDo&); + ~VToDo(); + + VToDo(icalcomponent* v); + VToDo(string str); +}; + +class VAgenda : public VComponent { +public: + VAgenda(); + VAgenda(const VAgenda&); + VAgenda& operator=(const VAgenda&); + ~VAgenda(); + + VAgenda(icalcomponent* v); + VAgenda(string str); +}; + +class VQuery : public VComponent { +public: + VQuery(); + VQuery(const VQuery&); + VQuery& operator=(const VQuery&); + ~VQuery(); + + VQuery(icalcomponent* v); + VQuery(string str); +}; + +class VJournal : public VComponent { +public: + VJournal(); + VJournal(const VJournal&); + VJournal& operator=(const VJournal&); + ~VJournal(); + + VJournal(icalcomponent* v); + VJournal(string str); +}; + +class VAlarm : public VComponent { +public: + VAlarm(); + VAlarm(const VAlarm&); + VAlarm& operator=(const VAlarm&); + ~VAlarm(); + + VAlarm(icalcomponent* v); + VAlarm(string str); + + /** + * compute the absolute trigger time for this alarm. trigger + * may be related to the containing component c. the result + * is populated in tr->time + */ + icalrequeststatus getTriggerTime(VComponent &c, struct icaltriggertype *tr); +}; + +class VFreeBusy : public VComponent { +public: + VFreeBusy(); + VFreeBusy(const VFreeBusy&); + VFreeBusy& operator=(const VFreeBusy&); + ~VFreeBusy(); + + VFreeBusy(icalcomponent* v); + VFreeBusy(string str); +}; + +class VTimezone : public VComponent { +public: + VTimezone(); + VTimezone(const VTimezone&); + VTimezone& operator=(const VTimezone&); + ~VTimezone(); + + VTimezone(icalcomponent* v); + VTimezone(string str); +}; + +class XStandard : public VComponent { +public: + XStandard(); + XStandard(const XStandard&); + XStandard& operator=(const XStandard&); + ~XStandard(); + + XStandard(icalcomponent* v); + XStandard(string str); +}; + +class XDaylight : public VComponent { +public: + XDaylight(); + XDaylight(const XDaylight&); + XDaylight& operator=(const XDaylight&); + ~XDaylight(); + + XDaylight(icalcomponent* v); + XDaylight(string str); +}; + +typedef ICPointerHolder<VComponent> VComponentTmpPtr; /* see icptrholder.h for comments */ + +#endif /* VComponent_H */ diff --git a/libical/src/libical/vsnprintf.c b/libical/src/libical/vsnprintf.c index 6339183dd4..982920b21c 100644 --- a/libical/src/libical/vsnprintf.c +++ b/libical/src/libical/vsnprintf.c @@ -1,4 +1,7 @@ -#ifdef __osf__ +#ifndef WIN32 +#include "config.h" +#endif +#ifndef HAVE_SNPRINTF /* * Revision 12: http://theos.com/~deraadt/snprintf.c * @@ -25,12 +28,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef WIN32 #include <sys/param.h> -#include <sys/types.h> #include <sys/mman.h> +#include <unistd.h> +#endif +#include <sys/types.h> #include <signal.h> #include <stdio.h> -#include <unistd.h> #include <string.h> #if __STDC__ #include <stdarg.h> diff --git a/libical/src/libicalcap/Makefile.am b/libical/src/libicalcap/Makefile.am new file mode 100644 index 0000000000..b03a6717e4 --- /dev/null +++ b/libical/src/libicalcap/Makefile.am @@ -0,0 +1,77 @@ +#====================================================================== +# FILE: Makefile.am +# CREATOR: acampi +# +# $Id: Makefile.am,v 1.1 2003/09/11 22:04:28 hansp Exp $ +# +# +# (C) COPYRIGHT 2003, Andrea Campi, mailto:a.campi@inet.it +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# +# +#====================================================================== + + +lib_LTLIBRARIES = libicalcap.la + +noinst_LTLIBRARIES = libicalcap-static.la +libicalcap_static_la_SOURCES = $(libicalcap_la_SOURCES) +libicalcap_static_la_LDFLAGS = --all-static + +INCLUDES = \ + -I$(top_builddir) \ + -I$(top_srcdir)/src \ + -I$(top_builddir)/src \ + -I$(top_srcdir)/src/libical \ + -I$(top_builddir)/libical \ + -I$(srcdir) \ + -DWITH_RR $(RRCAP_CFLAGS) + +libicalcap_la_LDFLAGS = $(RRCAP_LIBS) -version-info 0:0:0 + + +libicalcap_la_SOURCES = \ + icalcap.c \ + icalcap.h \ + icalcap_impl.h \ + icalcap_message.c \ + icalcap_message_impl.h \ + icalcap_rr.c \ + icalcap_server.c \ + icalcap_server.h \ + icalcap_server_impl.h \ + icalcap_session.c \ + icalcap_session.h \ + icalcap_session_impl.h \ + icalcap_utils.c + +libicalcapincludedir = $(includedir) + +libicalcapinclude_HEADERS = \ + icalcap.h \ + icalcap_impl.h \ + icalcap_message_impl.h \ + icalcap_server.h \ + icalcap_server_impl.h \ + icalcap_session.h \ + icalcap_session_impl.h + + +noinst_PROGRAMS = client + +LDADD = ../libicalss/.libs/libicalss.a ../libicalvcal/.libs/libicalvcal.a $(cxx_libs) ../libical/.libs/libical.a libicalcap.la $(RRCAP_LIBS) + + +client_SOURCES = client.c + diff --git a/libical/src/libicalcap/client.c b/libical/src/libicalcap/client.c new file mode 100644 index 0000000000..399568ac79 --- /dev/null +++ b/libical/src/libicalcap/client.c @@ -0,0 +1,187 @@ +/*- + * $Id$ + * + * See the file LICENSE for redistribution information. + * If you have not received a copy of the license, please contact CodeFactory + * by email at info@codefactory.se, or on the web at http://www.codefactory.se/ + * You may also write to: CodeFactory AB, SE-903 47, Umeå, Sweden. + * + * Copyright (c) 2002 Jonas Borgström <jonas@codefactory.se> + * Copyright (c) 2002 Daniel Lundin <daniel@codefactory.se> + * Copyright (c) 2002 CodeFactory AB. All rights reserved. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include <librr/rr.h> + +#include "icalcap.h" +#include "icalcap_session.h" + +#define CLIENT_CAPABILITY \ +"Content-Type: text/html\n\n\ +BEGIN:VCALENDAR\n\ +VERSION:2.0\n\ +PRODIR:rrcap-client\n\ +CMD:REPLY\n\ +BEGIN:VREPLY\n\ +CAP-VERSION:1.0\n\ +PRODID:rrcap-client\n\ +QUERY-LEVEL:CAL-QL-NONE\n\ +CAR-LEVEL:CAR-FULL-NONE\n\ +DATE-MAX:99991231T235959Z\n\ +DATE-MIN:00000101T000000Z\n\ +MAX-COMPONENT-SIZE:0\n\ +COMPONENTS:VCALENDAR,VTODO,VJOURNAL,VEVENT,VCAR,\n\ + VALARM,VFREEBUSY,VTIMEZONE,STANDARD,DAYLIGHT,VREPLY\n\ +ITIP-VERSION:2447\n\ +RECUR-ACCEPTED:TRUE\n\ +RECUR-EXPAND:TRUE\n\ +RECUR-LIMIT:0\n\ +STORES-EXPANDED:FALSE\n\ +END:VREPLY\n\ +END:VCALENDAR\n" + + +icalcomponent * +icalcap_send_cmd(const icalcap *cap, const gchar *cmd, const gchar *id, int timeout) { + + icalcap_message*capmsg; + icalcomponent *comp, *ret = NULL; + icalproperty *prop; + + prop = icalproperty_vanew_cmd( + icalproperty_string_to_enum(cmd), + icalparameter_new_id(id), + 0); + + if (timeout > 0) { + char buf[16]; + + snprintf(buf, 16, "%d", timeout); + icalproperty_add_parameter(prop, + icalparameter_new_latency(buf)); + + icalproperty_add_parameter(prop, + icalparameter_new_actionparam(ICAL_ACTIONPARAM_ABORT)); + } + + comp = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version("2.0"), + icalproperty_new_prodid("-//I.Net spa//NONSGML//EN"), + prop, + 0); + + capmsg = icalcap_message_new(cap, comp); + ret = icalcap_message_sync_send(capmsg, timeout); + icalcap_message_free(capmsg); + icalcomponent_free(comp); + + return ret; +} + +icalcomponent * +icalcap_new_reply_component(const char *id, const icalcomponent *comp) { + + if (comp == NULL) + return NULL; + + return icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version("2.0"), + icalproperty_new_prodid("-//I.Net spa//NONSGML//EN"), + icalproperty_vanew_cmd( + ICAL_CMD_REPLY, +/* icalparameter_new_id(id), */ + 0), + comp, + 0); +} + + +static int +msg_handler(const icalcap_message *capmsg) { + + icalcomponent *reply; + + g_message("Got: %s", icalcomponent_as_ical_string(capmsg->comp)); + + /* FIXME Check it's a GET-CAPABILITY */ + + reply = icalcap_new_reply_component(NULL, capmsg->comp); + if (reply == NULL) { + return FALSE; + } + + icalcomponent_add_property(reply, + icalproperty_new_prodid("client")); + + icalcomponent_free(reply); + return TRUE; +} + +int +main (gint argc, gchar **argv) +{ + icalcap_session*conn; + icalcap *cap; + icalcomponent *comp; + + int i, n; + int verbose = 0; + + if ((conn = icalcap_session_new()) == NULL) { + fprintf(stderr, "Init failed\n"); + exit(0); + } + + if (!icalcap_session_connect(conn, "gundam.inet.it", 0)) { + fprintf(stderr, "Connect failed\n"); + exit(0); + } + + if (!icalcap_session_login(conn, "user@example.com", "user@example.com", "password")) { + fprintf(stderr, "Login failed\n"); + exit(0); + } + + if ((cap = icalcap_session_start(conn, msg_handler)) == NULL) { + fprintf(stderr, "Start failed\n"); + exit(0); + } + + if (argc > 1 && *argv[1] == '1') + n = 100; + else + n = 1; + + for (i=0; i<n; i++) { + g_print("Test 1: %d\n", i); + + if ((comp = icalcap_send_cmd(cap, "GET-CAPABILITY", "zero",15)) + == NULL) { + fprintf(stderr, "Send failed\n"); + exit(0); + } + + if (verbose) + g_print("Got %s\n", icalcomponent_as_ical_string(comp)); + + if (comp) + icalcomponent_free(comp); + } + + if (!icalcap_stop(cap)) { + fprintf(stderr, "Stop failed\n"); + exit(0); + } + + if (!icalcap_session_disconnect(conn)) { + fprintf(stderr, "Disconnect failed\n"); + exit(0); + } + + return 0; +} diff --git a/libical/src/libicalcap/icalcap.c b/libical/src/libicalcap/icalcap.c new file mode 100644 index 0000000000..8d404f0ad4 --- /dev/null +++ b/libical/src/libicalcap/icalcap.c @@ -0,0 +1,44 @@ +#include "config.h" + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include "icalcap.h" +#include "icalcap_impl.h" +#include "icalcap_session_impl.h" /* FIXME */ + + +void +icalcap_free(icalcap *cap) { + +#ifdef WITH_RR + icalcap_free_rr(cap); +#endif +} + +int +icalcap_stop(icalcap *cap) { + +#ifdef WITH_RR + return icalcap_stop_rr(cap); +#else + return 0; +#endif +} + +const char * +icalcap_get_username(const icalcap *cap) { + +#ifdef WITH_RR + if (cap == NULL || cap->username == NULL) + return NULL; + + return cap->username; +#else + return NULL; +#endif +} diff --git a/libical/src/libicalcap/icalcap.h b/libical/src/libicalcap/icalcap.h new file mode 100644 index 0000000000..5e61bf9c8e --- /dev/null +++ b/libical/src/libicalcap/icalcap.h @@ -0,0 +1,47 @@ +#ifndef __ICALCAP_H__ +#define __ICALCAP_H__ + +#include <ical.h> + +/* + * Opaque objects + */ +typedef struct _icalcap icalcap; +typedef struct _icalerror icalerror; +typedef struct _icalcap_message icalcap_message; + +/* + * Callback + */ +typedef int (*icalcap_msg_handler)(const icalcap_message *msg); + +/* + * icalcap member functions + */ +void icalcap_free(icalcap *cap); +int icalcap_stop(icalcap *cap); +const char *icalcap_get_username(const icalcap *cap); + +/* + * icalcap_message member functions + */ + +struct _icalcap_message { + icalcap *cap; + int type; + + icalcomponent *comp; +}; + +icalcap_message*icalcap_message_new(const icalcap *cap, const icalcomponent *comp); +icalcap_message*icalcap_message_new_reply(const icalcap_message *capmsg, const icalcomponent *comp); +void icalcap_message_free(icalcap_message *capmsg); + +int icalcap_message_reply_error(const icalcap_message *orig, enum icalrequeststatus status, + const char *msg, const char *debug); +int icalcap_message_reply_component(const icalcap_message *orig, icalcomponent *comp); + +int icalcap_message_send(icalcap_message *capmsg); +icalcomponent *icalcap_message_sync_send(icalcap_message *capmsg, int timeout); + +#endif diff --git a/libical/src/libicalcap/icalcap_impl.h b/libical/src/libicalcap/icalcap_impl.h new file mode 100644 index 0000000000..19f8c1db06 --- /dev/null +++ b/libical/src/libicalcap/icalcap_impl.h @@ -0,0 +1,34 @@ +#ifndef __ICALCAP_IMPL_H__ +#define __ICALCAP_IMPL_H__ + +#include "icalcap_session.h" + +#ifdef WITH_RR + +#include <librr/rr.h> +#include <librrsasl/rr-sasl.h> +#include <librrtls/rr-tls.h> +#include <librrcap/rr-cap.h> + +struct _icalcap { + RRCAP *chan; + const char *username, + *authname; +}; + +struct _icalerror { + GError *err; +}; + + +void icalcap_free_rr(icalcap *cap); + +int icalcap_stop_rr(icalcap *cap); + +icalcomponent *icalcap_send_component_rr(const icalcap *cap, const icalcomponent *comp, int timeout); + +#else +#error "No implementation of icalcap found!" +#endif + +#endif diff --git a/libical/src/libicalcap/icalcap_message.c b/libical/src/libicalcap/icalcap_message.c new file mode 100644 index 0000000000..32abbf0a73 --- /dev/null +++ b/libical/src/libicalcap/icalcap_message.c @@ -0,0 +1,225 @@ +#include "config.h" + +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include "ical.h" +#include "icalcap.h" +#include "icalcap_message_impl.h" + + +/** + * constructor + * + * Create a new icalcap_message from a component. This represents a command. + */ +icalcap_message * +icalcap_message_new(const icalcap *cap, const icalcomponent *comp) { + + icalcap_message *ret = NULL; + +#ifdef WITH_RR + ret = icalcap_message_new_rr(cap, comp); +#else + ret = NULL; +#endif + return ret; +} + +/** + * constructor + * + * Create a new icalcap_message from a component. This represents a reply. + */ +icalcap_message * +icalcap_message_new_reply(const icalcap_message *capmsg, const icalcomponent *comp) { + +#ifdef WITH_RR + return icalcap_message_new_reply_rr(capmsg, comp); +#else + return NULL; +#endif +} + +/** + * destructor + * + * Delete icalcap_message + */ +void +icalcap_message_free(icalcap_message *capmsg) { + +#ifdef WITH_RR + icalcap_message_free_rr(capmsg); +#else +#endif +} + +/** + * Send the icalcap_message and wait for an answer. + * The icalcap_message will be invalid after this call, and only valid call will be + * icalcap_message_free(). + */ +icalcomponent * +icalcap_message_sync_send(icalcap_message *capmsg, int timeout) { + + g_return_val_if_fail(capmsg, NULL); + +#ifdef WITH_RR + return icalcap_message_sync_send_rr(capmsg, timeout); +#else + return NULL; +#endif +} + +/** + * Send the icalcap_message. + * The icalcap_message will be invalid after this call, and only valid call will be + * icalcap_message_free(). + */ +int +icalcap_message_send(icalcap_message *capmsg) { + + int rc = FALSE; + char *str; + + g_return_val_if_fail(capmsg, FALSE); + +#ifdef WITH_RR + rc = icalcap_message_send_reply_rr(capmsg); +#else + rc = FALSE; +#endif + + return rc; +} + +/** + * Convenience method to send a component in reply to the given icalcap_message. + * The icalcomponent is not modified in any way. + * + * FIXME should be const icalcomponent * + */ +int +icalcap_message_reply_component(const icalcap_message *orig, icalcomponent *in) { + + icalcap_message*reply; + int rc; + + reply = icalcap_message_new_reply(orig, in); + if (reply == NULL) + return FALSE; + + rc = icalcap_message_send(reply); + icalcap_message_free(reply); + + return rc; +} + +/* Only used by icalcap_message_reply_error */ +static icalcomponent *new_reply_component(const icalcap_message *capmsg, const icalcomponent *comp); + +/** + * Convenience method to send an error in reply to the given icalcap_message. + */ +int +icalcap_message_reply_error(const icalcap_message *orig, enum icalrequeststatus status, + const char *msg, const char *debug) { + + struct icalreqstattype stat; + icalcomponent *comp, *vreply; + int rc; + + /* Prepare the REQUEST-STATUS */ + stat = icalreqstattype_from_string( + icalenum_reqstat_code(status)); + + if (msg != NULL) { + /* FIXME we used to do + stat.desc = strdup(msg); + but this created a memory leak. Maybe the destructor for reqstat? */ + stat.desc = msg; + } else { + stat.desc = icalenum_reqstat_desc(status); + } + + if (debug != NULL) + stat.debug = debug; + + /* Prepare a VREPLY component */ + vreply = icalcomponent_vanew( + ICAL_VREPLY_COMPONENT, + icalproperty_new_requeststatus(stat), + 0); + if (vreply == NULL) { + /* FIXME */ + return FALSE; + } + + comp = new_reply_component(orig, vreply); + + rc = icalcap_message_reply_component(orig, comp); + + icalcomponent_free(comp); + icalcomponent_free(vreply); + + return rc; +} + + +/* internal use */ + +/* only used by new_reply_component */ +static const char * +get_id(icalcomponent *comp) { + + icalproperty *prop; + icalparameter *param; + + prop = icalcomponent_get_first_property(comp, ICAL_CMD_PROPERTY); + if (prop == NULL) + return NULL; + + param = icalproperty_get_first_parameter(prop, ICAL_ID_PARAMETER); + if (param == NULL) + return NULL; + + return icalparameter_get_id(param); +} + +/* only used by icalcap_message_reply_error */ +static icalcomponent * +new_reply_component(const icalcap_message *capmsg, const icalcomponent *comp) { + + icalcomponent *clone, *cal, *root; + icalproperty *cmd; + const char *id; + + cmd = icalproperty_new_cmd(ICAL_CMD_REPLY); + + if (capmsg->comp != NULL) { + id = get_id(capmsg->comp); + + if (id != NULL) + icalproperty_add_parameter(cmd, icalparameter_new_id(id)); + } + + cal = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version("2.0"), + icalproperty_new_prodid("-//I.Net spa//NONSGML//EN"), + cmd, + 0); + + if (comp != NULL) { + clone = icalcomponent_new_clone(comp); + icalcomponent_add_component(cal, clone); + } + + root = icalcomponent_vanew( + ICAL_XROOT_COMPONENT, + cal, + 0); + return root; +} diff --git a/libical/src/libicalcap/icalcap_message_impl.h b/libical/src/libicalcap/icalcap_message_impl.h new file mode 100644 index 0000000000..ae234d2efa --- /dev/null +++ b/libical/src/libicalcap/icalcap_message_impl.h @@ -0,0 +1,33 @@ +#ifndef __ICALCAP_MESSAGE_IMPL_H__ +#define __ICALCAP_MESSAGE_IMPL_H__ + +#ifdef WITH_RR + +#include <ical.h> +#include <librr/rr.h> + +#define ICALCAP_MESSAGE_CMD 1 +#define ICALCAP_MESSAGE_REPLY 1 + +struct _icalcap_message_rr { + const icalcap *cap; + int type; + + icalcomponent *comp; + + RRFrame *frame; + RRMessage *msg; +}; + +icalcap_message*icalcap_message_new_rr(const icalcap *cap, const icalcomponent *comp); +icalcap_message*icalcap_message_new_reply_rr(const icalcap_message *capmsg, const icalcomponent *comp); +void icalcap_message_free_rr(icalcap_message *capmsg); + +int icalcap_message_send_reply_rr(icalcap_message *capmsg); +icalcomponent *icalcap_message_sync_send_rr(icalcap_message *capmsg, int timeout); + +#else +#error "No implementation of icalcap found!" +#endif + +#endif diff --git a/libical/src/libicalcap/icalcap_rr.c b/libical/src/libicalcap/icalcap_rr.c new file mode 100644 index 0000000000..7e464ee155 --- /dev/null +++ b/libical/src/libicalcap/icalcap_rr.c @@ -0,0 +1,545 @@ +#include "config.h" + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include "icalcap.h" +#include "icalcap_session.h" +#include "icalcap_server.h" + +#include "icalcap_impl.h" +#include "icalcap_message_impl.h" +#include "icalcap_session_impl.h" +#include "icalcap_server_impl.h" + +icalcomponent *icalcap_component_new_from_string(const char *data); + +static int default_msg_handler(RRCAP *cap, RRFrame *frame, GError **error); +static void client_final_handler(RRCAP *cap); + +/** + * Implementation of functions in icalcap + */ +void +icalcap_free_rr(icalcap *cap) { + + g_return_if_fail(cap); + + if (cap->username) + free(cap->username); + + if (cap->authname) + free(cap->authname); + + g_free(cap); +} + +/** + * Implementation of functions in icalcap_session + */ +icalcap_session * +icalcap_session_new_rr(void) { + + icalcap_session *sess; + GError *error = NULL; + + /* Initialize roadrunner */ + if (!rr_init(0, NULL, &error)) + return 0; + + if ((sess = g_new0(icalcap_session, 1)) == NULL) { + /* FIXME return an error */ + return NULL; + } + + sess->cfg = rr_cap_config_new(); + + /* Tell roadrunner which profiles we want to support */ + sess->profreg = rr_profile_registry_new(); + rr_profile_registry_add_profile(sess->profreg, RR_TYPE_CAP, NULL); + rr_profile_registry_add_profile(sess->profreg, RR_TYPE_TLS, NULL); + rr_profile_registry_add_profile(sess->profreg, RR_TYPE_SASL_DIGEST_MD5, NULL); + + return sess; +} + +int +icalcap_session_connect_rr(icalcap_session *sess, const char *hostname, const int port) { + + GError *error = NULL; + + if (sess == NULL) { + /* FIXME return the error */ + return FALSE; + } + + /* Create a connection object */ + sess->connection = rr_tcp_connection_new(sess->profreg, hostname, port, &error); + if (sess->connection == NULL) { + /* FIXME return the error */ + return FALSE; + } + + return TRUE; +} + +int +icalcap_session_login_rr(icalcap_session *sess, const char *username, const char *authname, + const char *password) { + + /* assert cap != NULL */ + GError *error = NULL; + + rr_sasl_set_username(sess->connection, username); + rr_sasl_set_authname(sess->connection, authname); + rr_sasl_set_password(sess->connection, password); + + /* FIXME */ + if (!rr_sasl_login(sess->connection, RR_TYPE_SASL_DIGEST_MD5, + "foo.example.com", NULL, &error)) { + /* FIXME return the error */ + return 0; + } + + return 1; +} + +icalcap * +icalcap_session_start_rr(const icalcap_session *sess, icalcap_msg_handler handler) { + + /* assert sess != NULL */ + icalcap *cap; + RRCAP *channel; + GError *error = NULL; + + if ((cap = g_new0(icalcap, 1)) == NULL) { + /* FIXME return an error */ + return NULL; + } + + if (handler != NULL) { + rr_cap_config_set_msg_handler(sess->cfg, default_msg_handler, (void *)handler); + /* FIXME rr_cap_config_set_final_handler(cfg, client_final_handler); */ + } + + if ((channel = rr_cap_client_start(sess->connection, sess->cfg, &error)) == NULL) { + /* FIXME return the error */ + goto FAILED; + } + + cap->chan = channel; + channel->hl = cap; + + return cap; + +FAILED: + g_free(cap); + return NULL; +} + +int +icalcap_stop_rr(icalcap *cap) { + + /* assert cap != NULL */ + GError *error = NULL; + + if (!rr_cap_close(cap->chan, &error)) { + /* FIXME return the error */ + return 0; + } + + cap->chan = NULL; + g_free(cap); + + return 1; +} + +int +icalcap_session_disconnect_rr(icalcap_session *sess) { + + /* assert cap != NULL */ + GError *error = NULL; + + if (!rr_connection_disconnect(sess->connection, &error)) { + /* FIXME return the error */ + return 0; + } + + sess->connection = NULL; + g_free(sess); + + if (!rr_exit(&error)) { + /* FIXME return the error */ + return 0; + } + + return 1; +} + +/** + * Implementation of functions in icalcap_server + */ + +/** + * If the user properly authenticated (via SASL), initialize the channel + * credentials. Otherwise, refuse to open the channel. + */ +static int +server_init_handler(RRCAP *chan, const gchar *piggyback, GError **error) { + + icalcap *cap; + RRConnection *connection; + + icalcap_auth_handler func; + const gchar *username, *authname; + int rc; + + g_return_val_if_fail(chan, FALSE); + g_return_val_if_fail(chan->cfg, FALSE); + g_return_val_if_fail(chan->cfg->server_init_data, FALSE); + + connection = rr_channel_get_connection(RR_CHANNEL(chan)); + if ((username = rr_sasl_get_username(connection)) == NULL) + return FALSE; + if ((authname = rr_sasl_get_authname(connection)) == NULL) + return FALSE; + + if ((cap = g_new0(icalcap, 1)) == NULL) { + return FALSE; + } + + cap->chan = chan; + chan->hl = cap; + + cap->username = strdup(username); + cap->authname = strdup(authname); + + func = (icalcap_auth_handler)chan->cfg->server_init_data; + return func(cap, piggyback); +} + +static void +server_confirmation_handler(RRCAP *chan) { + + icalcap_chanup_handler func; + + g_return_if_fail(chan); + g_return_if_fail(chan->cfg); + g_return_if_fail(chan->cfg->server_confirmation_data); + + func = (icalcap_chanup_handler)chan->cfg->server_confirmation_data; + + func(chan->hl); +} + +static gboolean +server_frame_handler(RRCAP *cap, RRFrame *frame, GError **error) +{ + if (frame->type == RR_FRAME_TYPE_MSG) + /* FIXME */ + return default_msg_handler(cap, frame, error); + else + return FALSE; +} + +static void +server_final_handler(RRCAP *cap) +{ + g_return_if_fail(cap); + g_return_if_fail(RR_CAP(cap)); + + if (cap->hl != NULL) { + icalcap_free(cap->hl); + cap->hl = NULL; + } +} + +/* + * FIXME Do we want to pass argc and argv in? + */ +icalcap_server * +icalcap_server_new_rr(icalcap_auth_handler auth_cb, icalcap_chanup_handler chanup_cb, + icalcap_msg_handler msg_cb) { + + icalcap_server *serv; + GError *error = NULL; + + /* Initialize roadrunner */ + if (!rr_init(0, NULL, &error)) + return 0; + + if ((serv = g_new0(icalcap_server, 1)) == NULL) { + /* FIXME return an error */ + return NULL; + } + serv->handler = msg_cb; + + /* This is somewhat hackish */ + serv->cfg = rr_cap_config_new(); + rr_cap_config_set_msg_handler(serv->cfg, NULL, (void *)msg_cb); + rr_cap_config_set_frame_handler(serv->cfg, server_frame_handler); + rr_cap_config_set_final_handler(serv->cfg, server_final_handler); + rr_cap_config_set_server_init_handler(serv->cfg, server_init_handler, (void *)auth_cb); + rr_cap_config_set_server_confirmation_handler(serv->cfg, + server_confirmation_handler, (void *)chanup_cb); + + /* Tell roadrunner which profiles we want to support */ + serv->profreg = rr_profile_registry_new(); + rr_profile_registry_add_profile(serv->profreg, RR_TYPE_CAP, serv->cfg); + rr_profile_registry_add_profile(serv->profreg, RR_TYPE_TLS, NULL); + rr_profile_registry_add_profile(serv->profreg, RR_TYPE_SASL_DIGEST_MD5, NULL); + + return serv; +} + +int +icalcap_server_listen_rr(icalcap_server *serv, const char *hostname, const int port) { + + GError *error = NULL; + g_return_val_if_fail(serv, FALSE); + + /* Create a listener object */ + serv->listener = rr_tcp_listener_new(serv->profreg, hostname, port, &error); + if (serv->listener == NULL) { + /* FIXME return the error */ + return FALSE; + } + + return TRUE; +} + +int +icalcap_server_run_rr(const icalcap_server *serv) { + + /* assert cap != NULL */ + GError *error = NULL; + + if (!rr_wait_until_done(&error)) { + /* FIXME return the error */ + return FALSE; + } + + return TRUE; +} + +int +icalcap_server_shutdown_rr(icalcap_server *serv) { + + /* assert cap != NULL */ + GError *error = NULL; + + if (!rr_listener_shutdown(serv->listener, &error)) { + /* FIXME return the error */ + return 0; + } + + serv->listener = NULL; + g_free(serv); + + return 1; +} + +/* + * icalcap_message.c + */ + +/* + * Internal constructor + */ +static struct _icalcap_message_rr * +_icalcap_message_new_from_component_rr(const icalcap *cap, int type, icalcomponent *comp) { + + struct _icalcap_message_rr *ret; + + if ((ret = g_new0(struct _icalcap_message_rr, 1)) == NULL) { + /* FIXME return an error */ + return NULL; + } + + ret->cap = cap; + ret->type = type; + + ret->comp = comp; + + return ret; +} + +static icalcap_message * +_icalcap_message_new_from_frame_rr(const icalcap *cap, int type, RRFrame *frame) { + + struct _icalcap_message_rr *ret; + + if ((ret = g_new0(struct _icalcap_message_rr, 1)) == NULL) { + /* FIXME return an error */ + return NULL; + } + + ret->cap = cap; + ret->type = type; + ret->frame = frame; + + ret->comp = icalcap_component_new_from_string(ret->frame->payload); + + return (icalcap_message *)ret; +} + +icalcap_message * +icalcap_message_new_rr(const icalcap *cap, const icalcomponent *comp) { + + struct _icalcap_message_rr *ret; + gchar *str; + + if (comp == NULL) { + /* FIXME return an error */ + return NULL; + } + + ret = _icalcap_message_new_from_component_rr(cap, ICALCAP_MESSAGE_CMD, NULL); + + str = g_strdup_printf("%s\n\n%s", + "Content-Type: text/calendar", + icalcomponent_as_ical_string(comp)); + + ret->msg = rr_message_static_new(RR_FRAME_TYPE_MSG, str, strlen(str), TRUE); + + return (icalcap_message *)ret; +} + +/* + * This method and its implementation are critical. It has the responsibility for + * serializing the component. The tricky part is that we have a options for encoding XROOT. + */ +icalcap_message * +icalcap_message_new_reply_rr(const icalcap_message *orig, const icalcomponent *comp) { + + struct _icalcap_message_rr *in, *ret; + icalcomponent *cc; + GString *str; + + if ((in = (struct _icalcap_message_rr *)orig) == NULL) { + /* FIXME return an error */ + return NULL; + } + + ret = _icalcap_message_new_from_component_rr(in->cap, ICALCAP_MESSAGE_REPLY, NULL); + + /* FIXME */ + if (icalcomponent_isa(comp) != ICAL_XROOT_COMPONENT) + return NULL; + + /* FIXME don't hardcode */ + str = g_string_new("Content-Type: text/calendar\n\n"); + + for (cc = icalcomponent_get_first_component(comp, + ICAL_VCALENDAR_COMPONENT); + cc != NULL; + cc = icalcomponent_get_next_component(comp, + ICAL_VCALENDAR_COMPONENT)) { + g_string_append(str, icalcomponent_as_ical_string(cc)); + } + + ret->msg = rr_message_static_new(RR_FRAME_TYPE_RPY, str->str, strlen(str->str), TRUE); + /* FIXME this should now be ok but if change the API we need to change */ + ret->msg->msgno = in->frame->msgno; + + return (icalcap_message *)ret; +} + +void +icalcap_message_free_rr(icalcap_message *in) { + + struct _icalcap_message_rr *capmsg = (struct _icalcap_message_rr *)in; + g_return_if_fail(capmsg); + + if (capmsg->comp != NULL) { + icalcomponent_free(capmsg->comp); + capmsg->comp = NULL; + } + + if (capmsg->msg != NULL) { + g_free(capmsg->msg); + } + + g_free(capmsg); +} + +int +icalcap_message_send_reply_rr(icalcap_message *in) { + + struct _icalcap_message_rr *capmsg = (struct _icalcap_message_rr *)in; + GError *error = NULL; + int rc; + + if ((rc = rr_channel_send_message(RR_CHANNEL(capmsg->cap->chan), capmsg->msg, &error)) == 0) + g_message("error = %s", error->message); + /* FIXME handle error */ + + capmsg->msg = NULL; + + return rc; +} + +icalcomponent * +icalcap_message_sync_send_rr(icalcap_message *in, int timeout) { + + struct _icalcap_message_rr *capmsg = (struct _icalcap_message_rr *)in; + icalcomponent *comp, *ret; + + gchar *str2; + GError *error = NULL; + int rc; + + /* FIXME */ + rc = rr_cap_cmd(capmsg->cap->chan, capmsg->msg, 3 * timeout, &str2, &error); + capmsg->msg = NULL; + if (rc == 0) { + g_message("error = %s", error->message); + /* FIXME handle error */ + return 0; + } + + comp = icalcap_component_new_from_string(str2); + g_free(str2); + if (ret == NULL) + return NULL; + + return comp; +} + +/* + * + */ + +/* + * FIXME We assume we can safely create an icalcap_message derived object + * without calls to the base object + */ +int +default_msg_handler(RRCAP *cap, RRFrame *frame, GError **error) { + + icalcap_msg_handler func; + icalcap_message *msg; + int ret; + + g_return_val_if_fail(cap, FALSE); + g_return_val_if_fail(cap->cfg, FALSE); + g_return_val_if_fail(cap->cfg->msg_handler_data, FALSE); + + func = (icalcap_msg_handler)cap->cfg->msg_handler_data; + + msg = _icalcap_message_new_from_frame_rr(cap->hl, ICALCAP_MESSAGE_CMD, frame); + if (msg == NULL) { + /* FIXME */ + g_message("error"); + return FALSE; + } + + ret = func(msg); + icalcap_message_free(msg); + + return ret; +} diff --git a/libical/src/libicalcap/icalcap_server.c b/libical/src/libicalcap/icalcap_server.c new file mode 100644 index 0000000000..77b8484554 --- /dev/null +++ b/libical/src/libicalcap/icalcap_server.c @@ -0,0 +1,52 @@ +#include "config.h" + +#include "icalcap.h" +#include "icalcap_server.h" +#include "icalcap_server_impl.h" + + +icalcap_server * +icalcap_server_new(icalcap_auth_handler auth_cb, icalcap_chanup_handler chanup_cb, + icalcap_msg_handler msg_cb) { + +#ifdef WITH_RR + return icalcap_server_new_rr(auth_cb, chanup_cb, msg_cb); +#else + return NULL; +#endif +} + +int +icalcap_server_listen(icalcap_server *cap, const char *hostname, const int _port) { + + int port = _port; + + if (port <= 0) + port = 1026; + +#ifdef WITH_RR + return icalcap_server_listen_rr(cap, hostname, port); +#else + return 0; +#endif +} + +int +icalcap_server_run(const icalcap_server *cap) { + +#ifdef WITH_RR + return icalcap_server_run_rr(cap); +#else + return 0; +#endif +} + +int +icalcap_server_shutdown(icalcap_server *cap) { + +#ifdef WITH_RR + return icalcap_server_shutdown_rr(cap); +#else + return 0; +#endif +} diff --git a/libical/src/libicalcap/icalcap_server.h b/libical/src/libicalcap/icalcap_server.h new file mode 100644 index 0000000000..53c73d3bab --- /dev/null +++ b/libical/src/libicalcap/icalcap_server.h @@ -0,0 +1,19 @@ +#ifndef __ICALCAP_SERVER_H__ +#define __ICALCAP_SERVER_H__ + +#include "icalcap.h" + +typedef struct _icalcap_server icalcap_server; + +typedef int (*icalcap_auth_handler)(const icalcap *cap, const char *piggyback); +typedef void (*icalcap_chanup_handler)(const icalcap *cap); + +icalcap_server*icalcap_server_new(icalcap_auth_handler auth_cb, + icalcap_chanup_handler chanup_cb, + icalcap_msg_handler msg_cb); + +int icalcap_server_listen(icalcap_server *cap, const char *hostname, const int port); +int icalcap_server_run(const icalcap_server *cap); +int icalcap_server_shutdown(icalcap_server *cap); + +#endif diff --git a/libical/src/libicalcap/icalcap_server_impl.h b/libical/src/libicalcap/icalcap_server_impl.h new file mode 100644 index 0000000000..c5d527d266 --- /dev/null +++ b/libical/src/libicalcap/icalcap_server_impl.h @@ -0,0 +1,31 @@ +#ifndef __ICALCAP_SERVER_IMPL_H__ +#define __ICALCAP_SERVER_IMPL_H__ + +#ifdef WITH_RR + +#include <librr/rr.h> +#include <librrsasl/rr-sasl.h> +#include <librrtls/rr-tls.h> +#include <librrcap/rr-cap.h> + +struct _icalcap_server { + RRProfileRegistry *profreg; + RRListener *listener; + RRCAPConfig *cfg; + icalcap_msg_handler handler; +}; + +icalcap_server *icalcap_server_new_rr(icalcap_auth_handler auth_cb, + icalcap_chanup_handler chanup_cb, + icalcap_msg_handler msg_cb); +int icalcap_server_listen_rr(icalcap_server *cap, + const char *hostname, + const int port); +int icalcap_server_run_rr(const icalcap_server *cap); +int icalcap_server_shutdown_rr(icalcap_server *cap); + +#else +#error "No implementation of icalcap found!" +#endif + +#endif diff --git a/libical/src/libicalcap/icalcap_session.c b/libical/src/libicalcap/icalcap_session.c new file mode 100644 index 0000000000..2f8fb2a701 --- /dev/null +++ b/libical/src/libicalcap/icalcap_session.c @@ -0,0 +1,62 @@ +#include "config.h" + +#include "icalcap.h" +#include "icalcap_session.h" +#include "icalcap_session_impl.h" + + +icalcap_session * +icalcap_session_new(void) { + +#ifdef WITH_RR + return icalcap_session_new_rr(); +#else + return NULL; +#endif +} + +int +icalcap_session_connect(icalcap_session *sess, const char *hostname, const int _port) { + + int port = _port; + + if (port <= 0) + port = 1026; + +#ifdef WITH_RR + return icalcap_session_connect_rr(sess, hostname, port); +#else + return 0; +#endif +} + +int +icalcap_session_login(icalcap_session *sess, const char *username, const char *authname, + const char *password) { + +#ifdef WITH_RR + return icalcap_session_login_rr(sess, username, authname, password); +#else + return 0; +#endif +} + +icalcap * +icalcap_session_start(const icalcap_session *sess, icalcap_msg_handler handler) { + +#ifdef WITH_RR + return icalcap_session_start_rr(sess, handler); +#else + return 0; +#endif +} + +int +icalcap_session_disconnect(icalcap_session *sess) { + +#ifdef WITH_RR + return icalcap_session_disconnect_rr(sess); +#else + return 0; +#endif +} diff --git a/libical/src/libicalcap/icalcap_session.h b/libical/src/libicalcap/icalcap_session.h new file mode 100644 index 0000000000..c12d434b8c --- /dev/null +++ b/libical/src/libicalcap/icalcap_session.h @@ -0,0 +1,15 @@ +#ifndef __ICALCAP_SESSION_H__ +#define __ICALCAP_SESSION_H__ + +#include "icalcap.h" + +typedef struct _icalcap_session icalcap_session; + +icalcap_session*icalcap_session_new(void); +int icalcap_session_connect(icalcap_session *cap, const char *hostname, const int port); +int icalcap_session_login(icalcap_session *cap, const char *username, const char *authname, + const char *password); +icalcap*icalcap_session_start(const icalcap_session *cap, icalcap_msg_handler handler); +int icalcap_session_disconnect(icalcap_session *cap); + +#endif diff --git a/libical/src/libicalcap/icalcap_session_impl.h b/libical/src/libicalcap/icalcap_session_impl.h new file mode 100644 index 0000000000..26bb7d107d --- /dev/null +++ b/libical/src/libicalcap/icalcap_session_impl.h @@ -0,0 +1,36 @@ +#ifndef __ICALCAP_SESSION_IMPL_H__ +#define __ICALCAP_SESSION_IMPL_H__ + +#ifdef WITH_RR + +#include <librr/rr.h> +#include <librrsasl/rr-sasl.h> +#include <librrtls/rr-tls.h> +#include <librrcap/rr-cap.h> + +struct _icalcap_session { + RRProfileRegistry *profreg; + RRConnection *connection; + RRCAPConfig *cfg; + icalcap_msg_handler handler; + + char *username; +}; + +icalcap_session*icalcap_session_new_rr(void); +int icalcap_session_connect_rr(icalcap_session *cap, + const char *hostname, + const int port); +int icalcap_session_login_rr(icalcap_session *cap, + const char *username, + const char *authname, + const char *password); +icalcap *icalcap_session_start_rr(const icalcap_session *cap, + icalcap_msg_handler handler); +int icalcap_session_disconnect_rr(icalcap_session *cap); + +#else +#error "No implementation of icalcap found!" +#endif + +#endif diff --git a/libical/src/libicalcap/icalcap_utils.c b/libical/src/libicalcap/icalcap_utils.c new file mode 100644 index 0000000000..b676f6272d --- /dev/null +++ b/libical/src/libicalcap/icalcap_utils.c @@ -0,0 +1,134 @@ +/*- + * $Id$ + * + * See the file LICENSE for redistribution information. + * + * Copyright (c) 2002 Andrea Campi <a.campi@inet.it> + */ + +#include "config.h" + +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include "icalcap.h" + +#define CONTENT_TYPE "Content-Type: text/calendar" + + +icalcomponent * +icalcap_component_new_from_string(const char *data) { + + icalcomponent *ret = NULL; + char *mtype; + + /* FIXME split the check */ + if (strncmp(data, CONTENT_TYPE, strlen(CONTENT_TYPE))) { + return NULL; + } + + mtype = (char *)data+strlen(CONTENT_TYPE); + + ret = icalcomponent_new_from_string(mtype); + if (ret == NULL) { + return NULL; + } + +#ifdef DEBUG + g_message("icalcap_component_new_from_string icalcomponent_new_from_string = %p", ret); +#endif + + /* FIXME + * Validate here: should check at least the version + */ + if (icalcomponent_isa(ret) != ICAL_VCALENDAR_COMPONENT && + icalcomponent_isa(ret) != ICAL_XROOT_COMPONENT) { + icalcomponent_free(ret); + + return NULL; + } + + return ret; +} + +#if 0 +RRCAPCmdArgs * +msg_parse(RRCAP *cap, icalcomponent *comp) { + + icalproperty *prop; + icalparameter *param; + icalvalue *value; + RRCAPCmdArgs *ret = g_new0(RRCAPCmdArgs, 1); + + ret->comp = comp; + + /* Find the command */ + if ((prop = icalcomponent_get_first_property(comp, ICAL_CMD_PROPERTY)) == NULL) { + rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND, + "No CMD sent", NULL); + goto FAILED; + } + if ((value = icalproperty_get_value(prop)) == NULL) { + rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND, + "CMD has no value", icalproperty_as_ical_string(prop)); + goto FAILED; + } + ret->cmd = icalvalue_get_cmd(value); + + /* Look for params */ + + /* ID */ + if ((param = icalproperty_get_first_parameter(prop, + ICAL_ID_PARAMETER)) != NULL) { + if ((ret->id = icalparameter_get_id(param)) == NULL) { + rr_cap_send_error(cap, NULL, + ICAL_9_0_UNRECOGNIZED_COMMAND, + "ID param is garbled", + icalproperty_as_ical_string(prop)); + goto FAILED; + } + } + + /* LATENCY */ + if ((param = icalproperty_get_first_parameter(prop, + ICAL_LATENCY_PARAMETER)) != NULL) { + const char *tmp; + if ((tmp = icalparameter_get_latency(param)) == NULL) { + rr_cap_send_error(cap, NULL, + ICAL_9_0_UNRECOGNIZED_COMMAND, + "LATENCY is garbled", + icalproperty_as_ical_string(prop)); + goto FAILED; + } + + ret->latency = atoi(tmp); + } + + /* ACTION */ + if ((param = icalproperty_get_first_parameter(prop, + ICAL_ACTIONPARAM_PARAMETER)) != NULL) { + if ((ret->action = icalparameter_get_actionparam(param)) + == NULL) { + rr_cap_send_error(cap, NULL, + ICAL_9_0_UNRECOGNIZED_COMMAND, + "ACTION is garbled", + icalproperty_as_ical_string(prop)); + goto FAILED; + } + } + + if ((ret->latency >= 0) ^ (ret->action != ICAL_ACTIONPARAM_NONE)) { + rr_cap_send_error(cap, NULL, ICAL_9_0_UNRECOGNIZED_COMMAND, + "LATENCY and ACTION must be both present", + icalproperty_as_ical_string(prop)); + goto FAILED; + } + + return ret; + +FAILED: + g_free(ret); + return NULL; +} +#endif diff --git a/libical/src/libicalss/.cvsignore b/libical/src/libicalss/.cvsignore index 04a3e1b036..25846dfca6 100644 --- a/libical/src/libicalss/.cvsignore +++ b/libical/src/libicalss/.cvsignore @@ -1,10 +1,6 @@ Makefile .deps -Makefile.in +.libs *.lo *.la -.libs -y.output -icalsslexer.c -icalssyacc.c icalss.h diff --git a/libical/src/libicalss/Makefile.am b/libical/src/libicalss/Makefile.am index 9e11bc3fc8..ebb755c95a 100644 --- a/libical/src/libicalss/Makefile.am +++ b/libical/src/libicalss/Makefile.am @@ -1,26 +1,89 @@ -lib_LTLIBRARIES = libicalss.la +#====================================================================== +# FILE: Makefile.am +# CREATOR: eric +# +# $Id: Makefile.am,v 1.19 2003/09/11 22:04:30 hansp Exp $ +# +# +# (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# +# +#====================================================================== -YFLAGS =-d -v -p ss -LFLAGS = -Pss + +AM_YFLAGS =-d -v -p ss +AM_LFLAGS = -Pss LEX_OUTPUT_ROOT = lex.ss all: icalss.h +# just to get it built +$(srcdir)/icalgauge.c: icalssyacc.h +$(srcdir)/icalsslexer.c: icalssyacc.h + + +if WITH_BDB4 +BDB_INCLUDE=-I@BDB_DIR_INCLUDE@ -DWITH_BDB4 +BDB_SOURCEFILES=icalbdbset.c icalbdbset.h icalbdbsetimpl.h +BDB_HEADERFILES=$(srcdir)/icalbdbset.h +libicalssinclude_BDBHEADERS=icalbdbset.h icalbdbsetimpl.h +BDB_LIBFILES=@BDB_DIR_LIB@/@BDB_LIB@ +else +BDB_INCLUDE= +BDB_SOURCEFILES= +BDB_HEADERFILES= +endif + +if WITH_CXX +cxx_lib=libicalss_cxx.la +cxx_headers=icalspanlist_cxx.h +else +cxx_lib= +cxx_headers= +endif + +lib_LTLIBRARIES = libicalss.la $(cxx_lib) + INCLUDES = \ -I$(top_srcdir)/src \ -I$(top_builddir)/src \ -I$(top_srcdir)/src/libical \ - -I$(top_builddir)/src/libical + -I$(top_builddir)/libical \ + $(BDB_INCLUDE) libicalss_la_LDFLAGS = -version-info 0:0:0 +libicalss_la_LIBADD = $(BDB_LIBFILES) + +if DEV +libicalss_la_DEVSOURCES = icalsslexer.l icalssyacc.y +else +libicalss_la_DEVSOURCES = icalsslexer.c icalssyacc.c +endif libicalss_la_SOURCES = \ + icalcalendar.c \ icalcalendar.h \ icalclassify.c \ icalclassify.h \ + icalcluster.c \ + icalcluster.h \ + icalclusterimpl.h \ icalgauge.c \ icalgauge.h \ icalgaugeimpl.h \ + icaldirset.c \ icaldirset.h \ icaldirsetimpl.h \ icalfileset.c \ @@ -28,42 +91,58 @@ libicalss_la_SOURCES = \ icalfilesetimpl.h \ icalset.c \ icalset.h \ - icalsslexer.l \ icalssyacc.h \ - icalssyacc.y \ icalspanlist.c \ icalspanlist.h \ icalmessage.c \ icalmessage.h \ - icalcstpclient.c \ - icalcstpclient.h \ - icalcstpserver.c \ - icalcstpserver.h \ - icalcstp.c \ - icalcstp.h + $(BDB_SOURCEFILES) \ + $(libicalss_la_DEVSOURCES) libicalssincludedir = $(includedir) COMBINEDHEADERS = \ $(srcdir)/icalgauge.h \ $(srcdir)/icalset.h \ + $(srcdir)/icalcluster.h \ $(srcdir)/icalfileset.h \ $(srcdir)/icaldirset.h \ + $(BDB_HEADERFILES) \ $(srcdir)/icalcalendar.h \ $(srcdir)/icalclassify.h \ $(srcdir)/icalspanlist.h \ - $(srcdir)/icalmessage.h \ - $(srcdir)/icalcstp.h \ - $(srcdir)/icalcstpclient.h \ - $(srcdir)/icalcstpserver.h + $(srcdir)/icalmessage.h icalss.h: $(COMBINEDHEADERS) - cat $(COMBINEDHEADERS) | egrep -v "#include.*\"ical" \ - | egrep -v "#include.*\"pvl\.h\"" > icalss.h + echo '#ifdef __cplusplus' > icalss.h + echo 'extern "C" {' >> icalss.h + echo '#endif' >> icalss.h + echo '/*' >> icalss.h + echo ' $$''Id''$$' >> icalss.h + echo '*/' >> icalss.h + cat $(COMBINEDHEADERS) \ + | egrep -v "#include.*\"ical" \ + | egrep -v "#include.*\"pvl\.h\"" \ + | egrep -v '\$$(Id|Locker): .+\$$'>> icalss.h + echo '#ifdef __cplusplus' >> icalss.h + echo '};' >> icalss.h + echo '#endif' >> icalss.h + + +if WITH_CXX +libicalss_cxx_la_SOURCES = \ + $(libicalss_la_SOURCES) \ + icalspanlist_cxx.h \ + icalspanlist_cxx.cpp + +# c++ needs ical.h auto-generated. +icalspanlist_cxx.lo: icalss.h + +endif -libicalssinclude_HEADERS = icalss.h +libicalssinclude_HEADERS = icalss.h icalcalendar.h icalclassify.h icalcluster.h icaldirset.h icaldirsetimpl.h icalfileset.h icalfilesetimpl.h icalgauge.h icalgaugeimpl.h icalmessage.h icalset.h icalspanlist.h icalssyacc.h $(libicalssinclude_BDBHEADERS) $(cxx_headers) CONFIG_CLEAN_FILES = y.output diff --git a/libical/src/libicalss/icalbdbset.c b/libical/src/libicalss/icalbdbset.c new file mode 100644 index 0000000000..6b11e46741 --- /dev/null +++ b/libical/src/libicalss/icalbdbset.c @@ -0,0 +1,1598 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalbdbset.c + ======================================================================*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "icalbdbset.h" +#include "icalgauge.h" +#include <errno.h> +#include <sys/stat.h> /* for stat */ +#include <stdio.h> + +#ifndef WIN32 +#include <unistd.h> /* for stat, getpid, unlink */ +#include <fcntl.h> /* for fcntl */ +#include <unistd.h> /* for fcntl */ +#else +#define S_IRUSR S_IREAD /* R for owner */ +#define S_IWUSR S_IWRITE /* W for owner */ +#endif +#include <stdlib.h> +#include <string.h> + +#include "icalbdbsetimpl.h" + +#define STRBUF_LEN 255 +#define MAX_RETRY 5 + +extern int errno; + + + +/* these are just stub functions */ +icalerrorenum icalbdbset_read_database(icalbdbset* bset, char *(*pfunc)(const DBT *dbt)); +icalerrorenum icalbdbset_create_cluster(const char *path); +int icalbdbset_cget(DBC *dbcp, DBT *key, DBT *data, int access_method); + +static int _compare_keys(DB *dbp, const DBT *a, const DBT *b); + + +/** Default options used when NULL is passed to icalset_new() **/ +icalbdbset_options icalbdbset_options_default = {ICALBDB_EVENTS, DB_BTREE, 0644, 0, NULL, NULL}; + + +static DB_ENV *ICAL_DB_ENV = 0; + +/** Initialize the db environment */ + +int icalbdbset_init_dbenv(char *db_env_dir, void (*logDbFunc)(const char*, char*)) { + int ret; + int flags; + + if (db_env_dir) { + struct stat env_dir_sb; + + if (stat(db_env_dir, &env_dir_sb)) { + fprintf(stderr, "The directory '%s' is missing, please create it.\n", db_env_dir); + return EINVAL; + } + } + + ret = db_env_create(&ICAL_DB_ENV, 0); + + if (ret) { + /* some kind of error... */ + return ret; + } + + /* Do deadlock detection internally */ + if ((ret = ICAL_DB_ENV->set_lk_detect(ICAL_DB_ENV, DB_LOCK_DEFAULT)) != 0) { + char * foo = db_strerror(ret); + fprintf(stderr, "Could not initialize the database locking environment\n"); + return ret; + } + + flags = DB_INIT_LOCK | DB_INIT_TXN | DB_CREATE | DB_THREAD | \ + DB_RECOVER | DB_INIT_LOG | DB_INIT_MPOOL; + ret = ICAL_DB_ENV->open(ICAL_DB_ENV, db_env_dir, flags, S_IRUSR|S_IWUSR); + + if (ret) { + char * foo = db_strerror(ret); + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "dbenv->open"); + return ret; + } + + /* display additional error messages */ + if (logDbFunc != NULL) { + ICAL_DB_ENV->set_errcall(ICAL_DB_ENV, logDbFunc); + } + + return ret; +} + +void icalbdbset_checkpoint(void) +{ + int ret; + char *err; + + switch (ret = ICAL_DB_ENV->txn_checkpoint(ICAL_DB_ENV, 0,0,0)) { + case 0: + case DB_INCOMPLETE: + break; + default: + err = db_strerror(ret); + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "checkpoint failed"); + abort(); + } +} + +void icalbdbset_rmdbLog(void) +{ + int ret = 0; + char** listp; + + /* remove log files that are archivable (ie. no longer needed) */ + if (ICAL_DB_ENV->log_archive(ICAL_DB_ENV, &listp, DB_ARCH_ABS) == 0) { + if (listp != NULL) { + int ii = 0; + while (listp[ii] != NULL) { + ret = unlink(listp[ii]); + ii++; + } + free(listp); + } + } +} + +int icalbdbset_cleanup(void) +{ + int ret = 0; + + /* one last checkpoint.. */ + icalbdbset_checkpoint(); + + /* remove logs that are not needed anymore */ + icalbdbset_rmdbLog(); + + if (ICAL_DB_ENV) + ret = ICAL_DB_ENV->close(ICAL_DB_ENV, 0); + + return ret; +} + +DB_ENV *icalbdbset_get_env(void) { + return ICAL_DB_ENV; +} + + +/** Initialize an icalbdbset. Also attempts to populate from the + * database (primary if only dbp is given, secondary if sdbp is + * given) and creates an empty object if retrieval is unsuccessful. + * pfunc is used to unpack data from the database. If not given, we + * assume data is a string. + */ + +icalset* icalbdbset_init(icalset* set, const char* dsn, void* options_in) +{ + icalbdbset *bset = (icalbdbset*)set; + icalbdbset_options *options = options_in; + int ret; + DB *cal_db; + char *subdb_name; + + if (options == NULL) + *options = icalbdbset_options_default; + + switch (options->subdb) { + case ICALBDB_CALENDARS: + subdb_name = "calendars"; + break; + case ICALBDB_EVENTS: + subdb_name = "events"; + break; + case ICALBDB_TODOS: + subdb_name = "todos"; + break; + case ICALBDB_REMINDERS: + subdb_name = "reminders"; + break; + } + + cal_db = icalbdbset_bdb_open(set->dsn, + subdb_name, + options->dbtype, + options->mode, + options->flag); + if (cal_db == NULL) + return NULL; + + bset->dbp = cal_db; + bset->sdbp = NULL; + bset->gauge = 0; + bset->cluster = 0; + + if ((ret = icalbdbset_read_database(bset, options->pfunc)) != ICAL_NO_ERROR) { + return NULL; + } + + return (icalset *)bset; +} + + +/** open a database and return a reference to it. Used only for + opening the primary index. + flag = set_flag() DUP | DUP_SORT + */ + +icalset* icalbdbset_new(const char* database_filename, + icalbdbset_subdb_type subdb_type, + int dbtype, int flag) +{ + icalbdbset_options options = icalbdbset_options_default; + + options.subdb = subdb_type; + options.dbtype = dbtype; + options.flag = flag; + + /* this will in turn call icalbdbset_init */ + return icalset_new(ICAL_BDB_SET, database_filename, &options); +} + +/** + * Open a secondary database, used for accessing secondary indices. + * The callback function tells icalbdbset how to associate secondary + * key information with primary data. See the BerkeleyDB reference + * guide for more information. + */ + +DB * icalbdbset_bdb_open_secondary(DB *dbp, + const char *database, + const char *sub_database, + int (*callback) (DB *db, + const DBT *dbt1, + const DBT *dbt2, + DBT *dbt3), + int type) +{ + int ret; + int flags; + DB *sdbp = NULL; + + if (!sub_database) + return NULL; + + if (!ICAL_DB_ENV) + icalbdbset_init_dbenv(NULL, NULL); + + /* Open/create secondary */ + if((ret = db_create(&sdbp, ICAL_DB_ENV, 0)) != 0) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "secondary index: %s", sub_database); + return NULL; + } + + if ((ret = sdbp->set_flags(sdbp, DB_DUP | DB_DUPSORT)) != 0) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "set_flags error for secondary index: %s", sub_database); + return NULL; + } + + flags = DB_CREATE | DB_THREAD; + if ((ret = sdbp->open(sdbp, database, sub_database, type, (u_int32_t) flags, 0644)) != 0) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "failed to open secondary index: %s", sub_database); + if (ret == DB_RUNRECOVERY) + abort(); + else + return NULL; + } + + /* Associate the primary index with a secondary */ + if((ret = dbp->associate(dbp, sdbp, callback, 0)) != 0) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "failed to associate secondary index: %s", sub_database); + return NULL; + } + + return sdbp; +} + +DB* icalbdbset_bdb_open(const char* path, + const char *subdb, + int dbtype, + mode_t mode, + int flag) +{ + DB *dbp = NULL; + int ret; + int flags; + + /* Initialize the correct set of db subsystems (see capdb.c) */ + flags = DB_CREATE | DB_THREAD; + + /* should just abort here instead of opening an env in the current dir.. */ + if (!ICAL_DB_ENV) + icalbdbset_init_dbenv(NULL, NULL); + + /* Create and initialize database object, open the database. */ + if ((ret = db_create(&dbp, ICAL_DB_ENV, 0)) != 0) { + return (NULL); + } + + /* set comparison function, if BTREE */ + if (dbtype == DB_BTREE) + dbp->set_bt_compare(dbp, _compare_keys); + + /* set DUP, DUPSORT */ + if (flag != 0) + dbp->set_flags(dbp, flag); + + if ((ret = dbp->open(dbp, path, subdb, dbtype, flags, mode)) != 0) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "%s (database: %s): open failed.", path, subdb); + if (ret == DB_RUNRECOVERY) + abort(); + else + return NULL; + } + + return (dbp); +} + + +/* icalbdbset_parse_data -- parses using pfunc to unpack data. */ +char *icalbdbset_parse_data(DBT *dbt, char *(*pfunc)(const DBT *dbt)) +{ + char *ret; + + if(pfunc) { + ret = (char *)pfunc(dbt); + } else { + ret = (char *) dbt->data; + } + + return (ret); +} + +/* This populates a cluster with the entire contents of a database */ +icalerrorenum icalbdbset_read_database(icalbdbset* bset, char *(*pfunc)(const DBT *dbt)) +{ + + DB *dbp; + DBC *dbcp; + DBT key, data; + char *str, *szpstr; + int ret; + char keystore[256]; + char datastore[1024]; + char *more_mem = NULL; + DB_TXN *tid; + + memset(&key, 0, sizeof(DBT)); + memset(&data, 0, sizeof(DBT)); + + if (bset->sdbp) { dbp = bset->sdbp; } + else { dbp = bset->dbp; } + + if(!dbp) { goto err1; } + + bset->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); + + if ((ret = ICAL_DB_ENV->txn_begin(ICAL_DB_ENV, NULL, &tid, 0)) != 0) { + char *foo = db_strerror(ret); + abort(); + } + + /* acquire a cursor for the database */ + if ((ret = dbp->cursor(dbp, tid, &dbcp, 0)) != 0) { + dbp->err(dbp, ret, "primary index"); + goto err1; + } + + key.flags = DB_DBT_USERMEM; + key.data = keystore; + key.ulen = sizeof(keystore); + + data.flags= DB_DBT_USERMEM; + data.data = datastore; + data.ulen = sizeof(datastore); + + + /* fetch the key/data pair */ + while (1) { + ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT); + if (ret == DB_NOTFOUND) { + break; + } else if (ret == ENOMEM) { + if (more_mem) free (more_mem); + more_mem = malloc(data.ulen+1024); + data.data = more_mem; + data.ulen = data.ulen+1024; + } else if (ret == DB_LOCK_DEADLOCK) { + char *foo = db_strerror(ret); + abort(); /* should retry in case of DB_LOCK_DEADLOCK */ + } else if (ret) { + char *foo = db_strerror(ret); + /* some other weird-ass error */ + dbp->err(dbp, ret, "cursor"); + abort(); + } else { + icalcomponent *cl; + + /* this prevents an array read bounds error */ + if((str = (char *)calloc(data.size + 1, sizeof(char)))==NULL) + goto err2; + memcpy(str, (char *)data.data, data.size); + + cl = icalparser_parse_string(str); + + icalcomponent_add_component(bset->cluster, cl); + free(str); + } + } + if(ret != DB_NOTFOUND) { + goto err2; + } + + + if (more_mem) { + free(more_mem); + more_mem = NULL; + } + + if ((ret = dbcp->c_close(dbcp)) != 0) { + char * foo = db_strerror(ret); + abort(); /* should retry in case of DB_LOCK_DEADLOCK */ + } + + if ((ret = tid->commit(tid, 0)) != 0) { + char * foo = db_strerror(ret); + abort(); + } + + return ICAL_NO_ERROR; + + err2: + if (more_mem) free(more_mem); + dbcp->c_close(dbcp); + abort(); /* should retry in case of DB_LOCK_DEADLOCK */ + return ICAL_INTERNAL_ERROR; + + err1: + dbp->err(dbp, ret, "cursor index"); + abort(); + return (ICAL_FILE_ERROR); +} + + +/* XXX add more to this */ +void icalbdbset_free(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + int ret; + + icalerror_check_arg_rv((bset!=0),"bset"); + + if (bset->cluster != 0){ + icalbdbset_commit(set); + icalcomponent_free(bset->cluster); + bset->cluster=0; + } + + if(bset->gauge !=0){ + icalgauge_free(bset->gauge); + } + + if(bset->path != 0){ + free((char *)bset->path); + bset->path = 0; + } + + if(bset->sindex != 0) { + free((char *)bset->sindex); + bset->sindex = 0; + } + + if (bset->dbp && + ((ret = bset->dbp->close(bset->dbp, 0)) != 0)) { + } + bset->dbp = NULL; +} + +/* return cursor is in rdbcp */ +int icalbdbset_acquire_cursor(DB *dbp, DB_TXN *tid, DBC **rdbcp) { + int ret=0; + + if((ret = dbp->cursor(dbp, tid, rdbcp, 0)) != 0) { + dbp->err(dbp, ret, "couldn't open cursor"); + goto err1; + } + + return ICAL_NO_ERROR; + + err1: + return ICAL_FILE_ERROR; + +} + +/* returns key/data in arguments */ +int icalbdbset_get_first(DBC *dbcp, DBT *key, DBT *data) { + return icalbdbset_cget(dbcp, key, data, DB_FIRST); +} + +int icalbdbset_get_next(DBC *dbcp, DBT *key, DBT *data) { + return icalbdbset_cget(dbcp, key, data, DB_NEXT); +} + +int icalbdbset_get_last(DBC *dbcp, DBT *key, DBT *data) { + return icalbdbset_cget(dbcp, key, data, DB_LAST); +} + +int icalbdbset_get_key(DBC *dbcp, DBT *key, DBT *data) { + return icalbdbset_cget(dbcp, key, data, DB_SET); +} + +int icalbdbset_delete(DB *dbp, DBT *key) { + DB_TXN *tid; + int ret; + int done = 0; + int retry = 0; + + while ((retry < MAX_RETRY) && !done) { + + if ((ret = ICAL_DB_ENV->txn_begin(ICAL_DB_ENV, NULL, &tid, 0)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else { + char *foo = db_strerror(ret); + abort(); + } + } + + if ((ret = dbp->del(dbp, tid, key, 0)) != 0) { + if (ret == DB_NOTFOUND) { + /* do nothing - not an error condition */ + } + else if (ret == DB_LOCK_DEADLOCK) { + tid->abort(tid); + retry++; + continue; + } + else { + char *strError = db_strerror(ret); + icalerror_warn("icalbdbset_delete faild: "); + icalerror_warn(strError); + tid->abort(tid); + return ICAL_FILE_ERROR; + } + } + + if ((ret = tid->commit(tid, 0)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + tid->abort(tid); + retry++; + continue; + } + else { + char * foo = db_strerror(ret); + abort(); + } + } + + done = 1; /* all is well */ + } + + if (!done) { + if (tid != NULL) tid->abort(tid); + } + + return ret; +} + +int icalbdbset_cget(DBC *dbcp, DBT *key, DBT *data, int access_method) { + int ret=0; + + key->flags |= DB_DBT_MALLOC; /* change these to DB_DBT_USERMEM */ + data->flags |= DB_DBT_MALLOC; + + /* fetch the key/data pair */ + if((ret = dbcp->c_get(dbcp, key, data, access_method)) != 0) { + goto err1; + } + + return ICAL_NO_ERROR; + + err1: + return ICAL_FILE_ERROR; +} + + +int icalbdbset_cput(DBC *dbcp, DBT *key, DBT *data, int access_method) { + int ret=0; + + key->flags |= DB_DBT_MALLOC; /* change these to DB_DBT_USERMEM */ + data->flags |= DB_DBT_MALLOC; + + /* fetch the key/data pair */ + if((ret = dbcp->c_put(dbcp, key, data, 0)) != 0) { + goto err1; + } + + return ICAL_NO_ERROR; + + err1: + return ICAL_FILE_ERROR; +} + + +int icalbdbset_put(DB *dbp, DBT *key, DBT *data, int access_method) +{ + int ret = 0; + DB_TXN *tid = NULL; + int retry = 0; + int done = 0; + + while ((retry < MAX_RETRY) && !done) { + + if ((ret = ICAL_DB_ENV->txn_begin(ICAL_DB_ENV, NULL, &tid, 0)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else { + char *foo = db_strerror(ret); + abort(); + } + } + + if ((ret = dbp->put(dbp, tid, key, data, access_method)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + tid->abort(tid); + retry++; + continue; + } + else { + char *strError = db_strerror(ret); + icalerror_warn("icalbdbset_put faild: "); + icalerror_warn(strError); + tid->abort(tid); + return ICAL_FILE_ERROR; + } + } + + if ((ret = tid->commit(tid, 0)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + tid->abort(tid); + retry++; + continue; + } + else { + char * foo = db_strerror(ret); + abort(); + } + } + + done = 1; /* all is well */ + } + + if (!done) { + if (tid != NULL) tid->abort(tid); + return ICAL_FILE_ERROR; + } + else + return ICAL_NO_ERROR; +} + +int icalbdbset_get(DB *dbp, DB_TXN *tid, DBT *key, DBT *data, int flags) +{ + return (dbp->get(dbp, tid, key, data, flags)); +} + +/** Return the path of the database file **/ + +const char* icalbdbset_path(icalset* set) +{ + icalerror_check_arg_rz((set!=0),"set"); + + return set->dsn; +} + +const char* icalbdbset_subdb(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + return bset->subdb; +} + + +/** Write changes out to the database file. + */ + +icalerrorenum icalbdbset_commit(icalset *set) { + DB *dbp; + DBC *dbcp; + DBT key, data; + icalcomponent *c; + char *str; + int ret=0; + int reterr = ICAL_NO_ERROR; + char keystore[256]; + char uidbuf[256]; + char datastore[1024]; + char *more_mem = NULL; + DB_TXN *tid = NULL; + icalbdbset *bset = (icalbdbset*)set; + int bad_uid_counter = 0; + int retry = 0, done = 0, completed = 0, deadlocked = 0; + + icalerror_check_arg_re((bset!=0),"bset",ICAL_BADARG_ERROR); + + dbp = bset->dbp; + icalerror_check_arg_re((dbp!=0),"dbp is invalid",ICAL_BADARG_ERROR); + + if (bset->changed == 0) + return ICAL_NO_ERROR; + + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + + key.flags = DB_DBT_USERMEM; + key.data = keystore; + key.ulen = sizeof(keystore); + + data.flags = DB_DBT_USERMEM; + data.data = datastore; + data.ulen = sizeof(datastore); + + if (!ICAL_DB_ENV) + icalbdbset_init_dbenv(NULL, NULL); + + while ((retry < MAX_RETRY) && !done) { + + if ((ret = ICAL_DB_ENV->txn_begin(ICAL_DB_ENV, NULL, &tid, 0)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else if (ret == DB_RUNRECOVERY) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "icalbdbset_commit: txn_begin failed"); + abort(); + } + else { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "icalbdbset_commit"); + return ICAL_INTERNAL_ERROR; + } + } + + /* first delete everything in the database, because there could be removed components */ + if ((ret = dbp->cursor(dbp, tid, &dbcp, DB_DIRTY_READ)) != 0) { + tid->abort(tid); + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else if (ret == DB_RUNRECOVERY) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "curor failed"); + abort(); + } + else { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "curor failed"); + /* leave bset->changed set to true */ + return ICAL_INTERNAL_ERROR; + } + } + + /* fetch the key/data pair, then delete it */ + completed = 0; + while (!completed && !deadlocked) { + ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT); + if (ret == DB_NOTFOUND) { + completed = 1; + } else if (ret == ENOMEM) { + if (more_mem) free(more_mem); + more_mem = malloc(data.ulen+1024); + data.data = more_mem; + data.ulen = data.ulen+1024; + } else if (ret == DB_LOCK_DEADLOCK) { + deadlocked = 1; + } else if (ret == DB_RUNRECOVERY) { + tid->abort(tid); + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "c_get failed."); + abort(); + } else if (ret == 0) { + if ((ret = dbcp->c_del(dbcp,0))!=0) { + dbp->err(dbp, ret, "cursor"); + if (ret == DB_KEYEMPTY) { + /* never actually created, continue onward.. */ + /* do nothing - break; */ + } else if (ret == DB_LOCK_DEADLOCK) { + deadlocked = 1; + } else { + char *foo = db_strerror(ret); + abort(); + } + } + } else { /* some other non-fatal error */ + dbcp->c_close(dbcp); + tid->abort(tid); + if (more_mem) { + free(more_mem); + more_mem = NULL; + } + return ICAL_INTERNAL_ERROR; + } + } + + if (more_mem) { + free(more_mem); + more_mem = NULL; + } + + if (deadlocked) { + dbcp->c_close(dbcp); + tid->abort(tid); + retry++; + continue; /* next retry */ + } + + deadlocked = 0; + for (c = icalcomponent_get_first_component(bset->cluster,ICAL_ANY_COMPONENT); + c != 0 && !deadlocked; + c = icalcomponent_get_next_component(bset->cluster,ICAL_ANY_COMPONENT)) { + + memset(&key, 0, sizeof(key)); + memset(&data, 0, sizeof(data)); + + /* Note that we're always inserting into a primary index. */ + if (icalcomponent_isa(c) != ICAL_VAGENDA_COMPONENT) { + char *uidstr = (char *)icalcomponent_get_uid(c); + if (!uidstr) { /* this shouldn't happen */ + /* no uid string, we need to add one */ + snprintf(uidbuf, 256, "baduid%d-%d", getpid(), bad_uid_counter++); + key.data = uidbuf; + } else { + key.data = uidstr; + } + } else { + char *relcalid = NULL; + relcalid = (char*)icalcomponent_get_relcalid(c); + if (relcalid == NULL) { + snprintf(uidbuf, 256, "baduid%d-%d", getpid(), bad_uid_counter++); + key.data = uidbuf; + } else { + key.data = relcalid; + } + } + key.size = strlen(key.data); + + str = icalcomponent_as_ical_string(c); + data.data = str; + data.size = strlen(str); + + if ((ret = dbcp->c_put(dbcp, &key, &data, DB_KEYLAST)) != 0) { + if (ret == DB_LOCK_DEADLOCK) { + deadlocked = 1; + } + else if (ret == DB_RUNRECOVERY) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "c_put failed."); + abort(); + } + else { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "c_put failed %s.", str); + /* continue to try to put as many icalcomponent as possible */ + reterr = ICAL_INTERNAL_ERROR; + } + } + } + + if (deadlocked) { + dbcp->c_close(dbcp); + tid->abort(tid); + retry++; + continue; + } + + if ((ret = dbcp->c_close(dbcp)) != 0) { + tid->abort(tid); + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else if (ret == DB_RUNRECOVERY) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "c_closed failed."); + abort(); + } + else { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "c_closed failed."); + reterr = ICAL_INTERNAL_ERROR; + } + } + + if ((ret = tid->commit(tid, 0)) != 0) { + tid->abort(tid); + if (ret == DB_LOCK_DEADLOCK) { + retry++; + continue; + } + else if (ret == DB_RUNRECOVERY) { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "commit failed."); + abort(); + } + else { + ICAL_DB_ENV->err(ICAL_DB_ENV, ret, "commit failed."); + reterr = ICAL_INTERNAL_ERROR; + } + } + + done = 1; + } + + bset->changed = 0; + return reterr; +} + + +void icalbdbset_mark(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rv((bset!=0),"bset"); + + bset->changed = 1; +} + + +icalcomponent* icalbdbset_get_component(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + return bset->cluster; +} + + +/* manipulate the components in the cluster */ + +icalerrorenum icalbdbset_add_component(icalset *set, + icalcomponent* child) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_re((bset!=0),"bset", ICAL_BADARG_ERROR); + icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); + + icalcomponent_add_component(bset->cluster,child); + + icalbdbset_mark(set); + + return ICAL_NO_ERROR; +} + + +icalerrorenum icalbdbset_remove_component(icalset *set, + icalcomponent* child) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_re((bset!=0),"bset", ICAL_BADARG_ERROR); + icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); + + icalcomponent_remove_component(bset->cluster,child); + + icalbdbset_mark(set); + + return ICAL_NO_ERROR; +} + + +int icalbdbset_count_components(icalset *set, + icalcomponent_kind kind) +{ + icalbdbset *bset = (icalbdbset*)set; + + if(set == 0){ + icalerror_set_errno(ICAL_BADARG_ERROR); + return -1; + } + + return icalcomponent_count_components(bset->cluster,kind); +} + + +/** Set the gauge **/ + +icalerrorenum icalbdbset_select(icalset* set, icalgauge* gauge) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_re((bset!=0),"bset", ICAL_BADARG_ERROR); + icalerror_check_arg_re(gauge!=0,"gauge",ICAL_BADARG_ERROR); + + bset->gauge = gauge; + + return ICAL_NO_ERROR; +} + + +/** Clear the gauge **/ + +void icalbdbset_clear(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rv((bset!=0),"bset"); + + bset->gauge = 0; +} + + +icalcomponent* icalbdbset_fetch(icalset* set, icalcomponent_kind kind, const char* uid) +{ + icalcompiter i; + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + for(i = icalcomponent_begin_component(bset->cluster, kind); + icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ + + icalcomponent *this = icalcompiter_deref(&i); + icalproperty *p = NULL; + const char *this_uid = NULL; + + if (this != 0){ + if (kind == ICAL_VAGENDA_COMPONENT) { + p = icalcomponent_get_first_property(this,ICAL_RELCALID_PROPERTY); + if (p != NULL) this_uid = icalproperty_get_relcalid(p); + } else { + p = icalcomponent_get_first_property(this,ICAL_UID_PROPERTY); + if (p != NULL) this_uid = icalproperty_get_uid(p); + } + + if(this_uid==NULL){ + icalerror_warn("icalbdbset_fetch found a component with no UID"); + continue; + } + + if (strcmp(uid,this_uid)==0){ + return this; + } + } + } + + return 0; +} + + +int icalbdbset_has_uid(icalset* store,const char* uid) +{ + assert(0); /* HACK, not implemented */ + return 0; +} + + +/******* support routines for icalbdbset_fetch_match *********/ + +struct icalbdbset_id { + char* uid; + char* recurrence_id; + int sequence; +}; + +void icalbdbset_id_free(struct icalbdbset_id *id) +{ + if(id->recurrence_id != 0){ + free(id->recurrence_id); + } + + if(id->uid != 0){ + free(id->uid); + } + +} + +struct icalbdbset_id icalbdbset_get_id(icalcomponent* comp) +{ + + icalcomponent *inner; + struct icalbdbset_id id; + icalproperty *p; + + inner = icalcomponent_get_first_real_component(comp); + + p = icalcomponent_get_first_property(inner, ICAL_UID_PROPERTY); + + assert(p!= 0); + + id.uid = strdup(icalproperty_get_uid(p)); + + p = icalcomponent_get_first_property(inner, ICAL_SEQUENCE_PROPERTY); + + if(p == 0) { + id.sequence = 0; + } else { + id.sequence = icalproperty_get_sequence(p); + } + + p = icalcomponent_get_first_property(inner, ICAL_RECURRENCEID_PROPERTY); + + if (p == 0){ + id.recurrence_id = 0; + } else { + icalvalue *v; + v = icalproperty_get_value(p); + id.recurrence_id = strdup(icalvalue_as_ical_string(v)); + + assert(id.recurrence_id != 0); + } + + return id; +} + +/* Find the component that is related to the given + component. Currently, it just matches based on UID and + RECURRENCE-ID */ + +icalcomponent* icalbdbset_fetch_match(icalset* set, icalcomponent *comp) +{ + icalbdbset *bset = (icalbdbset*)set; + icalcompiter i; + struct icalbdbset_id comp_id, match_id; + + icalerror_check_arg_rz((bset!=0),"bset"); + comp_id = icalbdbset_get_id(comp); + + for(i = icalcomponent_begin_component(bset->cluster,ICAL_ANY_COMPONENT); + icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ + + icalcomponent *match = icalcompiter_deref(&i); + + match_id = icalbdbset_get_id(match); + + if(strcmp(comp_id.uid, match_id.uid) == 0 && + ( comp_id.recurrence_id ==0 || + strcmp(comp_id.recurrence_id, match_id.recurrence_id) ==0 )){ + + /* HACK. What to do with SEQUENCE? */ + + icalbdbset_id_free(&match_id); + icalbdbset_id_free(&comp_id); + return match; + + } + + icalbdbset_id_free(&match_id); + } + + icalbdbset_id_free(&comp_id); + return 0; + +} + + +icalerrorenum icalbdbset_modify(icalset* set, icalcomponent *old, + icalcomponent *newc) +{ + assert(0); /* HACK, not implemented */ + return ICAL_NO_ERROR; +} + +/* caller is responsible to cal icalbdbset_free_cluster first */ +icalerrorenum icalbdbset_set_cluster(icalset* set, icalcomponent* cluster) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + bset->cluster = cluster; +} + +icalerrorenum icalbdbset_free_cluster(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + if (bset->cluster != NULL) icalcomponent_free(bset->cluster); +} + +icalcomponent* icalbdbset_get_cluster(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalerror_check_arg_rz((bset!=0),"bset"); + + return (bset->cluster); +} + + +/** Iterate through components. */ +icalcomponent* icalbdbset_get_current_component (icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + + icalerror_check_arg_rz((bset!=0),"bset"); + + return icalcomponent_get_current_component(bset->cluster); +} + + +icalcomponent* icalbdbset_get_first_component(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalcomponent *c=0; + + icalerror_check_arg_rz((bset!=0),"bset"); + + do { + if (c == 0) + c = icalcomponent_get_first_component(bset->cluster, + ICAL_ANY_COMPONENT); + else + c = icalcomponent_get_next_component(bset->cluster, + ICAL_ANY_COMPONENT); + + if(c != 0 && (bset->gauge == 0 || + icalgauge_compare(bset->gauge,c) == 1)){ + return c; + } + + } while (c!=0); + + return 0; +} + + +icalsetiter icalbdbset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge, const char* tzid) +{ + icalsetiter itr = icalsetiter_null; + icalcomponent* comp = NULL; + icalcompiter citr; + icalbdbset *bset = (icalbdbset*) set; + struct icaltimetype start, next, end; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + icaltimezone *u_zone; + int g = 0; + int orig_time_was_utc = 0; + + icalerror_check_arg_re((set!=0), "set", icalsetiter_null); + + itr.gauge = gauge; + itr.tzid = tzid; + + citr = icalcomponent_begin_component(bset->cluster, kind); + comp = icalcompiter_deref(&citr); + + if (gauge == 0) { + itr.iter = citr; + return itr; + } + + /* if there is a gauge, the first matched component is returned */ + while (comp != 0) { + + /* check if it is a recurring component and with guage expand, if so + * we need to add recurrence-id property to the given component */ + rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + g = icalgauge_get_expand(gauge); + + if (rrule != 0 + && g == 1) { + + /* it is a recurring event */ + + u_zone = icaltimezone_get_builtin_timezone(itr.tzid); + + /* use UTC, if that's all we have. */ + if (!u_zone) + u_zone = icaltimezone_get_utc_timezone(); + + + recur = icalproperty_get_rrule(rrule); + + if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + /* Convert to the user's timezone in order to be able to compare + * the results from the rrule iterator. */ + if (icaltime_is_utc(start)) { + start = icaltime_convert_to_zone(start, u_zone); + orig_time_was_utc = 1; + } + + if (itr.last_component == NULL) { + itr.ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(itr.ritr); + itr.last_component = comp; + } + else { + next = icalrecur_iterator_next(itr.ritr); + if (icaltime_is_null_time(next)){ + itr.last_component = NULL; + icalrecur_iterator_free(itr.ritr); + itr.ritr = NULL; + /* no matched occurence */ + goto getNextComp; + } else { + itr.last_component = comp; + } + } + + /* if it is excluded, do next one */ + if (icalproperty_recurrence_is_excluded(comp, &start, &next)) { + icalrecur_iterator_decrement_count(itr.ritr); + continue; + } + + /* add recurrence-id value to the property if the property already exist; + * add the recurrence id property and the value if the property does not exist */ + prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY); + if (prop == 0) + icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next)); + else + icalproperty_set_recurrenceid(prop, next); + + /* convert the next recurrence time into the user's timezone */ + if (orig_time_was_utc) + next = icaltime_convert_to_zone(next, icaltimezone_get_utc_timezone()); + + } /* end of a recurring event */ + + if (gauge == 0 || icalgauge_compare(itr.gauge, comp) == 1) { + /* find a matched and return it */ + itr.iter = citr; + return itr; + } + + /* if it is a recurring but no matched occurrence has been found OR + * it is not a recurring and no matched component has been found, + * read the next component to find out */ +getNextComp: + if ((rrule != NULL && itr.last_component == NULL) || + (rrule == NULL)) { + comp = icalcompiter_next(&citr); + comp = icalcompiter_deref(&citr); + } + } /* while */ + + /* no matched component has found */ + return icalsetiter_null; +} + +icalcomponent* icalbdbset_form_a_matched_recurrence_component(icalsetiter* itr) +{ + icalcomponent* comp = NULL; + struct icaltimetype start, next, end; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + icaltimezone *u_zone; + int g = 0; + int orig_time_was_utc = 0; + + comp = itr->last_component; + + if (comp == NULL || itr->gauge == NULL) { + return NULL; + } + + + rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + /* if there is no RRULE, simply return to the caller */ + if (rrule == NULL) + return NULL; + + u_zone = icaltimezone_get_builtin_timezone(itr->tzid); + + /* use UTC, if that's all we have. */ + if (!u_zone) + u_zone = icaltimezone_get_utc_timezone(); + + recur = icalproperty_get_rrule(rrule); + + if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + /* Convert to the user's timezone in order to be able to compare the results + * from the rrule iterator. */ + if (icaltime_is_utc(start)) { + start = icaltime_convert_to_zone(start, u_zone); + orig_time_was_utc = 1; + } + + if (itr->ritr == NULL) { + itr->ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(itr->ritr); + itr->last_component = comp; + } else { + next = icalrecur_iterator_next(itr->ritr); + if (icaltime_is_null_time(next)){ + /* no more recurrence, returns */ + itr->last_component = NULL; + icalrecur_iterator_free(itr->ritr); + itr->ritr = NULL; + /* no more pending matched occurence, + * all the pending matched occurences have been returned */ + return NULL; + } else { + itr->last_component = comp; + } + } + + /* if it is excluded, return NULL to the caller */ + if (icalproperty_recurrence_is_excluded(comp, &start, &next)) { + icalrecur_iterator_decrement_count(itr->ritr); + return NULL; + } + + /* set recurrence-id value to the property if the property already exist; + * add the recurrence id property and the value if the property does not exist */ + prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY); + if (prop == 0) + icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next)); + else + icalproperty_set_recurrenceid(prop, next); + + if (orig_time_was_utc) { + next = icaltime_convert_to_zone(next, icaltimezone_get_utc_timezone()); + } + + + if (itr->gauge == 0 || icalgauge_compare(itr->gauge, comp) == 1) { + /* find a matched and return it */ + return comp; + } + + /* not matched */ + return NULL; + +} + +icalcomponent* icalbdbsetiter_to_next(icalset *set, icalsetiter* i) +{ + + icalcomponent* comp = NULL; + icalbdbset *bset = (icalbdbset*) set; + struct icaltimetype start, next, end; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + icaltimezone *u_zone; + int g = 0; + int orig_time_was_utc = 0; + + do { + + /* no pending occurence, read the next component */ + if (i->last_component == NULL) { + comp = icalcompiter_next(&(i->iter)); + } + else { + comp = i->last_component; + } + + /* no next component, simply return */ + if (comp == 0) return NULL; + if (i->gauge == 0) return comp; + + /* finding the next matched component and return it to the caller */ + + rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + g = icalgauge_get_expand(i->gauge); + + /* a recurring component with expand query */ + if (rrule != 0 + && g == 1) { + + u_zone = icaltimezone_get_builtin_timezone(i->tzid); + + /* use UTC, if that's all we have. */ + if (!u_zone) + u_zone = icaltimezone_get_utc_timezone(); + + recur = icalproperty_get_rrule(rrule); + + if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + /* Convert to the user's timezone in order to be able to compare + * the results from the rrule iterator. */ + if (icaltime_is_utc(start)) { + start = icaltime_convert_to_zone(start, u_zone); + orig_time_was_utc = 1; + } + + if (i->ritr == NULL) { + i->ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(i->ritr); + i->last_component = comp; + } else { + next = icalrecur_iterator_next(i->ritr); + if (icaltime_is_null_time(next)) { + i->last_component = NULL; + icalrecur_iterator_free(i->ritr); + i->ritr = NULL; + /* no more occurence, should go to get next component */ + continue; + } else { + i->last_component = comp; + } + } + + /* if it is excluded, do next one */ + if (icalproperty_recurrence_is_excluded(comp, &start, &next)) { + icalrecur_iterator_decrement_count(i->ritr); + continue; + } + + /* set recurrence-id value to the property if the property already exist; + * add the recurrence id property and the value if the property does not exist */ + prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY); + if (prop == 0) + icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next)); + else + icalproperty_set_recurrenceid(prop, next); + + if (orig_time_was_utc) { + next = icaltime_convert_to_zone(next, icaltimezone_get_utc_timezone()); + } + + } /* end of recurring event with expand query */ + + if(comp != 0 && (i->gauge == 0 || + icalgauge_compare(i->gauge, comp) == 1)){ + /* found a matched, return it */ + return comp; + } + } while (comp != 0); + + return 0; + +} + +icalcomponent* icalbdbset_get_next_component(icalset* set) +{ + icalbdbset *bset = (icalbdbset*)set; + icalcomponent *c=0; + + struct icaltimetype start, next; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + int g = 0; + + icalerror_check_arg_rz((bset!=0),"bset"); + + do { + c = icalcomponent_get_next_component(bset->cluster, + ICAL_ANY_COMPONENT); + if(c != 0 && (bset->gauge == 0 || + icalgauge_compare(bset->gauge,c) == 1)){ + return c; + } + + } while(c != 0); + + return 0; +} + +int icalbdbset_begin_transaction(DB_TXN* parent_tid, DB_TXN** tid) +{ + return (ICAL_DB_ENV->txn_begin(ICAL_DB_ENV, parent_tid, tid, 0)); +} + +int icalbdbset_commit_transaction(DB_TXN* txnid) +{ + return (txnid->commit(txnid, 0)); +} + + +static int _compare_keys(DB *dbp, const DBT *a, const DBT *b) +{ +/* + * Returns: + * < 0 if a < b + * = 0 if a = b + * > 0 if a > b + */ + + char* ac = (char*)a->data; + char* bc = (char*)b->data; + return (strncmp(ac, bc, a->size)); +} + + + diff --git a/libical/src/libicalss/icalbdbset.h b/libical/src/libicalss/icalbdbset.h new file mode 100644 index 0000000000..c5c835fae3 --- /dev/null +++ b/libical/src/libicalss/icalbdbset.h @@ -0,0 +1,147 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalbdbset.h + CREATOR: dml 12 December 2001 + (C) COPYRIGHT 2001, Critical Path + + $Id$ + $Locker$ +======================================================================*/ + +#ifndef ICALBDBSET_H +#define ICALBDBSET_H + +#include "ical.h" +#include "icalset.h" +#include "icalgauge.h" +#include <db.h> + +typedef struct icalbdbset_impl icalbdbset; + +enum icalbdbset_subdb_type {ICALBDB_CALENDARS, ICALBDB_EVENTS, ICALBDB_TODOS, ICALBDB_REMINDERS}; +typedef enum icalbdbset_subdb_type icalbdbset_subdb_type; + +/** sets up the db environment, should be done in parent thread.. */ +int icalbdbset_init_dbenv(char *db_env_dir, void (*logDbFunc)(const char*, char*)); + +icalset* icalbdbset_init(icalset* set, const char *dsn, void *options); +int icalbdbset_cleanup(void); +void icalbdbset_checkpoint(void); +void icalbdbset_rmdbLog(void); + +/** Creates a component handle. flags allows caller to + specify if database is internally a BTREE or HASH */ +icalset * icalbdbset_new(const char* database_filename, + icalbdbset_subdb_type subdb_type, + int dbtype, int flag); + +DB * icalbdbset_bdb_open_secondary(DB *dbp, + const char *subdb, + const char *sindex, + int (*callback) (DB *db, + const DBT *dbt1, + const DBT *dbt2, + DBT *dbt3), + int type); + +char *icalbdbset_parse_data(DBT *dbt, char *(*pfunc)(const DBT *dbt)) ; + +void icalbdbset_free(icalset* set); + +/* cursor operations */ +int icalbdbset_acquire_cursor(DB *dbp, DB_TXN* tid, DBC **rdbcp); +int icalbdbset_cget(DBC *dbcp, DBT *key, DBT *data, int access_method); +int icalbdbset_cput(DBC *dbcp, DBT *key, DBT *data, int access_method); + +int icalbdbset_get_first(DBC *dbcp, DBT *key, DBT *data); +int icalbdbset_get_next(DBC *dbcp, DBT *key, DBT *data); +int icalbdbset_get_last(DBC *dbcp, DBT *key, DBT *data); +int icalbdbset_get_key(DBC *dbcp, DBT *key, DBT *data); +int icalbdbset_delete(DB *dbp, DBT *key); +int icalbdbset_put(DB *dbp, DBT *key, DBT *data, int access_method); +int icalbdbset_get(DB *dbp, DB_TXN *tid, DBT *key, DBT *data, int flags); + +const char* icalbdbset_path(icalset* set); +const char* icalbdbset_subdb(icalset* set); + +/* Mark the set as changed, so it will be written to disk when it + is freed. Commit writes to disk immediately. */ +void icalbdbset_mark(icalset* set); +icalerrorenum icalbdbset_commit(icalset *set); + +icalerrorenum icalbdbset_add_component(icalset* set, + icalcomponent* child); + +icalerrorenum icalbdbset_remove_component(icalset* set, + icalcomponent* child); + +int icalbdbset_count_components(icalset* set, + icalcomponent_kind kind); + +/* Restrict the component returned by icalbdbset_first, _next to those + that pass the gauge. _clear removes the gauge */ +icalerrorenum icalbdbset_select(icalset* store, icalgauge* gauge); +void icalbdbset_clear(icalset* store); + +/* Get and search for a component by uid */ +icalcomponent* icalbdbset_fetch(icalset* set, icalcomponent_kind kind, const char* uid); +int icalbdbset_has_uid(icalset* set, const char* uid); +icalcomponent* icalbdbset_fetch_match(icalset* set, icalcomponent *c); + + +icalerrorenum icalbdbset_modify(icalset* set, icalcomponent *old, + icalcomponent *newc); + +/* cluster management functions */ +icalerrorenum icalbdbset_set_cluster(icalset* set, icalcomponent* cluster); +icalerrorenum icalbdbset_free_cluster(icalset* set); +icalcomponent* icalbdbset_get_cluster(icalset* set); + +/* Iterate through components. If a gauge has been defined, these + will skip over components that do not pass the gauge */ + +icalcomponent* icalbdbset_get_current_component (icalset* set); +icalcomponent* icalbdbset_get_first_component(icalset* set); +icalcomponent* icalbdbset_get_next_component(icalset* set); + +/* External iterator for thread safety */ +icalsetiter icalbdbset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge, const char* tzid); + +icalcomponent* icalbdbset_form_a_matched_recurrence_component(icalsetiter* itr); + +icalcomponent* icalbdbsetiter_to_next(icalset* set, icalsetiter* i); +icalcomponent* icalbdbsetiter_to_prior(icalset* set, icalsetiter* i); + +/* Return a reference to the internal component. You probably should + not be using this. */ + +icalcomponent* icalbdbset_get_component(icalset* set); + +DB_ENV *icalbdbset_get_env(void); + + +int icalbdbset_begin_transaction(DB_TXN* parent_id, DB_TXN** txnid); +int icalbdbset_commit_transaction(DB_TXN* txnid); + +DB* icalbdbset_bdb_open(const char* path, + const char *subdb, + int type, + mode_t mode, int flag); + + +typedef struct icalbdbset_options { + icalbdbset_subdb_type subdb; /**< the subdatabase to open */ + int dbtype; /**< db_open type: DB_HASH | DB_BTREE */ + mode_t mode; /**< file mode */ + u_int32_t flag; /**< DB->set_flags(): DB_DUP | DB_DUPSORT */ + char *(*pfunc)(const DBT *dbt); /**< parsing function */ + int (*callback) (DB *db, /**< callback for secondary db open */ + const DBT *dbt1, + const DBT *dbt2, + DBT *dbt3); +} icalbdbset_options; + +#endif /* !ICALBDBSET_H */ + + + diff --git a/libical/src/libicalss/icalbdbset_cxx.h b/libical/src/libicalss/icalbdbset_cxx.h new file mode 100644 index 0000000000..678adaa299 --- /dev/null +++ b/libical/src/libicalss/icalbdbset_cxx.h @@ -0,0 +1,61 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalbdbset_cxx.h + CREATOR: dml 12/12/01 + (C) COPYRIGHT 2001, Critical Path +======================================================================*/ + +#ifndef ICALBDBSET_CXX_H +#define ICALBDBSET_CXX_H + + +extern "C" { +#include "ical.h" +#include "icalgauge.h" +} + +#include "vcomponent.h" +#include <db_cxx.h> + +typedef char* string; // Will use the string library from STL + +class ICalBDBSet { +public: + + ICalBDBSet(); + ICalBDBSet(const ICalBDBSet&); + ICalBDBSet operator=(const ICalBDBSet &); + ~ICalBDBSet(); + + ICalBDBSet(const string& path, int flags); + +public: + + void free(); + string path(); + + icalerrorenum add_component(VComponent* child); + icalerrorenum remove_component(VComponent* child); + int count_components(icalcomponent_kind kind); + + // Restrict the component returned by icalbdbset_first, _next to those + // that pass the gauge. _clear removes the gauge + icalerrorenum select(icalgauge *gauge); + void clear(); + + // Get and search for a component by uid + VComponent* fetch(string &uid); + VComponent* fetch_match(icalcomponent *c); + int has_uid(string &uid); + + // Iterate through components. If a guage has been defined, these + // will skip over components that do not pass the gauge + VComponent* get_current_component(); + VComponent* get_first_component(); + VComponent* get_next_component(); + + VComponent* get_component(); + +}; + +#endif diff --git a/libical/src/libicalss/icalbdbsetimpl.h b/libical/src/libicalss/icalbdbsetimpl.h new file mode 100644 index 0000000000..281a4834d4 --- /dev/null +++ b/libical/src/libicalss/icalbdbsetimpl.h @@ -0,0 +1,41 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalbdbsetimpl.h + CREATOR: dml 12 December 2001 + (C) COPYRIGHT 2001, Critical Path + + $Id$ + $Locker$ + ======================================================================*/ + +#ifndef ICALBDBSETIMPL_H +#define ICALBDBSETIMPL_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "icalgauge.h" +#include <db.h> + +/* This definition is in its own file so it can be kept out of the + main header file, but used by "friend classes" like icaldirset*/ + +struct icalbdbset_impl { + icalset super; /**< parent class */ + const char *path; + const char *subdb; + const char *sindex; + const char *key; + void *data; + int datasize; + int changed; + icalcomponent* cluster; + icalgauge* gauge; + DB_ENV *dbenv; + DB *dbp; + DB *sdbp; + DBC *dbcp; +}; + +#endif diff --git a/libical/src/libicalss/icalcalendar.c b/libical/src/libicalss/icalcalendar.c index e63b5330ad..1f24f88db6 100644 --- a/libical/src/libicalss/icalcalendar.c +++ b/libical/src/libicalss/icalcalendar.c @@ -34,7 +34,16 @@ #include <sys/stat.h> /* For mkdir, stat */ #include <sys/types.h> /* For mkdir */ #include <fcntl.h> /* For mkdir */ + +#ifndef WIN32 #include <unistd.h> /* For mkdir, stat */ +#endif + +#ifndef PATH_MAX +#define PATH_MAX 512 +#endif + + #include <stdlib.h> /* for malloc */ #include <string.h> /* for strcat */ #include <errno.h> @@ -47,13 +56,13 @@ struct icalcalendar_impl { char* dir; - icalcomponent* freebusy; - icalcomponent* properties; + icalset* freebusy; + icalset* properties; icalset* booked; icalset* incoming; }; -struct icalcalendar_impl* icalcalendar_new_impl() +struct icalcalendar_impl* icalcalendar_new_impl(void) { struct icalcalendar_impl* impl; @@ -119,29 +128,26 @@ icalcalendar* icalcalendar_new(char* dir) return impl; } -void icalcalendar_free(icalcalendar* calendar) +void icalcalendar_free(icalcalendar* impl) { - - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; - if (impl->dir !=0){ free(impl->dir); } if (impl->freebusy !=0){ - icalfileset_free(impl->freebusy); + icalset_free(impl->booked); } if (impl->properties !=0){ - icalfileset_free(impl->properties); + icalset_free(impl->properties); } if (impl->booked !=0){ - icaldirset_free(impl->booked); + icalset_free(impl->booked); } if (impl->incoming !=0){ - icaldirset_free(impl->incoming); + icalset_free(impl->incoming); } impl->dir = 0; @@ -155,37 +161,32 @@ void icalcalendar_free(icalcalendar* calendar) } -int icalcalendar_lock(icalcalendar* calendar) +int icalcalendar_lock(icalcalendar* impl) { - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); return 0; } -int icalcalendar_unlock(icalcalendar* calendar) +int icalcalendar_unlock(icalcalendar* impl) { - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); return 0; } -int icalcalendar_islocked(icalcalendar* calendar) +int icalcalendar_islocked(icalcalendar* impl) { - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); return 0; } -int icalcalendar_ownlock(icalcalendar* calendar) +int icalcalendar_ownlock(icalcalendar* impl) { - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); return 0; } -icalset* icalcalendar_get_booked(icalcalendar* calendar) +icalset* icalcalendar_get_booked(icalcalendar* impl) { - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; char dir[PATH_MAX]; icalerror_check_arg_rz((impl != 0),"impl"); @@ -205,10 +206,9 @@ icalset* icalcalendar_get_booked(icalcalendar* calendar) } -icalset* icalcalendar_get_incoming(icalcalendar* calendar) +icalset* icalcalendar_get_incoming(icalcalendar* impl) { char path[PATH_MAX]; - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); path[0] = '\0'; @@ -223,10 +223,9 @@ icalset* icalcalendar_get_incoming(icalcalendar* calendar) return impl->properties; } -icalset* icalcalendar_get_properties(icalcalendar* calendar) +icalset* icalcalendar_get_properties(icalcalendar* impl) { char path[PATH_MAX]; - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); path[0] = '\0'; @@ -241,10 +240,9 @@ icalset* icalcalendar_get_properties(icalcalendar* calendar) return impl->properties; } -icalset* icalcalendar_get_freebusy(icalcalendar* calendar) +icalset* icalcalendar_get_freebusy(icalcalendar* impl) { char path[PATH_MAX]; - struct icalcalendar_impl *impl = (struct icalcalendar_impl*)calendar; icalerror_check_arg_rz((impl != 0),"impl"); path[0] = '\0'; diff --git a/libical/src/libicalss/icalcalendar.h b/libical/src/libicalss/icalcalendar.h index f07457c60d..2a0c15196a 100644 --- a/libical/src/libicalss/icalcalendar.h +++ b/libical/src/libicalss/icalcalendar.h @@ -38,7 +38,7 @@ * components. It also has interfaces to access the free/busy list * and a list of calendar properties */ -typedef void icalcalendar; +typedef struct icalcalendar_impl icalcalendar; icalcalendar* icalcalendar_new(char* dir); diff --git a/libical/src/libicalss/icalcaputil.h b/libical/src/libicalss/icalcaputil.h new file mode 100644 index 0000000000..4f9bcb31c4 --- /dev/null +++ b/libical/src/libicalss/icalcaputil.h @@ -0,0 +1,58 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalutil.h + CREATOR: eric 23 December 1999 + + + $Id$ + $Locker$ + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + + =========================================================================*/ + + +/* Create new components that have a form suitable for the various + iTIP trasactions */ + +/* Scheduling commands */ +icalcomponent* icalcaputil_new_accept_reply(icalcomponent* comp, char* calid); +icalcomponent* icalcaputil_new_decline_reply(icalcomponent* comp, char* calid); +icalcomponent* icalcaputil_new_refresh(icalcomponent* comp, char* calid); +icalcomponent* icalcaputil_new_cancel(icalcomponent* comp); +icalcomponent* icalcaputil_new_counter(icalcomponent* comp); +icalcomponent* icalcaputil_new_declinecounter(icalcomponent* comp); + +/* Calendaring commands */ +icalcomponent* icalcaputil_new_create(); +icalcomponent* icalcaputil_new_delete(); +icalcomponent* icalcaputil_new_modify(); +icalerrorenum* icalcaputil_modify_add_old_prop(icalcomponent* c, + icalproperty *p); +icalerrorenum* icalcaputil_modify_add_new_prop(icalcomponent* c, + icalproperty *p); +icalerrorenum* icalcaputil_add_query(icalcomponent* c, char* str); + + +icalcomponent* icalcaputil_new_move(); +icalcomponent* icalcaputil_new_read(); + +icalerrorenum icalcaputil_add_target(icalcomponent* comp,char* target); +icalerrorenum icalcaputil_add_to_vcar(icalcomponent* comp,char* target); + + + + + diff --git a/libical/src/libicalss/icalclassify.c b/libical/src/libicalss/icalclassify.c index ad2d6d6fd8..61ddbd3a76 100644 --- a/libical/src/libicalss/icalclassify.c +++ b/libical/src/libicalss/icalclassify.c @@ -29,6 +29,7 @@ #include "ical.h" #include "icalclassify.h" #include "icalmemory.h" + #include <ctype.h> /* For tolower() */ #include <string.h> /* for index() */ #include <stdlib.h> /* for malloc and free */ @@ -36,15 +37,16 @@ struct icalclassify_parts { - icalcomponent *c; - icalproperty_method method; - char* organizer; - icalparameter_partstat reply_partstat; - char* reply_attendee; - char* uid; - int sequence; - struct icaltimetype dtstamp; - struct icaltimetype recurrence_id; + icalcomponent *c; + icalcomponent_kind inner_kind; + icalproperty_method method; + char* organizer; + icalparameter_partstat reply_partstat; + char* reply_attendee; + char* uid; + int sequence; + struct icaltimetype dtstamp; + struct icaltimetype recurrence_id; }; @@ -121,27 +123,48 @@ icalproperty* icalclassify_find_attendee(icalcomponent *c, const char* attendee) { icalproperty *p; - char* lattendee = icalclassify_lowercase(attendee); - char* upn = strchr(lattendee,':'); - icalcomponent *inner = icalcomponent_get_first_real_component(c); + icalcomponent* inner; + char* lattendee; + char* upn; + + if(attendee == 0){ + return 0; + } + + lattendee = icalclassify_lowercase(attendee); + upn = strchr(lattendee,':'); + + if (upn== 0){ + upn = lattendee; + } else { + upn++; /* skip the ";"*/ + } + + inner = icalcomponent_get_first_real_component(c); for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); p != 0; p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY)) { - const char* this_attendee + char* this_attendee = icalclassify_lowercase(icalproperty_get_attendee(p)); char* this_upn = strchr(this_attendee,':'); if(this_upn == 0){ continue; - } + } else { + this_upn++; + } if(strcmp(this_upn,upn)==0){ + free(lattendee); + free(this_attendee); return p; } + free(this_attendee); } + free(lattendee); return 0; @@ -191,6 +214,8 @@ void icalssutil_get_parts(icalcomponent* c, inner = icalcomponent_get_first_real_component(c); + parts->inner_kind = icalcomponent_isa(inner); + p = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); if(p!=0){ parts->organizer = strdup(icalproperty_get_organizer(p)); @@ -263,7 +288,7 @@ int icalssutil_is_rescheduled(icalcomponent* a,icalcomponent* b) p1 = icalcomponent_get_first_property(i1,kind_array[i]); p2 = icalcomponent_get_first_property(i2,kind_array[i]); - if( (p1!=0)^(p1!=0) ){ + if( (p1!=0)^(p2!=0) ){ /* Return true if the property exists in one component and not the other */ return 1; @@ -293,7 +318,7 @@ int icalclassify_publish_new(struct icalclassify_parts *comp, icalclassify_pre; if(comp->method == ICAL_METHOD_PUBLISH && - match == 0){ + match == 0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){ rtrn = 1; } @@ -308,7 +333,7 @@ int icalclassify_publish_update(struct icalclassify_parts *comp, icalclassify_pre; if(comp->method == ICAL_METHOD_PUBLISH && - match !=0 ){ + match !=0 && comp->inner_kind != ICAL_VFREEBUSY_COMPONENT){ rtrn = 1; } @@ -323,7 +348,7 @@ int icalclassify_publish_freebusy(struct icalclassify_parts *comp, icalclassify_pre; if(comp->method == ICAL_METHOD_PUBLISH && - match == 0){ + comp->inner_kind == ICAL_VFREEBUSY_COMPONENT){ rtrn = 1; } @@ -392,11 +417,19 @@ int icalclassify_request_delegate( struct icalclassify_parts *match, const char* user) { - icalclassify_pre + icalproperty* attendee; + icalparameter* param; + icalclassify_pre; - if (match->c != 0 && - comp->sequence > match->sequence && - icalssutil_is_rescheduled(comp->c,match->c)){ + attendee = icalclassify_find_attendee(comp->c,user); + + if(attendee == 0){ + return 0; + } + + param = icalproperty_get_first_parameter(attendee,ICAL_DELEGATEDFROM_PARAMETER); + + if (param != 0){ rtrn = 1; } @@ -411,7 +444,7 @@ int icalclassify_request_new_organizer( { /* Organizer has changed between match and component */ icalclassify_pre - + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); icalclassify_post } @@ -422,6 +455,7 @@ int icalclassify_request_status( const char* user) { icalclassify_pre + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); icalclassify_post } @@ -431,6 +465,7 @@ int icalclassify_request_forward( const char* user) { icalclassify_pre + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); icalclassify_post } @@ -440,6 +475,7 @@ int icalclassify_request_freebusy( const char* user) { icalclassify_pre + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); icalclassify_post } @@ -477,6 +513,22 @@ int icalclassify_reply_decline( } icalclassify_post } +int icalclassify_reply_delegate( + struct icalclassify_parts *comp, + struct icalclassify_parts *match, + const char* user) +{ + icalproperty* attendee; + icalclassify_pre; + + attendee = icalclassify_find_attendee(match->c,comp->reply_attendee); + + if( attendee != 0 && + comp->reply_partstat == ICAL_PARTSTAT_DELEGATED){ + rtrn = 1; + } + icalclassify_post +} int icalclassify_reply_crasher_accept( struct icalclassify_parts *comp, struct icalclassify_parts *match, @@ -498,7 +550,6 @@ int icalclassify_reply_crasher_decline( struct icalclassify_parts *match, const char* user) { - icalparameter_partstat partstat; icalproperty* attendee; icalclassify_pre; @@ -594,45 +645,47 @@ int icalclassify_delinecounter( struct icalclassify_map { icalproperty_method method; int (*fn)(struct icalclassify_parts *comp,struct icalclassify_parts *match, const char* user); - ical_class class; + icalproperty_xlicclass class; } icalclassify_map[] = -{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_PUBLISH_NEW_CLASS}, - {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_PUBLISH_UPDATE_CLASS}, - {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_PUBLISH_FREEBUSY_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_REQUEST_NEW_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_REQUEST_UPDATE_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_REQUEST_RESCHEDULE_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_REQUEST_DELEGATE_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_REQUEST_NEW_ORGANIZER_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_REQUEST_FORWARD_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_REQUEST_STATUS_CLASS}, - {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_REQUEST_FREEBUSY_CLASS}, - - {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_REPLY_ACCEPT_CLASS}, - {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_REPLY_DECLINE_CLASS}, - {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_REPLY_CRASHER_ACCEPT_CLASS}, - {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_REPLY_CRASHER_DECLINE_CLASS}, - - {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_ADD_INSTANCE_CLASS}, - - {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_CANCEL_EVENT_CLASS}, - {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_CANCEL_INSTANCE_CLASS}, - {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_CANCEL_ALL_CLASS}, - - {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_REFRESH_CLASS}, - {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_COUNTER_CLASS}, - {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_DECLINECOUNTER_CLASS}, - {ICAL_METHOD_NONE,0,ICAL_NO_CLASS} +{ {ICAL_METHOD_PUBLISH,icalclassify_publish_new,ICAL_XLICCLASS_PUBLISHNEW}, + {ICAL_METHOD_PUBLISH,icalclassify_publish_update,ICAL_XLICCLASS_PUBLISHUPDATE}, + {ICAL_METHOD_PUBLISH,icalclassify_publish_freebusy,ICAL_XLICCLASS_PUBLISHFREEBUSY}, + {ICAL_METHOD_REQUEST,icalclassify_request_delegate,ICAL_XLICCLASS_REQUESTDELEGATE}, + {ICAL_METHOD_REQUEST,icalclassify_request_new,ICAL_XLICCLASS_REQUESTNEW}, + {ICAL_METHOD_REQUEST,icalclassify_request_update,ICAL_XLICCLASS_REQUESTUPDATE}, + {ICAL_METHOD_REQUEST,icalclassify_request_reschedule,ICAL_XLICCLASS_REQUESTRESCHEDULE}, + + {ICAL_METHOD_REQUEST,icalclassify_request_new_organizer,ICAL_XLICCLASS_REQUESTNEWORGANIZER}, + {ICAL_METHOD_REQUEST,icalclassify_request_forward,ICAL_XLICCLASS_REQUESTFORWARD}, + {ICAL_METHOD_REQUEST,icalclassify_request_status,ICAL_XLICCLASS_REQUESTSTATUS}, + {ICAL_METHOD_REQUEST,icalclassify_request_freebusy,ICAL_XLICCLASS_REQUESTFREEBUSY}, + + {ICAL_METHOD_REPLY,icalclassify_reply_accept,ICAL_XLICCLASS_REPLYACCEPT}, + {ICAL_METHOD_REPLY,icalclassify_reply_decline,ICAL_XLICCLASS_REPLYDECLINE}, + {ICAL_METHOD_REPLY,icalclassify_reply_delegate,ICAL_XLICCLASS_REPLYDELEGATE}, + {ICAL_METHOD_REPLY,icalclassify_reply_crasher_accept,ICAL_XLICCLASS_REPLYCRASHERACCEPT}, + {ICAL_METHOD_REPLY,icalclassify_reply_crasher_decline,ICAL_XLICCLASS_REPLYCRASHERDECLINE}, + + {ICAL_METHOD_ADD,icalclassify_add_instance,ICAL_XLICCLASS_ADDINSTANCE}, + + {ICAL_METHOD_CANCEL,icalclassify_cancel_event,ICAL_XLICCLASS_CANCELEVENT}, + {ICAL_METHOD_CANCEL,icalclassify_cancel_instance,ICAL_XLICCLASS_CANCELINSTANCE}, + {ICAL_METHOD_CANCEL,icalclassify_cancel_all,ICAL_XLICCLASS_CANCELALL}, + + {ICAL_METHOD_REFRESH,icalclassify_refesh,ICAL_XLICCLASS_REFRESH}, + {ICAL_METHOD_COUNTER,icalclassify_counter,ICAL_XLICCLASS_COUNTER}, + {ICAL_METHOD_DECLINECOUNTER,icalclassify_delinecounter,ICAL_XLICCLASS_DECLINECOUNTER}, + {ICAL_METHOD_NONE,0,ICAL_XLICCLASS_NONE} }; -ical_class icalclassify(icalcomponent* c,icalcomponent* match, +icalproperty_xlicclass icalclassify(icalcomponent* c,icalcomponent* match, const char* user) { icalcomponent *inner; icalproperty *p; icalproperty_method method; - ical_class class = ICAL_UNKNOWN_CLASS; + icalproperty_xlicclass class = ICAL_XLICCLASS_UNKNOWN; int i; @@ -642,7 +695,7 @@ ical_class icalclassify(icalcomponent* c,icalcomponent* match, inner = icalcomponent_get_first_real_component(c); if (inner == 0) { - return ICAL_NO_CLASS; + return ICAL_XLICCLASS_NONE; } icalssutil_get_parts(c,&comp_parts); @@ -659,7 +712,8 @@ ical_class icalclassify(icalcomponent* c,icalcomponent* match, icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)>0) { /* comp has a smaller sequence and a later DTSTAMP */ - return ICAL_MISSEQUENCED_CLASS; + class = ICAL_XLICCLASS_MISSEQUENCED; + goto CLEANUP; } if( (comp_parts.sequence<match_parts.sequence ) @@ -668,14 +722,16 @@ ical_class icalclassify(icalcomponent* c,icalcomponent* match, ( comp_parts.sequence == match_parts.sequence && icaltime_compare(comp_parts.dtstamp,match_parts.dtstamp)<=0)){ - return ICAL_OBSOLETE_CLASS; + class = ICAL_XLICCLASS_OBSOLETE; + goto CLEANUP; } } p = icalcomponent_get_first_property(c,ICAL_METHOD_PROPERTY); if (p == 0) { - return ICAL_UNKNOWN_CLASS; + class = ICAL_XLICCLASS_UNKNOWN; + goto CLEANUP; } method = icalproperty_get_method(p); @@ -688,9 +744,11 @@ ical_class icalclassify(icalcomponent* c,icalcomponent* match, } } +CLEANUP: icalssutil_free_parts(&comp_parts); icalssutil_free_parts(&match_parts); return class; } + diff --git a/libical/src/libicalss/icalclassify.h b/libical/src/libicalss/icalclassify.h index ae76434378..aceabc0a20 100644 --- a/libical/src/libicalss/icalclassify.h +++ b/libical/src/libicalss/icalclassify.h @@ -29,42 +29,14 @@ #include "ical.h" #include "icalset.h" - -typedef enum icalclass { - ICAL_NO_CLASS, - ICAL_PUBLISH_NEW_CLASS, - ICAL_PUBLISH_UPDATE_CLASS, - ICAL_PUBLISH_FREEBUSY_CLASS, - ICAL_REQUEST_NEW_CLASS, - ICAL_REQUEST_UPDATE_CLASS, - ICAL_REQUEST_RESCHEDULE_CLASS, - ICAL_REQUEST_DELEGATE_CLASS, - ICAL_REQUEST_NEW_ORGANIZER_CLASS, - ICAL_REQUEST_FORWARD_CLASS, - ICAL_REQUEST_STATUS_CLASS, - ICAL_REQUEST_FREEBUSY_CLASS, - ICAL_REPLY_ACCEPT_CLASS, - ICAL_REPLY_DECLINE_CLASS, - ICAL_REPLY_CRASHER_ACCEPT_CLASS, - ICAL_REPLY_CRASHER_DECLINE_CLASS, - ICAL_ADD_INSTANCE_CLASS, - ICAL_CANCEL_EVENT_CLASS, - ICAL_CANCEL_INSTANCE_CLASS, - ICAL_CANCEL_ALL_CLASS, - ICAL_REFRESH_CLASS, - ICAL_COUNTER_CLASS, - ICAL_DECLINECOUNTER_CLASS, - ICAL_MALFORMED_CLASS, - ICAL_OBSOLETE_CLASS, /* 21 */ - ICAL_MISSEQUENCED_CLASS, /* 22 */ - ICAL_UNKNOWN_CLASS /* 23 */ -} ical_class; - -ical_class icalclassify(icalcomponent* c,icalcomponent* match, +icalproperty_xlicclass icalclassify(icalcomponent* c,icalcomponent* match, const char* user); icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp); +char* icalclassify_class_to_string(icalproperty_xlicclass c); + + #endif /* ICALCLASSIFY_H*/ diff --git a/libical/src/libicalss/icalcluster.c b/libical/src/libicalss/icalcluster.c new file mode 100644 index 0000000000..6d11078a72 --- /dev/null +++ b/libical/src/libicalss/icalcluster.c @@ -0,0 +1,245 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalcluster.c + CREATOR: acampi 13 March 2002 + + $Id$ + $Locker$ + + (C) COPYRIGHT 2002, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The Original Code is eric. The Initial Developer of the Original + Code is Eric Busboom + + + ======================================================================*/ + + +/** + * + * icalcluster is an utility class design to manage clusters of + * icalcomponents on behalf of an implementation of icalset. This is + * done in order to split out common behavior different classes might + * need. + * The definition of what exactly a cluster will contain depends on the + * icalset subclass. At the basic level, an icluster is just a tuple, + * with anything as key and an icalcomponent as value. + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdlib.h> +#include <string.h> + +#if 0 +#include <errno.h> +#include <sys/stat.h> /* for stat */ +#ifndef WIN32 +#include <unistd.h> /* for stat, getpid */ +#else +#include <io.h> +#include <share.h> +#endif +#include <fcntl.h> /* for fcntl */ +#endif + +#include "icalcluster.h" +#include "icalclusterimpl.h" +#include "icalgauge.h" + +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + + +icalcluster * icalcluster_new_impl(void) { + + struct icalcluster_impl* impl; + + if ((impl = (struct icalcluster_impl*)malloc( + sizeof(struct icalcluster_impl))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + memset(impl, 0, sizeof(struct icalcluster_impl)); + strcpy(impl->id,ICALCLUSTER_ID); + + return impl; +} + +/** + * Create a cluster with a key/value pair. + * + * @todo Always do a deep copy. + */ + +icalcluster * icalcluster_new(const char* key, icalcomponent *data) { + struct icalcluster_impl *impl = icalcluster_new_impl(); + assert(impl->data == 0); + + impl->key = strdup(key); + impl->changed = 0; + impl->data = 0; + + if (data != NULL) { + if (icalcomponent_isa(data) != ICAL_XROOT_COMPONENT) { + impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT); + icalcomponent_add_component(impl->data, data); + } else { + impl->data = icalcomponent_new_clone(data); + } + } else { + impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT); + } + + return impl; +} + +/** + * Deep clone an icalcluster to a new one + */ + +icalcluster *icalcluster_new_clone(const icalcluster *data) { + struct icalcluster_impl *old = (struct icalcluster_impl *)data; + struct icalcluster_impl *impl = icalcluster_new_impl(); + + impl->key = strdup(old->key); + impl->data = icalcomponent_new_clone(old->data); + impl->changed = 0; + + return impl; +} + + +void icalcluster_free(icalcluster *impl) { + icalerror_check_arg_rv((impl!=0),"cluster"); + + if (impl->key != 0){ + free(impl->key); + impl->key = 0; + } + + if (impl->data != 0){ + icalcomponent_free(impl->data); + impl->data = 0; + } + + free(impl); +} + + +const char *icalcluster_key(icalcluster *impl) { + icalerror_check_arg_rz((impl!=0),"cluster"); + + return impl->key; +} + + +int icalcluster_is_changed(icalcluster *impl) { + icalerror_check_arg_rz((impl!=0),"cluster"); + + return impl->changed; +} + + +void icalcluster_mark(icalcluster *impl) { + icalerror_check_arg_rv((impl!=0),"cluster"); + + impl->changed = 1; +} + + +void icalcluster_commit(icalcluster *impl) { + icalerror_check_arg_rv((impl!=0),"cluster"); + + impl->changed = 0; +} + + +icalcomponent *icalcluster_get_component(icalcluster *impl) { + + icalerror_check_arg_rz((impl!=0),"cluster"); + + if (icalcomponent_isa(impl->data) != ICAL_XROOT_COMPONENT) { + icalerror_warn("The top component is not an XROOT"); + fprintf(stderr, "%s\n", icalcomponent_as_ical_string(impl->data)); + abort(); + } + + return impl->data; +} + + +icalerrorenum icalcluster_add_component(icalcluster *impl, icalcomponent* child) { + + icalerror_check_arg_re((impl!=0),"cluster", ICAL_BADARG_ERROR); + icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); + + icalcomponent_add_component(impl->data, child); + icalcluster_mark(impl); + + return ICAL_NO_ERROR; +} + + +icalerrorenum icalcluster_remove_component(icalcluster *impl, icalcomponent* child) { + + icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); + icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); + + icalcomponent_remove_component(impl->data,child); + icalcluster_mark(impl); + + return ICAL_NO_ERROR; +} + + +int icalcluster_count_components(icalcluster *impl, icalcomponent_kind kind) { + + icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); + + return icalcomponent_count_components(impl->data, kind); +} + + +/** Iterate through components **/ +icalcomponent *icalcluster_get_current_component(icalcluster* impl) { + + icalerror_check_arg_rz((impl!=0),"cluster"); + + return icalcomponent_get_current_component(impl->data); +} + + +icalcomponent *icalcluster_get_first_component(icalcluster* impl) { + + icalerror_check_arg_rz((impl!=0),"cluster"); + + return icalcomponent_get_first_component(impl->data, + ICAL_ANY_COMPONENT); +} + + +icalcomponent *icalcluster_get_next_component(icalcluster* impl) { + + icalerror_check_arg_rz((impl!=0),"cluster"); + + return icalcomponent_get_next_component(impl->data, + ICAL_ANY_COMPONENT); +} diff --git a/libical/src/libicalss/icalcluster.h b/libical/src/libicalss/icalcluster.h new file mode 100644 index 0000000000..f4eb041b04 --- /dev/null +++ b/libical/src/libicalss/icalcluster.h @@ -0,0 +1,61 @@ +/* -*- Mode: C -*- */ +/*====================================================================== + FILE: icalcluster.h + CREATOR: eric 23 December 1999 + + + $Id$ + $Locker$ + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The Original Code is eric. The Initial Developer of the Original + Code is Eric Busboom + + +======================================================================*/ + +#ifndef ICALCLUSTER_H +#define ICALCLUSTER_H + +#include "ical.h" +#include "icalset.h" + +typedef struct icalcluster_impl icalcluster; + +icalcluster* icalcluster_new(const char *key, icalcomponent *data); +icalcluster* icalcluster_new_clone(const icalcluster *cluster); + +void icalcluster_free(icalcluster *cluster); + +const char* icalcluster_key(icalcluster *cluster); +int icalcluster_is_changed(icalcluster *cluster); +void icalcluster_mark(icalcluster *cluster); +void icalcluster_commit(icalcluster *cluster); + +icalcomponent* icalcluster_get_component(icalcluster* cluster); +int icalcluster_count_components(icalcluster *cluster, icalcomponent_kind kind); +icalerrorenum icalcluster_add_component(icalcluster* cluster, + icalcomponent* child); +icalerrorenum icalcluster_remove_component(icalcluster* cluster, + icalcomponent* child); + +icalcomponent* icalcluster_get_current_component(icalcluster* cluster); +icalcomponent* icalcluster_get_first_component(icalcluster* cluster); +icalcomponent* icalcluster_get_next_component(icalcluster* cluster); + +#endif /* !ICALCLUSTER_H */ + + + diff --git a/libical/src/libicalss/icalclusterimpl.h b/libical/src/libicalss/icalclusterimpl.h new file mode 100644 index 0000000000..ef80e1af81 --- /dev/null +++ b/libical/src/libicalss/icalclusterimpl.h @@ -0,0 +1,45 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: icalfilesetimpl.h + CREATOR: eric 23 December 1999 + + $Id$ + $Locker$ + + (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + The Original Code is eric. The Initial Developer of the Original + Code is Eric Busboom + + + ======================================================================*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* This definition is in its own file so it can be kept out of the + main header file, but used by "friend classes" like icaldirset*/ + +#define ICALCLUSTER_ID "clus" + +struct icalcluster_impl { + + char id[5]; /* clus */ + + char *key; + icalcomponent *data; + int changed; +}; diff --git a/libical/src/libicalss/icaldirset.c b/libical/src/libicalss/icaldirset.c index f5da125459..4a20fe1978 100644 --- a/libical/src/libicalss/icaldirset.c +++ b/libical/src/libicalss/icaldirset.c @@ -26,9 +26,10 @@ ======================================================================*/ -/* +/** + @file icaldirset.c - icaldirset manages a database of ical components and offers + @brief icaldirset manages a database of ical components and offers interfaces for reading, writting and searching for components. icaldirset groups components in to clusters based on their DTSTAMP @@ -36,12 +37,13 @@ together in a single file. All files in a sotre are kept in a single directory. - The primary interfaces are icaldirset_first and icaldirset_next. These - routine iterate through all of the components in the store, subject - to the current gauge. A gauge is an icalcomponent that is tested - against other componets for a match. If a gauge has been set with - icaldirset_select, icaldirset_first and icaldirset_next will only - return componentes that match the gauge. + The primary interfaces are icaldirset__get_first_component and + icaldirset_get_next_component. These routine iterate through all of + the components in the store, subject to the current gauge. A gauge + is an icalcomponent that is tested against other componets for a + match. If a gauge has been set with icaldirset_select, + icaldirset_first and icaldirset_next will only return componentes + that match the gauge. The Store generated UIDs for all objects that are stored if they do not already have a UID. The UID is the name of the cluster (month & @@ -57,64 +59,74 @@ #include "ical.h" #include "icaldirset.h" -#include "pvl.h" -#include "icalerror.h" -#include "icalparser.h" #include "icaldirset.h" #include "icalfileset.h" #include "icalfilesetimpl.h" +#include "icalcluster.h" #include "icalgauge.h" #include <limits.h> /* For PATH_MAX */ +#ifndef WIN32 +#include <dirent.h> /* for opendir() */ +#include <unistd.h> /* for stat, getpid */ +#include <sys/utsname.h> /* for uname */ +#else +#include <io.h> +#include <process.h> +#endif #include <errno.h> #include <sys/types.h> /* for opendir() */ -#include <dirent.h> /* for opendir() */ #include <sys/stat.h> /* for stat */ -#include <unistd.h> /* for stat, getpid */ #include <time.h> /* for clock() */ #include <stdlib.h> /* for rand(), srand() */ -#include <sys/utsname.h> /* for uname */ #include <string.h> /* for strdup */ #include "icaldirsetimpl.h" -struct icaldirset_impl* icaldirset_new_impl() -{ - struct icaldirset_impl* impl; +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp - if ( ( impl = (struct icaldirset_impl*) - malloc(sizeof(struct icaldirset_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } +#define _S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask)) - strcpy(impl->id,ICALDIRSET_ID); +#define S_ISDIR(mode) _S_ISTYPE((mode), _S_IFDIR) +#define S_ISREG(mode) _S_ISTYPE((mode), _S_IFREG) +#endif - return impl; -} +/** Default options used when NULL is passed to icalset_new() **/ +icaldirset_options icaldirset_options_default = {O_RDWR|O_CREAT}; -const char* icaldirset_path(icaldirset* cluster) -{ - struct icaldirset_impl *impl = icaldirset_new_impl(); - return impl->dir; +const char* icaldirset_path(icalset* set) +{ + icaldirset *dset = (icaldirset*)set; + return dset->dir; } -void icaldirset_mark(icaldirset* store) + +void icaldirset_mark(icalset* set) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; + icaldirset *dset = (icaldirset*)set; - icalfileset_mark(impl->cluster); + icalcluster_mark(dset->cluster); } -icalerrorenum icaldirset_commit(icaldirset* store) +icalerrorenum icaldirset_commit(icalset* set) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; + icaldirset *dset = (icaldirset*)set; + icalset *fileset; + icalfileset_options options = icalfileset_options_default; - return icalfileset_commit(impl->cluster); + options.cluster = dset->cluster; + fileset = icalset_new(ICAL_FILE_SET, icalcluster_key(dset->cluster), &options); + + fileset->commit(fileset); + fileset->free(fileset); + + return ICAL_NO_ERROR; } void icaldirset_lock(const char* dir) @@ -127,21 +139,22 @@ void icaldirset_unlock(const char* dir) } /* Load the contents of the store directory into the store's internal directory list*/ -icalerrorenum icaldirset_read_directory(struct icaldirset_impl* impl) +icalerrorenum icaldirset_read_directory(icaldirset *dset) { + char *str; +#ifndef WIN32 struct dirent *de; DIR* dp; - char *str; - dp = opendir(impl->dir); + dp = opendir(dset->dir); - if ( dp == 0) { + if (dp == 0) { icalerror_set_errno(ICAL_FILE_ERROR); return ICAL_FILE_ERROR; } /* clear contents of directory list */ - while((str = pvl_pop(impl->directory))){ + while((str = pvl_pop(dset->directory))){ free(str); } @@ -156,24 +169,52 @@ icalerrorenum icaldirset_read_directory(struct icaldirset_impl* impl) continue; } - pvl_push(impl->directory, (void*)strdup(de->d_name)); + pvl_push(dset->directory, (void*)strdup(de->d_name)); } closedir(dp); +#else + struct _finddata_t c_file; + long hFile; + + /* Find first .c file in current directory */ + if( (hFile = _findfirst( "*", &c_file )) == -1L ) { + icalerror_set_errno(ICAL_FILE_ERROR); + return ICAL_FILE_ERROR; + } else { + while((str = pvl_pop(dset->directory))){ + free(str); + } + + /* load all of the cluster names in the directory list */ + do { + /* Remove known directory names '.' and '..'*/ + if (strcmp(c_file.name,".") == 0 || + strcmp(c_file.name,"..") == 0 ){ + continue; + } + + pvl_push(dset->directory, (void*)strdup(c_file.name)); + } + while ( _findnext( hFile, &c_file ) == 0 ); + + _findclose( hFile ); + } + +#endif return ICAL_NO_ERROR; } -icaldirset* icaldirset_new(const char* dir) + +icalset* icaldirset_init(icalset* set, const char* dir, void* options_in) { - struct icaldirset_impl *impl = icaldirset_new_impl(); + icaldirset *dset = (icaldirset*)set; + icaldirset_options *options = options_in; struct stat sbuf; - if (impl == 0){ - return 0; - } - icalerror_check_arg_rz( (dir!=0), "dir"); + icalerror_check_arg_rz( (set!=0), "set"); if (stat(dir,&sbuf) != 0){ icalerror_set_errno(ICAL_FILE_ERROR); @@ -188,68 +229,83 @@ icaldirset* icaldirset_new(const char* dir) icaldirset_lock(dir); - impl = icaldirset_new_impl(); + dset->dir = (char*)strdup(dir); + dset->options = *options; + dset->directory = pvl_newlist(); + dset->directory_iterator = 0; + dset->gauge = 0; + dset->first_component = 0; + dset->cluster = 0; + + return set; +} + +icalset* icaldirset_new(const char* dir) +{ + return icalset_new(ICAL_DIR_SET, dir, &icaldirset_options_default); +} - if (impl ==0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - impl->directory = pvl_newlist(); - impl->directory_iterator = 0; - impl->dir = (char*)strdup(dir); - impl->gauge = 0; - impl->first_component = 0; - impl->cluster = 0; +icalset* icaldirset_new_reader(const char* dir) +{ + icaldirset_options reader_options = icaldirset_options_default; + + reader_options.flags = O_RDONLY; + + return icalset_new(ICAL_DIR_SET, dir, &reader_options); +} + + +icalset* icaldirset_new_writer(const char* dir) +{ + icaldirset_options writer_options = icaldirset_options_default; - icaldirset_read_directory(impl); + writer_options.flags = O_RDWR|O_CREAT; - return (icaldirset*) impl; + return icalset_new(ICAL_DIR_SET, dir, &writer_options); } -void icaldirset_free(icaldirset* s) + +void icaldirset_free(icalset* s) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)s; + icaldirset *dset = (icaldirset*)s; char* str; - icaldirset_unlock(impl->dir); + icaldirset_unlock(dset->dir); - if(impl->dir !=0){ - free(impl->dir); + if(dset->dir !=0){ + free(dset->dir); + dset->dir = 0; } - if(impl->gauge !=0){ - icalcomponent_free(impl->gauge); + if(dset->gauge !=0){ + icalgauge_free(dset->gauge); + dset->gauge = 0; } - if(impl->cluster !=0){ - icalfileset_free(impl->cluster); + if(dset->cluster !=0){ + icalcluster_free(dset->cluster); } - while(impl->directory !=0 && (str=pvl_pop(impl->directory)) != 0){ + while(dset->directory !=0 && (str=pvl_pop(dset->directory)) != 0){ free(str); } - if(impl->directory != 0){ - pvl_free(impl->directory); + if(dset->directory != 0){ + pvl_free(dset->directory); + dset->directory = 0; } - impl->directory = 0; - impl->directory_iterator = 0; - impl->dir = 0; - impl->gauge = 0; - impl->first_component = 0; - - free(impl); - + dset->directory_iterator = 0; + dset->first_component = 0; } + /* icaldirset_next_uid_number updates a serial number in the Store directory in a file called SEQUENCE */ -int icaldirset_next_uid_number(icaldirset* store) +int icaldirset_next_uid_number(icaldirset* dset) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; char sequence = 0; char temp[128]; char filename[ICAL_PATH_MAX]; @@ -257,9 +313,9 @@ int icaldirset_next_uid_number(icaldirset* store) FILE *f; struct stat sbuf; - icalerror_check_arg_rz( (store!=0), "store"); + icalerror_check_arg_rz( (dset!=0), "dset"); - sprintf(filename,"%s/%s",impl->dir,"SEQUENCE"); + sprintf(filename,"%s/%s",dset->dir,"SEQUENCE"); /* Create the file if it does not exist.*/ if (stat(filename,&sbuf) == -1 || !S_ISREG(sbuf.st_mode)){ @@ -272,7 +328,6 @@ int icaldirset_next_uid_number(icaldirset* store) icalerror_warn("Can't create SEQUENCE file in icaldirset_next_uid_number"); return 0; } - } if ( (f = fopen(filename,"r+")) != 0){ @@ -298,85 +353,85 @@ int icaldirset_next_uid_number(icaldirset* store) icalerror_warn("Can't create SEQUENCE file in icaldirset_next_uid_number"); return 0; } - } -icalerrorenum icaldirset_next_cluster(icaldirset* store) +icalerrorenum icaldirset_next_cluster(icaldirset* dset) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; char path[ICAL_PATH_MAX]; - if (impl->directory_iterator == 0){ + if (dset->directory_iterator == 0){ icalerror_set_errno(ICAL_INTERNAL_ERROR); return ICAL_INTERNAL_ERROR; } - impl->directory_iterator = pvl_next(impl->directory_iterator); + dset->directory_iterator = pvl_next(dset->directory_iterator); - if (impl->directory_iterator == 0){ + if (dset->directory_iterator == 0){ /* There are no more clusters */ - if(impl->cluster != 0){ - icalfileset_free(impl->cluster); - impl->cluster = 0; + if(dset->cluster != 0){ + icalcluster_free(dset->cluster); + dset->cluster = 0; } return ICAL_NO_ERROR; } - sprintf(path,"%s/%s",impl->dir,(char*)pvl_data(impl->directory_iterator)); - - icalfileset_free(impl->cluster); + sprintf(path,"%s/%s", dset->dir,(char*)pvl_data(dset->directory_iterator)); - impl->cluster = icalfileset_new(path); + icalcluster_free(dset->cluster); + dset->cluster = icalfileset_produce_icalcluster(path); return icalerrno; } -void icaldirset_add_uid(icaldirset* store, icaldirset* comp) +static void icaldirset_add_uid(icalcomponent* comp) { char uidstring[ICAL_PATH_MAX]; icalproperty *uid; +#ifndef WIN32 struct utsname unamebuf; +#endif - icalerror_check_arg_rv( (store!=0), "store"); icalerror_check_arg_rv( (comp!=0), "comp"); uid = icalcomponent_get_first_property(comp,ICAL_UID_PROPERTY); if (uid == 0) { +#ifndef WIN32 uname(&unamebuf); sprintf(uidstring,"%d-%s",(int)getpid(),unamebuf.nodename); +#else + sprintf(uidstring,"%d-%s",(int)getpid(),"WINDOWS"); /* FIX: There must be an easy get the system name */ +#endif uid = icalproperty_new_uid(uidstring); icalcomponent_add_property(comp,uid); } else { - strcpy(uidstring,icalproperty_get_uid(uid)); } } -/* This assumes that the top level component is a VCALENDAR, and there +/** + This assumes that the top level component is a VCALENDAR, and there is an inner component of type VEVENT, VTODO or VJOURNAL. The inner - component must have a DTAMP property */ + component must have a DSTAMP property +*/ -icalerrorenum icaldirset_add_component(icaldirset* store, icaldirset* comp) +icalerrorenum icaldirset_add_component(icalset* set, icalcomponent* comp) { - struct icaldirset_impl *impl; char clustername[ICAL_PATH_MAX]; - icalproperty *dt; + icalproperty *dt = 0; icalvalue *v; struct icaltimetype tm; icalerrorenum error = ICAL_NO_ERROR; icalcomponent *inner; + icaldirset *dset = (icaldirset*) set; - impl = (struct icaldirset_impl*)store; - icalerror_check_arg_rz( (store!=0), "store"); + icalerror_check_arg_rz( (dset!=0), "dset"); icalerror_check_arg_rz( (comp!=0), "comp"); - errno = 0; - - icaldirset_add_uid(store,comp); + icaldirset_add_uid(comp); /* Determine which cluster this object belongs in. This is a HACK */ @@ -386,52 +441,44 @@ icalerrorenum icaldirset_add_component(icaldirset* store, icaldirset* comp) dt = icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY); - if (dt != 0){ + if (dt != 0) break; } - } - - if (dt == 0){ + if (dt == 0) { for(inner = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT); inner != 0; inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){ dt = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY); - if (dt != 0){ + if (dt != 0) break; } } - } - if (dt == 0){ - - icalerror_warn("The component does not have a DTSTAMP or DTSTART property, so it cannot be added to the store"); icalerror_set_errno(ICAL_BADARG_ERROR); return ICAL_BADARG_ERROR; } v = icalproperty_get_value(dt); - tm = icalvalue_get_datetime(v); - snprintf(clustername,ICAL_PATH_MAX,"%s/%04d%02d",impl->dir,tm.year,tm.month); + snprintf(clustername,ICAL_PATH_MAX,"%s/%04d%02d",dset->dir, tm.year, tm.month); /* Load the cluster and insert the object */ - - if(impl->cluster != 0 && - strcmp(clustername,icalfileset_path(impl->cluster)) != 0 ){ - icalfileset_free(impl->cluster); - impl->cluster = 0; + if(dset->cluster != 0 && + strcmp(clustername,icalcluster_key(dset->cluster)) != 0 ){ + icalcluster_free(dset->cluster); + dset->cluster = 0; } - if (impl->cluster == 0){ - impl->cluster = icalfileset_new(clustername); + if (dset->cluster == 0){ + dset->cluster = icalfileset_produce_icalcluster(clustername); - if (impl->cluster == 0){ + if (dset->cluster == 0){ error = icalerrno; } } @@ -442,33 +489,31 @@ icalerrorenum icaldirset_add_component(icaldirset* store, icaldirset* comp) } /* Add the component to the cluster */ - - icalfileset_add_component(impl->cluster,comp); + icalcluster_add_component(dset->cluster,comp); - icalfileset_mark(impl->cluster); + /* icalcluster_mark(impl->cluster); */ return ICAL_NO_ERROR; } -/* Remove a component in the current cluster. HACK. This routine is a +/** + Remove a component in the current cluster. HACK. This routine is a "friend" of icalfileset, and breaks its encapsulation. It was either do it this way, or add several layers of interfaces that had - no other use. */ -icalerrorenum icaldirset_remove_component(icaldirset* store, icaldirset* comp) -{ - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; - - struct icalfileset_impl *filesetimpl = - (struct icalfileset_impl*)impl->cluster; + no other use. + */ - icalcomponent *filecomp = filesetimpl->cluster; +icalerrorenum icaldirset_remove_component(icalset* set, icalcomponent* comp) +{ + icaldirset *dset = (icaldirset*)set; + icalcomponent *filecomp = icalcluster_get_component(dset->cluster); icalcompiter i; int found = 0; - icalerror_check_arg_re((store!=0),"store",ICAL_BADARG_ERROR); + icalerror_check_arg_re((set!=0),"set",ICAL_BADARG_ERROR); icalerror_check_arg_re((comp!=0),"comp",ICAL_BADARG_ERROR); - icalerror_check_arg_re((impl->cluster!=0),"Cluster pointer",ICAL_USAGE_ERROR); + icalerror_check_arg_re((dset->cluster!=0),"Cluster pointer",ICAL_USAGE_ERROR); for(i = icalcomponent_begin_component(filecomp,ICAL_ANY_COMPONENT); icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ @@ -487,17 +532,16 @@ icalerrorenum icaldirset_remove_component(icaldirset* store, icaldirset* comp) return ICAL_USAGE_ERROR; } - icalfileset_remove_component(impl->cluster,comp); + icalcluster_remove_component(dset->cluster,comp); - icalfileset_mark(impl->cluster); + /* icalcluster_mark(impl->cluster); */ /* If the removal emptied the fileset, get the next fileset */ - if( icalfileset_count_components(impl->cluster,ICAL_ANY_COMPONENT)==0){ - - icalerrorenum error = icaldirset_next_cluster(store); + if( icalcluster_count_components(dset->cluster,ICAL_ANY_COMPONENT)==0){ + icalerrorenum error = icaldirset_next_cluster(dset); - if(impl->cluster != 0 && error == ICAL_NO_ERROR){ - icalfileset_get_first_component(impl->cluster); + if(dset->cluster != 0 && error == ICAL_NO_ERROR){ + icalcluster_get_first_component(dset->cluster); } else { /* HACK. Not strictly correct for impl->cluster==0 */ return error; @@ -511,95 +555,84 @@ icalerrorenum icaldirset_remove_component(icaldirset* store, icaldirset* comp) -int icaldirset_count_components(icaldirset* store, +int icaldirset_count_components(icalset* store, icalcomponent_kind kind) { /* HACK, not implemented */ - assert(0); return 0; } -icalcomponent* icaldirset_fetch_match(icaldirset* set, icalcomponent *c) +icalcomponent* icaldirset_fetch_match(icalset* set, icalcomponent *c) { fprintf(stderr," icaldirset_fetch_match is not implemented\n"); assert(0); + return 0; } -icalcomponent* icaldirset_fetch(icaldirset* store, const char* uid) +icalcomponent* icaldirset_fetch(icalset* set, const char* uid) { - icalcomponent *gauge; - icalcomponent *old_gauge; + icaldirset *dset = (icaldirset*)set; + icalgauge *gauge; + icalgauge *old_gauge; icalcomponent *c; - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; + char sql[256]; - icalerror_check_arg_rz( (store!=0), "store"); + icalerror_check_arg_rz( (set!=0), "set"); icalerror_check_arg_rz( (uid!=0), "uid"); - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_uid( - uid, - icalparameter_new_xliccomparetype( - ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); + snprintf(sql, 256, "SELECT * FROM VEVENT WHERE UID = \"%s\"", uid); + + gauge = icalgauge_new_from_sql(sql, 0); - old_gauge = impl->gauge; - impl->gauge = gauge; + old_gauge = dset->gauge; + dset->gauge = gauge; - c= icaldirset_get_first_component(store); + c= icaldirset_get_first_component(set); - impl->gauge = old_gauge; + dset->gauge = old_gauge; - icalcomponent_free(gauge); + icalgauge_free(gauge); return c; } -int icaldirset_has_uid(icaldirset* store, const char* uid) +int icaldirset_has_uid(icalset* set, const char* uid) { icalcomponent *c; - icalerror_check_arg_rz( (store!=0), "store"); + icalerror_check_arg_rz( (set!=0), "set"); icalerror_check_arg_rz( (uid!=0), "uid"); /* HACK. This is a temporary implementation. _has_uid should use a database, and _fetch should use _has_uid, not the other way around */ - c = icaldirset_fetch(store,uid); + c = icaldirset_fetch(set,uid); return c!=0; } -icalerrorenum icaldirset_select(icaldirset* store, icalcomponent* gauge) - { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; +icalerrorenum icaldirset_select(icalset* set, icalgauge* gauge) +{ + icaldirset *dset = (icaldirset*)set; - icalerror_check_arg_re( (store!=0), "store",ICAL_BADARG_ERROR); + icalerror_check_arg_re( (set!=0), "set",ICAL_BADARG_ERROR); icalerror_check_arg_re( (gauge!=0), "gauge",ICAL_BADARG_ERROR); - if (!icalcomponent_is_valid(gauge)){ - return ICAL_BADARG_ERROR; - } - - impl->gauge = gauge; + dset->gauge = gauge; return ICAL_NO_ERROR; } -icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *old, +icalerrorenum icaldirset_modify(icalset* set, + icalcomponent *old, icalcomponent *new) { assert(0); @@ -608,7 +641,7 @@ icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *old, } -void icaldirset_clear(icaldirset* store) +void icaldirset_clear(icalset* set) { assert(0); @@ -616,53 +649,58 @@ void icaldirset_clear(icaldirset* store) /* HACK, not implemented */ } -icalcomponent* icaldirset_get_current_component(icaldirset* store) +icalcomponent* icaldirset_get_current_component(icalset* set) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; + icaldirset *dset = (icaldirset*)set; - if(impl->cluster == 0){ - icaldirset_get_first_component(store); + if (dset->cluster == 0){ + icaldirset_get_first_component(set); + } + if(dset->cluster == 0){ + return 0; } - return icalfileset_get_current_component(impl->cluster); - + return icalcluster_get_current_component(dset->cluster); } -icalcomponent* icaldirset_get_first_component(icaldirset* store) +icalcomponent* icaldirset_get_first_component(icalset* set) { - struct icaldirset_impl *impl = (struct icaldirset_impl*)store; + icaldirset *dset = (icaldirset*)set; + icalerrorenum error; char path[ICAL_PATH_MAX]; - error = icaldirset_read_directory(impl); + error = icaldirset_read_directory(dset); if (error != ICAL_NO_ERROR){ icalerror_set_errno(error); return 0; } - impl->directory_iterator = pvl_head(impl->directory); + dset->directory_iterator = pvl_head(dset->directory); - if (impl->directory_iterator == 0){ + if (dset->directory_iterator == 0){ icalerror_set_errno(error); return 0; } - snprintf(path,ICAL_PATH_MAX,"%s/%s",impl->dir,(char*)pvl_data(impl->directory_iterator)); + snprintf(path,ICAL_PATH_MAX,"%s/%s", + dset->dir, + (char*)pvl_data(dset->directory_iterator)); /* If the next cluster we need is different than the current cluster, delete the current one and get a new one */ - if(impl->cluster != 0 && strcmp(path,icalfileset_path(impl->cluster)) != 0 ){ - icalfileset_free(impl->cluster); - impl->cluster = 0; + if(dset->cluster != 0 && strcmp(path,icalcluster_key(dset->cluster)) != 0 ){ + icalcluster_free(dset->cluster); + dset->cluster = 0; } - if (impl->cluster == 0){ - impl->cluster = icalfileset_new(path); + if (dset->cluster == 0){ + dset->cluster = icalfileset_produce_icalcluster(path); - if (impl->cluster == 0){ + if (dset->cluster == 0){ error = icalerrno; } } @@ -672,23 +710,22 @@ icalcomponent* icaldirset_get_first_component(icaldirset* store) return 0; } - impl->first_component = 1; + dset->first_component = 1; - return icaldirset_get_next_component(store); + return icaldirset_get_next_component(set); } -icalcomponent* icaldirset_get_next_component(icaldirset* store) + +icalcomponent* icaldirset_get_next_component(icalset* set) { - struct icaldirset_impl *impl; + icaldirset *dset = (icaldirset*)set; icalcomponent *c; icalerrorenum error; - icalerror_check_arg_rz( (store!=0), "store"); - - impl = (struct icaldirset_impl*)store; + icalerror_check_arg_rz( (set!=0), "set"); - if(impl->cluster == 0){ + if(dset->cluster == 0){ icalerror_warn("icaldirset_get_next_component called with a NULL cluster (Caller must call icaldirset_get_first_component first"); icalerror_set_errno(ICAL_USAGE_ERROR); return 0; @@ -696,30 +733,26 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store) } /* Set the component iterator for the following for loop */ - if (impl->first_component == 1){ - icalfileset_get_first_component(impl->cluster); - impl->first_component = 0; + if (dset->first_component == 1){ + icalcluster_get_first_component(dset->cluster); + dset->first_component = 0; } else { - icalfileset_get_next_component(impl->cluster); + icalcluster_get_next_component(dset->cluster); } - while(1){ /* Iterate through all of the objects in the cluster*/ - for( c = icalfileset_get_current_component(impl->cluster); + for( c = icalcluster_get_current_component(dset->cluster); c != 0; - c = icalfileset_get_next_component(impl->cluster)){ + c = icalcluster_get_next_component(dset->cluster)){ /* If there is a gauge defined and the component does not pass the gauge, skip the rest of the loop */ -#if 0 /* HACK */ - if (impl->gauge != 0 && icalgauge_test(c,impl->gauge) == 0){ + if (dset->gauge != 0 && icalgauge_compare(dset->gauge,c) == 0){ continue; } -#else - assert(0); /* icalgauge_test needs to be fixed */ -#endif + /* Either there is no gauge, or the component passed the gauge, so return it*/ @@ -729,13 +762,13 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store) /* Fell through the loop, so the component we want is not in this cluster. Load a new cluster and try again.*/ - error = icaldirset_next_cluster(store); + error = icaldirset_next_cluster(dset); - if(impl->cluster == 0 || error != ICAL_NO_ERROR){ + if(dset->cluster == 0 || error != ICAL_NO_ERROR){ /* No more clusters */ return 0; } else { - c = icalfileset_get_first_component(impl->cluster); + c = icalcluster_get_first_component(dset->cluster); return c; } @@ -745,9 +778,28 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store) return 0; /* Should never get here */ } - +icalsetiter icaldirset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge) +{ + icalsetiter itr = icalsetiter_null; + icaldirset *fset = (icaldirset*) set; + + icalerror_check_arg_re((fset!=0), "set", icalsetiter_null); + itr.iter.kind = kind; + itr.gauge = gauge; + /* TO BE IMPLEMENTED */ + return icalsetiter_null; +} +icalcomponent* icaldirsetiter_to_next(icalset* set, icalsetiter* i) +{ + /* TO BE IMPLEMENTED */ + return NULL; +} - +icalcomponent* icaldirsetiter_to_prior(icalset* set, icalsetiter* i) +{ + /* TO BE IMPLEMENTED */ + return NULL; +} diff --git a/libical/src/libicalss/icaldirset.h b/libical/src/libicalss/icaldirset.h index 7d205ecf0a..a2d577dc34 100644 --- a/libical/src/libicalss/icaldirset.h +++ b/libical/src/libicalss/icaldirset.h @@ -30,51 +30,67 @@ #define ICALDIRSET_H #include "ical.h" +#include "icalset.h" +#include "icalcluster.h" +#include "icalgauge.h" /* icaldirset Routines for storing, fetching, and searching for ical * objects in a database */ -typedef void icaldirset; +typedef struct icaldirset_impl icaldirset; +icalset* icaldirset_new(const char* path); -icaldirset* icaldirset_new(const char* path); +icalset* icaldirset_new_reader(const char* path); +icalset* icaldirset_new_writer(const char* path); -void icaldirset_free(icaldirset* store); -const char* icaldirset_path(icaldirset* store); +icalset* icaldirset_init(icalset* set, const char *dsn, void *options); +void icaldirset_free(icalset* set); + +const char* icaldirset_path(icalset* set); /* Mark the cluster as changed, so it will be written to disk when it is freed. Commit writes to disk immediately*/ -void icaldirset_mark(icaldirset* store); -icalerrorenum icaldirset_commit(icaldirset* store); +void icaldirset_mark(icalset* set); +icalerrorenum icaldirset_commit(icalset* set); -icalerrorenum icaldirset_add_component(icaldirset* store, icalcomponent* comp); -icalerrorenum icaldirset_remove_component(icaldirset* store, icalcomponent* comp); +icalerrorenum icaldirset_add_component(icalset* store, icalcomponent* comp); +icalerrorenum icaldirset_remove_component(icalset* store, icalcomponent* comp); -int icaldirset_count_components(icaldirset* store, +int icaldirset_count_components(icalset* store, icalcomponent_kind kind); /* Restrict the component returned by icaldirset_first, _next to those that pass the gauge. _clear removes the gauge. */ -icalerrorenum icaldirset_select(icaldirset* store, icalcomponent* gauge); -void icaldirset_clear(icaldirset* store); +icalerrorenum icaldirset_select(icalset* store, icalgauge* gauge); +void icaldirset_clear(icalset* store); /* Get a component by uid */ -icalcomponent* icaldirset_fetch(icaldirset* store, const char* uid); -int icaldirset_has_uid(icaldirset* store, const char* uid); -icalcomponent* icaldirset_fetch_match(icaldirset* set, icalcomponent *c); +icalcomponent* icaldirset_fetch(icalset* store, const char* uid); +int icaldirset_has_uid(icalset* store, const char* uid); +icalcomponent* icaldirset_fetch_match(icalset* set, icalcomponent *c); /* Modify components according to the MODIFY method of CAP. Works on the currently selected components. */ -icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *oldc, +icalerrorenum icaldirset_modify(icalset* store, icalcomponent *oldc, icalcomponent *newc); -/* Iterate through the components. If a guage has been defined, these +/* Iterate through the components. If a gauge has been defined, these will skip over components that do not pass the gauge */ -icalcomponent* icaldirset_get_current_component(icaldirset* store); -icalcomponent* icaldirset_get_first_component(icaldirset* store); -icalcomponent* icaldirset_get_next_component(icaldirset* store); +icalcomponent* icaldirset_get_current_component(icalset* store); +icalcomponent* icaldirset_get_first_component(icalset* store); +icalcomponent* icaldirset_get_next_component(icalset* store); + +/* External iterator for thread safety */ +icalsetiter icaldirset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge); +icalcomponent* icaldirsetiter_to_next(icalset* set, icalsetiter* i); +icalcomponent* icaldirsetiter_to_prior(icalset* set, icalsetiter* i); + +typedef struct icaldirset_options { + int flags; /**< flags corresponding to the open() system call O_RDWR, etc. */ +} icaldirset_options; #endif /* !ICALDIRSET_H */ diff --git a/libical/src/libicalss/icaldirsetimpl.h b/libical/src/libicalss/icaldirsetimpl.h index 0e69ba2f2e..332a369b02 100644 --- a/libical/src/libicalss/icaldirsetimpl.h +++ b/libical/src/libicalss/icaldirsetimpl.h @@ -30,18 +30,19 @@ #include "config.h" #endif +#include "icalcluster.h" + /* This definition is in its own file so it can be kept out of the main header file, but used by "friend classes" like icalset*/ -#define ICALDIRSET_ID "dset" - struct icaldirset_impl { - char id[5]; /* "dset" */ - char* dir; - icalcomponent* gauge; - icaldirset* cluster; - int first_component; - pvl_list directory; - pvl_elem directory_iterator; + icalset super; /**< parent class */ + char* dir; /**< directory containing ics files */ + icaldirset_options options; /**< copy of options passed to icalset_new() */ + icalcluster* cluster; /**< cluster containing data */ + icalgauge* gauge; /**< gauge for filtering out data */ + int first_component; /**< ??? */ + pvl_list directory; /**< ??? */ + pvl_elem directory_iterator; /**< ??? */ }; diff --git a/libical/src/libicalss/icalfileset.c b/libical/src/libicalss/icalfileset.c index b6e3430f7d..389cec7587 100644 --- a/libical/src/libicalss/icalfileset.c +++ b/libical/src/libicalss/icalfileset.c @@ -34,98 +34,151 @@ #include "icalgauge.h" #include <errno.h> #include <sys/stat.h> /* for stat */ +#ifndef WIN32 #include <unistd.h> /* for stat, getpid */ +#else +#include <io.h> +#include <share.h> +#endif #include <stdlib.h> #include <string.h> #include <fcntl.h> /* for fcntl */ -#include <unistd.h> /* for fcntl */ #include "icalfilesetimpl.h" +#include "icalclusterimpl.h" + +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp + +#define _S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask)) + +#define S_ISDIR(mode) _S_ISTYPE((mode), _S_IFDIR) +#define S_ISREG(mode) _S_ISTYPE((mode), _S_IFREG) +#endif extern int errno; -int icalfileset_lock(icalfileset *cluster); -int icalfileset_unlock(icalfileset *cluster); -icalerrorenum icalfileset_read_file(icalfileset* cluster, mode_t mode); -int icalfileset_filesize(icalfileset* cluster); +/** Default options used when NULL is passed to icalset_new() **/ +icalfileset_options icalfileset_options_default = {O_RDWR|O_CREAT, 0644, 0}; + +int icalfileset_lock(icalfileset *set); +int icalfileset_unlock(icalfileset *set); +icalerrorenum icalfileset_read_file(icalfileset* set, mode_t mode); +int icalfileset_filesize(icalfileset* set); icalerrorenum icalfileset_create_cluster(const char *path); -icalfileset* icalfileset_new_impl() +icalset* icalfileset_new(const char* path) { - struct icalfileset_impl* impl; - - if ( ( impl = (struct icalfileset_impl*) - malloc(sizeof(struct icalfileset_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - errno = ENOMEM; - return 0; - } - - memset(impl,0,sizeof(struct icalfileset_impl)); - - strcpy(impl->id,ICALFILESET_ID); - - return impl; + return icalset_new(ICAL_FILE_SET, path, &icalfileset_options_default); } - -icalfileset* icalfileset_new(const char* path) +icalset* icalfileset_new_reader(const char* path) { - return icalfileset_new_open(path, O_RDWR|O_CREAT, 0664); + icalfileset_options reader_options = icalfileset_options_default; + reader_options.flags = O_RDONLY; + + return icalset_new(ICAL_FILE_SET, path, &reader_options); } -icalfileset* icalfileset_new_open(const char* path, int flags, mode_t mode) +icalset* icalfileset_new_writer(const char* path) { - struct icalfileset_impl *impl = icalfileset_new_impl(); - struct icaltimetype tt; - off_t cluster_file_size; + icalfileset_options writer_options = icalfileset_options_default; + writer_options.flags = O_RDONLY; - memset(&tt,0,sizeof(struct icaltimetype)); + return icalset_new(ICAL_FILE_SET, path, &writer_options); +} - icalerror_clear_errno(); - icalerror_check_arg_rz( (path!=0), "path"); +icalset* icalfileset_init(icalset *set, const char* path, void* options_in) +{ + icalfileset_options *options = (options_in) ? options_in : &icalfileset_options_default; + icalfileset *fset = (icalfileset*) set; + int flags; + mode_t mode; + off_t cluster_file_size; - if (impl == 0){ - return 0; - } + icalerror_clear_errno(); + icalerror_check_arg_rz( (path!=0), "path"); + icalerror_check_arg_rz( (fset!=0), "fset"); - impl->path = strdup(path); + fset->path = strdup(path); + fset->options = *options; - cluster_file_size = icalfileset_filesize(impl); - - if(cluster_file_size < 0){ - icalfileset_free(impl); - return 0; - } + flags = options->flags; + mode = options->mode; + + cluster_file_size = icalfileset_filesize(fset); + + if(cluster_file_size < 0){ + icalfileset_free(set); + return 0; + } - impl->fd = open(impl->path,flags, mode); +#ifndef WIN32 + fset->fd = open(fset->path, flags, mode); +#else + fset->fd = open(fset->path, flags, mode); + /* fset->fd = sopen(fset->path,flags, _SH_DENYWR, _S_IREAD | _S_IWRITE); */ +#endif - if (impl->fd < 0){ - icalerror_set_errno(ICAL_FILE_ERROR); - icalfileset_free(impl); - return 0; - } + if (fset->fd < 0){ + icalerror_set_errno(ICAL_FILE_ERROR); + icalfileset_free(set); + return 0; + } - icalfileset_lock(impl); +#ifndef WIN32 + icalfileset_lock(fset); +#endif if(cluster_file_size > 0 ){ icalerrorenum error; - if((error = icalfileset_read_file(impl,mode))!= ICAL_NO_ERROR){ - icalfileset_free(impl); - return 0; + if((error = icalfileset_read_file(fset,mode))!= ICAL_NO_ERROR){ + icalfileset_free(set); + return 0; } } - if(impl->cluster == 0){ - impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); - } + if (options->cluster) { + fset->cluster = icalcomponent_new_clone(icalcluster_get_component(options->cluster)); + fset->changed = 1; + } + + if (fset->cluster == 0) { + fset->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); + } + + return set; +} + + +icalcluster* icalfileset_produce_icalcluster(const char *path) { + icalset *fileset; + icalcluster *ret; + + int errstate = icalerror_errors_are_fatal; + icalerror_errors_are_fatal = 0; - return impl; + fileset = icalfileset_new_reader(path); + + + if (fileset == 0 && icalerrno == ICAL_FILE_ERROR) { + /* file does not exist */ + ret = icalcluster_new(path, NULL); + } else { + ret = icalcluster_new(path, ((icalfileset*)fileset)->cluster); + icalfileset_free(fileset); + } + + icalerror_errors_are_fatal = errstate; + icalerror_set_errno(ICAL_NO_ERROR); + return ret; } + + char* icalfileset_read_from_file(char *s, size_t size, void *d) { - char* p = s; int fd = (int)d; @@ -150,42 +203,38 @@ char* icalfileset_read_from_file(char *s, size_t size, void *d) } -icalerrorenum icalfileset_read_file(icalfileset* cluster,mode_t mode) +icalerrorenum icalfileset_read_file(icalfileset* set,mode_t mode) { - icalparser *parser; - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - parser = icalparser_new(); - icalparser_set_gen_data(parser,(void*)impl->fd); - impl->cluster = icalparser_parse(parser,icalfileset_read_from_file); + + icalparser_set_gen_data(parser,(void*)set->fd); + set->cluster = icalparser_parse(parser,icalfileset_read_from_file); icalparser_free(parser); - if (impl->cluster == 0 || icalerrno != ICAL_NO_ERROR){ + if (set->cluster == 0 || icalerrno != ICAL_NO_ERROR){ icalerror_set_errno(ICAL_PARSE_ERROR); - return ICAL_PARSE_ERROR; + /*return ICAL_PARSE_ERROR;*/ } - if (icalcomponent_isa(impl->cluster) != ICAL_XROOT_COMPONENT){ + if (icalcomponent_isa(set->cluster) != ICAL_XROOT_COMPONENT){ /* The parser got a single component, so it did not put it in an XROOT. */ - icalcomponent *cl = impl->cluster; - impl->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); - icalcomponent_add_component(impl->cluster,cl); + icalcomponent *cl = set->cluster; + set->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT); + icalcomponent_add_component(set->cluster,cl); } return ICAL_NO_ERROR; - } -int icalfileset_filesize(icalfileset* cluster) +int icalfileset_filesize(icalfileset* fset) { - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; int cluster_file_size; struct stat sbuf; - - if (stat(impl->path,&sbuf) != 0){ + + if (stat(fset->path,&sbuf) != 0){ /* A file by the given name does not exist, or there was another error */ @@ -214,120 +263,110 @@ int icalfileset_filesize(icalfileset* cluster) /*return -1; not reached*/ } -void icalfileset_free(icalfileset* cluster) +void icalfileset_free(icalset* set) { - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_rv((cluster!=0),"cluster"); + icalerror_check_arg_rv((set!=0),"set"); - if (impl->cluster != 0){ - icalfileset_commit(cluster); - icalcomponent_free(impl->cluster); - impl->cluster=0; + if (fset->cluster != 0){ + icalfileset_commit(set); + icalcomponent_free(fset->cluster); + fset->cluster=0; } - if(impl->fd > 0){ - icalfileset_unlock(impl); - close(impl->fd); - impl->fd = -1; + if (fset->gauge != 0){ + icalgauge_free(fset->gauge); + fset->gauge=0; } - if(impl->path != 0){ - free(impl->path); - impl->path = 0; + if(fset->fd > 0){ + icalfileset_unlock(fset); + close(fset->fd); + fset->fd = -1; } - free(impl); + if(fset->path != 0){ + free(fset->path); + fset->path = 0; + } } -const char* icalfileset_path(icalfileset* cluster) -{ - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - icalerror_check_arg_rz((cluster!=0),"cluster"); +const char* icalfileset_path(icalset* set) { + icalerror_check_arg_rz((set!=0),"set"); - return impl->path; + return ((icalfileset*)set)->path; } -int icalfileset_lock(icalfileset *cluster) +int icalfileset_lock(icalfileset *set) { - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; +#ifndef WIN32 struct flock lock; int rtrn; - icalerror_check_arg_rz((impl->fd>0),"impl->fd"); + icalerror_check_arg_rz((set->fd>0),"set->fd"); errno = 0; lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_start = 0; /* byte offset relative to l_whence */ lock.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_len = 0; /* #bytes (0 means to EOF) */ - rtrn = fcntl(impl->fd, F_SETLKW, &lock); + rtrn = fcntl(set->fd, F_SETLKW, &lock); return rtrn; +#else + return 0; +#endif } -int icalfileset_unlock(icalfileset *cluster) +int icalfileset_unlock(icalfileset *set) { - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; +#ifndef WIN32 struct flock lock; - icalerror_check_arg_rz((impl->fd>0),"impl->fd"); + icalerror_check_arg_rz((set->fd>0),"set->fd"); lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_start = 0; /* byte offset relative to l_whence */ lock.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_len = 0; /* #bytes (0 means to EOF) */ - return (fcntl(impl->fd, F_UNLCK, &lock)); - -} - -#ifdef ICAL_SAFESAVES -int icalfileset_safe_saves=1; + return (fcntl(set->fd, F_UNLCK, &lock)); #else -int icalfileset_safe_saves=0; + return 0; #endif +} -icalerrorenum icalfileset_commit(icalfileset* cluster) +icalerrorenum icalfileset_commit(icalset* set) { char tmp[ICAL_PATH_MAX]; char *str; icalcomponent *c; off_t write_size=0; + icalfileset *fset = (icalfileset*) set; + + icalerror_check_arg_re((fset!=0),"set",ICAL_BADARG_ERROR); - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - - icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); - - icalerror_check_arg_re((impl->fd>0),"impl->fd is invalid", + icalerror_check_arg_re((fset->fd>0),"set->fd is invalid", ICAL_INTERNAL_ERROR) ; - if (impl->changed == 0 ){ + if (fset->changed == 0 ){ return ICAL_NO_ERROR; } - if(icalfileset_safe_saves == 1){ - snprintf(tmp,ICAL_PATH_MAX,"cp %s %s.bak",impl->path,impl->path); - - if(system(tmp) < 0){ - icalerror_set_errno(ICAL_FILE_ERROR); - return ICAL_FILE_ERROR; - } - } - - if(lseek(impl->fd,SEEK_SET,0) < 0){ + if(lseek(fset->fd, 0, SEEK_SET) < 0){ icalerror_set_errno(ICAL_FILE_ERROR); return ICAL_FILE_ERROR; } - for(c = icalcomponent_get_first_component(impl->cluster,ICAL_ANY_COMPONENT); + for(c = icalcomponent_get_first_component(fset->cluster,ICAL_ANY_COMPONENT); c != 0; - c = icalcomponent_get_next_component(impl->cluster,ICAL_ANY_COMPONENT)){ + c = icalcomponent_get_next_component(fset->cluster,ICAL_ANY_COMPONENT)){ int sz; str = icalcomponent_as_ical_string(c); - sz=write(impl->fd,str,strlen(str)); + sz=write(fset->fd,str,strlen(str)); if ( sz != strlen(str)){ perror("write"); @@ -338,132 +377,138 @@ icalerrorenum icalfileset_commit(icalfileset* cluster) write_size += sz; } - impl->changed = 0; + fset->changed = 0; - if(ftruncate(impl->fd,write_size) < 0){ +#ifndef WIN32 + if(ftruncate(fset->fd,write_size) < 0){ return ICAL_FILE_ERROR; } +#else + chsize( fset->fd, tell( fset->fd ) ); +#endif return ICAL_NO_ERROR; - } -void icalfileset_mark(icalfileset* cluster){ - - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; - - icalerror_check_arg_rv((impl!=0),"cluster"); - - impl->changed = 1; +void icalfileset_mark(icalset* set) { + icalerror_check_arg_rv((set!=0),"set"); + ((icalfileset*)set)->changed = 1; } -icalcomponent* icalfileset_get_component(icalfileset* cluster){ - struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster; +icalcomponent* icalfileset_get_component(icalset* set){ + icalfileset *fset = (icalfileset*) set; + icalerror_check_arg_rz((set!=0),"set"); - icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR); - - return impl->cluster; + return fset->cluster; } -/* manipulate the components in the cluster */ +/* manipulate the components in the set */ -icalerrorenum icalfileset_add_component(icalfileset *cluster, +icalerrorenum icalfileset_add_component(icalset *set, icalcomponent* child) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_re((cluster!=0),"cluster", ICAL_BADARG_ERROR); + icalerror_check_arg_re((set!=0),"set", ICAL_BADARG_ERROR); icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); - icalcomponent_add_component(impl->cluster,child); + icalcomponent_add_component(fset->cluster,child); - icalfileset_mark(cluster); + icalfileset_mark(set); return ICAL_NO_ERROR; - } -icalerrorenum icalfileset_remove_component(icalfileset *cluster, +icalerrorenum icalfileset_remove_component(icalset *set, icalcomponent* child) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_re((cluster!=0),"cluster",ICAL_BADARG_ERROR); + icalerror_check_arg_re((set!=0),"set",ICAL_BADARG_ERROR); icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR); - icalcomponent_remove_component(impl->cluster,child); + icalcomponent_remove_component(fset->cluster,child); - icalfileset_mark(cluster); + icalfileset_mark(set); return ICAL_NO_ERROR; } -int icalfileset_count_components(icalfileset *cluster, +int icalfileset_count_components(icalset *set, icalcomponent_kind kind) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; - if(cluster == 0){ + if (set == 0){ icalerror_set_errno(ICAL_BADARG_ERROR); return -1; } - return icalcomponent_count_components(impl->cluster,kind); + return icalcomponent_count_components(fset->cluster,kind); } -icalerrorenum icalfileset_select(icalfileset* set, icalgauge* gauge) +icalerrorenum icalfileset_select(icalset* set, icalgauge* gauge) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)set; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_re(gauge!=0,"guage",ICAL_BADARG_ERROR); + icalerror_check_arg_re(gauge!=0,"gauge",ICAL_BADARG_ERROR); - impl->gauge = gauge; + fset->gauge = gauge; return ICAL_NO_ERROR; } -void icalfileset_clear(icalfileset* gauge) +void icalfileset_clear(icalset* set) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)gauge; - - impl->gauge = 0; + icalfileset *fset = (icalfileset*) set; + + icalerror_check_arg_rv(set!=0,"set"); + fset->gauge = 0; } -icalcomponent* icalfileset_fetch(icalfileset* store,const char* uid) +icalcomponent* icalfileset_fetch(icalset* set,const char* uid) { + icalfileset *fset = (icalfileset*) set; icalcompiter i; - struct icalfileset_impl* impl = (struct icalfileset_impl*)store; + + icalerror_check_arg_rz(set!=0,"set"); - for(i = icalcomponent_begin_component(impl->cluster,ICAL_ANY_COMPONENT); + for(i = icalcomponent_begin_component(fset->cluster,ICAL_ANY_COMPONENT); icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ - icalcomponent *this = icalcompiter_deref(&i); - icalcomponent *inner = icalcomponent_get_first_real_component(this); - icalcomponent *p; - const char *this_uid; - - if(inner != 0){ - p = icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY); - this_uid = icalproperty_get_uid(p); - - if(this_uid==0){ - icalerror_warn("icalfileset_fetch found a component with no UID"); - continue; - } - - if (strcmp(uid,this_uid)==0){ - return this; - } + icalcomponent *this = icalcompiter_deref(&i); + icalcomponent *inner; + icalproperty *p; + const char *this_uid; + + for(inner = icalcomponent_get_first_component(this,ICAL_ANY_COMPONENT); + inner != 0; + inner = icalcomponent_get_next_component(this,ICAL_ANY_COMPONENT)){ + + p = icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY); + if ( p ) + { + this_uid = icalproperty_get_uid(p); + + if(this_uid==0){ + icalerror_warn("icalfileset_fetch found a component with no UID"); + continue; + } + + if (strcmp(uid,this_uid)==0){ + return this; + } + } + } } - } return 0; } -int icalfileset_has_uid(icalfileset* store,const char* uid) +int icalfileset_has_uid(icalset* set,const char* uid) { assert(0); /* HACK, not implemented */ return 0; @@ -486,12 +531,11 @@ void icalfileset_id_free(struct icalfileset_id *id) if(id->uid != 0){ free(id->uid); } - } + struct icalfileset_id icalfileset_get_id(icalcomponent* comp) { - icalcomponent *inner; struct icalfileset_id id; icalproperty *p; @@ -527,19 +571,20 @@ struct icalfileset_id icalfileset_get_id(icalcomponent* comp) return id; } + /* Find the component that is related to the given component. Currently, it just matches based on UID and RECURRENCE-ID */ -icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *comp) +icalcomponent* icalfileset_fetch_match(icalset* set, icalcomponent *comp) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)set; + icalfileset *fset = (icalfileset*) set; icalcompiter i; struct icalfileset_id comp_id, match_id; comp_id = icalfileset_get_id(comp); - for(i = icalcomponent_begin_component(impl->cluster,ICAL_ANY_COMPONENT); + for(i = icalcomponent_begin_component(fset->cluster,ICAL_ANY_COMPONENT); icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ icalcomponent *match = icalcompiter_deref(&i); @@ -567,43 +612,45 @@ icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *comp) } -icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *old, +icalerrorenum icalfileset_modify(icalset* set, icalcomponent *old, icalcomponent *new) { + icalfileset *fset = (icalfileset*) set; + assert(0); /* HACK, not implemented */ return ICAL_NO_ERROR; } /* Iterate through components */ -icalcomponent* icalfileset_get_current_component (icalfileset* cluster) +icalcomponent* icalfileset_get_current_component (icalset* set) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_rz((cluster!=0),"cluster"); + icalerror_check_arg_rz((set!=0),"set"); - return icalcomponent_get_current_component(impl->cluster); + return icalcomponent_get_current_component(fset->cluster); } -icalcomponent* icalfileset_get_first_component(icalfileset* cluster) +icalcomponent* icalfileset_get_first_component(icalset* set) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; icalcomponent *c=0; + icalfileset *fset = (icalfileset*) set; - icalerror_check_arg_rz((cluster!=0),"cluster"); + icalerror_check_arg_rz((set!=0),"set"); do { if (c == 0){ - c = icalcomponent_get_first_component(impl->cluster, + c = icalcomponent_get_first_component(fset->cluster, ICAL_ANY_COMPONENT); } else { - c = icalcomponent_get_next_component(impl->cluster, + c = icalcomponent_get_next_component(fset->cluster, ICAL_ANY_COMPONENT); } - if(c != 0 && (impl->gauge == 0 || - icalgauge_compare(impl->gauge,c) == 1)){ + if(c != 0 && (fset->gauge == 0 || + icalgauge_compare(fset->gauge, c) == 1)){ return c; } @@ -613,19 +660,19 @@ icalcomponent* icalfileset_get_first_component(icalfileset* cluster) return 0; } -icalcomponent* icalfileset_get_next_component(icalfileset* cluster) +icalcomponent* icalfileset_get_next_component(icalset* set) { - struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster; + icalfileset *fset = (icalfileset*) set; icalcomponent *c; - icalerror_check_arg_rz((cluster!=0),"cluster"); + icalerror_check_arg_rz((set!=0),"set"); do { - c = icalcomponent_get_next_component(impl->cluster, + c = icalcomponent_get_next_component(fset->cluster, ICAL_ANY_COMPONENT); - if(c != 0 && (impl->gauge == 0 || - icalgauge_compare(impl->gauge,c) == 1)){ + if(c != 0 && (fset->gauge == 0 || + icalgauge_compare(fset->gauge,c) == 1)){ return c; } @@ -634,4 +681,241 @@ icalcomponent* icalfileset_get_next_component(icalfileset* cluster) return 0; } +/* +icalsetiter icalfileset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge) +{ + icalsetiter itr = icalsetiter_null; + icalcomponent* comp = NULL; + icalcompiter citr; + icalfileset *fset = (icalfileset*) set; + + icalerror_check_arg_re((set!=0), "set", icalsetiter_null); + + itr.gauge = gauge; + + citr = icalcomponent_begin_component(fset->cluster, kind); + comp = icalcompiter_deref(&citr); + + while (comp != 0) { + comp = icalcompiter_deref(&citr); + if (gauge == 0 || icalgauge_compare(itr.gauge, comp) == 1) { + itr.iter = citr; + return itr; + } + comp = icalcompiter_next(&citr); + } + + return icalsetiter_null; +} +*/ + +icalsetiter icalfileset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge) +{ + icalsetiter itr = icalsetiter_null; + icalcomponent* comp = NULL; + icalcompiter citr; + icalfileset *fset = (icalfileset*) set; + struct icaltimetype start, next; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + int g = 0; + icalerror_check_arg_re((set!=0), "set", icalsetiter_null); + + itr.gauge = gauge; + + citr = icalcomponent_begin_component(fset->cluster, kind); + comp = icalcompiter_deref(&citr); + + if (gauge == 0) { + itr.iter = citr; + return itr; + } + + while (comp != 0) { + + /* check if it is a recurring component and with guage expand, if so + we need to add recurrence-id property to the given component */ + rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + g = icalgauge_get_expand(gauge); + + if (rrule != 0 + && g == 1) { + + recur = icalproperty_get_rrule(rrule); + if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + if (itr.last_component == NULL) { + itr.ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(itr.ritr); + itr.last_component = comp; + } + else { + next = icalrecur_iterator_next(itr.ritr); + if (icaltime_is_null_time(next)){ + itr.last_component = NULL; + icalrecur_iterator_free(itr.ritr); + itr.ritr = NULL; + return icalsetiter_null; + } else { + itr.last_component = comp; + } + } + + /* add recurrence-id to the component + if there is a recurrence-id already, remove it, then add the new one */ + if (prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY)) + icalcomponent_remove_property(comp, prop); + icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next)); + + } + + if (gauge == 0 || icalgauge_compare(itr.gauge, comp) == 1) { + /* matches and returns */ + itr.iter = citr; + return itr; + } + + /* if there is no previous component pending, then get the next component */ + if (itr.last_component == NULL) + comp = icalcompiter_next(&citr); + } + + return icalsetiter_null; +} +icalcomponent* icalfileset_form_a_matched_recurrence_component(icalsetiter* itr) +{ + icalcomponent* comp = NULL; + struct icaltimetype start, next; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + + comp = itr->last_component; + + if (comp == NULL || itr->gauge == NULL) { + return NULL; + } + + rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY); + + recur = icalproperty_get_rrule(rrule); + + if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + if (itr->ritr == NULL) { + itr->ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(itr->ritr); + itr->last_component = comp; + } else { + next = icalrecur_iterator_next(itr->ritr); + if (icaltime_is_null_time(next)){ + /* no more recurrence, returns */ + itr->last_component = NULL; + icalrecur_iterator_free(itr->ritr); + itr->ritr = NULL; + return NULL; + } else { + itr->last_component = comp; + } + } + + /* add recurrence-id to the component + * if there is a recurrence-id already, remove it, then add the new one */ + if (prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY)) + icalcomponent_remove_property(comp, prop); + icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next)); + + if (itr->gauge == 0 || icalgauge_compare(itr->gauge, comp) == 1) { + /* matches and returns */ + return comp; + } + /* not matched */ + return NULL; + +} +icalcomponent* icalfilesetiter_to_next(icalset* set, icalsetiter* i) +{ + + icalcomponent* c = NULL; + icalfileset *fset = (icalfileset*) set; + struct icaltimetype start, next; + icalproperty *dtstart, *rrule, *prop, *due; + struct icalrecurrencetype recur; + int g = 0; + + + do { + c = icalcompiter_next(&(i->iter)); + + if (c == 0) continue; + if (i->gauge == 0) return c; + + + rrule = icalcomponent_get_first_property(c, ICAL_RRULE_PROPERTY); + g = icalgauge_get_expand(i->gauge); + + /* a recurring component with expand query */ + if (rrule != 0 + && g == 1) { + + recur = icalproperty_get_rrule(rrule); + + if (icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT) { + dtstart = icalcomponent_get_first_property(c, ICAL_DTSTART_PROPERTY); + if (dtstart) + start = icalproperty_get_dtstart(dtstart); + } else if (icalcomponent_isa(c) == ICAL_VTODO_COMPONENT) { + due = icalcomponent_get_first_property(c, ICAL_DUE_PROPERTY); + if (due) + start = icalproperty_get_due(due); + } + + if (i->ritr == NULL) { + i->ritr = icalrecur_iterator_new(recur, start); + next = icalrecur_iterator_next(i->ritr); + i->last_component = c; + } else { + next = icalrecur_iterator_next(i->ritr); + if (icaltime_is_null_time(next)) { + /* no more recurrence, returns */ + i->last_component = NULL; + icalrecur_iterator_free(i->ritr); + i->ritr = NULL; + return NULL; + } else { + i->last_component = c; + } + } + } + + /* add recurrence-id to the component + * if there is a recurrence-id already, remove it, then add the new one */ + if (prop = icalcomponent_get_first_property(c, ICAL_RECURRENCEID_PROPERTY)) + icalcomponent_remove_property(c, prop); + icalcomponent_add_property(c, icalproperty_new_recurrenceid(next)); + + if(c != 0 && (i->gauge == 0 || + icalgauge_compare(i->gauge, c) == 1)){ + return c; + } + } while (c != 0); + + return 0; + +} diff --git a/libical/src/libicalss/icalfileset.h b/libical/src/libicalss/icalfileset.h index c785921463..1a42307525 100644 --- a/libical/src/libicalss/icalfileset.h +++ b/libical/src/libicalss/icalfileset.h @@ -31,73 +31,99 @@ #include "ical.h" #include "icalset.h" +#include "icalcluster.h" #include "icalgauge.h" #include <sys/types.h> /* For open() flags and mode */ #include <sys/stat.h> /* For open() flags and mode */ #include <fcntl.h> /* For open() flags and mode */ -extern int icalfileset_safe_saves; +#ifdef WIN32 +#define mode_t int +#endif -typedef void icalfileset; +typedef struct icalfileset_impl icalfileset; +icalset* icalfileset_new(const char* path); +icalset* icalfileset_new_reader(const char* path); +icalset* icalfileset_new_writer(const char* path); -/* icalfileset - icalfilesetfile - icalfilesetdir -*/ +icalset* icalfileset_init(icalset *set, const char *dsn, void* options); +icalfileset* icalfileset_new_from_cluster(const char* path, icalcluster *cluster); -icalfileset* icalfileset_new(const char* path); +icalcluster* icalfileset_produce_icalcluster(const char *path); -/* Like _new, but takes open() flags for opening the file */ -icalfileset* icalfileset_new_open(const char* path, - int flags, mode_t mode); +void icalfileset_free(icalset* cluster); -void icalfileset_free(icalfileset* cluster); - -const char* icalfileset_path(icalfileset* cluster); +const char* icalfileset_path(icalset* cluster); /* Mark the cluster as changed, so it will be written to disk when it is freed. Commit writes to disk immediately. */ -void icalfileset_mark(icalfileset* cluster); -icalerrorenum icalfileset_commit(icalfileset* cluster); +void icalfileset_mark(icalset* set); +icalerrorenum icalfileset_commit(icalset* set); -icalerrorenum icalfileset_add_component(icalfileset* cluster, +icalerrorenum icalfileset_add_component(icalset* set, icalcomponent* child); -icalerrorenum icalfileset_remove_component(icalfileset* cluster, +icalerrorenum icalfileset_remove_component(icalset* set, icalcomponent* child); -int icalfileset_count_components(icalfileset* cluster, +int icalfileset_count_components(icalset* set, icalcomponent_kind kind); -/* Restrict the component returned by icalfileset_first, _next to those - that pass the gauge. _clear removes the gauge */ -icalerrorenum icalfileset_select(icalfileset* store, icalgauge* gauge); -void icalfileset_clear(icalfileset* store); +/** + * Restrict the component returned by icalfileset_first, _next to those + * that pass the gauge. _clear removes the gauge + */ +icalerrorenum icalfileset_select(icalset* set, icalgauge* gauge); + +/** clear the gauge **/ +void icalfileset_clear(icalset* set); -/* Get and search for a component by uid */ -icalcomponent* icalfileset_fetch(icalfileset* cluster, const char* uid); -int icalfileset_has_uid(icalfileset* cluster, const char* uid); -icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *c); +/** Get and search for a component by uid **/ +icalcomponent* icalfileset_fetch(icalset* set, const char* uid); +int icalfileset_has_uid(icalset* set, const char* uid); +icalcomponent* icalfileset_fetch_match(icalset* set, icalcomponent *c); -/* Modify components according to the MODIFY method of CAP. Works on - the currently selected components. */ -icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *oldcomp, +/** + * Modify components according to the MODIFY method of CAP. Works on the + * currently selected components. + */ +icalerrorenum icalfileset_modify(icalset* set, + icalcomponent *oldcomp, icalcomponent *newcomp); -/* Iterate through components. If a guage has been defined, these +/* Iterate through components. If a gauge has been defined, these will skip over components that do not pass the gauge */ -icalcomponent* icalfileset_get_current_component (icalfileset* cluster); -icalcomponent* icalfileset_get_first_component(icalfileset* cluster); -icalcomponent* icalfileset_get_next_component(icalfileset* cluster); -/* Return a reference to the internal component. You probably should +icalcomponent* icalfileset_get_current_component (icalset* cluster); +icalcomponent* icalfileset_get_first_component(icalset* cluster); +icalcomponent* icalfileset_get_next_component(icalset* cluster); + +/* External iterator for thread safety */ +icalsetiter icalfileset_begin_component(icalset* set, icalcomponent_kind kind, icalgauge* gauge); +icalcomponent * icalfilesetiter_to_next(icalset* set, icalsetiter *iter); +icalcomponent* icalfileset_form_a_matched_recurrence_component(icalsetiter* itr); + +/** Return a reference to the internal component. You probably should not be using this. */ -icalcomponent* icalfileset_get_component(icalfileset* cluster); +icalcomponent* icalfileset_get_component(icalset* cluster); + +/** + * @brief options for opening an icalfileset. + * + * These options should be passed to the icalset_new() function + */ + +typedef struct icalfileset_options { + int flags; /**< flags for open() O_RDONLY, etc */ + mode_t mode; /**< file mode */ + icalcluster *cluster; /**< use this cluster to initialize data */ +} icalfileset_options; +extern icalfileset_options icalfileset_options_default; #endif /* !ICALFILESET_H */ diff --git a/libical/src/libicalss/icalfilesetimpl.h b/libical/src/libicalss/icalfilesetimpl.h index fcd3415121..fe39604225 100644 --- a/libical/src/libicalss/icalfilesetimpl.h +++ b/libical/src/libicalss/icalfilesetimpl.h @@ -25,6 +25,8 @@ ======================================================================*/ +#ifndef ICALFILESETIMPL_H +#define ICALFILESETIMPL_H #ifdef HAVE_CONFIG_H #include "config.h" @@ -38,12 +40,14 @@ #define ICALFILESET_ID "fset" struct icalfileset_impl { - - char id[5]; /*fset*/ - char *path; - icalcomponent* cluster; - icalgauge* gauge; - int changed; - int fd; /* file descriptor */ + icalset super; /**< parent class */ + char *path; /**< pathname of file */ + icalfileset_options options; /**< copy of options passed to icalset_new() */ + + icalcomponent* cluster; /**< cluster containing data */ + icalgauge* gauge; /**< gauge for filtering out data */ + int changed; /**< boolean flag, 1 if data has changed */ + int fd; /**< file descriptor */ }; +#endif diff --git a/libical/src/libicalss/icalgauge.c b/libical/src/libicalss/icalgauge.c index b958ecfc9d..f4854c747b 100644 --- a/libical/src/libicalss/icalgauge.c +++ b/libical/src/libicalss/icalgauge.c @@ -31,15 +31,17 @@ #include "icalgaugeimpl.h" #include <stdlib.h> -extern char* input_buffer; -extern char* input_buffer_p; -int ssparse(void); +#include "icalssyacc.h" -struct icalgauge_impl *icalss_yy_gauge; +typedef void* yyscan_t; -icalgauge* icalgauge_new_from_sql(char* sql) +int ssparse(yyscan_t ); + + +icalgauge* icalgauge_new_from_sql(char* sql, int expand) { struct icalgauge_impl *impl; + yyscan_t yy_globals = NULL; int r; @@ -52,60 +54,82 @@ icalgauge* icalgauge_new_from_sql(char* sql) impl->select = pvl_newlist(); impl->from = pvl_newlist(); impl->where = pvl_newlist(); + impl->expand = expand; + + sslex_init(&yy_globals); + + ssset_extra(impl, yy_globals); - icalss_yy_gauge = impl; + ss_scan_string(sql, yy_globals); - input_buffer_p = input_buffer = sql; - r = ssparse(); + r = ssparse(yy_globals); + sslex_destroy(yy_globals); - return impl; + if (r == 0) { + return impl; + } + else { + icalgauge_free(impl); + return NULL; + } } +int icalgauge_get_expand(icalgauge* gauge) +{ +return (gauge->expand); + +} void icalgauge_free(icalgauge* gauge) { - struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; struct icalgauge_where *w; - assert(impl->select != 0); - assert(impl->where != 0); - assert(impl->from != 0); + assert(gauge->select != 0); + assert(gauge->where != 0); + assert(gauge->from != 0); - if(impl->select){ - while( (w=pvl_pop(impl->select)) != 0){ + if(gauge->select){ + while( (w=pvl_pop(gauge->select)) != 0){ if(w->value != 0){ free(w->value); } free(w); } - pvl_free(impl->select); + pvl_free(gauge->select); + gauge->select = 0; } - if(impl->where){ - while( (w=pvl_pop(impl->where)) != 0){ + if(gauge->where){ + while( (w=pvl_pop(gauge->where)) != 0){ if(w->value != 0){ free(w->value); } free(w); } - pvl_free(impl->where); + pvl_free(gauge->where); + gauge->where = 0; } - if(impl->from){ - pvl_free(impl->from); + if(gauge->from){ + pvl_free(gauge->from); + gauge->from = 0; } + + free(gauge); } -/* Convert a VQUERY component into a gauge */ + +/** Convert a VQUERY component into a gauge */ icalcomponent* icalgauge_make_gauge(icalcomponent* query); -/* icaldirset_test compares a component against a gauge, and returns +/** + icaldirset_test compares a component against a gauge, and returns true if the component passes the test The gauge is a VCALENDAR component that specifies how to test the - target components. The guage holds a collection of VEVENT, VTODO or + target components. The gauge holds a collection of VEVENT, VTODO or VJOURNAL sub-components. Each of the sub-components has a collection of properties that are compared to corresponding properties in the target component, according to the @@ -252,26 +276,45 @@ int icalgauge_compare_recurse(icalcomponent* comp, icalcomponent* gauge) int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) { - struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; icalcomponent *inner; int local_pass = 0; int last_clause = 1, this_clause = 1; pvl_elem e; + icalcomponent_kind kind; + icalproperty *rrule; + int compare_recur = 0; + icalerror_check_arg_rz( (comp!=0), "comp"); icalerror_check_arg_rz( (gauge!=0), "gauge"); + if (gauge == 0 || comp == 0) return 0; + inner = icalcomponent_get_first_real_component(comp); if(inner == 0){ - icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); - return 0; + /* Wally Yau: our component is not always wrapped with + * a <VCALENDAR>. It's not an error. + * icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + * return 0; */ + kind = icalcomponent_isa(comp); + if(kind == ICAL_VEVENT_COMPONENT || + kind == ICAL_VTODO_COMPONENT || + kind == ICAL_VJOURNAL_COMPONENT || + kind == ICAL_VQUERY_COMPONENT || + kind == ICAL_VAGENDA_COMPONENT){ + inner = comp; + } + else { + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); + return 0; + } + inner = comp; } - /* Check that this component is one of the FROM types */ local_pass = 0; - for(e = pvl_head(impl->from);e!=0;e=pvl_next(e)){ + for(e = pvl_head(gauge->from);e!=0;e=pvl_next(e)){ icalcomponent_kind k = (icalcomponent_kind)pvl_data(e); if(k == icalcomponent_isa(inner)){ @@ -284,8 +327,8 @@ int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) } - /* Check each where clause against the component */ - for(e = pvl_head(impl->where);e!=0;e=pvl_next(e)){ + /**** Check each where clause against the component ****/ + for(e = pvl_head(gauge->where);e!=0;e=pvl_next(e)){ struct icalgauge_where *w = pvl_data(e); icalcomponent *sub_comp; icalvalue *v; @@ -301,11 +344,14 @@ int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) vk = icalenum_property_kind_to_value_kind(w->prop); if(vk == ICAL_NO_VALUE){ - icalerror_set_errno(ICAL_INTERNAL_ERROR); + icalerror_set_errno(ICAL_INTERNAL_ERROR); return 0; } - v = icalvalue_new_from_string(vk,w->value); + if (w->compare == ICALGAUGECOMPARE_ISNULL || w->compare == ICALGAUGECOMPARE_ISNOTNULL) + v = icalvalue_new(vk); + else + v = icalvalue_new_from_string(vk,w->value); if (v == 0){ /* Keep error set by icalvalue_from-string*/ @@ -324,14 +370,46 @@ int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) } } + /* check if it is a recurring */ + rrule = icalcomponent_get_first_property(sub_comp,ICAL_RRULE_PROPERTY); + + if (gauge->expand + && rrule) { + + if (w->prop == ICAL_DTSTART_PROPERTY || + w->prop == ICAL_DTEND_PROPERTY || + w->prop == ICAL_DUE_PROPERTY){ + /** needs to use recurrence-id to do comparison */ + compare_recur = 1; + } + + } + + this_clause = 0; - local_pass = 0; + local_pass = (w->compare == ICALGAUGECOMPARE_ISNULL) ? 1 : 0; + for(prop = icalcomponent_get_first_property(sub_comp,w->prop); prop != 0; prop = icalcomponent_get_next_property(sub_comp,w->prop)){ icalvalue* prop_value; icalgaugecompare relation; + if (w->compare == ICALGAUGECOMPARE_ISNULL) { + local_pass = 0; + break; + } + + if (w->compare == ICALGAUGECOMPARE_ISNOTNULL) { + local_pass = 1; + break; + } + + if (compare_recur) { + icalproperty *p = icalcomponent_get_first_property(sub_comp, ICAL_RECURRENCEID_PROPERTY); + prop_value = icalproperty_get_value(p); + } + else /* prop value from this component */ prop_value = icalproperty_get_value(prop); relation = (icalgaugecompare)icalvalue_compare(prop_value,v); @@ -355,34 +433,40 @@ int icalgauge_compare(icalgauge* gauge,icalcomponent* comp) } } + this_clause = local_pass > 0 ? 1 : 0; + /* Now look at the logic operator for this clause to see how the value should be merge with the previous clause */ if(w->logic == ICALGAUGELOGIC_AND){ last_clause = this_clause && last_clause; - } else if(w->logic == ICALGAUGELOGIC_AND) { + } else if(w->logic == ICALGAUGELOGIC_OR) { last_clause = this_clause || last_clause; } else { last_clause = this_clause; } - } + + icalvalue_free(v); + + }/**** check next one in where clause ****/ return last_clause; } +/** @brief Debug + * Print gauge information to stdout. + */ -void icalgauge_dump(icalcomponent* gauge) +void icalgauge_dump(icalgauge* gauge) { - pvl_elem *p; - struct icalgauge_impl *impl = (struct icalgauge_impl*)gauge; - + pvl_elem p; printf("--- Select ---\n"); - for(p = pvl_head(impl->select);p!=0;p=pvl_next(p)){ + for(p = pvl_head(gauge->select);p!=0;p=pvl_next(p)){ struct icalgauge_where *w = pvl_data(p); if(w->comp != ICAL_NO_COMPONENT){ @@ -407,14 +491,14 @@ void icalgauge_dump(icalcomponent* gauge) } printf("--- From ---\n"); - for(p = pvl_head(impl->from);p!=0;p=pvl_next(p)){ + for(p = pvl_head(gauge->from);p!=0;p=pvl_next(p)){ icalcomponent_kind k = (icalcomponent_kind)pvl_data(p); printf("%s\n",icalenum_component_kind_to_string(k)); } printf("--- Where ---\n"); - for(p = pvl_head(impl->where);p!=0;p=pvl_next(p)){ + for(p = pvl_head(gauge->where);p!=0;p=pvl_next(p)){ struct icalgauge_where *w = pvl_data(p); if(w->logic != ICALGAUGELOGIC_NONE){ @@ -441,7 +525,5 @@ void icalgauge_dump(icalcomponent* gauge) printf("\n"); } - - } diff --git a/libical/src/libicalss/icalgauge.h b/libical/src/libicalss/icalgauge.h index 1caf0ac7d1..c35b4f7508 100644 --- a/libical/src/libicalss/icalgauge.h +++ b/libical/src/libicalss/icalgauge.h @@ -29,23 +29,33 @@ #ifndef ICALGAUGE_H #define ICALGAUGE_H -typedef void icalgauge; +/** @file icalgauge.h + * @brief Routines implementing a filter for ical components + */ -icalgauge* icalgauge_new_from_sql(char* sql); +typedef struct icalgauge_impl icalgauge; + +icalgauge* icalgauge_new_from_sql(char* sql, int expand); + +int icalgauge_get_expand(icalgauge* gauge); void icalgauge_free(icalgauge* gauge); char* icalgauge_as_sql(icalcomponent* gauge); -void icalgauge_dump(icalcomponent* gauge); +void icalgauge_dump(icalgauge* gauge); + -/* Return true is comp matches the gauge. The component must be in - cannonical form -- a VCALENDAR with one VEVENT, VTODO or VJOURNAL - sub component */ +/** @brief Return true if comp matches the gauge. + * + * The component must be in + * cannonical form -- a VCALENDAR with one VEVENT, VTODO or VJOURNAL + * sub component + */ int icalgauge_compare(icalgauge* g, icalcomponent* comp); -/* Clone the component, but only return the properties specified in - the gauge */ +/** Clone the component, but only return the properties + * specified in the gauge */ icalcomponent* icalgauge_new_clone(icalgauge* g, icalcomponent* comp); #endif /* ICALGAUGE_H*/ diff --git a/libical/src/libicalss/icalgaugeimpl.h b/libical/src/libicalss/icalgaugeimpl.h index 73a2813242..e56b1c01c1 100644 --- a/libical/src/libicalss/icalgaugeimpl.h +++ b/libical/src/libicalss/icalgaugeimpl.h @@ -24,8 +24,6 @@ #include "ical.h" -#include "pvl.h" - typedef enum icalgaugecompare { ICALGAUGECOMPARE_EQUAL=ICAL_XLICCOMPARETYPE_EQUAL, ICALGAUGECOMPARE_LESS=ICAL_XLICCOMPARETYPE_LESS, @@ -34,6 +32,8 @@ typedef enum icalgaugecompare { ICALGAUGECOMPARE_GREATEREQUAL=ICAL_XLICCOMPARETYPE_GREATEREQUAL, ICALGAUGECOMPARE_NOTEQUAL=ICAL_XLICCOMPARETYPE_NOTEQUAL, ICALGAUGECOMPARE_REGEX=ICAL_XLICCOMPARETYPE_REGEX, + ICALGAUGECOMPARE_ISNULL=ICAL_XLICCOMPARETYPE_ISNULL, + ICALGAUGECOMPARE_ISNOTNULL=ICAL_XLICCOMPARETYPE_ISNOTNULL, ICALGAUGECOMPARE_NONE=0 } icalgaugecompare; @@ -54,10 +54,10 @@ struct icalgauge_where { struct icalgauge_impl { - - pvl_list select; /*Of icalgaugecompare, using only prop and comp fields*/ - pvl_list from; /* List of component_kinds, as integers */ - pvl_list where; /* List of icalgaugecompare */ + pvl_list select; /**< Of icalgaugecompare, using only prop and comp fields*/ + pvl_list from; /**< List of component_kinds, as integers */ + pvl_list where; /**< List of icalgaugecompare */ + int expand; }; diff --git a/libical/src/libicalss/icalmessage.c b/libical/src/libicalss/icalmessage.c index e1e8d8015c..731a2c7cfc 100644 --- a/libical/src/libicalss/icalmessage.c +++ b/libical/src/libicalss/icalmessage.c @@ -40,7 +40,7 @@ icalcomponent* icalmessage_get_inner(icalcomponent* comp) } } -char* lowercase(const char* str) +static char* lowercase(const char* str) { char* p = 0; char* n = icalmemory_strdup(str); @@ -158,8 +158,13 @@ icalcomponent *icalmessage_new_reply_base(icalcomponent* c, icalcomponent_add_property(reply,icalproperty_new_version("2.0")); +#ifndef WIN32 sprintf(tmp, "-//SoftwareStudio//NONSGML %s %s //EN",PACKAGE,VERSION); +#else + sprintf(tmp, + "-//SoftwareStudio//NONSGML %s %s //EN",ICAL_PACKAGE,ICAL_VERSION); +#endif icalcomponent_add_property(reply,icalproperty_new_prodid(tmp)); return reply; @@ -230,11 +235,11 @@ icalcomponent* icalmessage_new_counterpropose_reply(icalcomponent* oldc, icalerror_check_arg_rz(oldc,"oldc"); icalerror_check_arg_rz(newc,"newc"); - reply = icalcomponent_new_clone(newc); + reply = icalmessage_new_reply_base(newc,user,msg); icalcomponent_set_method(reply,ICAL_METHOD_COUNTER); - return newc; + return reply; } @@ -353,10 +358,7 @@ icalcomponent* icalmessage_new_error_reply(icalcomponent* c, rs.debug = debug; icalcomponent_add_property(inner, - icalproperty_new_requeststatus( - icalreqstattype_as_string(rs) - ) - ); + icalproperty_new_requeststatus(rs)); } else { /* code == ICAL_UNKNOWN_STATUS */ /* Copy all of the request status properties */ diff --git a/libical/src/libicalss/icalset.c b/libical/src/libicalss/icalset.c index 2120609928..0ad22696f7 100644 --- a/libical/src/libicalss/icalset.c +++ b/libical/src/libicalss/icalset.c @@ -41,33 +41,26 @@ #include "icaldirset.h" #include "icaldirsetimpl.h" #include <stdlib.h> -/*#include "icalheapset.h"*/ -/*#include "icalmysqlset.h"*/ - -#define ICALSET_ID "set " - -struct icalset_fp { - void (*free)(icalset* set); - const char* (*path)(icalset* set); - void (*mark)(icalset* set); - icalerrorenum (*commit)(icalset* set); - icalerrorenum (*add_component)(icalset* set, icalcomponent* comp); - icalerrorenum (*remove_component)(icalset* set, icalcomponent* comp); - int (*count_components)(icalset* set, - icalcomponent_kind kind); - icalerrorenum (*select)(icalset* set, icalcomponent* gauge); - void (*clear)(icalset* set); - icalcomponent* (*fetch)(icalset* set, const char* uid); - icalcomponent* (*fetch_match)(icalset* set, icalcomponent *comp); - int (*has_uid)(icalset* set, const char* uid); - icalerrorenum (*modify)(icalset* set, icalcomponent *old, - icalcomponent *new); - icalcomponent* (*get_current_component)(icalset* set); - icalcomponent* (*get_first_component)(icalset* set); - icalcomponent* (*get_next_component)(icalset* set); -}; - -struct icalset_fp icalset_dirset_fp = { +#include <string.h> +#include <errno.h> + +#ifdef WITH_BDB4 +#include "icalbdbset.h" +#include "icalbdbsetimpl.h" +#endif + +/* #define _DLOPEN_TEST */ +#ifdef _DLOPEN_TEST +#include <sys/types.h> +#include <dlfcn.h> +#include <dirent.h> +#endif + +static icalset icalset_dirset_init = { + ICAL_DIR_SET, + sizeof(icaldirset), + NULL, + icaldirset_init, icaldirset_free, icaldirset_path, icaldirset_mark, @@ -83,11 +76,18 @@ struct icalset_fp icalset_dirset_fp = { icaldirset_modify, icaldirset_get_current_component, icaldirset_get_first_component, - icaldirset_get_next_component + icaldirset_get_next_component, + icaldirset_begin_component, + icaldirsetiter_to_next, + icaldirsetiter_to_prior }; -struct icalset_fp icalset_fileset_fp = { +static icalset icalset_fileset_init = { + ICAL_FILE_SET, + sizeof(icalfileset), + NULL, + icalfileset_init, icalfileset_free, icalfileset_path, icalfileset_mark, @@ -103,265 +103,391 @@ struct icalset_fp icalset_fileset_fp = { icalfileset_modify, icalfileset_get_current_component, icalfileset_get_first_component, - icalfileset_get_next_component + icalfileset_get_next_component, + icalfileset_begin_component, + icalfilesetiter_to_next, + NULL }; -struct icalset_impl { +#ifdef WITH_BDB4 +static icalset icalset_bdbset_init = { + ICAL_BDB_SET, + sizeof(icalbdbset), + NULL, + icalbdbset_init, + icalbdbset_free, + icalbdbset_path, + icalbdbset_mark, + icalbdbset_commit, + icalbdbset_add_component, + icalbdbset_remove_component, + icalbdbset_count_components, + icalbdbset_select, + icalbdbset_clear, + icalbdbset_fetch, + icalbdbset_fetch_match, + icalbdbset_has_uid, + icalbdbset_modify, + icalbdbset_get_current_component, + icalbdbset_get_first_component, + icalbdbset_get_next_component, + icalbdbset_begin_component, + icalbdbsetiter_to_next, + NULL +}; +#endif - char id[5]; /* "set " */ +#ifdef _DLOPEN_TEST +static int icalset_init_done = 0; +static pvl_list icalset_kinds = 0; - void *derived_impl; - struct icalset_fp *fp; -}; +typedef icalset *(*fptr)(void); -/* Figure out what was actually passed in as the set. This could be a - set or and of the derived types such as dirset or fileset. Note - this routine returns a value, not a reference, to avoid memory - leaks in the methods */ -struct icalset_impl icalset_get_impl(icalset* set) -{ - struct icalset_impl impl; - - memset(&impl,0,sizeof(impl)); - icalerror_check_arg_re( (set!=0),"set",impl); - - if(strcmp((char*)set,ICALSET_ID)==0) { - /* It is actually a set, so just sent the reference back out. */ - return *(struct icalset_impl*)set; - } else if(strcmp((char*)set,ICALFILESET_ID)==0) { - /* Make a new set from the fileset */ - impl.fp = &icalset_fileset_fp; - impl.derived_impl = set; - strcpy(impl.id,ICALFILESET_ID);/* HACK. Is this necessary? */ - return impl; - } else if(strcmp((char*)set,ICALDIRSET_ID)==0) { - /* Make a new set from the dirset */ - impl.fp = &icalset_dirset_fp; - impl.derived_impl = set; - strcpy(impl.id,ICALDIRSET_ID);/* HACK. Is this necessary? */ - return impl; - } else { - /* The type of set is unknown, so throw an error */ - icalerror_assert((0),"Unknown set type"); - return impl; - } +/** + * Try to load the file and register any icalset found within. + */ +static int load(const char *file) { + + void *modh; + fptr inith; + icalset *icalset_init_ptr; + + if ((modh = dlopen(file, RTLD_NOW)) == 0) { + perror("dlopen"); + return 0; + } + + if ((inith = (fptr)dlsym(modh, "InitModule")) == 0) { + perror("dlsym"); + return 0; + } + + while ((icalset_init_ptr = ((inith)())) != 0) { + pvl_push(icalset_kinds, &icalset_init_ptr); + } + + return 1; } +/** + * Look in the given directory for files called mod_*.o and try to + * load them. + */ +int icalset_loaddir(const char *path) { + DIR *d; + struct dirent *dp; + char buf[PATH_MAX], + *bufptr; + int tot = 0; -struct icalset_impl* icalset_new_impl() -{ - - struct icalset_impl* impl; + strcpy(buf, path); + bufptr = buf + strlen(buf); - if ( ( impl = (struct icalset_impl*) - malloc(sizeof(struct icalset_impl))) == 0) { - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } + if (*(bufptr-1) != '/') + *bufptr++ = '/'; - strcpy(impl->id,ICALSET_ID); + if ((d = opendir(path)) == 0) { + perror("opendir"); + return 0; + } - impl->derived_impl = 0; - impl->fp = 0; + while ((dp = readdir(d)) != 0) { + if (strncmp(dp->d_name, "mod_", 4)) continue; - return impl; -} + strcpy(bufptr, dp->d_name); -struct icalset_impl* icalset_new_file_from_ref(icalfileset *fset) -{ - struct icalset_impl *impl = icalset_new_impl(); + load(buf); + tot++; + } + (void)closedir(d); - icalerror_check_arg_rz( (fset!=0),"fset"); + return 1; +} - if(impl == 0){ - free(impl); - return 0; - } +int icalset_register_class(icalset *set); - impl->derived_impl = fset; +static void icalset_init(void) { + assert(icalset_kinds == 0); + icalset_kinds = pvl_newlist(); - if (impl->derived_impl == 0){ - free(impl); - return 0; - } + pvl_push(icalset_kinds, &icalset_fileset_init); + pvl_push(icalset_kinds, &icalset_dirset_init); +#ifdef WITH_BDB4 + pvl_push(icalset_kinds, &icalset_bdb4set_init); +#endif - impl->fp = &icalset_fileset_fp; +#ifdef EXT_PATH + icalset_loaddir(EXT_PATH); +#endif - return (struct icalset_impl*)impl; + icalset_init_done++; } -icalset* icalset_new_file(const char* path) -{ - icalfileset *fset = icalfileset_new(path); +int icalset_register_class(icalset *set) { - if(fset == 0){ - return 0; - } + if (!icalset_init_done) + icalset_init(); - return (icalset*)icalset_new_file_from_ref(fset); + pvl_push(icalset_kinds, set); + return 1; } -icalset* icalset_new_dir_from_ref(icaldirset *dset) -{ +#endif - struct icalset_impl *impl = icalset_new_impl(); +icalset* icalset_new(icalset_kind kind, const char* dsn, void* options) { + icalset *data = NULL; + icalset *ret = NULL; - icalerror_check_arg_rz( (dset!=0),"dset"); +#ifdef _DLOPEN_TEST + pvl_elem e; + icalset *impl; - if(impl == 0){ - return 0; + if (!icalset_init_done) + icalset_init(); + + for(e = pvl_head(icalset_kinds); e!=0; e = pvl_next(e)) { + impl = (icalset*)pvl_data(e); + if (impl->kind == kind) + break; + } + if (e == 0) { + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); + return(NULL); } - impl->derived_impl = dset; + data = (icalset*)malloc(impl->size); + if (data == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + errno = ENOMEM; + return 0; + } - if (impl->derived_impl == 0){ - free(impl); + /* The first member of the derived class must be an icalset. */ + memset(data,0,impl->size); + /* *data = *impl; */ + memcpy(data, impl, sizeof(icalset)); + + data->dsn = strdup(dsn); +#else + switch(kind) { + case ICAL_FILE_SET: + data = (icalset*) malloc(sizeof(icalfileset)); + if (data == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + errno = ENOMEM; + return 0; + } + memset(data,0,sizeof(icalfileset)); + *data = icalset_fileset_init; + break; + case ICAL_DIR_SET: + data = (icalset*) malloc(sizeof(icaldirset)); + if (data == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + errno = ENOMEM; + return 0; + } + memset(data,0,sizeof(icaldirset)); + *data = icalset_dirset_init; + break; +#ifdef WITH_BDB4 + case ICAL_BDB_SET: + data = (icalset*) malloc(sizeof(icalbdbset)); + if (data == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + errno = ENOMEM; return 0; } + memset(data,0,sizeof(icalbdbset)); + *data = icalset_bdbset_init; + break; +#endif + + default: + icalerror_set_errno(ICAL_UNIMPLEMENTED_ERROR); + /** unimplemented **/ + return(NULL); + } + + if ( data == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + data->kind = kind; + data->dsn = strdup(dsn); +#endif - impl->fp = &icalset_dirset_fp; + /** call the implementation specific initializer **/ + if ((ret = data->init(data, dsn, options)) == NULL) + icalset_free(data); - return impl; + return ret; } -icalset* icalset_new_dir(const char* path) +icalset* icalset_new_file(const char* path) { - icaldirset *dset = icaldirset_new(path); - - if(dset == 0){ - return 0; - } + return icalset_new(ICAL_FILE_SET, path, NULL); +} - return icalset_new_dir_from_ref(dset); +icalset* icalset_new_file_writer(const char* path) +{ + return icalfileset_new_writer(path); } -icalset* icalset_new_heap(void) +icalset* icalset_new_file_reader(const char* path) { - struct icalset_impl *impl = icalset_new_impl(); + return icalfileset_new_reader(path); +} - if(impl == 0){ - free(impl); - return 0; - } +icalset* icalset_new_dir(const char* path) +{ + return icalset_new(ICAL_DIR_SET, path, NULL); +} - return 0; +icalset* icalset_new_dir_writer(const char* path) +{ + return icaldirset_new_writer(path); } -icalset* icalset_new_mysql(const char* path) +icalset* icalset_new_dir_reader(const char* path) { - struct icalset_impl *impl = icalset_new_impl(); + return icaldirset_new_reader(path); +} - if(impl == 0){ - free(impl); - return 0; - } - return 0; -} + +/* Functions for built-in methods */ + +/** + * free memory associated with this icalset + * automatically calls the implementation specific free routine + */ void icalset_free(icalset* set) { - struct icalset_impl impl = icalset_get_impl(set); - (*(impl.fp->free))(impl.derived_impl); + if (set->free) + set->free(set); - if(strcmp((char*)set,ICALSET_ID)) { - free(set); - } -} + if (set->dsn) + free(set->dsn); -const char* icalset_path(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->path))(impl.derived_impl); + free(set); } -void icalset_mark(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - (*(impl.fp->mark))(impl.derived_impl); + +const char* icalset_path(icalset* set) { + return set->path(set); } -icalerrorenum icalset_commit(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->commit))(impl.derived_impl); +void icalset_mark(icalset* set) { + set->mark(set); } -icalerrorenum icalset_add_component(icalset* set, icalcomponent* comp) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->add_component))(impl.derived_impl,comp); +icalerrorenum icalset_commit(icalset* set) { + return set->commit(set); } -icalerrorenum icalset_remove_component(icalset* set, icalcomponent* comp) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->remove_component))(impl.derived_impl,comp); +icalerrorenum icalset_add_component(icalset* set, icalcomponent* comp) { + return set->add_component(set,comp); } -int icalset_count_components(icalset* set,icalcomponent_kind kind) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->count_components))(impl.derived_impl,kind); +icalerrorenum icalset_remove_component(icalset* set, icalcomponent* comp) { + return set->remove_component(set,comp); } -icalerrorenum icalset_select(icalset* set, icalcomponent* gauge) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->select))(impl.derived_impl,gauge); +int icalset_count_components(icalset* set,icalcomponent_kind kind) { + return set->count_components(set,kind); } -void icalset_clear(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - (*(impl.fp->clear))(impl.derived_impl); +icalerrorenum icalset_select(icalset* set, icalgauge* gauge) { + return set->select(set, gauge); } -icalcomponent* icalset_fetch(icalset* set, const char* uid) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->fetch))(impl.derived_impl,uid); +void icalset_clear(icalset* set) { + set->clear(set); } -icalcomponent* icalset_fetch_match(icalset* set, icalcomponent *comp) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->fetch_match))(impl.derived_impl,comp); +icalcomponent* icalset_fetch(icalset* set, const char* uid) { + return set->fetch(set, uid); } +icalcomponent* icalset_fetch_match(icalset* set, icalcomponent *comp) { + return set->fetch_match(set, comp); +} -int icalset_has_uid(icalset* set, const char* uid) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->has_uid))(impl.derived_impl,uid); +int icalset_has_uid(icalset* set, const char* uid) { + return set->has_uid(set, uid); } icalerrorenum icalset_modify(icalset* set, icalcomponent *old, - icalcomponent *new) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->modify))(impl.derived_impl,old,new); + icalcomponent *new) { + return set->modify(set, old, new); } -icalcomponent* icalset_get_current_component(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->get_current_component))(impl.derived_impl); +icalcomponent* icalset_get_current_component(icalset* set) { + return set->get_current_component(set); } -icalcomponent* icalset_get_first_component(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->get_first_component))(impl.derived_impl); +icalcomponent* icalset_get_first_component(icalset* set) { + return set->get_first_component(set); } -icalcomponent* icalset_get_next_component(icalset* set) -{ - struct icalset_impl impl = icalset_get_impl(set); - return (*(impl.fp->get_next_component))(impl.derived_impl); +icalcomponent* icalset_get_next_component(icalset* set) { + return set->get_next_component(set); +} + +icalsetiter icalsetiter_null = {{ICAL_NO_COMPONENT, 0}, 0}; + +icalsetiter icalset_begin_component(icalset* set, + icalcomponent_kind kind, icalgauge* gauge) { + return set->icalset_begin_component(set, kind, gauge); +} + +icalcomponent* icalsetiter_next(icalsetiter* itr) { + + icalcomponent* c = 0; + icalerror_check_arg_rz( (itr != NULL), "i"); + + do { + c = icalcompiter_next(&(itr->iter)); + if(c != 0 && (itr->gauge == 0 || + icalgauge_compare(itr->gauge, c) == 1)){ + return c; + } + } while (c != 0); + + return 0; } +icalcomponent* icalsetiter_prior(icalsetiter* i) { + + icalcomponent* c = 0; + icalerror_check_arg_rz( (i != NULL), "i" ); + + do { + c = icalcompiter_prior(&(i->iter)); + if(c != 0 && (i->gauge == 0 || + icalgauge_compare(i->gauge, c) == 1)){ + return c; + } + } while (c != 0); + + return 0; +} +icalcomponent* icalsetiter_deref(icalsetiter* i) { + icalerror_check_arg_rz( (i != NULL), "i" ); + return (icalcompiter_deref(&(i->iter))); +} +/* for subclasses that use multiple clusters that require specialized cluster traversal */ +icalcomponent* icalsetiter_to_next(icalset* set, icalsetiter* i) +{ + return set->icalsetiter_to_next(set, i); +} +icalcomponent* icalsetiter_to_prior(icalset* set, icalsetiter* i) +{ + return set->icalsetiter_to_prior(set, i); +} diff --git a/libical/src/libicalss/icalset.h b/libical/src/libicalss/icalset.h index 7b083dae24..4008c6216f 100644 --- a/libical/src/libicalss/icalset.h +++ b/libical/src/libicalss/icalset.h @@ -1,17 +1,19 @@ /* -*- Mode: C -*- */ -/*====================================================================== - FILE: icalset.h - CREATOR: eric 28 November 1999 - +/** + @file icalset.h + @author eric 28 November 1999 Icalset is the "base class" for representations of a collection of iCal components. Derived classes (actually delegatees) include: - icalfileset Store componetns in a single file + icalfileset Store components in a single file icaldirset Store components in multiple files in a directory + icalbdbset Store components in a Berkeley DB File icalheapset Store components on the heap icalmysqlset Store components in a mysql database. +**/ +/* $Id$ $Locker$ @@ -39,7 +41,7 @@ #include <limits.h> /* For PATH_MAX */ #include "ical.h" -#include "icalerror.h" +#include "icalgauge.h" #ifdef PATH_MAX #define ICAL_PATH_MAX PATH_MAX @@ -48,33 +50,86 @@ #endif - - -typedef void icalset; +typedef struct icalset_impl icalset; typedef enum icalset_kind { ICAL_FILE_SET, ICAL_DIR_SET, - ICAL_HEAP_SET, - ICAL_MYSQL_SET, - ICAL_CAP_SET + ICAL_BDB_SET } icalset_kind; +typedef struct icalsetiter +{ + icalcompiter iter; /* icalcomponent_kind, pvl_elem iter */ + icalgauge* gauge; + icalrecur_iterator* ritr; /*the last iterator*/ + icalcomponent* last_component; /*the pending recurring component to be processed */ + const char* tzid; /* the calendar's timezone id */ +} icalsetiter; + +struct icalset_impl { + icalset_kind kind; + int size; + char *dsn; + icalset* (*init)(icalset* set, const char *dsn, void *options); + void (*free)(icalset* set); + const char* (*path)(icalset* set); + void (*mark)(icalset* set); + icalerrorenum (*commit)(icalset* set); + icalerrorenum (*add_component)(icalset* set, icalcomponent* comp); + icalerrorenum (*remove_component)(icalset* set, icalcomponent* comp); + int (*count_components)(icalset* set, + icalcomponent_kind kind); + icalerrorenum (*select)(icalset* set, icalgauge* gauge); + void (*clear)(icalset* set); + icalcomponent* (*fetch)(icalset* set, const char* uid); + icalcomponent* (*fetch_match)(icalset* set, icalcomponent *comp); + int (*has_uid)(icalset* set, const char* uid); + icalerrorenum (*modify)(icalset* set, icalcomponent *old, + icalcomponent *newc); + icalcomponent* (*get_current_component)(icalset* set); + icalcomponent* (*get_first_component)(icalset* set); + icalcomponent* (*get_next_component)(icalset* set); + icalsetiter (*icalset_begin_component)(icalset* set, + icalcomponent_kind kind, icalgauge* gauge); + icalcomponent* (*icalsetiter_to_next)(icalset* set, icalsetiter* i); + icalcomponent* (*icalsetiter_to_prior)(icalset* set, icalsetiter* i); +}; + +/** @brief Register a new derived class */ +int icalset_register_class(icalset *set); + + +/** @brief Generic icalset constructor + * + * @param kind The type of icalset to create + * @param dsn Data Source Name - usually a pathname or DB handle + * @param options Any implementation specific options + * + * @return A valid icalset reference or NULL if error. + * + * This creates any of the icalset types available. + */ + +icalset* icalset_new(icalset_kind kind, const char* dsn, void* options); -/* Create a specific derived type of set */ icalset* icalset_new_file(const char* path); +icalset* icalset_new_file_reader(const char* path); +icalset* icalset_new_file_writer(const char* path); + icalset* icalset_new_dir(const char* path); -icalset* icalset_new_heap(void); -icalset* icalset_new_mysql(const char* path); -/*icalset* icalset_new_cap(icalcstp* cstp);*/ +icalset* icalset_new_file_reader(const char* path); +icalset* icalset_new_file_writer(const char* path); void icalset_free(icalset* set); const char* icalset_path(icalset* set); -/* Mark the cluster as changed, so it will be written to disk when it - is freed. Commit writes to disk immediately*/ +/** Mark the cluster as changed, so it will be written to disk when it + is freed. **/ void icalset_mark(icalset* set); + +/** Write changes to disk immediately */ icalerrorenum icalset_commit(icalset* set); icalerrorenum icalset_add_component(icalset* set, icalcomponent* comp); @@ -83,28 +138,46 @@ icalerrorenum icalset_remove_component(icalset* set, icalcomponent* comp); int icalset_count_components(icalset* set, icalcomponent_kind kind); -/* Restrict the component returned by icalset_first, _next to those - that pass the gauge. _clear removes the gauge. */ -icalerrorenum icalset_select(icalset* set, icalcomponent* gauge); +/** Restrict the component returned by icalset_first, _next to those + that pass the gauge. */ +icalerrorenum icalset_select(icalset* set, icalgauge* gauge); + +/** Clears the gauge defined by icalset_select() */ void icalset_clear_select(icalset* set); -/* Get a component by uid */ +/** Get a component by uid */ icalcomponent* icalset_fetch(icalset* set, const char* uid); + int icalset_has_uid(icalset* set, const char* uid); icalcomponent* icalset_fetch_match(icalset* set, icalcomponent *c); -/* Modify components according to the MODIFY method of CAP. Works on +/** Modify components according to the MODIFY method of CAP. Works on the currently selected components. */ icalerrorenum icalset_modify(icalset* set, icalcomponent *oldc, icalcomponent *newc); -/* Iterate through the components. If a guage has been defined, these +/** Iterate through the components. If a guage has been defined, these will skip over components that do not pass the gauge */ icalcomponent* icalset_get_current_component(icalset* set); icalcomponent* icalset_get_first_component(icalset* set); icalcomponent* icalset_get_next_component(icalset* set); +/** External Iterator with gauge - for thread safety */ +extern icalsetiter icalsetiter_null; + +icalsetiter icalset_begin_component(icalset* set, + icalcomponent_kind kind, icalgauge* gauge); + +/** Default _next, _prior, _deref for subclasses that use single cluster */ +icalcomponent* icalsetiter_next(icalsetiter* i); +icalcomponent* icalsetiter_prior(icalsetiter* i); +icalcomponent* icalsetiter_deref(icalsetiter* i); + +/** for subclasses that use multiple clusters that require specialized cluster traversal */ +icalcomponent* icalsetiter_to_next(icalset* set, icalsetiter* i); +icalcomponent* icalsetiter_to_prior(icalset* set, icalsetiter* i); + #endif /* !ICALSET_H */ diff --git a/libical/src/libicalss/icalspanlist.c b/libical/src/libicalss/icalspanlist.c index cab6a81c68..f42ff41ed8 100644 --- a/libical/src/libicalss/icalspanlist.c +++ b/libical/src/libicalss/icalspanlist.c @@ -28,14 +28,27 @@ #include "ical.h" #include "icalspanlist.h" -#include "pvl.h" + #include <stdlib.h> /* for free and malloc */ +#include <string.h> struct icalspanlist_impl { - pvl_list spans; + pvl_list spans; /**< list of icaltime_span data **/ + struct icaltimetype start; /**< start time of span **/ + struct icaltimetype end; /**< end time of span **/ }; -int compare_span(void* a, void* b) +/** @brief Internal comparison function for two spans + * + * @param a a spanlist. + * @param b another spanlist. + * + * @return -1, 0, 1 depending on the comparison of the start times. + * + * Used to insert spans into the tree in sorted order. + */ + +static int compare_span(void* a, void* b) { struct icaltime_span *span_a = (struct icaltime_span *)a ; struct icaltime_span *span_b = (struct icaltime_span *)b ; @@ -49,20 +62,52 @@ int compare_span(void* a, void* b) } } -icalcomponent* icalspanlist_get_inner(icalcomponent* comp) + +/** @brief callback function for collecting spanlists of a + * series of events. + * + * @param comp A valid icalcomponent. + * @param span The span to insert into data. + * @param data The actual spanlist to insert into + * + * This callback is used by icalcomponent_foreach_recurrence() + * to build up a spanlist. + */ + +static void icalspanlist_new_callback(icalcomponent *comp, + struct icaltime_span *span, + void *data) { - if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT){ - return icalcomponent_get_first_real_component(comp); - } else { - return comp; - } + icaltime_span *s; + icalspanlist *sl = (icalspanlist*) data; + + if (span->is_busy == 0) + return; + + if ((s=(icaltime_span *) malloc(sizeof(icaltime_span))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return; + } + + /** copy span data into allocated memory.. **/ + *s = *span; + pvl_insert_ordered(sl->spans, compare_span, (void*)s); } + -void print_span(int c, struct icaltime_span span ); +/** @brief Make a free list from a set of VEVENT components. + * + * @param set A valid icalset containing VEVENTS + * @param start The free list starts at this date/time + * @param end The free list ends at this date/time + * + * @return A spanlist corresponding to the VEVENTS + * + * Given a set of components, a start time and an end time + * return a spanlist that contains the free/busy times. + */ - -/* Make a free list from a set of component */ icalspanlist* icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end) @@ -71,7 +116,7 @@ icalspanlist* icalspanlist_new(icalset *set, pvl_elem itr; icalcomponent *c,*inner; icalcomponent_kind kind, inner_kind; - struct icalspanlist_impl *sl; + icalspanlist *sl; struct icaltime_span *freetime; if ( ( sl = (struct icalspanlist_impl*) @@ -81,14 +126,12 @@ icalspanlist* icalspanlist_new(icalset *set, } sl->spans = pvl_newlist(); + sl->start = start; + sl->end = end; range.start = icaltime_as_timet(start); range.end = icaltime_as_timet(end); - printf("Range start: %s",ctime(&range.start)); - printf("Range end : %s",ctime(&range.end)); - - /* Get a list of spans of busy time from the events in the set and order the spans based on the start time */ @@ -96,8 +139,6 @@ icalspanlist* icalspanlist_new(icalset *set, c != 0; c = icalset_get_next_component(set)){ - struct icaltime_span span; - kind = icalcomponent_isa(c); inner = icalcomponent_get_inner(c); @@ -113,31 +154,12 @@ icalspanlist* icalspanlist_new(icalset *set, } icalerror_clear_errno(); - - span = icalcomponent_get_span(c); - span.is_busy = 1; - - if(icalerrno != ICAL_NO_ERROR){ - continue; - } - - if ((range.start < span.end && icaltime_is_null_time(end)) || - (range.start < span.end && range.end > span.start )){ - - struct icaltime_span *s; - - if ((s=(struct icaltime_span *) - malloc(sizeof(struct icaltime_span))) == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - - memcpy(s,&span,sizeof(span)); - - pvl_insert_ordered(sl->spans,compare_span,(void*)s); - - } - } + + icalcomponent_foreach_recurrence(c, start, end, + icalspanlist_new_callback, + (void*)sl); + + } /* Now Fill in the free time spans. loop through the spans. if the start of the range is not within the span, create a free entry @@ -148,7 +170,7 @@ icalspanlist* icalspanlist_new(icalset *set, itr != 0; itr = pvl_next(itr)) { - struct icaltime_span *s = (icalproperty*)pvl_data(itr); + struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); if ((freetime=(struct icaltime_span *) malloc(sizeof(struct icaltime_span))) == 0){ @@ -178,7 +200,7 @@ icalspanlist* icalspanlist_new(icalset *set, if( icaltime_is_null_time(end)){ struct icaltime_span* last_span; - last_span = pvl_data(pvl_tail(sl->spans)); + last_span = (struct icaltime_span*)pvl_data(pvl_tail(sl->spans)); if (last_span != 0){ @@ -197,35 +219,46 @@ icalspanlist* icalspanlist_new(icalset *set, return sl; - } +/** @brief Destructor. + * @param s A valid icalspanlist + * + * Free memory associated with the spanlist + */ + void icalspanlist_free(icalspanlist* s) { struct icaltime_span *span; - struct icalspanlist_impl* impl = (struct icalspanlist_impl*)s; - - while( (span=pvl_pop(impl->spans)) != 0){ + + if (s == NULL) + return; + + while( (span=pvl_pop(s->spans)) != 0){ free(span); } - pvl_free(impl->spans); + pvl_free(s->spans); - impl->spans = 0; + s->spans = 0; + + free(s); } -void icalspanlist_dump(icalspanlist* s){ +/** @brief (Debug) print out spanlist to stdout. + * @param sl A valid icalspanlist. + */ +void icalspanlist_dump(icalspanlist* sl){ int i = 0; - struct icalspanlist_impl* sl = (struct icalspanlist_impl*)s; pvl_elem itr; for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { - struct icaltime_span *s = (icalproperty*)pvl_data(itr); + struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); printf("#%02d %d start: %s",++i,s->is_busy,ctime(&s->start)); printf(" end : %s",ctime(&s->end)); @@ -236,10 +269,19 @@ void icalspanlist_dump(icalspanlist* s){ icalcomponent* icalspanlist_make_free_list(icalspanlist* sl); icalcomponent* icalspanlist_make_busy_list(icalspanlist* sl); + +/** @brief Find next free time span in a spanlist. + * + * @param sl The spanlist to search. + * @param t The time to start looking. + * + * Given a spanlist and a time, find the next period of time + * that is free + */ + struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, struct icaltimetype t) { - struct icalspanlist_impl* impl = (struct icalspanlist_impl*)sl; pvl_elem itr; struct icalperiodtype period; struct icaltime_span *s; @@ -249,22 +291,22 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, period.start = icaltime_null_time(); period.end = icaltime_null_time(); - /* Is the reference time before the first span? If so, assume - that the reference time is free */ - itr = pvl_head(impl->spans); - s = (icalproperty*)pvl_data(itr); + itr = pvl_head(sl->spans); + s = (struct icaltime_span *)pvl_data(itr); if (s == 0){ /* No elements in span */ return period; } + /* Is the reference time before the first span? If so, assume + that the reference time is free */ if(rangett <s->start ){ /* End of period is start of first span if span is busy, end of the span if it is free */ period.start = t; - if (s->is_busy == 0){ + if (s->is_busy == 1){ period.end = icaltime_from_timet(s->start,0); } else { period.end = icaltime_from_timet(s->end,0); @@ -275,12 +317,11 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, /* Otherwise, find the first free span that contains the reference time. */ - - for( itr = pvl_head(impl->spans); + for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { - s = (icalproperty*)pvl_data(itr); + s = (struct icaltime_span *)pvl_data(itr); if(s->is_busy == 0 && s->start >= rangett && ( rangett < s->end || s->end == s->start)){ @@ -307,3 +348,220 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, struct icalperiodtype icalspanlist_next_busy_time(icalspanlist* sl, struct icaltimetype t); + +/** @brief Returns an hour-by-hour array of free/busy times over a + * given period. + * + * @param sl A valid icalspanlist + * @param delta_t The time slice to divide by, in seconds. Default 3600. + * + * @return A pointer to an array of integers containing the number of + * busy events in each delta_t time period. The final entry + * contains the value -1. + * + * This calculation is somewhat tricky. This is due to the fact that + * the time range contains the start time, but does not contain the + * end time. To perform a proper calculation we subtract one second + * off the end times to get a true containing time. + * + * Also note that if you supplying a spanlist that does not start or + * end on a time boundary divisible by delta_t you may get results + * that are not quite what you expect. + */ + +int* icalspanlist_as_freebusy_matrix(icalspanlist* sl, int delta_t) { + pvl_elem itr; + int spanduration_secs; + int *matrix; + int matrix_slots; + time_t sl_start, sl_end; + + icalerror_check_arg_rz( (sl!=0), "spanlist"); + + if (!delta_t) + delta_t = 3600; + + /** calculate the start and end time as time_t **/ + sl_start = icaltime_as_timet_with_zone(sl->start, icaltimezone_get_utc_timezone()); + sl_end = icaltime_as_timet_with_zone(sl->end, icaltimezone_get_utc_timezone()); + + + /** insure that the time period falls on a time boundary divisable + by delta_t */ + + sl_start /= delta_t; + sl_start *= delta_t; + + sl_end /= delta_t; + sl_end *= delta_t; + + + /** find the duration of this spanlist **/ + spanduration_secs = sl_end - sl_start; + + + /** malloc our matrix, add one extra slot for a final -1 **/ + matrix_slots = spanduration_secs/delta_t + 1; + + matrix = (int*) malloc(sizeof(int) * matrix_slots); + if (matrix == NULL) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return NULL; + } + memset(matrix, 0, sizeof(int) * matrix_slots); + matrix[matrix_slots-1] = -1; + + /* loop through each span and mark the slots in the array */ + + for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { + struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); + + if (s->is_busy == 1) { + int offset_start = s->start/delta_t - sl_start/delta_t; + int offset_end = (s->end - 1) /delta_t - sl_start/delta_t + 1; + int i; + + if (offset_end >= matrix_slots) + offset_end = matrix_slots - 1; + + i = offset_start; + for (i=offset_start; i < offset_end; i++) { + matrix[i]++; + } + } + } + return matrix; +} + + +/** @brief Return a VFREEBUSY component for the corresponding spanlist + * + * @param sl A valid icalspanlist, from icalspanlist_new() + * @param organizer The organizer specified as MAILTO:user@domain + * @param attendee The attendee specified as MAILTO:user@domain + * + * @return A valid icalcomponent or NULL. + * + * This function returns a VFREEBUSY component for the given spanlist. + * The start time is mapped to DTSTART, the end time to DTEND. + * Each busy span is represented as a separate FREEBUSY entry. + * An attendee parameter is required, and organizer parameter is + * optional. + */ + +icalcomponent *icalspanlist_as_vfreebusy(icalspanlist* sl, + const char* organizer, + const char* attendee) { + icalcomponent *comp; + icalproperty *p; + struct icaltimetype atime = icaltime_from_timet( time(0),0); + pvl_elem itr; + icaltimezone *utc_zone; + icalparameter *param; + + if (!attendee) { + icalerror_set_errno(ICAL_USAGE_ERROR); + return 0; + } + + utc_zone = icaltimezone_get_utc_timezone (); + + comp = icalcomponent_new_vfreebusy(); + + icalcomponent_add_property(comp, icalproperty_new_dtstart(sl->start)); + icalcomponent_add_property(comp, icalproperty_new_dtend(sl->end)); + icalcomponent_add_property(comp, icalproperty_new_dtstamp(atime)); + + if (organizer) { + icalcomponent_add_property(comp, icalproperty_new_organizer(organizer)); + } + icalcomponent_add_property(comp, icalproperty_new_attendee(attendee)); + + /* now add the freebusy sections.. */ + + for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { + struct icalperiodtype period; + struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); + + if (s->is_busy == 1) { + + period.start = icaltime_from_timet_with_zone (s->start, 0, utc_zone); + period.end = icaltime_from_timet_with_zone (s->end, 0, utc_zone); + period.duration = icaldurationtype_null_duration(); + + + p = icalproperty_new_freebusy(period); + param = icalparameter_new_fbtype(ICAL_FBTYPE_BUSY); + icalproperty_add_parameter(p, param); + + icalcomponent_add_property(comp, p); + } + + } + + return comp; +} + + +/** @brief Return a spanlist corresponding to the VFREEBUSY portion of + * an icalcomponent. + * + * @param c A valid icalcomponent. + * + * @return A valid icalspanlist or NULL if no VFREEBUSY section. + * + */ + + +icalspanlist *icalspanlist_from_vfreebusy(icalcomponent* comp) +{ + icalcomponent *inner; + icalproperty *prop; + icalspanlist *sl; + + icalerror_check_arg_rz((comp != NULL), "comp"); + + inner = icalcomponent_get_inner(comp); + if (!inner) return NULL; + + if ( ( sl = (icalspanlist*) malloc(sizeof(icalspanlist))) == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + sl->spans = pvl_newlist(); + + /* cycle through each FREEBUSY property, adding to the spanlist */ + for (prop = icalcomponent_get_first_property(inner, ICAL_FREEBUSY_PROPERTY); + prop != NULL; + prop = icalcomponent_get_next_property(inner, ICAL_FREEBUSY_PROPERTY)) { + icaltime_span *s = (icaltime_span *) malloc(sizeof(icaltime_span)); + icalparameter *param; + struct icalperiodtype period; + icalparameter_fbtype fbtype; + + if (s == 0) { + icalerror_set_errno(ICAL_NEWFAILED_ERROR); + return 0; + } + + param = icalproperty_get_first_parameter(prop, ICAL_FBTYPE_PARAMETER); + fbtype = (param) ? icalparameter_get_fbtype(param) : ICAL_FBTYPE_BUSY; + + switch (fbtype) { + case ICAL_FBTYPE_FREE: + case ICAL_FBTYPE_NONE: + case ICAL_FBTYPE_X: + s->is_busy = 1; + default: + s->is_busy = 0; + } + + period = icalproperty_get_freebusy(prop); + s->start = icaltime_as_timet_with_zone(period.start, icaltimezone_get_utc_timezone()); + s->end = icaltime_as_timet_with_zone(period.end, icaltimezone_get_utc_timezone()); +; + pvl_insert_ordered(sl->spans, compare_span, (void*)s); + } + /** @todo calculate start/end limits.. fill in holes? **/ + return sl; +} diff --git a/libical/src/libicalss/icalspanlist.h b/libical/src/libicalss/icalspanlist.h index 83cb1c8a6d..91f0acb8c1 100644 --- a/libical/src/libicalss/icalspanlist.h +++ b/libical/src/libicalss/icalspanlist.h @@ -28,26 +28,49 @@ #include "ical.h" #include "icalset.h" -typedef void icalspanlist; +/** @file icalspanlist.h + * @brief Code that supports collections of free/busy spans of time + */ + +typedef struct icalspanlist_impl icalspanlist; + + +/** @brief Constructor + * Make a free list from a set of component. Start and end should be in UTC + */ -/* Make a free list from a set of component. Start and end should be in UTC */ icalspanlist* icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end); +/** @brief Destructor + */ void icalspanlist_free(icalspanlist* spl); +/* Unimplemented functions */ icalcomponent* icalspanlist_make_free_list(icalspanlist* sl); icalcomponent* icalspanlist_make_busy_list(icalspanlist* sl); -/* Get first free or busy time after time t. all times are in UTC */ +/** Get first next free time after time t. all times are in UTC. */ struct icalperiodtype icalspanlist_next_free_time(icalspanlist* sl, struct icaltimetype t); +/** Get first next busy time after time t. all times are in UTC. */ struct icalperiodtype icalspanlist_next_busy_time(icalspanlist* sl, struct icaltimetype t); void icalspanlist_dump(icalspanlist* s); +/** @brief Return a valid VFREEBUSY component for this span */ +icalcomponent *icalspanlist_as_vfreebusy(icalspanlist* s_in, + const char* organizer, + const char* attendee); + +/** @brief Return an integer matrix of total events per delta_t timespan */ +int *icalspanlist_as_freebusy_matrix(icalspanlist* span, int delta_t); + +/** @brief Construct an icalspanlist from a VFREEBUSY component */ +icalspanlist *icalspanlist_from_vfreebusy(icalcomponent* c); + #endif diff --git a/libical/src/libicalss/icalspanlist_cxx.cpp b/libical/src/libicalss/icalspanlist_cxx.cpp new file mode 100644 index 0000000000..38761af4c6 --- /dev/null +++ b/libical/src/libicalss/icalspanlist_cxx.cpp @@ -0,0 +1,92 @@ +#include "icalspanlist_cxx.h" +#include <exception> + +/** @brief Construct an ICalSpanList from an icalset + @param set The icalset containing the VEVENTS + @param start Designated start of the spanlist + @param end Designated end of the spanlist +*/ + +ICalSpanList::ICalSpanList(icalset *set, icaltimetype start, icaltimetype end) throw(icalerrorenum) +{ + data = icalspanlist_new(set, start, end); + if (!data) throw icalerrno; +}; + + +/** @brief Constructor + @param comp A valid icalcomponent with a VFREEBUSY section +*/ + +ICalSpanList::ICalSpanList(icalcomponent *comp) throw(icalerrorenum) +{ + data = icalspanlist_from_vfreebusy(comp); + if (!data) throw icalerrno; +} + +/** @brief Constructor + @param comp A valid VComponent with a VFREEBUSY section +*/ +ICalSpanList::ICalSpanList(VComponent &comp) throw(icalerrorenum) +{ + data = icalspanlist_from_vfreebusy((icalcomponent*) comp); + if (!data) throw icalerrno; +} + +/** Destructor */ +ICalSpanList::~ICalSpanList() { + if (data) + icalspanlist_free(data); +} + + +/** + * @brief Returns a VFREEBUSY component for the object. + * + * @see icalspanlist_as_vfreebusy() + */ + +VComponent* +ICalSpanList::get_vfreebusy(const char *organizer, const char *attendee) throw(icalerrorenum) +{ + icalcomponent *comp; + VComponent *vcomp; + + comp = icalspanlist_as_vfreebusy(data, organizer, attendee); + if (comp == 0) throw icalerrno; + + vcomp = new VComponent(comp); + if (vcomp == 0) throw icalerrno; + + return vcomp; +} + + +/** + * @brief Returns a summary of events over delta_t + * + * @param delta_t Number of seconds to divide the spanlist time period + * into. + * + * This method calculates the total number of events in each time slot + * of delta_t seconds. + * + * @see icalspanlist_as_freebusy_matrix() + */ + +std::vector<int> ICalSpanList::as_vector(int delta_t) throw(icalerrorenum) +{ + int *matrix; + int i = 0; + std::vector<int> event_vec; + + matrix = icalspanlist_as_freebusy_matrix(data, delta_t); + + if (!matrix) throw ICAL_USAGE_ERROR; + + while (matrix[i] != -1) { + event_vec.push_back(matrix[i]); // Add item at end of vector + } + + return(event_vec); +} diff --git a/libical/src/libicalss/icalspanlist_cxx.h b/libical/src/libicalss/icalspanlist_cxx.h new file mode 100644 index 0000000000..fce901c3db --- /dev/null +++ b/libical/src/libicalss/icalspanlist_cxx.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++ -*- */ + +/** + * @file icalspanlist_cxx.h + * @author Critical Path + * @brief C++ class wrapping the icalspanlist data structure + * + * This class wraps the icalspanlist routines in libicalss + * + * Errors within libicalss are propagated via exceptions of type + * icalerrorenum. See icalerror.h for the complete list of exceptions + * that might be thrown. + */ + +#ifndef ICALSPANLIST_CXX_H +#define ICALSPANLIST_CXX_H + +#include "ical.h" +#include "icalss.h" +#include "vcomponent.h" +#include <vector> /* For as_matrix.. */ + +class ICalSpanList { + public: + /** Construct an ICalSpanList from an icalset */ + ICalSpanList(icalset *set, icaltimetype start, icaltimetype end) throw(icalerrorenum); + + /** Construct an ICalSpanList from the VFREEBUSY chunk of a icalcomponent */ + ICalSpanList(icalcomponent *comp) throw(icalerrorenum); + + /** Construct an ICalSpanList from the VFREEBUSY chunk of a vcomponent */ + ICalSpanList(VComponent &comp) throw(icalerrorenum); + + /** Destructor */ + ~ICalSpanList(); + + /** Return a VFREEBUSY icalcomponent */ + VComponent* get_vfreebusy(const char *organizer, const char *attendee) throw(icalerrorenum); + + /** Return the base data when casting */ + operator icalspanlist*() {return data;} + + /** Return a vector of the number of events over delta t */ + std::vector<int> as_vector(int delta_t) throw(icalerrorenum); + + /** Dump the spanlist to stdout */ + void dump() {icalspanlist_dump(data);} + + private: + icalspanlist *data; +}; + +#endif diff --git a/libical/src/libicalss/icalsslexer.l b/libical/src/libicalss/icalsslexer.l index 848a9bc74f..6ea9f0ef2a 100644 --- a/libical/src/libicalss/icalsslexer.l +++ b/libical/src/libicalss/icalsslexer.l @@ -6,7 +6,7 @@ DESCRIPTION: - $Id: icalsslexer.l,v 1.1.1.2 2001/01/23 19:20:41 jpr Exp $ + $Id: icalsslexer.l,v 1.2 2003/09/11 22:04:30 hansp Exp $ $Locker: $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -33,16 +33,12 @@ #include <string.h> /* For strdup() */ -int icalparser_flex_input(char* buf, int max_size); -void icalparser_clear_flex_input(); - -#undef YY_INPUT -#define YY_INPUT(b,r,ms) ( r= icalparser_flex_input(b,ms)) +#undef YYPURE +#define YYPURE #undef SS_FATAL_ERROR #define SS_FATAL_ERROR(msg) sserror(msg) - %} crlf \x0D?\x0A @@ -61,6 +57,7 @@ digit [0-9] %array /* Make yytext an array. Slow, but handy. HACK */ %option caseless +%option reentrant-bison %s sql string_value @@ -77,6 +74,7 @@ FROM { return FROM; } WHERE { return WHERE; } , { return COMMA; } "=" { return EQUALS; } +"==" { return EQUALS; } "!=" { return NOTEQUALS; } "<" { return LESS; } ">" { return GREATER; } @@ -84,29 +82,35 @@ WHERE { return WHERE; } ">=" { return GREATEREQUALS; } AND { return AND; } OR { return OR; } +IS { return IS; } +NOT { return NOT; } +NULL { return SQLNULL; } \' { return QUOTE; } [ \t\n\r]+ ; ; { return EOL; } -\'[\*A-Za-z0-9\-\.]+\' { - int c = input(); + +\'[\@\*A-Za-z0-9\-\.\:\ ]+\' { + int c = input(yy_globals); unput(c); if(c!='\''){ - sslval.v_string= icalmemory_tmp_copy(sstext); + yylvalp->v_string= icalmemory_tmp_copy(yytext); return STRING; } else { /*ssmore();*/ } } -[\*A-Za-z0-9\-\.]+ { sslval.v_string= icalmemory_tmp_copy(sstext); - return STRING; } +[\@\*A-Za-z0-9\-\.]+ { + yylval->v_string= icalmemory_tmp_copy(yytext); + return STRING; +} . { return yytext[0]; } %% -int sswrap() +int yywrap(yyscan_t yy_globals) { return 1; } diff --git a/libical/src/libicalss/icalssyacc.h b/libical/src/libicalss/icalssyacc.h index 9a933dc735..6d03a0f5ae 100644 --- a/libical/src/libicalss/icalssyacc.h +++ b/libical/src/libicalss/icalssyacc.h @@ -1,22 +1,31 @@ +#ifndef BISON_Y_TAB_H +# define BISON_Y_TAB_H + +#ifndef YYSTYPE typedef union { char* v_string; -} YYSTYPE; -#define STRING 257 -#define SELECT 258 -#define FROM 259 -#define WHERE 260 -#define COMMA 261 -#define QUOTE 262 -#define EQUALS 263 -#define NOTEQUALS 264 -#define LESS 265 -#define GREATER 266 -#define LESSEQUALS 267 -#define GREATEREQUALS 268 -#define AND 269 -#define OR 270 -#define EOL 271 -#define END 272 +} yystype; +# define YYSTYPE yystype +#endif +# define STRING 257 +# define SELECT 258 +# define FROM 259 +# define WHERE 260 +# define COMMA 261 +# define QUOTE 262 +# define EQUALS 263 +# define NOTEQUALS 264 +# define LESS 265 +# define GREATER 266 +# define LESSEQUALS 267 +# define GREATEREQUALS 268 +# define AND 269 +# define OR 270 +# define EOL 271 +# define END 272 +# define IS 273 +# define NOT 274 +# define SQLNULL 275 -extern YYSTYPE sslval; +#endif /* not BISON_Y_TAB_H */ diff --git a/libical/src/libicalss/icalssyacc.y b/libical/src/libicalss/icalssyacc.y index 047b158e93..224841f520 100644 --- a/libical/src/libicalss/icalssyacc.y +++ b/libical/src/libicalss/icalssyacc.y @@ -1,3 +1,5 @@ +%pure_parser + %{ /* -*- Mode: C -*- ====================================================================== @@ -6,7 +8,7 @@ DESCRIPTION: - $Id: icalssyacc.y,v 1.1.1.2 2001/01/23 19:20:41 jpr Exp $ + $Id: icalssyacc.y,v 1.2 2003/09/11 22:04:30 hansp Exp $ $Locker: $ (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org @@ -26,26 +28,28 @@ Code is Eric Busboom ======================================================================*/ - +/*#define YYDEBUG 1*/ #include <stdlib.h> #include <string.h> /* for strdup() */ #include <limits.h> /* for SHRT_MAX*/ #include "ical.h" -#include "pvl.h" #include "icalgauge.h" #include "icalgaugeimpl.h" -extern struct icalgauge_impl *icalss_yy_gauge; - -void ssyacc_add_where(struct icalgauge_impl* impl, char* prop, - icalgaugecompare compare , char* value); -void ssyacc_add_select(struct icalgauge_impl* impl, char* str1); -void ssyacc_add_from(struct icalgauge_impl* impl, char* str1); -void set_logic(struct icalgauge_impl* impl,icalgaugelogic l); -void sserror(char *s); /* Don't know why I need this.... */ +#define YYPARSE_PARAM yy_globals +#define YYLEX_PARAM yy_globals +#define YY_EXTRA_TYPE icalgauge_impl* + /* ick...*/ +#define yyextra ((struct icalgauge_impl*)ssget_extra(yy_globals)) +static void ssyacc_add_where(struct icalgauge_impl* impl, char* prop, + icalgaugecompare compare , char* value); +static void ssyacc_add_select(struct icalgauge_impl* impl, char* str1); +static void ssyacc_add_from(struct icalgauge_impl* impl, char* str1); +static void set_logic(struct icalgauge_impl* impl,icalgaugelogic l); +void sserror(char *s); /* Don't know why I need this.... */ %} @@ -56,49 +60,51 @@ void sserror(char *s); /* Don't know why I need this.... */ %token <v_string> STRING %token SELECT FROM WHERE COMMA QUOTE EQUALS NOTEQUALS LESS GREATER LESSEQUALS -%token GREATEREQUALS AND OR EOL END +%token GREATEREQUALS AND OR EOL END IS NOT SQLNULL %% query_min: SELECT select_list FROM from_list WHERE where_list + | SELECT select_list FROM from_list | error { - icalparser_clear_flex_input(); yyclearin; + YYABORT; } ; select_list: - STRING {ssyacc_add_select(icalss_yy_gauge,$1);} - | select_list COMMA STRING {ssyacc_add_select(icalss_yy_gauge,$3);} + STRING {ssyacc_add_select(yyextra,$1);} + | select_list COMMA STRING {ssyacc_add_select(yyextra,$3);} ; from_list: - STRING {ssyacc_add_from(icalss_yy_gauge,$1);} - | from_list COMMA STRING {ssyacc_add_from(icalss_yy_gauge,$3);} + STRING {ssyacc_add_from(yyextra,$1);} + | from_list COMMA STRING {ssyacc_add_from(yyextra,$3);} ; where_clause: /* Empty */ - | STRING EQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_EQUAL,$3); } - - | STRING NOTEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_NOTEQUAL,$3); } - | STRING LESS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESS,$3); } - | STRING GREATER STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATER,$3); } - | STRING LESSEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESSEQUAL,$3); } - | STRING GREATEREQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATEREQUAL,$3); } + | STRING EQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_EQUAL,$3); } + | STRING IS SQLNULL {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_ISNULL,""); } + | STRING IS NOT SQLNULL {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_ISNOTNULL,""); } + | STRING NOTEQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_NOTEQUAL,$3); } + | STRING LESS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_LESS,$3); } + | STRING GREATER STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_GREATER,$3); } + | STRING LESSEQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_LESSEQUAL,$3); } + | STRING GREATEREQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_GREATEREQUAL,$3); } ; where_list: - where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_NONE);} - | where_list AND where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_AND);} - | where_list OR where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_OR);} + where_clause {set_logic(yyextra,ICALGAUGELOGIC_NONE);} + | where_list AND where_clause {set_logic(yyextra,ICALGAUGELOGIC_AND);} + | where_list OR where_clause {set_logic(yyextra,ICALGAUGELOGIC_OR);} ; %% -void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, +static void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, icalgaugecompare compare , char* value_str) { @@ -160,7 +166,7 @@ void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, pvl_push(impl->where,where); } -void set_logic(struct icalgauge_impl* impl,icalgaugelogic l) +static void set_logic(struct icalgauge_impl* impl,icalgaugelogic l) { pvl_elem e = pvl_tail(impl->where); struct icalgauge_where *where = pvl_data(e); @@ -171,7 +177,7 @@ void set_logic(struct icalgauge_impl* impl,icalgaugelogic l) -void ssyacc_add_select(struct icalgauge_impl* impl, char* str1) +static void ssyacc_add_select(struct icalgauge_impl* impl, char* str1) { char *c, *compstr, *propstr; struct icalgauge_where *where; @@ -217,15 +223,15 @@ void ssyacc_add_select(struct icalgauge_impl* impl, char* str1) if(where->prop == ICAL_NO_PROPERTY){ - icalgauge_free(where); - icalerror_set_errno(ICAL_BADARG_ERROR); - return; + free(where); + icalerror_set_errno(ICAL_BADARG_ERROR); + return; } pvl_push(impl->select,where); } -void ssyacc_add_from(struct icalgauge_impl* impl, char* str1) +static void ssyacc_add_from(struct icalgauge_impl* impl, char* str1) { icalcomponent_kind ckind; @@ -241,5 +247,6 @@ void ssyacc_add_from(struct icalgauge_impl* impl, char* str1) void sserror(char *s){ - fprintf(stderr,"Parse error \'%s\'\n", s); + fprintf(stderr,"Parse error \'%s\'\n", s); + icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); } diff --git a/libical/src/libicalvcal/.cvsignore b/libical/src/libicalvcal/.cvsignore index 533caa2f3d..bbc8ba00d1 100644 --- a/libical/src/libicalvcal/.cvsignore +++ b/libical/src/libicalvcal/.cvsignore @@ -1,12 +1,5 @@ -*.la -*.lo -.libs -.deps Makefile -Makefile.in -libtool -ltconfig -ltmain.sh -stamp-h -stamp-h.in -vcc.c
\ No newline at end of file +.deps +.libs +*.lo +*.la diff --git a/libical/src/libicalvcal/Makefile.am b/libical/src/libicalvcal/Makefile.am index f9d8dd39d9..bd0320b09a 100644 --- a/libical/src/libicalvcal/Makefile.am +++ b/libical/src/libicalvcal/Makefile.am @@ -1,4 +1,4 @@ -privlib_LTLIBRARIES = libicalvcal-evolution.la +lib_LTLIBRARIES = libicalvcal.la INCLUDES = \ -I$(top_builddir) \ @@ -6,20 +6,27 @@ INCLUDES = \ -I$(top_builddir)/src/libical \ -I$(top_srcdir)/src/libicalss -libicalvcal_evolution_la_LDFLAGS = -version-info 0:0:0 +libicalvcal_la_LDFLAGS = -version-info 0:0:0 -libicalvcal_evolution_la_SOURCES = \ +if DEV +libicalvcal_la_DEVSOURCES = vcc.y +else +libicalvcal_la_DEVSOURCES = vcc.c +endif + + +libicalvcal_la_SOURCES = \ icalvcal.h \ icalvcal.c \ port.h \ vcc.h \ - vcc.y \ vobject.h \ vobject.c \ vcaltmp.h \ - vcaltmp.c + vcaltmp.c \ + $(libicalvcal_la_DEVSOURCES) -#libicalvcalincludedir = $(privincludedir)/libicalvcal +libicalvcalincludedir = $(includedir)/libicalvcal #libicalvcalinclude_HEADERS = \ # icalvcal.h \ diff --git a/libical/src/libicalvcal/icalvcal.c b/libical/src/libicalvcal/icalvcal.c index 9ab3fa899e..f5d417cb6d 100644 --- a/libical/src/libicalvcal/icalvcal.c +++ b/libical/src/libicalvcal/icalvcal.c @@ -42,6 +42,11 @@ #include "icalvcal.h" #include <string.h> +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + enum datatype { COMPONENT, PROPERTY, @@ -62,6 +67,7 @@ int weekday_codes[] = { ICAL_SATURDAY_WEEKDAY }; + struct conversion_table_struct { char* vcalname; enum datatype type; @@ -149,10 +155,10 @@ static void convert_floating_time_to_utc (struct icaltimetype *itt) } -static int icalvcal_traverse_objects(VObject *object, - icalcomponent* last_comp, - icalproperty* last_prop, - icalvcal_defaults *defaults) +static void icalvcal_traverse_objects(VObject *object, + icalcomponent* last_comp, + icalproperty* last_prop, + icalvcal_defaults *defaults) { VObjectIterator iterator; char* name = "[No Name]"; @@ -161,7 +167,8 @@ static int icalvcal_traverse_objects(VObject *object, if ( vObjectName(object)== 0){ printf("ERROR, object has no name"); - return 0; + assert(0); + return; } name = (char*)vObjectName(object); @@ -184,7 +191,8 @@ static int icalvcal_traverse_objects(VObject *object, icalproperty_set_x_name(prop,name); icalcomponent_add_property(last_comp,prop); } else { - return 0; + assert(0); + return; } } else { @@ -203,9 +211,8 @@ static int icalvcal_traverse_objects(VObject *object, object, last_comp, defaults)); if (subc) { - icalcomponent_add_component(last_comp,subc); - } - + icalcomponent_add_component(last_comp,subc); + } break; } @@ -220,7 +227,7 @@ static int icalvcal_traverse_objects(VObject *object, object, last_comp, defaults)); if (prop) - icalcomponent_add_property(last_comp,prop); + icalcomponent_add_property(last_comp,prop); last_prop = prop; @@ -260,6 +267,7 @@ static int icalvcal_traverse_objects(VObject *object, /* Do Nothing. */ break; } + } } @@ -274,16 +282,12 @@ static int icalvcal_traverse_objects(VObject *object, should use it as the 'last_comp' */ if(subc!=0){ - if (!icalvcal_traverse_objects(eachProp,subc,last_prop,defaults)) - return 0; + icalvcal_traverse_objects(eachProp,subc,last_prop,defaults); } else { - if (!icalvcal_traverse_objects(eachProp,last_comp,last_prop,defaults)) - return 0; + icalvcal_traverse_objects(eachProp,last_comp,last_prop,defaults); } } - - return 1; } icalcomponent* icalvcal_convert_with_defaults (VObject *object, @@ -309,8 +313,7 @@ icalcomponent* icalvcal_convert_with_defaults (VObject *object, printf ("===========================================\n"); #endif - if (!icalvcal_traverse_objects(object,container,0,defaults)) - return 0; + icalvcal_traverse_objects(object,container,0,defaults); /* HACK. I am using the extra 'container' component because I am lazy. I know there is a way to get rid of it, but I did not care @@ -446,7 +449,7 @@ static int get_alarm_properties (icalcomponent *comp, VObject *object, icalcomponent_add_property (comp, trigger_prop); } - + } else if (!strcmp (name, VCSnoozeTimeProp)) { struct icaldurationtype d; @@ -455,7 +458,7 @@ static int get_alarm_properties (icalcomponent *comp, VObject *object, which we don't handle at present. Though it is unlikely they will be used as a snooze time between repeated alarms! */ d = icaldurationtype_from_string (s); - + duration_prop = icalproperty_new_duration (d); icalcomponent_add_property (comp, duration_prop); @@ -531,7 +534,7 @@ static int get_alarm_properties (icalcomponent *comp, VObject *object, if (!summary_prop) { summary_prop = icalproperty_new_summary (s); icalcomponent_add_property (comp, summary_prop); - } + } } if (free_string) @@ -692,23 +695,23 @@ void* alarm_comp(int icaltype, VObject *o, icalcomponent *comp, int is_valid_alarm; icalcomponent* c = icalcomponent_new(ICAL_VALARM_COMPONENT); - + is_valid_alarm = get_alarm_properties (c, o, icaltype, defaults); if (is_valid_alarm) { - return (void*)c; + return (void*)c; } else { icalcomponent_free (c); return NULL; } } + /* These #defines indicate conversion routines that are not defined yet. */ #define parameter 0 #define rsvp_parameter 0 - void* transp_prop(int icaltype, VObject *object, icalcomponent *comp, icalvcal_defaults *defaults) { @@ -718,11 +721,12 @@ void* transp_prop(int icaltype, VObject *object, icalcomponent *comp, s = get_string_value (object, &free_string); + /* In vCalendar "0" means opaque, "1" means transparent, and >1 is implementation-specific. So we just check for "1" and output TRANSPARENT. For anything else, the default OPAQUE will be used. */ if (!strcmp (s, "1")) { - prop = icalproperty_new_transp ("TRANSPARENT"); + prop = icalproperty_new_transp (ICAL_TRANSP_TRANSPARENT); } if (free_string) @@ -731,7 +735,6 @@ void* transp_prop(int icaltype, VObject *object, icalcomponent *comp, return (void*)prop; } - void* sequence_prop(int icaltype, VObject *object, icalcomponent *comp, icalvcal_defaults *defaults) { @@ -1013,8 +1016,8 @@ static char* rrule_parse_weekly_days (char *s, e = s + 2; if (*e == ' ' || *e == '\t' || *e == '\0') { found_day = day; - break; - } + break; + } } } @@ -1067,8 +1070,8 @@ static char* rrule_parse_monthly_days (char *s, } else if (*e == '-') { e++; month_day = -month_day; - } } + } /* Check the next char is whitespace or the end of the string. */ if (*e != ' ' && *e != '\t' && *e != '\0') @@ -1388,9 +1391,10 @@ void* dc_prop(int icaltype, VObject *object, icalcomponent *comp, icalproperty *prop; icalvalue *value; icalvalue_kind value_kind; - char *s; + char *s,*t=0; int free_string; + prop = icalproperty_new(kind); value_kind = icalenum_property_kind_to_value_kind (icalproperty_isa(prop)); @@ -1418,7 +1422,6 @@ struct conversion_table_struct conversion_table[] = {VCCalProp, COMPONENT, comp, ICAL_VCALENDAR_COMPONENT}, {VCTodoProp, COMPONENT, comp, ICAL_VTODO_COMPONENT}, {VCEventProp, COMPONENT, comp, ICAL_VEVENT_COMPONENT}, - {VCAAlarmProp, COMPONENT, alarm_comp, ICAL_XAUDIOALARM_COMPONENT}, {VCDAlarmProp, COMPONENT, alarm_comp, ICAL_XDISPLAYALARM_COMPONENT}, {VCMAlarmProp, COMPONENT, alarm_comp, ICAL_XEMAILALARM_COMPONENT}, @@ -1478,7 +1481,6 @@ struct conversion_table_struct conversion_table[] = {VCSnoozeTimeProp, IGNORE,0, 0}, {VCRepeatCountProp, IGNORE,0, 0}, {VCValueProp, IGNORE,0, 0}, -{VCAudioContentProp, IGNORE,0, 0}, {VCProcedureNameProp, IGNORE,0, 0}, {VCDisplayStringProp, IGNORE,0, 0}, {VCEmailAddressProp, IGNORE,0, 0}, @@ -1495,6 +1497,7 @@ struct conversion_table_struct conversion_table[] = {VCAppleLinkProp, UNSUPPORTED,0, 0}, {VCAttachProp, UNSUPPORTED,0, 0}, {VCATTMailProp, UNSUPPORTED,0, 0}, +{VCAudioContentProp, UNSUPPORTED,0, 0}, {VCAVIProp, UNSUPPORTED,0, 0}, {VCBase64Prop, UNSUPPORTED,0, 0}, {VCBBSProp, UNSUPPORTED,0, 0}, diff --git a/libical/src/libicalvcal/icalvcal.h b/libical/src/libicalvcal/icalvcal.h index 96e94b9f2e..67119ce042 100644 --- a/libical/src/libicalvcal/icalvcal.h +++ b/libical/src/libicalvcal/icalvcal.h @@ -44,10 +44,10 @@ struct _icalvcal_defaults { icalcomponent* icalvcal_convert(VObject *object); + icalcomponent* icalvcal_convert_with_defaults (VObject *object, icalvcal_defaults *defaults); - #endif /* !ICALVCAL_H */ diff --git a/libical/src/libicalvcal/vcc.y b/libical/src/libicalvcal/vcc.y index 5338f563a6..245774f37e 100644 --- a/libical/src/libicalvcal/vcc.y +++ b/libical/src/libicalvcal/vcc.y @@ -56,6 +56,11 @@ DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. #define DBG_(x) #endif +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + /**** External Functions ****/ /* assign local name to parser variables and functions so that @@ -419,7 +424,7 @@ static void enterValues(const char *value) using ';' to separate the values. */ if (vObjectUStringZValue(curProp)) { p1 = fakeCString(vObjectUStringZValue(curProp)); - p2 = malloc((strlen(p1)+strlen(value)+2)); + p2 = malloc((strlen(p1)+strlen(value)+1)); strcpy(p2, p1); deleteStr(p1); @@ -432,7 +437,7 @@ static void enterValues(const char *value) setVObjectUStringZValue_(curProp,fakeUnicode(p2,0)); deleteStr(p2); } else { - setVObjectUStringZValue_(curProp,fakeUnicode(value,0)); + setVObjectUStringZValue_(curProp,fakeUnicode(value,0)); } } } diff --git a/libical/src/libicalvcal/vobject.c b/libical/src/libicalvcal/vobject.c index b17830eb72..616581ffa8 100644 --- a/libical/src/libicalvcal/vobject.c +++ b/libical/src/libicalvcal/vobject.c @@ -42,6 +42,11 @@ DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. * vobject, and convert a vobject into its textual representation. */ +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + #include "vobject.h" #include <stdlib.h> #include <string.h> @@ -1244,9 +1249,10 @@ static void writeGroup(OFile *fp, VObject *o) char buf2[256]; strcpy(buf1,NAME_OF(o)); while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { - strcpy(buf2,STRINGZ_VALUE_OF(o)); - strcat(buf2,"."); - strcat(buf2,buf1); + strncpy(buf2,STRINGZ_VALUE_OF(o),sizeof(buf2)); + buf2[sizeof(buf2)-1] = '\0'; + strncat(buf2,".",sizeof(buf2)-strlen(buf2)-1); + strncat(buf2,buf1,sizeof(buf2)-strlen(buf2)-1); strcpy(buf1,buf2); } appendsOFile(fp,buf1); diff --git a/libical/src/python/.cvsignore b/libical/src/python/.cvsignore index 3dda72986f..801247a12c 100644 --- a/libical/src/python/.cvsignore +++ b/libical/src/python/.cvsignore @@ -1,2 +1,9 @@ -Makefile.in Makefile +.deps +.libs +*.lo +*.la +*.pyc +LibicalWrap.c +LibicalWrap_wrap.doc +config.c diff --git a/libical/src/python/Attendee.py b/libical/src/python/Attendee.py new file mode 100644 index 0000000000..52001ba3e8 --- /dev/null +++ b/libical/src/python/Attendee.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python +# -*- Mode: python -*- +#====================================================================== +# FILE: Property.py +# CREATOR: eric +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org> +# (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +#====================================================================== + +from LibicalWrap import * +from Property import Property +from types import DictType, StringType, IntType + +class Attendee(Property): + """Class for Attendee properties. + + Usage: + Attendee([dict]) + Attendee([address]) + + Where: + dict is an optional dictionary with keys of + 'value': CAL-ADDRESS string and any parameter: parameter_value entries. + 'name' and 'value_type' entries in dict are ignored and automatically set + with the appropriate values. + address is the CAL-ADDRESS (string) of the Attendee + """ + + def __init__(self, arg={}): + + assert(isinstance(arg,DictType)) + + ref = None + + if arg!={}: + ref = arg['ref'] + + Property.__init__(self,type='ATTENDEE',ref=ref) + + def _doParam(self, parameter, v): + if v!=None: + self[parameter]=v + return self[parameter] + + # Methods for accessing enumerated parameters + def cn(self, v=None): self._doParam('CN', v) + def cutype(self, v=None): self._doParam('CUTYPE', v) + def dir(self, v=None): self._doParam('DIR', v) + def delegated_from(self, v=None): self._doParam('DELEGATED-FROM', v) + def delegated_to(self, v=None): self._doParam('DELEGATED-TO', v) + def language(self, v=None): self._doParam('LANGUAGE', v) + def member(self, v=None): self._doParam('MEMBER', v) + def partstat(self, v=None): self._doParam('PARTSTAT', v) + def role(self, v=None): self._doParam('ROLE', v) + def rsvp(self, v=None): self._doParam('RSVP', v) + def sent_by(self, v=None): self._doParam('SENT-BY', v) + + +class Organizer(Property): + """Class for Organizer property. + """ + + def __init__(self, arg={}): + + assert(isinstance(arg, DictType)) + + ref = None + if arg != {}: + ref = arg['ref'] + Property.__init__(self, type='ORGANIZER', ref=ref) + +## param_t = ( 'CN', 'DIR', 'SENT-BY', 'LANGUAGE' ) +## for param in param_t: +## self[param] = None +## if value != None: +## self.value(value) + + + def _doParam(self, parameter, v): + if v!=None: + self[parameter]=v + return self[parameter] + + def name(self): + "Return the name of the property." + return Property.name(self) + + def value_type(self): + "Return the value type of the property." + return self._desc['value_type'] + + # Methods for accessing enumerated parameters + def cn(self, v=None): self._doParam('CN', v) + def dir(self, v=None): self._doParam('DIR', v) + def language(self, v=None): self._doParam('LANGUAGE', v) + def sent_by(self, v=None): self._doParam('SENT-BY', v) diff --git a/libical/src/python/ChangeLog b/libical/src/python/ChangeLog index 7b16306ce5..ef096f4e3a 100644 --- a/libical/src/python/ChangeLog +++ b/libical/src/python/ChangeLog @@ -1,3 +1,23 @@ +2001-04-04 Eric Busboom <eric@softwarestudio.org> + + * Component.py Added Calendar class. + + * Componeny.py Changed all component constructor so they cannot + take string arguments. Now, only NewComponent() can turn an iCal + string into a component. + + +2001-04-02 Eric Busboom <eric@softwarestudio.org> + + * Component.py removed arguments from the Event constructor, since + I presume that the Component derived classes will always be + constructed with no arguments. + + * Property.py Split out Attendee, Organizer, Time, Duration and + Period into their own files. Moved remaining classes to Derived + Properties.pm + + 2001-03-13 Eric Busboom <eric@softwarestudio.org> * Component.py Added Component.property() diff --git a/libical/src/python/Component.py b/libical/src/python/Component.py index f4399f6c20..41ef7419db 100644 --- a/libical/src/python/Component.py +++ b/libical/src/python/Component.py @@ -26,29 +26,39 @@ #====================================================================== from LibicalWrap import * -from types import * -from Property import * +from types import DictType, StringType, IntType +from Property import Property from Collection import * +from Attendee import Attendee, Organizer +from Time import Time +from Duration import Duration +from Period import Period +import string + +WrapperNULL = None class Component: - def __init__(self,str=None, component_kind="ANY", ref=None): + def __init__(self,ref=None,kind=None): - if ref != None: + if ref != None: self._ref = ref + elif kind != None: + self._ref = icalcomponent_new( + icalcomponent_string_to_kind("VCALENDAR")) + _kind = icalcomponent_string_to_kind(kind) + inner = icalcomponent_new(_kind) + + icalcomponent_add_component(self._ref,inner); + else: - self._ref = None - if str != None: - self._ref = icalparser_parse_string(str) - else: - kind = icalenum_string_to_component_kind(component_kind) - self._ref = icalcomponent_new(kind) - + raise "Could not construct component of kind" + kind + self.cached_props = {} + self.cached_comps = {} def __del__(self): - if self._ref != None and \ - icalcomponent_get_parent(self._ref) != None: + if self._ref != None and icalcomponent_get_parent(self._ref) != WrapperNULL: for k in self.cached_props.keys(): del self.cached_props[k] @@ -58,10 +68,19 @@ class Component: def _prop_from_ref(self,p): - d_string = icallangbind_property_eval_string(p,":") - d = eval(d_string) + if(p == None or p== WrapperNULL): + return None; + + d = {} + d['value'] = icalproperty_get_value_as_string(p) + d['name'] = icalproperty_get_name(p) + + propkind = icalproperty_string_to_kind(d['name']) + kind = icalproperty_kind_to_value_kind(propkind) + d['value_type'] = icalvalue_kind_to_string(kind) d['ref'] = p - + + if not self.cached_props.has_key(p): if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE': @@ -85,7 +104,7 @@ class Component: p = icallangbind_get_first_property(self._ref,type) - if p !='NULL': + if p !=WrapperNULL: self._prop_from_ref(p) prop = self.cached_props[p] return prop @@ -102,8 +121,9 @@ class Component: p = icallangbind_get_first_property(self._ref,type) - while p !='NULL': - self._prop_from_ref(p) + while p !=WrapperNULL and p != None: + + self._prop_from_ref(p) # Puts property in self.cached_props prop = self.cached_props[p] props.append(prop) p = icallangbind_get_next_property(self._ref,type) @@ -122,12 +142,12 @@ class Component: s = str(prop) prop_p = icalproperty_new_from_string(s) - if prop_p == 'NULL': + if prop_p == WrapperNULL: raise "Bad property string: " + s prop.ref(prop_p) - if icalproperty_get_parent(prop_p)=='NULL': + if icalproperty_get_parent(prop_p)==WrapperNULL: icalcomponent_add_property(self._ref, prop_p) elif icalproperty_get_parent(prop_p) != self._ref: raise "Property is already a child of another component" @@ -143,16 +163,48 @@ class Component: def components(self,type='ANY'): comps = [] + kind = icalcomponent_string_to_kind(type) + c = icalcomponent_get_first_component(self._ref,kind); + + while c != WrapperNULL and c != None: + + if not self.cached_comps.has_key(c): + + self.cached_comps[c] = Component(c) + + comp = self.cached_comps[c] + comps.append(comp) + c = icalcomponent_get_next_component(self._ref,kind); + return comps - def add_component(self, componentObj): - "Adds a child component." - pass + def inner_component(self): + inner = icalcomponent_get_inner(self._ref) + + if inner == WrapperNULL and inner != None: + return None - def remove_component(self, component): + return NewComponent(inner) + + def add_component(self, comp): + "Adds a child component." + + if not isinstance(comp,Component): + raise ValueError("Expected a Component") + + if icalcomponent_get_parent(comp._ref) != WrapperNULL: + raise "Failed to add child component. Child already has a parent"; + + icalcomponent_add_component(self._ref,comp._ref) + + def remove_component(self, comp): "Removes a child component" - pass + + if not isinstance(comp,Component): + raise ValueError("Expected a Component") + + icalcomponent_remove_component(self._ref,comp._ref) def as_ical_string(self): return self.__str__() @@ -161,32 +213,72 @@ class Component: return icalcomponent_as_ical_string(self._ref) + def ref(self): + """ Return the internal reference to the libical icalproperty """ + return self._ref + +def CloneComponent(c): + "Clones a string or C icalcomponent into the right component object." + + wasStr=0 # Were we passed a string or an icalcomponent? + + if isinstance(c, Component): + comp = icalparser_parse_string(c.as_ical_string()) + elif isinstance (c, StringType) and string.find(c,"icalcomponent") == -1: + comp = icalparser_parse_string(c) + else: + comp = c + + if comp == None or comp == WrapperNULL: + raise ValueError("Expected a libical reference or an iCal string") + + kind = icalcomponent_isa(comp) + kindStr = icalcomponent_kind_to_string(kind) + + if kindStr == 'VCALENDAR': + inner = icalcomponent_get_inner(comp) + kind = icalcomponent_isa(inner) + kindStr = icalcomponent_kind_to_string(kind) + + if kindStr == 'VEVENT': + newComp = Event(comp) + elif kindStr == 'VTODO': + newComp = Todo(comp) + elif kindStr == 'VJOURNAL': + newComp = Journal(comp) + else: + newComp = Component(comp) + + # I don't think I need to free the component created when passed a string, + # as it wasn't created with a _new function. + + return newComp -def NewComponent(comp): +def NewComponent(c): "Converts a string or C icalcomponent into the right component object." wasStr=0 # Were we passed a string or an icalcomponent? - if isinstance (comp, StringType): - compStr = comp - comp = icalparser_parse_string(comp) - wasStr=1 + if isinstance (c, StringType) and string.find(c,"icalcomponent") == -1: + comp = icalparser_parse_string(c) else: - compStr = icalcomponent_as_ical_string(comp) + comp = c + + if comp == None or comp == WrapperNULL: + raise ValueError("Expected a libical reference or an iCal string") kind = icalcomponent_isa(comp) - kindStr = icalenum_component_kind_to_string(kind) - # Do I need to free kind? (I think not). + kindStr = icalcomponent_kind_to_string(kind) if kindStr == 'VEVENT': - newComp = Event(compStr) + newComp = Event(comp) elif kindStr == 'VTODO': - newComp = Todo(compStr) + newComp = Todo(comp) elif kindStr == 'VJOURNAL': - newComp = Journal(compstr) + newComp = Journal(comp) else: - newComp = Component(compStr) + newComp = Component(comp) # I don't think I need to free the component created when passed a string, # as it wasn't created with a _new function. @@ -196,9 +288,16 @@ def NewComponent(comp): class GenericComponent(Component): - def __init__(self): - - # Component.__init__(self, str) # Call from subclasses + def __init__(self,ref=None,kind=None): + + if ref != None: + Component.__init__(self, ref=ref) # Call from subclasses + elif type != None: + Component.__init__(self, kind=kind) # Call from subclasses + else: + raise ValueError("Expected either a icalcomponent reference or a kind string") + + self._recurrence_set=None def _singular_property(self, name, value_type, value=None, @@ -208,14 +307,23 @@ class GenericComponent(Component): This is a constructor method for properties without a strictly defined object.""" - curr_properties = self.properties(name) + # Depending on the property name, this routine will either + # operate on the VCALENDAR container or on the inner VEVENT, + # VTODO, or VJOURNAL + + if name in ['METHOD','PRODID','CALSCALE','VERSION']: + comp = self + else: + comp = self.inner_component() + + curr_properties = comp.properties(name) # Get the value if value==None: if len(curr_properties) == 0: return None elif len(curr_properties) == 1: - return curr_properties[0].value() + return curr_properties[0] else: raise ValueError, "too many properties of type %s" % propType @@ -223,7 +331,7 @@ class GenericComponent(Component): else: # Check if value is in enumerated_values if enumerated_values: - value = upper(value) + value = string.upper(value) if value not in enumerated_values: raise ValueError, "%s is not one of %s" \ % (value, enumerated_values) @@ -235,6 +343,8 @@ class GenericComponent(Component): if property_obj == Time: p = Time(value, name) ## p.value_type(value_type) + elif property_obj == Duration: + p = Duration(value) else: p = property_obj() ## p.value_type(value_type) @@ -248,12 +358,15 @@ class GenericComponent(Component): p.value(value) if len(curr_properties) == 1: - self.remove_property(curr_properties[0]) + comp.remove_property(curr_properties[0]) elif len(curr_properties) > 1: raise ValueError, "too many properties of type %s" % propType - self.add_property(p) - + comp.add_property(p) + + # METHOD, PRODID, CALSCALE and VERSION are properties of the + # VCALENDAR, not the inner component + def method(self, v=None): "Sets or returns the value of the METHOD property." return self._singular_property("METHOD", "TEXT", v) @@ -266,10 +379,20 @@ class GenericComponent(Component): "Sets or returns the value of the CALSCALE property." return self._singular_property("CALSCALE", "TEXT", v) + def version(self, v=None): + "Sets or returns the value of the Version property." + return self._singular_property("VERSION", "TEXT", v) + + # The remaining properties are all in the inner component + + def clone(self): + "Returns a copy of the object." + return CloneComponent(self) + def class_prop(self, v=None): # Class is a reserved word "Sets or returns the value of the CLASS property." if v!=None: - v = upper(v) + v = string.upper(v) return self._singular_property('CLASS', 'TEXT', v) def created(self, v=None): @@ -313,10 +436,10 @@ class GenericComponent(Component): """Sets or returns the value of the LAST-MODIFIED property. Usage: - lastmodified(time_obj) # Set the value using a Time object - lastmodified('19970101T123000Z')# Set using an iCalendar string - lastmodified(982362522) # Set using seconds - lastmodified() # Return an iCalendar string + last_modified(time_obj) # Set the value using a Time object + last_modified('19970101T123000Z')# Set using an iCalendar string + last_modified(982362522) # Set using seconds + last_modified() # Return an iCalendar string """ return self._singular_property("LAST-MODIFIED", "DATE-TIME", v, Time) @@ -389,7 +512,7 @@ class GenericComponent(Component): """ if values!=None: for alarm in values: - self.addComponent(alarm) + self.add_component(alarm) else: return ComponentCollection(self, self.components('VALARM')) @@ -401,6 +524,8 @@ class GenericComponent(Component): property_obj=None): "Processes set/get for Properties that can have multiple instances." + comp = self.inner_component() + # Set value if values!=None: if not isinstance(values, TupleType) \ @@ -408,8 +533,8 @@ class GenericComponent(Component): raise TypeError, "%s is not a tuple or list." # Delete old properties - for p in self.properties(name): - self.remove_property(p) + for p in comp.properties(name): + comp.remove_property(p) for v in values: if property_obj: # Specialized properties @@ -419,16 +544,15 @@ class GenericComponent(Component): else: # Use existing object new_prop = v else: # Generic properties - new_prop= Property() - new_prop.name(name) + new_prop=Property(name) # new_prop.value_type(value_type) new_prop.value(v) - self.add_property(new_prop) + comp.add_property(new_prop) # Get value else: - return Collection(self, self.properties(name)) + return Collection(self, comp.properties(name)) def attachments(self, values=None): """Sets or returns a Collection of Attach properties. @@ -490,25 +614,26 @@ class GenericComponent(Component): return self._multiple_properties('CONTACT', 'TEXT', value) def related_tos(self, value=None): - "Sets or returns a Collectoin of RELATED-TO properties." + "Sets or returns a Collection of RELATED-TO properties." return self._multiple_properties('RELATED-TO', 'TEXT', value) + def x_properties(self, name, value=None): + "Sets or returns a Collection of X- properties." + return self._multiple_properties(name, 'TEXT', value) class Event(GenericComponent): "The iCalendar Event object." - def __init__(self, str=None): - Component.__init__(self, str, "VEVENT") - GenericComponent.__init__(self) + def __init__(self,ref=None): + if ref != None: + GenericComponent.__init__(self, ref=ref) + else: + GenericComponent.__init__(self, kind='VEVENT') def component_type(self): "Returns the type of component for the object." return "VEVENT" - def clone(self): - "Returns a copy of the object." - return Event(self.asIcalString()) - def dtend(self, v=None): """Sets or returns the value of the DTEND property. @@ -541,7 +666,7 @@ class Event(GenericComponent): """ if v != None: - dtend = self.properites('DTEND') + dtend = self.properties('DTEND') for d in dtend: self.remove_property(d) # Clear DTEND properties return self._singular_property("DURATION", "DURATION", v, Duration) @@ -601,14 +726,17 @@ class Event(GenericComponent): class Todo(GenericComponent): "The iCalendar TODO component." + def __init__(self,ref=None): + if ref != None: + GenericComponent.__init__(self, ref=ref) + else: + GenericComponent.__init__(self, kind='VTODO') + + def component_type(self): "Returns the type of component for the object." return "VTODO" - def clone(self): - "Returns a copy of the object." - return Todo(self.asIcalString()) - def completed(self, value=None): return self._singular_property('COMPLETED', 'DATE-TIME', value, Time) @@ -627,7 +755,7 @@ class Todo(GenericComponent): def status(self, value=None): if value!=None: - value=upper(value) + value=string.upper(value) ok_values = ('NEEDS-ACTION', 'COMPLETED', 'IN-PROCESS', 'CANCELLED') return self._singular_property('STATUS', 'TEXT', value, enumerated_values=ok_values) @@ -648,22 +776,23 @@ class Todo(GenericComponent): def resources(): pass - class Journal(GenericComponent): "The iCalendar JOURNAL component." + def __init__(self): + if ref != None: + GenericComponent.__init__(self, ref=ref) + else: + GenericComponent.__init__(self, kind='VJOURNAL') + def component_type(self): "Returns the type of component for the object." return "VJOURNAL" - def clone(self): - "Returns a copy of the object." - return Journal(self.asIcalString()) - def status(self, v=None): if v!=None: - v = upper(v) + v = string.upper(v) ok_values=('DRAFT', 'FINAL', 'CANCELLED') return self._singular_property('STATUS', 'TEXT', v, enumerated_values=ok_values) diff --git a/libical/src/python/DerivedProperties.py b/libical/src/python/DerivedProperties.py index b557a1f7d7..81248fe7b7 100644 --- a/libical/src/python/DerivedProperties.py +++ b/libical/src/python/DerivedProperties.py @@ -25,7 +25,10 @@ # the License at http://www.mozilla.org/MPL/ #====================================================================== -from Property import Time, Period, Duration +from Property import Property +from Time import Time +from Period import Period +from Duration import Duration def RDate(arg): @@ -57,3 +60,100 @@ def Trigger(arg): +class Recurrence_Id(Time): + """Class for RECURRENCE-ID property. + + Usage: + Reccurence_Id(dict) # A normal property dictionary + Reccurence_Id("19960401") # An iCalendar string + Reccurence_Id(8349873494) # Seconds from epoch + + If the 'dict' constructor is used, 'name' and 'value_type' + entries in dict are ignored and automatically set with the appropriate + values. + """ + + def __init__(self, dict={}): + Time.__init__(self, dict) + Property.name(self, 'RECURRENCE-ID') + + def name(self): + return Property.name(self) + + def _doParam(self, parameter, v): + if v!=None: + self[parameter]=v + return self[parameter] + + # Enumerated parameters + def value_parameter(self, v=None): + """Sets or gets the VALUE parameter value. + + The value passed should be either "DATE-TIME" or "DATE". Setting this + parameter has no impact on the property's value_type. Doing something + like: + + rid=Recurrence_Id("19960401") # Sets value & makes value_type="DATE" + rid.value_parameter("DATE-TIME") # Sets the parameter VALUE=DATE-TIME + + Would be allowed (even though it is wrong), so pay attention. + Verifying the component will reveal the error. + """ + if v!=None and v!="DATE" and v!="DATE-TIME": + raise ValueError, "%s is an invalid VALUE parameter value" % str(v) + self._doParam("VALUE", v) + + def tzid(self, v=None): + "Sets or gets the TZID parameter value." + self._doParam("TZID", v) + + def range_parameter(self, v=None): # 'range' is a builtin function + "Sets or gets the RANGE parameter value." + if v!=None and v!="THISANDPRIOR" and v!= "THISANDFUTURE": + raise ValueError, "%s is an invalid RANGE parameter value" % str(v) + self._doParam("RANGE", v) + +class Attach(Property): + """A class representing an ATTACH property. + + Usage: + Attach(uriString [, parameter_dict]) + Attach(fileObj [, parameter_dict]) + """ + + def __init__(self, value=None, parameter_dict={}): + Property.__init__(self, parameter_dict) + Property.name(self, 'ATTACH') + self.value(value) + + def value(self, v=None): + "Returns or sets the value of the property." + if v != None: + if isinstance(v, StringType): # Is a URI + self._desc['value']=v + Property.value_type(self, 'URI') + else: + try: + tempStr = v.read() + except: + raise TypeError,"%s must be a URL string or file-ish type"\ + % str(v) + self._desc['value'] = base64.encodestring(tempStr) + Property.value_type(self, 'BINARY') + else: + return self._desc['value'] + + def name(self): + "Returns the name of the property." + return Property.name(self) + + def value_type(self): + return Property.value_type(self) + + def fmttype(self, v=None): + "Gets or sets the FMTYPE parameter." + if v!= None: + self['FMTTYPE']=v + else: + return self['FMTTYPE'] + diff --git a/libical/src/python/Duration.py b/libical/src/python/Duration.py new file mode 100644 index 0000000000..e6c642a8f7 --- /dev/null +++ b/libical/src/python/Duration.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# -*- Mode: python -*- +#====================================================================== +# FILE: Duration.py +# CREATOR: eric +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org> +# (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +#=============================================================== + +from LibicalWrap import * +from Property import Property +from types import DictType, StringType, IntType + +class Duration(Property): + """ + Represent a length of time, like 3 minutes, or 6 days, 20 seconds. + + + """ + + def __init__(self, arg, name="DURATION"): + """ + Create a new duration from an RFC2445 string or number of seconds. + Construct the duration from an iCalendar string or a number of seconds. + + Duration("P3DT2H34M45S") Construct from an iCalendar string + Duration(3660) Construct from seconds + """ + + self.dur = None + + e=icalerror_supress("MALFORMEDDATA") + + if isinstance(arg, DictType): + + self.dur = icaldurationtype_from_string(arg['value']) + Property.__init__(self,ref=arg['ref']) + else: + if isinstance(arg, StringType): + self.dur = icaldurationtype_from_string(arg) + elif isinstance(arg, IntType): + self.dur = icaldurationtype_from_int(arg) + elif isinstance(arg,Duration): + self.dur = arg.dur + else: + self.dur = icaldurationtype_null_duration() + + Property.__init__(self,type=name) + + icalerror_restore("MALFORMEDDATA",e) + + if self.dur == None or icaldurationtype_is_null_duration(self.dur): + raise Property.ConstructorFailedError("Failed to construct Duration from " +str(arg)) + + try: + self._update_value() + except Property.UpdateFailedError: + raise Property.ConstructorFailedError("Failed to construct Duration from " + str(arg)) + + def _update_value(self): + + self.value(icaldurationtype_as_ical_string(self.dur),"DURATION") + + def valid(self): + "Return true if this is a valid duration" + + return not icaldurationtype_is_null_duration(self.dur) + + def seconds(self,v=None): + """Return or set duration in seconds""" + if(v != None): + self.dur = icaldurationtype_from_int(v); + self.dict['value'] = icaltimedurationtype_as_ical_string(self.dur) + return icaldurationtype_as_int(self.dur) diff --git a/libical/src/python/Error.py b/libical/src/python/Error.py new file mode 100644 index 0000000000..912553d14e --- /dev/null +++ b/libical/src/python/Error.py @@ -0,0 +1,10 @@ + + +class LibicalError(Exception): + "Libical Error" + + def __init__(self,str): + Exception.__init__(self,str) + + def __str__(self): + return Exception.__str__(self)+"\nLibical errno: "+icalerror_perror() diff --git a/libical/src/python/Gauge.py b/libical/src/python/Gauge.py new file mode 100644 index 0000000000..ec859055fb --- /dev/null +++ b/libical/src/python/Gauge.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*- Mode: python -*- +#====================================================================== +# FILE: Gauge.py +# CREATOR: mtearle +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org> +# (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +#====================================================================== + +from LibicalWrap import * +from Error import LibicalError +from Component import Component + +class Gauge: + """ + Base class for gauge + """ + + class ConstructorFailedError(LibicalError): + "Failed to create a Guage " + + class CloneFailedError(LibicalError): + "Failed to clone a component given Gauge " + + class CompareFailedError(LibicalError): + "Failed to compare a component given Gauge " + + def __init__(self,ref=None,sql=None,expand=0): + if ref != None: + self._ref = ref + elif sql != None: + s = str(sql) + self._ref = icalgauge_new_from_sql(s,expand) + else: + Gauge.ConstructorFailedError("No SQL Specified") + + def __del__(self): + if self._ref != None: + icalgauge_free(self._ref) + self._ref = None + + def ref(self): + return self._ref + + def compare(self, comp): + if not isinstance(comp,Component): + raise Gauge.CompareFailedError("Argument is not a component") + + if comp.ref() == None: + raise Gauge.CompareFailedError("Argument is not a component") + + return icalgauge_compare(self._ref, comp.ref()) + + # Pending Implementation + #def as_sql_string(self): + # return self.__str__() + + #def __str__(self): + # return icalgauge_as_sql(self._ref) + + #def clone(self, comp): +# if not isinstance(comp,Component): +# raise Gauge.CloneFailedError("Argument is not a component") +# +# comp_ref = icalgauge_new_clone(self._ref, comp) +# +# if comp_ref == None: +# return None +# +# return Component(ref=comp_ref) diff --git a/libical/src/python/Libical.py b/libical/src/python/Libical.py index 78a0fff8ff..9cf5076520 100644 --- a/libical/src/python/Libical.py +++ b/libical/src/python/Libical.py @@ -25,15 +25,12 @@ # the License at http://www.mozilla.org/MPL/ #====================================================================== - -import LibicalWrap - from Component import Component, NewComponent, Event, Todo, Journal - -# Will eventually remove Time for real Property events -from Property import Property, Time, Duration, Period, Attendee, Organizer, \ - Recurrence_Id, Attach, RecurrenceSet - -from DerivedProperties import RDate, Trigger - +from Property import Property, RecurrenceSet, test_enum +from Time import Time +from Period import Period +from Duration import Duration +from Attendee import Attendee, Organizer +from DerivedProperties import RDate, Trigger,Recurrence_Id, Attach from Store import Store, FileStore +from Gauge import Gauge diff --git a/libical/src/python/LibicalWrap.i b/libical/src/python/LibicalWrap.i index c6b6740383..bf3e19c1d9 100644 --- a/libical/src/python/LibicalWrap.i +++ b/libical/src/python/LibicalWrap.i @@ -43,10 +43,15 @@ typedef void icalproperty; icalcomponent* icalparser_parse_string(char* str); +/* actually takes icalcomponent_kind */ icalcomponent* icalcomponent_new(int kind); icalcomponent* icalcomponent_new_clone(icalcomponent* component); icalcomponent* icalcomponent_new_from_string(char* str); +const char* icalcomponent_kind_to_string(int kind); +int icalcomponent_string_to_kind(const char* string); + + char* icalcomponent_as_ical_string(icalcomponent* component); void icalcomponent_free(icalcomponent* component); @@ -75,12 +80,19 @@ void icalcomponent_remove_property(icalcomponent* component, icalproperty* property); +void icalcomponent_add_component(icalcomponent* parent, + icalcomponent* child); + +void icalcomponent_remove_component(icalcomponent* parent, + icalcomponent* child); + +icalcomponent* icalcomponent_get_inner(icalcomponent* comp); + icalcomponent* icalcomponent_get_parent(icalcomponent* component); int icalcomponent_isa(icalcomponent* component); int icalrestriction_check(icalcomponent* comp); - /* actually takes icalproperty_kind */ icalproperty* icalproperty_new(int kind); @@ -90,44 +102,59 @@ char* icalproperty_as_ical_string(icalproperty *prop); void icalproperty_set_parameter_from_string(icalproperty* prop, const char* name, const char* value); -void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char * kind); - -const char* icalproperty_get_value_as_string(icalproperty* prop); const char* icalproperty_get_parameter_as_string(icalproperty* prop, const char* name); +void icalproperty_remove_parameter_by_name(icalproperty* prop, + const char *name); +void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char * kind); +const char* icalproperty_get_value_as_string(icalproperty* prop); icalcomponent* icalproperty_get_parent(icalproperty* property); +const char* icalproperty_kind_to_string(int kind); +int icalproperty_string_to_kind(const char* string); +int icalproperty_string_to_enum(const char* str); +int icalproperty_enum_belongs_to_property(int kind, int e); +int icalproperty_kind_to_value_kind(int kind); + +/* Deal with X properties */ + +void icalproperty_set_x_name(icalproperty* prop, const char* name); +const char* icalproperty_get_x_name(icalproperty* prop); + +/* Return the name of the property -- the type name converted to a + string, or the value of _get_x_name if the type is and X property */ +const char* icalproperty_get_name (const icalproperty* prop); + + int icalerror_supress(const char* error); void icalerror_restore(const char* error, int es); char* icalerror_perror(); void icalerror_clear_errno(void); -const char* icalproperty_kind_to_string(int kind); -int icalproperty_string_to_kind(const char* string); -int icalproperty_kind_to_value_kind(int kind); const char* icalvalue_kind_to_string(int kind); int icalvalue_string_to_kind(const char* str); +char* icalparameter_as_ical_string(icalparameter* parameter); + const char* icalparameter_kind_to_string(int kind); int icalparameter_string_to_kind(const char* string); -const char* icalenum_component_kind_to_string(int kind); -int icalenum_string_to_component_kind(const char* string); - int* icallangbind_new_array(int size); void icallangbind_free_array(int* array); int icallangbind_access_array(int* array, int index); +/* int icalrecur_expand_recurrence(char* rule, int start, + int count, int* array);*/ int icalrecur_expand_recurrence(char* rule, int start, - int count, int* array); + int count, time_t* array); -/* Iterate through properties and components using strings for the kind */ +/* Iterate through properties, components and parameters using strings for the kind */ icalproperty* icallangbind_get_first_property(icalcomponent *c, const char* prop); @@ -140,6 +167,10 @@ icalcomponent* icallangbind_get_first_component(icalcomponent *c, icalcomponent* icallangbind_get_next_component(icalcomponent *c, const char* comp); +icalparameter* icallangbind_get_first_parameter(icalproperty *prop); + +icalparameter* icallangbind_get_next_parameter(icalproperty *prop); + /* Return a string that can be evaluated in perl or python to generated a hash that holds the property's name, value and @@ -149,6 +180,8 @@ const char* icallangbind_property_eval_string(icalproperty* prop, char* sep); int icallangbind_string_to_open_flag(const char* str); +const char* icallangbind_quote_as_ical(const char* str); + /*********************************************************************** Time routines ***********************************************************************/ @@ -162,22 +195,20 @@ struct icaltimetype int hour; int minute; int second; - - int is_utc; /* 1-> time is in UTC timezone */ - - int is_date; /* 1 -> interpret this as date. */ - - const char* zone; /*Ptr to Olsen placename. Libical does not own mem*/ }; /* Convert seconds past UNIX epoch to a timetype*/ struct icaltimetype icaltime_from_timet(int v, int is_date); +/** Convert seconds past UNIX epoch to a timetype, using timezones. */ +struct icaltimetype icaltime_from_timet_with_zone(int tm, + int is_date, icaltimezone *zone); + /* Return the time as seconds past the UNIX epoch */ /* Normally, this returns a time_t, but SWIG tries to turn that type into a pointer */ -int icaltime_as_timet(struct icaltimetype); +int icaltime_as_timet(struct icaltimetype tt); /* Return a string represention of the time, in RFC2445 format. The string is owned by libical */ @@ -187,19 +218,6 @@ char* icaltime_as_ical_string(struct icaltimetype tt); struct icaltimetype icaltime_from_string(const char* str); /* Routines for handling timezones */ -/* Return the offset of the named zone as seconds. tt is a time - indicating the date for which you want the offset */ -int icaltime_utc_offset(struct icaltimetype tt, const char* tzid); - -/* convert tt, of timezone tzid, into a utc time. Does nothing if the - time is already UTC. */ -struct icaltimetype icaltime_as_utc(struct icaltimetype tt, - const char* tzid); - -/* convert tt, a time in UTC, into a time in timezone tzid */ -struct icaltimetype icaltime_as_zone(struct icaltimetype tt, - const char* tzid); - /* Return a null time, which indicates no time has been set. This time represent the beginning of the epoch */ struct icaltimetype icaltime_null_time(void); @@ -211,6 +229,22 @@ int icaltime_is_null_time(struct icaltimetype t); it, or setting one of the flags to an illegal value. */ int icaltime_is_valid_time(struct icaltimetype t); +/** @brief Return the timezone */ +const icaltimezone *icaltime_get_timezone(const struct icaltimetype t); + +/** @brief Return the tzid, or NULL for a floating time */ +char *icaltime_get_tzid(const struct icaltimetype t); + +/** @brief Set the timezone */ +struct icaltimetype icaltime_set_timezone(struct icaltimetype *t, + const icaltimezone *zone); + +/* Returns true if time is of DATE type, false if DATE-TIME */ +int icaltime_is_date(struct icaltimetype t); + +/* Returns true if time is relative to UTC zone */ +int icaltime_is_utc(struct icaltimetype t); + /* Reset all of the time components to be in their normal ranges. For instance, given a time with minutes=70, the minutes will be reduces to 10, and the hour incremented. This allows the caller to do @@ -231,9 +265,6 @@ short icaltime_day_of_week(struct icaltimetype t); given time is within. */ short icaltime_start_doy_of_week(struct icaltimetype t); -/* Return a string with the time represented in the same format as ctime(). THe string is owned by libical */ -char* icaltime_as_ctime(struct icaltimetype); - /* Return the week number for the week the given time is within */ short icaltime_week_number(struct icaltimetype t); @@ -246,6 +277,12 @@ int icaltime_compare_date_only(struct icaltimetype a, struct icaltimetype b); /* Return the number of days in the given month */ short icaltime_days_in_month(short month,short year); +/** convert tt, of timezone tzid, into a utc time. Does nothing if the + time is already UTC. */ +struct icaltimetype icaltime_convert_to_zone(struct icaltimetype tt, + icaltimezone *zone); + + /*********************************************************************** Duration Routines @@ -295,58 +332,122 @@ struct icalperiodtype icalperiodtype_null_period(); int icalperiodtype_is_null_period(struct icalperiodtype p); int icalperiodtype_is_valid_period(struct icalperiodtype p); +/*********************************************************************** + * timezone handling routines +***********************************************************************/ + +/** Returns a single builtin timezone, given its Olson city name. */ +icaltimezone* icaltimezone_get_builtin_timezone (const char *location); + +/** Returns the UTC timezone. */ +icaltimezone* icaltimezone_get_utc_timezone (void); /*********************************************************************** Storage Routines ***********************************************************************/ -icalfileset* icalfileset_new(const char* path); +/** + * @brief options for opening an icalfileset. + * + * These options should be passed to the icalset_new() function + */ + +struct icalfileset_options { + int flags; /**< flags for open() O_RDONLY, etc */ + mode_t mode; /**< file mode */ + icalcluster *cluster; /**< use this cluster to initialize data */ +}; + +icalset* icalfileset_new(const char* path); +icalset* icalfileset_new_reader(const char* path); +icalset* icalfileset_new_writer(const char* path); -/* Like _new, but takes open() flags for opening the file */ -icalfileset* icalfileset_new_open(const char* path, - int flags, int mode); +icalset* icalfileset_init(icalset *set, const char *dsn, void* options); -void icalfileset_free(icalfileset* cluster); +/* icalfileset* icalfileset_new_from_cluster(const char* path, icalcluster *cluster); */ -const char* icalfileset_path(icalfileset* cluster); +icalcluster* icalfileset_produce_icalcluster(const char *path); + +void icalfileset_free(icalset* cluster); + +const char* icalfileset_path(icalset* cluster); /* Mark the cluster as changed, so it will be written to disk when it is freed. Commit writes to disk immediately. */ -void icalfileset_mark(icalfileset* cluster); -icalerrorenum icalfileset_commit(icalfileset* cluster); +void icalfileset_mark(icalset* set); +icalerrorenum icalfileset_commit(icalset* set); -icalerrorenum icalfileset_add_component(icalfileset* cluster, +icalerrorenum icalfileset_add_component(icalset* set, icalcomponent* child); -icalerrorenum icalfileset_remove_component(icalfileset* cluster, +icalerrorenum icalfileset_remove_component(icalset* set, icalcomponent* child); -int icalfileset_count_components(icalfileset* cluster, - icalcomponent_kind kind); +int icalfileset_count_components(icalset* set, + int kind); -/* Restrict the component returned by icalfileset_first, _next to those - that pass the gauge. _clear removes the gauge */ -icalerrorenum icalfileset_select(icalfileset* store, icalgauge* gauge); -void icalfileset_clear(icalfileset* store); +/** + * Restrict the component returned by icalfileset_first, _next to those + * that pass the gauge. _clear removes the gauge + */ +icalerrorenum icalfileset_select(icalset* set, icalgauge* gauge); -/* Get and search for a component by uid */ -icalcomponent* icalfileset_fetch(icalfileset* cluster, const char* uid); -int icalfileset_has_uid(icalfileset* cluster, const char* uid); -icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *c); +/** clear the gauge **/ +void icalfileset_clear(icalset* set); +/** Get and search for a component by uid **/ +icalcomponent* icalfileset_fetch(icalset* set, const char* uid); +int icalfileset_has_uid(icalset* set, const char* uid); +icalcomponent* icalfileset_fetch_match(icalset* set, icalcomponent *c); -/* Modify components according to the MODIFY method of CAP. Works on - the currently selected components. */ -icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *oldcomp, + +/** + * Modify components according to the MODIFY method of CAP. Works on the + * currently selected components. + */ +icalerrorenum icalfileset_modify(icalset* set, + icalcomponent *oldcomp, icalcomponent *newcomp); -/* Iterate through components. If a guage has been defined, these +/* Iterate through components. If a gauge has been defined, these will skip over components that do not pass the gauge */ -icalcomponent* icalfileset_get_current_component (icalfileset* cluster); -icalcomponent* icalfileset_get_first_component(icalfileset* cluster); -icalcomponent* icalfileset_get_next_component(icalfileset* cluster); -/* Return a reference to the internal component. You probably should - not be using this. */ +icalcomponent* icalfileset_get_current_component (icalset* cluster); +icalcomponent* icalfileset_get_first_component(icalset* cluster); +icalcomponent* icalfileset_get_next_component(icalset* cluster); + +/* External iterator for thread safety */ +icalsetiter icalfileset_begin_component(icalset* set, int kind, icalgauge* gauge); +icalcomponent * icalfilesetiter_to_next(icalset* set, icalsetiter *iter); +icalcomponent* icalfileset_form_a_matched_recurrence_component(icalsetiter* itr); + +/*********************************************************************** + Gauge Routines +***********************************************************************/ + +icalgauge* icalgauge_new_from_sql(char* sql, int expand); + +int icalgauge_get_expand(icalgauge* gauge); + +void icalgauge_free(icalgauge* gauge); + +/* Pending Implementation */ +/* char* icalgauge_as_sql(icalcomponent* gauge); */ + +void icalgauge_dump(icalgauge* gauge); + + +/** @brief Return true if comp matches the gauge. + * + * The component must be in + * cannonical form -- a VCALENDAR with one VEVENT, VTODO or VJOURNAL + * sub component + */ +int icalgauge_compare(icalgauge* g, icalcomponent* comp); + +/* Pending Implementation */ +/** Clone the component, but only return the properties + * specified in the gauge */ +/* icalcomponent* icalgauge_new_clone(icalgauge* g, icalcomponent* comp); */ + -icalcomponent* icalfileset_get_component(icalfileset* cluster); diff --git a/libical/src/python/Makefile.am b/libical/src/python/Makefile.am index 8eaf4a74cb..e221fa91c1 100644 --- a/libical/src/python/Makefile.am +++ b/libical/src/python/Makefile.am @@ -32,11 +32,17 @@ Libical.py \ LibicalWrap.i \ python-binding.txt \ test.py \ +Attendee.py \ Collection.py \ Component.py \ DerivedProperties.py \ +Duration.py \ +Error.py \ +Gauge.py \ +Period.py \ Property.py \ Store.py \ +Time.py \ ChangeLog diff --git a/libical/src/python/Period.py b/libical/src/python/Period.py new file mode 100644 index 0000000000..e8d9b3ed40 --- /dev/null +++ b/libical/src/python/Period.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python +# -*- Mode: python -*- +#====================================================================== +# FILE: Period.py +# CREATOR: eric +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org> +# (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +#=========================================================== + +from LibicalWrap import * +from Property import Property +from types import DictType, StringType, IntType +from Time import Time +from Duration import Duration + +class Period(Property): + """Represent a span of time""" + def __init__(self,arg,name='FREEBUSY'): + """ """ + + Property.__init__(self, type = name) + + self.pt=None + + #icalerror_clear_errno() + e1=icalerror_supress("MALFORMEDDATA") + e2=icalerror_supress("BADARG") + + if isinstance(arg, DictType): + + + es=icalerror_supress("MALFORMEDDATA") + self.pt = icalperiodtype_from_string(arg['value']) + icalerror_restore("MALFORMEDDATA",es) + + Property.__init__(self, ref=arg['ref']) + else: + if isinstance(arg, StringType): + + self.pt = icalperiodtype_from_string(arg) + + else: + self.pt = icalperiodtype_null_period() + + Property.__init__(self,type=name) + + icalerror_restore("MALFORMEDDATA",e1) + icalerror_restore("BADARG",e2) + + + if self.pt == None or icalperiodtype_is_null_period(self.pt): + raise Property.ConstructorFailedError("Failed to construct Period") + + + try: + self._update_value() + except Property.UpdateFailedError: + raise Property.ConstructorFailedError("Failed to construct Period") + + def _end_is_duration(self): + dur = icalperiodtype_duration_get(self.pt) + if not icaldurationtype_is_null_duration(dur): + return 1 + return 0 + + def _end_is_time(self): + end = icalperiodtype_end_get(self.pt) + if not icaltime_is_null_time(end): + return 1 + return 0 + + def _update_value(self): + + self.value(icalperiodtype_as_ical_string(self.pt),"PERIOD") + + + def valid(self): + "Return true if this is a valid period" + + return not icalperiodtype_is_null_period(self.dur) + + def start(self,v=None): + """ + Return or set start time of the period. The start time may be + expressed as an RFC2445 format string or an instance of Time. + The return value is an instance of Time + """ + + if(v != None): + if isinstance(t,Time): + t = v + elif isinstance(t,StringType) or isinstance(t,IntType): + t = Time(v,"DTSTART") + else: + raise TypeError + + icalperiodtype_start_set(self.pt,t.tt) + + self._update_value() + + + return Time(icaltime_as_timet(icalperiodtype_start_get(self.pt)), + "DTSTART") + + def end(self,v=None): + """ + Return or set end time of the period. The end time may be + expressed as an RFC2445 format string or an instance of Time. + The return value is an instance of Time. + + If the Period has a duration set, but not an end time, this + method will caluculate the end time from the duration. """ + + if(v != None): + + if isinstance(t,Time): + t = v + elif isinstance(t,StringType) or isinstance(t,IntType): + t = Time(v) + else: + raise TypeError + + if(self._end_is_duration()): + start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) + dur = t.utc_seconds()-start; + icalperiodtype_duration_set(self.pt, + icaldurationtype_from_int(dur)) + else: + icalperiodtype_end_set(self.pt,t.tt) + + self._update_value() + + if(self._end_is_time()): + rt = Time(icaltime_as_timet(icalperiodtype_end_get(self.pt)), + 'DTEND') + rt.timezone(self.timezone()) + return rt + elif(self._end_is_duration()): + start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) + dur = icaldurationtype_as_int(icalperiodtype_duration_get(self.pt)) + rt = Time(start+dur,'DTEND') + rt.timezone(self.timezone()) + return rt + else: + return Time({},'DTEND') + + + + def duration(self,v=None): + """ + Return or set the duration of the period. The duration may be + expressed as an RFC2445 format string or an instance of Duration. + The return value is an instance of Duration. + + If the period has an end time set, but not a duration, this + method will calculate the duration from the end time. """ + + if(v != None): + + if isinstance(t,Duration): + d = v + elif isinstance(t,StringType) or isinstance(t,IntType): + d = Duration(v) + else: + raise TypeError + + if(self._end_is_time()): + start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) + end = start + d.seconds() + + icalperiodtype_end_set(self.pt,icaltime_from_timet(end,0)) + else: + icalperiodtype_duration_set(self.pt,d.dur) + + if(self._end_is_time()): + start =icaltime_as_timet(icalperiodtype_start_get(self.pt)) + end = icaltime_as_timet(icalperiodtype_end_get(self.pt)) + + print "End is time " + str(end-start) + + return Duration(end-start,"DURATION") + + elif(self._end_is_duration()): + dur = icaldurationtype_as_int( + icalperiodtype_duration_get(self.pt)) + + return Duration(dur,"DURATION") + else: + + + return Duration(0,"DURATION") + + + def timezone(self,v=None): + """ Return or set the timezone string for this time """ + if (v != None): + self['TZID'] = v + return self['TZID'] diff --git a/libical/src/python/Property.py b/libical/src/python/Property.py index d63b265525..80c5864855 100644 --- a/libical/src/python/Property.py +++ b/libical/src/python/Property.py @@ -26,10 +26,10 @@ #====================================================================== from LibicalWrap import * -from types import * -import regsub +import re import base64 -from string import index, upper +from string import index, upper, split +from types import StringType #def icalerror_supress(arg): # pass @@ -41,6 +41,19 @@ def error_type(): error = icalerror_perror() return error[:index(error,':')] +def test_enum(prop,enum): + + kind = icalproperty_string_to_kind(prop) + e = icalproperty_string_to_enum(enum) + + t = icalproperty_enum_belongs_to_property(kind,e) + + if t == 1: + return 1 + + return None + + class Property: """ Represent any iCalendar Property. @@ -73,6 +86,8 @@ class Property: kind = icalproperty_string_to_kind(type) self._ref = icalproperty_new(kind) + if type.find("X-") == 0: + icalproperty_set_x_name(self._ref, type) if self._ref == None or self._ref == 'NULL': raise Property.ConstructorFailedError("Failed to construct Property") @@ -95,11 +110,7 @@ class Property: def name(self,v=None): """ Return the name of the property """ - str = icalproperty_as_ical_string(self._ref) - - idx = index(str, '\n') - - return str[:idx] + return icalproperty_get_name(self._ref) def ref(self,v=None): """ Return the internal reference to the libical icalproperty """ @@ -129,6 +140,7 @@ class Property: vt = kind elif self.__getitem__('VALUE'): vt = self.__getitem__('VALUE') + print "###########", self else: vt = 'NO' # Use the kind of the existing value @@ -136,42 +148,45 @@ class Property: icalerror_clear_errno() #e1=icalerror_supress("MALFORMEDDATA") - icalproperty_set_value_from_string(self._ref,v,vt) + if (self.name().find("X-") == 0) and type(v) is StringType: + v = icallangbind_quote_as_ical(v) + v = icallangbind_quote_as_ical(v) + + icalproperty_set_value_from_string(self._ref,str(v),vt) #icalerror_restore("MALFORMEDDATA",e1) if error_type() != "NO": raise Property.UpdateFailedError(error_type()) s = icalproperty_get_value_as_string(self._ref) - assert(s == v) return icalproperty_get_value_as_string(self._ref) def parameters(self): + """ + Return a list of parameters + """ - d_string = icallangbind_property_eval_string(self._ref,":") - dict = eval(d_string) + params = [] - desc_keys = ('name', 'value', 'value_type', 'pid', 'ref', 'deleted' ) - - def foo(k,d=dict): - if d.has_key(k): del d[k] + p = icallangbind_get_first_parameter(self._ref) + + while p != None: + kv = split(icalparameter_as_ical_string(p),'=',2) + params.append(kv[0]) + p = icallangbind_get_next_parameter(self._ref) - map( foo, desc_keys) - - return filter(lambda p, s=self: s[p] != None, dict.keys()) + return params - def as_ical_string(self): - + "Return the property in iCalendar text format." return icalproperty_as_ical_string(self._ref) def __getitem__(self,key): """ Return property values by name """ key = upper(key) - str = icalproperty_get_parameter_as_string(self._ref,key) - + if(str == 'NULL'): return None return str @@ -184,10 +199,17 @@ class Property: return self.__getitem__(key) + def __delitem__(self,key): + """ Remove Property Values by Name """ + key = upper(key) + + if self.__getitem__(key): + icalproperty_remove_parameter_by_name(self._ref,key) + def __str__(self): str = self.as_ical_string() - return regsub.gsub('\r?\n ?','',str) + return re.sub('\r?\n ?','',str) def __cmp__(self, other): s_str = str(self) @@ -196,599 +218,6 @@ class Property: return cmp(s_str,o_str) -class Time(Property): - """ Represent iCalendar DATE, TIME and DATE-TIME """ - def __init__(self, arg, name="DTSTART"): - """ - Create a new Time from a string or number of seconds past the - POSIX epoch - - Time("19970325T123000Z") Construct from an iCalendar string - Time(8349873494) Construct from seconds past POSIX epoch - - """ - e1=icalerror_supress("MALFORMEDDATA") - e2=icalerror_supress("BADARG") - - if isinstance(arg, DictType): - # Dictionary -- used for creating from Component - self.tt = icaltime_from_string(arg['value']) - Property.__init__(self, ref=arg['ref']) - else: - if isinstance(arg, StringType): - # Create from an iCal string - self.tt = icaltime_from_string(arg) - elif isinstance(arg, IntType) or \ - isinstance(arg, FloatType): - # Create from seconds past the POSIX epoch - self.tt = icaltime_from_timet(int(arg),0) - elif isinstance(arg, Time): - # Copy an instance - self.tt = arg.tt - else: - self.tt = icaltime_null_time() - - Property.__init__(self,type=name) - - icalerror_restore("MALFORMEDDATA",e1) - icalerror_restore("BADARG",e2) - - if icaltime_is_null_time(self.tt): - raise Property.ConstructorFailedError("Failed to construct a Time") - - try: - self._update_value() - except Property.UpdateFailedError: - raise Property.ConstructorFailedError("Failed to construct a Time") - - def _update_value(self): - self.tt = icaltime_normalize(self.tt) - self.value(icaltime_as_ical_string(self.tt),"DATE-TIME") - - def valid(self): - " Return true if this is a valid time " - return not icaltime_is_null_time(self.tt) - - def utc_seconds(self,v=None): - """ Return or set time in seconds past POSIX epoch""" - if (v!=None): - self.tt = icaltime_from_timet(v,0) - self._update_value() - - return icaltime_as_timet(self.tt) - - def is_utc(self,v=None): - """ Return or set boolean indicating if time is in UTC """ - if(v != None): - icaltimetype_is_utc_set(self.tt,v) - self._update_value() - return icaltimetype_is_utc_get(self.tt) - - def is_date(self,v=None): - """ Return or set boolean indicating if time is actually a date """ - if(v != None): - icaltimetype_is_date_set(self.tt,v) - self._update_value() - return icaltimetype_is_date_get(self.tt) - - def timezone(self,v=None): - """ Return or set the timezone string for this time """ - - if (v != None): - assert(isinstance(v,StringType) ) - self['TZID'] = v - return self['TZID'] - - def second(self,v=None): - """ Get or set the seconds component of this time """ - if(v != None): - icaltimetype_second_set(self.tt,v) - self._update_value() - return icaltimetype_second_get(self.tt) - - def minute(self,v=None): - """ Get or set the minute component of this time """ - if(v != None): - icaltimetype_minute_set(self.tt,v) - self._update_value() - return icaltimetype_minute_get(self.tt) - - def hour(self,v=None): - """ Get or set the hour component of this time """ - if(v != None): - icaltimetype_hour_set(self.tt,v) - self._update_value() - return icaltimetype_hour_get(self.tt) - - def day(self,v=None): - """ Get or set the month day component of this time """ - if(v != None): - icaltimetype_day_set(self.tt,v) - self._update_value() - return icaltimetype_day_get(self.tt) - - def month(self,v=None): - """ Get or set the month component of this time. January is month 1 """ - if(v != None): - icaltimetype_month_set(self.tt,v) - self._update_value() - return icaltimetype_month_get(self.tt) - - def year(self,v=None): - """ Get or set the year component of this time """ - if(v != None): - icaltimetype_year_set(self.tt,v) - self._update_value() - - return icaltimetype_year_get(self.tt) - - - - def __add__(self,o): - - other = Duration(o,"DURATION") - - if not other.valid(): - return Duration(0,"DURATION") - - seconds = self.utc_seconds() + other.seconds() - - new = Time(seconds,self.name()) - new.timezone(self.timezone()) - new.is_utc(self.is_utc()) - - return new - - def __radd_(self,o): - return self.__add__(o) - - - def __sub__(self,o): - - - if isinstance(o,Time): - # Subtract a time from this time and return a duration - seconds = self.utc_seconds() - other.utc_seconds() - return Duration(seconds) - elif isinstance(o,Duration): - # Subtract a duration from this time and return a time - other = Duration(o) - if(not other.valid()): - return Time() - - seconds = self.utc_seconds() - other.seconds() - return Time(seconds) - else: - raise TypeError, "subtraction with Time reqires Time or Duration" - -class Duration(Property): - """ - Represent a length of time, like 3 minutes, or 6 days, 20 seconds. - - - """ - - def __init__(self, arg, name="DURATION"): - """ - Create a new duration from an RFC2445 string or number of seconds. - Construct the duration from an iCalendar string or a number of seconds. - - Duration("P3DT2H34M45S") Construct from an iCalendar string - Duration(3660) Construct from seconds - """ - - self.dur = None - - e=icalerror_supress("MALFORMEDDATA") - - if isinstance(arg, DictType): - - self.dur = icaldurationtype_from_string(arg['value']) - Property.__init__(self,ref=arg['ref']) - else: - if isinstance(arg, StringType): - self.dur = icaldurationtype_from_string(arg) - elif isinstance(arg, IntType): - self.dur = icaldurationtype_from_int(arg) - elif isinstance(arg,Duration): - self.dur = arg.dur - else: - self.dur = icaldurationtype_null_duration() - - Property.__init__(self,type=name) - - icalerror_restore("MALFORMEDDATA",e) - - if self.dur == None or icaldurationtype_is_null_duration(self.dur): - raise Property.ConstructorFailedError("Failed to construct Duration from " +str(arg)) - - try: - self._update_value() - except Property.UpdateFailedError: - raise Property.ConstructorFailedError("Failed to construct Duration from " + str(arg)) - - def _update_value(self): - - self.value(icaldurationtype_as_ical_string(self.dur),"DURATION") - - def valid(self): - "Return true if this is a valid duration" - - return not icaldurationtype_is_null_duration(self.dur) - - def seconds(self,v=None): - """Return or set duration in seconds""" - if(v != None): - self.dur = icaldurationtype_from_int(v); - self.dict['value'] = icaltimedurationtype_as_ical_string(self.dur) - return icaldurationtype_as_int(self.dur) - - -class Period(Property): - """Represent a span of time""" - def __init__(self,arg,name='FREEBUSY'): - """ """ - - Property.__init__(self, type = name) - - self.pt=None - - #icalerror_clear_errno() - e1=icalerror_supress("MALFORMEDDATA") - e2=icalerror_supress("BADARG") - - if isinstance(arg, DictType): - - - es=icalerror_supress("MALFORMEDDATA") - self.pt = icalperiodtype_from_string(arg['value']) - icalerror_restore("MALFORMEDDATA",es) - - Property.__init__(self, ref=arg['ref']) - else: - if isinstance(arg, StringType): - - self.pt = icalperiodtype_from_string(arg) - - else: - self.pt = icalperiodtype_null_period() - - Property.__init__(self,type=name) - - icalerror_restore("MALFORMEDDATA",e1) - icalerror_restore("BADARG",e2) - - - if self.pt == None or icalperiodtype_is_null_period(self.pt): - raise Property.ConstructorFailedError("Failed to construct Period") - - - try: - self._update_value() - except Property.UpdateFailedError: - raise Property.ConstructorFailedError("Failed to construct Period") - - def _end_is_duration(self): - dur = icalperiodtype_duration_get(self.pt) - if not icaldurationtype_is_null_duration(dur): - return 1 - return 0 - - def _end_is_time(self): - end = icalperiodtype_end_get(self.pt) - if not icaltime_is_null_time(end): - return 1 - return 0 - - def _update_value(self): - - self.value(icalperiodtype_as_ical_string(self.pt),"PERIOD") - - - def valid(self): - "Return true if this is a valid period" - - return not icalperiodtype_is_null_period(self.dur) - - def start(self,v=None): - """ - Return or set start time of the period. The start time may be - expressed as an RFC2445 format string or an instance of Time. - The return value is an instance of Time - """ - - if(v != None): - if isinstance(t,Time): - t = v - elif isinstance(t,StringType) or isinstance(t,IntType): - t = Time(v,"DTSTART") - else: - raise TypeError - - icalperiodtype_start_set(self.pt,t.tt) - - self._update_value() - - - return Time(icaltime_as_timet(icalperiodtype_start_get(self.pt)), - "DTSTART") - - def end(self,v=None): - """ - Return or set end time of the period. The end time may be - expressed as an RFC2445 format string or an instance of Time. - The return value is an instance of Time. - - If the Period has a duration set, but not an end time, this - method will caluculate the end time from the duration. """ - - if(v != None): - - if isinstance(t,Time): - t = v - elif isinstance(t,StringType) or isinstance(t,IntType): - t = Time(v) - else: - raise TypeError - - if(self._end_is_duration()): - start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) - dur = t.utc_seconds()-start; - icalperiodtype_duration_set(self.pt, - icaldurationtype_from_int(dur)) - else: - icalperiodtype_end_set(self.pt,t.tt) - - self._update_value() - - if(self._end_is_time()): - rt = Time(icaltime_as_timet(icalperiodtype_end_get(self.pt)), - 'DTEND') - rt.timezone(self.timezone()) - return rt - elif(self._end_is_duration()): - start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) - dur = icaldurationtype_as_int(icalperiodtype_duration_get(self.pt)) - rt = Time(start+dur,'DTEND') - rt.timezone(self.timezone()) - return rt - else: - return Time({},'DTEND') - - - - def duration(self,v=None): - """ - Return or set the duration of the period. The duration may be - expressed as an RFC2445 format string or an instance of Duration. - The return value is an instance of Duration. - - If the period has an end time set, but not a duration, this - method will calculate the duration from the end time. """ - - if(v != None): - - if isinstance(t,Duration): - d = v - elif isinstance(t,StringType) or isinstance(t,IntType): - d = Duration(v) - else: - raise TypeError - - if(self._end_is_time()): - start = icaltime_as_timet(icalperiodtype_start_get(self.pt)) - end = start + d.seconds() - - icalperiodtype_end_set(self.pt,icaltime_from_timet(end,0)) - else: - icalperiodtype_duration_set(self.pt,d.dur) - - if(self._end_is_time()): - start =icaltime_as_timet(icalperiodtype_start_get(self.pt)) - end = icaltime_as_timet(icalperiodtype_end_get(self.pt)) - - print "End is time " + str(end-start) - - return Duration(end-start,"DURATION") - - elif(self._end_is_duration()): - dur = icaldurationtype_as_int( - icalperiodtype_duration_get(self.pt)) - - return Duration(dur,"DURATION") - else: - - - return Duration(0,"DURATION") - - - def timezone(self,v=None): - """ Return or set the timezone string for this time """ - if (v != None): - self['TZID'] = v - return self['TZID'] - -class Attendee(Property): - """Class for Attendee properties. - - Usage: - Attendee([dict]) - Attendee([address]) - - Where: - dict is an optional dictionary with keys of - 'value': CAL-ADDRESS string and any parameter: parameter_value entries. - 'name' and 'value_type' entries in dict are ignored and automatically set - with the appropriate values. - address is the CAL-ADDRESS (string) of the Attendee - """ - - def __init__(self, arg={}): - - assert(isinstance(arg,DictType)) - - ref = None - - if arg!={}: - ref = arg['ref'] - - Property.__init__(self,type='ATTENDEE',ref=ref) - - def _doParam(self, parameter, v): - if v!=None: - self[parameter]=v - return self[parameter] - - # Methods for accessing enumerated parameters - def cn(self, v=None): self._doParam('CN', v) - def cutype(self, v=None): self._doParam('CUTYPE', v) - def dir(self, v=None): self._doParam('DIR', v) - def delegated_from(self, v=None): self._doParam('DELEGATED-FROM', v) - def delegated_to(self, v=None): self._doParam('DELEGATED-TO', v) - def language(self, v=None): self._doParam('LANGUAGE', v) - def member(self, v=None): self._doParam('MEMBER', v) - def partstat(self, v=None): self._doParam('PARTSTAT', v) - def role(self, v=None): self._doParam('ROLE', v) - def rsvp(self, v=None): self._doParam('RSVP', v) - def sent_by(self, v=None): self._doParam('SENT-BY', v) - - -class Organizer(Property): - """Class for Organizer property. - """ - - def __init__(self, arg={}): - - assert(isinstance(arg, DictType)) - - ref = None - if arg != {}: - ref = arg['ref'] - Property.__init__(self, type='ORGANIZER', ref=ref) - -## param_t = ( 'CN', 'DIR', 'SENT-BY', 'LANGUAGE' ) -## for param in param_t: -## self[param] = None -## if value != None: -## self.value(value) - - - def _doParam(self, parameter, v): - if v!=None: - self[parameter]=v - return self[parameter] - - def name(self): - "Return the name of the property." - return Property.name(self) - - def value_type(self): - "Return the value type of the property." - return self._desc['value_type'] - - # Methods for accessing enumerated parameters - def cn(self, v=None): self._doParam('CN', v) - def dir(self, v=None): self._doParam('DIR', v) - def language(self, v=None): self._doParam('LANGUAGE', v) - def sent_by(self, v=None): self._doParam('SENT-BY', v) - -class Recurrence_Id(Time): - """Class for RECURRENCE-ID property. - - Usage: - Reccurence_Id(dict) # A normal property dictionary - Reccurence_Id("19960401") # An iCalendar string - Reccurence_Id(8349873494) # Seconds from epoch - - If the 'dict' constructor is used, 'name' and 'value_type' - entries in dict are ignored and automatically set with the appropriate - values. - """ - - def __init__(self, dict={}): - Time.__init__(self, dict) - Property.name(self, 'RECURRENCE-ID') - - def name(self): - return Property.name(self) - - def _doParam(self, parameter, v): - if v!=None: - self[parameter]=v - return self[parameter] - - # Enumerated parameters - def value_parameter(self, v=None): - """Sets or gets the VALUE parameter value. - - The value passed should be either "DATE-TIME" or "DATE". Setting this - parameter has no impact on the property's value_type. Doing something - like: - - rid=Recurrence_Id("19960401") # Sets value & makes value_type="DATE" - rid.value_parameter("DATE-TIME") # Sets the parameter VALUE=DATE-TIME - - Would be allowed (even though it is wrong), so pay attention. - Verifying the component will reveal the error. - """ - if v!=None and v!="DATE" and v!="DATE-TIME": - raise ValueError, "%s is an invalid VALUE parameter value" % str(v) - self._doParam("VALUE", v) - - def tzid(self, v=None): - "Sets or gets the TZID parameter value." - self._doParam("TZID", v) - - def range_parameter(self, v=None): # 'range' is a builtin function - "Sets or gets the RANGE parameter value." - if v!=None and v!="THISANDPRIOR" and v!= "THISANDFUTURE": - raise ValueError, "%s is an invalid RANGE parameter value" % str(v) - self._doParam("RANGE", v) - -class Attach(Property): - """A class representing an ATTACH property. - - Usage: - Attach(uriString [, parameter_dict]) - Attach(fileObj [, parameter_dict]) - """ - - def __init__(self, value=None, parameter_dict={}): - Property.__init__(self, parameter_dict) - Property.name(self, 'ATTACH') - self.value(value) - - def value(self, v=None): - "Returns or sets the value of the property." - if v != None: - if isinstance(v, StringType): # Is a URI - self._desc['value']=v - Property.value_type(self, 'URI') - else: - try: - tempStr = v.read() - except: - raise TypeError,"%s must be a URL string or file-ish type"\ - % str(v) - self._desc['value'] = base64.encodestring(tempStr) - Property.value_type(self, 'BINARY') - else: - return self._desc['value'] - - def name(self): - "Returns the name of the property." - return Property.name(self) - - def value_type(self): - return Property.value_type(self) - - def fmttype(self, v=None): - "Gets or sets the FMTYPE parameter." - if v!= None: - self['FMTTYPE']=v - else: - return self['FMTTYPE'] - class RecurrenceSet: """ Represents a set of event occurrences. This diff --git a/libical/src/python/Store.py b/libical/src/python/Store.py index 6d13bd5211..00b5b0c2d0 100644 --- a/libical/src/python/Store.py +++ b/libical/src/python/Store.py @@ -27,7 +27,8 @@ from LibicalWrap import * from Error import LibicalError -from Component import Component +from Component import Component, CloneComponent +from Gauge import Gauge class Store: """ @@ -88,20 +89,11 @@ class Store: class FileStore(Store): - def __init__(self, file,mode="r",flags=0664): - - _flags = icallangbind_string_to_open_flag(mode) - - - if _flags == -1: - raise Store.ConstructorFailedError("Illegal value for mode: "+mode) - + def __init__(self, file): e1=icalerror_supress("FILE") - self._ref = icalfileset_new_open(file,_flags,flags) + self._ref = icalfileset_new(file) icalerror_restore("FILE",e1) - print self._ref - if self._ref == None or self._ref == 'NULL': raise Store.ConstructorFailedError(file) @@ -121,33 +113,46 @@ class FileStore(Store): if not isinstance(comp,Component): raise Store.AddFailedError("Argument is not a component") - error = icalfileset_add_component(self._ref,comp) + error = icalfileset_add_component(self._ref,comp.ref()) def remove_component(self, comp): if not isinstance(comp,Component): raise Store.AddFailedError("Argument is not a component") - error = icalfileset_remove_component(self._ref,comp) - - + error = icalfileset_remove_component(self._ref,comp.ref()) def count_components(self, kind): - pass + _kind = icalcomponent_string_to_kind(kind) + + return icalfileset_count_components(self._ref, _kind) def select(self, gauge): - pass + error = icalfileset_select(self._ref, gauge.ref()) def clearSelect(self): - pass + icalfileset_clear(self._ref) def fetch(self, uid): - pass + comp_ref = icalfileset_fetch(self._ref, uid) + + if comp_ref == None: + return None + + return CloneComponent(comp_ref) def fetchMatch(self, comp): - pass + if not isinstance(comp,Component): + raise Store.AddFailedError("Argument is not a component") + + comp_ref = icalfileset_fetch_match(self._ref,comp.ref()) + + if comp_ref == None: + return None + + return CloneComponent(comp_ref) def modify(self, oldc, newc): - pass + pass def current_component(self): comp_ref = icalfileset_get_current_component(self._ref) @@ -155,7 +160,7 @@ class FileStore(Store): if comp_ref == None: return None - return Component(ref=comp_ref) + return CloneComponent(comp_ref) def first_component(self): comp_ref = icalfileset_get_first_component(self._ref) @@ -163,7 +168,7 @@ class FileStore(Store): if comp_ref == None: return None - return Component(ref=comp_ref) + return CloneComponent(comp_ref) def next_component(self): @@ -172,5 +177,5 @@ class FileStore(Store): if comp_ref == None: return None - return Component(ref=comp_ref) + return CloneComponent(comp_ref) diff --git a/libical/src/python/Time.py b/libical/src/python/Time.py new file mode 100644 index 0000000000..673607d7b4 --- /dev/null +++ b/libical/src/python/Time.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python +# -*- Mode: python -*- +#====================================================================== +# FILE: Time.py +# CREATOR: eric +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org> +# (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of either: +# +# The LGPL as published by the Free Software Foundation, version +# 2.1, available at: http://www.fsf.org/copyleft/lesser.html +# +# Or: +# +# The Mozilla Public License Version 1.0. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +#====================================================================== + +from LibicalWrap import * +from Property import Property +from types import DictType, StringType, IntType, FloatType +from Duration import Duration + +class Time(Property): + """ Represent iCalendar DATE, TIME and DATE-TIME """ + def __init__(self, arg, name="DTSTART", zone=None): + """ + Create a new Time from a string or number of seconds past the + POSIX epoch + + Time("19970325T123000Z") Construct from an iCalendar string + Time(8349873494) Construct from seconds past POSIX epoch + + """ + e1=icalerror_supress("MALFORMEDDATA") + e2=icalerror_supress("BADARG") + + if isinstance(arg, DictType): + # Dictionary -- used for creating from Component + self.tt = icaltime_from_string(arg['value']) + Property.__init__(self, ref=arg['ref']) + else: + if isinstance(arg, StringType): + # Create from an iCal string + self.tt = icaltime_from_string(arg) + elif isinstance(arg, IntType) or \ + isinstance(arg, FloatType): + # Create from seconds past the POSIX epoch + if zone: + self.tt = icaltime_from_timet_with_zone(int(arg),0,icaltimezone_get_builtin_timezone(zone)) + else: + self.tt = icaltime_from_timet_with_zone(int(arg),0,icaltimezone_get_utc_timezone()) + elif isinstance(arg, Time): + # Copy an instance + self.tt = arg.tt + else: + self.tt = icaltime_null_time() + + Property.__init__(self,type=name) + + icalerror_restore("MALFORMEDDATA",e1) + icalerror_restore("BADARG",e2) + + if icaltime_is_null_time(self.tt): + raise Property.ConstructorFailedError("Failed to construct a Time") + + try: + self._update_value() + except Property.UpdateFailedError: + raise Property.ConstructorFailedError("Failed to construct a Time") + + def _update_value(self): + self.tt = icaltime_normalize(self.tt) + self.value(icaltime_as_ical_string(self.tt),"DATE-TIME") + + def valid(self): + " Return true if this is a valid time " + return not icaltime_is_null_time(self.tt) + + def utc_seconds(self,v=None): + """ Return or set time in seconds past POSIX epoch""" + if (v!=None): + tz = icaltimezone_get_builtin_timezone(self.timezone()) + self.tt = icaltime_from_timet_with_zone(v,0,tz) + self._update_value() + + return icaltime_as_timet(self.tt) + + def is_utc(self): + """ Return a boolean indicating if time is in UTC """ + return icaltime_is_utc(self.tt) + + def is_date(self): + """ Return a boolean indicating if time is actually a date """ + return icaltime_is_date(self.tt) + + def timezone(self,v=None): + """ Return, set (if none) or alter the timezone for this time """ + + origtz = icaltime_get_tzid(self.tt) + + if (v != None): + assert(isinstance(v,StringType) ) + if (v == "UTC"): + tz = icaltimezone_get_utc_timezone() + del self['TZID'] + else: + tz = icaltimezone_get_builtin_timezone(v) + + if not origtz: + self.tt = icaltime_set_timezone(self.tt, tz) + else: + self.tt = icaltime_convert_to_zone(self.tt,tz) + + if (icaltime_get_tzid(self.tt) != "UTC"): + self['TZID'] = icaltime_get_tzid(self.tt) + + self._update_value() + return icaltime_get_tzid(self.tt) + + def second(self,v=None): + """ Get or set the seconds component of this time """ + if(v != None): + icaltimetype_second_set(self.tt,v) + self._update_value() + return icaltimetype_second_get(self.tt) + + def minute(self,v=None): + """ Get or set the minute component of this time """ + if(v != None): + icaltimetype_minute_set(self.tt,v) + self._update_value() + return icaltimetype_minute_get(self.tt) + + def hour(self,v=None): + """ Get or set the hour component of this time """ + if(v != None): + icaltimetype_hour_set(self.tt,v) + self._update_value() + return icaltimetype_hour_get(self.tt) + + def day(self,v=None): + """ Get or set the month day component of this time """ + if(v != None): + icaltimetype_day_set(self.tt,v) + self._update_value() + return icaltimetype_day_get(self.tt) + + def month(self,v=None): + """ Get or set the month component of this time. January is month 1 """ + if(v != None): + icaltimetype_month_set(self.tt,v) + self._update_value() + return icaltimetype_month_get(self.tt) + + def year(self,v=None): + """ Get or set the year component of this time """ + if(v != None): + icaltimetype_year_set(self.tt,v) + self._update_value() + + return icaltimetype_year_get(self.tt) + + + def __cmp__(self,other): + + if other == None: + return cmp(self.utc_seconds(),None) + + return cmp(self.utc_seconds(),other.utc_seconds()) + + + def __add__(self,o): + + other = Duration(o,"DURATION") + + if not other.valid(): + return Duration(0,"DURATION") + + seconds = self.utc_seconds() + other.seconds() + + new = Time(seconds,self.name(),self.timezone()) + + return new + + def __radd_(self,o): + return self.__add__(o) + + + def __sub__(self,o): + + + if isinstance(o,Time): + # Subtract a time from this time and return a duration + seconds = self.utc_seconds() - other.utc_seconds() + return Duration(seconds) + elif isinstance(o,Duration): + # Subtract a duration from this time and return a time + other = Duration(o) + if(not other.valid()): + return Time() + + seconds = self.utc_seconds() - other.seconds() + return Time(seconds) + else: + raise TypeError, "subtraction with Time reqires Time or Duration" diff --git a/libical/src/python/littlefile.txt b/libical/src/python/littlefile.txt new file mode 100644 index 0000000000..cba0891115 --- /dev/null +++ b/libical/src/python/littlefile.txt @@ -0,0 +1,3 @@ +This is just a small file to test mime encoding. + +There isn't much here at all. diff --git a/libical/src/python/python-binding.txt b/libical/src/python/python-binding.txt index 7fc9e066bf..7f925e246f 100644 --- a/libical/src/python/python-binding.txt +++ b/libical/src/python/python-binding.txt @@ -149,7 +149,7 @@ it. that the specific interface has not implemented or cannot manage well. -4) Cller may create a new component, using a combination of the +4) Caller may create a new component, using a combination of the general and specific interfaces. The caller may send the message to another user via mail, or may submit it to the user's CAP server with the CAPStore class. @@ -159,7 +159,7 @@ Following are the methods in each of the classes. Component Construct from string - output string in ical form + Output string in ical form Get a Property by type Get a set of Properties by type @@ -177,7 +177,7 @@ Component Event, JournalEntry, Todo Construct from string - output string in ical form + Output string in ical form There are get/set accessors for every property. These are listed in a later section @@ -187,7 +187,7 @@ FreeBusy Construct from string Construct from arguments - output string in ical form + Output string in ical form Accessors for the following properties. See below for return types for these properties: @@ -211,7 +211,7 @@ TimezonePhase Construct from string Construct from arguments - output string in ical form + Output string in ical form Accessors for the following properties. See below for return types for these properties: @@ -227,7 +227,7 @@ TimeZone Construct from string Construct from arguments - output string in ical form + Output string in ical form Accessors for the following properties. See below for return types for these properties: @@ -243,7 +243,7 @@ Property Construct from string Construct from arguments - output string in ical form + Output string in ical form Dictionary access to parameters @@ -253,7 +253,7 @@ Attendee Construct from string Construct from arguments - output string in ical form + Output string in ical form Access to the following properties and parameters: cuid diff --git a/libical/src/python/test.py b/libical/src/python/test.py index 1fdf515408..4047e78c95 100644 --- a/libical/src/python/test.py +++ b/libical/src/python/test.py @@ -25,6 +25,7 @@ # the License at http://www.mozilla.org/MPL/ #====================================================================== +import LibicalWrap from Libical import * def error_type(): @@ -32,6 +33,10 @@ def error_type(): return error[:index(error,':')] comp_str = """ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +METHOD:REQUEST BEGIN:VEVENT ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com COMMENT: When in the course of writting comments and nonsense text\, it @@ -43,13 +48,15 @@ DURATION:P3DT4H25M FREEBUSY:19970101T120000/19970101T120000 FREEBUSY:19970101T120000/PT3H FREEBUSY:19970101T120000/PT3H -END:VEVENT""" +END:VEVENT +END:VCALENDAR""" def test_property(): print "--------------------------- Test Property ----------------------" - + + liw = LibicalWrap icalprop = liw.icalproperty_new_from_string("ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com") @@ -58,19 +65,43 @@ def test_property(): p = Property(ref=icalprop) print p.name() - print p.parameters() + print + print "Parameters:" + for param in p.parameters(): + print " ", param, " = ", p[param] + print print p['ROLE'] p['ROLE'] = 'INDIVIDUAL' print p['ROLE'] + p['ROLE'] = 'GROFROMBLATZ' + + print p['ROLE'] + + print + + p['X-MAN-FAVOURITE'] = 'Wolverine' + p['X-FILES-FAVOURITE'] = 'Mulder' + + print p['X-MAN-FAVOURITE'] + + assert(p['X-MAN-FAVOURITE'] == 'Wolverine') + assert(p['X-FILES-FAVOURITE'] == 'Mulder') + assert(p['X-FILES-FAVOURITE'] != 'Scully') + print p.value() p.value("mailto:Bob@bob.com") print p.value() print p.as_ical_string() + del p['ROLE'] + del p['X-MAN-FAVOURITE'] + + print p.as_ical_string() + try: p = Property() @@ -79,6 +110,22 @@ def test_property(): else: assert(0) + # X Property + p = Property("X-COMMENT") + + p.value("This is a sentence, with punctuation; indeed: it is") + print p + + p.value("This is not approved by the Ministry of Silly Walks") + print p + + + assert(test_enum('METHOD','PUBLISH')) + assert(not test_enum('METHOD','FOO')) + + assert(test_enum('ACTION','AUDIO')) + assert(not test_enum('ACTION','OPAQUE')) + def test_time(): "Test routine" @@ -99,12 +146,13 @@ def test_time(): t.timezone("America/Los_Angeles") print str(t) - assert(str(t)=='DTSTART;TZID=America/Los_Angeles:19970325T123010Z') + print t.timezone() + #assert(str(t)=='DTSTART;TZID=America/Los_Angeles:19970325T123010') + assert(str(t)=='DTSTART;TZID=/softwarestudio.org/Olson_20010626_2/America/Los_Angeles:19970325T043010') t.second(t.second()+80) - print t - + t.timezone("UTC") assert(t.minute() == 31) assert(t.second() == 30) @@ -120,6 +168,13 @@ def test_time(): assert(isinstance(t2,Time)) assert(t2.hour() == 11) + # test int args + t = Time(2) + print t + + # test float args + t = Time(2.5) + print t def test_period(): @@ -129,7 +184,6 @@ def test_period(): print p - assert(str(p) == 'FREEBUSY:19970101T180000Z/19970101T233000Z') print p.start() @@ -221,14 +275,25 @@ def test_component(): print "------------------- Test Component ----------------------" - c = Component(comp_str); - + c = NewComponent(comp_str); + props = c.properties() for p in props: print p.as_ical_string() + + inner = c.components()[0] + + print inner + print type(inner) + + + props = inner.properties() + + for p in props: + print p.as_ical_string() - dtstart = c.properties('DTSTART')[0] + dtstart = inner.properties('DTSTART')[0] print dtstart @@ -240,21 +305,21 @@ def test_component(): print "\n New hour: ", dtstart.hour() assert(dtstart.hour() == 17) - attendee = c.properties('ATTENDEE')[0] + attendee = inner.properties('ATTENDEE')[0] print attendee t = Time("20011111T123030") t.name('DTEND') - c.add_property(t) + inner.add_property(t) print c - dtstart1 = c.properties('DTSTART')[0] - dtstart2 = c.properties('DTSTART')[0] - dtstart3 = c.property('DTSTART') + dtstart1 = inner.properties('DTSTART')[0] + dtstart2 = inner.properties('DTSTART')[0] + dtstart3 = inner.property('DTSTART') assert(dtstart1 is dtstart2) assert(dtstart1 == dtstart2) @@ -266,53 +331,81 @@ def test_component(): p = Property(type="SUMMARY"); p.value("This is a summary") - c.properties().append(p) + inner.properties().append(p) - print c.as_ical_string() + print inner.as_ical_string() - p = c.properties("SUMMARY")[0] + p = inner.properties("SUMMARY")[0] assert(p!=None); print str(p) assert(str(p) == "SUMMARY:This is a summary") - c.properties()[:] = [p] + inner.properties()[:] = [p] + + print inner.as_ical_string() + + # test sequence + event = Event() - print c.as_ical_string() + try: + event.sequence("foo") + except TypeError: + pass + event.sequence(-1) + print event.sequence() + event.sequence(1) + event.sequence(88) + print event.sequence() + def test_event(): print "------------ Event Class ----------------------" + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") - #print "created =", event.created() - assert (event.created() == "20010313T123000Z") + print "created =", event.created() + assert (event.created() == Time("20010313T123000Z")) event.organizer("MAILTO:j_doe@nowhere.com") - org = event.properties('ORGANIZER')[0] - #print org.cn() + org = event.organizer() + print org.cn() org.cn('Jane Doe') assert (isinstance(org, Organizer)) - #print "organizer =", event.organizer() - assert (event.organizer() == "MAILTO:j_doe@nowhere.com") + print "organizer =", event.organizer() + assert (event.organizer().value() == "MAILTO:j_doe@nowhere.com") event.dtstart("20010401T183000Z") - #print "dtstart =", event.dtstart() - assert (event.dtstart()=="20010401T183000Z") + print "dtstart =", event.dtstart() + assert (event.dtstart()== Time("20010401T183000Z")) dtend = Time('20010401T190000Z', 'DTEND') event.dtend(dtend) - assert (event.dtend()==dtend.value()) - assert (event.dtend() == '20010401T190000Z') + assert (event.dtend() ==dtend ) + assert (event.dtend() == Time('20010401T190000Z')) att = Attendee() att.value('jsmith@nothere.com') event.attendees(('ef_hutton@listenup.com', att)) + + event.x_properties('X-TEST',('foo', 'bar')) + event.x_properties('X-TEST2',('foo, biz', 'bar, biz')) + + inner = event.components()[0] + for e in inner.properties('X-TEST'): + print " ", e.as_ical_string() + + assert(len(event.x_properties('X-TEST'))==2) - event.description("A short description. Longer ones break things.") + event.description("A short description. Longer ones break things. Really. What does it break. The code is supposed to handle realy long lines, longer, in fact, than any sane person would create except by writting a random text generator or by excerpting text from a less sane person. Actually, it did \"break\" and I had to remove an \n assert to fix it.") event.status('TeNtAtIvE') print event.as_ical_string() - + def test_derivedprop(): @@ -348,6 +441,138 @@ def test_derivedprop(): assert(0) except: pass +def test_gauge(): + print "------------ Gauge -----------------" + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") + event.organizer("MAILTO:j_doe@nowhere.com") + org = event.organizer() + org.cn('Jane Doe') + event.dtstart("20010401T183000Z") + dtend = Time('20010401T190000Z', 'DTEND') + event.dtend(dtend) + event.description("A short description.") + event.status('TeNtAtIvE') + + print event.as_ical_string() + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T180000Z'") + + assert(gauge.compare(event) == 1) + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T190000Z'") + + assert(gauge.compare(event) == 0) + +def do_test_store(storeobj=None, *args): + assert(storeobj != None) + store = storeobj(*args) + assert(store != None) + + print ">------------ ", + print store.__class__, + print "Store -----------------" + + + # create fileset + + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") + event.organizer("MAILTO:j_doe@nowhere.com") + event.dtstart("20010401T183000Z") + event.duration('PT3H') + + event.description("A short description.") + + # for i = 1 to 10 + # copy event + # munge uid and increment month + for i in range(1,11): + newevent = event.clone() + newevent.uid("%d@localhost" % (i,)) + newevent.dtstart().month( newevent.dtstart().month() + i ) + + #print ne + store.add_component(newevent) + + # commit + store.commit() + assert(store.count_components("VCALENDAR") == 10) + # free + del(store) + + # open again + store = storeobj(*args) + # assert count of components = 10 + assert(store.count_components("VCALENDAR") == 10) + + # print them out + # fetch by uid + n7 = store.fetch("7@localhost") + print n7 + # fetch by match + + n7m = store.fetchMatch(n7) + assert(str(n7) == str(n7m)) + + # modify in memory + n7.uid("42@localhost") + del(store) + del(n7) + + store = storeobj(*args) + assert(store.fetch("42@localhost") == None) + n7 = store.fetch("7@localhost") + n7.uid("42@localhost") + store.mark() + store.commit() + del(store) + store = storeobj(*args) + assert(store.fetch("7@localhost") == None) + + # fetch by gauge + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010601T000000Z' AND DTSTART < '20010901T000000Z'") + + store.select(gauge) + + count = 0 + + c = store.first_component() + while c != None: + print c.uid() + print c.dtstart() + print + count = count + 1 + c = store.next_component() + + store.clearSelect() + + assert(count == 3) + + # remove all of them + c = store.first_component() + while c != None: + print c.uid() + store.remove_component(c) + c = store.first_component() + + assert(store.count_components("VCALENDAR") == 0) + store.commit() + assert(store.count_components("VCALENDAR") == 0) + # print them out + # assert count of components = 0 + + +def test_store(): + print "------------ Store -----------------" + do_test_store(FileStore,"filesetout.ics") def run_tests(): test_property() @@ -366,6 +591,11 @@ def run_tests(): #test_attach() + test_gauge() + + test_store() + + if __name__ == "__main__": diff --git a/libical/src/test/.cvsignore b/libical/src/test/.cvsignore index ed72bfe59f..3e3f2ca509 100644 --- a/libical/src/test/.cvsignore +++ b/libical/src/test/.cvsignore @@ -1,18 +1,15 @@ -*.la -*.lo -.libs Makefile -Makefile.in .deps .libs -copycluster -regression -parser -findobj -storage -stow -recur -testmime +*.lo +*.la +copycluster +regression +parser +storage +stow +recur +testmime testvcal - - +process +testclassify diff --git a/libical/src/test/2445.ics b/libical/src/test/2445.ics new file mode 100644 index 0000000000..71cf45e750 --- /dev/null +++ b/libical/src/test/2445.ics @@ -0,0 +1,326 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//hacksw/handcal//NONSGML v1.0//EN +BEGIN:VEVENT +DTSTAMP:19970901T1300Z +DTSTART:19970714T170000Z +DTEND:19970715T035959Z +SUMMARY:Bastille Day Party +END:VEVENT +END:VCALENDAR + +BEGIN:VEVENT +UID:19970901T130000Z-123401@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970903T163000Z +DTEND:19970903T190000Z +SUMMARY:Annual Employee Review +CLASS:PRIVATE +CATEGORIES:BUSINESS,HUMAN RESOURCES +END:VEVENT + +BEGIN:VEVENT +UID:19970901T130000Z-123402@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970401T163000Z +DTEND:19970402T010000Z +SUMMARY:Laurel is in sensitivity awareness class. +CLASS:PUBLIC +CATEGORIES:BUSINESS,HUMAN RESOURCES +TRANSP:TRANSPARENT +END:VEVENT + +BEGIN:VEVENT +UID:19970901T130000Z-123403@host.com +DTSTAMP:19970901T1300Z +DTSTART:19971102 +SUMMARY:Our Blissful Anniversary +CLASS:CONFIDENTIAL +CATEGORIES:ANNIVERSARY,PERSONAL,SPECIAL OCCASION +RRULE:FREQ=YEARLY +END:VEVENT + +BEGIN:VTODO +UID:19970901T130000Z-123404@host.com +DTSTAMP:19970901T1300Z +DTSTART:19970415T133000Z +DUE:19970416T045959Z +SUMMARY:1996 Income Tax Preparation +CLASS:CONFIDENTIAL +CATEGORIES:FAMILY,FINANCE +PRIORITY:1 +STATUS:NEEDS-ACTION +END:VTODO +BEGIN:VJOURNAL +UID:19970901T130000Z-123405@host.com +DTSTAMP:19970901T1300Z +DTSTART;VALUE=DATE:19970317 +SUMMARY:Staff meeting minutes +DESCRIPTION:1. Staff meeting: Participants include Joe\, Lisa + and Bob. Aurora project plans were reviewed. There is currently + no budget reserves for this project. Lisa will escalate to + management. Next meeting on Tuesday.\n + 2. Telephone Conference: ABC Corp. sales representative called + to discuss new printer. Promised to get us a demo by Friday.\n + 3. Henry Miller (Handsoff Insurance): Car was totaled by tree. + Is looking into a loaner car. 654-2323 (tel). +END:VJOURNAL +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jane_doe@host1.com +ATTENDEE:MAILTO:john_public@host2.com +DTSTART:19971015T050000Z +DTEND:19971016T050000Z +DTSTAMP:19970901T083000Z +END:VFREEBUSY +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jane_doe@host1.com +ATTENDEE:MAILTO:john_public@host2.com +DTSTAMP:19970901T100000Z +FREEBUSY;VALUE=PERIOD:19971015T050000Z/PT8H30M, + 19971015T160000Z/PT5H30M,19971015T223000Z/PT6H30M +URL:http://host2.com/pub/busy/jpublic-01.ifb +COMMENT:This iCalendar file contains busy time information for + the next three months. +END:VFREEBUSY +BEGIN:VFREEBUSY +ORGANIZER:jsmith@host.com +DTSTART:19980313T141711Z +DTEND:19980410T141711Z +FREEBUSY:19980314T233000Z/19980315T003000Z +FREEBUSY:19980316T153000Z/19980316T163000Z +FREEBUSY:19980318T030000Z/19980318T040000Z +URL:http://www.host.com/calendar/busytime/jsmith.ifb +END:VFREEBUSY +BEGIN:VTIMEZONE +TZID:US-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTAMP:19970901T130000Z +DTSTART:19971026T020000 +RDATE:19971026T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19971026T020000 +RDATE:19970406T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US-Eastern +LAST-MODIFIED:19870101T000000Z +TZURL:http://zones.stds_r_us.net/tz/US-Eastern +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US--Fictitious-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T070000Z +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:US--Fictitious-Eastern +LAST-MODIFIED:19870101T000000Z +BEGIN:STANDARD +DTSTART:19671029T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19870405T020000 +RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T070000Z +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +BEGIN:DAYLIGHT +DTSTART:19990424T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=4 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VALARM +TRIGGER;VALUE=DATE-TIME:19970317T133000Z +REPEAT:4 +DURATION:PT15M +ACTION:AUDIO +ATTACH;FMTTYPE=audio/basic:ftp://host.com/pub/sounds/bell-01.aud +END:VALARM +BEGIN:VALARM +TRIGGER:-PT30M +REPEAT:2 +DURATION:PT15M +ACTION:DISPLAY +DESCRIPTION:Breakfast meeting with executive\n + team at 8:30 AM EST. +END:VALARM +BEGIN:VALARM +TRIGGER:-P2D +ACTION:EMAIL +ATTENDEE:MAILTO:john_doe@host.com +SUMMARY:*** REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING *** +DESCRIPTION:A draft agenda needs to be sent out to the attendees + to the weekly managers meeting (MGR-LIST). Attached is a + pointer the document template for the agenda file. +ATTACH;FMTTYPE=application/binary:http://host.com/templates/agen + da.doc +END:VALARM +BEGIN:VALARM +TRIGGER;VALUE=DATE-TIME:19980101T050000Z +REPEAT:23 +DURATION:PT1H +ACTION:PROCEDURE +ATTACH;FMTTYPE=application/binary:ftp://host.com/novo- + procs/felizano.exe +END:VALARM +BEGIN:VCALENDAR +PRODID:-//RDU Software//NONSGML HandCal//EN +VERSION:2.0 +BEGIN:VTIMEZONE +TZID:US-Eastern +BEGIN:STANDARD +DTSTART:19981025T020000 +RDATE:19981025T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19990404T020000 +RDATE:19990404T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +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 +CLASS:PUBLIC +CREATED:19980309T130000Z +SUMMARY:XYZ Project Review +DTSTART;TZID=US-Eastern:19980312T083000 +DTEND;TZID=US-Eastern:19980312T093000 +LOCATION:1CP Conference Room 4350 +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +METHOD:PUBLISH +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VEVENT +DTSTAMP:19970324T1200Z +SEQUENCE:0 +UID:uid3@host1.com +ORGANIZER:MAILTO:jdoe@host1.com +DTSTART:19970324T123000Z +DTEND:19970324T210000Z +CATEGORIES:MEETING,PROJECT +CLASS:PUBLIC +SUMMARY:Calendaring Interoperability Planning Meeting +DESCRIPTION:Discuss how we can test c&s interoperability\n + using iCalendar and other IETF standards. +LOCATION:LDB Lobby +ATTACH;FMTTYPE=application/postscript:ftp://xyzCorp.com/pub/ + conf/bkgrnd.ps +END:VEVENT +END:VCALENDAR + +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VTODO +DTSTAMP:19980130T134500Z +SEQUENCE:2 +UID:uid4@host1.com +ORGANIZER:MAILTO:unclesam@us.gov +ATTENDEE;PARTSTAT=ACCEPTED:MAILTO:jqpublic@host.com +DUE:19980415T235959 +STATUS:NEEDS-ACTION +SUMMARY:Submit Income Taxes +BEGIN:VALARM +ACTION:AUDIO +TRIGGER:19980403T120000 +ATTACH;FMTTYPE=audio/basic:http://host.com/pub/audio- + files/ssbanner.aud +REPEAT:4 +DURATION:PT1H +END:VALARM +END:VTODO +END:VCALENDAR + +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VJOURNAL +DTSTAMP:19970324T120000Z +UID:uid5@host1.com +ORGANIZER:MAILTO:jsmith@host.com +STATUS:DRAFT +CLASS:PUBLIC +CATEGORIES:Project Report, XYZ, Weekly Meeting +DESCRIPTION:Project xyz Review Meeting Minutes\n + Agenda\n1. Review of project version 1.0 requirements.\n2. + Definition + of project processes.\n3. Review of project schedule.\n + Participants: John Smith\, Jane Doe\, Jim Dandy\n-It was + decided that the requirements need to be signed off by + product marketing.\n-Project processes were accepted.\n + -Project schedule needs to account for scheduled holidays + and employee vacation time. Check with HR for specific + dates.\n-New schedule will be distributed by Friday.\n- + Next weeks meeting is cancelled. No meeting until 3/23. +END:VJOURNAL +END:VCALENDAR +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//RDU Software//NONSGML HandCal//EN +BEGIN:VFREEBUSY +ORGANIZER:MAILTO:jsmith@host.com +DTSTART:19980313T141711Z +DTEND:19980410T141711Z +FREEBUSY:19980314T233000Z/19980315T003000Z +FREEBUSY:19980316T153000Z/19980316T163000Z +FREEBUSY:19980318T030000Z/19980318T040000Z +URL:http://www.host.com/calendar/busytime/jsmith.ifb +END:VFREEBUSY +END:VCALENDAR diff --git a/libical/src/test/2446.ics b/libical/src/test/2446.ics new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/libical/src/test/2446.ics diff --git a/libical/src/test/Makefile.am b/libical/src/test/Makefile.am index d4fa33c040..4892507869 100644 --- a/libical/src/test/Makefile.am +++ b/libical/src/test/Makefile.am @@ -1,7 +1,27 @@ +if WITH_CXX +cxx_inc=-DWITH_CXX +cxx_libs=../libical/libical_cxx.la +regression_cxx = regression-cxx.cpp +else +cxx_inc= +cxx_libs= +regression_cxx = +CXX=@CC@ +endif -noinst_PROGRAMS = copycluster regression parser storage stow recur testmime testvcal process testclassify +if WITH_BDB4 +bdb4_inc=-DWITH_BDB -I@BDB_DIR@/include +bdb4_libs=@BDB_DIR_LIB@/@BDB_LIB@ +else +bdb4_inc= +bdb4_libs= +endif -LDADD = ../libicalss/.libs/libicalss.a ../libicalvcal/.libs/libicalvcal.a ../libical/.libs/libical.a +noinst_PROGRAMS = copycluster regression parser stow recur testmime testvcal process + +LDADD = ../libicalss/libicalss.la ../libicalvcal/libicalvcal.la $(cxx_libs) ../libical/libical.la $(bdb4_libs) + +LIBS = @PTHREAD_LIBS@ INCLUDES = \ -I. \ @@ -11,15 +31,24 @@ INCLUDES = \ -I../libical \ -I$(srcdir)/../libical \ -I../libicalss \ - -I$(srcdir)/../libicalss + -I$(srcdir)/../libicalss \ + $(cxx_inc) $(bdb4_inc) +TESTS=regression copycluster_SOURCES = copycluster.c -regression_SOURCES = regression.c +regression_SOURCES = \ + regression.c \ + regression.h \ + regression-component.c \ + regression-classify.c \ + regression-utils.c \ + regression-recur.c \ + regression-storage.c \ + $(regression_cxx) + parser_SOURCES = icaltestparser.c -storage_SOURCES = storage.c stow_SOURCES = stow.c testvcal_SOURCES = testvcal.c recur_SOURCES = recur.c testmime_SOURCES = testmime.c process_SOURCES = process.c -testclassify_SOURCES = testclassify.c diff --git a/libical/src/test/copycluster.c b/libical/src/test/copycluster.c index 4eefc37758..6c57177290 100644 --- a/libical/src/test/copycluster.c +++ b/libical/src/test/copycluster.c @@ -26,14 +26,14 @@ ======================================================================*/ #include <stdio.h> /* for printf */ -#include "ical.h" -#include "icalss.h" -#include "icalfileset.h" #include <errno.h> #include <string.h> /* For strerror */ #include <signal.h> /* for signal */ #include <unistd.h> /* for alarm */ -#include "icalrestriction.h" +#include <stdlib.h> /* for exit */ + +#include "ical.h" +#include "icalss.h" static void sig_alrm(int i){ fprintf(stderr,"Could not get lock on file\n"); @@ -48,7 +48,7 @@ void usage(char* arg0) { int main(int c, char *argv[]){ - icalfileset *clusterin, *clusterout; + icalset *clusterin, *clusterout; icalcomponent *itr; int count=0; int tostdout = 0; @@ -63,23 +63,26 @@ int main(int c, char *argv[]){ } - icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); - + /*icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL);*/ signal(SIGALRM,sig_alrm); - alarm(0); + alarm(10); clusterin = icalfileset_new(argv[1]); alarm(0); if (clusterin == 0){ - printf("Could not open input cluster \"%s\"",argv[1]); - + printf("Could not open input cluster \"%s\"\n",argv[1]); + if(icalerrno!= ICAL_NO_ERROR){ + printf("Error: %s\n",icalerror_strerror(icalerrno)); + } exit(1); } if (!tostdout){ + alarm(10); clusterout = icalfileset_new(argv[2]); + alarm(0); if (clusterout == 0){ printf("Could not open output cluster \"%s\"\n",argv[2]); exit(1); @@ -117,11 +120,11 @@ int main(int c, char *argv[]){ printf("Transfered %d components\n",count); - icalfileset_free(clusterin); + icalset_free(clusterin); if (!tostdout){ icalfileset_mark(clusterout); - icalfileset_free(clusterout); + icalset_free(clusterout); } return 0; diff --git a/libical/src/test/findobj.c b/libical/src/test/findobj.c index c31101c33d..3c1eac85e3 100644 --- a/libical/src/test/findobj.c +++ b/libical/src/test/findobj.c @@ -26,12 +26,11 @@ ======================================================================*/ #include <stdio.h> /* for printf */ -#include "ical.h" -#include "icalcalendar.h" -#include "icaldirset.h" #include <errno.h> #include <string.h> /* For strerror */ -#include "icalrestriction.h" + +#include "ical.h" +#include "icalss.h" /* This program finds an object stored in a calendar */ diff --git a/libical/src/test/itip.ics b/libical/src/test/itip.ics new file mode 100644 index 0000000000..9a71660a75 --- /dev/null +++ b/libical/src/test/itip.ics @@ -0,0 +1,14 @@ + +BEGIN:VCALENDAR +METHOD:REPLY +PRODID:-//ACME/DesktopCalendar//EN +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:a@example.com +ATTENDEE:mailto:eric@agony.busboom.org +DTSTART:19970701T200000Z +DTSTAMP:19970611T190000Z +SUMMARY:ST. PAUL SAINTS -VS- DULUTH-SUPERIOR DUKES +UID:0981234-1234234-23@example.com +END:VEVENT +END:VCALENDAR diff --git a/libical/src/test/outgoing.ics b/libical/src/test/outgoing.ics new file mode 100644 index 0000000000..9f9fd3fd69 --- /dev/null +++ b/libical/src/test/outgoing.ics @@ -0,0 +1,544 @@ +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170735Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170735Z +UID + :calsrv.example.com-873970198738704@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 2 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170735Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170953Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170953Z +UID + :calsrv.example.com-873970198738704@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 2 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T170953Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=ACCEPTED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T171147Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :Unfortunately\, I have another commitment that conflicts with this + meeting. I am delegating my attendance to Bob. +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DELEGATED + ;DELEGATED-TO=bob@cal.softwarestudio.org + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +X-LIC-NOTE + : Overlap with Slot 2\, 1300 to 1400\, should be counterproposed +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + :Mailto:alice@cal.softwarestudio.org +ATTENDEE + ;RSVP=TRUE + ;CUTYPE=INDIVIDUAL + ;CN=B + :Mailto:B@example.com +DTSTAMP + :19970611T040000Z +DTSTART + :19970701T070000 +DTEND + :19970701T080000 +SUMMARY + :Overlap 2 +UID + :calsrv.example.com-873970198738704@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T171147Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can't make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DECLINED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T171154Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :Unfortunately\, I have another commitment that conflicts with this + meeting. I am delegating my attendance to Bob. +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DELEGATED + ;DELEGATED-TO=bob@cal.softwarestudio.org + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +X-LIC-NOTE + : Overlap with Slot 2\, 1300 to 1400\, should be counterproposed +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + :Mailto:alice@cal.softwarestudio.org +ATTENDEE + ;RSVP=TRUE + ;CUTYPE=INDIVIDUAL + ;CN=B + :Mailto:B@example.com +DTSTAMP + :19970611T040000Z +DTSTART + :19970701T070000 +DTEND + :19970701T080000 +SUMMARY + :Overlap 2 +UID + :calsrv.example.com-873970198738704@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T171154Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can't make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DECLINED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T144324Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :Unfortunately\, I have another commitment that conflicts with this + meeting. I am delegating my attendance to Bob. +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DELEGATED + ;DELEGATED-TO=bob@cal.softwarestudio.org + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +X-LIC-NOTE + : Overlap with Slot 2\, 1300 to 1400\, should be counterproposed +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + :Mailto:alice@cal.softwarestudio.org +ATTENDEE + ;RSVP=TRUE + ;CUTYPE=INDIVIDUAL + ;CN=B + :Mailto:B@example.com +DTSTAMP + :19970611T040000Z +DTSTART + :19970701T230000 +DTEND + :19970702T000000 +SUMMARY + :Overlap 2 +UID + :calsrv.example.com-873970198738704@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T144324Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can't make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DECLINED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T144412Z +UID + :calsrv.example.com-873970198738703@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + : Overlap 1 +SEQUENCE + :0 +COMMENT + :Unfortunately\, I have another commitment that conflicts with this + meeting. I am delegating my attendance to Bob. +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DELEGATED + ;DELEGATED-TO=bob@cal.softwarestudio.org + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +X-LIC-NOTE + : Overlap with Slot 2\, 1300 to 1400\, should be counterproposed +METHOD + :REQUEST +VERSION + :2.0 +BEGIN:VEVENT +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + :Mailto:alice@cal.softwarestudio.org +ATTENDEE + ;RSVP=TRUE + ;CUTYPE=INDIVIDUAL + ;CN=B + :Mailto:B@example.com +DTSTAMP + :19970611T040000Z +DTSTART + :19970701T230000 +DTEND + :19970702T000000 +SUMMARY + :Overlap 2 +UID + :calsrv.example.com-873970198738704@example.com +SEQUENCE + :0 +STATUS + :CONFIRMED +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD + :REPLY +VERSION + :2.0 +PRODID + :-//SoftwareStudio//NONSGML libical 0.21 //EN +BEGIN:VEVENT +DTSTAMP + :20001121T144412Z +UID + :calsrv.example.com-873970198738705@example.com +ORGANIZER + :Mailto:bob@cal.softwarestudio.org +SUMMARY + :Overlap 3 +SEQUENCE + :0 +COMMENT + :I can't make it to this meeting +ATTENDEE + ;ROLE=CHAIR + ;CUTYPE=INDIVIDUAL + ;CN=Alice + ;PARTSTAT=DECLINED + :Mailto:alice@cal.softwarestudio.org +END:VEVENT +END:VCALENDAR diff --git a/libical/src/test/process.c b/libical/src/test/process.c index 56f1c65fb1..466cf38101 100644 --- a/libical/src/test/process.c +++ b/libical/src/test/process.c @@ -22,55 +22,12 @@ ======================================================================*/ #include <stdio.h> /* for printf */ -#include "ical.h" -#include "icalss.h" #include <errno.h> #include <string.h> /* For strerror */ #include <stdlib.h> /* for free */ -struct class_map { - ical_class class; - char *str; -} class_map[] = { - {ICAL_NO_CLASS,"No class"}, - {ICAL_PUBLISH_NEW_CLASS,"New Publish"}, - {ICAL_PUBLISH_UPDATE_CLASS,"New Publish"}, - {ICAL_REQUEST_NEW_CLASS,"New request"}, - {ICAL_REQUEST_UPDATE_CLASS,"Update"}, - {ICAL_REQUEST_RESCHEDULE_CLASS,"Reschedule"}, - {ICAL_REQUEST_DELEGATE_CLASS,"Delegate"}, - {ICAL_REQUEST_NEW_ORGANIZER_CLASS,"New Organizer"}, - {ICAL_REQUEST_FORWARD_CLASS,"Forward"}, - {ICAL_REQUEST_STATUS_CLASS,"Status request"}, - {ICAL_REPLY_ACCEPT_CLASS,"Accept reply"}, - {ICAL_REPLY_DECLINE_CLASS,"Decline reply"}, - {ICAL_REPLY_CRASHER_ACCEPT_CLASS,"Crasher's accept reply"}, - {ICAL_REPLY_CRASHER_DECLINE_CLASS,"Crasher's decline reply"}, - {ICAL_ADD_INSTANCE_CLASS,"Add instance"}, - {ICAL_CANCEL_EVENT_CLASS,"Cancel event"}, - {ICAL_CANCEL_INSTANCE_CLASS,"Cancel instance"}, - {ICAL_CANCEL_ALL_CLASS,"Cancel all instances"}, - {ICAL_REFRESH_CLASS,"Refresh"}, - {ICAL_COUNTER_CLASS,"Counter"}, - {ICAL_DECLINECOUNTER_CLASS,"Decline counter"}, - {ICAL_MALFORMED_CLASS,"Malformed"}, - {ICAL_OBSOLETE_CLASS,"Obsolete"}, - {ICAL_MISSEQUENCED_CLASS,"Missequenced"}, - {ICAL_UNKNOWN_CLASS,"Unknown"} -}; - -char* find_class_string(ical_class class) -{ - int i; - - for (i = 0;class_map[i].class != ICAL_UNKNOWN_CLASS;i++){ - if (class_map[i].class == class){ - return class_map[i].str; - } - } - - return "Unknown"; -} +#include "ical.h" +#include "icalss.h" void send_message(icalcomponent *reply,const char* this_user) { @@ -84,7 +41,7 @@ int main(int argc, char* argv[]) { icalcomponent *c, *next_c; int i=0; - char *class_string; + const char *class_string; int dont_remove; icalset* f = icalset_new_file("../../test-data/process-incoming.ics"); @@ -103,7 +60,7 @@ int main(int argc, char* argv[]) /* Foreach incoming message */ for(c=icalset_get_first_component(f);c!=0;c = next_c){ - ical_class class; + icalproperty_xlicclass class; icalcomponent *match; icalcomponent *inner; icalcomponent *reply = 0; @@ -130,7 +87,7 @@ int main(int argc, char* argv[]) class = icalclassify(c,match,this_user); - class_string = find_class_string(class); + class_string = icalproperty_enum_to_string(class); /* Print out the notes associated with the incoming component and the matched component in the */ @@ -171,7 +128,7 @@ int main(int argc, char* argv[]) /* Main processing structure */ switch (class){ - case ICAL_NO_CLASS: { + case ICAL_XLICCLASS_NONE: { char temp[1024]; /* Huh? Return an error to sender */ icalrestriction_check(c); @@ -191,15 +148,15 @@ int main(int argc, char* argv[]) break; } - case ICAL_PUBLISH_NEW_CLASS: { + case ICAL_XLICCLASS_PUBLISHNEW: { /* Don't accept published events from anyone but - self. If self, fall through to ICAL_REQUEST_NEW_CLASS */ + self. If self, fall through to ICAL_XLICCLASS_REQUESTNEW */ } - case ICAL_REQUEST_NEW_CLASS: { + case ICAL_XLICCLASS_REQUESTNEW: { /* Book the new component if it does not overlap anything. If the time is busy and the start time is @@ -283,110 +240,114 @@ conflicts with this meeting. I am proposing a time that works better for me."); } break; } - case ICAL_PUBLISH_FREEBUSY_CLASS: { + case ICAL_XLICCLASS_PUBLISHFREEBUSY: { /* Store the busy time information in a file named after the sender */ break; } - case ICAL_PUBLISH_UPDATE_CLASS: { + case ICAL_XLICCLASS_PUBLISHUPDATE: { /* Only accept publish updates from self. If self, fall - throught to ICAL_REQUEST_UPDATE_CLASS */ + throught to ICAL_XLICCLASS_REQUESTUPDATE */ } - case ICAL_REQUEST_UPDATE_CLASS: { + case ICAL_XLICCLASS_REQUESTUPDATE: { /* always accept the changes */ break; } - case ICAL_REQUEST_RESCHEDULE_CLASS: { + case ICAL_XLICCLASS_REQUESTRESCHEDULE: { /* Use same rules as REQUEST_NEW */ icalcomponent *overlaps; overlaps = icalclassify_find_overlaps(cal,c); break; } - case ICAL_REQUEST_DELEGATE_CLASS: { + case ICAL_XLICCLASS_REQUESTDELEGATE: { break; } - case ICAL_REQUEST_NEW_ORGANIZER_CLASS: { + case ICAL_XLICCLASS_REQUESTNEWORGANIZER: { break; } - case ICAL_REQUEST_FORWARD_CLASS: { + case ICAL_XLICCLASS_REQUESTFORWARD: { break; } - case ICAL_REQUEST_STATUS_CLASS: { + case ICAL_XLICCLASS_REQUESTSTATUS: { break; } - case ICAL_REQUEST_FREEBUSY_CLASS: { + case ICAL_XLICCLASS_REQUESTFREEBUSY: { break; } - case ICAL_REPLY_ACCEPT_CLASS: { + case ICAL_XLICCLASS_REPLYACCEPT: { /* Change the PARTSTAT of the sender */ break; } - case ICAL_REPLY_DECLINE_CLASS: { + case ICAL_XLICCLASS_REPLYDECLINE: { /* Change the PARTSTAT of the sender */ break; } - case ICAL_REPLY_CRASHER_ACCEPT_CLASS: { + case ICAL_XLICCLASS_REPLYCRASHERACCEPT: { /* Add the crasher to the ATTENDEE list with the appropriate PARTSTAT */ break; } - case ICAL_REPLY_CRASHER_DECLINE_CLASS: { + case ICAL_XLICCLASS_REPLYCRASHERDECLINE: { /* Add the crasher to the ATTENDEE list with the appropriate PARTSTAT */ break; } - case ICAL_ADD_INSTANCE_CLASS: { + case ICAL_XLICCLASS_ADDINSTANCE: { break; } - case ICAL_CANCEL_EVENT_CLASS: { + case ICAL_XLICCLASS_CANCELEVENT: { /* Remove the component */ break; } - case ICAL_CANCEL_INSTANCE_CLASS: { + case ICAL_XLICCLASS_CANCELINSTANCE: { break; } - case ICAL_CANCEL_ALL_CLASS: { + case ICAL_XLICCLASS_CANCELALL: { /* Remove the component */ break; } - case ICAL_REFRESH_CLASS: { + case ICAL_XLICCLASS_REFRESH: { /* Resend the latest copy of the request */ break; } - case ICAL_COUNTER_CLASS: { + case ICAL_XLICCLASS_COUNTER: { break; } - case ICAL_DECLINECOUNTER_CLASS: { + case ICAL_XLICCLASS_DECLINECOUNTER: { break; } - case ICAL_MALFORMED_CLASS: { + case ICAL_XLICCLASS_MALFORMED: { /* Send back an error */ break; } - case ICAL_OBSOLETE_CLASS: { + case ICAL_XLICCLASS_OBSOLETE: { printf(" ** Got an obsolete component:\n%s", icalcomponent_as_ical_string(c)); /* Send back an error */ break; } - case ICAL_MISSEQUENCED_CLASS: { + case ICAL_XLICCLASS_MISSEQUENCED: { printf(" ** Got a missequenced component:\n%s", icalcomponent_as_ical_string(c)); /* Send back an error */ break; } - case ICAL_UNKNOWN_CLASS: { + case ICAL_XLICCLASS_UNKNOWN: { printf(" ** Don't know what to do with this component:\n%s", icalcomponent_as_ical_string(c)); /* Send back an error */ break; } + case ICAL_XLICCLASS_X: + case ICAL_XLICCLASS_REPLYDELEGATE: + default: { + } } #if(0) diff --git a/libical/src/test/recur.c b/libical/src/test/recur.c index f4d9a38647..bb23337adb 100644 --- a/libical/src/test/recur.c +++ b/libical/src/test/recur.c @@ -25,96 +25,137 @@ ======================================================================*/ -#include "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() */ #include <signal.h> /* for signal */ +#ifndef WIN32 #include <unistd.h> /* for alarm */ -#include "icalmemory.h" -#include "icaldirset.h" -#include "icalfileset.h" +#endif + +#include "ical.h" +#include "icalss.h" + +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif static void sig_alrm(int i){ fprintf(stderr,"Could not get lock on file\n"); exit(1); } +static void recur_callback(icalcomponent *comp, + struct icaltime_span *span, + void *data) +{ + printf("cb: %s", ctime(&span->start)); + printf(" %s\n", ctime(&span->end)); + +} + int main(int argc, char *argv[]) { - icalfileset *cin; - struct icaltimetype start, next; + icalset *cin; + struct icaltimetype next; icalcomponent *itr; icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator* ritr; time_t tt; char* file; - + icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); - + +#ifndef WIN32 signal(SIGALRM,sig_alrm); - - +#endif + if (argc <= 1){ - file = "../../test-data/recur.txt"; + file = "../../test-data/recur.txt"; } else if (argc == 2){ - file = argv[1]; + file = argv[1]; } else { - fprintf(stderr,"usage: recur [input file]\n"); - exit(1); + fprintf(stderr,"usage: recur [input file]\n"); + exit(1); } - + +#ifndef WIN32 alarm(300); /* to get file lock */ +#endif cin = icalfileset_new(file); +#ifndef WIN32 alarm(0); - +#endif + if(cin == 0){ - fprintf(stderr,"recur: can't open file %s\n",file); - exit(1); + fprintf(stderr,"recur: can't open file %s\n",file); + exit(1); } - - - for (itr = icalfileset_get_first_component(cin); - itr != 0; - itr = icalfileset_get_next_component(cin)){ - - desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); - dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); - rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); - - if (desc == 0 || dtstart == 0 || rrule == 0){ - printf("\n******** Error in input component ********\n"); - printf("The following component is malformed:\n %s\n", - icalcomponent_as_ical_string(itr)); - continue; - } - - printf("\n\n#### %s\n",icalproperty_get_description(desc)); - printf("#### %s\n",icalvalue_as_ical_string(icalproperty_get_value(rrule))); - recur = icalproperty_get_rrule(rrule); - start = icalproperty_get_dtstart(dtstart); - ritr = icalrecur_iterator_new(recur,start); - tt = icaltime_as_timet(start); - - printf("#### %s\n",ctime(&tt )); - - for(ritr = icalrecur_iterator_new(recur,start), - next = icalrecur_iterator_next(ritr); - !icaltime_is_null_time(next); - next = icalrecur_iterator_next(ritr)){ - - tt = icaltime_as_timet(next); - - printf(" %s",ctime(&tt )); - - } - + for (itr = icalfileset_get_first_component(cin); + itr != 0; + itr = icalfileset_get_next_component(cin)){ + + struct icaltimetype start = icaltime_from_timet(1,0); + struct icaltimetype end = icaltime_today(); + + + + desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); + dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); + rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); + + if (desc == 0 || dtstart == 0 || rrule == 0){ + printf("\n******** Error in input component ********\n"); + printf("The following component is malformed:\n %s\n", + icalcomponent_as_ical_string(itr)); + continue; + } + + printf("\n\n#### %s\n",icalproperty_get_description(desc)); + printf("#### %s\n",icalvalue_as_ical_string(icalproperty_get_value(rrule))); + recur = icalproperty_get_rrule(rrule); + start = icalproperty_get_dtstart(dtstart); + + ritr = icalrecur_iterator_new(recur,start); + + tt = icaltime_as_timet(start); + + printf("#### %s\n",ctime(&tt )); + + icalrecur_iterator_free(ritr); + + for(ritr = icalrecur_iterator_new(recur,start), + next = icalrecur_iterator_next(ritr); + !icaltime_is_null_time(next); + next = icalrecur_iterator_next(ritr)){ + + tt = icaltime_as_timet(next); + + printf(" %s",ctime(&tt )); + + } + icalrecur_iterator_free(ritr); + + icalcomponent_foreach_recurrence(itr, start, end, + recur_callback, NULL); + + + } + icalset_free(cin); + + icaltimezone_free_builtin_timezones(); + + icalmemory_free_ring(); + + free_zone_directory(); + return 0; } diff --git a/libical/src/test/regression-classify.c b/libical/src/test/regression-classify.c new file mode 100644 index 0000000000..c805047c24 --- /dev/null +++ b/libical/src/test/regression-classify.c @@ -0,0 +1,187 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: regression-classify.c + CREATOR: eric 11 February 2000 + + $Id$ + $Locker$ + + (C) COPYRIGHT 2000 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 Code is eric. The Initial Developer of the Original + Code is Eric Busboom + + + ======================================================================*/ +#include <stdio.h> /* for printf */ +#include <errno.h> +#include <string.h> /* For strerror */ + +#include "ical.h" +#include "icalss.h" +#include "regression.h" + +extern int VERBOSE; + +/* Get a note about the purpose of the property*/ +static const char* get_note(icalcomponent *c) +{ + icalproperty *p; + const char* note = 0; + + if(c != 0){ + for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY); + p!= 0; + p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){ + if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){ + note = icalproperty_get_x(p); + } + } + } + + if(note == 0){ + note = "None"; + } + + return note; +} + +/* Get the expected result about the purpose of the property*/ + +static const char* get_expect(icalcomponent *c) +{ + icalproperty *p; + const char* note = 0; + + if(c != 0){ + for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY); + p!= 0; + p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){ + if(strcmp(icalproperty_get_x_name(p),"X-LIC-EXPECT")==0){ + note = icalproperty_get_x(p); + } + } + } + + if(note == 0){ + note = "None"; + } + + return note; +} + +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 */ + icalset* incoming = icalset_new_file("../../test-data/incoming.ics"); + icalset* cal = icalset_new_file("../../test-data/calendar.ics"); + icalset* f = icalset_new_file("../../test-data/classify.ics"); + + 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,"A@example.com") == 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; + const char* match_note; + 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); + sprintf(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,"A@example.com"); + /** eventually test this too.. **/ + match_note = get_note(match); + actual_result = icalproperty_enum_to_string(class); + sprintf(msg, "expecting %s", expected_result); + 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); + +} + + diff --git a/libical/src/test/regression-component.c b/libical/src/test/regression-component.c new file mode 100644 index 0000000000..0babb579ba --- /dev/null +++ b/libical/src/test/regression-component.c @@ -0,0 +1,580 @@ +#include "ical.h" +#include "regression.h" + +#include <string.h> +extern int VERBOSE; + +void create_simple_component(void) +{ + + icalcomponent* calendar; + icalproperty *version, *bogus; + + /* Create calendar and add properties */ + calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); + + ok("create vcalendar component", (calendar!=NULL)); + + icalcomponent_add_property( + calendar, + icalproperty_new_version("2.0") + ); + + version = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); + ok("version property added", (version!=NULL)); + + bogus = icalcomponent_get_first_property(calendar,ICAL_DTSTART_PROPERTY); + ok("bogus dtstart not found", (bogus == NULL)); + + if (VERBOSE && calendar) + printf("%s\n",icalcomponent_as_ical_string(calendar)); + + icalcomponent_free(calendar); +} + + +static char* create_new_component_str = +"BEGIN:VCALENDAR\n" +"VERSION:2.0\n" +"PRODID:-//RDU Software//NONSGML HandCal//EN\n" +"BEGIN:VTIMEZONE\n" +"TZID:America/New_York\n" +"BEGIN:DAYLIGHT\n" +"DTSTART:20020606T212449\n" +"RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n" +"TZOFFSETFROM:-0500\n" +"TZOFFSETTO:-0400\n" +"TZNAME:EST\n" +"END:DAYLIGHT\n" +"BEGIN:STANDARD\n" +"DTSTART:20020606T212449\n" +"RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n" +"TZOFFSETFROM:-0400\n" +"TZOFFSETTO:-0500\n" +"TZNAME:EST\n" +"END:STANDARD\n" +"END:VTIMEZONE\n" +"BEGIN:VEVENT\n" +"DTSTAMP:20020606T212449\n" +"UID:guid-1.host1.com\n" +"ORGANIZER;ROLE=CHAIR:mrbig@host.com\n" +"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CUTYPE=GROUP:employee-A@host.com\n" +"DESCRIPTION:Project XYZ Review Meeting\n" +"CATEGORIES:MEETING\n" +"CLASS:PRIVATE\n" +"CREATED:20020606T212449\n" +"SUMMARY:XYZ Project Review\n" +"DTSTART;TZID=America/New_York:20020606T212449\n" +"DTEND;TZID=America/New_York:20020606T212449\n" +"LOCATION:1CP Conference Room 4350\n" +"END:VEVENT\n" +"END:VCALENDAR\n"; + + +/* Create a new component */ +void create_new_component() +{ + icalcomponent* calendar; + icalcomponent* timezone; + icalcomponent* tzc; + icalcomponent* event; + struct icaltimetype atime = icaltime_from_timet( 1023398689, 0); + struct icaldatetimeperiodtype rtime; + icalproperty* property; + char *calendar_as_string; + + rtime.period.start = icaltime_from_timet( 1023398689,0); + rtime.period.end = icaltime_from_timet( 1023409689,0); + rtime.period.end.hour++; + rtime.time = icaltime_null_time(); + + /* Create calendar and add properties */ + calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); + + + icalcomponent_add_property( + calendar, + icalproperty_new_version("2.0") + ); + + icalcomponent_add_property( + calendar, + icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN") + ); + + /* Create a timezone object and add it to the calendar */ + + timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT); + + icalcomponent_add_property( + timezone, + icalproperty_new_tzid("America/New_York") + ); + + /* Add a sub-component of the timezone */ + tzc = icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT); + + icalcomponent_add_property( + tzc, + icalproperty_new_dtstart(atime) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_rdate(rtime) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzoffsetfrom(-5*3600) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzoffsetto(-4*3600) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzname("EST") + ); + + icalcomponent_add_component(timezone,tzc); + + icalcomponent_add_component(calendar,timezone); + + /* Add a second subcomponent */ + tzc = icalcomponent_new(ICAL_XSTANDARD_COMPONENT); + + icalcomponent_add_property( + tzc, + icalproperty_new_dtstart(atime) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_rdate(rtime) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzoffsetfrom(-4*3600) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzoffsetto(-5*3600) + ); + + icalcomponent_add_property( + tzc, + icalproperty_new_tzname("EST") + ); + + icalcomponent_add_component(timezone,tzc); + + /* Add an event */ + + event = icalcomponent_new(ICAL_VEVENT_COMPONENT); + + icalcomponent_add_property( + event, + icalproperty_new_dtstamp(atime) + ); + + icalcomponent_add_property( + event, + icalproperty_new_uid("guid-1.host1.com") + ); + + /* add a property that has parameters */ + property = icalproperty_new_organizer("mrbig@host.com"); + + icalproperty_add_parameter( + property, + icalparameter_new_role(ICAL_ROLE_CHAIR) + ); + + icalcomponent_add_property(event,property); + + /* add another property that has parameters */ + property = icalproperty_new_attendee("employee-A@host.com"); + + icalproperty_add_parameter( + property, + icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT) + ); + + icalproperty_add_parameter( + property, + icalparameter_new_rsvp(ICAL_RSVP_TRUE) + ); + + 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_PRIVATE) + ); + + 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("America/New_York") + ); + + icalcomponent_add_property(event,property); + + + property = icalproperty_new_dtend(atime); + + icalproperty_add_parameter( + property, + icalparameter_new_tzid("America/New_York") + ); + + icalcomponent_add_property(event,property); + + icalcomponent_add_property( + event, + icalproperty_new_location("1CP Conference Room 4350") + ); + + icalcomponent_add_component(calendar,event); + + calendar_as_string = icalcomponent_as_ical_string(calendar); + + is("build large, complex component", + calendar_as_string, + create_new_component_str); + + if (VERBOSE && calendar) + printf("%s\n",icalcomponent_as_ical_string(calendar)); + + + if (calendar) + icalcomponent_free(calendar); + +} + +/* Create a new component, using the va_args list */ + +void create_new_component_with_va_args() +{ + + icalcomponent* calendar; + struct icaltimetype atime = icaltime_from_timet( time(0),0); + struct icaldatetimeperiodtype rtime; + + rtime.period.start = icaltime_from_timet( time(0),0); + rtime.period.end = icaltime_from_timet( time(0),0); + rtime.period.end.hour++; + rtime.time = icaltime_null_time(); + + calendar = + icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version("2.0"), + icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), + icalcomponent_vanew( + ICAL_VTIMEZONE_COMPONENT, + icalproperty_new_tzid("America/New_York"), + icalcomponent_vanew( + ICAL_XDAYLIGHT_COMPONENT, + icalproperty_new_dtstart(atime), + icalproperty_new_rdate(rtime), + icalproperty_new_tzoffsetfrom(-4.0), + icalproperty_new_tzoffsetto(-5.0), + icalproperty_new_tzname("EST"), + 0 + ), + icalcomponent_vanew( + ICAL_XSTANDARD_COMPONENT, + icalproperty_new_dtstart(atime), + icalproperty_new_rdate(rtime), + icalproperty_new_tzoffsetfrom(-5.0), + icalproperty_new_tzoffsetto(-4.0), + icalproperty_new_tzname("EST"), + 0 + ), + 0 + ), + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstamp(atime), + icalproperty_new_uid("guid-1.host1.com"), + icalproperty_vanew_organizer( + "mrbig@host.com", + icalparameter_new_role(ICAL_ROLE_CHAIR), + 0 + ), + icalproperty_vanew_attendee( + "employee-A@host.com", + icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), + icalparameter_new_rsvp(ICAL_RSVP_TRUE), + 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("America/New_York"), + 0 + ), + icalproperty_vanew_dtend( + atime, + icalparameter_new_tzid("America/New_York"), + 0 + ), + icalproperty_new_location("1CP Conference Room 4350"), + 0 + ), + 0 + ); + + ok("creating a complex vcalendar", (calendar != NULL)); + if (VERBOSE && calendar) + printf("%s\n",icalcomponent_as_ical_string(calendar)); + + icalcomponent_free(calendar); + +} + +static void print_span(int c, struct icaltime_span span ){ + printf("span-->%d, %d\n", (int)span.start, (int)span.end); + if (span.start == 0) + printf("#%02d start: (empty)\n",c); + else + printf("#%02d start: %s\n",c,ical_timet_string(span.start)); + + if (span.end == 0) + printf(" end : (empty)\n"); + else + printf(" end : %s\n",ical_timet_string(span.end)); + +} + +/** Test icalcomponent_get_span() + * + */ +void test_icalcomponent_get_span() +{ + time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, + Sat Nov 4 15:00:00 PST 2000 */ + time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 + Sat Nov 4 16:00:00 PST 2000 */ + struct icaldurationtype dur; + struct icaltime_span span; + icalcomponent *c; + icaltimezone *azone, *bzone; + int tnum = 0; + + /** test 0 + * Direct assigning time_t means they will be interpreted as UTC + */ + span.start = tm1; + span.end = tm2; + if (VERBOSE) print_span(tnum++,span); + + /** test 1 + * We specify times in a timezone, the returned span is in UTC + */ + azone = icaltimezone_get_builtin_timezone("America/Los_Angeles"); + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart( + icaltime_from_timet_with_zone(tm1,0,azone), + icalparameter_new_tzid("America/Los_Angeles"),0), + icalproperty_vanew_dtend( + icaltime_from_timet_with_zone(tm2,0,azone), + icalparameter_new_tzid("America/Los_Angeles"),0), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("America/Los_Angeles", span.start, 973407600); + icalcomponent_free(c); + + /** test 2 + * We specify times as floating, the returned span is in UTC + * with no conversion applied - so result should be as test 0 + */ + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0),0), + icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("floating time", span.start, tm1); + + icalcomponent_free(c); + + /** test 3 + * We specify times in a timezone, the returned span is in UTC + */ + azone = icaltimezone_get_builtin_timezone("America/New_York"); + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart( + icaltime_from_timet_with_zone(tm1,0,azone), + icalparameter_new_tzid("America/New_York"),0), + icalproperty_vanew_dtend( + icaltime_from_timet_with_zone(tm2,0,azone), + icalparameter_new_tzid("America/New_York"),0), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("America/New_York", span.start, 973396800); + + icalcomponent_free(c); + + /** test 4 + * We specify times in two different timezones, the returned span + * is in UTC + */ + azone = icaltimezone_get_builtin_timezone("America/New_York"); + bzone = icaltimezone_get_builtin_timezone("America/Los_Angeles"); + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart( + icaltime_from_timet_with_zone(tm1,0,azone), + icalparameter_new_tzid("America/New_York"),0), + icalproperty_vanew_dtend( + icaltime_from_timet_with_zone(tm2,0,bzone), + icalparameter_new_tzid("America/Los_Angeles"),0), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("America/New_York", span.start, 973396800); + + icalcomponent_free(c); + + /** test 5 + * We specify start time in a timezone and a duration, the returned span + * is in UTC + */ + azone = icaltimezone_get_builtin_timezone("America/Los_Angeles"); + memset(&dur,0,sizeof(dur)); + dur.minutes = 30; + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart( + icaltime_from_timet_with_zone(tm1,0,azone), + icalparameter_new_tzid("America/Los_Angeles"),0), + icalproperty_new_duration(dur), + + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("America/Los_Angeles w/ duration", span.end, 973409400); + + icalcomponent_free(c); + + icalerror_errors_are_fatal = 0; + /** test 6 + * We specify only start time, should return a null span with no error + */ + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart(icaltime_from_timet(tm1,0)), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("null span", span.start, 0); + icalcomponent_free(c); + + /** test 7 + * We specify start and end date + */ + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart(icaltime_from_timet(tm1,1)), + icalproperty_new_dtend(icaltime_from_timet(tm1,1)), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("UTC", span.start, 973296000); + icalcomponent_free(c); + + /** test 8 + * We specify start and end date + */ + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart(icaltime_from_timet(tm1,1)), + icalproperty_new_dtend(icaltime_from_timet(tm2,1)), + 0 + ); + + span = icalcomponent_get_span(c); + int_is("UTC #2", span.start, 973296000); + if (VERBOSE) print_span(tnum++,span); + + icalcomponent_free(c); + + /** test 9 + * We specify start date + */ + c = icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart(icaltime_from_timet(tm1,1)), + 0 + ); + + span = icalcomponent_get_span(c); + if (VERBOSE) print_span(tnum++,span); + int_is("start date only", span.end, 973382399); + + icalcomponent_free(c); + + /* assert(icalerrno == ICAL_MALFORMEDDATA_ERROR); */ + icalerror_errors_are_fatal = 1; +} diff --git a/libical/src/test/regression-cxx.cpp b/libical/src/test/regression-cxx.cpp new file mode 100644 index 0000000000..e7605b8531 --- /dev/null +++ b/libical/src/test/regression-cxx.cpp @@ -0,0 +1,137 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include "icalparameter_cxx.h" +#include "icalproperty_cxx.h" +#include "vcomponent.h" +#include "regression.h" + +char content[] = "BEGIN:VCALENDAR\n\ +VERSION:2.1\n\ +BEGIN:VEVENT\n\ +UID:abcd12345\n\ +DTSTART:20020307T180000Z\n\ +DTEND:20020307T190000Z\n\ +SUMMARY:Important Meeting\n\ +END:VEVENT\n\ +END:VCALENDAR"; + +void test_cxx(void) +{ + ICalProperty *summProp = new ICalProperty(ICAL_SUMMARY_PROPERTY); + ICalProperty *startProp = new ICalProperty(ICAL_DTSTART_PROPERTY); + ICalProperty *endProp = new ICalProperty(ICAL_DTEND_PROPERTY); + ICalProperty *locationProp = new ICalProperty(ICAL_LOCATION_PROPERTY); + ICalProperty *descProp = new ICalProperty(ICAL_DESCRIPTION_PROPERTY); + + ok("Valid SUMMARY Property", (summProp != 0)); + ok("Valid DTSTART Property", (startProp != 0)); + ok("Valid DTEND Property", (endProp != 0)); + ok("Valid LOCATION Property", (locationProp != 0)); + ok("Valid DESCRIPTION Property", (descProp != 0)); + + struct icaltimetype starttime = icaltime_from_string("20011221T180000Z"); // UTC time ends in Z + struct icaltimetype endtime = icaltime_from_string("20020101T080000Z"); // UTC time ends in Z + + summProp->set_summary("jon said: change dir to c:\\rest\\test\\nest to get the file called <foo.dat>\nthis should be in the next line."); + startProp->set_dtstart(starttime); + endProp->set_dtend(endtime); + locationProp->set_location("SF, California; Seattle, Washington"); + descProp->set_description("The best cities on the west coast, hit 'NO' if you don't agree!\n"); + + VEvent *vEvent = new VEvent(); + + ok("Create a new VEvent", (vEvent!=0)); + + vEvent->add_property(summProp); + vEvent->add_property(startProp); + vEvent->add_property(endProp); + vEvent->add_property(locationProp); + vEvent->add_property(descProp); + + // + is ("vEvent->get_summary()", + vEvent->get_summary(), + "jon said: change dir to c:\\rest\\test\\nest to get the file called <foo.dat>\nthis should be in the next line."); + + is ("vEvent->get_dtstart()", + icaltime_as_ical_string(vEvent->get_dtstart()), + "20011221T180000Z"); + + is ("vEvent->get_dtend()", + icaltime_as_ical_string(vEvent->get_dtend()), + "20020101T080000Z"); + + ok ("vEvent->as_ical_string()", + (vEvent->as_ical_string() != 0)); + + if (VERBOSE) { + printf("Summary: %s\n", vEvent->get_summary()); + printf("DTSTART: %s\n", icaltime_as_ical_string(vEvent->get_dtstart())); + printf("DTEND: %s\n", icaltime_as_ical_string(vEvent->get_dtend())); + printf("LOCATION: %s\n", vEvent->get_location()); + printf("DESCRIPTION: %s\n", vEvent->get_description()); + + printf("vcomponent: %s", vEvent->as_ical_string()); + } + + VComponent ic(icalparser_parse_string((const char*)content)); + ok("Parsing component", (ic.is_valid())); + + if (VERBOSE) + printf("%s\n", ic.as_ical_string()); + + // component is wrapped within BEGIN:VCALENDAR END:VCALENDAR + // we need to unwrap it. + + VEvent* sub_ic = dynamic_cast<VEvent*>(ic.get_first_component(ICAL_VEVENT_COMPONENT)); + + int_is("Getting VEvent subcomponent", + sub_ic->isa(), + ICAL_VEVENT_COMPONENT); + + while (sub_ic != NULL) { + if (VERBOSE) + printf("subcomponent: %s\n", sub_ic->as_ical_string()); + + sub_ic = dynamic_cast<VEvent*>(ic.get_next_component(ICAL_VEVENT_COMPONENT)); + } + + VCalendar* cal = new VCalendar(); + VAgenda* vAgenda = new VAgenda(); + + ok("Create a new VCalendar object", (cal != 0)); + ok("Create a new VAgenda object", (vAgenda != 0)); + + ICalProperty* prop = new ICalProperty(ICAL_OWNER_PROPERTY); + prop->set_owner("fred@flintstone.net"); + vAgenda->add_property(prop); + + prop = new ICalProperty(ICAL_SUMMARY_PROPERTY); + prop->set_summary("CPMain"); + vAgenda->add_property(prop); + + prop = new ICalProperty(ICAL_TZID_PROPERTY); + prop->set_tzid("America/Los_Angeles"); + vAgenda->add_property(prop); + + cal->add_component(vAgenda); + + ok("Complex VCALENDAR/VAGENDA", (cal->as_ical_string() != 0)); + + if (VERBOSE) + printf("vAgenda: %s\n", cal->as_ical_string()); + + int caughtException = 0; + try { + string foo = "HFHFHFHF"; + VComponent v = VComponent(foo); + } catch (icalerrorenum err) { + if (err == ICAL_BADARG_ERROR) { + caughtException = 1; + } + } + int_is("Testing exception handling", caughtException, 1); + +} + diff --git a/libical/src/test/regression-recur.c b/libical/src/test/regression-recur.c new file mode 100644 index 0000000000..85f643e964 --- /dev/null +++ b/libical/src/test/regression-recur.c @@ -0,0 +1,194 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: regression-recur.c + CREATOR: ebusboom 8jun00 + + DESCRIPTION: + + (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. + + ======================================================================*/ + +#include <assert.h> +#include <string.h> /* for strdup */ +#include <stdlib.h> /* for malloc */ +#include <stdio.h> /* for printf */ +#include <time.h> /* for time() */ +#include <signal.h> /* for signal */ +#ifndef WIN32 +#include <unistd.h> /* for alarm */ +#endif + +#include "ical.h" +#include "icalss.h" +#include "regression.h" + +extern int VERBOSE; + +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + + +static void sig_alrm(int i){ + fprintf(stderr,"Could not get lock on file\n"); + exit(1); +} + +/* Get the expected result about the purpose of the property*/ + +static int get_expected_numevents(icalcomponent *c) +{ + icalproperty *p; + const char* note = 0; + int num_events = 0; + + if(c != 0){ + for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY); + p!= 0; + p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){ + if(strcmp(icalproperty_get_x_name(p),"X-EXPECT-NUMEVENTS")==0){ + note = icalproperty_get_x(p); + } + } + } + + if(note != 0){ + num_events = atoi(note); + } + + + return num_events; +} + + + +static void recur_callback(icalcomponent *comp, + struct icaltime_span *span, + void *data) +{ + int *num_recurs = data; + + if (VERBOSE) { + printf("recur: %s", ctime(&span->start)); + printf(" %s", ctime(&span->end)); + } + *num_recurs = *num_recurs + 1; +} + +void test_recur_file() +{ + icalset *cin = 0; + struct icaltimetype next; + icalcomponent *itr; + icalproperty *desc, *dtstart, *rrule; + struct icalrecurrencetype recur; + icalrecur_iterator* ritr; + time_t tt; + char* file; + int num_recurs_found = 0; + + icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); + +#ifndef WIN32 + signal(SIGALRM,sig_alrm); +#endif + file = getenv("ICAL_RECUR_FILE"); + if (!file) + file = "../../test-data/recur.txt"; + +#ifndef WIN32 + alarm(15); /* to get file lock */ +#endif + cin = icalfileset_new(file); +#ifndef WIN32 + alarm(0); +#endif + + ok("opening file with recurring events", (cin!=NULL)); + assert(cin!=NULL); + + for (itr = icalfileset_get_first_component(cin); + itr != 0; + itr = icalfileset_get_next_component(cin)){ + int badcomp = 0; + int expected_events = 0; + char msg[128]; + + + struct icaltimetype start = icaltime_null_time(); + struct icaltimetype startmin = icaltime_from_timet(1,0); + struct icaltimetype endmax = icaltime_null_time(); + const char *desc_str = "malformed component"; + + desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); + dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); + rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); + if (desc) { + desc_str = icalproperty_get_description(desc); + } + + ok((char*)desc_str, !(desc == 0 || dtstart == 0 || rrule == 0)); + + if (desc == 0 || dtstart == 0 || rrule == 0) { + badcomp = 1; + if (VERBOSE) { + printf("\n******** Error in input component ********\n"); + printf("The following component is malformed:\n %s\n", desc_str); + } + continue; + } + if (VERBOSE) { + printf("\n\n#### %s\n",desc_str); + printf("#### %s\n",icalvalue_as_ical_string(icalproperty_get_value(rrule))); + } + + recur = icalproperty_get_rrule(rrule); + start = icalproperty_get_dtstart(dtstart); + + ritr = icalrecur_iterator_new(recur,start); + + tt = icaltime_as_timet(start); + + if (VERBOSE) + printf("#### %s\n",ctime(&tt )); + + icalrecur_iterator_free(ritr); + + for(ritr = icalrecur_iterator_new(recur,start), + next = icalrecur_iterator_next(ritr); + !icaltime_is_null_time(next); + next = icalrecur_iterator_next(ritr)){ + + tt = icaltime_as_timet(next); + + if (VERBOSE) + printf(" %s",ctime(&tt )); + + } + + icalrecur_iterator_free(ritr); + num_recurs_found = 0; + expected_events = get_expected_numevents(itr); + + icalcomponent_foreach_recurrence(itr, startmin, endmax, + recur_callback, &num_recurs_found); + + sprintf(msg," expecting total of %d events", expected_events); + int_is(msg, num_recurs_found, expected_events); + } + + icalset_free(cin); +} diff --git a/libical/src/test/regression-storage.c b/libical/src/test/regression-storage.c new file mode 100644 index 0000000000..6f67c6c030 --- /dev/null +++ b/libical/src/test/regression-storage.c @@ -0,0 +1,804 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: regression-storage.c + CREATOR: eric 03 April 1999 + + DESCRIPTION: + + $Id$ + $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 <assert.h> +#include <string.h> /* for strdup */ +#include <stdlib.h> /* for malloc */ +#include <stdio.h> /* for printf */ +#include <time.h> /* for time() */ + +#include "ical.h" +#include "icalss.h" +#include "regression.h" + +#define OUTPUT_FILE "filesetout.ics" + +/* define sample calendar struct */ +struct calendar { + int ID; + int total_size; + + /* offsets */ + int total_size_offset; + int vcalendar_size_offset; + int vcalendar_offset; + int title_size_offset; + int title_offset; + + /* data */ + int vcalendar_size; + char *vcalendar; + + int title_size; + char *title; + +}; + +int vcalendar_init(struct calendar **cal, char *vcalendar, char *title); + +#ifdef WITH_BDB +#include <db.h> + +int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey); +char * parse_vcalendar(const DBT *dbt) ; +char * pack_calendar(struct calendar *cal, int size); +struct calendar * unpack_calendar(char *str, int size); +#endif + +static char str[] = "BEGIN:VCALENDAR\n\ +PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ +VERSION:2.0\n\ +BEGIN:VTIMEZONE\n\ +TZID:US-Eastern\n\ +BEGIN:STANDARD\n\ +DTSTART:19981025T020000\n\ +RDATE:19981025T020000\n\ +TZOFFSETFROM:-0400\n\ +TZOFFSETTO:-0500\n\ +TZNAME:EST\n\ +END:STANDARD\n\ +BEGIN:DAYLIGHT\n\ +DTSTART:19990404T020000\n\ +RDATE:19990404T020000\n\ +TZOFFSETFROM:-0500\n\ +TZOFFSETTO:-0400\n\ +TZNAME:EDT\n\ +END:DAYLIGHT\n\ +END:VTIMEZONE\n\ +BEGIN:VEVENT\n\ +DTSTAMP:19980309T231000Z\n\ +UID:guid-1.host1.com\n\ +ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\ +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\ +DESCRIPTION:Project XYZ Review Meeting\n\ +CATEGORIES:MEETING\n\ +CLASS:PUBLIC\n\ +CREATED:19980309T130000Z\n\ +SUMMARY:XYZ Project Review\n\ +DTSTART;TZID=US-Eastern:19980312T083000\n\ +DTEND;TZID=US-Eastern:19980312T093000\n\ +LOCATION:1CP Conference Room 4350\n\ +END:VEVENT\n\ +BEGIN:BOOGA\n\ +DTSTAMP:19980309T231000Z\n\ +X-LIC-FOO:Booga\n\ +DTSTOMP:19980309T231000Z\n\ +UID:guid-1.host1.com\n\ +END:BOOGA\n\ +END:VCALENDAR"; + +char str2[] = "BEGIN:VCALENDAR\n\ +PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ +VERSION:2.0\n\ +BEGIN:VEVENT\n\ +DTSTAMP:19980309T231000Z\n\ +UID:guid-1.host1.com\n\ +ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\ +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\ +DESCRIPTION:Project XYZ Review Meeting\n\ +CATEGORIES:MEETING\n\ +CLASS:PUBLIC\n\ +CREATED:19980309T130000Z\n\ +SUMMARY:XYZ Project Review\n\ +DTSTART;TZID=US-Eastern:19980312T083000\n\ +DTEND;TZID=US-Eastern:19980312T093000\n\ +LOCATION:1CP Conference Room 4350\n\ +END:VEVENT\n\ +END:VCALENDAR\n\ +"; + + +void test_fileset_extended(void) +{ + icalset *cout; + int month = 0; + int count=0; + struct icaltimetype start, end; + icalcomponent *c,*clone, *itr; + icalsetiter iter; + + start = icaltime_from_timet( time(0),0); + end = start; + end.hour++; + + cout = icalfileset_new(OUTPUT_FILE); + ok("Opening output file", (cout != 0)); + assert(cout!=0); + + c = icalparser_parse_string(str2); + ok("Parsing str2", (c!=0)); + assert(c != 0); + + icalset_free(cout); + + /* Add data to the file */ + + for(month = 1; month < 10; month++){ + icalcomponent *event; + icalproperty *dtstart, *dtend; + + cout = icalfileset_new(OUTPUT_FILE); + ok("Opening output file", (cout != 0)); + assert(cout != 0); + + start.month = month; + end.month = month; + + clone = icalcomponent_new_clone(c); + ok("Making clone of output file", (clone!=0)); + assert(clone !=0); + + event = icalcomponent_get_first_component(clone,ICAL_VEVENT_COMPONENT); + ok("Getting first event from clone", (event!=0)); + assert(event != 0); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + ok("find DTSTART", (dtstart !=0)); + assert(dtstart!=0); + + icalproperty_set_dtstart(dtstart,start); + + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + ok("find DTEND", (dtend !=0)); + + assert(dtend!=0); + + icalproperty_set_dtend(dtend,end); + + icalfileset_add_component(cout,clone); + icalfileset_commit(cout); + + icalset_free(cout); + } + + /* Print them out */ + + cout = icalfileset_new(OUTPUT_FILE); + + ok("Opening output file", (cout != 0)); + assert(cout != 0); + + for (iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0); + icalsetiter_deref(&iter) != 0; icalsetiter_next(&iter)) { + icalcomponent *event; + icalproperty *dtstart, *dtend; + + itr = icalsetiter_deref(&iter); + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + if (VERBOSE) + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + + /* Remove all of them */ + + icalset_free(cout); + + cout = icalfileset_new(OUTPUT_FILE); + ok("Opening output file", (cout!=0)); + assert(cout != 0); + + /* need to advance the iterator first before calling remove_componenet() */ + /* otherwise, iter will contain a "removed" component and icalsetiter_next(&iter) */ + /* will fail. */ + + iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0); + itr = icalsetiter_deref(&iter); + while (itr != 0) { + icalsetiter_next(&iter); + icalfileset_remove_component(cout, itr); + icalcomponent_free(itr); + itr = icalsetiter_deref(&iter); + } + + icalset_free(cout); + + /* Print them out again */ + + cout = icalfileset_new(OUTPUT_FILE); + ok("Opening output file", (cout != 0)); + assert(cout != 0); + count =0; + + for (itr = icalfileset_get_first_component(cout); + itr != 0; + itr = icalfileset_get_next_component(cout)){ + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + + icalset_free(cout); + icalcomponent_free(c); +} + + +#ifdef WITH_BDB + +/* + In this example, we're storing a calendar with several components + under the reference id "calendar_7286" and retrieving records based + on title, "month_1" through "month_10". We use a number of the + "optional" arguments to specify secondary indices, sub-databases + (i.e. having multiple databases residing within a single Berkeley + DB file), and keys for storage and retrieval. +*/ + +void test_bdbset() +{ + icalset *cout; + int month = 0; + int count=0; + int num_components=0; + int szdata_len=0; + int ret=0; + char *subdb, *szdata, *szpacked_data; + char uid[255]; + struct icaltimetype start, end; + icalcomponent *c,*clone, *itr; + DBT key, data; + DBC *dbcp; + + struct calendar *cal; + int cal_size; + + return; // for now... TODO fix these broken tests.. + + + + start = icaltime_from_timet( time(0),0); + end = start; + end.hour++; + + /* Note: as per the Berkeley DB ref pages: + * + * The database argument is optional, and allows applications to + * have multiple databases in a single file. Although no database + * argument needs to be specified, it is an error to attempt to + * open a second database in a file that was not initially created + * using a database name. + * + */ + + subdb = "calendar_id"; + + /* open database, using subdb */ + cout = icalbdbset_new("calendar.db", ICALBDB_EVENTS, DB_HASH, 0); + /* + sdbp = icalbdbset_secondary_open(dbp, + DATABASE, + "title", + get_title, + DB_HASH); + */ + + c = icalparser_parse_string(str2); + + assert(c != 0); + + /* Add data to the file */ + + for(month = 1; month < 10; month++){ + icalcomponent *event; + icalproperty *dtstart, *dtend, *location; + + /* retrieve data */ + // cout = icalbdbset_new(dbp, sdbp, NULL); + // assert(cout != 0); + + start.month = month; + end.month = month; + + clone = icalcomponent_new_clone(c); + assert(clone !=0); + event = icalcomponent_get_first_component(clone, + ICAL_VEVENT_COMPONENT); + assert(event != 0); + + dtstart = icalcomponent_get_first_property(event, + ICAL_DTSTART_PROPERTY); + assert(dtstart!=0); + icalproperty_set_dtstart(dtstart,start); + + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + assert(dtend!=0); + icalproperty_set_dtend(dtend,end); + + location = icalcomponent_get_first_property(event, ICAL_LOCATION_PROPERTY); + assert(location!=0); + +#if 0 + /* change the uid to include the month */ + sprintf(uid, "%s_%d", icalcomponent_get_uid(clone), month); + icalcomponent_set_uid(clone, uid); +#endif + + icalbdbset_add_component(cout,clone); + + /* commit changes */ + icalbdbset_commit(cout); + + num_components = icalcomponent_count_components(clone, ICAL_ANY_COMPONENT); + + icalset_free(cout); + + } + + /* try out the cursor operations */ + memset(&key, 0, sizeof(DBT)); + memset(&data, 0, sizeof(DBT)); + +#if 0 + ret = icalbdbset_acquire_cursor(dbp, &dbcp); + ret = icalbdbset_get_first(dbcp, &key, &data); + ret = icalbdbset_get_next(dbcp, &key, &data); + ret = icalbdbset_get_last(dbcp, &key, &data); +#endif + /* Print them out */ + + for(month = 1, count=0; month < 10; month++){ + char *title; + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + icalset_free(cout); + } + + /* open database */ + // cout = icalbdbset_bdb_open("calendar.db", "title", DB_HASH, 0644); + /* sdbp = icalbdbset_secondary_open(dbp, + DATABASE, + "title", + get_title, + DB_HASH); + */ + /* Remove all of them */ + for(month = 1; month < 10; month++){ + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalbdbset_remove_component(cout, itr); + } + + icalbdbset_commit(cout); + icalset_free(cout); + + } + + /* Print them out again */ + + for(month = 1, count=0; month < 10; month++){ + char *title; + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + icalset_free(cout); + } +} +#endif + +int vcalendar_init(struct calendar **rcal, char *vcalendar, char *title) +{ + int vcalendar_size, title_size, total_size; + struct calendar *cal; + + if(vcalendar) + vcalendar_size = strlen(vcalendar); + else { + vcalendar = ""; + vcalendar_size = strlen(vcalendar); + } + + if(title) + title_size = strlen(title); + else { + title = ""; + title_size = strlen(title); + } + + total_size = sizeof(struct calendar) + vcalendar_size + title_size; + + if((cal = (struct calendar *)malloc(total_size))==NULL) + return 0; + memset(cal, 0, total_size); + + /* offsets */ + cal->total_size_offset = sizeof(int); + cal->vcalendar_size_offset = (sizeof(int) * 7); + cal->vcalendar_offset = cal->vcalendar_size_offset + sizeof(int); + cal->title_size_offset = cal->vcalendar_offset + vcalendar_size; + cal->title_offset = cal->title_size_offset + sizeof(int); + + /* sizes */ + cal->total_size = total_size; + cal->vcalendar_size = vcalendar_size; + cal->title_size = title_size; + + if (vcalendar && *vcalendar) + cal->vcalendar = strdup(vcalendar); + + if (title && *title) + cal->title = strdup(title); + + *rcal = cal; + + return 0; +} + +/* get_title -- extracts a secondary key (the vcalendar) + * from a primary key/data pair */ + +/* just create a random title for now */ +#ifdef WITH_BDB + +int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) +{ + icalcomponent *cl; + char title[255]; + + memset(skey, 0, sizeof(DBT)); + + cl = icalparser_parse_string((char *)pdata->data); + sprintf(title, "title_%s", icalcomponent_get_uid(cl)); + + skey->data = strdup(title); + skey->size = strlen(skey->data); + return (0); +} + +char * pack_calendar(struct calendar *cal, int size) +{ + char *str; + + if((str = (char *)malloc(sizeof(char) * size))==NULL) + return 0; + + /* ID */ + memcpy(str, &cal->ID, sizeof(cal->ID)); + + /* total_size */ + memcpy(str + cal->total_size_offset, + &cal->total_size, + sizeof(cal->total_size)); + + /* vcalendar_size */ + memcpy(str + cal->vcalendar_size_offset, + &cal->vcalendar_size, + sizeof(cal->vcalendar_size)); + + /* vcalendar */ + memcpy(str + cal->vcalendar_offset, + cal->vcalendar, + cal->vcalendar_size); + + /* title_size */ + memcpy(str + cal->title_size_offset, + &cal->title_size, + sizeof(cal->title_size)); + + /* title */ + memcpy(str + cal->title_offset, + cal->title, + cal->title_size); + + return str; +} + +struct calendar * unpack_calendar(char *str, int size) +{ + struct calendar *cal; + if((cal = (struct calendar *) malloc(size))==NULL) + return 0; + memset(cal, 0, size); + + /* offsets */ + cal->total_size_offset = sizeof(int); + cal->vcalendar_size_offset = (sizeof(int) * 7); + cal->vcalendar_offset = cal->vcalendar_size_offset + sizeof(int); + + /* ID */ + memcpy(&cal->ID, str, sizeof(cal->ID)); + + /* total_size */ + memcpy(&cal->total_size, + str + cal->total_size_offset, + sizeof(cal->total_size)); + + /* vcalendar_size */ + memcpy(&cal->vcalendar_size, + str + cal->vcalendar_size_offset, + sizeof(cal->vcalendar_size)); + + if((cal->vcalendar = (char *)malloc(sizeof(char) * + cal->vcalendar_size))==NULL) + return 0; + + /* vcalendar */ + memcpy(cal->vcalendar, + (char *)(str + cal->vcalendar_offset), + cal->vcalendar_size); + + cal->title_size_offset = cal->vcalendar_offset + cal->vcalendar_size; + cal->title_offset = cal->title_size_offset + sizeof(int); + + /* title_size */ + memcpy(&cal->title_size, + str + cal->title_size_offset, + sizeof(cal->title_size)); + + if((cal->title = (char *)malloc(sizeof(char) * + cal->title_size))==NULL) + return 0; + + /* title*/ + memcpy(cal->title, + (char *)(str + cal->title_offset), + cal->title_size); + + return cal; +} + +char * parse_vcalendar(const DBT *dbt) +{ + char *str; + struct calendar *cal; + + str = (char *)dbt->data; + cal = unpack_calendar(str, dbt->size); + + return cal->vcalendar; +} +#endif + +void test_dirset_extended(void) +{ + + icalcomponent *c; + icalgauge *gauge; + icalerrorenum error; + icalcomponent *itr; + icalset* cluster; + struct icalperiodtype rtime; + icalset *s = icaldirset_new("store"); + icalset *s2 = icaldirset_new("store-new"); + int i, count = 0; + + ok("Open dirset 'store'", (s!=0)); + assert(s != 0); + + rtime.start = icaltime_from_timet( time(0),0); + + cluster = icalfileset_new(OUTPUT_FILE); + + ok("Open fileset to duplicate 4 times", (cluster != 0)); + assert(cluster != 0); + +#define NUMCOMP 4 + + /* Duplicate every component in the cluster NUMCOMP times */ + + icalerror_clear_errno(); + + for (i = 1; i<NUMCOMP+1; i++){ + + /*rtime.start.month = i%12;*/ + rtime.start.month = i; + rtime.end = rtime.start; + rtime.end.hour++; + + for (itr = icalfileset_get_first_component(cluster); + itr != 0; + itr = icalfileset_get_next_component(cluster)){ + icalcomponent *clone, *inner; + icalproperty *p; + + inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + if (inner == 0){ + continue; + } + + /* Change the dtstart and dtend times in the component + pointed to by Itr*/ + + clone = icalcomponent_new_clone(itr); + inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + ok("Duplicating component...", + (icalerrno == ICAL_NO_ERROR)&&(inner!=0)); + + assert(icalerrno == ICAL_NO_ERROR); + assert(inner !=0); + + /* DTSTART*/ + p = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY); + ok("Fetching DTSTART", (icalerrno == ICAL_NO_ERROR)); + assert(icalerrno == ICAL_NO_ERROR); + + if (p == 0){ + p = icalproperty_new_dtstart(rtime.start); + icalcomponent_add_property(inner,p); + } else { + icalproperty_set_dtstart(p,rtime.start); + } + + ok("Adding DTSTART property", (icalerrno == ICAL_NO_ERROR)); + assert(icalerrno == ICAL_NO_ERROR); + + /* DTEND*/ + p = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY); + ok("Fetching DTEND property", (icalerrno == ICAL_NO_ERROR)); + assert(icalerrno == ICAL_NO_ERROR); + + if (p == 0){ + p = icalproperty_new_dtstart(rtime.end); + icalcomponent_add_property(inner,p); + } else { + icalproperty_set_dtstart(p,rtime.end); + } + ok("Setting DTEND property", (icalerrno == ICAL_NO_ERROR)); + assert(icalerrno == ICAL_NO_ERROR); + + if (VERBOSE) + printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner)); + + error = icaldirset_add_component(s, + icalcomponent_new_clone(itr)); + + ok("Adding component to dirset", (icalerrno == ICAL_NO_ERROR)); + assert(icalerrno == ICAL_NO_ERROR); + } + + } + + gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0); + + ok("Creating complex Gauge", (gauge!=0)); + + icaldirset_select(s,gauge); + + for(c = icaldirset_get_first_component(s); c != 0; + c = icaldirset_get_next_component(s)){ + + printf("Got one! (%d)\n", count++); + + if (c != 0){ + printf("%s", icalcomponent_as_ical_string(c));; + if (icaldirset_add_component(s2,c) == 0){ + printf("Failed to write!\n"); + } + icalcomponent_free(c); + } else { + printf("Failed to get component\n"); + } + } + + icalset_free(s2); + + for(c = icaldirset_get_first_component(s); + c != 0; + c = icaldirset_get_next_component(s)){ + + if (c != 0){ + printf("%s", icalcomponent_as_ical_string(c));; + } else { + printf("Failed to get component\n"); + } + + } + + /* Remove all of the components */ + i=0; + while((c=icaldirset_get_current_component(s)) != 0 ){ + i++; + + icaldirset_remove_component(s,c); + } + + + icalset_free(s); + icalset_free(cluster); +} + diff --git a/libical/src/test/regression-utils.c b/libical/src/test/regression-utils.c new file mode 100644 index 0000000000..edc1eddba3 --- /dev/null +++ b/libical/src/test/regression-utils.c @@ -0,0 +1,169 @@ +#include "ical.h" + +#include <stdlib.h> /* abort() */ +#include <string.h> /* strcmp() */ + +static char ictt_str[1024]; +int VERBOSE = 0; +int QUIET = 0; + +const char* ical_timet_string(const time_t t) +{ + struct tm stm = *(gmtime(&t)); + + sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z",stm.tm_year+1900, + stm.tm_mon+1,stm.tm_mday,stm.tm_hour,stm.tm_min,stm.tm_sec); + + return ictt_str; + +} + +const char* ictt_as_string(struct icaltimetype t) +{ + const char *zone = icaltimezone_get_tzid((icaltimezone *)t.zone); + + if (icaltime_is_utc(t)) + sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z UTC", + t.year,t.month,t.day, t.hour,t.minute,t.second); + else + sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d %s", + t.year,t.month,t.day, t.hour,t.minute,t.second, + zone == NULL? "(floating)": zone); + + return ictt_str; +} + +char* icaltime_as_ctime(struct icaltimetype t) +{ + time_t tt; + + tt = icaltime_as_timet(t); + sprintf(ictt_str,"%s",ctime(&tt)); + + return ictt_str; +} + + +/** This variable is used to control whether we core dump on errors **/ +static int die_on_errors = 0; +static int testnumber = 0; +static int failed = 0; +static int current_set = 0; + +static struct {int set; int test;} failed_tests[1024]; + +void die_on_errors_set(int val) { + die_on_errors = 1; +} + +void _ok(char* test_name, int success, char *file, int linenum, char *test) { + testnumber++; + + if (!QUIET || (QUIET && !success)) + printf("%sok %d - %s\n", (success)?"" : "not ", testnumber, test_name); + if (!success) { + failed_tests[failed].set = current_set; + failed_tests[failed].test = testnumber; + failed++; + + printf("# test failed: \"%s\"\n", test); + printf("# at: %s:%-d\n", file, linenum); + } + + if (die_on_errors == 1 && !success) { + abort(); + } +} + +void _is(char* test_name, const char* str1, const char* str2, char *file, int linenum) { + int diff; + + if (str1 == NULL || str2 == NULL) { + diff = 1; + } else { + diff = strcmp(str1, str2); + } + + if (!test_name) test_name = "()"; + + _ok(test_name, (diff==0), file, linenum, ""); + + if (diff) { + printf("# got: %s\n", str1 ? str1 : "(null)"); + printf("# expected: %s\n", str2 ? str2 : "(null)"); + } +} + +void _int_is(char* test_name, int i1, int i2, char *file, int linenum) { + _ok(test_name, (i1==i2), file, linenum, ""); + + if (i1!=i2) { + printf("# got: %d\n", i1); + printf("# expected: %d\n", i2); + } +} + + +void verbose(int newval) { + VERBOSE = newval; +} + +void test_start(int numtests) { + if (numtests) { + if (!QUIET) + printf("1..%-d\n", numtests); + } else { + if (!QUIET) + printf("1..\n"); + } +} + +void test_header(char *header, int set) { + if (!QUIET) + printf("########## %-40s (%d) ##########\n", header, set); + current_set = set; +} + +void test_end(void) { + int pct; + + if (failed) { + int i, oldset = 0; + + pct = ((testnumber - failed)*100)/testnumber; + printf("\n Failed %d/%d tests, %2d%% okay\n", failed, testnumber, pct); + printf("\n Failed tests:\n "); + for (i = 0; i < failed; i++) { + int this_set = failed_tests[i].set; + char *prefix = ""; + if (this_set != oldset) { + prefix = "\n "; + oldset = this_set; + } + + printf("%s%d/%d ", prefix, this_set, failed_tests[i].test); + } + printf("\n"); + + } else { + printf("\n All Tests Successful.\n"); + } +} + + +void test_run(char *test_name, + void (*test_fcn)(void), + int do_test, int headeronly) +{ + static int test_set = 1; + + if (headeronly || do_test == 0 || do_test == test_set) + test_header(test_name, test_set); + + if (!headeronly && (do_test==0 || do_test == test_set)) { + (*test_fcn)(); + if (!QUIET) + printf("\n"); + } + test_set++; +} diff --git a/libical/src/test/regression.c b/libical/src/test/regression.c index 08696207f2..1e9fc8e2c5 100644 --- a/libical/src/test/regression.c +++ b/libical/src/test/regression.c @@ -29,16 +29,27 @@ #include "ical.h" #include "icalss.h" +#include "icalvcal.h" + +#include "regression.h" #include <assert.h> #include <string.h> /* for strdup */ #include <stdlib.h> /* for malloc */ #include <stdio.h> /* for printf */ #include <time.h> /* for time() */ +#ifndef WIN32 #include <unistd.h> /* for unlink, fork */ #include <sys/wait.h> /* For waitpid */ -#include <sys/types.h> /* For wait pid */ #include <sys/time.h> /* for select */ +#else +#include <Windows.h> +#endif +#include <sys/types.h> /* For wait pid */ + +#ifdef WIN32 +typedef int pid_t; +#endif /* For GNU libc, strcmp appears to be a macro, so using strcmp in @@ -52,11 +63,11 @@ int regrstrcmp(const char* a, const char* b){ /* This example creates and minipulates the ical object that appears * in rfc 2445, page 137 */ -char str[] = "BEGIN:VCALENDAR\ +static char str[] = "BEGIN:VCALENDAR\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\ VERSION:2.0\ BEGIN:VTIMEZONE\ -TZID:US-Eastern\ +TZID:America/New_York\ BEGIN:STANDARD\ DTSTART:19981025T020000\ RDATE:19981025T020000\ @@ -82,8 +93,8 @@ CATEGORIES:MEETING\ CLASS:PUBLIC\ CREATED:19980309T130000Z\ SUMMARY:XYZ Project Review\ -DTSTART;TZID=US-Eastern:19980312T083000\ -DTEND;TZID=US-Eastern:19980312T093000\ +DTSTART;TZID=America/New_York:19980312T083000\ +DTEND;TZID=America/New_York:19980312T093000\ LOCATION:1CP Conference Room 4350\ END:VEVENT\ BEGIN:BOOGA\ @@ -95,336 +106,10 @@ END:BOOGA\ END:VCALENDAR"; -icalcomponent* create_simple_component() -{ - - icalcomponent* calendar; - struct icalperiodtype rtime; - - 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); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - return calendar; - -} - -/* Create a new component */ -icalcomponent* create_new_component() -{ - - icalcomponent* calendar; - icalcomponent* timezone; - icalcomponent* tzc; - icalcomponent* event; - struct icaltimetype atime = icaltime_from_timet( time(0),0); - struct icaldatetimeperiodtype rtime; - icalproperty* property; - - rtime.period.start = icaltime_from_timet( time(0),0); - rtime.period.end = icaltime_from_timet( time(0),0); - rtime.period.end.hour++; - rtime.time = icaltime_null_time(); - - - - /* Create calendar and add properties */ - calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - icalcomponent_add_property( - calendar, - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN") - ); - - /* Create a timezone object and add it to the calendar */ - - timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT); - - icalcomponent_add_property( - timezone, - icalproperty_new_tzid("US_Eastern") - ); - - /* Add a sub-component of the timezone */ - tzc = icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - icalcomponent_add_component(calendar,timezone); - - /* Add a second subcomponent */ - tzc = icalcomponent_new(ICAL_XSTANDARD_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - /* Add an event */ - - event = icalcomponent_new(ICAL_VEVENT_COMPONENT); - - icalcomponent_add_property( - event, - icalproperty_new_dtstamp(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_uid("guid-1.host1.com") - ); - - /* add a property that has parameters */ - property = icalproperty_new_organizer("mrbig@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_CHAIR) - ); - - icalcomponent_add_property(event,property); - - /* add another property that has parameters */ - property = icalproperty_new_attendee("employee-A@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_rsvp(ICAL_RSVP_TRUE) - ); - - 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("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); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - icalcomponent_free(calendar); - - return 0; -} - - -/* Create a new component, using the va_args list */ - -icalcomponent* create_new_component_with_va_args() -{ - - icalcomponent* calendar; - struct icaltimetype atime = icaltime_from_timet( time(0),0); - struct icaldatetimeperiodtype rtime; - - rtime.period.start = icaltime_from_timet( time(0),0); - rtime.period.end = icaltime_from_timet( time(0),0); - rtime.period.end.hour++; - rtime.time = icaltime_null_time(); - - calendar = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), - icalcomponent_vanew( - ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), - icalcomponent_vanew( - ICAL_XDAYLIGHT_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-4.0), - icalproperty_new_tzoffsetto(-5.0), - icalproperty_new_tzname("EST"), - 0 - ), - icalcomponent_vanew( - ICAL_XSTANDARD_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-5.0), - icalproperty_new_tzoffsetto(-4.0), - icalproperty_new_tzname("EST"), - 0 - ), - 0 - ), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_dtstamp(atime), - icalproperty_new_uid("guid-1.host1.com"), - icalproperty_vanew_organizer( - "mrbig@host.com", - icalparameter_new_role(ICAL_ROLE_CHAIR), - 0 - ), - icalproperty_vanew_attendee( - "employee-A@host.com", - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), - icalparameter_new_rsvp(ICAL_RSVP_TRUE), - icalparameter_new_cutype(ICAL_CUTYPE_GROUP), - 0 - ), - icalproperty_new_description("Project XYZ Review Meeting"), - icalproperty_new_categories("MEETING"), - icalproperty_new_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 - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - - icalcomponent_free(calendar); - - return 0; -} - /* Return a list of all attendees who are required. */ -char** get_required_attendees(icalproperty* event) +static char** get_required_attendees(icalcomponent* event) { icalproperty* p; icalparameter* parameter; @@ -435,8 +120,8 @@ char** get_required_attendees(icalproperty* event) attendees = malloc(max * (sizeof (char *))); - assert(event != 0); - assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); + ok("event is non null", (event != 0)); + int_is("event is a VEVENT", icalcomponent_isa(event), ICAL_VEVENT_COMPONENT); for( p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); @@ -464,7 +149,7 @@ char** get_required_attendees(icalproperty* event) /* If an attendee has a PARTSTAT of NEEDSACTION or has no PARTSTAT parameter, change it to TENTATIVE. */ -void update_attendees(icalproperty* event) +static void update_attendees(icalcomponent* event) { icalproperty* p; icalparameter* parameter; @@ -490,7 +175,7 @@ void update_attendees(icalproperty* event) } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) { - icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER); + icalproperty_remove_parameter_by_ref(p,parameter); icalparameter_free(parameter); @@ -510,75 +195,99 @@ void test_values() icalvalue *copy; v = icalvalue_new_caladdress("cap://value/1"); - printf("caladdress 1: %s\n",icalvalue_get_caladdress(v)); + + is("icalvalue_new_caladdress()", + icalvalue_get_caladdress(v), "cap://value/1"); + icalvalue_set_caladdress(v,"cap://value/2"); - printf("caladdress 2: %s\n",icalvalue_get_caladdress(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); - + + is("icalvalue_set_caladdress()", + icalvalue_get_caladdress(v), "cap://value/2"); + + is("icalvalue_as_ical_string()", + icalvalue_as_ical_string(v), "cap://value/2"); + copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + + is("icalvalue_new_clone()", + icalvalue_as_ical_string(copy), "cap://value/2"); icalvalue_free(v); icalvalue_free(copy); v = icalvalue_new_boolean(1); - printf("caladdress 1: %d\n",icalvalue_get_boolean(v)); + int_is("icalvalue_new_boolean(1)", icalvalue_get_boolean(v), 1); icalvalue_set_boolean(v,2); - printf("caladdress 2: %d\n",icalvalue_get_boolean(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); + ok("icalvalue_set_boolean(2)", (2 == icalvalue_get_boolean(v))); + is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "2"); copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "2"); + icalvalue_free(v); icalvalue_free(copy); - v = icalvalue_new_date(icaltime_from_timet( time(0),0)); - printf("date 1: %s\n",icalvalue_as_ical_string(v)); - icalvalue_set_date(v,icaltime_from_timet( time(0)+3600,0)); - printf("date 2: %s\n",icalvalue_as_ical_string(v)); + v = icalvalue_new_x("test"); + is("icalvalue_new_x(test)", icalvalue_get_x(v), "test"); + icalvalue_set_x(v, "test2"); + is("icalvalue_set_x(test2)", icalvalue_get_x(v), "test2"); + is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "test2"); copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "test2"); + + icalvalue_free(v); + icalvalue_free(copy); + + + v = icalvalue_new_date(icaltime_from_timet( 1023404802,0)); + is("icalvalue_new_date()", icalvalue_as_ical_string(v), "20020606T230642"); + icalvalue_set_date(v,icaltime_from_timet( 1023404802-3600,0)); + is("icalvalue_set_date()",icalvalue_as_ical_string(v), "20020606T220642"); + + copy = icalvalue_new_clone(v); + is("icalvalue_new_clone()",icalvalue_as_ical_string(v), "20020606T220642"); + icalvalue_free(v); icalvalue_free(copy); v = icalvalue_new(-1); - printf("Invalid type: %p\n",v); + ok("icalvalue_new(-1), Invalid type", (v == NULL)); if (v!=0) icalvalue_free(v); - assert(ICAL_BOOLEAN_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_BOOLEAN)); - assert(ICAL_UTCOFFSET_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_UTCOFFSET)); - assert(ICAL_RECUR_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_RECUR)); - assert(ICAL_CALADDRESS_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_CALADDRESS)); - assert(ICAL_PERIOD_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_PERIOD)); - assert(ICAL_BINARY_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_BINARY)); - assert(ICAL_TEXT_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_TEXT)); - assert(ICAL_DURATION_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DURATION)); - assert(ICAL_INTEGER_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_INTEGER)); - assert(ICAL_TIME_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_TIME)); - assert(ICAL_URI_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_URI)); - assert(ICAL_FLOAT_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_FLOAT)); - assert(ICAL_X_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_X)); - assert(ICAL_DATETIME_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DATETIME)); - assert(ICAL_DATE_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DATE)); + ok("ICAL_BOOLEAN_VALUE",(ICAL_BOOLEAN_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_BOOLEAN))); + ok("ICAL_UTCOFFSET_VALUE",(ICAL_UTCOFFSET_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_UTCOFFSET))); + ok("ICAL_RECUR_VALUE", (ICAL_RECUR_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_RECUR))); + ok("ICAL_CALADDRESS_VALUE",(ICAL_CALADDRESS_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_CALADDRESS))); + ok("ICAL_PERIOD_VALUE", (ICAL_PERIOD_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_PERIOD))); + ok("ICAL_BINARY_VALUE",(ICAL_BINARY_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_BINARY))); + ok("ICAL_TEXT_VALUE",(ICAL_TEXT_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_TEXT))); + ok("ICAL_DURATION_VALUE",(ICAL_DURATION_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DURATION))); + ok("ICAL_INTEGER_VALUE", + (ICAL_INTEGER_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_INTEGER))); + + ok("ICAL_URI_VALUE", + (ICAL_URI_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_URI))); + ok("ICAL_FLOAT_VALUE",(ICAL_FLOAT_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_FLOAT))); + ok("ICAL_X_VALUE",(ICAL_X_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_X))); + ok("ICAL_DATETIME_VALUE",(ICAL_DATETIME_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DATETIME))); + ok("ICAL_DATE_TIME",(ICAL_DATE_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DATE))); /* v = icalvalue_new_caladdress(0); @@ -586,14 +295,29 @@ void test_values() if (v!=0) icalvalue_free(v); */ + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL); + v = icalvalue_new_from_string(ICAL_RECUR_VALUE,"D2 #0"); + ok("illegal recur value", (v == 0)); + + v = icalvalue_new_from_string(ICAL_TRIGGER_VALUE,"Gonk"); + ok("illegal trigger value", (v == 0)); + + v = icalvalue_new_from_string(ICAL_REQUESTSTATUS_VALUE,"Gonk"); + ok("illegal requeststatus value", (v == 0)); + + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_DEFAULT); } + void test_properties() { icalproperty *prop; icalparameter *param; icalproperty *clone; + char test_cn_str[128] = ""; + char *test_cn_str_good = "A Common Name 1A Common Name 2A Common Name 3A Common Name 4"; + char *test_ical_str_good = "COMMENT;CN=A Common Name 1;CN=A Common Name 2;CN=A Common Name 3;CN=A \n Common Name 4:Another Comment\n"; prop = icalproperty_vanew_comment( "Another Comment", @@ -606,38 +330,56 @@ void test_properties() 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)); + const char *str = icalparameter_get_cn(param); + if (VERBOSE) printf("Prop parameter: %s\n",icalparameter_get_cn(param)); + strcat(test_cn_str, str); } + is("fetching parameters", test_cn_str, test_cn_str_good); - printf("Prop value: %s\n",icalproperty_get_comment(prop)); - + if (VERBOSE) printf("Prop value: %s\n",icalproperty_get_comment(prop)); + is("icalproperty_get_comment()", + icalproperty_get_comment(prop), "Another Comment"); - printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); + if (VERBOSE) printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); + + is("icalproperty_as_ical_string()", + icalproperty_as_ical_string(prop), test_ical_str_good); clone = icalproperty_new_clone(prop); - printf("Clone:\n %s\n",icalproperty_as_ical_string(prop)); + if (VERBOSE) printf("Clone:\n %s\n",icalproperty_as_ical_string(prop)); + is("icalproperty_new_clone()", + icalproperty_as_ical_string(prop), test_ical_str_good); icalproperty_free(clone); icalproperty_free(prop); prop = icalproperty_new(-1); - printf("Invalid type: %p\n",prop); + ok("test icalproperty_new() with invalid type (-1)", + (prop == NULL)); if (prop!=0) icalproperty_free(prop); +} - /* - prop = icalproperty_new_method(0); +void test_utf8() +{ + icalproperty *prop; + char *utf8text = "aáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaá"; + char *test_ical_str_good = "DESCRIPTION:\n" +" aáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaá\n" +" óaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóa\n" +" áóaáóaáóaáóaáóaáóaáóaáóaáóaá\n"; - printf("Bad string: %p\n",prop); - + prop = icalproperty_new_description(utf8text); - if (prop!=0) icalproperty_free(prop); - */ + is("icalproperty_as_ical_string()", + icalproperty_as_ical_string(prop), test_ical_str_good); + icalproperty_free(prop); } + + void test_parameters() { icalparameter *p; @@ -648,47 +390,55 @@ void test_parameters() p = icalparameter_new_cn(str1); - printf("Common Name: %s\n",icalparameter_get_cn(p)); - - assert(regrstrcmp(str1,icalparameter_get_cn(p)) == 0); - - printf("As String: %s\n",icalparameter_as_ical_string(p)); - - assert(regrstrcmp(icalparameter_as_ical_string(p),"CN=A Common Name")==0); - + is("icalparameter_new_cn()", icalparameter_get_cn(p), str1); + is("icalparameter_as_ical_string()" ,icalparameter_as_ical_string(p),"CN=A Common Name"); + icalparameter_free(p); - p = icalparameter_new_from_string("PARTSTAT=ACCEPTED"); - assert(icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_PARTSTAT_ACCEPTED); + ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER)); + ok("PARTSTAT_ACCEPTED", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_ACCEPTED)); + + icalparameter_free(p); p = icalparameter_new_from_string("ROLE=CHAIR"); - assert(icalparameter_isa(p) == ICAL_ROLE_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_ROLE_CHAIR); + + ok("ROLE_PARAMETER", (icalparameter_isa(p) == ICAL_ROLE_PARAMETER)); + ok("ROLE_CHAIR", (icalparameter_get_partstat(p) == ICAL_ROLE_CHAIR)); + + icalparameter_free(p); p = icalparameter_new_from_string("PARTSTAT=X-FOO"); - assert(icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_PARTSTAT_X); + ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER)); + ok("PARTSTAT_X", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_X)); + + icalparameter_free(p); p = icalparameter_new_from_string("X-PARAM=X-FOO"); - assert(icalparameter_isa(p) == ICAL_X_PARAMETER); + ok("X_PARAMETER", (icalparameter_isa(p) == ICAL_X_PARAMETER)); + + icalparameter_free(p); for (i=0;enums[i] != -1; i++){ - - printf("%s\n",icalparameter_enum_to_string(enums[i])); - assert(icalparameter_string_to_enum( - icalparameter_enum_to_string(enums[i]))==enums[i]); + if (VERBOSE) printf("%s\n",icalparameter_enum_to_string(enums[i])); + ok("test paramter enums", + (icalparameter_string_to_enum(icalparameter_enum_to_string(enums[i]))==enums[i])); } - - } +char *good_child = +"BEGIN:VEVENT\n" +"VERSION:2.0\n" +"DESCRIPTION:This is an event\n" +"COMMENT;CN=A Common Name 1;CN=A Common Name 2;CN=A Common Name 3;CN=A \n" +" Common Name 4:Another Comment\n" +"X-LIC-ERROR;X-LIC-ERRORTYPE=COMPONENT-PARSE-ERROR:This is only a test\n" +"END:VEVENT\n"; + void test_components() { - icalcomponent* c; icalcomponent* child; @@ -721,16 +471,24 @@ void test_components() 0 ); - printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c)); + if (VERBOSE) + printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c)); child = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - - printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child)); - icalcomponent_free(c); + ok("test icalcomponent_get_first_component()", + (child != NULL)); + + if (VERBOSE) + printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child)); + is("test results of child component", + icalcomponent_as_ical_string(child), good_child); + + icalcomponent_free(c); } + void test_memory() { size_t bufsize = 256; @@ -792,19 +550,23 @@ void test_memory() icalmemory_append_string(&f, &p, &bufsize, b8); - printf("1: %p %s \n",b1,b1); - printf("2: %p %s\n",b2,b2); - printf("3: %p %s\n",b3,b3); - printf("4: %p %s\n",b4,b4); - printf("5: %p %s\n",b5,b5); - printf("6: %p %s\n",b6,b6); - printf("7: %p %s\n",b7,b7); - printf("8: %p %s\n",b8,b8); - - - printf("Final: %s\n", f); + if (VERBOSE) { + printf("1: %p %s \n",b1,b1); + printf("2: %p %s\n",b2,b2); + printf("3: %p %s\n",b3,b3); + printf("4: %p %s\n",b4,b4); + printf("5: %p %s\n",b5,b5); + printf("6: %p %s\n",b6,b6); + printf("7: %p %s\n",b7,b7); + printf("8: %p %s\n",b8,b8); + + + printf("Final: %s\n", f); + + printf("Final buffer size: %d\n",bufsize); + } - printf("Final buffer size: %d\n",bufsize); + ok("final buffer size == 806", (bufsize == 806)); free(f); @@ -816,46 +578,49 @@ void test_memory() p = f; icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); + icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); - + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); + + free(f); + for(i=0; i<100; i++){ f = icalmemory_tmp_buffer(bufsize); @@ -867,16 +632,26 @@ void test_memory() } -int test_store() +void test_dirset() { - - icalcomponent *c, *gauge; + icalcomponent *c; + icalgauge *gauge; icalerrorenum error; icalcomponent *next, *itr; - icalfileset* cluster; + icalset* cluster; + icalset *s, *s2; struct icalperiodtype rtime; - icaldirset *s = icaldirset_new("store"); int i; + int count = 0; + + mkdir("store", 0755); + mkdir("store-new", 0755); + + s = icaldirset_new("store"); + s2 = icaldirset_new("store-new"); + + ok("opening 'store' dirset", s!=NULL); + ok("opening 'store-new' dirset", s2!=NULL); rtime.start = icaltime_from_timet( time(0),0); @@ -884,7 +659,6 @@ int test_store() if (cluster == 0){ printf("Failed to create cluster: %s\n",icalerror_strerror(icalerrno)); - return 0; } #define NUMCOMP 4 @@ -911,7 +685,6 @@ int test_store() continue; } - assert(itr != 0); /* Change the dtstart and dtend times in the component pointed to by Itr*/ @@ -949,42 +722,19 @@ int test_store() error = icaldirset_add_component(s,clone); assert(icalerrno == ICAL_NO_ERROR); - } - } - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Submit Income Taxes", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Bastille Day Party", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); - -#if 0 - + gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0); icaldirset_select(s,gauge); - for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ - + for(c = icaldirset_get_first_component(s); c != 0; c = icaldirset_get_next_component(s)){ printf("Got one! (%d)\n", count++); if (c != 0){ printf("%s", icalcomponent_as_ical_string(c));; - if (icaldirset_store(s2,c) == 0){ + if (icaldirset_add_component(s2,c) == 0){ printf("Failed to write!\n"); } icalcomponent_free(c); @@ -994,9 +744,7 @@ int test_store() } - icaldirset_free(s2); -#endif - + icalset_free(s2); for(c = icaldirset_get_first_component(s); c != 0; @@ -1010,51 +758,70 @@ int test_store() } else { printf("Failed to get component\n"); } - - } - icaldirset_free(s); - return 0; + icalset_free(s); + icalset_free(cluster); } -int test_compare() + +void test_compare() { icalvalue *v1, *v2; v1 = icalvalue_new_caladdress("cap://value/1"); v2 = icalvalue_new_clone(v1); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("compare value and clone", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_caladdress("A"); v2 = icalvalue_new_caladdress("B"); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of A and B results in LESS", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS)); + + ok("test compare of B and A results in GREATER", + (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_caladdress("B"); v2 = icalvalue_new_caladdress("A"); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of caladdress A and B results in GREATER", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_GREATER)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_integer(5); v2 = icalvalue_new_integer(5); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of 5 and 5 results in EQUAL", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_integer(5); v2 = icalvalue_new_integer(10); - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_integer(10); - v2 = icalvalue_new_integer(5); - - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of 5 and 10 results in LESS", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS)); + + ok("test compare of 10 and 5 results in GREATER", + (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER)); - return 0; + icalvalue_free(v1); + icalvalue_free(v2); } + void test_restriction() { icalcomponent *comp; @@ -1063,6 +830,8 @@ void test_restriction() struct icaldatetimeperiodtype rtime; + char *str; + rtime.period.start = icaltime_from_timet( time(0),0); rtime.period.end = icaltime_from_timet( time(0),0); rtime.period.end.hour++; @@ -1076,7 +845,7 @@ void test_restriction() icalproperty_new_method(ICAL_METHOD_REQUEST), icalcomponent_vanew( ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), + icalproperty_new_tzid("America/New_York"), icalcomponent_vanew( ICAL_XDAYLIGHT_COMPONENT, icalproperty_new_dtstart(atime), @@ -1115,17 +884,17 @@ void test_restriction() ), icalproperty_new_description("Project XYZ Review Meeting"), icalproperty_new_categories("MEETING"), - icalproperty_new_class("PUBLIC"), + icalproperty_new_class(ICAL_CLASS_PUBLIC), icalproperty_new_created(atime), icalproperty_new_summary("XYZ Project Review"), /* icalproperty_new_dtstart( atime, - icalparameter_new_tzid("US-Eastern"), + icalparameter_new_tzid("America/New_York"), 0 ),*/ icalproperty_vanew_dtend( atime, - icalparameter_new_tzid("US-Eastern"), + icalparameter_new_tzid("America/New_York"), 0 ), icalproperty_new_location("1CP Conference Room 4350"), @@ -1135,22 +904,31 @@ void test_restriction() ); valid = icalrestriction_check(comp); + + ok("icalrestriction_check() == 0", (valid==0)); + + str = icalcomponent_as_ical_string(comp); - printf("#### %d ####\n%s\n",valid, icalcomponent_as_ical_string(comp)); + icalcomponent_free(comp); } -#if 0 void test_calendar() { icalcomponent *comp; - icalfileset *c; - icaldirset *s; - icalcalendar* calendar = icalcalendar_new("calendar"); + icalset *c; + icalset *s; + icalcalendar* calendar; icalerrorenum error; struct icaltimetype atime = icaltime_from_timet( time(0),0); - comp = icalcomponent_vanew( + mkdir("calendar", 0755); + mkdir("calendar/booked", 0755); + + calendar = icalcalendar_new("calendar"); + + comp = icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_new_version("2.0"), icalproperty_new_description("This is an event"), @@ -1167,25 +945,25 @@ void test_calendar() icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), 0), - 0); - - + 0),0); + s = icalcalendar_get_booked(calendar); error = icaldirset_add_component(s,comp); - assert(error == ICAL_NO_ERROR); + ok("Adding Component to dirset", (error == ICAL_NO_ERROR)); c = icalcalendar_get_properties(calendar); error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); - assert(error == ICAL_NO_ERROR); + ok("Adding Clone Component to dirset", (error == ICAL_NO_ERROR)); icalcalendar_free(calendar); + ok("icalcalendar test", (1)); } -#endif + void test_increment(void); @@ -1223,9 +1001,9 @@ void test_recur() rt = icalrecurrencetype_from_string("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA"); start = icaltime_from_string("19970905T090000Z"); - print_occur(rt,start); + if (VERBOSE) print_occur(rt,start); - printf("\n Using icalrecur_expand_recurrence\n"); + if (VERBOSE) printf("\n Using icalrecur_expand_recurrence\n"); icalrecur_expand_recurrence("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA", icaltime_as_timet(start), @@ -1233,8 +1011,7 @@ void test_recur() array); for(i =0; array[i] != 0 && i < 25 ; i++){ - - printf(" %s",ctime(&(array[i]))); + if (VERBOSE) printf(" %s",ctime(&(array[i]))); } @@ -1242,20 +1019,22 @@ void test_recur() } + void test_expand_recurrence(){ time_t arr[10]; time_t now = 931057385; - int i; + int i, numfound = 0; icalrecur_expand_recurrence( "FREQ=MONTHLY;BYDAY=MO,WE", now, 5, arr ); - printf("Start %s",ctime(&now) ); - for (i=0; i<5; i++) - { - printf("i=%d %s\n", i, ctime(&arr[i]) ); - } - + if (VERBOSE) printf("Start %s",ctime(&now) ); + + for (i=0; i<5; i++) { + numfound++; + if (VERBOSE) printf("i=%d %s\n", i, ctime(&arr[i]) ); + } + int_is("Get an array of 5 items", numfound, 5); } @@ -1273,23 +1052,6 @@ enum byrule { BY_SET_POS }; -struct icalrecur_iterator_impl { - - struct icaltimetype dtstart; - struct icaltimetype last; /* last time return from _iterator_next*/ - int occurrence_no; /* number of step made on this iterator */ - struct icalrecurrencetype rule; - - short days[366]; - short days_index; - - enum byrule byrule; - short by_indices[9]; - - - short *by_ptrs[9]; /* Pointers into the by_* array elements of the rule */ -}; - void icalrecurrencetype_test() { icalvalue *v = icalvalue_new_from_string( @@ -1312,6 +1074,10 @@ void icalrecurrencetype_test() printf("%s",ctime(&tt )); } while( ! icaltime_is_null_time(next)); + + icalvalue_free(v); + + icalrecur_iterator_free(itr); } @@ -1327,26 +1093,27 @@ void test_recur_parameter_bug(){ #include <ical.h> static const char test_icalcomp_str[] = -"BEGIN:VEVENT\r\n" -"RRULE\r\n" -" ;X-EVOLUTION-ENDDATE=20030209T081500\r\n" -" :FREQ=DAILY;COUNT=10;INTERVAL=6\r\n" -"END:VEVENT\r\n"; +"BEGIN:VEVENT\n" +"RRULE;X-EVOLUTION-ENDDATE=20030209T081500:FREQ=DAILY;COUNT=10;INTERVAL=6\n" +"END:VEVENT\n"; icalcomponent *icalcomp; icalproperty *prop; struct icalrecurrencetype recur; int n_errors; - + char *str; + icalcomp = icalparser_parse_string ((char *) test_icalcomp_str); - if (!icalcomp) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + ok("icalparser_parse_string()",(icalcomp!=NULL)); + assert(icalcomp!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); + str = icalcomponent_as_ical_string(icalcomp); + is("parsed matches original", str, (char*)test_icalcomp_str); + if (VERBOSE) printf("%s\n\n",str); n_errors = icalcomponent_count_errors (icalcomp); + int_is("no parse errors", n_errors, 0); + if (n_errors) { icalproperty *p; @@ -1355,7 +1122,7 @@ void test_recur_parameter_bug(){ p; p = icalcomponent_get_next_property (icalcomp, ICAL_XLICERROR_PROPERTY)) { - char *str; + const char *str; str = icalproperty_as_ical_string (p); fprintf (stderr, "error: %s\n", str); @@ -1363,350 +1130,564 @@ void test_recur_parameter_bug(){ } prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY); - if (!prop) { - fprintf (stderr, "main(): could not get the RRULE property"); - exit (EXIT_FAILURE); - } + ok("get RRULE property", (prop!=NULL)); + assert(prop!=NULL); recur = icalproperty_get_rrule (prop); - printf("%s\n",icalrecurrencetype_as_string(&recur)); + if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur)); + icalcomponent_free(icalcomp); } void test_duration() { - - struct icaldurationtype d; d = icaldurationtype_from_string("PT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 30600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("PT8H30M", icaldurationtype_as_int(d), 30600); d = icaldurationtype_from_string("-PT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == -30600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("-PT8H30M", icaldurationtype_as_int(d), -30600); d = icaldurationtype_from_string("PT10H10M10S"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 36610); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("PT10H10M10S", icaldurationtype_as_int(d), 36610); d = icaldurationtype_from_string("P7W"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 4233600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P7W", icaldurationtype_as_int(d), 4233600); d = icaldurationtype_from_string("P2DT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 203400); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P2DT8H30M", icaldurationtype_as_int(d), 203400); icalerror_errors_are_fatal = 0; + /* Test conversion of bad input */ + + d = icaldurationtype_from_int(1314000); + if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d), + icaldurationtype_as_int(d)); + is("1314000", icaldurationtype_as_ical_string(d), "P15DT5H"); + + d = icaldurationtype_from_string("P2W1DT5H"); + if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d), + icaldurationtype_as_int(d)); + int_is("P15DT5H", icaldurationtype_as_int(d), 0); + d = icaldurationtype_from_string("P-2DT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P-2DT8H30M", icaldurationtype_as_int(d), 0); d = icaldurationtype_from_string("P7W8H"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P7W8H", icaldurationtype_as_int(d), 0); d = icaldurationtype_from_string("T10H"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); - + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("T10H", icaldurationtype_as_int(d), 0); icalerror_errors_are_fatal = 1; + d = icaldurationtype_from_int(4233600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + is("P7W", + icaldurationtype_as_ical_string(d), "P7W"); + + d = icaldurationtype_from_int(4424400); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + is("P51DT5H", + icaldurationtype_as_ical_string(d), "P51DT5H"); } + void test_period() { - struct icalperiodtype p; icalvalue *v; + char *str; + + str = "19971015T050000Z/PT8H30M"; + p = icalperiodtype_from_string(str); + is(str, icalperiodtype_as_ical_string(p),str); - p = icalperiodtype_from_string("19971015T050000Z/PT8H30M"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19971015T050000Z/PT8H30M") == 0); - p = icalperiodtype_from_string("19971015T050000Z/19971015T060000Z"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19971015T050000Z/19971015T060000Z") == 0); + str = "19971015T050000Z/19971015T060000Z"; + p = icalperiodtype_from_string(str); + is(str, icalperiodtype_as_ical_string(p),str); - p = icalperiodtype_from_string("19970101T120000/PT3H"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19970101T120000/PT3H") == 0); - v = icalvalue_new_from_string(ICAL_PERIOD_VALUE,"19970101T120000/PT3H"); - printf("%s\n",icalvalue_as_ical_string(v)); - assert(strcmp(icalvalue_as_ical_string(v), - "19970101T120000/PT3H") == 0); + str = "19970101T120000/PT3H"; + v = icalvalue_new_from_string(ICAL_PERIOD_VALUE,str); + is(str, icalvalue_as_ical_string(v), str); + icalvalue_free(v); } -void test_strings(){ +void test_strings(){ icalvalue *v; v = icalvalue_new_text("foo;bar;bats"); - - printf("%s\n",icalvalue_as_ical_string(v)); + if (VERBOSE) + printf("%s\n",icalvalue_as_ical_string(v)); + + is("test encoding of 'foo;bar;bats'", + "foo\\;bar\\;bats", icalvalue_as_ical_string(v)); icalvalue_free(v); + v = icalvalue_new_text("foo\\;b\nar\\;ba\tts"); + if (VERBOSE) + printf("%s\n",icalvalue_as_ical_string(v)); - printf("%s\n",icalvalue_as_ical_string(v)); + is("test encoding of 'foo\\\\;b\\nar\\\\;ba\\tts'", + "foo\\\\\\;b\\nar\\\\\\;ba\\tts", icalvalue_as_ical_string(v)); icalvalue_free(v); - - } + void test_requeststat() { - icalrequeststatus s; - struct icalreqstattype st, st2; - char temp[1024]; - - s = icalenum_num_to_reqstat(2,1); - - assert(s == ICAL_2_1_FALLBACK_STATUS); - - assert(icalenum_reqstat_major(s) == 2); - assert(icalenum_reqstat_minor(s) == 1); - - printf("2.1: %s\n",icalenum_reqstat_desc(s)); - - st.code = s; - st.debug = "booga"; - st.desc = 0; - - printf("%s\n",icalreqstattype_as_string(st)); + icalproperty *p; + icalrequeststatus s; + struct icalreqstattype st, st2; + char temp[1024]; + + s = icalenum_num_to_reqstat(2,1); + + ok("icalenum_num_to_reqstat(2,1)",(s == ICAL_2_1_FALLBACK_STATUS)); + + ok("icalenum_reqstat_major()",(icalenum_reqstat_major(s) == 2)); + ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(s) == 1)); + + is ("icalenum_reqstat_desc() -> 2.1", icalenum_reqstat_desc(s), + "Success but fallback taken on one or more property values."); + + st.code = s; + st.debug = "booga"; + st.desc = 0; + + is("icalreqstattype_as_string()", + icalreqstattype_as_string(st), + "2.1;Success but fallback taken on one or more property values.;booga"); + + st.desc = " A non-standard description"; + + is("icalreqstattype_as_string() w/ non standard description", + icalreqstattype_as_string(st), + "2.1; A non-standard description;booga"); + + st.desc = 0; + + sprintf(temp,"%s\n",icalreqstattype_as_string(st)); + + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); + + /* printf("%d -- %d -- %s -- %s\n",*/ + ok("icalenum_reqstat_major()",(icalenum_reqstat_major(st2.code) == 2)); + ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(st2.code) == 1)); + is("icalenum_reqstat_desc", + icalenum_reqstat_desc(st2.code), + "Success but fallback taken on one or more property values."); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values."); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); - st.desc = " A non-standard description"; + is("st2 test again", + icalreqstattype_as_string(st2), + "2.1;Success but fallback taken on one or more property values."); + + st2 = icalreqstattype_from_string("2.1"); + is("st2 test #3", + icalreqstattype_as_string(st2), + "2.1;Success but fallback taken on one or more property values."); + + p = icalproperty_new_from_string("REQUEST-STATUS:2.1;Success but fallback taken on one or more property values.;booga"); - printf("%s\n",icalreqstattype_as_string(st)); + is("icalproperty_new_from_string()", + icalproperty_as_ical_string(p), + "REQUEST-STATUS:2.1;Success but fallback taken on one or more property \n values.;booga\n"); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); + st2 = icalreqstattype_from_string("16.4"); + + ok("test unknown code", (st2.code == ICAL_UNKNOWN_STATUS)); + + st2 = icalreqstattype_from_string("1."); + + ok("test malformed code", (st2.code == ICAL_UNKNOWN_STATUS)); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT); - st.desc = 0; + icalproperty_free(p); +} - sprintf(temp,"%s\n",icalreqstattype_as_string(st)); - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); +void test_dtstart(){ + + struct icaltimetype tt,tt2; + + icalproperty *p; + - printf("%d -- %d -- %s -- %s\n",icalenum_reqstat_major(st2.code), - icalenum_reqstat_minor(st2.code), - icalenum_reqstat_desc(st2.code), - st2.debug); + tt = icaltime_from_string("19970101"); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); - printf("%s\n",icalreqstattype_as_string(st2)); + int_is("19970101 is a date", tt.is_date, 1); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;"); - printf("%s\n",icalreqstattype_as_string(st2)); + p = icalproperty_new_dtstart(tt); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values."); - printf("%s\n",icalreqstattype_as_string(st2)); + if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p)))); - st2 = icalreqstattype_from_string("2.1;"); - printf("%s\n",icalreqstattype_as_string(st2)); + ok("ICAL_DATE_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATE_VALUE)); - st2 = icalreqstattype_from_string("2.1"); - printf("%s\n",icalreqstattype_as_string(st2)); + tt2 = icalproperty_get_dtstart(p); + int_is("converted date is date", tt2.is_date, 1); -#ifndef ICAL_ERRORS_ARE_FATAL - st2 = icalreqstattype_from_string("16.4"); - assert(st2.code == ICAL_UNKNOWN_STATUS); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - st2 = icalreqstattype_from_string("1."); - assert(st2.code == ICAL_UNKNOWN_STATUS); -#endif -} + tt = icaltime_from_string("19970101T103000"); -char ictt_str[1024]; -char* ictt_as_string(struct icaltimetype t) -{ + int_is("19970101T103000 is not a date", tt.is_date, 0); - sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d%s",t.year,t.month,t.day, - t.hour,t.minute,t.second,t.is_utc?" Z":""); + icalproperty_free(p); - return ictt_str; -} + p = icalproperty_new_dtstart(tt); + if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p)))); + ok("ICAL_DATETIME_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATETIME_VALUE)); -char* ical_timet_string(time_t t) -{ - struct tm stm = *(gmtime(&t)); + tt2 = icalproperty_get_dtstart(p); + int_is("converted datetime is not date", tt2.is_date, 0); - sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z",stm.tm_year+1900, - stm.tm_mon+1,stm.tm_mday,stm.tm_hour,stm.tm_min,stm.tm_sec); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - return ictt_str; - + icalproperty_free(p); } void do_test_time(char* zone) { - struct icaltimetype ictt, icttutc, icttutczone, icttdayl, + struct icaltimetype ictt, icttutc, icttzone, icttdayl, icttla, icttny,icttphoenix, icttlocal, icttnorm; time_t tt,tt2, tt_p200; - int offset_la, offset_tz; + int offset_tz; icalvalue *v; short day_of_week,start_day_of_week, day_of_year; + icaltimezone *azone, *utczone; + char msg[256]; icalerror_errors_are_fatal = 0; + azone = icaltimezone_get_builtin_timezone(zone); + utczone = icaltimezone_get_utc_timezone(); + + /* Test new API */ + if (VERBOSE) printf("\n---> From time_t \n"); + + tt = 1025127869; /* stick with a constant... */ + + if (VERBOSE) printf("Orig : %s\n",ical_timet_string(tt)); + if (VERBOSE) printf("\nicaltime_from_timet(tt,0) (DEPRECATED)\n"); + + ictt = icaltime_from_timet(tt, 0); + + is("icaltime_from_timet(1025127869) as UTC", ictt_as_string(ictt), + "2002-06-26 21:44:29 (floating)"); + + ictt = icaltime_from_timet_with_zone(tt, 0, NULL); + is("Floating time from time_t", + ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); + + ictt = icaltime_from_timet_with_zone(tt, 0, azone); + ok("icaltime_from_timet_with_zone(tt,0,zone) as zone", + strncmp(ictt_as_string(ictt), "2002-06-26 21:44:29", 19)==0); + + ictt = icaltime_from_timet_with_zone(tt, 0, utczone); + + is("icaltime_from_timet_with_zone(tt,0,utc)", ictt_as_string(ictt), + "2002-06-26 21:44:29 Z UTC"); + + if (VERBOSE) printf("\n---> Convert from floating \n"); + + ictt = icaltime_from_timet_with_zone(tt, 0, NULL); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + is("Convert from floating to UTC", + ictt_as_string(icttutc), + "2002-06-26 21:44:29 Z UTC"); + + icttzone = icaltime_convert_to_zone(ictt, azone); + + ok("Convert from floating to zone", + (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 19)==0)); + + tt2 = icaltime_as_timet(icttzone); + + if (VERBOSE) printf("\n---> Convert from UTC \n"); + + ictt = icaltime_from_timet_with_zone(tt, 0, utczone); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + is("Convert from UTC to UTC", + ictt_as_string(icttutc), + "2002-06-26 21:44:29 Z UTC"); + + icttzone = icaltime_convert_to_zone(ictt, azone); + + ok("Convert from UTC to zone (test year/mon only..)", + (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 7)==0)); + + tt2 = icaltime_as_timet(icttzone); + + if (VERBOSE) printf("No conversion: %s\n", ical_timet_string(tt2)); + + ok("No conversion at all (test year/mon only)", + (strncmp(ical_timet_string(tt2), "2002-06-26 21:44:29 Z",7) == 0)); + + tt2 = icaltime_as_timet_with_zone(icttzone, utczone); + if (VERBOSE) printf("Back to UTC : %s\n", ical_timet_string(tt2)); + + ok("test time conversion routines",(tt==tt2)); + + if (VERBOSE) printf("\n---> Convert from zone \n"); + ictt = icaltime_from_timet_with_zone(tt, 0, azone); + icttzone = icaltime_convert_to_zone(ictt, azone); + + if (VERBOSE) + printf("To zone : %s\n", ictt_as_string(icttzone)); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + if (VERBOSE) + printf("To UTC : %s\n", ictt_as_string(icttutc)); + tt2 = icaltime_as_timet(icttutc); + + if (VERBOSE) + printf("No conversion: %s\n", ical_timet_string(tt2)); + + tt2 = icaltime_as_timet_with_zone(icttutc, azone); + + if (VERBOSE) + printf("Back to zone : %s\n", ical_timet_string(tt2)); + + ok("test time conversion, round 2", (tt==tt2)); + ictt = icaltime_from_string("20001103T183030Z"); tt = icaltime_as_timet(ictt); - assert(tt==973276230); /* Fri Nov 3 10:30:30 PST 2000 in PST - Fri Nov 3 18:30:30 PST 2000 in UTC */ + ok("test icaltime -> time_t for 20001103T183030Z", (tt==973276230)); + /* Fri Nov 3 10:30:30 PST 2000 in PST + Fri Nov 3 18:30:30 PST 2000 in UTC */ - offset_la = icaltime_utc_offset(ictt,"America/Los_Angeles"); - offset_tz = icaltime_utc_offset(ictt, zone); - + if (VERBOSE) { printf(" Normalize \n"); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); + } icttnorm = ictt; icttnorm.second -= 60 * 60 * 24 * 5; icttnorm = icaltime_normalize(icttnorm); - printf("-5d in sec : %s\n", ictt_as_string(icttnorm)); + + if (VERBOSE) + printf("-5d in sec : %s\n", ictt_as_string(icttnorm)); icttnorm.day += 60; icttnorm = icaltime_normalize(icttnorm); - printf("+60 d : %s\n", ictt_as_string(icttnorm)); + if (VERBOSE) + printf("+60 d : %s\n", ictt_as_string(icttnorm)); + + /** add test case here.. **/ + if (VERBOSE) printf("\n As time_t \n"); tt2 = icaltime_as_timet(ictt); - printf("20001103T183030Z (timet): %s\n",ical_timet_string(tt2)); - printf("20001103T183030Z : %s\n",ictt_as_string(ictt)); - assert(tt2 == tt); - icttlocal = icaltime_from_string("20001103T183030"); + if (VERBOSE) { + printf("20001103T183030Z (timet): %s\n",ical_timet_string(tt2)); + printf("20001103T183030Z : %s\n",ictt_as_string(ictt)); + } + + /** this test is bogus **/ + ok("test normalization", (tt2 == tt)); + + icttlocal = icaltime_convert_to_zone(ictt, azone); tt2 = icaltime_as_timet(icttlocal); - printf("20001103T183030 (timet): %s\n",ical_timet_string(tt2)); - printf("20001103T183030 : %s\n",ictt_as_string(icttlocal)); - assert(tt-tt2 == offset_tz); + if (VERBOSE) { + printf("20001103T183030 (timet): %s\n",ical_timet_string(tt2)); + printf("20001103T183030 : %s\n",ictt_as_string(icttlocal)); + } - printf("\n From time_t \n"); + offset_tz = -icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0); /* FIXME */ + if (VERBOSE) + printf("offset_tz : %d\n",offset_tz); - printf("Orig : %s\n",ical_timet_string(tt)); - printf("As utc : %s\n", ictt_as_string(ictt)); + ok("test utc offset", (tt-tt2 == offset_tz)); - icttlocal = icaltime_as_zone(ictt,zone); - printf("As local : %s\n", ictt_as_string(icttlocal)); - + /* FIXME with the new API, it's not very useful */ + icttlocal = ictt; + icaltimezone_convert_time(&icttlocal, + icaltimezone_get_utc_timezone(), + icaltimezone_get_builtin_timezone(zone)); - printf("\n Convert to and from lib c \n"); + if (VERBOSE) + printf("As local : %s\n", ictt_as_string(icttlocal)); - printf("System time is: %s\n",ical_timet_string(tt)); + if (VERBOSE) printf("\n Convert to and from lib c \n"); + + if (VERBOSE) printf("System time is: %s\n",ical_timet_string(tt)); v = icalvalue_new_datetime(ictt); - printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); + if (VERBOSE) + printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); + + icalvalue_free(v); tt2 = icaltime_as_timet(ictt); + + if (VERBOSE) printf("Converted back to libc: %s\n",ical_timet_string(tt2)); - printf("\n Incrementing time \n"); + if (VERBOSE) printf("\n Incrementing time \n"); icttnorm = ictt; icttnorm.year++; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add a year: %s\n",ical_timet_string(tt2)); icttnorm.month+=13; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add 13 months: %s\n",ical_timet_string(tt2)); icttnorm.second+=90; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add 90 seconds: %s\n",ical_timet_string(tt2)); - printf("\n Day Of week \n"); + if (VERBOSE) printf("\n Day Of week \n"); day_of_week = icaltime_day_of_week(ictt); start_day_of_week = icaltime_start_doy_of_week(ictt); day_of_year = icaltime_day_of_year(ictt); + sprintf(msg, "Testing day of week %d", day_of_week); + int_is(msg, day_of_week, 6); - printf("Today is day of week %d, day of year %d\n",day_of_week,day_of_year); - printf("Week started n doy of %d\n",start_day_of_week); - assert(day_of_week == 6); - assert(day_of_year == 308); - assert(start_day_of_week == 303 ); + sprintf(msg, "Testing day of year %d",day_of_year); + int_is(msg, day_of_year, 308); + + sprintf(msg, "Week started on doy of %d", start_day_of_week); + int_is(msg, start_day_of_week , 303); + + if (VERBOSE) printf("\n TimeZone Conversions \n"); + +/* + icttla = ictt; + icaltimezone_convert_time(&icttla, + icaltimezone_get_utc_timezone(), + lazone); +*/ + icttla = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); - printf("\n TimeZone Conversions \n"); + int_is("Converted hour in America/Los_Angeles is 10", icttla.hour, 10); - icttla = icaltime_as_zone(ictt,"America/Los_Angeles"); - assert(icttla.hour == 10); + icttutc = icaltime_convert_to_zone(icttla,icaltimezone_get_utc_timezone()); - icttutc = icaltime_as_utc(icttla,"America/Los_Angeles"); - assert(icaltime_compare(icttla, - icaltime_from_string("20001103T103030"))==0); + ok("America/Los_Angeles local time is 2000-11-03 10:30:30", + (strncmp(ictt_as_string(icttla), "2000-11-03 10:30:30", 19)==0)); - icttutczone = icaltime_as_zone(ictt,"Etc/GMT0"); - icttutczone.is_utc = 1; - assert(icaltime_compare(icttutc, icttutczone) == 0); - assert(icaltime_compare(icttutc, ictt) == 0); + ok("Test conversion back to UTC",(icaltime_compare(icttutc, ictt) == 0)); - icttny = icaltime_as_zone(ictt,"America/New_York"); + icttny = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/New_York")); - icttphoenix = icaltime_as_zone(ictt,"America/Phoenix"); + icttphoenix = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Phoenix")); + if (VERBOSE) { printf("Orig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("UTC : %s\n", ictt_as_string(icttutc)); printf("Los Angeles : %s\n", ictt_as_string(icttla)); printf("Phoenix : %s\n", ictt_as_string(icttphoenix)); printf("New York : %s\n", ictt_as_string(icttny)); - + } + /** @todo Check results for Phoenix here?... **/ /* Daylight savings test for New York */ + if (VERBOSE) { printf("\n Daylight Savings \n"); printf("Orig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("NY : %s\n", ictt_as_string(icttny)); + } - assert(strcmp(ictt_as_string(icttny),"2000-11-03 13:30:30")==0); + ok("Converted time in zone America/New_York is 2000-11-03 13:30:30", + (strncmp(ictt_as_string(icttny),"2000-11-03 13:30:30",19)==0)); tt_p200 = tt + 200 * 24 * 60 * 60 ; /* Add 200 days */ - icttdayl = icaltime_from_timet(tt_p200,0); - icttny = icaltime_as_zone(icttdayl,"America/New_York"); - + icttdayl = icaltime_from_timet_with_zone(tt_p200,0, + icaltimezone_get_utc_timezone()); + icttny = icaltime_convert_to_zone(icttdayl, + icaltimezone_get_builtin_timezone("America/New_York")); + + if (VERBOSE) { printf("Orig +200d : %s\n", ical_timet_string(tt_p200) ); printf("NY+200D : %s\n", ictt_as_string(icttny)); + } + + ok("Converted time +200d in zone America/New_York is 2001-05-22 14:30:30", + (strncmp(ictt_as_string(icttny),"2001-05-22 14:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttny),"2001-05-22 14:30:30")==0); /* Daylight savings test for Los Angeles */ - icttla = icaltime_as_zone(ictt,"America/Los_Angeles"); + icttla = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); + if (VERBOSE) { printf("\nOrig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("LA : %s\n", ictt_as_string(icttla)); + } + + ok("Converted time in zone America/Los_Angeles is 2000-11-03 10:30:30", + (strncmp(ictt_as_string(icttla),"2000-11-03 10:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttla),"2000-11-03 10:30:30")==0); - - icttla = icaltime_as_zone(icttdayl,"America/Los_Angeles"); + icttla = icaltime_convert_to_zone(icttdayl, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); + + if (VERBOSE) { printf("Orig +200d : %s\n", ical_timet_string(tt_p200) ); printf("LA+200D : %s\n", ictt_as_string(icttla)); + } + + ok("Converted time +200d in zone America/Los_Angeles is 2001-05-22 11:30:30", + (strncmp(ictt_as_string(icttla),"2001-05-22 11:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttla),"2001-05-22 11:30:30")==0); icalerror_errors_are_fatal = 1; } @@ -1715,34 +1696,40 @@ void test_iterators() { icalcomponent *c,*inner,*next; icalcompiter i; + char vevent_list[64] = ""; + char remaining_list[64] = ""; + char *vevent_list_good = "12347"; + char *remaining_list_good = "568910"; + + int nomore = 1; + c= icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("1"),0), + icalproperty_new_version("1"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("2"),0), + icalproperty_new_version("2"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("3"),0), + icalproperty_new_version("3"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("4"),0), + icalproperty_new_version("4"),0), icalcomponent_vanew(ICAL_VTODO_COMPONENT, - icalproperty_vanew_version("5"),0), + icalproperty_new_version("5"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("6"),0), + icalproperty_new_version("6"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("7"),0), + icalproperty_new_version("7"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("8"),0), + icalproperty_new_version("8"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("9"),0), + icalproperty_new_version("9"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("10"),0), + icalproperty_new_version("10"),0), 0); - printf("1: "); - /* List all of the VEVENTS */ + for(i = icalcomponent_begin_component(c,ICAL_VEVENT_COMPONENT); icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ @@ -1753,24 +1740,10 @@ void test_iterators() ICAL_VERSION_PROPERTY); const char* s = icalproperty_get_version(p); - printf("%s ",s); - - } - - printf("\n2: "); - -#if 0 - for(inner = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - inner != 0; - inner = next){ - - next = icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); - - icalcomponent_remove_component(c,inner); - - icalcomponent_free(inner); + strcat(vevent_list, s); } -#endif + is("iterate through VEVENTS in a component", + vevent_list, vevent_list_good); /* Delete all of the VEVENTS */ /* reset iterator */ @@ -1779,12 +1752,11 @@ void test_iterators() while((inner=icalcomponent_get_current_component(c)) != 0 ){ if(icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT){ icalcomponent_remove_component(c,inner); + icalcomponent_free(inner); } else { icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); } } - - /* List all remaining components */ for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); @@ -1797,10 +1769,11 @@ void test_iterators() const char* s = icalproperty_get_version(p); - printf("%s ",s); + strcat(remaining_list, s); } - printf("\n3: "); + is("iterate through remaining components", + remaining_list, remaining_list_good); /* Remove all remaining components */ @@ -1815,7 +1788,6 @@ void test_iterators() p=icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); s = icalproperty_get_version(p); - printf("rem:%s ",s); icalcomponent_remove_component(c,inner); @@ -1824,14 +1796,11 @@ void test_iterators() if(this != 0){ p=icalcomponent_get_first_property(this,ICAL_VERSION_PROPERTY); s = icalproperty_get_version(p); - printf("next:%s; ",s); } icalcomponent_free(inner); } - printf("\n4: "); - /* List all remaining components */ for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); @@ -1843,95 +1812,33 @@ void test_iterators() const char* s = icalproperty_get_version(p); - printf("%s ",s); - } - - printf("\n"); -} - - - -char* test_set_tz(const char* tzid) -{ - char *tzstr = 0; - char *tmp; - - /* Put the new time zone into the environment */ - if(getenv("TZ") != 0){ - tzstr = (char*)icalmemory_strdup(getenv("TZ")); - - if(tzstr == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - } - - tmp = (char*)malloc(1024); - - if(tmp == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; + if (s) + nomore = 0; } - snprintf(tmp,1024,"TZ=%s",tzid); - - /* HACK. In some libc versions, putenv gives the string to the - system and in some it gives a copy, so the following might be a - memory leak. THe linux man page says that glibc2.1.2 take - ownership ( no leak) while BSD4.4 uses a copy ( A leak ) */ - putenv(tmp); - - return tzstr; /* This will be zero if the TZ env var was not set */ -} - -void test_unset_tz(char* tzstr) -{ - /* restore the original environment */ - - if(tzstr!=0){ - char temp[1024]; - snprintf(temp,1024,"TZ=%s",tzstr); - putenv(temp); - free(tzstr); - } else { - putenv("TZ"); /* Delete from environment */ - } + ok("test if any components remain after deleting the rest", + nomore == 1); + + icalcomponent_free(c); } void test_time() { - char zones[6][40] = { "America/Los_Angeles","America/New_York","Europe/London","Asia/Shanghai", ""}; + char *zones[6] = { "America/Los_Angeles","America/New_York","Europe/London","Asia/Shanghai", NULL}; + int i; - char* old_tz; - int orig_month; - time_t tt; - struct tm stm; - - tt = time(0); - - stm = *(localtime(&tt)); - - orig_month = stm.tm_mon; do_test_time(0); - old_tz = test_set_tz(zones[0]); + for(i = 0; zones[i] != NULL; i++){ - for(i = 0; zones[i][0] != 0; i++){ - - if(zones[i][0] != 0){ - test_set_tz(zones[i]); - } - - printf(" ######### Timezone: %s ############\n",zones[i]); - + if (VERBOSE) printf(" ######### Timezone: %s ############\n",zones[i]); + do_test_time(zones[i]); } - test_unset_tz(old_tz); - } @@ -1958,168 +1865,16 @@ void test_icalset() printf(" class %d\n",icalclassify(c,0,"user")); } -} - -void test_classify() -{ - icalcomponent *c,*match; - icalset* f = icalset_new_file("../../test-data/classify.ics"); - - assert(f!=0); - - c = icalset_get_first_component(f); - match = icalset_get_next_component(f); - - printf("Class %d\n",icalclassify(c,match,"A@example.com")); - - + icalset_free(f); + icalset_free(d); } -void print_span(int c, struct icaltime_span span ){ - - printf("#%02d start: %s\n",c,ical_timet_string(span.start)); - printf(" end : %s\n",ical_timet_string(span.end)); - -} - -struct icaltimetype icaltime_as_local(struct icaltimetype tt) { - return icaltime_as_zone(tt,0); -} - -void test_span() -{ - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, - Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 - Sat Nov 4 16:00:00 PST 2000 */ - struct icaldurationtype dur; - struct icaltime_span span; - icalcomponent *c; - - memset(&dur,0,sizeof(dur)); - dur.minutes = 30; - - span.start = tm1; - span.end = tm2; - print_span(0,span); - - /* Specify save timezone as in commend above */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Pacific"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Pacific"),0), - 0 - ); - - printf("%s\n",icalcomponent_as_ical_string(c)); - - span = icalcomponent_get_span(c); - - print_span(1,span); - - icalcomponent_free(c); - - /* Use machine's local timezone. Same as above if run in US/Pacific */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0),0), - icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0), - 0 - ); - - span = icalcomponent_get_span(c); - - print_span(2,span); - - icalcomponent_free(c); - - /* Specify different timezone */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Eastern"),0), - 0 - ); - span = icalcomponent_get_span(c); - print_span(3,span); - - icalcomponent_free(c); - - - /* Specify different timezone for start and end*/ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Pacific"),0), - 0 - ); - span = icalcomponent_get_span(c); - print_span(4,span); - - icalcomponent_free(c); - - /* Use Duration */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Pacific"),0), - icalproperty_new_duration(dur), - - 0 - ); - span = icalcomponent_get_span(c); - print_span(5,span); - - icalcomponent_free(c); - - -#ifndef ICAL_ERRORS_ARE_FATAL - /* Both UTC and Timezone -- an error */ - icalerror_clear_errno(); - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend(icaltime_from_timet(tm2,0), - icalparameter_new_tzid("US/Eastern"),0), - 0 - ); - - span = icalcomponent_get_span(c); - assert(icalerrno != ICAL_NO_ERROR); - - icalcomponent_free(c); - -#endif /*ICAL_ERRORS_ARE_FATAL*/ - -} icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp); void test_overlaps() { - -#if 0 /* Hack, not working right now */ icalcomponent *cset,*c; icalset *set; time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, @@ -2131,7 +1886,6 @@ void test_overlaps() set = icalset_new_file("../../test-data/overlaps.ics"); - printf("-- 1 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0), @@ -2140,10 +1894,14 @@ void test_overlaps() ); cset = icalclassify_find_overlaps(set,c); + ok("TODO find overlaps 1", (cset != NULL)); + + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); + + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); - printf("%s\n",icalcomponent_as_ical_string(cset)); - printf("-- 2 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0), @@ -2153,9 +1911,12 @@ void test_overlaps() cset = icalclassify_find_overlaps(set,c); - printf("%s\n",icalcomponent_as_ical_string(cset)); + ok("TODO find overlaps 1", cset != NULL); + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); + + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); - printf("-- 3 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1+5*hh,0),0), @@ -2164,63 +1925,144 @@ void test_overlaps() ); cset = icalclassify_find_overlaps(set,c); + ok("TODO find overlaps 1", cset != NULL); + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); - printf("%s\n",icalcomponent_as_ical_string(cset)); + if (set) icalset_free(set); + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); +} -#endif -} void test_fblist() { - icalspanlist *sl; + icalspanlist *sl, *new_sl; icalset* set = icalset_new_file("../../test-data/spanlist.ics"); struct icalperiodtype period; + icalcomponent *comp; + int * foo; + int i; sl = icalspanlist_new(set, - icaltime_from_string("19970324T120000Z"), - icaltime_from_string("19990424T020000Z")); + icaltime_from_string("19980101T000000Z"), + icaltime_from_string("19980108T000000Z")); - printf("Restricted spanlist\n"); - icalspanlist_dump(sl); + ok("open ../../test-data/spanlist.ics", (set!=NULL)); + assert(set!=NULL); + + if (VERBOSE) printf("Restricted spanlist\n"); + if (VERBOSE) icalspanlist_dump(sl); period= icalspanlist_next_free_time(sl, - icaltime_from_string("19970801T120000Z")); + icaltime_from_string("19970801T120000")); + + is("Next Free time start 19970801T120000", icaltime_as_ical_string(period.start), "19970801T120000"); + is("Next Free time end 19980101T000000", icaltime_as_ical_string(period.end), "19980101T000000"); + + period= icalspanlist_next_free_time(sl, period.end); + + is("Next Free time start 19980101T010000", icaltime_as_ical_string(period.start), "19980101T010000"); + is("Next Free time end 19980102T010000", icaltime_as_ical_string(period.end), "19980102T010000"); + + if (VERBOSE) printf("%s\n", + icalcomponent_as_ical_string(icalspanlist_as_vfreebusy(sl, + "a@foo.com", + "b@foo.com") + )); + + foo = icalspanlist_as_freebusy_matrix(sl,3600); + + for (i=0; foo[i] != -1; i++); /* find number entries */ + + int_is("Calculating freebusy hourly matrix", i, (7*24)); + + if (VERBOSE) { + for (i=0; foo[i] != -1; i++) { + printf("%d", foo[i]); + if ((i % 24) == 23) + printf("\n"); + } + printf("\n\n"); + } + + + free(foo); + foo = icalspanlist_as_freebusy_matrix(sl,3600*24); - printf("Next Free time: %s\n",icaltime_as_ctime(period.start)); - printf(" %s\n",icaltime_as_ctime(period.end)); + ok("Calculating daily freebusy matrix", (foo!=NULL)); + { + char out_str[80] = ""; + char *strp = out_str; + + for (i=0; foo[i]!=-1; i++){ + sprintf(strp, "%d", foo[i]); + strp++; + } + is("Checking freebusy validity", out_str, "1121110"); + } + if (VERBOSE) { + for (i=0; foo[i] != -1; i++) { + printf("%d", foo[i]); + if ((i % 7) == 6) + printf("\n"); + } + printf("\n\n"); + } + free(foo); icalspanlist_free(sl); - printf("Unrestricted spanlist\n"); + + if (VERBOSE) printf("Unrestricted spanlist\n"); sl = icalspanlist_new(set, - icaltime_from_string("19970324T120000Z"), + icaltime_from_string("19970324T120000Z"), icaltime_null_time()); - - printf("Restricted spanlist\n"); - icalspanlist_dump(sl); + ok("add 19970324T120000Z to spanlist", (sl!=NULL)); + + if (VERBOSE) printf("Restricted spanlist\n"); + if (VERBOSE) icalspanlist_dump(sl); period= icalspanlist_next_free_time(sl, icaltime_from_string("19970801T120000Z")); - printf("Next Free time: %s\n",icaltime_as_ctime(period.start)); - printf(" %s\n",icaltime_as_ctime(period.end)); + is("Next Free time start 19980101T010000", + icaltime_as_ical_string(period.start), + "19980101T010000"); + is("Next Free time end 19980102T010000", + icaltime_as_ical_string(period.end), + "19980102T010000"); - icalspanlist_free(sl); + comp = icalspanlist_as_vfreebusy(sl, "a@foo.com", "b@foo.com"); + + ok("Calculating VFREEBUSY component", (comp != NULL)); + if (VERBOSE) printf("%s\n", icalcomponent_as_ical_string(comp)); + new_sl = icalspanlist_from_vfreebusy(comp); + ok("Calculating spanlist from generated VFREEBUSY component", + (new_sl != NULL)); + + if (VERBOSE) icalspanlist_dump(new_sl); + + if (sl) icalspanlist_free(sl); + if (new_sl) icalspanlist_free(new_sl); + if (comp) icalcomponent_free(comp); + + icalset_free(set); } + void test_convenience(){ - icalcomponent *c; int duration; + struct icaltimetype tt; c = icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, @@ -2232,14 +2074,15 @@ void test_convenience(){ ), 0); - printf("** 1 DTSTART and DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 (floating)"); + is("End is 1997-08-01 13:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:00:00 (floating)"); + ok("Duration is 60 m", (duration == 60)); icalcomponent_free(c); @@ -2253,17 +2096,20 @@ void test_convenience(){ ), 0); - printf("\n** 2 DTSTART and DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 Z UTC", + ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 Z UTC"); + is("End is 1997-08-01 13:30:00 Z UTC", + ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:30:00 Z UTC"); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); + icalerror_errors_are_fatal = 0; + c = icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, icalcomponent_vanew( @@ -2276,14 +2122,17 @@ void test_convenience(){ icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); - printf("** 3 DTSTART and DTEND, Set DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtstart(c)), + "1997-08-01 12:00:00 (floating)"); + is("End is 1997-08-01 13:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtend(c)), + "1997-08-01 13:00:00 (floating)"); + ok("Duration is 60 m", (duration == 60)); icalcomponent_free(c); @@ -2299,14 +2148,18 @@ void test_convenience(){ icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z")); - printf("\n** 4 DTSTART and DURATION, set DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); + duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); + + icalerror_errors_are_fatal = 1; icalcomponent_free(c); @@ -2321,15 +2174,16 @@ void test_convenience(){ icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z")); icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z")); - printf("\n** 5 Set DTSTART and DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); @@ -2345,18 +2199,44 @@ void test_convenience(){ icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z")); icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); - printf("\n** 6 Set DTSTART and DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); + c = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + 0 + ), + 0); + + tt = icaltime_from_string("19970801T120000"); + icaltime_set_timezone(&tt, + icaltimezone_get_builtin_timezone("Europe/Rome")); + icalcomponent_set_dtstart(c,tt); + + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); + + icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); + duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; + + ok("Start is 1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", + (0 == strcmp("1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", + (0 == strcmp("1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); + + icalcomponent_free(c); } void test_time_parser() @@ -2366,77 +2246,176 @@ void test_time_parser() icalerror_errors_are_fatal = 0; tt = icaltime_from_string("19970101T1000"); - assert(icaltime_is_null_time(tt)); + ok("19970101T1000 is null time", icaltime_is_null_time(tt)); tt = icaltime_from_string("19970101X100000"); - assert(icaltime_is_null_time(tt)); + ok("19970101X100000 is null time", icaltime_is_null_time(tt)); tt = icaltime_from_string("19970101T100000"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + ok("19970101T100000 is valid", !icaltime_is_null_time(tt)); + + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); tt = icaltime_from_string("19970101T100000Z"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + + ok("19970101T100000Z is valid" , !icaltime_is_null_time(tt)); + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); tt = icaltime_from_string("19970101"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + ok("19970101 is valid", (!icaltime_is_null_time(tt))); - icalerror_errors_are_fatal = 1; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); + icalerror_errors_are_fatal = 1; } void test_recur_parser() { - struct icalrecurrencetype rt; + struct icalrecurrencetype rt; + char *str; + + str = "FREQ=YEARLY;UNTIL=20000131T090000Z;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8"; + rt = icalrecurrencetype_from_string(str); + is(str, icalrecurrencetype_as_string(&rt), str); + + str = "FREQ=DAILY;COUNT=3;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8"; + + rt = icalrecurrencetype_from_string(str); + is(str, icalrecurrencetype_as_string(&rt), str); +} + +char* ical_strstr(const char *haystack, const char *needle){ + return strstr(haystack,needle); +} + +void test_start_of_week() +{ + struct icaltimetype tt2; + struct icaltimetype tt1 = icaltime_from_string("19900110"); + int dow, doy,start_dow; - printf("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA\n"); + do{ + tt1 = icaltime_normalize(tt1); - rt = icalrecurrencetype_from_string("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA"); + doy = icaltime_start_doy_of_week(tt1); + dow = icaltime_day_of_week(tt1); - printf("%s\n\n",icalrecurrencetype_as_string(&rt)); + tt2 = icaltime_from_day_of_year(doy,tt1.year); + start_dow = icaltime_day_of_week(tt2); - printf("FREQ=DAILY;COUNT=3;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,S\n"); + if(doy == 1){ + char msg[128]; + sprintf(msg, "%s", ictt_as_string(tt1)); + int_is(msg, start_dow, 1); + } - rt = icalrecurrencetype_from_string("FREQ=DAILY;COUNT=3;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA"); + if(start_dow != 1){ /* Sunday is 1 */ + printf("failed: Start of week (%s) is not a Sunday \n for %s (doy=%d,dow=%d)\n",ictt_as_string(tt2), ictt_as_string(tt1),dow,start_dow); + } - printf("%s\n",icalrecurrencetype_as_string(&rt)); -} + assert(start_dow == 1); -char* ical_strstr(const char *haystack, const char *needle){ - return strstr(haystack,needle); + + tt1.day+=1; + + } while(tt1.year < 2010); } void test_doy() { struct icaltimetype tt1, tt2; - short doy; + short doy,doy2; + char msg[128]; + + doy = -1; + + tt1 = icaltime_from_string("19900101"); + + if (VERBOSE) printf("Test icaltime_day_of_year() agreement with mktime\n"); + + do{ + struct tm stm; + + tt1 = icaltime_normalize(tt1); + + stm.tm_sec = tt1.second; + stm.tm_min = tt1.minute; + stm.tm_hour = tt1.hour; + stm.tm_mday = tt1.day; + stm.tm_mon = tt1.month-1; + stm.tm_year = tt1.year-1900; + stm.tm_isdst = -1; + + mktime(&stm); + + doy = icaltime_day_of_year(tt1); + + doy2 = stm.tm_yday+1; + + if (doy == 1) { + /** show some test cases **/ + sprintf(msg, "Year %d - mktime() compare", tt1.year); + int_is(msg, doy,doy2); + } + + if (doy != doy2){ + printf("Failed for %s (%d,%d)\n",ictt_as_string(tt1),doy,doy2); + } + assert(doy == doy2); + + tt1.day+=1; + + } while(tt1.year < 2010); + + if (VERBOSE) printf("\nTest icaltime_day_of_year() agreement with icaltime_from_day_of_year()\n"); + + tt1 = icaltime_from_string("19900101"); + + do{ + if(doy == 1){ + /** show some test cases **/ + sprintf(msg, "Year %d - icaltime_day_of_year() compare", tt1.year); + int_is(msg, doy,doy2); + } + + doy = icaltime_day_of_year(tt1); + tt2 = icaltime_from_day_of_year(doy,tt1.year); + doy2 = icaltime_day_of_year(tt2); + + assert(doy2 == doy); + assert(icaltime_compare(tt1,tt2) == 0); + + tt1.day+=1; + tt1 = icaltime_normalize(tt1); + + } while(tt1.year < 2010); + tt1 = icaltime_from_string("19950301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1995); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 60); + if(VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); + + ok("test 19950301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 60", (doy == 60)); tt1 = icaltime_from_string("19960301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1996); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 61); + if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); + ok("test 19960301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 61", (doy == 61)); tt1 = icaltime_from_string("19970301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1997); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 60); + if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); -} + ok("test 19970301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 60", (doy == 60)); +} void test_x(){ @@ -2462,15 +2441,15 @@ void test_x(){ int n_errors; icalcomp = icalparser_parse_string ((char *) test_icalcomp_str); - if (!icalcomp) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + assert(icalcomp!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); + if (VERBOSE) printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); n_errors = icalcomponent_count_errors (icalcomp); + int_is("icalparser_parse_string()", n_errors,0); + if (n_errors) { + /** NOT USED **/ icalproperty *p; for (p = icalcomponent_get_first_property (icalcomp, @@ -2478,7 +2457,7 @@ void test_x(){ p; p = icalcomponent_get_next_property (icalcomp, ICAL_XLICERROR_PROPERTY)) { - char *str; + const char *str; str = icalproperty_as_ical_string (p); fprintf (stderr, "error: %s\n", str); @@ -2486,44 +2465,67 @@ void test_x(){ } prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY); - if (!prop) { - fprintf (stderr, "main(): could not get the RRULE property"); - exit (EXIT_FAILURE); - } + ok("get RRULE property", (prop != NULL)); + assert(prop!=NULL); recur = icalproperty_get_rrule (prop); - printf("%s\n",icalrecurrencetype_as_string(&recur)); + if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur)); + + icalcomponent_free(icalcomp); } void test_gauge_sql() { - - icalgauge *g; + char* str; - printf("\nSELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5\n"); + str= "SELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5"; - g = icalgauge_new_from_sql("SELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5"); - - icalgauge_dump(g); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); icalgauge_free(g); - printf("\nSELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'\n"); + str="SELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'"; - g = icalgauge_new_from_sql("SELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'"); - - icalgauge_dump(g); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); + + str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); + + str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); icalgauge_free(g); + str="SELECT * FROM VEVENT WHERE LOCATION == '104 Forum'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); } -void test_gauge_compare() { +void test_gauge_compare() { icalgauge *g; icalcomponent *c; + char* str; /* Equality */ @@ -2533,35 +2535,35 @@ void test_gauge_compare() { icaltime_from_string("20000101T000002")),0),0); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", (c!=0 && g!=0)); assert(c!=0); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'\n", (c!=0 && g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); @@ -2569,47 +2571,48 @@ void test_gauge_compare() { /* Less than */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", (c!=0 && g!=0)); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); assert(g!=0); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); /* Greater than */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); + icalgauge_free(g); @@ -2617,53 +2620,117 @@ void test_gauge_compare() { /* Greater than or Equal to */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); /* Less than or Equal to */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); icalcomponent_free(c); + /* Combinations */ + + c = icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart( + icaltime_from_string("20000102T000000")),0),0); + + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + + icalcomponent_free(c); + + /* Combinations, non-cannonical component */ + + c = icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart( + icaltime_from_string("20000102T000000")),0); + + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + icalcomponent_free(c); + /* Complex comparisions */ @@ -2684,37 +2751,45 @@ void test_gauge_compare() { 0), 0); + + str = "SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'"; - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'"); - - printf("SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'\n"); - - assert(icalgauge_compare(g,c) == 1); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE COMMENT = 'foo'"); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); - printf("SELECT * FROM VEVENT WHERE COMMENT = 'foo'\n"); - - assert(icalgauge_compare(g,c) == 1); + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' AND VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'"); - - printf("SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'\n"); + icalgauge_free(g); - assert(icalgauge_compare(g,c) == 1); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' or VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); icalcomponent_free(c); - + } icalcomponent* make_component(int i){ @@ -2743,18 +2818,21 @@ icalcomponent* make_component(int i){ } void test_fileset() { - icalfileset *fs; + icalset *fs; icalcomponent *c; int i; + int comp_count = 0; char *path = "test_fileset.ics"; icalgauge *g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z'", 0); + ok("icalgauge_new_from_sql()", (g!=NULL)); unlink(path); fs = icalfileset_new(path); + ok("icalfileset_new()", (fs!=NULL)); assert(fs != 0); for (i = 0; i!= 10; i++){ @@ -2764,60 +2842,68 @@ void test_fileset() icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); + /** reopen fileset.ics **/ fs = icalfileset_new(path); + if (VERBOSE) printf("== No Selections \n"); - printf("== No Selections \n"); - + comp_count = 0; for (c = icalfileset_get_first_component(fs); c != 0; c = icalfileset_get_next_component(fs)){ struct icaltimetype t = icalcomponent_get_dtstart(c); - - printf("%s\n",icaltime_as_ctime(t)); + comp_count++; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(t)); } + int_is("icalfileset get components",comp_count, 10); icalfileset_select(fs,g); - printf("\n== DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z' \n"); + if (VERBOSE) printf("\n== DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z' \n"); + comp_count = 0; for (c = icalfileset_get_first_component(fs); c != 0; c = icalfileset_get_next_component(fs)){ struct icaltimetype t = icalcomponent_get_dtstart(c); - - printf("%s\n",icaltime_as_ctime(t)); + comp_count++; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(t)); } + int_is("icalfileset get components with gauge",comp_count, 3); - icalfileset_free(fs); + icalset_free(fs); + + /*icalgauge_free(g);*/ } void microsleep(int us) { +#ifndef WIN32 struct timeval tv; tv.tv_sec = 0; tv.tv_usec = us; select(0,0,0,0,&tv); - +#else + Sleep(us); +#endif } void test_file_locks() { +#ifndef WIN32 pid_t pid; char *path = "test_fileset_locktest.ics"; - icalfileset *fs; + icalset *fs; icalcomponent *c, *c2; struct icaldurationtype d; int i; int final,sec; - icalfileset_safe_saves = 1; - icalerror_clear_errno(); unlink(path); @@ -2840,7 +2926,7 @@ void test_file_locks() icalfileset_commit(fs); } - icalfileset_free(fs); + icalset_free(fs); assert(icalerrno == ICAL_NO_ERROR); @@ -2877,7 +2963,7 @@ void test_file_locks() icalfileset_mark(fs); icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); microsleep(rand()/(RAND_MAX/20)); @@ -2911,7 +2997,7 @@ void test_file_locks() icalfileset_mark(fs); icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); putc('.',stdout); fflush(stdout); @@ -2943,48 +3029,50 @@ void test_file_locks() assert(sec == final); +#endif } void test_action() { icalcomponent *c; icalproperty *p; - + char *str; + static const char test_icalcomp_str[] = "BEGIN:VEVENT\n" "ACTION:EMAIL\n" "ACTION:PROCEDURE\n" "ACTION:AUDIO\n" "ACTION:FUBAR\n" -"END:VEVENT\r\n"; +"END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); - if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + + ok("icalparser_parse_string(), ACTIONS", (c!=NULL)); + assert(c!=0); - printf("%s\n\n",icalcomponent_as_ical_string(c)); + str = icalcomponent_as_ical_string(c); + is("icalcomponent_as_ical_string()", str, ((char*) test_icalcomp_str)); + if (VERBOSE) printf("%s\n\n",str); p = icalcomponent_get_first_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_EMAIL); + ok("ICAL_ACTION_EMAIL", (icalproperty_get_action(p) == ICAL_ACTION_EMAIL)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_PROCEDURE); + ok("ICAL_ACTION_PROCEDURE", (icalproperty_get_action(p) == ICAL_ACTION_PROCEDURE)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_AUDIO); + ok("ICAL_ACTION_AUDIO", (icalproperty_get_action(p) == ICAL_ACTION_AUDIO)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_X); - assert(regrstrcmp(icalvalue_get_x(icalproperty_get_value(p)), "FUBAR")==0); - - + ok("ICAL_ACTION_X", (icalproperty_get_action(p) == ICAL_ACTION_X)); + is("ICAL_ACTION -> FUBAR", icalvalue_get_x(icalproperty_get_value(p)), "FUBAR"); + icalcomponent_free(c); } @@ -2995,24 +3083,22 @@ void test_trigger() struct icaltriggertype tr; icalcomponent *c; icalproperty *p; - char* str; + const char* str; static const char test_icalcomp_str[] = "BEGIN:VEVENT\n" "TRIGGER;VALUE=DATE-TIME:19980403T120000\n" -"TRIGGER:-PT15M\n" -"TRIGGER:19980403T120000\n" "TRIGGER;VALUE=DURATION:-PT15M\n" -"END:VEVENT\r\n"; +"TRIGGER;VALUE=DATE-TIME:19980403T120000\n" +"TRIGGER;VALUE=DURATION:-PT15M\n" +"END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); - if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + ok("icalparser_parse_string()", (c!= NULL)); + assert(c!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(c)); + is("parsed triggers", icalcomponent_as_ical_string(c), (char*)test_icalcomp_str); for(p = icalcomponent_get_first_property(c,ICAL_TRIGGER_PROPERTY); p != 0; @@ -3020,20 +3106,21 @@ void test_trigger() tr = icalproperty_get_trigger(p); if(!icaltime_is_null_time(tr.time)){ - printf("value=DATE-TIME:%s\n", icaltime_as_ical_string(tr.time)); + if (VERBOSE) printf("value=DATE-TIME:%s\n", icaltime_as_ical_string(tr.time)); } else { - printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration)); + if (VERBOSE) printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration)); } } + icalcomponent_free(c); + /* Trigger, as a DATETIME */ tr.duration = icaldurationtype_null_duration(); tr.time = icaltime_from_string("19970101T120000"); p = icalproperty_new_trigger(tr); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /* TRIGGER, as a DURATION */ @@ -3042,8 +3129,7 @@ void test_trigger() p = icalproperty_new_trigger(tr); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); /* TRIGGER, as a DATETIME, VALUE=DATETIME*/ @@ -3053,8 +3139,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=DATETIME */ @@ -3065,8 +3150,7 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); /* TRIGGER, as a DATETIME, VALUE=DURATION*/ @@ -3076,8 +3160,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=DURATION */ @@ -3088,8 +3171,7 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); @@ -3100,8 +3182,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=BINARY */ @@ -3112,20 +3193,17 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); - - - } + void test_rdate() { struct icaldatetimeperiodtype dtp; icalproperty *p; - char* str; + const char* str; struct icalperiodtype period; period.start = icaltime_from_string("19970101T120000"); @@ -3137,10 +3215,10 @@ void test_rdate() dtp.period = icalperiodtype_null_period(); p = icalproperty_new_rdate(dtp); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); - icalproperty_free(p); + is("RDATE as DATE-TIME", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); + icalproperty_free(p); /* RDATE, as PERIOD */ dtp.time = icaltime_null_time(); @@ -3148,8 +3226,7 @@ void test_rdate() p = icalproperty_new_rdate(dtp); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + is("RDATE, as PERIOD", "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); /* RDATE, as DATE-TIME, VALUE=DATE-TIME */ @@ -3158,8 +3235,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=DATE-TIME", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3169,8 +3247,8 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + is("RDATE, as PERIOD, VALUE=DATE-TIME", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); @@ -3180,8 +3258,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=PERIOD", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3191,8 +3270,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + + is("RDATE, as PERIOD, VALUE=PERIOD", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); @@ -3202,8 +3282,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=BINARY", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3213,11 +3294,10 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); - icalproperty_free(p); - + is("RDAE, as PERIOD, VALUE=BINARY", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); + icalproperty_free(p); } @@ -3225,11 +3305,12 @@ void test_langbind() { icalcomponent *c, *inner; icalproperty *p; - + char *test_str_parsed; static const char test_str[] = "BEGIN:VEVENT\n" "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n" "COMMENT: Comment that \n spans a line\n" +"COMMENT: Comment with \"quotable\" \'characters\' and other \t bad magic \n things \f Yeah.\n" "DTSTART:19970101T120000\n" "DTSTART:19970101T120000Z\n" "DTSTART:19970101\n" @@ -3237,13 +3318,37 @@ void test_langbind() "FREEBUSY:19970101T120000/19970101T120000\n" "FREEBUSY:19970101T120000/P3DT4H25M\n" "END:VEVENT\n"; - - printf("%s\n",test_str); + static const char *test_str_parsed_good = +"BEGIN:VEVENT\n" +"ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:\n" +" employee-A@host.com\n" +"COMMENT: Comment that spans a line\n" +"COMMENT: Comment with \\\"quotable\\\" 'characters' and other \\t bad magic \n" +" things \\f Yeah.\n" +"DTSTART:19970101T120000\n" +"DTSTART:19970101T120000Z\n" +"DTSTART;VALUE=DATE:19970101\n" +"DURATION:P3DT4H25M\n" +"FREEBUSY:19970101T120000/19970101T120000\n" +"FREEBUSY:19970101T120000/P3DT4H25M\n" +"END:VEVENT\n"; + + if (VERBOSE) printf("%s\n",test_str); c = icalparser_parse_string(test_str); - inner = icalcomponent_get_inner(c); + ok("icalparser_parse_string()", (c!=NULL)); + assert(c != NULL); + + test_str_parsed = icalcomponent_as_ical_string(c); + + is("parsed version with bad chars, etc", + test_str_parsed, + test_str_parsed_good); + + + inner = icalcomponent_get_inner(c); for( p = icallangbind_get_first_property(inner,"ANY"); @@ -3251,39 +3356,56 @@ void test_langbind() p = icallangbind_get_next_property(inner,"ANY") ) { - printf("%s\n",icallangbind_property_eval_string(p,":")); + const char *str = icallangbind_property_eval_string(p,":"); + /** TODO add tests **/ + if (VERBOSE) printf("%s\n",str); } - p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); icalproperty_set_parameter_from_string(p,"CUTYPE","INDIVIDUAL"); - printf("%s\n",icalproperty_as_ical_string(p)); - - + is ("Set attendee parameter", + icalproperty_as_ical_string(p), + "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:MAILTO:\n" + " employee-A@host.com\n"); + icalproperty_set_value_from_string(p,"mary@foo.org","TEXT"); - printf("%s\n",icalproperty_as_ical_string(p)); + is ("Set attendee parameter value", + icalproperty_as_ical_string(p), + "ATTENDEE;VALUE=TEXT;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:\n" +" mary@foo.org\n"); + icalcomponent_free(c); } void test_property_parse() { icalproperty *p; + const char *str; p= icalproperty_new_from_string( "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com"); + ok("icalproperty_from_string(), ATTENDEE", (p != 0)); assert (p != 0); - printf("%s\n",icalproperty_as_ical_string(p)); + str = icalproperty_as_ical_string(p); + if (VERBOSE) printf("%s\n",str); + + icalproperty_free(p); p= icalproperty_new_from_string("DTSTART:19970101T120000Z\n"); + ok("icalproperty_from_string(), simple DTSTART", (p != 0)); assert (p != 0); - printf("%s\n",icalproperty_as_ical_string(p)); + + str = icalproperty_as_ical_string(p); + if (VERBOSE) printf("%s\n",str); + + icalproperty_free(p); } @@ -3303,303 +3425,243 @@ void test_value_parameter() "END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); + ok("icalparser_parse_string()", (c != NULL)); if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); exit (EXIT_FAILURE); } - printf("%s",icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c)); p = icalcomponent_get_first_property(c,ICAL_DTSTART_PROPERTY); param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER); - assert(icalparameter_get_value(param) == ICAL_VALUE_DATETIME); + + ok("icalproperty_get_value()", (icalparameter_get_value(param) == ICAL_VALUE_DATETIME)); p = icalcomponent_get_next_property(c,ICAL_DTSTART_PROPERTY); param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER); - assert(icalparameter_get_value(param) == ICAL_VALUE_DATE); + ok("icalproperty_get_first_parameter()",(icalparameter_get_value(param) == ICAL_VALUE_DATE)); + icalcomponent_free(c); } -void test_x_property() +void test_x_parameter() { icalproperty *p; - - p= icalproperty_new_from_string( - "X-LIC-PROPERTY: This is a note"); - - printf("%s\n",icalproperty_as_ical_string(p)); - - assert(icalproperty_isa(p) == ICAL_X_PROPERTY); - assert(regrstrcmp(icalproperty_get_x_name(p),"X-LIC-PROPERTY")==0); - assert(regrstrcmp(icalproperty_get_x(p)," This is a note")==0); - -} - -int main(int argc, char *argv[]) -{ - int c; - extern char *optarg; - extern int optopt; - int errflg=0; - char* program_name = strrchr(argv[0],'/'); - int ttime=0, trecur=0,tspan=0, tmisc=0, tgauge = 0, tfile = 0, - tbasic = 0; - - if(argc==1) { - ttime = trecur = tspan = tmisc = tgauge = tfile = tbasic = 1; - } - while ((c = getopt(argc, argv, "t:s:r:m:g:f:b:")) != -1) { - switch (c) { - - case 'b': { - tbasic = atoi(optarg); - break; - } + p= icalproperty_new_from_string( + "COMMENT;X-A=1;X-B=2: This is a note"); - case 't': { - ttime = atoi(optarg); - break; - } + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - case 's': { - tspan = atoi(optarg); - break; - } + ok("COMMENT property",(icalproperty_isa(p) == ICAL_COMMENT_PROPERTY)); + is("COMMENT parses param", icalproperty_get_comment(p)," This is a note"); - case 'r': { - trecur = atoi(optarg); - break; - } + icalproperty_set_parameter_from_string(p,"X-LIES", "no"); + icalproperty_set_parameter_from_string(p,"X-LAUGHS", "big"); + icalproperty_set_parameter_from_string(p,"X-TRUTH", "yes"); + icalproperty_set_parameter_from_string(p,"X-HUMOUR", "bad"); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - case 'm': { - tmisc = atoi(optarg); - break; - } - + is("Check X-LIES", icalproperty_get_parameter_as_string(p, "X-LIES"), "no"); + is("Check X-LAUGHS", icalproperty_get_parameter_as_string(p, "X-LAUGHS"), "big"); + is("Check X-TRUTH", icalproperty_get_parameter_as_string(p, "X-TRUTH"), "yes"); + is("Check X-HUMOUR", icalproperty_get_parameter_as_string(p, "X-HUMOUR"), "bad"); - case 'g': { - tgauge = atoi(optarg); - break; - } - - case 'f': { - tfile = atoi(optarg); - break; - } - - case ':': {/* Option given without an operand */ - fprintf(stderr, - "%s: Option -%c requires an operand\n", - program_name,optopt); - errflg++; - break; - } - case '?': { - errflg++; - } - - } - - } - - - if(ttime==1 || ttime==2){ - printf("\n------------Test time parser ----------\n"); - test_time_parser(); - - } - - if(ttime==1 || ttime==3){ - printf("\n------------Test time----------------\n"); - test_time(); - } - - if(ttime==1 || ttime==4){ - printf("\n------------Test day of year---------\n"); - test_doy(); - } - - if(ttime==1 || ttime==5){ - printf("\n------------Test duration---------------\n"); - test_duration(); - } - - if(ttime==1 || ttime==6){ - printf("\n------------Test period ----------------\n"); - test_period(); - } - - - - if(trecur==1 || trecur==2){ - printf("\n------------Test recur parser ----------\n"); - test_recur_parser(); - } - - if(trecur==1 || trecur==3){ - printf("\n------------Test recur---------------\n"); - test_recur(); - } + icalproperty_free(p); +} - if(trecur==1 || trecur==4){ - printf("\n------------Test parameter bug---------\n"); - test_recur_parameter_bug(); - } - if(trecur==1 || trecur==5){ - printf("\n------------Test Array Expansion---------\n"); - test_expand_recurrence(); - } +void test_x_property() +{ + icalproperty *p; + p= icalproperty_new_from_string( + "X-LIC-PROPERTY: This is a note"); + if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p)); - if(tspan==1 || tspan==2){ - printf("\n------------Test FBlist------------\n"); - test_fblist(); - } - - if(tspan==1 || tspan==3){ - printf("\n------------Test Overlaps------------\n"); - test_overlaps(); - } - - if(tspan==1 || tspan==4){ - printf("\n------------Test Span----------------\n"); - test_span(); - } - - if(tgauge == 1 || tgauge == 2){ - printf("\n------------Test Gauge SQL----------------\n"); - test_gauge_sql(); - } - - if(tgauge == 1 || tgauge == 3){ - printf("\n------------Test Gauge Compare--------------\n"); - test_gauge_compare(); - } - - if(tfile ==1 || tfile == 2){ - printf("\n------------Test File Set--------------\n"); - test_fileset(); - } + ok("x-property is correct kind",(icalproperty_isa(p) == ICAL_X_PROPERTY)); + is("icalproperty_get_x_name() works", + icalproperty_get_x_name(p),"X-LIC-PROPERTY"); + is("icalproperty_get_x() works", + icalproperty_get_x(p)," This is a note"); - if(tfile ==1 || tfile == 3){ - printf("\n------------Test File Locks--------------\n"); - test_file_locks(); - } + icalproperty_free(p); +} +void test_utcoffset() +{ + icalproperty *p; + p = icalproperty_new_from_string("TZOFFSETFROM:-001608"); + ok("parse TZOOFSETFROM:-001608", (p!=NULL)); - if(tmisc == 1 || tmisc == 2){ - printf("\n------------Test X Props and Params--------\n"); - test_x(); - } + if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p)); - if(tmisc == 1 || tmisc == 3){ - printf("\n------------Test Trigger ------------------\n"); - test_trigger(); - } + if (p) icalproperty_free(p); +} - if(tmisc == 1 || tmisc == 4){ +void test_attach() +{ + icalcomponent *c; - printf("\n------------Test Restriction---------------\n"); - test_restriction(); - } + static const char test_icalcomp_str[] = +"BEGIN:VEVENT\n" +"ATTACH:CID:jsmith.part3.960817T083000.xyzMain@host1.com\n" +"ATTACH:FMTTYPE=application/postscript;ftp://xyzCorp.com/pub/reports/r-960812.ps\n" +"END:VEVENT\n"; - if(tmisc == 1 || tmisc == 5){ + c = icalparser_parse_string ((char *) test_icalcomp_str); + ok("parse simple attachment", (c != NULL)); - printf("\n------------Test RDATE---------------\n"); - test_rdate(); - } + if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c)); - if(tmisc == 1 || tmisc == 6){ + if (c) icalcomponent_free(c); +} - printf("\n------------Test language binding---------------\n"); - test_langbind(); - } +void test_vcal(void) +{ + VObject *vcal = 0; + icalcomponent *comp; + char* file = "../../test-data/user-cal.vcf"; - if(tmisc == 1 || tmisc == 7){ + vcal = Parse_MIME_FromFileName(file); + + ok("Parsing ../../test-data/user-cal.vcf", (vcal != 0)); - printf("\n------------Test property parser---------------\n"); - test_property_parse(); - } + comp = icalvcal_convert(vcal); - if(tmisc == 1 || tmisc == 8){ - printf("\n------------Test Action ------------------\n"); - test_action(); - } + ok("Converting to ical component", (comp != 0)); + + if (VERBOSE && comp) + printf("%s\n",icalcomponent_as_ical_string(comp)); - if(tmisc == 1 || tmisc == 9){ - printf("\n------------Test Value Parameter ------------------\n"); - test_value_parameter(); - } + if (comp) icalcomponent_free(comp); + if (vcal) deleteVObject(vcal); +} - if(tmisc == 1 || tmisc == 10){ - printf("\n------------Test X property ------------------\n"); - test_x_property(); +int main(int argc, char *argv[]) +{ + int c; + extern char *optarg; + extern int optopt; + int errflg=0; + char* program_name = strrchr(argv[0],'/'); + int do_test = 0; + int do_header = 0; + + set_zone_directory("../../zoneinfo"); + putenv("TZ="); + + test_start(0); + + +#ifndef WIN32 + while ((c = getopt(argc, argv, "lvq")) != -1) { + switch (c) { + case 'v': { + VERBOSE = 1; + break; + } + case 'q': { + QUIET = 1; + break; + } + case 'l': { + do_header = 1;; + } + case '?': { + errflg++; + } + } + } + if (optind < argc) { + do_test = atoi(argv[argc-1]); } +#else + if (argc>1) + do_test = atoi(argv[2]); - - if(tbasic == 1 || tbasic == 2){ - printf("\n------------Test Values---------------\n"); - test_values(); - } +#endif - if(tbasic == 1 || tbasic == 3){ - printf("\n------------Test Parameters-----------\n"); - test_parameters(); - } - - if(tbasic == 1 || tbasic == 4){ - printf("\n------------Test Properties-----------\n"); - test_properties(); - } + + test_run("Test time parser functions", test_time_parser, do_test, do_header); + test_run("Test time", test_time, do_test, do_header); + test_run("Test day of Year", test_doy, do_test, do_header); + test_run("Test duration", test_duration, do_test, do_header); + test_run("Test period", test_period, do_test, do_header); + test_run("Test DTSTART", test_dtstart, do_test, do_header); + test_run("Test day of year of week start", test_start_of_week, do_test, do_header); + test_run("Test recur parser", test_recur_parser, do_test, do_header); + test_run("Test recur", test_recur, do_test, do_header); + test_run("Test Recurring Events File", test_recur_file, do_test, do_header); + test_run("Test parameter bug", test_recur_parameter_bug, do_test, do_header); + test_run("Test Array Expansion", test_expand_recurrence, do_test, do_header); + test_run("Test Free/Busy lists", test_fblist, do_test, do_header); + test_run("Test Overlaps", test_overlaps, do_test, do_header); + + test_run("Test Span", test_icalcomponent_get_span, do_test, do_header); + test_run("Test Gauge SQL", test_gauge_sql, do_test, do_header); + test_run("Test Gauge Compare", test_gauge_compare, do_test, do_header); + test_run("Test File Set", test_fileset, do_test, do_header); + test_run("Test File Set (Extended)", test_fileset_extended, do_test, do_header); + test_run("Test Dir Set", test_dirset, do_test, do_header); + test_run("Test Dir Set (Extended)", test_dirset_extended, do_test, do_header); + + test_run("Test File Locks", test_file_locks, do_test, do_header); + test_run("Test X Props and Params", test_x, do_test, do_header); + test_run("Test Trigger", test_trigger, do_test, do_header); + test_run("Test Restriction", test_restriction, do_test, do_header); + test_run("Test RDATE", test_rdate, do_test, do_header); + test_run("Test language binding", test_langbind, do_test, do_header); + test_run("Test property parser", test_property_parse, do_test, do_header); + test_run("Test Action", test_action, do_test, do_header); + test_run("Test Value Parameter", test_value_parameter, do_test, do_header); + test_run("Test X property", test_x_property, do_test, do_header); + test_run("Test X parameter", test_x_parameter, do_test, do_header); + test_run("Test request status", test_requeststat, do_test, do_header); + test_run("Test UTC-OFFSET", test_utcoffset, do_test, do_header); + test_run("Test Values", test_values, do_test, do_header); + test_run("Test Parameters", test_parameters, do_test, do_header); + test_run("Test Properties", test_properties, do_test, do_header); + test_run("Test Components", test_components, do_test, do_header); + test_run("Test Convenience", test_convenience, do_test, do_header); + test_run("Test classify ", test_classify, do_test, do_header); + test_run("Test Iterators", test_iterators, do_test, do_header); + test_run("Test strings", test_strings, do_test, do_header); + test_run("Test Compare", test_compare, do_test, do_header); + test_run("Create Simple Component", create_simple_component, do_test, do_header); + test_run("Create Components", create_new_component, do_test, do_header); + test_run("Create Components with vaargs", create_new_component_with_va_args, do_test, do_header); + test_run("Test Memory", test_memory, do_test, do_header); + test_run("Test Attachment", test_attach, do_test, do_header); + test_run("Test icalcalendar", test_calendar, do_test, do_header); + test_run("Test Dirset", test_dirset, do_test, do_header); + test_run("Test vCal to iCal conversion", test_vcal, do_test, do_header); + test_run("Test UTF-8 Handling", test_utf8, do_test, do_header); + + /** OPTIONAL TESTS go here... **/ + +#ifdef WITH_CXX + test_run("Test C++ API", test_cxx, do_test, do_header); +#endif - if(tbasic == 1 || tbasic == 5){ - printf("\n------------Test Components ----------\n"); - test_components(); - } +#ifdef WITH_BDB + test_run("Test BDB Set", test_bdbset, do_test, do_header); +#endif - if(tmisc == 1){ - printf("\n------------Test Convenience ------------\n"); - test_convenience(); - - - printf("\n------------Test classify ---------------\n"); - test_classify(); - - - printf("\n------------Test Iterators-----------\n"); - test_iterators(); - - - printf("\n-----------Test request status-------\n"); - test_requeststat(); - - printf("\n------------Test strings---------------\n"); - test_strings(); - - printf("\n------------Test Compare---------------\n"); - test_compare(); - - printf("\n------------Create Components --------\n"); - create_new_component(); - - printf("\n----- Create Components with vaargs ---\n"); - create_new_component_with_va_args(); + icaltimezone_free_builtin_timezones(); + icalmemory_free_ring(); + free_zone_directory(); - printf("\n------------Test Memory---------------\n"); - test_memory(); - } + test_end(); return 0; } - diff --git a/libical/src/test/regression.h b/libical/src/test/regression.h new file mode 100644 index 0000000000..633cd3295d --- /dev/null +++ b/libical/src/test/regression.h @@ -0,0 +1,53 @@ +#ifdef __cplusplus +extern "C" { +#endif + +extern int VERBOSE; +extern int QUIET; + +/* regression-component.c */ +void create_new_component(void); +void create_new_component_with_va_args(void); +void create_simple_component(void); +void test_icalcomponent_get_span(void); +void create_new_component_with_va_args(void); + +/* regression-classify.c */ +void test_classify(void); + +/* regression-recur.c */ +void test_recur_file(void); + +/* regression-cxx.c */ +void test_cxx(void); + +/* regression-storage.c */ +void test_fileset_extended(void); +void test_dirset_extended(void); +void test_bdbset(void); + +/* regression-utils.c */ +const char* ical_timet_string(const time_t t); +const char* ictt_as_string(struct icaltimetype t); +char* icaltime_as_ctime(struct icaltimetype t); + + +void _ok(char*name, int result, char*file, int linenum, char *test); +void _is(char* test_name, const char* str1, const char* str2, char *file, int linenum); +void _int_is(char* test_name, int i1, int i2, char *file, int linenum); +#define ok(TEST, EX) (_ok(TEST, EX, __FILE__, __LINE__, #EX)) +#define is(S1, S2, EX) (_is(S1, S2, EX, __FILE__, __LINE__)) +#define int_is(I1, I2, EX) (_int_is(I1, I2, EX, __FILE__, __LINE__)) +void test_header(char*title, int test_set); +void test_start(int); +void test_end(void); +void test_run(char *test_name, + void (*test_fcn)(void), + int do_test, int headeronly); + + + + +#ifdef __cplusplus +} +#endif diff --git a/libical/src/test/storage.c b/libical/src/test/storage.c index 2d8bc586f4..9c29d728af 100644 --- a/libical/src/test/storage.c +++ b/libical/src/test/storage.c @@ -1,6 +1,6 @@ /* -*- Mode: C -*- ====================================================================== - FILE: usecases.c + FILE: storage.c CREATOR: eric 03 April 1999 DESCRIPTION: @@ -36,11 +36,46 @@ #include "icalmemory.h" #include "icaldirset.h" #include "icalfileset.h" +#ifdef WITH_BDB4 +#include "icalbdbset.h" +#endif #include "icalerror.h" #include "icalrestriction.h" #include "icalcalendar.h" #define OUTPUT_FILE "filesetout.ics" +#define DATABASE "calendar.db" + +/* define sample calendar struct */ +struct calendar { + int ID; + int total_size; + + /* offsets */ + int total_size_offset; + int vcalendar_size_offset; + int vcalendar_offset; + int title_size_offset; + int title_offset; + + /* data */ + int vcalendar_size; + char *vcalendar; + + int title_size; + char *title; + +}; + +int vcalendar_init(struct calendar **cal, char *vcalendar, char *title); + +#ifdef WITH_BDB4 +int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey); +char * parse_vcalendar(const DBT *dbt) ; +#endif + +char * pack_calendar(struct calendar *cal, int size); +struct calendar * unpack_calendar(char *str, int size); char str[] = "BEGIN:VCALENDAR\n\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ @@ -104,7 +139,6 @@ END:VEVENT\n\ END:VCALENDAR\n\ "; - void test_fileset() { icalfileset *cout; @@ -151,14 +185,12 @@ void test_fileset() icalfileset_add_component(cout,clone); icalfileset_commit(cout); - icalfileset_free(cout); + icalset_free(cout); } - /* Print them out */ - cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); @@ -183,7 +215,7 @@ void test_fileset() /* Remove all of them */ - icalfileset_free(cout); + icalset_free(cout); cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); @@ -196,7 +228,7 @@ void test_fileset() icalfileset_remove_component(cout, itr); } - icalfileset_free(cout); + icalset_free(cout); /* Print them out again */ @@ -224,12 +256,393 @@ void test_fileset() } - icalfileset_free(cout); + icalset_free(cout); } +/* + In this example, we're storing a calendar with several components + under the reference id "calendar_7286" and retrieving records based + on title, "month_1" through "month_10". We use a number of the + "optional" arguments to specify secondary indices, sub-databases + (i.e. having multiple databases residing within a single Berkeley + DB file), and keys for storage and retrieval. +*/ + +#ifdef WITH_BDB4 +void test_bdbset() +{ + icalbdbset *cout; + int month = 0; + int count=0; + int num_components=0; + int szdata_len=0; + int ret=0; + char *subdb, *szdata, *szpacked_data; + char uid[255]; + struct icaltimetype start, end; + icalcomponent *c,*clone, *itr; + DB *dbp, *sdbp; + DBT key, data; + DBC *dbcp; + + struct calendar *cal; + int cal_size; + + start = icaltime_from_timet( time(0),0); + end = start; + end.hour++; + + /* Note: as per the Berkeley DB ref pages: + * + * The database argument is optional, and allows applications to + * have multiple databases in a single file. Although no database + * argument needs to be specified, it is an error to attempt to + * open a second database in a file that was not initially created + * using a database name. + * + */ + + subdb = "calendar_id"; + sdbp = 0; + + /* open database, using subdb */ + dbp = icalbdbset_database_open(DATABASE, subdb, DB_HASH); + sdbp = icalbdbset_secondary_open(dbp, + DATABASE, + "title", + get_title, + DB_HASH); + + c = icalparser_parse_string(str2); + assert(c != 0); + + /* Add data to the file */ + + for(month = 1; month < 10; month++){ + icalcomponent *event; + icalproperty *dtstart, *dtend, *location; + + /* retrieve data */ + cout = icalbdbset_new(dbp, sdbp, NULL); + assert(cout != 0); + + start.month = month; + end.month = month; + + clone = icalcomponent_new_clone(c); + assert(clone !=0); + event = icalcomponent_get_first_component(clone, + ICAL_VEVENT_COMPONENT); + assert(event != 0); + + dtstart = icalcomponent_get_first_property(event, + ICAL_DTSTART_PROPERTY); + assert(dtstart!=0); + icalproperty_set_dtstart(dtstart,start); + + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + assert(dtend!=0); + icalproperty_set_dtend(dtend,end); + + location = icalcomponent_get_first_property(event, ICAL_LOCATION_PROPERTY); + assert(location!=0); + +#if 0 + /* change the uid to include the month */ + sprintf(uid, "%s_%d", icalcomponent_get_uid(clone), month); + icalcomponent_set_uid(clone, uid); +#endif + + icalbdbset_add_component(cout,clone); + + /* commit changes */ + icalbdbset_commit(cout); + + num_components = icalcomponent_count_components(clone, ICAL_ANY_COMPONENT); + + icalset_free(cout); + + } + + /* try out the cursor operations */ + memset(&key, 0, sizeof(DBT)); + memset(&data, 0, sizeof(DBT)); + + ret = icalbdbset_acquire_cursor(dbp, &dbcp); + ret = icalbdbset_get_first(dbcp, &key, &data); + ret = icalbdbset_get_next(dbcp, &key, &data); + ret = icalbdbset_get_last(dbcp, &key, &data); + + /* Print them out */ + + for(month = 1, count=0; month < 10; month++){ + char *title; + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + cout = icalbdbset_new(dbp, sdbp, NULL); + assert(cout != 0); + + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + icalset_free(cout); + } + + /* close database */ + icalbdbset_database_close(dbp); + icalbdbset_database_close(sdbp); + + /* open database */ + dbp = icalbdbset_database_open(DATABASE, subdb, DB_HASH); + sdbp = icalbdbset_secondary_open(dbp, + DATABASE, + "title", + get_title, + DB_HASH); + + /* Remove all of them */ + for(month = 1; month < 10; month++){ + + cout = icalbdbset_new(dbp, sdbp, NULL); + assert(cout != 0); + + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalbdbset_remove_component(cout, itr); + } + + icalbdbset_commit(cout); + icalset_free(cout); + + } + + /* Print them out again */ + for(month = 1, count=0; month < 10; month++){ + char *title; + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + cout = icalbdbset_new(dbp, sdbp, NULL); + assert(cout != 0); + + for (itr = icalbdbset_get_first_component(cout); + itr != 0; + itr = icalbdbset_get_next_component(cout)){ + + icalcomponent *event; + icalproperty *dtstart, *dtend; + + count++; + + event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); + + dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); + dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); + + printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), + icalproperty_as_ical_string(dtend)); + + } + icalset_free(cout); + } +} + +/* get_title -- extracts a secondary key (the vcalendar) + * from a primary key/data pair */ + +/* just create a random title for now */ + +int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) +{ + icalcomponent *cl; + char title[255]; + + memset(skey, 0, sizeof(DBT)); + + cl = icalparser_parse_string((char *)pdata->data); + sprintf(title, "title_%s", icalcomponent_get_uid(cl)); + + skey->data = strdup(title); + skey->size = strlen(skey->data); + return (0); +} + +char * parse_vcalendar(const DBT *dbt) +{ + char *str; + struct calendar *cal; + + str = (char *)dbt->data; + cal = unpack_calendar(str, dbt->size); + + return cal->vcalendar; +} + +#endif + + +int vcalendar_init(struct calendar **rcal, char *vcalendar, char *title) +{ + int vcalendar_size, title_size, total_size; + struct calendar *cal; + + if(vcalendar) + vcalendar_size = strlen(vcalendar); + else { + vcalendar = ""; + vcalendar_size = strlen(vcalendar); + } + + if(title) + title_size = strlen(title); + else { + title = ""; + title_size = strlen(title); + } + + total_size = sizeof(struct calendar) + vcalendar_size + title_size; + + if((cal = (struct calendar *)malloc(total_size))==NULL) + return 0; + memset(cal, 0, total_size); + + /* offsets */ + cal->total_size_offset = sizeof(int); + cal->vcalendar_size_offset = (sizeof(int) * 7); + cal->vcalendar_offset = cal->vcalendar_size_offset + sizeof(int); + cal->title_size_offset = cal->vcalendar_offset + vcalendar_size; + cal->title_offset = cal->title_size_offset + sizeof(int); + + /* sizes */ + cal->total_size = total_size; + cal->vcalendar_size = vcalendar_size; + cal->title_size = title_size; + + if (vcalendar && *vcalendar) + cal->vcalendar = strdup(vcalendar); + + if (title && *title) + cal->title = strdup(title); + + *rcal = cal; + + return 0; +} + +char * pack_calendar(struct calendar *cal, int size) +{ + char *str; + + if((str = (char *)malloc(sizeof(char) * size))==NULL) + return 0; + + /* ID */ + memcpy(str, &cal->ID, sizeof(cal->ID)); + + /* total_size */ + memcpy(str + cal->total_size_offset, + &cal->total_size, + sizeof(cal->total_size)); + + /* vcalendar_size */ + memcpy(str + cal->vcalendar_size_offset, + &cal->vcalendar_size, + sizeof(cal->vcalendar_size)); + + /* vcalendar */ + memcpy(str + cal->vcalendar_offset, + cal->vcalendar, + cal->vcalendar_size); + + /* title_size */ + memcpy(str + cal->title_size_offset, + &cal->title_size, + sizeof(cal->title_size)); + + /* title */ + memcpy(str + cal->title_offset, + cal->title, + cal->title_size); + + return str; +} + +struct calendar * unpack_calendar(char *str, int size) +{ + struct calendar *cal; + if((cal = (struct calendar *) malloc(size))==NULL) + return 0; + memset(cal, 0, size); + + /* offsets */ + cal->total_size_offset = sizeof(int); + cal->vcalendar_size_offset = (sizeof(int) * 7); + cal->vcalendar_offset = cal->vcalendar_size_offset + sizeof(int); + + /* ID */ + memcpy(&cal->ID, str, sizeof(cal->ID)); + + /* total_size */ + memcpy(&cal->total_size, + str + cal->total_size_offset, + sizeof(cal->total_size)); + + /* vcalendar_size */ + memcpy(&cal->vcalendar_size, + str + cal->vcalendar_size_offset, + sizeof(cal->vcalendar_size)); + + if((cal->vcalendar = (char *)malloc(sizeof(char) * + cal->vcalendar_size))==NULL) + return 0; + + /* vcalendar */ + memcpy(cal->vcalendar, + (char *)(str + cal->vcalendar_offset), + cal->vcalendar_size); + + cal->title_size_offset = cal->vcalendar_offset + cal->vcalendar_size; + cal->title_offset = cal->title_size_offset + sizeof(int); + + /* title_size */ + memcpy(&cal->title_size, + str + cal->title_size_offset, + sizeof(cal->title_size)); + + if((cal->title = (char *)malloc(sizeof(char) * + cal->title_size))==NULL) + return 0; + + /* title*/ + memcpy(cal->title, + (char *)(str + cal->title_offset), + cal->title_size); + + return cal; +} int test_dirset() { @@ -358,7 +771,7 @@ int test_dirset() } - icaldirset_free(s2); + icalset_free(s2); #endif @@ -383,7 +796,7 @@ int test_dirset() } - icaldirset_free(s); + icalset_free(s); return 0; } @@ -395,7 +808,7 @@ void test_calendar() icaldirset *s; icalcalendar* calendar = icalcalendar_new("calendar"); icalerrorenum error; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); + struct icaltimetype atime = icaltime_null_time(); comp = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, @@ -434,22 +847,23 @@ void test_calendar() } #endif - int main(int argc, char *argv[]) { -/* printf("\n------------Test File Set---------------\n"); - test_fileset(); */ + printf("\n------------Test File Set---------------\n"); + test_fileset(); printf("\n------------Test Dir Set---------------\n"); test_dirset(); -#if 0 - +#ifdef WITH_BDB4 + printf("\n------------Test BerkeleyDB Set---------------\n"); + test_bdbset(); +#endif +#if 0 printf("\n------------Test Calendar---------------\n"); test_calendar(); - #endif return 0; diff --git a/libical/src/test/stow.c b/libical/src/test/stow.c index e676c677f3..01abea4f75 100644 --- a/libical/src/test/stow.c +++ b/libical/src/test/stow.c @@ -39,9 +39,7 @@ #include <ctype.h> /* for tolower */ #include "ical.h" -#include "icalcalendar.h" -#include "icalfileset.h" -#include "icalmime.h" +#include "icalss.h" char* program_name; #define TMPSIZE 2048 @@ -180,7 +178,7 @@ icalcomponent* get_first_real_component(icalcomponent *comp) -char* make_mime(char* to, const char* from, const char* subject, +char* make_mime(const char* to, const char* from, const char* subject, const char* text_message, const char* method, const char* ical_message) { @@ -250,13 +248,20 @@ void return_failure(icalcomponent* comp, char* message, { char* local_attendee = opt->calid; FILE* p; + const char *org_addr; icalcomponent *inner = get_first_real_component(comp); icalproperty *organizer_prop = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); const char *organizer = icalproperty_get_organizer(organizer_prop); - organizer += 7; + org_addr = strchr(organizer,':'); + + if(org_addr != 0){ + org_addr++; /* Skip the ';' */ + } else { + org_addr = organizer; + } if (opt->errors == ERRORS_TO_ORGANIZER){ p = popen(SENDMAIL,"w"); @@ -271,7 +276,7 @@ void return_failure(icalcomponent* comp, char* message, exit(1); } - fputs(make_mime(organizer, local_attendee, "iMIP error", + fputs(make_mime(org_addr, local_attendee, "iMIP error", message, "reply", icalcomponent_as_ical_string(comp)),p); @@ -380,6 +385,17 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, int errors = 0; icalproperty *p; int found_attendee = 0; + struct icalreqstattype rs; + + rs.code = ICAL_UNKNOWN_STATUS; + rs.desc = 0; + rs.debug = 0; + + /*{ + icalrequeststatus code; + const char* desc; + const char* debug; + };*/ *return_status = 0; @@ -401,6 +417,8 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, strcpy(static_component_error_str, "Root component is not a VCALENDAR"); component_error_str = static_component_error_str; + rs.code = ICAL_3_11_MISSREQCOMP_STATUS; + break; } @@ -410,8 +428,9 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, if (icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY) == 0) { strcpy(static_component_error_str, - "Component does not have a METHOD property"); + "The component you sent did not have a METHOD property"); component_error_str = static_component_error_str; + rs.code = ICAL_3_11_MISSREQCOMP_STATUS; break; } @@ -421,8 +440,8 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, /* Check that the compopnent has an organizer */ if(icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY) == 0){ fprintf(stderr,"%s: fatal. Component does not have an ORGANIZER property\n",program_name); - - exit(1); + rs.code = ICAL_3_11_MISSREQCOMP_STATUS; + break; } @@ -444,7 +463,6 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, if (found_attendee == 0){ struct icalreqstattype rs; - char* rs_string; memset(static_component_error_str,0,PATH_MAX); snprintf(static_component_error_str,PATH_MAX, @@ -453,11 +471,6 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, component_error_str = static_component_error_str; rs.code = ICAL_3_7_INVCU_STATUS; - rs.desc = 0; - rs.debug = component_error_str; - rs_string = icalreqstattype_as_string(rs); - - *return_status = icalproperty_new_requeststatus(rs_string); break; } @@ -480,6 +493,10 @@ char* check_component(icalcomponent* comp, icalproperty **return_status, } while(0); + if(rs.code != ICAL_UNKNOWN_STATUS){ + *return_status = icalproperty_new_requeststatus(rs); + } + return component_error_str; } @@ -638,35 +655,32 @@ void get_options(int argc, char* argv[], struct options_struct *opt) p = strrchr(facspath,'/'); - if (p == 0){ - fprintf(stderr,"%s: Invalid calendar filename \"%s\"", - program_name,facspath); - exit(1); - } - - *p='\0'; - - type = test_file(facspath); - - errno = 0; - if (type == NO_FILE){ - - if(mkdir(facspath,0775) != 0){ - fprintf(stderr, - "%s: Failed to create calendar directory %s: %s\n", - program_name,facspath, strerror(errno)); - exit(1); - } else { - fprintf(stderr,"%s: Creating calendar directory %s\n", - program_name,facspath); - } - - } else if(type==REGULAR || type == ERROR){ - fprintf(stderr,"%s: Cannot create calendar directory %s\n", - program_name,facspath); - exit(1); - } - } + if (p != 0){ + /* Use some other directory */ + *p='\0'; + + type = test_file(facspath); + + errno = 0; + if (type == NO_FILE){ + + if(mkdir(facspath,0775) != 0){ + fprintf(stderr, + "%s: Failed to create calendar directory %s: %s\n", + program_name,facspath, strerror(errno)); + exit(1); + } else { + fprintf(stderr,"%s: Creating calendar directory %s\n", + program_name,facspath); + } + + } else if(type==REGULAR || type == ERROR){ + fprintf(stderr,"%s: Cannot create calendar directory %s\n", + program_name,facspath); + exit(1); + } + } + } } char* check_options(struct options_struct *opt) @@ -680,7 +694,7 @@ void store_component(icalcomponent *comp, struct options_struct *opt) if(opt->storage == STORE_IN_FILE){ - icalfileset *fs = icalfileset_new(opt->output_file); + icalset *fs = icalfileset_new(opt->output_file); if (fs == 0){ fprintf(stderr, @@ -706,7 +720,7 @@ void store_component(icalcomponent *comp, struct options_struct *opt) exit(1); } - icalfileset_free(fs); + icalset_free(fs); return; } else { @@ -726,6 +740,7 @@ icalcomponent* read_nonmime_component(struct options_struct *opt) FILE *stream; icalcomponent *comp; icalparser* parser = icalparser_new(); + icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); char* line; if(opt->input_source == INPUT_FROM_FILE){ @@ -746,7 +761,9 @@ icalcomponent* read_nonmime_component(struct options_struct *opt) do { line = icalparser_get_line(parser,read_stream); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); comp = icalparser_add_line(parser,line); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); if (comp != 0){ return comp; @@ -847,12 +864,17 @@ int main(int argc, char* argv[] ) comp = read_component(&opt); + /* If the component had any fatal errors, return an error message + to the organizer */ if ( (component_error_str = check_component(comp,&return_status,&opt)) != 0){ + reply = make_reply(comp,return_status,&opt); + return_failure(reply, component_error_str, &opt); icalcomponent_free(reply); exit(0); + } store_component(comp,&opt); diff --git a/libical/src/test/test_fileset.ics b/libical/src/test/test_fileset.ics new file mode 100644 index 0000000000..35799e4569 --- /dev/null +++ b/libical/src/test/test_fileset.ics @@ -0,0 +1,60 @@ +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000101T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000102T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000103T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000104T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000105T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000106T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000107T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000108T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000109T120000Z +END:VEVENT +END:VCALENDAR +BEGIN:VCALENDAR +METHOD:REQUEST +BEGIN:VEVENT +DTSTART:20000110T120000Z +END:VEVENT +END:VCALENDAR diff --git a/libical/src/test/testclassify.c b/libical/src/test/testclassify.c index 2c6c785dfa..649d80cc58 100644 --- a/libical/src/test/testclassify.c +++ b/libical/src/test/testclassify.c @@ -29,52 +29,29 @@ #include "ical.h" #include <errno.h> #include <string.h> /* For strerror */ -#include "icalset.h" -#include "icalclassify.h" - - -struct class_map { - ical_class class; - char *str; -} class_map[] = { - {ICAL_NO_CLASS,"No class"}, - {ICAL_PUBLISH_NEW_CLASS,"New Publish"}, - {ICAL_PUBLISH_UPDATE_CLASS,"Update Publish"}, - {ICAL_REQUEST_NEW_CLASS,"New request"}, - {ICAL_REQUEST_UPDATE_CLASS,"Update"}, - {ICAL_REQUEST_RESCHEDULE_CLASS,"Reschedule"}, - {ICAL_REQUEST_DELEGATE_CLASS,"Delegate"}, - {ICAL_REQUEST_NEW_ORGANIZER_CLASS,"New Organizer"}, - {ICAL_REQUEST_FORWARD_CLASS,"Forward"}, - {ICAL_REQUEST_STATUS_CLASS,"Status request"}, - {ICAL_REPLY_ACCEPT_CLASS,"Accept reply"}, - {ICAL_REPLY_DECLINE_CLASS,"Decline reply"}, - {ICAL_REPLY_CRASHER_ACCEPT_CLASS,"Crasher's accept reply"}, - {ICAL_REPLY_CRASHER_DECLINE_CLASS,"Crasher's decline reply"}, - {ICAL_ADD_INSTANCE_CLASS,"Add instance"}, - {ICAL_CANCEL_EVENT_CLASS,"Cancel event"}, - {ICAL_CANCEL_INSTANCE_CLASS,"Cancel instance"}, - {ICAL_CANCEL_ALL_CLASS,"Cancel all instances"}, - {ICAL_REFRESH_CLASS,"Refresh"}, - {ICAL_COUNTER_CLASS,"Counter"}, - {ICAL_DECLINECOUNTER_CLASS,"Decline counter"}, - {ICAL_MALFORMED_CLASS,"Malformed"}, - {ICAL_OBSOLETE_CLASS,"Obsolete"}, - {ICAL_MISSEQUENCED_CLASS,"Missequenced"}, - {ICAL_UNKNOWN_CLASS,"Unknown"} -}; - -char* find_class_string(ical_class class) -{ - int i; +#include "icalss.h" - for (i = 0;class_map[i].class != ICAL_UNKNOWN_CLASS;i++){ - if (class_map[i].class == class){ - return class_map[i].str; - } +/* Get a note about the purpose of the property*/ +const char* get_note(icalcomponent *c) +{ + icalproperty *p; + const char* note = 0; + + if(c != 0){ + for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY); + p!= 0; + p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){ + if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){ + note = icalproperty_get_x(p); + } + } + } + + if(note == 0){ + note = "None"; } - - return "Unknown"; + + return note; } @@ -83,71 +60,66 @@ int main(int argc, char* argv[]) icalcomponent *c; int i=0; - icalset* f = icalset_new_file("../../test-data/incoming.ics"); + /* Open up the two storage files, one for the incomming components, + one for the calendar */ + icalset* incoming = icalset_new_file("../../test-data/incoming.ics"); icalset* cal = icalset_new_file("../../test-data/calendar.ics"); - assert(f!= 0); + assert(incoming!= 0); assert(cal!=0); - - /* Foreach incoming message */ - for(c=icalset_get_first_component(f);c!=0; - c=icalset_get_next_component(f)){ + /* Iterate through all of the incoming components */ + for(c=icalset_get_first_component(incoming);c!=0; + c=icalset_get_next_component(incoming)){ - ical_class class; - icalcomponent *match; - icalcomponent *inner = icalcomponent_get_first_real_component(c); - icalcomponent *p; - const char *this_uid; - const char *i_x_note=0; - const char *c_x_note=0; + icalproperty_xlicclass class; + icalcomponent *match = 0; + const char* this_uid; i++; - if(inner == 0){ - continue; - } - - p = icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY); - this_uid = icalproperty_get_uid(p); - - assert(this_uid != 0); - - /* Find a booked component that is matched to the incoming - message, based on the incoming component's UID, SEQUENCE - and RECURRENCE-ID*/ - - match = icalset_fetch(cal,this_uid); - + /* 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 */ + if(icalcomponent_count_errors(c) != 0){ + 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,"A@example.com"); - for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY); - p!= 0; - p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){ - if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){ - i_x_note = icalproperty_get_x(p); - } - } - - - if(i_x_note == 0){ - i_x_note = "None"; - } - - for(p = icalcomponent_get_first_property(match,ICAL_X_PROPERTY); - p!= 0; - p = icalcomponent_get_next_property(match,ICAL_X_PROPERTY)){ - if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){ - c_x_note = icalproperty_get_x(p); - } - } - - if(c_x_note == 0){ - c_x_note = "None"; - } - - - printf("Test %d\nIncoming: %s\nMatched: %s\nClassification: %s\n\n",i,i_x_note,c_x_note,find_class_string(class)); + printf("Test %d\n\ +Incoming: %s\n\ +Matched: %s\n\ +Classification: %s\n\n", + i,get_note(c),get_note(match), + icalproperty_enum_to_string(class)); } return 0; diff --git a/libical/src/test/testmime.c b/libical/src/test/testmime.c index 5dfc3b7d31..cdb47d88dc 100644 --- a/libical/src/test/testmime.c +++ b/libical/src/test/testmime.c @@ -34,8 +34,7 @@ ======================================================================*/ #include "ical.h" -#include "sspm.h" -#include "icalmime.h" + #include <stdlib.h> /* For rand */ #include <string.h> /* for strrchr, strdup*/ #include <unistd.h> /* for getopt */ @@ -265,7 +264,7 @@ int main(int argc, char* argv[]) { d.pos = 0; d.str = buf; - c = icalmime_parse(string_line_generator,&d); + c = icalmime_parse(icalparser_string_line_generator,&d); printf("%s\n",icalcomponent_as_ical_string(c)); |