summaryrefslogtreecommitdiffabout
path: root/kabc/vcard
authorulf69 <ulf69>2004-09-28 21:32:21 (UTC)
committer ulf69 <ulf69>2004-09-28 21:32:21 (UTC)
commit551a0bb353c7ffff4b307956a7cc7a023bf36863 (patch) (unidiff)
tree99a2f40f6c510f8ea2f482d481f2051bd9f2227d /kabc/vcard
parent57c00cdf5002e90603e0e1cfb5ac5c2c8bf19fe7 (diff)
downloadkdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.zip
kdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.tar.gz
kdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.tar.bz2
fixed a potential crash when loading adresses from any adressbook file.
Diffstat (limited to 'kabc/vcard') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/ContentLine.cpp10
-rw-r--r--kabc/vcard/VCardv.cpp12
-rw-r--r--kabc/vcard/include/VCardDefines.h3
3 files changed, 18 insertions, 7 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp
index 0fb5b5d..f7e04a9 100644
--- a/kabc/vcard/ContentLine.cpp
+++ b/kabc/vcard/ContentLine.cpp
@@ -1,292 +1,298 @@
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
65using namespace VCARD; 65using namespace VCARD;
66 66
67ContentLine::ContentLine() 67ContentLine::ContentLine()
68 :Entity(), 68 :Entity(),
69 value_(0) 69 value_(0),
70 paramType_( ParamUnknown ),
71 valueType_( ValueUnknown ),
72 entityType_( EntityUnknown )
70{ 73{
71 paramList_.setAutoDelete( TRUE ); 74 paramList_.setAutoDelete( TRUE );
72} 75}
73 76
74ContentLine::ContentLine(const ContentLine & x) 77ContentLine::ContentLine(const ContentLine & x)
75 :Entity(x), 78 :Entity(x),
76 group_ (x.group_), 79 group_ (x.group_),
77 name_ (x.name_), 80 name_ (x.name_),
78 /*US paramList_(x.paramList_),*/ 81 /*US paramList_(x.paramList_),*/
79 value_(x.value_->clone()), 82 value_(x.value_->clone()),
80 paramType_(x.paramType_), 83 paramType_(x.paramType_),
81 valueType_(x.valueType_), 84 valueType_(x.valueType_),
82 entityType_(x.entityType_) 85 entityType_(x.entityType_)
83{ 86{
84 paramList_.setAutoDelete( TRUE ); 87 paramList_.setAutoDelete( TRUE );
85 88
86 89
87 ParamListIterator it(x.paramList_); 90 ParamListIterator it(x.paramList_);
88 for (; it.current(); ++it) 91 for (; it.current(); ++it)
89 { 92 {
90 Param *p = new Param; 93 Param *p = new Param;
91 p->setName( it.current()->name() ); 94 p->setName( it.current()->name() );
92 p->setValue( it.current()->value() ); 95 p->setValue( it.current()->value() );
93 paramList_.append(p); 96 paramList_.append(p);
94 } 97 }
95 98
96} 99}
97 100
98ContentLine::ContentLine(const QCString & s) 101ContentLine::ContentLine(const QCString & s)
99 :Entity(s), 102 :Entity(s),
100 value_(0) 103 value_(0),
104 paramType_( ParamUnknown ),
105 valueType_( ValueUnknown ),
106 entityType_( EntityUnknown )
101{ 107{
102 paramList_.setAutoDelete( TRUE ); 108 paramList_.setAutoDelete( TRUE );
103} 109}
104 110
105 ContentLine & 111 ContentLine &
106ContentLine::operator = (ContentLine & x) 112ContentLine::operator = (ContentLine & x)
107{ 113{
108 if (*this == x) return *this; 114 if (*this == x) return *this;
109 115
110 ParamListIterator it(x.paramList_); 116 ParamListIterator it(x.paramList_);
111 for (; it.current(); ++it) 117 for (; it.current(); ++it)
112 { 118 {
113 Param *p = new Param; 119 Param *p = new Param;
114 p->setName( it.current()->name() ); 120 p->setName( it.current()->name() );
115 p->setValue( it.current()->value() ); 121 p->setValue( it.current()->value() );
116 paramList_.append(p); 122 paramList_.append(p);
117 } 123 }
118 124
119 value_ = x.value_->clone(); 125 value_ = x.value_->clone();
120 126
121 Entity::operator = (x); 127 Entity::operator = (x);
122 return *this; 128 return *this;
123} 129}
124 130
125 ContentLine & 131 ContentLine &
126ContentLine::operator = (const QCString & s) 132ContentLine::operator = (const QCString & s)
127{ 133{
128 Entity::operator = (s); 134 Entity::operator = (s);
129 delete value_; 135 delete value_;
130 value_ = 0; 136 value_ = 0;
131 return *this; 137 return *this;
132} 138}
133 139
134 bool 140 bool
135ContentLine::operator == (ContentLine & x) 141ContentLine::operator == (ContentLine & x)
136{ 142{
137 x.parse(); 143 x.parse();
138 144
139 QPtrListIterator<Param> it(x.paramList()); 145 QPtrListIterator<Param> it(x.paramList());
140 146
141 if (!paramList_.find(it.current())) 147 if (!paramList_.find(it.current()))
142 return false; 148 return false;
143 149
144 return true; 150 return true;
145} 151}
146 152
147ContentLine::~ContentLine() 153ContentLine::~ContentLine()
148{ 154{
149 delete value_; 155 delete value_;
150 value_ = 0; 156 value_ = 0;
151} 157}
152 158
153 void 159 void
154ContentLine::_parse() 160ContentLine::_parse()
155{ 161{
156 vDebug("parse"); 162 vDebug("parse");
157 163
158 // Unqote newlines 164 // Unqote newlines
159 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); 165 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" );
160 166
161 int split = strRep_.find(':'); 167 int split = strRep_.find(':');
162 168
163 if (split == -1) { // invalid content line 169 if (split == -1) { // invalid content line
164 vDebug("No ':'"); 170 vDebug("No ':'");
165 return; 171 return;
166 } 172 }
167 173
168 QCString firstPart(strRep_.left(split)); 174 QCString firstPart(strRep_.left(split));
169 QCString valuePart(strRep_.mid(split + 1)); 175 QCString valuePart(strRep_.mid(split + 1));
170 176
171 split = firstPart.find('.'); 177 split = firstPart.find('.');
172 178
173 if (split != -1) { 179 if (split != -1) {
174 group_ = firstPart.left(split); 180 group_ = firstPart.left(split);
175 firstPart= firstPart.mid(split + 1); 181 firstPart= firstPart.mid(split + 1);
176 } 182 }
177 183
178 vDebug("Group == " + group_); 184 vDebug("Group == " + group_);
179 vDebug("firstPart == " + firstPart); 185 vDebug("firstPart == " + firstPart);
180 vDebug("valuePart == " + valuePart); 186 vDebug("valuePart == " + valuePart);
181 187
182 // Now we have the group, the name and param list together and the value. 188 // Now we have the group, the name and param list together and the value.
183 189
184 QStrList l; 190 QStrList l;
185 191
186 RTokenise(firstPart, ";", l); 192 RTokenise(firstPart, ";", l);
187 193
188 if (l.count() == 0) {// invalid - no name ! 194 if (l.count() == 0) {// invalid - no name !
189 vDebug("No name for this content line !"); 195 vDebug("No name for this content line !");
190 return; 196 return;
191 } 197 }
192 198
193 name_ = l.at(0); 199 name_ = l.at(0);
194 200
195 // Now we have the name, so the rest of 'l' is the params. 201 // Now we have the name, so the rest of 'l' is the params.
196 // Remove the name part. 202 // Remove the name part.
197 l.remove(0u); 203 l.remove(0u);
198 204
199 entityType_= EntityNameToEntityType(name_); 205 entityType_= EntityNameToEntityType(name_);
200 paramType_= EntityTypeToParamType(entityType_); 206 paramType_= EntityTypeToParamType(entityType_);
201 207
202 unsigned int i = 0; 208 unsigned int i = 0;
203 209
204 // For each parameter, create a new parameter of the correct type. 210 // For each parameter, create a new parameter of the correct type.
205 211
206 QStrListIterator it(l); 212 QStrListIterator it(l);
207 213
208 for (; it.current(); ++it, i++) { 214 for (; it.current(); ++it, i++) {
209 215
210 QCString str = *it; 216 QCString str = *it;
211 217
212 split = str.find("="); 218 split = str.find("=");
213 if (split < 0 ) { 219 if (split < 0 ) {
214 vDebug("No '=' in paramter."); 220 vDebug("No '=' in paramter.");
215 continue; 221 continue;
216 } 222 }
217 223
218 QCString paraName = str.left(split); 224 QCString paraName = str.left(split);
219 QCString paraValue = str.mid(split + 1); 225 QCString paraValue = str.mid(split + 1);
220 226
221 QStrList paraValues; 227 QStrList paraValues;
222 RTokenise(paraValue, ",", paraValues); 228 RTokenise(paraValue, ",", paraValues);
223 229
224 QStrListIterator it2( paraValues ); 230 QStrListIterator it2( paraValues );
225 231
226 for(; it2.current(); ++it2) { 232 for(; it2.current(); ++it2) {
227 233
228 Param *p = new Param; 234 Param *p = new Param;
229 p->setName( paraName ); 235 p->setName( paraName );
230 p->setValue( *it2 ); 236 p->setValue( *it2 );
231 237
232 paramList_.append(p); 238 paramList_.append(p);
233 } 239 }
234 } 240 }
235 241
236 // Create a new value of the correct type. 242 // Create a new value of the correct type.
237 243
238 valueType_ = EntityTypeToValueType(entityType_); 244 valueType_ = EntityTypeToValueType(entityType_);
239 245
240 //kdDebug(5710) << "valueType: " << valueType_ << endl; 246 //kdDebug(5710) << "valueType: " << valueType_ << endl;
241 247
242 switch (valueType_) { 248 switch (valueType_) {
243 249
244 case ValueSound: value_ = new SoundValue;break; 250 case ValueSound: value_ = new SoundValue;break;
245 case ValueAgent: value_ = new AgentValue;break; 251 case ValueAgent: value_ = new AgentValue;break;
246 case ValueAddress: value_ = new AdrValue; break; 252 case ValueAddress: value_ = new AdrValue; break;
247 case ValueTel: value_ = new TelValue; break; 253 case ValueTel: value_ = new TelValue; break;
248 case ValueTextBin: value_ = new TextBinValue;break; 254 case ValueTextBin: value_ = new TextBinValue;break;
249 case ValueOrg: value_ = new OrgValue; break; 255 case ValueOrg: value_ = new OrgValue; break;
250 case ValueN: value_ = new NValue; break; 256 case ValueN: value_ = new NValue; break;
251 case ValueUTC: value_ = new UTCValue; break; 257 case ValueUTC: value_ = new UTCValue; break;
252 case ValueURI: value_ = new URIValue; break; 258 case ValueURI: value_ = new URIValue; break;
253 case ValueClass: value_ = new ClassValue;break; 259 case ValueClass: value_ = new ClassValue;break;
254 case ValueFloat: value_ = new FloatValue;break; 260 case ValueFloat: value_ = new FloatValue;break;
255 case ValueImage: value_ = new ImageValue;break; 261 case ValueImage: value_ = new ImageValue;break;
256 case ValueDate: value_ = new DateValue; break; 262 case ValueDate: value_ = new DateValue; break;
257 case ValueTextList: value_ = new TextListValue;break; 263 case ValueTextList: value_ = new TextListValue;break;
258 case ValueGeo: value_ = new GeoValue; break; 264 case ValueGeo: value_ = new GeoValue; break;
259 case ValueText: 265 case ValueText:
260 case ValueUnknown: 266 case ValueUnknown:
261 default: value_ = new TextValue; break; 267 default: value_ = new TextValue; break;
262 } 268 }
263 269
264 *value_ = valuePart; 270 *value_ = valuePart;
265} 271}
266 272
267 void 273 void
268ContentLine::_assemble() 274ContentLine::_assemble()
269{ 275{
270 vDebug("Assemble (argl) - my name is \"" + name_ + "\""); 276 vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
271 strRep_.truncate(0); 277 strRep_.truncate(0);
272 278
273 QCString line; 279 QCString line;
274 280
275 if (!group_.isEmpty()) 281 if (!group_.isEmpty())
276 line += group_ + '.'; 282 line += group_ + '.';
277 283
278 line += name_; 284 line += name_;
279 285
280 vDebug("Adding parameters"); 286 vDebug("Adding parameters");
281 ParamListIterator it(paramList_); 287 ParamListIterator it(paramList_);
282 288
283 for (; it.current(); ++it) 289 for (; it.current(); ++it)
284 line += ";" + it.current()->asString(); 290 line += ";" + it.current()->asString();
285 291
286 vDebug("Adding value"); 292 vDebug("Adding value");
287 if (value_ != 0) 293 if (value_ != 0)
288 line += ":" + value_->asString(); 294 line += ":" + value_->asString();
289 else 295 else
290 vDebug("No value"); 296 vDebug("No value");
291 297
292 // Quote newlines 298 // Quote newlines
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp
index 391a69e..d19a004 100644
--- a/kabc/vcard/VCardv.cpp
+++ b/kabc/vcard/VCardv.cpp
@@ -1,295 +1,299 @@
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
34using namespace VCARD; 34using namespace VCARD;
35 35
36VCard::VCard() 36VCard::VCard()
37 :Entity() 37 :Entity()
38{ 38{
39 contentLineList_.setAutoDelete( TRUE ); 39 contentLineList_.setAutoDelete( TRUE );
40} 40}
41 41
42VCard::VCard(const VCard & x) 42VCard::VCard(const VCard & x)
43 :Entity(x), 43 :Entity(x),
44 group_(x.group_) 44 group_(x.group_)
45{ 45{
46 contentLineList_.setAutoDelete( TRUE ); 46 contentLineList_.setAutoDelete( TRUE );
47 47
48 QPtrListIterator<ContentLine> it(x.contentLineList_); 48 QPtrListIterator<ContentLine> it(x.contentLineList_);
49 for (; it.current(); ++it) { 49 for (; it.current(); ++it) {
50 ContentLine * c = new ContentLine(*it.current()); 50 ContentLine * c = new ContentLine(*it.current());
51 contentLineList_.append(c); 51 contentLineList_.append(c);
52 } 52 }
53 53
54} 54}
55 55
56VCard::VCard(const QCString & s) 56VCard::VCard(const QCString & s)
57 :Entity(s) 57 :Entity(s)
58{ 58{
59 contentLineList_.setAutoDelete( TRUE ); 59 contentLineList_.setAutoDelete( TRUE );
60} 60}
61 61
62 VCard & 62 VCard &
63VCard::operator = (VCard & x) 63VCard::operator = (VCard & x)
64{ 64{
65 if (*this == x) return *this; 65 if (*this == x) return *this;
66 66
67 group_ = x.group(); 67 group_ = x.group();
68 QPtrListIterator<ContentLine> it(x.contentLineList_); 68 QPtrListIterator<ContentLine> it(x.contentLineList_);
69 for (; it.current(); ++it) { 69 for (; it.current(); ++it) {
70 ContentLine * c = new ContentLine(*it.current()); 70 ContentLine * c = new ContentLine(*it.current());
71 contentLineList_.append(c); 71 contentLineList_.append(c);
72 } 72 }
73 73
74 Entity::operator = (x); 74 Entity::operator = (x);
75 return *this; 75 return *this;
76} 76}
77 77
78 VCard & 78 VCard &
79VCard::operator = (const QCString & s) 79VCard::operator = (const QCString & s)
80{ 80{
81 Entity::operator = (s); 81 Entity::operator = (s);
82 return *this; 82 return *this;
83} 83}
84 84
85 bool 85 bool
86VCard::operator == (VCard & x) 86VCard::operator == (VCard & x)
87{ 87{
88 x.parse(); 88 x.parse();
89 return false; 89 return false;
90} 90}
91 91
92VCard::~VCard() 92VCard::~VCard()
93{ 93{
94} 94}
95 95
96 void 96 void
97VCard::_parse() 97VCard::_parse()
98{ 98{
99 vDebug("parse() called"); 99 vDebug("parse() called");
100 QStrList l; 100 QStrList l;
101 101
102 RTokenise(strRep_, "\r\n", l); 102 RTokenise(strRep_, "\r\n", l);
103 103
104 if (l.count() < 3) { // Invalid VCARD ! 104 if (l.count() < 3) { // Invalid VCARD !
105 vDebug("Invalid vcard"); 105 vDebug("Invalid vcard");
106 return; 106 return;
107 } 107 }
108 108
109 // Get the first line 109 // Get the first line
110 QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); 110 QCString beginLine = QCString(l.at(0)).stripWhiteSpace();
111 111
112 vDebug("Begin line == \"" + beginLine + "\""); 112 vDebug("Begin line == \"" + beginLine + "\"");
113 113
114 // Remove extra blank lines 114 // Remove extra blank lines
115 while (QCString(l.last()).isEmpty()) 115 while (QCString(l.last()).isEmpty())
116 l.remove(l.last()); 116 l.remove(l.last());
117 117
118 // Now we know this is the last line 118 // Now we know this is the last line
119 QCString endLine = l.last(); 119 QCString endLine = l.last();
120 120
121 // Trash the first and last lines as we have seen them. 121 // Trash the first and last lines as we have seen them.
122 l.remove(0u); 122 l.remove(0u);
123 l.remove(l.last()); 123 l.remove(l.last());
124 124
125 /////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////
126 // FIRST LINE 126 // FIRST LINE
127 127
128 int split = beginLine.find(':'); 128 int split = beginLine.find(':');
129 129
130 if (split == -1) { // invalid, no BEGIN 130 if (split == -1) { // invalid, no BEGIN
131 vDebug("No split"); 131 vDebug("No split");
132 return; 132 return;
133 } 133 }
134 134
135 QCString firstPart(beginLine.left(split)); 135 QCString firstPart(beginLine.left(split));
136 QCString valuePart(beginLine.mid(split + 1)); 136 QCString valuePart(beginLine.mid(split + 1));
137 137
138 split = firstPart.find('.'); 138 split = firstPart.find('.');
139 139
140 if (split != -1) { 140 if (split != -1) {
141 group_ = firstPart.left(split); 141 group_ = firstPart.left(split);
142 firstPart= firstPart.right(firstPart.length() - split - 1); 142 firstPart= firstPart.right(firstPart.length() - split - 1);
143 } 143 }
144 144
145 if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! 145 if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN !
146 vDebug("No BEGIN"); 146 vDebug("No BEGIN");
147 return; 147 return;
148 } 148 }
149 149
150 if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! 150 if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard !
151 vDebug("No VCARD"); 151 vDebug("No VCARD");
152 return; 152 return;
153 } 153 }
154 154
155 /////////////////////////////////////////////////////////////// 155 ///////////////////////////////////////////////////////////////
156 // CONTENT LINES 156 // CONTENT LINES
157 // 157 //
158 vDebug("Content lines"); 158 vDebug("Content lines");
159 159
160 // Handle folded lines. 160 // Handle folded lines.
161 161
162 QStrList refolded; 162 QStrList refolded;
163 163
164 QStrListIterator it(l); 164 QStrListIterator it(l);
165 165
166 QCString cur; 166 QCString cur;
167 167
168 for (; it.current(); ++it) { 168 for (; it.current(); ++it) {
169 169
170 cur = it.current(); 170 cur = it.current();
171 171
172 ++it; 172 ++it;
173 173
174 while ( 174 while (
175 it.current() && 175 it.current() &&
176 it.current()[0] == ' '&& 176 it.current()[0] == ' '&&
177 strlen(it.current()) != 1) 177 strlen(it.current()) != 1)
178 { 178 {
179 cur += it.current() + 1; 179 cur += it.current() + 1;
180 ++it; 180 ++it;
181 } 181 }
182 182
183 --it; 183 --it;
184 184
185 refolded.append(cur); 185 refolded.append(cur);
186 } 186 }
187 187
188 QStrListIterator it2(refolded); 188 QStrListIterator it2(refolded);
189 189
190 for (; it2.current(); ++it2) { 190 for (; it2.current(); ++it2) {
191 191 vDebug("New contentline using \"" + QCString(it2.current()) + "\"");
192 vDebug("New contentline using \"" + QCString(it2.current()) + "\"");
193 ContentLine * cl = new ContentLine(it2.current()); 192 ContentLine * cl = new ContentLine(it2.current());
194 193
195 cl->parse(); 194 cl->parse();
196 195 if (cl->value() == 0)
197 contentLineList_.append(cl); 196 {
197 qDebug("Content line could not be parsed. Discarded: %s" + QCString(it2.current()));
198 delete cl;
199 }
200 else
201 contentLineList_.append(cl);
198 } 202 }
199 203
200 /////////////////////////////////////////////////////////////// 204 ///////////////////////////////////////////////////////////////
201 // LAST LINE 205 // LAST LINE
202 206
203 split = endLine.find(':'); 207 split = endLine.find(':');
204 208
205 if (split == -1) // invalid, no END 209 if (split == -1) // invalid, no END
206 return; 210 return;
207 211
208 firstPart = endLine.left(split); 212 firstPart = endLine.left(split);
209 valuePart = endLine.right(firstPart.length() - split - 1); 213 valuePart = endLine.right(firstPart.length() - split - 1);
210 214
211 split = firstPart.find('.'); 215 split = firstPart.find('.');
212 216
213 if (split != -1) { 217 if (split != -1) {
214 group_ = firstPart.left(split); 218 group_ = firstPart.left(split);
215 firstPart= firstPart.right(firstPart.length() - split - 1); 219 firstPart= firstPart.right(firstPart.length() - split - 1);
216 } 220 }
217 221
218 if (qstricmp(firstPart, "END") != 0) // No END ! 222 if (qstricmp(firstPart, "END") != 0) // No END !
219 return; 223 return;
220 224
221 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! 225 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard !
222 return; 226 return;
223} 227}
224 228
225 void 229 void
226VCard::_assemble() 230VCard::_assemble()
227{ 231{
228 vDebug("Assembling vcard"); 232 vDebug("Assembling vcard");
229 strRep_ = "BEGIN:VCARD\r\n"; 233 strRep_ = "BEGIN:VCARD\r\n";
230 strRep_ += "VERSION:3.0\r\n"; 234 strRep_ += "VERSION:3.0\r\n";
231 235
232 QPtrListIterator<ContentLine> it(contentLineList_); 236 QPtrListIterator<ContentLine> it(contentLineList_);
233 237
234 for (; it.current(); ++it) 238 for (; it.current(); ++it)
235 strRep_ += it.current()->asString() + "\r\n"; 239 strRep_ += it.current()->asString() + "\r\n";
236 240
237 strRep_ += "END:VCARD\r\n"; 241 strRep_ += "END:VCARD\r\n";
238} 242}
239 243
240 bool 244 bool
241VCard::has(EntityType t) 245VCard::has(EntityType t)
242{ 246{
243 parse(); 247 parse();
244 return contentLine(t) == 0 ? false : true; 248 return contentLine(t) == 0 ? false : true;
245} 249}
246 250
247 bool 251 bool
248VCard::has(const QCString & s) 252VCard::has(const QCString & s)
249{ 253{
250 parse(); 254 parse();
251 return contentLine(s) == 0 ? false : true; 255 return contentLine(s) == 0 ? false : true;
252} 256}
253 257
254 void 258 void
255VCard::add(const ContentLine & cl) 259VCard::add(const ContentLine & cl)
256{ 260{
257 parse(); 261 parse();
258 ContentLine * c = new ContentLine(cl); 262 ContentLine * c = new ContentLine(cl);
259 contentLineList_.append(c); 263 contentLineList_.append(c);
260} 264}
261 265
262 void 266 void
263VCard::add(const QCString & s) 267VCard::add(const QCString & s)
264{ 268{
265 parse(); 269 parse();
266 ContentLine * c = new ContentLine(s); 270 ContentLine * c = new ContentLine(s);
267 contentLineList_.append(c); 271 contentLineList_.append(c);
268} 272}
269 273
270 ContentLine * 274 ContentLine *
271VCard::contentLine(EntityType t) 275VCard::contentLine(EntityType t)
272{ 276{
273 parse(); 277 parse();
274 QPtrListIterator<ContentLine> it(contentLineList_); 278 QPtrListIterator<ContentLine> it(contentLineList_);
275 279
276 for (; it.current(); ++it) 280 for (; it.current(); ++it)
277 if (it.current()->entityType() == t) 281 if (it.current()->entityType() == t)
278 return it.current(); 282 return it.current();
279 283
280 return 0; 284 return 0;
281} 285}
282 286
283 ContentLine * 287 ContentLine *
284VCard::contentLine(const QCString & s) 288VCard::contentLine(const QCString & s)
285{ 289{
286 parse(); 290 parse();
287 QPtrListIterator<ContentLine> it(contentLineList_); 291 QPtrListIterator<ContentLine> it(contentLineList_);
288 292
289 for (; it.current(); ++it) 293 for (; it.current(); ++it)
290 if (it.current()->entityType() == EntityNameToEntityType(s)) 294 if (it.current()->entityType() == EntityNameToEntityType(s))
291 return it.current(); 295 return it.current();
292 296
293 return 0; 297 return 0;
294} 298}
295 299
diff --git a/kabc/vcard/include/VCardDefines.h b/kabc/vcard/include/VCardDefines.h
index dd38ae2..557410f 100644
--- a/kabc/vcard/include/VCardDefines.h
+++ b/kabc/vcard/include/VCardDefines.h
@@ -1,52 +1,53 @@
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#ifndef VCARD_DEFINES_H 24#ifndef VCARD_DEFINES_H
25#define VCARD_DEFINES_H 25#define VCARD_DEFINES_H
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28 28
29#ifdef VCARD_DEBUG 29#ifdef VCARD_DEBUG
30#define vDebug(a) kdDebug(5710) << a << endl; 30//US #define vDebug(a) kdDebug(5710) << a << endl;
31#define vDebug(a) qDebug(a);
31#else 32#else
32#define vDebug(a) 33#define vDebug(a)
33#endif 34#endif
34 35
35#if 0 36#if 0
36#ifndef NDEBUG 37#ifndef NDEBUG
37 #include <qcstring.h> 38 #include <qcstring.h>
38 #include <iostream> 39 #include <iostream>
39 #ifdef __GNUG__ 40 #ifdef __GNUG__
40 # define vDebug(a) cerr << className() << ":" << __FUNCTION__ << " (" \ 41 # define vDebug(a) cerr << className() << ":" << __FUNCTION__ << " (" \
41 << __LINE__ << "): " << QCString((a)).data() << endl; 42 << __LINE__ << "): " << QCString((a)).data() << endl;
42 #else 43 #else
43 # define vDebug(a) cerr << className() << ": " \ 44 # define vDebug(a) cerr << className() << ": " \
44 << QCString((a)).data() << endl; 45 << QCString((a)).data() << endl;
45 #endif 46 #endif
46#else 47#else
47 #define vDebug(a) 48 #define vDebug(a)
48#endif 49#endif
49#endif 50#endif
50 51
51#endif // Included this file 52#endif // Included this file
52 53