1 /*====================================================================== 2 FILE: ical.i 3 4 (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of either: 8 9 The LGPL as published by the Free Software Foundation, version 10 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html 11 12 Or: 13 14 The Mozilla Public License Version 2.0. You may obtain a copy of 15 the License at https://www.mozilla.org/MPL/ 16 17 The original author is Eric Busboom 18 19 Contributions from: 20 Graham Davison (g.m.davison@computer.org) 21 ======================================================================*/ 22 23 %module Net__ICal__Libical 24 25 %{ 26 #include "ical.h" 27 28 #include <sys/types.h> /* for size_t */ 29 #include <time.h> 30 31 %} 32 33 34 35 typedef void icalcomponent; 36 typedef void icalproperty; 37 38 icalcomponent* icalparser_parse_string(char* str); 39 40 41 icalcomponent* icalcomponent_new(icalcomponent_kind kind); 42 icalcomponent* icalcomponent_new_clone(icalcomponent* component); 43 icalcomponent* icalcomponent_new_from_string(char* str); 44 45 char* icalcomponent_as_ical_string(icalcomponent* component); 46 47 void icalcomponent_free(icalcomponent* component); 48 int icalcomponent_count_errors(icalcomponent* component); 49 void icalcomponent_strip_errors(icalcomponent* component); 50 void icalcomponent_convert_errors(icalcomponent* component); 51 52 icalproperty* icalcomponent_get_current_property(icalcomponent* component); 53 54 icalproperty* icalcomponent_get_first_property(icalcomponent* component, 55 icalproperty_kind kind); 56 icalproperty* icalcomponent_get_next_property(icalcomponent* component, 57 icalproperty_kind kind); 58 59 icalcomponent* icalcomponent_get_current_component (icalcomponent* component); 60 61 icalcomponent* icalcomponent_get_first_component(icalcomponent* component, 62 icalcomponent_kind kind); 63 icalcomponent* icalcomponent_get_next_component(icalcomponent* component, 64 icalcomponent_kind kind); 65 66 void icalcomponent_add_property(icalcomponent* component, 67 icalproperty* property); 68 69 void icalcomponent_remove_property(icalcomponent* component, 70 icalproperty* property); 71 72 73 icalcomponent* icalcomponent_get_parent(icalcomponent* component); 74 75 icalcomponent_kind icalcomponent_isa(icalcomponent* component); 76 77 int icalrestriction_check(icalcomponent* comp); 78 79 80 /* actually returns icalproperty_kind */ 81 int icalproperty_string_to_kind(const char* string); 82 83 /* actually takes icalproperty_kind */ 84 icalproperty* icalproperty_new(int kind); 85 86 icalproperty* icalproperty_new_from_string(char* str); 87 88 char* icalproperty_as_ical_string(icalproperty *prop); 89 90 void icalproperty_set_parameter_from_string(icalproperty* prop, 91 const char* name, const char* value); 92 void icalproperty_set_value_from_string(icalproperty* prop,const char* value, const char * kind); 93 94 const char* icalproperty_get_value_as_string(icalproperty* prop); 95 const char* icalproperty_get_parameter_as_string(icalproperty* prop, 96 const char* name); 97 98 99 icalcomponent* icalproperty_get_parent(icalproperty* property); 100 101 typedef enum icalerrorenum { 102 103 ICAL_BADARG_ERROR, 104 ICAL_NEWFAILED_ERROR, 105 ICAL_MALFORMEDDATA_ERROR, 106 ICAL_PARSE_ERROR, 107 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */ 108 ICAL_FILE_ERROR, 109 ICAL_ALLOCATION_ERROR, 110 ICAL_USAGE_ERROR, 111 ICAL_NO_ERROR, 112 ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror()*/ 113 114 } icalerrorenum; 115 116 /* Make an individual error fatal or non-fatal. */ 117 typedef enum icalererorstate { 118 ICAL_ERROR_FATAL, /* Not fata */ 119 ICAL_ERROR_NONFATAL, /* Fatal */ 120 ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/ 121 ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */ 122 } icalerrorstate ; 123 124 void icalerror_set_error_state( icalerrorenum error, icalerrorstate); 125 icalerrorstate icalerror_get_error_state( icalerrorenum error); 126 127 128 const char* icalenum_property_kind_to_string(icalproperty_kind kind); 129 icalproperty_kind icalenum_string_to_property_kind(const char* string); 130 131 const char* icalenum_value_kind_to_string(icalvalue_kind kind); 132 /*icalvalue_kind icalenum_value_kind_by_prop(icalproperty_kind kind);*/ 133 134 const char* icalenum_parameter_kind_to_string(icalparameter_kind kind); 135 icalparameter_kind icalenum_string_to_parameter_kind(const char* string); 136 137 const char* icalenum_component_kind_to_string(icalcomponent_kind kind); 138 icalcomponent_kind icalenum_string_to_component_kind(const char* string); 139 140 icalvalue_kind icalenum_property_kind_to_value_kind(icalproperty_kind kind); 141 142 143 int* icallangbind_new_array(int size); 144 void icallangbind_free_array(int* array); 145 int icallangbind_access_array(int* array, int index); 146 int icalrecur_expand_recurrence(const char* rule, int start, 147 int count, int* array); 148 149 150 /* Iterate through properties and components using strings for the kind */ 151 icalproperty* icallangbind_get_first_property(icalcomponent *c, 152 const char* prop); 153 154 icalproperty* icallangbind_get_next_property(icalcomponent *c, 155 const char* prop); 156 157 icalcomponent* icallangbind_get_first_component(icalcomponent *c, 158 const char* comp); 159 160 icalcomponent* icallangbind_get_next_component(icalcomponent *c, 161 const char* comp); 162 163 164 /* Return a string that can be evaluated in perl or python to 165 generated a hash that holds the property's name, value and 166 parameters. Sep is the hash seperation string, "=>" for perl and 167 ":" for python */ 168 const char* icallangbind_property_eval_string(icalproperty* prop, const char* sep); 169 170 /*********************************************************************** 171 Time routines 172 ***********************************************************************/ 173 174 175 struct icaltimetype 176 { 177 int year; 178 int month; 179 int day; 180 int hour; 181 int minute; 182 int second; 183 184 int is_utc; /* 1-> time is in UTC timezone */ 185 186 int is_date; /* 1 -> interpret this as date. */ 187 188 const char* zone; /*Ptr to Olsen placename. Libical does not own mem*/ 189 }; 190 191 192 /* Convert seconds past UNIX epoch to a timetype*/ 193 struct icaltimetype icaltime_from_timet_with_zone(int v, int is_date, const char* tzid); 194 195 /* Return the time as seconds past the UNIX epoch */ 196 /* Normally, this returns a time_t, but SWIG tries to turn that type 197 into a pointer */ 198 int icaltime_as_timet(struct icaltimetype); 199 200 /* Return a string represention of the time, in RFC2445 format. The 201 string is owned by libical */ 202 char* icaltime_as_ical_string(struct icaltimetype tt); 203 204 /* create a time from an ISO format string */ 205 struct icaltimetype icaltime_from_string(const char* str); 206 207 /* Routines for handling timezones */ 208 /* Return the offset of the named zone as seconds. tt is a time 209 indicating the date for which you want the offset */ 210 int icaltime_utc_offset(struct icaltimetype tt, const char* tzid); 211 212 /* convert tt, of timezone tzid, into a utc time. Does nothing if the 213 time is already UTC. */ 214 struct icaltimetype icaltime_as_utc(struct icaltimetype tt, 215 const char* tzid); 216 217 /* convert tt, a time in UTC, into a time in timezone tzid */ 218 struct icaltimetype icaltime_as_zone(struct icaltimetype tt, 219 const char* tzid); 220 221 /* Return a null time, which indicates no time has been set. This time represent the beginning of the epoch */ 222 struct icaltimetype icaltime_null_time(void); 223 224 /* Return true of the time is null. */ 225 int icaltime_is_null_time(struct icaltimetype t); 226 227 /* Returns false if the time is clearly invalid, but is not null. This 228 is usually the result of creating a new time type buy not clearing 229 it, or setting one of the flags to an illegal value. */ 230 int icaltime_is_valid_time(struct icaltimetype t); 231 232 /* Reset all of the time components to be in their normal ranges. For 233 instance, given a time with minutes=70, the minutes will be reduces 234 to 10, and the hour incremented. This allows the caller to do 235 arithmetic on times without worrying about overflow or 236 underflow. */ 237 struct icaltimetype icaltime_normalize(struct icaltimetype t); 238 239 /* Return the day of the year of the given time */ 240 short icaltime_day_of_year(struct icaltimetype t); 241 242 /* Create a new time, given a day of year and a year. */ 243 struct icaltimetype icaltime_from_day_of_year(short doy, short year); 244 245 /* Return the day of the week of the given time. Sunday is 0 */ 246 short icaltime_day_of_week(struct icaltimetype t); 247 248 /* Return the day of the year for the first day of the week that the 249 given time is within. */ 250 short icaltime_start_doy_week(struct icaltimetype t, int fdow); 251 252 /* Return a string with the time represented in the same format as ctime(). THe string is owned by libical */ 253 char* icaltime_as_ctime(struct icaltimetype); 254 255 /* Return the week number for the week the given time is within */ 256 short icaltime_week_number(struct icaltimetype t); 257 258 /* Return -1, 0, or 1 to indicate that a<b, a==b or a>b */ 259 int icaltime_compare(struct icaltimetype a,struct icaltimetype b); 260 261 /* like icaltime_compare, but only use the date parts. */ 262 int icaltime_compare_date_only(struct icaltimetype a, struct icaltimetype b); 263 264 /* Return the number of days in the given month */ 265 short icaltime_days_in_month(short month,short year); 266 267 268 /*********************************************************************** 269 Duration Routines 270 ***********************************************************************/ 271 272 273 struct icaldurationtype 274 { 275 int is_neg; 276 unsigned int days; 277 unsigned int weeks; 278 unsigned int hours; 279 unsigned int minutes; 280 unsigned int seconds; 281 }; 282 283 struct icaldurationtype icaldurationtype_from_int(int t); 284 struct icaldurationtype icaldurationtype_from_string(const char*); 285 int icaldurationtype_as_int(struct icaldurationtype duration); 286 char* icaldurationtype_as_ical_string(struct icaldurationtype d); 287 struct icaldurationtype icaldurationtype_null_duration(); 288 int icaldurationtype_is_null_duration(struct icaldurationtype d); 289 290 struct icaltimetype icaltime_add(struct icaltimetype t, 291 struct icaldurationtype d); 292 293 struct icaldurationtype icaltime_subtract(struct icaltimetype t1, 294 struct icaltimetype t2); 295 296 297 /*********************************************************************** 298 Period Routines 299 ***********************************************************************/ 300 301 302 struct icalperiodtype 303 { 304 struct icaltimetype start; 305 struct icaltimetype end; 306 struct icaldurationtype duration; 307 }; 308 309 struct icalperiodtype icalperiodtype_from_string (const char* str); 310 311 const char* icalperiodtype_as_ical_string(struct icalperiodtype p); 312 struct icalperiodtype icalperiodtype_null_period(); 313 int icalperiodtype_is_null_period(struct icalperiodtype p); 314 int icalperiodtype_is_valid_period(struct icalperiodtype p); 315