Diffstat (limited to 'libical/src/libical/icaltypes.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libical/icaltypes.c | 140 |
1 files changed, 23 insertions, 117 deletions
diff --git a/libical/src/libical/icaltypes.c b/libical/src/libical/icaltypes.c index 8c67deb..19719f8 100644 --- a/libical/src/libical/icaltypes.c +++ b/libical/src/libical/icaltypes.c | |||
@@ -32,141 +32,47 @@ | |||
32 | #include "icalmemory.h" | 32 | #include "icalmemory.h" |
33 | #include <stdlib.h> /* for malloc and abs() */ | 33 | #include <stdlib.h> /* for malloc and abs() */ |
34 | #include <errno.h> /* for errno */ | 34 | #include <errno.h> /* for errno */ |
35 | #include <string.h> /* for icalmemory_strdup */ | 35 | #include <string.h> /* for icalmemory_strdup */ |
36 | #include <assert.h> | 36 | #include <assert.h> |
37 | 37 | ||
38 | int snprintf(char *str, size_t n, char const *fmt, ...); | 38 | #ifdef WIN32 |
39 | #define snprintf _snprintf | ||
40 | #define strcasecmp stricmp | ||
41 | #endif | ||
39 | 42 | ||
40 | #define TEMP_MAX 1024 | 43 | #define TEMP_MAX 1024 |
41 | 44 | ||
42 | void* | ||
43 | icalattachtype_get_data (struct icalattachtype* type); | ||
44 | |||
45 | struct icalattachtype* | ||
46 | icalattachtype_new() | ||
47 | { | ||
48 | struct icalattachtype* v; | ||
49 | |||
50 | if ( ( v = (struct icalattachtype*) | ||
51 | malloc(sizeof(struct icalattachtype))) == 0) { | ||
52 | errno = ENOMEM; | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | v->refcount = 1; | ||
57 | |||
58 | v->binary = 0; | ||
59 | v->owns_binary = 0; | ||
60 | v->base64 = 0; | ||
61 | //fprintf(stderr,"setting base 64 to 0 \n"); | ||
62 | |||
63 | v->owns_base64 = 0; | ||
64 | |||
65 | v->url = 0; | ||
66 | |||
67 | return v; | ||
68 | } | ||
69 | |||
70 | |||
71 | void | ||
72 | icalattachtype_free(struct icalattachtype* v) | ||
73 | { | ||
74 | icalerror_check_arg( (v!=0),"v"); | ||
75 | |||
76 | v->refcount--; | ||
77 | 45 | ||
78 | if (v->refcount <= 0){ | 46 | int icaltriggertype_is_null_trigger(struct icaltriggertype tr) |
79 | |||
80 | if (v->base64 != 0 && v->owns_base64 != 0){ | ||
81 | int val = v->base64 ; | ||
82 | if ( val < 255 ) { | ||
83 | fprintf(stderr,"Possible error in attachment processing (%d)\nPocssible solution: Remove attachment from file.\n",val ); | ||
84 | } | ||
85 | free(v->base64); | ||
86 | } | ||
87 | |||
88 | if (v->binary != 0 && v->owns_binary != 0){ | ||
89 | free(v->binary); | ||
90 | } | ||
91 | |||
92 | if (v->url != 0){ | ||
93 | free(v->url); | ||
94 | } | ||
95 | |||
96 | free(v); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | void icalattachtype_add_reference(struct icalattachtype* v) | ||
101 | { | ||
102 | icalerror_check_arg( (v!=0),"v"); | ||
103 | v->refcount++; | ||
104 | } | ||
105 | |||
106 | void icalattachtype_set_url(struct icalattachtype* v, char* url) | ||
107 | { | ||
108 | icalerror_check_arg( (v!=0),"v"); | ||
109 | |||
110 | if (v->url != 0){ | ||
111 | free (v->url); | ||
112 | } | ||
113 | |||
114 | v->url = icalmemory_strdup(url); | ||
115 | |||
116 | /* HACK This routine should do something if icalmemory_strdup returns NULL */ | ||
117 | |||
118 | } | ||
119 | |||
120 | char* icalattachtype_get_url(struct icalattachtype* v) | ||
121 | { | 47 | { |
122 | icalerror_check_arg( (v!=0),"v"); | 48 | if(icaltime_is_null_time(tr.time) && |
123 | return v->url; | 49 | icaldurationtype_is_null_duration(tr.duration)){ |
50 | return 1; | ||
124 | } | 51 | } |
125 | 52 | ||
126 | void icalattachtype_set_base64(struct icalattachtype* v, char* base64, | 53 | return 0; |
127 | int owns) | ||
128 | { | ||
129 | //fprintf(stderr,"1setbase64 %d \n", base64 ); | ||
130 | icalerror_check_arg( (v!=0),"v"); | ||
131 | //fprintf(stderr,"setbase64 %d \n", base64 ); | ||
132 | v->base64 = base64; | ||
133 | v->owns_base64 = !(owns != 0 ); | ||
134 | |||
135 | } | 54 | } |
136 | 55 | ||
137 | char* icalattachtype_get_base64(struct icalattachtype* v) | 56 | int icaltriggertype_is_bad_trigger(struct icaltriggertype tr) |
138 | { | 57 | { |
139 | icalerror_check_arg( (v!=0),"v"); | 58 | if(icaldurationtype_is_bad_duration(tr.duration)){ |
140 | return v->base64; | 59 | return 1; |
141 | } | 60 | } |
142 | 61 | ||
143 | void icalattachtype_set_binary(struct icalattachtype* v, char* binary, | 62 | return 0; |
144 | int owns) | ||
145 | { | ||
146 | icalerror_check_arg( (v!=0),"v"); | ||
147 | |||
148 | v->binary = binary; | ||
149 | v->owns_binary = !(owns != 0 ); | ||
150 | |||
151 | } | 63 | } |
152 | 64 | ||
153 | void* icalattachtype_get_binary(struct icalattachtype* v) | 65 | struct icaltriggertype icaltriggertype_from_int(const int reltime) |
154 | { | 66 | { |
155 | icalerror_check_arg( (v!=0),"v"); | 67 | struct icaltriggertype tr; |
156 | return v->binary; | ||
157 | } | ||
158 | 68 | ||
159 | int icaltriggertype_is_null_trigger(struct icaltriggertype tr) | 69 | tr.time= icaltime_null_time(); |
160 | { | 70 | tr.duration = icaldurationtype_from_int(reltime); |
161 | if(icaltime_is_null_time(tr.time) && | ||
162 | icaldurationtype_is_null_duration(tr.duration)){ | ||
163 | return 1; | ||
164 | } | ||
165 | 71 | ||
166 | return 0; | 72 | return tr; |
167 | } | 73 | } |
168 | 74 | ||
169 | struct icaltriggertype icaltriggertype_from_string(const char* str) | 75 | struct icaltriggertype icaltriggertype_from_string(const char* str) |
170 | { | 76 | { |
171 | 77 | ||
172 | 78 | ||
@@ -178,54 +84,54 @@ struct icaltriggertype icaltriggertype_from_string(const char* str) | |||
178 | tr.duration = icaldurationtype_from_int(0); | 84 | tr.duration = icaldurationtype_from_int(0); |
179 | 85 | ||
180 | null_tr = tr; | 86 | null_tr = tr; |
181 | 87 | ||
182 | if(str == 0) goto error; | 88 | if(str == 0) goto error; |
183 | 89 | ||
184 | /* Surpress errors so a failure in icaltime_from_string() does not cause an abort */ | 90 | /* Suppress errors so a failure in icaltime_from_string() does not cause an abort */ |
185 | es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); | 91 | es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); |
186 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); | 92 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); |
187 | e = icalerrno; | 93 | e = icalerrno; |
188 | icalerror_set_errno(ICAL_NO_ERROR); | 94 | icalerror_set_errno(ICAL_NO_ERROR); |
189 | 95 | ||
190 | tr.time = icaltime_from_string(str); | 96 | tr.time = icaltime_from_string(str); |
191 | 97 | ||
192 | if (icaltime_is_null_time(tr.time)){ | 98 | if (icaltime_is_null_time(tr.time)){ |
193 | 99 | ||
194 | tr.duration = icaldurationtype_from_string(str); | 100 | tr.duration = icaldurationtype_from_string(str); |
195 | 101 | ||
196 | if(icaldurationtype_as_int(tr.duration) == 0) goto error; | 102 | if (icaldurationtype_is_bad_duration(tr.duration)) goto error; |
197 | } | 103 | } |
198 | 104 | ||
199 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); | 105 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); |
200 | icalerror_set_errno(e); | 106 | icalerror_set_errno(e); |
201 | return tr; | 107 | return tr; |
202 | 108 | ||
203 | error: | 109 | error: |
204 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); | 110 | icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); |
205 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 111 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
206 | return null_tr; | 112 | return tr; |
207 | 113 | ||
208 | } | 114 | } |
209 | 115 | ||
210 | 116 | ||
211 | struct icalreqstattype icalreqstattype_from_string(const char* str) | 117 | struct icalreqstattype icalreqstattype_from_string(const char* str) |
212 | { | 118 | { |
213 | const char *p1,*p2; | 119 | const char *p1,*p2; |
214 | struct icalreqstattype stat; | 120 | struct icalreqstattype stat; |
215 | int major, minor; | 121 | short major=0, minor=0; |
216 | 122 | ||
217 | icalerror_check_arg((str != 0),"str"); | 123 | icalerror_check_arg((str != 0),"str"); |
218 | 124 | ||
219 | stat.code = ICAL_UNKNOWN_STATUS; | 125 | stat.code = ICAL_UNKNOWN_STATUS; |
220 | stat.debug = 0; | 126 | stat.debug = 0; |
221 | stat.desc = 0; | 127 | stat.desc = 0; |
222 | 128 | ||
223 | /* Get the status numbers */ | 129 | /* Get the status numbers */ |
224 | 130 | ||
225 | sscanf(str, "%d.%d",&major, &minor); | 131 | sscanf(str, "%hd.%hd",&major, &minor); |
226 | 132 | ||
227 | if (major <= 0 || minor < 0){ | 133 | if (major <= 0 || minor < 0){ |
228 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); | 134 | icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); |
229 | return stat; | 135 | return stat; |
230 | } | 136 | } |
231 | 137 | ||