DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434

Classes for python binding to libical
(Indentation indicates inheritance)

	Component
		Event
		JournalEntry
		Todo
		FreeBusy
		Timezone
		Alarm
			AudioAlarm
			EmailAlarm
			ProcedureAlarm
			DisplayAlarm

	Property
		Attendee
		Organizer
		Status
		Error

	Time
	Period
	Date
	RecurrenceSet

	Timezone
	TimezonePhase

	Store
		FileStore
		DirStore
		CAPStore
		HeapStore
		MySQLStore



Component is the central class in the design. The component can be
though of as a container for child components and properties, or as
representation of a specific kind of iCal object. The first
interface offers general property and component accessors, and the
second treats some types of objects in a special way. 

The general interface offers simple manipulators for child property
and components, and it only works with immediate children. So, given
the Component:

	BEGIN:VCALENDAR
	METHOD:PUBLISH
	BEGIN:VEVENT
	BEGIN:VALARM
	COMMENT: An Alarm
	END:VALARM
	END:VEVENT
	END:VCALENDAR

A caller would have to descend three levels to access the COMMENT
property in the alarm, but only one to access the METHOD property. 

Libical is almost entirely dedicated to the general interface; it
includes all of the *get_first_*, *_next_next_*, *_add_* and *_remove_*
routines. 

The specific interface works with derived classes of Property and
Component. In this interface, the caller could get the COMMENT in the
alarm in the example in two steps. First the caller would ask the
Event object for its alarms, then then the caller would ask the first
Alarm object for its comment. 

The Specific interface is part of the
derived classes of Component. This interface names all of the types of 
properties and components that can be accessed from the derived
component type. 

In libical, the specific interface is primarily the "convenience
routines in icalcomponent.h, such as: 


	struct icaltimetype icalcomponent_get_dtend(icalcomponent* comp);
	void icalcomponent_set_dtend(icalcomponent* comp, struct icaltimetype v);

	void icalcomponent_set_duration(icalcomponent* comp, 
				struct icaldurationtype v);
	struct icaldurationtype icalcomponent_get_duration(icalcomponent* comp);

These routines are smarter and do more work than the general
interface. From the general interface, you can set the DTEND
property of a component by creating the property and adding it to a
component. But, if the component already has a DURATION property, then 
this is an error -- a component can't have both. 

icalcomponent_set_dtend determines if the component already has a
DURATION. If it does, it substracts the dtstart time from the new
dtend time and sets the duration to that. Otherwise, it creates aor
changes the DTEND. 

Also, icalcomponent_set_duration works the same regardless if the
component is a VCALENDAR or a VEVENT. If it is a VCALENDAR, the
routine descends into the VEVENT before making any changes. If it is
allready a VEVENT ( or VTODO or VJOURNAL ) the routine just makes the
changes. With icalcomponent_add_property, you need to do this check
yourself. 

( There should probably be a class between Component
and Event ,JournalEntry and Todo that names all of the properties and
components. Then Event, JournalEntry and Todo would remove the
accessors that did not apply to them. )
	
Parameters are accessed as dictionaries from Property or as attributes
of a derived class of Property. Both the names and the values of the
parameters are strings.

The Store hierarchy is a interface to various ways to store iCal
components. Each of these has the same interface as its corresponding
libical module:

	FileStore icalfileset	Store iCal components in a single file
	DirStore  icaldirset	Use multiple files, one per month of
				DTSTART
	CAPStore		Access components in a CAP server
	HeapStore		Components stored in memory
	MySQLStore		Components stored in a MySQL
				database. 

The only iCal value objects that will be implemented as Python classes 
are Time, Duration and Period. RecurrenceSet handles recurrence
rules. It replaces the properties RRULE, RDATE, EXRULE and EXDATE. 

(Not all of the libical modules are implemented )


How to Use the library
----------------------

The most common usecases will be something like this: 

1)Caller opens a Store object on a file, server or database. The
caller retrieves one or more component. Some of the components will be 
booked on the user's calendar. Other components will be messages that
other users have sent, like requests for meetings. 

2) The caller will use the Specific interface ( using methods specific 
to each property ) to example the component and decide what to do with 
it. 

3) Rarely, the caller will access the general interface to do things
that the specific interface has not implemented or cannot manage
well. 

4) Cller 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. 

	
Following are the methods in each of the classes. 

Component
	Construct from string
	output string in ical form
	
	Get a Property by type
	Get a set of Properties by type
	Remove a Property by reference

	Get a Component by type
	Get a set of Components by type
	Remove a Component  by reference

	Validate the component ( insert properties for errors )
	Count error properties
	Remove error properties
	Convert error properties into REQUEST-STATUS properties

Event, JournalEntry, Todo
	
	Construct from string
	output string in ical form

	There are get/set accessors for every property. These are
	listed in a later section


FreeBusy

	Construct from string
	Construct from arguments 
	output string in ical form

	Accessors for the following properties. See below for return
	types for these properties:

	method
	prodid
	attendee
	dtstamp
	dtstart
	freebusy
	organizer
	uid
	comment
	contact
	request-status
	url
	duration
	sequence

