author | ulf69 <ulf69> | 2004-09-28 21:32:21 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-28 21:32:21 (UTC) |
commit | 551a0bb353c7ffff4b307956a7cc7a023bf36863 (patch) (unidiff) | |
tree | 99a2f40f6c510f8ea2f482d481f2051bd9f2227d /kabc | |
parent | 57c00cdf5002e90603e0e1cfb5ac5c2c8bf19fe7 (diff) | |
download | kdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.zip kdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.tar.gz kdepimpi-551a0bb353c7ffff4b307956a7cc7a023bf36863.tar.bz2 |
fixed a potential crash when loading adresses from any adressbook file.
-rw-r--r-- | kabc/vcard/ContentLine.cpp | 10 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 12 | ||||
-rw-r--r-- | kabc/vcard/include/VCardDefines.h | 3 | ||||
-rw-r--r-- | kabc/vcardformatimpl.cpp | 2 |
4 files changed, 20 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 | |||
@@ -45,80 +45,86 @@ | |||
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 | paramType_( ParamUnknown ), | ||
71 | valueType_( ValueUnknown ), | ||
72 | entityType_( EntityUnknown ) | ||
70 | { | 73 | { |
71 | paramList_.setAutoDelete( TRUE ); | 74 | paramList_.setAutoDelete( TRUE ); |
72 | } | 75 | } |
73 | 76 | ||
74 | ContentLine::ContentLine(const ContentLine & x) | 77 | ContentLine::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 | ||
98 | ContentLine::ContentLine(const QCString & s) | 101 | ContentLine::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 & |
106 | ContentLine::operator = (ContentLine & x) | 112 | ContentLine::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 | ||
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 | |||
@@ -167,55 +167,59 @@ VCard::_parse() | |||
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 ! |
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 | |||
@@ -6,47 +6,48 @@ | |||
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 | ||
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index 2d6eb3d..1bf2cde 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -240,48 +240,49 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) | |||
240 | 240 | ||
241 | case EntityKey: | 241 | case EntityKey: |
242 | addressee.insertKey( readKeyValue( cl ) ); | 242 | addressee.insertKey( readKeyValue( cl ) ); |
243 | break; | 243 | break; |
244 | 244 | ||
245 | case EntityPhoto: | 245 | case EntityPhoto: |
246 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); | 246 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); |
247 | break; | 247 | break; |
248 | 248 | ||
249 | case EntityLogo: | 249 | case EntityLogo: |
250 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); | 250 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); |
251 | break; | 251 | break; |
252 | 252 | ||
253 | case EntityAgent: | 253 | case EntityAgent: |
254 | addressee.setAgent( readAgentValue( cl ) ); | 254 | addressee.setAgent( readAgentValue( cl ) ); |
255 | break; | 255 | break; |
256 | 256 | ||
257 | case EntitySound: | 257 | case EntitySound: |
258 | addressee.setSound( readSoundValue( cl, addressee ) ); | 258 | addressee.setSound( readSoundValue( cl, addressee ) ); |
259 | break; | 259 | break; |
260 | 260 | ||
261 | default: | 261 | default: |
262 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " | 262 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " |
263 | << int( type ) << ": " << cl->asString() << endl; | 263 | << int( type ) << ": " << cl->asString() << endl; |
264 | qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString()); | ||
264 | break; | 265 | break; |
265 | } | 266 | } |
266 | } | 267 | } |
267 | 268 | ||
268 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 269 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
269 | EntityType type = cl->entityType(); | 270 | EntityType type = cl->entityType(); |
270 | if ( type == EntityLabel ) { | 271 | if ( type == EntityLabel ) { |
271 | int type = readAddressParam( cl ); | 272 | int type = readAddressParam( cl ); |
272 | Address address = addressee.address( type ); | 273 | Address address = addressee.address( type ); |
273 | if ( address.isEmpty() ) | 274 | if ( address.isEmpty() ) |
274 | address.setType( type ); | 275 | address.setType( type ); |
275 | 276 | ||
276 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); | 277 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); |
277 | addressee.insertAddress( address ); | 278 | addressee.insertAddress( address ); |
278 | } | 279 | } |
279 | } | 280 | } |
280 | 281 | ||
281 | return true; | 282 | return true; |
282 | } | 283 | } |
283 | 284 | ||
284 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) | 285 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) |
285 | { | 286 | { |
286 | //US ContentLine cl; | 287 | //US ContentLine cl; |
287 | //US QString value; | 288 | //US QString value; |
@@ -618,48 +619,49 @@ PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) | |||
618 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; | 619 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; |
619 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; | 620 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; |
620 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; | 621 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; |
621 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; | 622 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; |
622 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; | 623 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; |
623 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; | 624 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; |
624 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; | 625 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; |
625 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; | 626 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; |
626 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; | 627 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; |
627 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; | 628 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; |
628 | } | 629 | } |
629 | } | 630 | } |
630 | p.setType( type ); | 631 | p.setType( type ); |
631 | 632 | ||
632 | return p; | 633 | return p; |
633 | } | 634 | } |
634 | 635 | ||
635 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) | 636 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) |
636 | { | 637 | { |
637 | VCARD::Value *value = cl->value(); | 638 | VCARD::Value *value = cl->value(); |
638 | if ( value ) { | 639 | if ( value ) { |
639 | return QString::fromUtf8( value->asString() ); | 640 | return QString::fromUtf8( value->asString() ); |
640 | } else { | 641 | } else { |
641 | kdDebug(5700) << "No value: " << cl->asString() << endl; | 642 | kdDebug(5700) << "No value: " << cl->asString() << endl; |
643 | qDebug("No value: %s", (const char*)(cl->asString())); | ||
642 | return QString::null; | 644 | return QString::null; |
643 | } | 645 | } |
644 | } | 646 | } |
645 | 647 | ||
646 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) | 648 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) |
647 | { | 649 | { |
648 | DateValue *dateValue = (DateValue *)cl->value(); | 650 | DateValue *dateValue = (DateValue *)cl->value(); |
649 | if ( dateValue ) | 651 | if ( dateValue ) |
650 | return dateValue->qdate(); | 652 | return dateValue->qdate(); |
651 | else | 653 | else |
652 | return QDate(); | 654 | return QDate(); |
653 | } | 655 | } |
654 | 656 | ||
655 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) | 657 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) |
656 | { | 658 | { |
657 | DateValue *dateValue = (DateValue *)cl->value(); | 659 | DateValue *dateValue = (DateValue *)cl->value(); |
658 | if ( dateValue ) | 660 | if ( dateValue ) |
659 | return dateValue->qdt(); | 661 | return dateValue->qdt(); |
660 | else | 662 | else |
661 | return QDateTime(); | 663 | return QDateTime(); |
662 | } | 664 | } |
663 | 665 | ||
664 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) | 666 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) |
665 | { | 667 | { |