author | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
commit | d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e (patch) (unidiff) | |
tree | 9b723a5c4f7da306036495e35d1863fbee646984 | |
parent | d9b7a7296b031b3cf3e510a163367b9c4ab42d7a (diff) | |
download | kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.zip kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.gz kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.bz2 |
bugfix: memoryleak in vCards during loading of addressbooks
-rw-r--r-- | kabc/vcard/ContentLine.cpp | 103 | ||||
-rw-r--r-- | kabc/vcard/VCardEntity.cpp | 23 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 23 |
3 files changed, 97 insertions, 52 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp index 6fa1a8f..0fb5b5d 100644 --- a/kabc/vcard/ContentLine.cpp +++ b/kabc/vcard/ContentLine.cpp | |||
@@ -1,289 +1,314 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1999 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1999 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include <qstrlist.h> | 25 | #include <qstrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | 27 | ||
28 | #include <kdebug.h> | 28 | #include <kdebug.h> |
29 | 29 | ||
30 | #include <VCardAdrParam.h> | 30 | #include <VCardAdrParam.h> |
31 | #include <VCardAgentParam.h> | 31 | #include <VCardAgentParam.h> |
32 | #include <VCardDateParam.h> | 32 | #include <VCardDateParam.h> |
33 | #include <VCardEmailParam.h> | 33 | #include <VCardEmailParam.h> |
34 | #include <VCardImageParam.h> | 34 | #include <VCardImageParam.h> |
35 | #include <VCardSourceParam.h> | 35 | #include <VCardSourceParam.h> |
36 | #include <VCardTelParam.h> | 36 | #include <VCardTelParam.h> |
37 | #include <VCardTextBinParam.h> | 37 | #include <VCardTextBinParam.h> |
38 | #include <VCardTextParam.h> | 38 | #include <VCardTextParam.h> |
39 | 39 | ||
40 | #include <VCardAdrValue.h> | 40 | #include <VCardAdrValue.h> |
41 | #include <VCardAgentValue.h> | 41 | #include <VCardAgentValue.h> |
42 | #include <VCardDateValue.h> | 42 | #include <VCardDateValue.h> |
43 | #include <VCardImageValue.h> | 43 | #include <VCardImageValue.h> |
44 | #include <VCardTextValue.h> | 44 | #include <VCardTextValue.h> |
45 | #include <VCardTextBinValue.h> | 45 | #include <VCardTextBinValue.h> |
46 | #include <VCardLangValue.h> | 46 | #include <VCardLangValue.h> |
47 | #include <VCardNValue.h> | 47 | #include <VCardNValue.h> |
48 | #include <VCardURIValue.h> | 48 | #include <VCardURIValue.h> |
49 | #include <VCardSoundValue.h> | 49 | #include <VCardSoundValue.h> |
50 | #include <VCardClassValue.h> | 50 | #include <VCardClassValue.h> |
51 | #include <VCardFloatValue.h> | 51 | #include <VCardFloatValue.h> |
52 | #include <VCardOrgValue.h> | 52 | #include <VCardOrgValue.h> |
53 | #include <VCardTelValue.h> | 53 | #include <VCardTelValue.h> |
54 | #include <VCardTextListValue.h> | 54 | #include <VCardTextListValue.h> |
55 | #include <VCardUTCValue.h> | 55 | #include <VCardUTCValue.h> |
56 | #include <VCardGeoValue.h> | 56 | #include <VCardGeoValue.h> |
57 | 57 | ||
58 | #include <VCardRToken.h> | 58 | #include <VCardRToken.h> |
59 | #include <VCardContentLine.h> | 59 | #include <VCardContentLine.h> |
60 | 60 | ||
61 | #include <VCardEntity.h> | 61 | #include <VCardEntity.h> |
62 | #include <VCardEnum.h> | 62 | #include <VCardEnum.h> |
63 | #include <VCardDefines.h> | 63 | #include <VCardDefines.h> |
64 | 64 | ||
65 | using namespace VCARD; | 65 | using namespace VCARD; |
66 | 66 | ||
67 | ContentLine::ContentLine() | 67 | ContentLine::ContentLine() |
68 | :Entity(), | 68 | :Entity(), |
69 | value_(0) | 69 | value_(0) |
70 | { | 70 | { |
71 | paramList_.setAutoDelete( TRUE ); | ||
71 | } | 72 | } |
72 | 73 | ||
73 | ContentLine::ContentLine(const ContentLine & x) | 74 | ContentLine::ContentLine(const ContentLine & x) |
74 | :Entity(x), | 75 | :Entity(x), |
75 | group_ (x.group_), | 76 | group_ (x.group_), |
76 | name_ (x.name_), | 77 | name_ (x.name_), |
77 | paramList_(x.paramList_), | 78 | /*US paramList_(x.paramList_),*/ |
78 | value_(x.value_->clone()) | 79 | value_(x.value_->clone()), |
80 | paramType_(x.paramType_), | ||
81 | valueType_(x.valueType_), | ||
82 | entityType_(x.entityType_) | ||
79 | { | 83 | { |
84 | paramList_.setAutoDelete( TRUE ); | ||
85 | |||
86 | |||
87 | ParamListIterator it(x.paramList_); | ||
88 | for (; it.current(); ++it) | ||
89 | { | ||
90 | Param *p = new Param; | ||
91 | p->setName( it.current()->name() ); | ||
92 | p->setValue( it.current()->value() ); | ||
93 | paramList_.append(p); | ||
94 | } | ||
95 | |||
80 | } | 96 | } |
81 | 97 | ||
82 | ContentLine::ContentLine(const QCString & s) | 98 | ContentLine::ContentLine(const QCString & s) |
83 | :Entity(s), | 99 | :Entity(s), |
84 | value_(0) | 100 | value_(0) |
85 | { | 101 | { |
102 | paramList_.setAutoDelete( TRUE ); | ||
86 | } | 103 | } |
87 | 104 | ||
88 | ContentLine & | 105 | ContentLine & |
89 | ContentLine::operator = (ContentLine & x) | 106 | ContentLine::operator = (ContentLine & x) |
90 | { | 107 | { |
91 | if (*this == x) return *this; | 108 | if (*this == x) return *this; |
92 | 109 | ||
93 | paramList_ = x.paramList(); | 110 | ParamListIterator it(x.paramList_); |
111 | for (; it.current(); ++it) | ||
112 | { | ||
113 | Param *p = new Param; | ||
114 | p->setName( it.current()->name() ); | ||
115 | p->setValue( it.current()->value() ); | ||
116 | paramList_.append(p); | ||
117 | } | ||
118 | |||
94 | value_ = x.value_->clone(); | 119 | value_ = x.value_->clone(); |
95 | 120 | ||
96 | Entity::operator = (x); | 121 | Entity::operator = (x); |
97 | return *this; | 122 | return *this; |
98 | } | 123 | } |
99 | 124 | ||
100 | ContentLine & | 125 | ContentLine & |
101 | ContentLine::operator = (const QCString & s) | 126 | ContentLine::operator = (const QCString & s) |
102 | { | 127 | { |
103 | Entity::operator = (s); | 128 | Entity::operator = (s); |
104 | delete value_; | 129 | delete value_; |
105 | value_ = 0; | 130 | value_ = 0; |
106 | return *this; | 131 | return *this; |
107 | } | 132 | } |
108 | 133 | ||
109 | bool | 134 | bool |
110 | ContentLine::operator == (ContentLine & x) | 135 | ContentLine::operator == (ContentLine & x) |
111 | { | 136 | { |
112 | x.parse(); | 137 | x.parse(); |
113 | 138 | ||
114 | QPtrListIterator<Param> it(x.paramList()); | 139 | QPtrListIterator<Param> it(x.paramList()); |
115 | 140 | ||
116 | if (!paramList_.find(it.current())) | 141 | if (!paramList_.find(it.current())) |
117 | return false; | 142 | return false; |
118 | 143 | ||
119 | return true; | 144 | return true; |
120 | } | 145 | } |
121 | 146 | ||
122 | ContentLine::~ContentLine() | 147 | ContentLine::~ContentLine() |
123 | { | 148 | { |
124 | delete value_; | 149 | delete value_; |
125 | value_ = 0; | 150 | value_ = 0; |
126 | } | 151 | } |
127 | 152 | ||
128 | void | 153 | void |
129 | ContentLine::_parse() | 154 | ContentLine::_parse() |
130 | { | 155 | { |
131 | vDebug("parse"); | 156 | vDebug("parse"); |
132 | 157 | ||
133 | // Unqote newlines | 158 | // Unqote newlines |
134 | strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); | 159 | strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); |
135 | 160 | ||
136 | int split = strRep_.find(':'); | 161 | int split = strRep_.find(':'); |
137 | 162 | ||
138 | if (split == -1) { // invalid content line | 163 | if (split == -1) { // invalid content line |
139 | vDebug("No ':'"); | 164 | vDebug("No ':'"); |
140 | return; | 165 | return; |
141 | } | 166 | } |
142 | 167 | ||
143 | QCString firstPart(strRep_.left(split)); | 168 | QCString firstPart(strRep_.left(split)); |
144 | QCString valuePart(strRep_.mid(split + 1)); | 169 | QCString valuePart(strRep_.mid(split + 1)); |
145 | 170 | ||
146 | split = firstPart.find('.'); | 171 | split = firstPart.find('.'); |
147 | 172 | ||
148 | if (split != -1) { | 173 | if (split != -1) { |
149 | group_ = firstPart.left(split); | 174 | group_ = firstPart.left(split); |
150 | firstPart= firstPart.mid(split + 1); | 175 | firstPart= firstPart.mid(split + 1); |
151 | } | 176 | } |
152 | 177 | ||
153 | vDebug("Group == " + group_); | 178 | vDebug("Group == " + group_); |
154 | vDebug("firstPart == " + firstPart); | 179 | vDebug("firstPart == " + firstPart); |
155 | vDebug("valuePart == " + valuePart); | 180 | vDebug("valuePart == " + valuePart); |
156 | 181 | ||
157 | // Now we have the group, the name and param list together and the value. | 182 | // Now we have the group, the name and param list together and the value. |
158 | 183 | ||
159 | QStrList l; | 184 | QStrList l; |
160 | 185 | ||
161 | RTokenise(firstPart, ";", l); | 186 | RTokenise(firstPart, ";", l); |
162 | 187 | ||
163 | if (l.count() == 0) {// invalid - no name ! | 188 | if (l.count() == 0) {// invalid - no name ! |
164 | vDebug("No name for this content line !"); | 189 | vDebug("No name for this content line !"); |
165 | return; | 190 | return; |
166 | } | 191 | } |
167 | 192 | ||
168 | name_ = l.at(0); | 193 | name_ = l.at(0); |
169 | 194 | ||
170 | // Now we have the name, so the rest of 'l' is the params. | 195 | // Now we have the name, so the rest of 'l' is the params. |
171 | // Remove the name part. | 196 | // Remove the name part. |
172 | l.remove(0u); | 197 | l.remove(0u); |
173 | 198 | ||
174 | entityType_= EntityNameToEntityType(name_); | 199 | entityType_= EntityNameToEntityType(name_); |
175 | paramType_= EntityTypeToParamType(entityType_); | 200 | paramType_= EntityTypeToParamType(entityType_); |
176 | 201 | ||
177 | unsigned int i = 0; | 202 | unsigned int i = 0; |
178 | 203 | ||
179 | // For each parameter, create a new parameter of the correct type. | 204 | // For each parameter, create a new parameter of the correct type. |
180 | 205 | ||
181 | QStrListIterator it(l); | 206 | QStrListIterator it(l); |
182 | 207 | ||
183 | for (; it.current(); ++it, i++) { | 208 | for (; it.current(); ++it, i++) { |
184 | 209 | ||
185 | QCString str = *it; | 210 | QCString str = *it; |
186 | 211 | ||
187 | split = str.find("="); | 212 | split = str.find("="); |
188 | if (split < 0 ) { | 213 | if (split < 0 ) { |
189 | vDebug("No '=' in paramter."); | 214 | vDebug("No '=' in paramter."); |
190 | continue; | 215 | continue; |
191 | } | 216 | } |
192 | 217 | ||
193 | QCString paraName = str.left(split); | 218 | QCString paraName = str.left(split); |
194 | QCString paraValue = str.mid(split + 1); | 219 | QCString paraValue = str.mid(split + 1); |
195 | 220 | ||
196 | QStrList paraValues; | 221 | QStrList paraValues; |
197 | RTokenise(paraValue, ",", paraValues); | 222 | RTokenise(paraValue, ",", paraValues); |
198 | 223 | ||
199 | QStrListIterator it2( paraValues ); | 224 | QStrListIterator it2( paraValues ); |
200 | 225 | ||
201 | for(; it2.current(); ++it2) { | 226 | for(; it2.current(); ++it2) { |
202 | 227 | ||
203 | Param *p = new Param; | 228 | Param *p = new Param; |
204 | p->setName( paraName ); | 229 | p->setName( paraName ); |
205 | p->setValue( *it2 ); | 230 | p->setValue( *it2 ); |
206 | 231 | ||
207 | paramList_.append(p); | 232 | paramList_.append(p); |
208 | } | 233 | } |
209 | } | 234 | } |
210 | 235 | ||
211 | // Create a new value of the correct type. | 236 | // Create a new value of the correct type. |
212 | 237 | ||
213 | valueType_ = EntityTypeToValueType(entityType_); | 238 | valueType_ = EntityTypeToValueType(entityType_); |
214 | 239 | ||
215 | //kdDebug(5710) << "valueType: " << valueType_ << endl; | 240 | //kdDebug(5710) << "valueType: " << valueType_ << endl; |
216 | 241 | ||
217 | switch (valueType_) { | 242 | switch (valueType_) { |
218 | 243 | ||
219 | case ValueSound: value_ = new SoundValue;break; | 244 | case ValueSound: value_ = new SoundValue;break; |
220 | case ValueAgent: value_ = new AgentValue;break; | 245 | case ValueAgent: value_ = new AgentValue;break; |
221 | case ValueAddress: value_ = new AdrValue; break; | 246 | case ValueAddress: value_ = new AdrValue; break; |
222 | case ValueTel: value_ = new TelValue; break; | 247 | case ValueTel: value_ = new TelValue; break; |
223 | case ValueTextBin: value_ = new TextBinValue;break; | 248 | case ValueTextBin: value_ = new TextBinValue;break; |
224 | case ValueOrg: value_ = new OrgValue; break; | 249 | case ValueOrg: value_ = new OrgValue; break; |
225 | case ValueN: value_ = new NValue; break; | 250 | case ValueN: value_ = new NValue; break; |
226 | case ValueUTC: value_ = new UTCValue; break; | 251 | case ValueUTC: value_ = new UTCValue; break; |
227 | case ValueURI: value_ = new URIValue; break; | 252 | case ValueURI: value_ = new URIValue; break; |
228 | case ValueClass: value_ = new ClassValue;break; | 253 | case ValueClass: value_ = new ClassValue;break; |
229 | case ValueFloat: value_ = new FloatValue;break; | 254 | case ValueFloat: value_ = new FloatValue;break; |
230 | case ValueImage: value_ = new ImageValue;break; | 255 | case ValueImage: value_ = new ImageValue;break; |
231 | case ValueDate: value_ = new DateValue; break; | 256 | case ValueDate: value_ = new DateValue; break; |
232 | case ValueTextList: value_ = new TextListValue;break; | 257 | case ValueTextList: value_ = new TextListValue;break; |
233 | case ValueGeo: value_ = new GeoValue; break; | 258 | case ValueGeo: value_ = new GeoValue; break; |
234 | case ValueText: | 259 | case ValueText: |
235 | case ValueUnknown: | 260 | case ValueUnknown: |
236 | default: value_ = new TextValue; break; | 261 | default: value_ = new TextValue; break; |
237 | } | 262 | } |
238 | 263 | ||
239 | *value_ = valuePart; | 264 | *value_ = valuePart; |
240 | } | 265 | } |
241 | 266 | ||
242 | void | 267 | void |
243 | ContentLine::_assemble() | 268 | ContentLine::_assemble() |
244 | { | 269 | { |
245 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); | 270 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); |
246 | strRep_.truncate(0); | 271 | strRep_.truncate(0); |
247 | 272 | ||
248 | QCString line; | 273 | QCString line; |
249 | 274 | ||
250 | if (!group_.isEmpty()) | 275 | if (!group_.isEmpty()) |
251 | line += group_ + '.'; | 276 | line += group_ + '.'; |
252 | 277 | ||
253 | line += name_; | 278 | line += name_; |
254 | 279 | ||
255 | vDebug("Adding parameters"); | 280 | vDebug("Adding parameters"); |
256 | ParamListIterator it(paramList_); | 281 | ParamListIterator it(paramList_); |
257 | 282 | ||
258 | for (; it.current(); ++it) | 283 | for (; it.current(); ++it) |
259 | line += ";" + it.current()->asString(); | 284 | line += ";" + it.current()->asString(); |
260 | 285 | ||
261 | vDebug("Adding value"); | 286 | vDebug("Adding value"); |
262 | if (value_ != 0) | 287 | if (value_ != 0) |
263 | line += ":" + value_->asString(); | 288 | line += ":" + value_->asString(); |
264 | else | 289 | else |
265 | vDebug("No value"); | 290 | vDebug("No value"); |
266 | 291 | ||
267 | // Quote newlines | 292 | // Quote newlines |
268 | line = line.replace( QRegExp( "\n" ), "\\n" ); | 293 | line = line.replace( QRegExp( "\n" ), "\\n" ); |
269 | 294 | ||
270 | // Fold lines longer than 72 chars | 295 | // Fold lines longer than 72 chars |
271 | const int maxLen = 72; | 296 | const int maxLen = 72; |
272 | uint cursor = 0; | 297 | uint cursor = 0; |
273 | while( line.length() > ( cursor + 1 ) * maxLen ) { | 298 | while( line.length() > ( cursor + 1 ) * maxLen ) { |
274 | strRep_ += line.mid( cursor * maxLen, maxLen ); | 299 | strRep_ += line.mid( cursor * maxLen, maxLen ); |
275 | strRep_ += "\r\n "; | 300 | strRep_ += "\r\n "; |
276 | ++cursor; | 301 | ++cursor; |
277 | } | 302 | } |
278 | strRep_ += line.mid( cursor * maxLen ); | 303 | strRep_ += line.mid( cursor * maxLen ); |
279 | } | 304 | } |
280 | 305 | ||
281 | void | 306 | void |
282 | ContentLine::clear() | 307 | ContentLine::clear() |
283 | { | 308 | { |
284 | group_.truncate(0); | 309 | group_.truncate(0); |
285 | name_.truncate(0); | 310 | name_.truncate(0); |
286 | paramList_.clear(); | 311 | paramList_.clear(); |
287 | delete value_; | 312 | delete value_; |
288 | value_ = 0; | 313 | value_ = 0; |
289 | } | 314 | } |
diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp index 0c21e2f..0cd2086 100644 --- a/kabc/vcard/VCardEntity.cpp +++ b/kabc/vcard/VCardEntity.cpp | |||
@@ -1,119 +1,122 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | 25 | ||
26 | #include <VCardDefines.h> | 26 | #include <VCardDefines.h> |
27 | #include <VCardVCardEntity.h> | 27 | #include <VCardVCardEntity.h> |
28 | 28 | ||
29 | using namespace VCARD; | 29 | using namespace VCARD; |
30 | 30 | ||
31 | VCardEntity::VCardEntity() | 31 | VCardEntity::VCardEntity() |
32 | :Entity() | 32 | :Entity() |
33 | { | 33 | { |
34 | cardList_.setAutoDelete( TRUE ); | ||
34 | } | 35 | } |
35 | 36 | ||
36 | VCardEntity::VCardEntity(const VCardEntity & x) | 37 | VCardEntity::VCardEntity(const VCardEntity & x) |
37 | :Entity(x) | 38 | :Entity(x) |
38 | { | 39 | { |
40 | cardList_.setAutoDelete( TRUE ); | ||
39 | } | 41 | } |
40 | 42 | ||
41 | VCardEntity::VCardEntity(const QCString & s) | 43 | VCardEntity::VCardEntity(const QCString & s) |
42 | :Entity(s) | 44 | :Entity(s) |
43 | { | 45 | { |
46 | cardList_.setAutoDelete( TRUE ); | ||
44 | } | 47 | } |
45 | 48 | ||
46 | VCardEntity & | 49 | VCardEntity & |
47 | VCardEntity::operator = (VCardEntity & x) | 50 | VCardEntity::operator = (VCardEntity & x) |
48 | { | 51 | { |
49 | if (*this == x) return *this; | 52 | if (*this == x) return *this; |
50 | 53 | ||
51 | Entity::operator = (x); | 54 | Entity::operator = (x); |
52 | return *this; | 55 | return *this; |
53 | } | 56 | } |
54 | 57 | ||
55 | VCardEntity & | 58 | VCardEntity & |
56 | VCardEntity::operator = (const QCString & s) | 59 | VCardEntity::operator = (const QCString & s) |
57 | { | 60 | { |
58 | Entity::operator = (s); | 61 | Entity::operator = (s); |
59 | return *this; | 62 | return *this; |
60 | } | 63 | } |
61 | 64 | ||
62 | bool | 65 | bool |
63 | VCardEntity::operator == (VCardEntity & x) | 66 | VCardEntity::operator == (VCardEntity & x) |
64 | { | 67 | { |
65 | x.parse(); | 68 | x.parse(); |
66 | return false; | 69 | return false; |
67 | } | 70 | } |
68 | 71 | ||
69 | VCardEntity::~VCardEntity() | 72 | VCardEntity::~VCardEntity() |
70 | { | 73 | { |
71 | } | 74 | } |
72 | 75 | ||
73 | void | 76 | void |
74 | VCardEntity::_parse() | 77 | VCardEntity::_parse() |
75 | { | 78 | { |
76 | vDebug("parse"); | 79 | vDebug("parse"); |
77 | QCString s(strRep_); | 80 | QCString s(strRep_); |
78 | 81 | ||
79 | int i = s.find(QRegExp("BEGIN:VCARD", false)); | 82 | int i = s.find(QRegExp("BEGIN:VCARD", false)); |
80 | 83 | ||
81 | while (i != -1) { | 84 | while (i != -1) { |
82 | 85 | ||
83 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); | 86 | i = s.find(QRegExp("BEGIN:VCARD", false), 11); |
84 | 87 | ||
85 | QCString cardStr(s.left(i)); | 88 | QCString cardStr(s.left(i)); |
86 | 89 | ||
87 | VCard * v = new VCard(cardStr); | 90 | VCard * v = new VCard(cardStr); |
88 | 91 | ||
89 | cardList_.append(v); | 92 | cardList_.append(v); |
90 | 93 | ||
91 | v->parse(); | 94 | v->parse(); |
92 | 95 | ||
93 | s.remove(0, i); | 96 | s.remove(0, i); |
94 | } | 97 | } |
95 | } | 98 | } |
96 | 99 | ||
97 | void | 100 | void |
98 | VCardEntity::_assemble() | 101 | VCardEntity::_assemble() |
99 | { | 102 | { |
100 | VCardListIterator it(cardList_); | 103 | VCardListIterator it(cardList_); |
101 | 104 | ||
102 | for (; it.current(); ++it) | 105 | for (; it.current(); ++it) |
103 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. | 106 | strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. |
104 | } | 107 | } |
105 | 108 | ||
106 | VCardList & | 109 | VCardList & |
107 | VCardEntity::cardList() | 110 | VCardEntity::cardList() |
108 | { | 111 | { |
109 | parse(); | 112 | parse(); |
110 | return cardList_; | 113 | return cardList_; |
111 | } | 114 | } |
112 | 115 | ||
113 | void | 116 | void |
114 | VCardEntity::setCardList(const VCardList & l) | 117 | VCardEntity::setCardList(const VCardList & l) |
115 | { | 118 | { |
116 | parse(); | 119 | parse(); |
117 | cardList_ = l; | 120 | cardList_ = l; |
118 | } | 121 | } |
119 | 122 | ||
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp index 8d271f4..3f0a5e5 100644 --- a/kabc/vcard/VCardv.cpp +++ b/kabc/vcard/VCardv.cpp | |||
@@ -1,251 +1,268 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include <qstrlist.h> | 25 | #include <qstrlist.h> |
26 | 26 | ||
27 | #include <VCardEntity.h> | 27 | #include <VCardEntity.h> |
28 | #include <VCardVCard.h> | 28 | #include <VCardVCard.h> |
29 | #include <VCardContentLine.h> | 29 | #include <VCardContentLine.h> |
30 | #include <VCardRToken.h> | 30 | #include <VCardRToken.h> |
31 | 31 | ||
32 | #include <VCardDefines.h> | 32 | #include <VCardDefines.h> |
33 | 33 | ||
34 | using namespace VCARD; | 34 | using namespace VCARD; |
35 | 35 | ||
36 | VCard::VCard() | 36 | VCard::VCard() |
37 | :Entity() | 37 | :Entity() |
38 | { | 38 | { |
39 | contentLineList_.setAutoDelete( TRUE ); | ||
39 | } | 40 | } |
40 | 41 | ||
41 | VCard::VCard(const VCard & x) | 42 | VCard::VCard(const VCard & x) |
42 | :Entity(x), | 43 | :Entity(x), |
43 | group_(x.group_), | 44 | group_(x.group_) |
44 | contentLineList_(x.contentLineList_) | ||
45 | { | 45 | { |
46 | contentLineList_.setAutoDelete( TRUE ); | ||
47 | //US | ||
48 | qDebug("VCard::VCard"); | ||
49 | |||
50 | QPtrListIterator<ContentLine> it(x.contentLineList_); | ||
51 | for (; it.current(); ++it) { | ||
52 | ContentLine * c = new ContentLine(*it.current()); | ||
53 | contentLineList_.append(c); | ||
54 | } | ||
55 | |||
46 | } | 56 | } |
47 | 57 | ||
48 | VCard::VCard(const QCString & s) | 58 | VCard::VCard(const QCString & s) |
49 | :Entity(s) | 59 | :Entity(s) |
50 | { | 60 | { |
61 | contentLineList_.setAutoDelete( TRUE ); | ||
51 | } | 62 | } |
52 | 63 | ||
53 | VCard & | 64 | VCard & |
54 | VCard::operator = (VCard & x) | 65 | VCard::operator = (VCard & x) |
55 | { | 66 | { |
67 | //US | ||
68 | qDebug("VCard::operator ="); | ||
56 | if (*this == x) return *this; | 69 | if (*this == x) return *this; |
57 | 70 | ||
58 | group_ = x.group(); | 71 | group_ = x.group(); |
59 | contentLineList_= x.contentLineList_; | 72 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
73 | for (; it.current(); ++it) { | ||
74 | ContentLine * c = new ContentLine(*it.current()); | ||
75 | contentLineList_.append(c); | ||
76 | } | ||
60 | 77 | ||
61 | Entity::operator = (x); | 78 | Entity::operator = (x); |
62 | return *this; | 79 | return *this; |
63 | } | 80 | } |
64 | 81 | ||
65 | VCard & | 82 | VCard & |
66 | VCard::operator = (const QCString & s) | 83 | VCard::operator = (const QCString & s) |
67 | { | 84 | { |
68 | Entity::operator = (s); | 85 | Entity::operator = (s); |
69 | return *this; | 86 | return *this; |
70 | } | 87 | } |
71 | 88 | ||
72 | bool | 89 | bool |
73 | VCard::operator == (VCard & x) | 90 | VCard::operator == (VCard & x) |
74 | { | 91 | { |
75 | x.parse(); | 92 | x.parse(); |
76 | return false; | 93 | return false; |
77 | } | 94 | } |
78 | 95 | ||
79 | VCard::~VCard() | 96 | VCard::~VCard() |
80 | { | 97 | { |
81 | } | 98 | } |
82 | 99 | ||
83 | void | 100 | void |
84 | VCard::_parse() | 101 | VCard::_parse() |
85 | { | 102 | { |
86 | vDebug("parse() called"); | 103 | vDebug("parse() called"); |
87 | QStrList l; | 104 | QStrList l; |
88 | 105 | ||
89 | RTokenise(strRep_, "\r\n", l); | 106 | RTokenise(strRep_, "\r\n", l); |
90 | 107 | ||
91 | if (l.count() < 3) { // Invalid VCARD ! | 108 | if (l.count() < 3) { // Invalid VCARD ! |
92 | vDebug("Invalid vcard"); | 109 | vDebug("Invalid vcard"); |
93 | return; | 110 | return; |
94 | } | 111 | } |
95 | 112 | ||
96 | // Get the first line | 113 | // Get the first line |
97 | QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); | 114 | QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); |
98 | 115 | ||
99 | vDebug("Begin line == \"" + beginLine + "\""); | 116 | vDebug("Begin line == \"" + beginLine + "\""); |
100 | 117 | ||
101 | // Remove extra blank lines | 118 | // Remove extra blank lines |
102 | while (QCString(l.last()).isEmpty()) | 119 | while (QCString(l.last()).isEmpty()) |
103 | l.remove(l.last()); | 120 | l.remove(l.last()); |
104 | 121 | ||
105 | // Now we know this is the last line | 122 | // Now we know this is the last line |
106 | QCString endLine = l.last(); | 123 | QCString endLine = l.last(); |
107 | 124 | ||
108 | // Trash the first and last lines as we have seen them. | 125 | // Trash the first and last lines as we have seen them. |
109 | l.remove(0u); | 126 | l.remove(0u); |
110 | l.remove(l.last()); | 127 | l.remove(l.last()); |
111 | 128 | ||
112 | /////////////////////////////////////////////////////////////// | 129 | /////////////////////////////////////////////////////////////// |
113 | // FIRST LINE | 130 | // FIRST LINE |
114 | 131 | ||
115 | int split = beginLine.find(':'); | 132 | int split = beginLine.find(':'); |
116 | 133 | ||
117 | if (split == -1) { // invalid, no BEGIN | 134 | if (split == -1) { // invalid, no BEGIN |
118 | vDebug("No split"); | 135 | vDebug("No split"); |
119 | return; | 136 | return; |
120 | } | 137 | } |
121 | 138 | ||
122 | QCString firstPart(beginLine.left(split)); | 139 | QCString firstPart(beginLine.left(split)); |
123 | QCString valuePart(beginLine.mid(split + 1)); | 140 | QCString valuePart(beginLine.mid(split + 1)); |
124 | 141 | ||
125 | split = firstPart.find('.'); | 142 | split = firstPart.find('.'); |
126 | 143 | ||
127 | if (split != -1) { | 144 | if (split != -1) { |
128 | group_ = firstPart.left(split); | 145 | group_ = firstPart.left(split); |
129 | firstPart= firstPart.right(firstPart.length() - split - 1); | 146 | firstPart= firstPart.right(firstPart.length() - split - 1); |
130 | } | 147 | } |
131 | 148 | ||
132 | if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! | 149 | if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! |
133 | vDebug("No BEGIN"); | 150 | vDebug("No BEGIN"); |
134 | return; | 151 | return; |
135 | } | 152 | } |
136 | 153 | ||
137 | if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! | 154 | if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! |
138 | vDebug("No VCARD"); | 155 | vDebug("No VCARD"); |
139 | return; | 156 | return; |
140 | } | 157 | } |
141 | 158 | ||
142 | /////////////////////////////////////////////////////////////// | 159 | /////////////////////////////////////////////////////////////// |
143 | // CONTENT LINES | 160 | // CONTENT LINES |
144 | // | 161 | // |
145 | vDebug("Content lines"); | 162 | vDebug("Content lines"); |
146 | 163 | ||
147 | // Handle folded lines. | 164 | // Handle folded lines. |
148 | 165 | ||
149 | QStrList refolded; | 166 | QStrList refolded; |
150 | 167 | ||
151 | QStrListIterator it(l); | 168 | QStrListIterator it(l); |
152 | 169 | ||
153 | QCString cur; | 170 | QCString cur; |
154 | 171 | ||
155 | for (; it.current(); ++it) { | 172 | for (; it.current(); ++it) { |
156 | 173 | ||
157 | cur = it.current(); | 174 | cur = it.current(); |
158 | 175 | ||
159 | ++it; | 176 | ++it; |
160 | 177 | ||
161 | while ( | 178 | while ( |
162 | it.current() && | 179 | it.current() && |
163 | it.current()[0] == ' '&& | 180 | it.current()[0] == ' '&& |
164 | strlen(it.current()) != 1) | 181 | strlen(it.current()) != 1) |
165 | { | 182 | { |
166 | cur += it.current() + 1; | 183 | cur += it.current() + 1; |
167 | ++it; | 184 | ++it; |
168 | } | 185 | } |
169 | 186 | ||
170 | --it; | 187 | --it; |
171 | 188 | ||
172 | refolded.append(cur); | 189 | refolded.append(cur); |
173 | } | 190 | } |
174 | 191 | ||
175 | QStrListIterator it2(refolded); | 192 | QStrListIterator it2(refolded); |
176 | 193 | ||
177 | for (; it2.current(); ++it2) { | 194 | for (; it2.current(); ++it2) { |
178 | 195 | ||
179 | vDebug("New contentline using \"" + QCString(it2.current()) + "\""); | 196 | vDebug("New contentline using \"" + QCString(it2.current()) + "\""); |
180 | ContentLine * cl = new ContentLine(it2.current()); | 197 | ContentLine * cl = new ContentLine(it2.current()); |
181 | 198 | ||
182 | cl->parse(); | 199 | cl->parse(); |
183 | 200 | ||
184 | contentLineList_.append(cl); | 201 | contentLineList_.append(cl); |
185 | } | 202 | } |
186 | 203 | ||
187 | /////////////////////////////////////////////////////////////// | 204 | /////////////////////////////////////////////////////////////// |
188 | // LAST LINE | 205 | // LAST LINE |
189 | 206 | ||
190 | split = endLine.find(':'); | 207 | split = endLine.find(':'); |
191 | 208 | ||
192 | if (split == -1) // invalid, no END | 209 | if (split == -1) // invalid, no END |
193 | return; | 210 | return; |
194 | 211 | ||
195 | firstPart = endLine.left(split); | 212 | firstPart = endLine.left(split); |
196 | valuePart = endLine.right(firstPart.length() - split - 1); | 213 | valuePart = endLine.right(firstPart.length() - split - 1); |
197 | 214 | ||
198 | split = firstPart.find('.'); | 215 | split = firstPart.find('.'); |
199 | 216 | ||
200 | if (split != -1) { | 217 | if (split != -1) { |
201 | group_ = firstPart.left(split); | 218 | group_ = firstPart.left(split); |
202 | firstPart= firstPart.right(firstPart.length() - split - 1); | 219 | firstPart= firstPart.right(firstPart.length() - split - 1); |
203 | } | 220 | } |
204 | 221 | ||
205 | if (qstricmp(firstPart, "END") != 0) // No END ! | 222 | if (qstricmp(firstPart, "END") != 0) // No END ! |
206 | return; | 223 | return; |
207 | 224 | ||
208 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! | 225 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! |
209 | return; | 226 | return; |
210 | } | 227 | } |
211 | 228 | ||
212 | void | 229 | void |
213 | VCard::_assemble() | 230 | VCard::_assemble() |
214 | { | 231 | { |
215 | vDebug("Assembling vcard"); | 232 | vDebug("Assembling vcard"); |
216 | strRep_ = "BEGIN:VCARD\r\n"; | 233 | strRep_ = "BEGIN:VCARD\r\n"; |
217 | strRep_ += "VERSION:3.0\r\n"; | 234 | strRep_ += "VERSION:3.0\r\n"; |
218 | 235 | ||
219 | QPtrListIterator<ContentLine> it(contentLineList_); | 236 | QPtrListIterator<ContentLine> it(contentLineList_); |
220 | 237 | ||
221 | for (; it.current(); ++it) | 238 | for (; it.current(); ++it) |
222 | strRep_ += it.current()->asString() + "\r\n"; | 239 | strRep_ += it.current()->asString() + "\r\n"; |
223 | 240 | ||
224 | strRep_ += "END:VCARD\r\n"; | 241 | strRep_ += "END:VCARD\r\n"; |
225 | } | 242 | } |
226 | 243 | ||
227 | bool | 244 | bool |
228 | VCard::has(EntityType t) | 245 | VCard::has(EntityType t) |
229 | { | 246 | { |
230 | parse(); | 247 | parse(); |
231 | return contentLine(t) == 0 ? false : true; | 248 | return contentLine(t) == 0 ? false : true; |
232 | } | 249 | } |
233 | 250 | ||
234 | bool | 251 | bool |
235 | VCard::has(const QCString & s) | 252 | VCard::has(const QCString & s) |
236 | { | 253 | { |
237 | parse(); | 254 | parse(); |
238 | return contentLine(s) == 0 ? false : true; | 255 | return contentLine(s) == 0 ? false : true; |
239 | } | 256 | } |
240 | 257 | ||
241 | void | 258 | void |
242 | VCard::add(const ContentLine & cl) | 259 | VCard::add(const ContentLine & cl) |
243 | { | 260 | { |
244 | parse(); | 261 | parse(); |
245 | ContentLine * c = new ContentLine(cl); | 262 | ContentLine * c = new ContentLine(cl); |
246 | contentLineList_.append(c); | 263 | contentLineList_.append(c); |
247 | } | 264 | } |
248 | 265 | ||
249 | void | 266 | void |
250 | VCard::add(const QCString & s) | 267 | VCard::add(const QCString & s) |
251 | { | 268 | { |