2 ======================================================================
4 CREATOR: eric 15 dec 2000
8 $Id: icallangbind.c,v 1.24 2008-01-02 20:07:31 dothebart Exp $
11 (C) COPYRIGHT 1999 Eric Busboom
12 http://www.softwarestudio.org
14 This package is free software and is provided "as is" without
15 express or implied warranty. It may be used, redistributed and/or
16 modified under the same terms as perl itself. ( Either the Artistic
19 ======================================================================*/
25 #include "icalcomponent.h"
26 #include "icalproperty.h"
27 #include "icalerror.h"
28 #include "icalmemory.h"
29 #include "icalvalue.h"
34 #define snprintf _snprintf
35 #define strcasecmp stricmp
38 int* icallangbind_new_array(int size){
39 int* p = (int*)malloc(size*sizeof(int));
40 return p; /* Caller handles failures */
43 void icallangbind_free_array(int* array){
47 int icallangbind_access_array(int* array, int index) {
51 /** Iterators to fetch parameters given property */
53 icalparameter* icallangbind_get_first_parameter(icalproperty *prop)
56 icalparameter_kind kind = ICAL_ANY_PARAMETER;
58 return icalproperty_get_first_parameter(prop,kind);
61 icalparameter* icallangbind_get_next_parameter(icalproperty *prop)
63 icalparameter_kind kind = ICAL_ANY_PARAMETER;
65 return icalproperty_get_next_parameter(prop,kind);
69 /** Like icalcomponent_get_first_component(), but takes a string for the
70 kind and can iterate over X properties as if each X name was a
73 icalproperty* icallangbind_get_first_property(icalcomponent *c,
76 icalproperty_kind kind = icalproperty_string_to_kind(prop);
79 if (kind == ICAL_NO_PROPERTY){
83 if(kind == ICAL_X_PROPERTY){
84 for(p = icalcomponent_get_first_property(c,kind);
86 p = icalcomponent_get_next_property(c,kind)){
88 if(strcmp(icalproperty_get_x_name(p),prop) == 0){
93 p=icalcomponent_get_first_property(c,kind);
102 icalproperty* icallangbind_get_next_property(icalcomponent *c,
105 icalproperty_kind kind = icalenum_string_to_property_kind(prop);
108 if (kind == ICAL_NO_PROPERTY){
112 if(kind == ICAL_X_PROPERTY){
113 for(p = icalcomponent_get_next_property(c,kind);
115 p = icalcomponent_get_next_property(c,kind)){
117 if(strcmp(icalproperty_get_x_name(p),prop) == 0){
122 p=icalcomponent_get_next_property(c,kind);
132 icalcomponent* icallangbind_get_first_component(icalcomponent *c,
135 icalcomponent_kind kind = icalenum_string_to_component_kind(comp);
137 if (kind == ICAL_NO_COMPONENT){
140 return icalcomponent_get_first_component(c,kind);
143 icalcomponent* icallangbind_get_next_component(icalcomponent *c,
146 icalcomponent_kind kind = icalenum_string_to_component_kind(comp);
148 if (kind == ICAL_NO_COMPONENT){
151 return icalcomponent_get_next_component(c,kind);
155 #define APPENDS(x) icalmemory_append_string(&buf, &buf_ptr, &buf_size, x);
157 #define APPENDC(x) icalmemory_append_char(&buf, &buf_ptr, &buf_size, x);
159 char* icallangbind_property_eval_string_r(icalproperty* prop, char* sep)
162 size_t buf_size = 1024;
165 icalparameter *param;
173 buf = icalmemory_new_buffer(buf_size);
178 value = icalproperty_get_value(prop);
183 APPENDS(icalproperty_kind_to_string(icalproperty_isa(prop)));
187 APPENDS(", 'value_type' ");
190 APPENDS(icalvalue_kind_to_string(icalvalue_isa(value)));
197 snprintf(tmp,25,"%p",prop);
203 switch (icalvalue_isa(value)){
205 case ICAL_ATTACH_VALUE:
206 case ICAL_BINARY_VALUE:
207 case ICAL_NO_VALUE: {
208 icalerror_set_errno(ICAL_INTERNAL_ERROR);
214 char* str = icalvalue_as_ical_string_r(value);
215 char* copy = (char*) malloc(strlen(str)+1);
221 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
224 /* Remove any newlines */
226 for(j=copy, i = str; *i != 0; j++,i++){
235 APPENDS(", 'value'");
251 for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER);
253 param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)){
255 char *copy = icalparameter_as_ical_string_r(param);
259 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
263 v = strchr(copy,'=');
293 const char* icallangbind_property_eval_string(icalproperty* prop, char* sep)
296 buf = icallangbind_property_eval_string_r(prop, sep);
297 icalmemory_add_tmp_buffer(buf);
303 int icallangbind_string_to_open_flag(const char* str)
305 if (strcmp(str,"r") == 0) {return O_RDONLY;}
306 else if (strcmp(str,"r+") == 0) {return O_RDWR;}
307 else if (strcmp(str,"w") == 0) {return O_WRONLY;}
308 else if (strcmp(str,"w+") == 0) {return O_RDWR|O_CREAT;}
309 else if (strcmp(str,"a") == 0) {return O_WRONLY|O_APPEND;}
314 char* icallangbind_quote_as_ical_r(const char* str)
316 size_t buf_size = 2 * strlen(str);
318 /* assume every char could be quoted */
319 char* buf = icalmemory_new_buffer(buf_size);
320 (void)icalvalue_encode_ical_string(str, buf, (int)buf_size);
326 const char* icallangbind_quote_as_ical(const char* str)
329 buf = icallangbind_quote_as_ical_r(str);
330 icalmemory_add_tmp_buffer(buf);