TimezonePhase

	Construct from string
	Construct from arguments 
	output string in ical form

	Accessors for the following properties. See below for return
	types for these properties:

	tzname
	offsetto
	offsetfrom
	rrule
	rdate
	comment

TimeZone

	Construct from string
	Construct from arguments 
	output string in ical form

	Accessors for the following properties. See below for return
	types for these properties:

	tzid
	last-modified
	tzurl
	standard (returns TimezonePhase)
	daylight (returns TimezonePhase)


Property
	
	Construct from string
	Construct from arguments
	output string in ical form

	Dictionary access to parameters

	Get/set value

Attendee

	Construct from string
	Construct from arguments
	output string in ical form

	Access to the following properties and parameters:
	cuid
	cutype
	member
	role
	rsvp
	delto
	delfrom
	sentby
	cn
	dir
	language

Organizer

	Access to the following properties:
	common_name
	dir
	sentby
	language


Time
Date
Period

	Same interfaces as libical modules. 

RecurenceSet
	I don't know -- need to think about it more. 

Store
	Similar methods to the icalset modules. 


RFC2445 Properties

This is a list of all of the RFC2445 properties and their associated
VALUE type.


Property	     Value
----------------------------
CALSCALE             TEXT		
METHOD		     TEXT
PRODID               TEXT
VERSION              TEXT
CATEGORIES           TEXT
CLASS                TEXT
COMMENT              TEXT
DESCRIPTION          TEXT
LOCATION             TEXT
PERCENT-COMPLETE     INTEGER
PRIORITY             INTEGER
RESOURCES            TEXT
STATUS               STATUS
SUMMARY              TEXT
COMPLETED            DATE-TIME
FREEBUSY             PERIOD
TRANSP               TEXT
TZNAME               TEXT
TZOFFSETFROM         UTC-OFFSET
TZOFFSETTO           UTC-OFFSET
TZURL                URI
TZID                 TEXT
ATTENDEE             CAL-ADDRESS
CONTACT              TEXT
ORGANIZER            CAL-ADDRESS
RELATED-TO           TEXT
URL                  URI
UID                  TEXT
EXRULE               RECUR
RRULE                RECUR
ACTION               TEXT
REPEAT               INTEGER
CREATED              DATE-TIME
DTSTAMP              DATE-TIME
LAST-MODIFIED        DATE-TIME
SEQUENCE             INTEGER
X         	     TEXT
REQUEST-STATUS       STRING             
ATTACH               URL, BINARY
GEO                  FLOAT
DTEND                DATE-TIME
DUE                  DATE-TIME
DTSTART              DATE-TIME
RECURRENCE-ID        DATE-TIME
EXDATE               DATE-TIME
RDATE                DATE-TIME, PERIOD
TRIGGER              DATE-TIME, DURATION
DURATION	     DURATION 

Some of the properties can appear multiple times in a component, other 
can appear only once. For a particular component, the number of times
a property can apper may also change with the METHOD property
associated with the component. This list shows which properties can
appear multiple times for some ( but not all ) combinations of
component type and METHOD value: 

ATTACH
ATTENDEE
CATEGORIES
COMMENT
CONTACT
EXDATE
EXRULE
FREEBUSY
NONE
RDATE
RELATEDTO
REQUESTSTATUS
RESOURCES
RRULE
TZNAME
TZURL
X          


This is a list of the value types and their associated python return
types. A lowercased return type is a python builtin, and an
uppercase-first-letter is a class in the library:


Value			Return Type
-----------------------------------
BINARY			file
BOOLEAN			number
CAL-ADDRESS		string
DATE			Time
DATE-TIME		Time
DURATION		Duration
FLOAT			number
GEO			tuple
INTEGER			number
METHOD			string
PERIOD			Period
RECUR			RecurrenceSet
TEXT			string
TIME			Time
URI			string
UTC-OFFSET		number
STATUS			string
X			string


I suspect that the Component class should use the three previous
tables to create the property accessor methods on the fly. If the
method generation system is general enough, we could also use it for
other classes, such as Alarm, Timezone, Attendee, Organizer and
Freebusy. 


Memory Handling
---------------

One of the things that made the perl binding to libcal difficult was
that if a Component (in perl) returns a reference to a child Component
(in perl), the child Component (in perl) will contain a reference to a
libical component. When the caller is done with the child component in
perl, the caller just drops it and lets perl reclaim the memory.

The destructor for Component needs to free the libical component that
it holds a reference to, but the child's libical component is still
being used by libical. So perl frees the libical component and later,
libical tries to reference freed memory.

The situation is actually a little better than that, because libical
will throw an error when you try to free a component that is still
attached to a parent. 

So, the perl library has to be able to determine when the destructor
should free a libical component or not. The perl library calls
icalcomponent_get_parent(), and if is it non-zero, it does not free
the component.

It is not hard, just more code, and something to watch out for.