summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/serializer.cpp
Side-by-side diff
Diffstat (limited to 'pwmanager/pwmanager/serializer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/serializer.cpp126
1 files changed, 75 insertions, 51 deletions
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index 203f82c..5c6568f 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -29,3 +29,3 @@
/* enable/disable serializer debugging (0/1) */
-#define SERIALIZER_DEBUG 0
+#define SERIALIZER_DEBUG 1
/* use the old xml tags for writing (0/1) */
@@ -306,2 +306,6 @@ bool Serializer::readEntries(const QDomNode &n,
PwMDataItem curEntr;
+ //US BUG: to initialize all values of curEntr with meaningfulldata,
+ // we call clear on it. Reason: Information in the file we will read might be incomplete.
+ // e.g. the metadata is missing.
+ curEntr.clear(true);
@@ -403,32 +407,38 @@ bool Serializer::extractMeta(const QDomNode &n,
}
+
+ //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers.
+ //because of that it is possible that here some values are not set, which means they are null.
+ //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates.
+
+ QDateTime dtval; //dtval should be invalid by definition.
+
+ if ((name == META_CREATE_DATE) ||
+ (name == META_VALID_DATE) ||
+ (name == META_EXPIRE_DATE) ||
+ (name == META_UPDATE_DATE))
+ {
+ //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length());
+
#ifndef PWM_EMBEDDED
- if (name == META_CREATE_DATE) {
- dta->create = QDateTime::fromString(val, Qt::ISODate);
- } else if (name == META_VALID_DATE) {
- dta->valid = QDateTime::fromString(val, Qt::ISODate);
- } else if (name == META_EXPIRE_DATE) {
- dta->expire = QDateTime::fromString(val, Qt::ISODate);
- } else if (name == META_UPDATE_DATE) {
- dta->update = QDateTime::fromString(val, Qt::ISODate);
- } else if (name == META_UPDATE_INT) {
- dta->updateInt = strtoul(val.latin1(), 0, 10);
- } else if (name == META_UNIQUEID) {
- dta->uniqueid = unescapeEntryData(val).latin1();
- } else {
- printDebug(string("extractMeta(): invalid: ")
- + name.latin1());
- }
+ dtval = QDateTime::fromString(val, Qt::ISODate);
#else
+ bool ok;
+ dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+
+ if (ok == false)
+ qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
+#endif
+ //if the parsed data is wrong, dtval should be invalid at this time.
- bool ok = true;
+ }
if (name == META_CREATE_DATE) {
- dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+ dta->create = dtval;
} else if (name == META_VALID_DATE) {
- dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+ dta->valid = dtval;
} else if (name == META_EXPIRE_DATE) {
- dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+ dta->expire = dtval;
} else if (name == META_UPDATE_DATE) {
- dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+ dta->update = dtval;
} else if (name == META_UPDATE_INT) {
@@ -442,7 +452,2 @@ bool Serializer::extractMeta(const QDomNode &n,
- if (ok == false)
- qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
-
-
-#endif
cur = cur.nextSibling();
@@ -606,37 +611,57 @@ bool Serializer::writeMeta(QDomElement *e,
- tag = domDoc->createElement(META_CREATE_DATE);
+ //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
+ //So do not transform an empty value at all.
+ if (dta.create.isValid())
+ {
+ tag = domDoc->createElement(META_CREATE_DATE);
#ifndef PWM_EMBEDDED
- text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
+ text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
#else
- text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
+ text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
#endif
- tag.appendChild(text);
- e->appendChild(tag);
+ tag.appendChild(text);
+ e->appendChild(tag);
+ }
- tag = domDoc->createElement(META_VALID_DATE);
+ //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
+ //So do not transform an empty value at all.
+ if (dta.valid.isValid())
+ {
+ tag = domDoc->createElement(META_VALID_DATE);
#ifndef PWM_EMBEDDED
- text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
+ text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
#else
- text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
+ text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
#endif
- tag.appendChild(text);
- e->appendChild(tag);
+ tag.appendChild(text);
+ e->appendChild(tag);
+ }
- tag = domDoc->createElement(META_EXPIRE_DATE);
+ //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
+ //So do not transform an empty value at all.
+ if (dta.expire.isValid())
+ {
+ tag = domDoc->createElement(META_EXPIRE_DATE);
#ifndef PWM_EMBEDDED
- text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
+ text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
#else
- text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
+ text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
#endif
- tag.appendChild(text);
- e->appendChild(tag);
+ tag.appendChild(text);
+ e->appendChild(tag);
+ }
- tag = domDoc->createElement(META_UPDATE_DATE);
+ //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
+ //So do not transform an empty value at all.
+ if (dta.update.isValid())
+ {
+ tag = domDoc->createElement(META_UPDATE_DATE);
#ifndef PWM_EMBEDDED
- text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
+ text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
#else
- text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
+ text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
#endif
- tag.appendChild(text);
- e->appendChild(tag);
+ tag.appendChild(text);
+ e->appendChild(tag);
+ }
@@ -674,3 +699,3 @@ QString Serializer::unescapeEntryData(QString dta)
#else
- dta.replace(QRegExp("$>--endl--<$"), "\n");
+ dta.replace(QRegExp("\\$>--endl--<\\$"), "\n");
dta.replace(QRegExp("||>"), "]]>");
@@ -732,3 +757,3 @@ bool Serializer::addSyncData(QDomElement *e,
QString curId, curDeviceName;
- QDomElement curSync, curSyncDate;
+ QDomElement curSync;
QDomText text;
@@ -747,4 +772,3 @@ bool Serializer::addSyncData(QDomElement *e,
#endif
- curSyncDate.appendChild(text);
- curSync.appendChild(curSyncDate);
+ curSync.appendChild(text);