author | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
commit | d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e (patch) (side-by-side diff) | |
tree | 9b723a5c4f7da306036495e35d1863fbee646984 /kabc/vcard | |
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 | 31 | ||||
-rw-r--r-- | kabc/vcard/VCardEntity.cpp | 3 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 23 |
3 files changed, 51 insertions, 6 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 @@ /* libvcard - vCard parsing library for vCard version 3.0 Copyright (C) 1999 Rik Hemsley rik@kde.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <qcstring.h> #include <qstrlist.h> #include <qregexp.h> #include <kdebug.h> #include <VCardAdrParam.h> #include <VCardAgentParam.h> #include <VCardDateParam.h> #include <VCardEmailParam.h> #include <VCardImageParam.h> #include <VCardSourceParam.h> #include <VCardTelParam.h> #include <VCardTextBinParam.h> #include <VCardTextParam.h> #include <VCardAdrValue.h> #include <VCardAgentValue.h> #include <VCardDateValue.h> #include <VCardImageValue.h> #include <VCardTextValue.h> #include <VCardTextBinValue.h> #include <VCardLangValue.h> #include <VCardNValue.h> #include <VCardURIValue.h> #include <VCardSoundValue.h> #include <VCardClassValue.h> #include <VCardFloatValue.h> #include <VCardOrgValue.h> #include <VCardTelValue.h> #include <VCardTextListValue.h> #include <VCardUTCValue.h> #include <VCardGeoValue.h> #include <VCardRToken.h> #include <VCardContentLine.h> #include <VCardEntity.h> #include <VCardEnum.h> #include <VCardDefines.h> using namespace VCARD; ContentLine::ContentLine() : Entity(), value_(0) { + paramList_.setAutoDelete( TRUE ); } ContentLine::ContentLine(const ContentLine & x) : Entity(x), group_ (x.group_), name_ (x.name_), - paramList_(x.paramList_), - value_(x.value_->clone()) +/*US paramList_(x.paramList_),*/ + value_(x.value_->clone()), + paramType_(x.paramType_), + valueType_(x.valueType_), + entityType_(x.entityType_) { + paramList_.setAutoDelete( TRUE ); + + + ParamListIterator it(x.paramList_); + for (; it.current(); ++it) + { + Param *p = new Param; + p->setName( it.current()->name() ); + p->setValue( it.current()->value() ); + paramList_.append(p); + } + } ContentLine::ContentLine(const QCString & s) : Entity(s), value_(0) { + paramList_.setAutoDelete( TRUE ); } ContentLine & ContentLine::operator = (ContentLine & x) { if (*this == x) return *this; - paramList_ = x.paramList(); + ParamListIterator it(x.paramList_); + for (; it.current(); ++it) + { + Param *p = new Param; + p->setName( it.current()->name() ); + p->setValue( it.current()->value() ); + paramList_.append(p); + } + value_ = x.value_->clone(); Entity::operator = (x); return *this; } ContentLine & ContentLine::operator = (const QCString & s) { Entity::operator = (s); delete value_; value_ = 0; return *this; } bool ContentLine::operator == (ContentLine & x) { x.parse(); QPtrListIterator<Param> it(x.paramList()); if (!paramList_.find(it.current())) return false; return true; } ContentLine::~ContentLine() { delete value_; value_ = 0; } void ContentLine::_parse() { vDebug("parse"); // Unqote newlines strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); int split = strRep_.find(':'); if (split == -1) { // invalid content line vDebug("No ':'"); return; } QCString firstPart(strRep_.left(split)); QCString valuePart(strRep_.mid(split + 1)); split = firstPart.find('.'); if (split != -1) { group_ = firstPart.left(split); firstPart = firstPart.mid(split + 1); } vDebug("Group == " + group_); vDebug("firstPart == " + firstPart); vDebug("valuePart == " + valuePart); // Now we have the group, the name and param list together and the value. QStrList l; RTokenise(firstPart, ";", l); if (l.count() == 0) {// invalid - no name ! vDebug("No name for this content line !"); return; } name_ = l.at(0); // Now we have the name, so the rest of 'l' is the params. // Remove the name part. l.remove(0u); entityType_ = EntityNameToEntityType(name_); paramType_ = EntityTypeToParamType(entityType_); unsigned int i = 0; // For each parameter, create a new parameter of the correct type. QStrListIterator it(l); for (; it.current(); ++it, i++) { QCString str = *it; split = str.find("="); if (split < 0 ) { vDebug("No '=' in paramter."); continue; } QCString paraName = str.left(split); QCString paraValue = str.mid(split + 1); QStrList paraValues; RTokenise(paraValue, ",", paraValues); QStrListIterator it2( paraValues ); for(; it2.current(); ++it2) { Param *p = new Param; p->setName( paraName ); p->setValue( *it2 ); paramList_.append(p); } } // Create a new value of the correct type. valueType_ = EntityTypeToValueType(entityType_); // kdDebug(5710) << "valueType: " << valueType_ << endl; switch (valueType_) { case ValueSound: value_ = new SoundValue; break; case ValueAgent: value_ = new AgentValue; break; case ValueAddress: value_ = new AdrValue; break; case ValueTel: value_ = new TelValue; break; case ValueTextBin: value_ = new TextBinValue; break; case ValueOrg: value_ = new OrgValue; break; case ValueN: value_ = new NValue; break; case ValueUTC: value_ = new UTCValue; break; case ValueURI: value_ = new URIValue; break; case ValueClass: value_ = new ClassValue; break; case ValueFloat: value_ = new FloatValue; break; case ValueImage: value_ = new ImageValue; break; case ValueDate: value_ = new DateValue; break; case ValueTextList: value_ = new TextListValue; break; case ValueGeo: value_ = new GeoValue; break; case ValueText: case ValueUnknown: default: value_ = new TextValue; break; } *value_ = valuePart; } void ContentLine::_assemble() { vDebug("Assemble (argl) - my name is \"" + name_ + "\""); strRep_.truncate(0); QCString line; if (!group_.isEmpty()) line += group_ + '.'; line += name_; vDebug("Adding parameters"); ParamListIterator it(paramList_); for (; it.current(); ++it) line += ";" + it.current()->asString(); vDebug("Adding value"); if (value_ != 0) line += ":" + value_->asString(); else vDebug("No value"); // Quote newlines line = line.replace( QRegExp( "\n" ), "\\n" ); // Fold lines longer than 72 chars const int maxLen = 72; uint cursor = 0; while( line.length() > ( cursor + 1 ) * maxLen ) { strRep_ += line.mid( cursor * maxLen, maxLen ); strRep_ += "\r\n "; ++cursor; } strRep_ += line.mid( cursor * maxLen ); } void ContentLine::clear() { group_.truncate(0); name_.truncate(0); paramList_.clear(); delete value_; value_ = 0; } 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 @@ /* libvcard - vCard parsing library for vCard version 3.0 Copyright (C) 1998 Rik Hemsley rik@kde.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <qregexp.h> #include <VCardDefines.h> #include <VCardVCardEntity.h> using namespace VCARD; VCardEntity::VCardEntity() : Entity() { + cardList_.setAutoDelete( TRUE ); } VCardEntity::VCardEntity(const VCardEntity & x) : Entity(x) { + cardList_.setAutoDelete( TRUE ); } VCardEntity::VCardEntity(const QCString & s) : Entity(s) { + cardList_.setAutoDelete( TRUE ); } VCardEntity & VCardEntity::operator = (VCardEntity & x) { if (*this == x) return *this; Entity::operator = (x); return *this; } VCardEntity & VCardEntity::operator = (const QCString & s) { Entity::operator = (s); return *this; } bool VCardEntity::operator == (VCardEntity & x) { x.parse(); return false; } VCardEntity::~VCardEntity() { } void VCardEntity::_parse() { vDebug("parse"); QCString s(strRep_); int i = s.find(QRegExp("BEGIN:VCARD", false)); while (i != -1) { i = s.find(QRegExp("BEGIN:VCARD", false), 11); QCString cardStr(s.left(i)); VCard * v = new VCard(cardStr); cardList_.append(v); v->parse(); s.remove(0, i); } } void VCardEntity::_assemble() { VCardListIterator it(cardList_); for (; it.current(); ++it) strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. } VCardList & VCardEntity::cardList() { parse(); return cardList_; } void VCardEntity::setCardList(const VCardList & l) { parse(); cardList_ = l; } 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,282 +1,299 @@ /* libvcard - vCard parsing library for vCard version 3.0 Copyright (C) 1998 Rik Hemsley rik@kde.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <qcstring.h> #include <qstrlist.h> #include <VCardEntity.h> #include <VCardVCard.h> #include <VCardContentLine.h> #include <VCardRToken.h> #include <VCardDefines.h> using namespace VCARD; VCard::VCard() : Entity() { + contentLineList_.setAutoDelete( TRUE ); } VCard::VCard(const VCard & x) : Entity(x), - group_(x.group_), - contentLineList_(x.contentLineList_) + group_(x.group_) { + contentLineList_.setAutoDelete( TRUE ); + //US + qDebug("VCard::VCard"); + + QPtrListIterator<ContentLine> it(x.contentLineList_); + for (; it.current(); ++it) { + ContentLine * c = new ContentLine(*it.current()); + contentLineList_.append(c); + } + } VCard::VCard(const QCString & s) : Entity(s) { + contentLineList_.setAutoDelete( TRUE ); } VCard & VCard::operator = (VCard & x) { + //US + qDebug("VCard::operator ="); if (*this == x) return *this; group_ = x.group(); - contentLineList_ = x.contentLineList_; + QPtrListIterator<ContentLine> it(x.contentLineList_); + for (; it.current(); ++it) { + ContentLine * c = new ContentLine(*it.current()); + contentLineList_.append(c); + } Entity::operator = (x); return *this; } VCard & VCard::operator = (const QCString & s) { Entity::operator = (s); return *this; } bool VCard::operator == (VCard & x) { x.parse(); return false; } VCard::~VCard() { } void VCard::_parse() { vDebug("parse() called"); QStrList l; RTokenise(strRep_, "\r\n", l); if (l.count() < 3) { // Invalid VCARD ! vDebug("Invalid vcard"); return; } // Get the first line QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); vDebug("Begin line == \"" + beginLine + "\""); // Remove extra blank lines while (QCString(l.last()).isEmpty()) l.remove(l.last()); // Now we know this is the last line QCString endLine = l.last(); // Trash the first and last lines as we have seen them. l.remove(0u); l.remove(l.last()); /////////////////////////////////////////////////////////////// // FIRST LINE int split = beginLine.find(':'); if (split == -1) { // invalid, no BEGIN vDebug("No split"); return; } QCString firstPart(beginLine.left(split)); QCString valuePart(beginLine.mid(split + 1)); split = firstPart.find('.'); if (split != -1) { group_ = firstPart.left(split); firstPart = firstPart.right(firstPart.length() - split - 1); } if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! vDebug("No BEGIN"); return; } if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! vDebug("No VCARD"); return; } /////////////////////////////////////////////////////////////// // CONTENT LINES // vDebug("Content lines"); // Handle folded lines. QStrList refolded; QStrListIterator it(l); QCString cur; for (; it.current(); ++it) { cur = it.current(); ++it; while ( it.current() && it.current()[0] == ' ' && strlen(it.current()) != 1) { cur += it.current() + 1; ++it; } --it; refolded.append(cur); } QStrListIterator it2(refolded); for (; it2.current(); ++it2) { vDebug("New contentline using \"" + QCString(it2.current()) + "\""); ContentLine * cl = new ContentLine(it2.current()); cl->parse(); contentLineList_.append(cl); } /////////////////////////////////////////////////////////////// // LAST LINE split = endLine.find(':'); if (split == -1) // invalid, no END return; firstPart = endLine.left(split); valuePart = endLine.right(firstPart.length() - split - 1); split = firstPart.find('.'); if (split != -1) { group_ = firstPart.left(split); firstPart = firstPart.right(firstPart.length() - split - 1); } if (qstricmp(firstPart, "END") != 0) // No END ! return; if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! return; } void VCard::_assemble() { vDebug("Assembling vcard"); strRep_ = "BEGIN:VCARD\r\n"; strRep_ += "VERSION:3.0\r\n"; QPtrListIterator<ContentLine> it(contentLineList_); for (; it.current(); ++it) strRep_ += it.current()->asString() + "\r\n"; strRep_ += "END:VCARD\r\n"; } bool VCard::has(EntityType t) { parse(); return contentLine(t) == 0 ? false : true; } bool VCard::has(const QCString & s) { parse(); return contentLine(s) == 0 ? false : true; } void VCard::add(const ContentLine & cl) { parse(); ContentLine * c = new ContentLine(cl); contentLineList_.append(c); } void VCard::add(const QCString & s) { parse(); ContentLine * c = new ContentLine(s); contentLineList_.append(c); } ContentLine * VCard::contentLine(EntityType t) { parse(); QPtrListIterator<ContentLine> it(contentLineList_); for (; it.current(); ++it) if (it.current()->entityType() == t) return it.current(); return 0; } ContentLine * VCard::contentLine(const QCString & s) { parse(); QPtrListIterator<ContentLine> it(contentLineList_); for (; it.current(); ++it) if (it.current()->entityType() == EntityNameToEntityType(s)) return it.current(); return 0; } |