-rw-r--r-- | libical/src/libical/icalmemory.c | 2 | ||||
-rw-r--r-- | libkcal/icalformat.cpp | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/libical/src/libical/icalmemory.c b/libical/src/libical/icalmemory.c index 18d7ef9..3ed38ad 100644 --- a/libical/src/libical/icalmemory.c +++ b/libical/src/libical/icalmemory.c | |||
@@ -40,65 +40,65 @@ | |||
40 | * interfaces simple, I did not want the caller to have to pass in a | 40 | * interfaces simple, I did not want the caller to have to pass in a |
41 | * memory buffer, but having libical pass out newly allocated memory | 41 | * memory buffer, but having libical pass out newly allocated memory |
42 | * makes it difficult to de-allocate the memory. | 42 | * makes it difficult to de-allocate the memory. |
43 | * | 43 | * |
44 | * The ring buffer in this scheme makes it possible for libical to pass | 44 | * The ring buffer in this scheme makes it possible for libical to pass |
45 | * out references to memory which the caller does not own, and be able | 45 | * out references to memory which the caller does not own, and be able |
46 | * to de-allocate the memory later. The ring allows libical to have | 46 | * to de-allocate the memory later. The ring allows libical to have |
47 | * several buffers active simultaneously, which is handy when creating | 47 | * several buffers active simultaneously, which is handy when creating |
48 | * string representations of components. | 48 | * string representations of components. |
49 | */ | 49 | */ |
50 | 50 | ||
51 | #define ICALMEMORY_C | 51 | #define ICALMEMORY_C |
52 | 52 | ||
53 | #ifdef HAVE_CONFIG_H | 53 | #ifdef HAVE_CONFIG_H |
54 | #include "config.h" | 54 | #include "config.h" |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #ifdef DMALLOC | 57 | #ifdef DMALLOC |
58 | #include "dmalloc.h" | 58 | #include "dmalloc.h" |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #include "icalmemory.h" | 61 | #include "icalmemory.h" |
62 | #include "icalerror.h" | 62 | #include "icalerror.h" |
63 | 63 | ||
64 | #include <stdio.h> /* for printf (debugging) */ | 64 | #include <stdio.h> /* for printf (debugging) */ |
65 | #include <stdlib.h> /* for malloc, realloc */ | 65 | #include <stdlib.h> /* for malloc, realloc */ |
66 | #include <string.h> /* for memset(), strdup */ | 66 | #include <string.h> /* for memset(), strdup */ |
67 | 67 | ||
68 | #ifdef WIN32 | 68 | #ifdef WIN32 |
69 | #include <windows.h> | 69 | #include <windows.h> |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | #define BUFFER_RING_SIZE 50 | 72 | #define BUFFER_RING_SIZE 100 |
73 | #define MIN_BUFFER_SIZE 64 | 73 | #define MIN_BUFFER_SIZE 64 |
74 | 74 | ||
75 | 75 | ||
76 | /* HACK. Not threadsafe */ | 76 | /* HACK. Not threadsafe */ |
77 | 77 | ||
78 | typedef struct { | 78 | typedef struct { |
79 | int pos; | 79 | int pos; |
80 | void *ring[BUFFER_RING_SIZE]; | 80 | void *ring[BUFFER_RING_SIZE]; |
81 | } buffer_ring; | 81 | } buffer_ring; |
82 | 82 | ||
83 | void icalmemory_free_tmp_buffer (void* buf); | 83 | void icalmemory_free_tmp_buffer (void* buf); |
84 | void icalmemory_free_ring_byval(buffer_ring *br); | 84 | void icalmemory_free_ring_byval(buffer_ring *br); |
85 | 85 | ||
86 | static buffer_ring* global_buffer_ring = 0; | 86 | static buffer_ring* global_buffer_ring = 0; |
87 | 87 | ||
88 | #ifdef HAVE_PTHREAD | 88 | #ifdef HAVE_PTHREAD |
89 | #include <pthread.h> | 89 | #include <pthread.h> |
90 | 90 | ||
91 | static pthread_key_t ring_key; | 91 | static pthread_key_t ring_key; |
92 | static pthread_once_t ring_key_once = PTHREAD_ONCE_INIT; | 92 | static pthread_once_t ring_key_once = PTHREAD_ONCE_INIT; |
93 | 93 | ||
94 | static void ring_destroy(void * buf) { | 94 | static void ring_destroy(void * buf) { |
95 | if (buf) icalmemory_free_ring_byval((buffer_ring *) buf); | 95 | if (buf) icalmemory_free_ring_byval((buffer_ring *) buf); |
96 | pthread_setspecific(ring_key, NULL); | 96 | pthread_setspecific(ring_key, NULL); |
97 | } | 97 | } |
98 | 98 | ||
99 | static void ring_key_alloc(void) { | 99 | static void ring_key_alloc(void) { |
100 | pthread_key_create(&ring_key, ring_destroy); | 100 | pthread_key_create(&ring_key, ring_destroy); |
101 | } | 101 | } |
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | 104 | ||
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index d9fe40b..5877406 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp | |||
@@ -115,64 +115,65 @@ bool ICalFormat::fromString( Calendar *cal, const QString &text ) | |||
115 | { | 115 | { |
116 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 116 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
117 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); | 117 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); |
118 | // Get first VCALENDAR component. | 118 | // Get first VCALENDAR component. |
119 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components | 119 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components |
120 | icalcomponent *calendar; | 120 | icalcomponent *calendar; |
121 | 121 | ||
122 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); | 122 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); |
123 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); | 123 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); |
124 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); | 124 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); |
125 | if (!calendar) { | 125 | if (!calendar) { |
126 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); | 126 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); |
127 | return false; | 127 | return false; |
128 | } | 128 | } |
129 | 129 | ||
130 | bool success = true; | 130 | bool success = true; |
131 | 131 | ||
132 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { | 132 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { |
133 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); | 133 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); |
134 | success = false; | 134 | success = false; |
135 | } else { | 135 | } else { |
136 | // put all objects into their proper places | 136 | // put all objects into their proper places |
137 | if ( !mImpl->populate( cal, calendar ) ) { | 137 | if ( !mImpl->populate( cal, calendar ) ) { |
138 | if ( !exception() ) { | 138 | if ( !exception() ) { |
139 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); | 139 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); |
140 | } | 140 | } |
141 | success = false; | 141 | success = false; |
142 | } else | 142 | } else |
143 | mLoadedProductId = mImpl->loadedProductId(); | 143 | mLoadedProductId = mImpl->loadedProductId(); |
144 | } | 144 | } |
145 | 145 | ||
146 | icalcomponent_free( calendar ); | 146 | icalcomponent_free( calendar ); |
147 | icalmemory_free_ring(); | ||
147 | 148 | ||
148 | return success; | 149 | return success; |
149 | } | 150 | } |
150 | 151 | ||
151 | Incidence *ICalFormat::fromString( const QString &text ) | 152 | Incidence *ICalFormat::fromString( const QString &text ) |
152 | { | 153 | { |
153 | CalendarLocal cal( mTimeZoneId ); | 154 | CalendarLocal cal( mTimeZoneId ); |
154 | fromString(&cal, text); | 155 | fromString(&cal, text); |
155 | 156 | ||
156 | Incidence *ical = 0; | 157 | Incidence *ical = 0; |
157 | QPtrList<Event> elist = cal.events(); | 158 | QPtrList<Event> elist = cal.events(); |
158 | if ( elist.count() > 0 ) { | 159 | if ( elist.count() > 0 ) { |
159 | ical = elist.first(); | 160 | ical = elist.first(); |
160 | } else { | 161 | } else { |
161 | QPtrList<Todo> tlist = cal.todos(); | 162 | QPtrList<Todo> tlist = cal.todos(); |
162 | if ( tlist.count() > 0 ) { | 163 | if ( tlist.count() > 0 ) { |
163 | ical = tlist.first(); | 164 | ical = tlist.first(); |
164 | } else { | 165 | } else { |
165 | QPtrList<Journal> jlist = cal.journals(); | 166 | QPtrList<Journal> jlist = cal.journals(); |
166 | if ( jlist.count() > 0 ) { | 167 | if ( jlist.count() > 0 ) { |
167 | ical = jlist.first(); | 168 | ical = jlist.first(); |
168 | } | 169 | } |
169 | } | 170 | } |
170 | } | 171 | } |
171 | return ical; | 172 | return ical; |
172 | } | 173 | } |
173 | #include <qapp.h> | 174 | #include <qapp.h> |
174 | 175 | ||
175 | QString ICalFormat::toString( Calendar *cal ) | 176 | QString ICalFormat::toString( Calendar *cal ) |
176 | { | 177 | { |
177 | 178 | ||
178 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 179 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
@@ -196,67 +197,68 @@ QString ICalFormat::toString( Calendar *cal ) | |||
196 | for(ev=events.first();ev;ev=events.next()) { | 197 | for(ev=events.first();ev;ev=events.next()) { |
197 | component = mImpl->writeEvent(ev); | 198 | component = mImpl->writeEvent(ev); |
198 | icalcomponent_add_component(calendar,component); | 199 | icalcomponent_add_component(calendar,component); |
199 | //qDebug("events "); | 200 | //qDebug("events "); |
200 | qApp->processEvents(); | 201 | qApp->processEvents(); |
201 | } | 202 | } |
202 | 203 | ||
203 | // journals | 204 | // journals |
204 | QPtrList<Journal> journals = cal->journals(); | 205 | QPtrList<Journal> journals = cal->journals(); |
205 | Journal *j; | 206 | Journal *j; |
206 | for(j=journals.first();j;j=journals.next()) { | 207 | for(j=journals.first();j;j=journals.next()) { |
207 | component = mImpl->writeJournal(j); | 208 | component = mImpl->writeJournal(j); |
208 | icalcomponent_add_component(calendar,component); | 209 | icalcomponent_add_component(calendar,component); |
209 | //qDebug("journals "); | 210 | //qDebug("journals "); |
210 | qApp->processEvents(); | 211 | qApp->processEvents(); |
211 | } | 212 | } |
212 | const char *text; | 213 | const char *text; |
213 | QString ret =""; | 214 | QString ret =""; |
214 | text = icalcomponent_as_ical_string( calendar ); | 215 | text = icalcomponent_as_ical_string( calendar ); |
215 | qApp->processEvents(); | 216 | qApp->processEvents(); |
216 | 217 | ||
217 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; | 218 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; |
218 | 219 | ||
219 | 220 | ||
220 | if ( text ) { | 221 | if ( text ) { |
221 | ret = QString ( text ); | 222 | ret = QString ( text ); |
222 | } | 223 | } |
223 | icalcomponent_free( calendar ); | 224 | icalcomponent_free( calendar ); |
224 | 225 | ||
225 | if (!text) { | 226 | if (!text) { |
226 | setException(new ErrorFormat(ErrorFormat::SaveError, | 227 | setException(new ErrorFormat(ErrorFormat::SaveError, |
227 | i18n("libical error"))); | 228 | i18n("libical error"))); |
229 | icalmemory_free_ring(); | ||
228 | return QString::null; | 230 | return QString::null; |
229 | } | 231 | } |
230 | 232 | icalmemory_free_ring(); | |
231 | return ret; | 233 | return ret; |
232 | } | 234 | } |
233 | 235 | ||
234 | QString ICalFormat::toICalString( Incidence *incidence ) | 236 | QString ICalFormat::toICalString( Incidence *incidence ) |
235 | { | 237 | { |
236 | CalendarLocal cal( mTimeZoneId ); | 238 | CalendarLocal cal( mTimeZoneId ); |
237 | cal.addIncidence( incidence->clone() ); | 239 | cal.addIncidence( incidence->clone() ); |
238 | return toString( &cal ); | 240 | return toString( &cal ); |
239 | } | 241 | } |
240 | 242 | ||
241 | QString ICalFormat::toString( Incidence *incidence ) | 243 | QString ICalFormat::toString( Incidence *incidence ) |
242 | { | 244 | { |
243 | icalcomponent *component; | 245 | icalcomponent *component; |
244 | 246 | ||
245 | component = mImpl->writeIncidence( incidence ); | 247 | component = mImpl->writeIncidence( incidence ); |
246 | 248 | ||
247 | const char *text = icalcomponent_as_ical_string( component ); | 249 | const char *text = icalcomponent_as_ical_string( component ); |
248 | 250 | ||
249 | icalcomponent_free( component ); | 251 | icalcomponent_free( component ); |
250 | 252 | ||
251 | return QString::fromLocal8Bit( text ); | 253 | return QString::fromLocal8Bit( text ); |
252 | } | 254 | } |
253 | 255 | ||
254 | QString ICalFormat::toString( Recurrence *recurrence ) | 256 | QString ICalFormat::toString( Recurrence *recurrence ) |
255 | { | 257 | { |
256 | icalproperty *property; | 258 | icalproperty *property; |
257 | property = mImpl->writeRecurrenceRule( recurrence ); | 259 | property = mImpl->writeRecurrenceRule( recurrence ); |
258 | const char *text = icalproperty_as_ical_string( property ); | 260 | const char *text = icalproperty_as_ical_string( property ); |
259 | icalproperty_free( property ); | 261 | icalproperty_free( property ); |
260 | return QString::fromLocal8Bit( text ); | 262 | return QString::fromLocal8Bit( text ); |
261 | } | 263 | } |
262 | /* | 264 | /* |