summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/serializer.cpp
Unidiff
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 @@
29/* enable/disable serializer debugging (0/1) */ 29/* enable/disable serializer debugging (0/1) */
30 #define SERIALIZER_DEBUG0 30 #define SERIALIZER_DEBUG1
31/* use the old xml tags for writing (0/1) */ 31/* use the old xml tags for writing (0/1) */
@@ -306,2 +306,6 @@ bool Serializer::readEntries(const QDomNode &n,
306 PwMDataItem curEntr; 306 PwMDataItem curEntr;
307 //US BUG: to initialize all values of curEntr with meaningfulldata,
308 // we call clear on it. Reason: Information in the file we will read might be incomplete.
309 // e.g. the metadata is missing.
310 curEntr.clear(true);
307 311
@@ -403,32 +407,38 @@ bool Serializer::extractMeta(const QDomNode &n,
403 } 407 }
408
409 //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers.
410 //because of that it is possible that here some values are not set, which means they are null.
411 //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates.
412
413 QDateTime dtval; //dtval should be invalid by definition.
414
415 if ((name == META_CREATE_DATE) ||
416 (name == META_VALID_DATE) ||
417 (name == META_EXPIRE_DATE) ||
418 (name == META_UPDATE_DATE))
419 {
420 //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length());
421
404#ifndef PWM_EMBEDDED 422#ifndef PWM_EMBEDDED
405 if (name == META_CREATE_DATE) { 423 dtval = QDateTime::fromString(val, Qt::ISODate);
406 dta->create = QDateTime::fromString(val, Qt::ISODate);
407 } else if (name == META_VALID_DATE) {
408 dta->valid = QDateTime::fromString(val, Qt::ISODate);
409 } else if (name == META_EXPIRE_DATE) {
410 dta->expire = QDateTime::fromString(val, Qt::ISODate);
411 } else if (name == META_UPDATE_DATE) {
412 dta->update = QDateTime::fromString(val, Qt::ISODate);
413 } else if (name == META_UPDATE_INT) {
414 dta->updateInt = strtoul(val.latin1(), 0, 10);
415 } else if (name == META_UNIQUEID) {
416 dta->uniqueid = unescapeEntryData(val).latin1();
417 } else {
418 printDebug(string("extractMeta(): invalid: ")
419 + name.latin1());
420 }
421#else 424#else
425 bool ok;
426 dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
427
428 if (ok == false)
429 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
430#endif
422 431
432 //if the parsed data is wrong, dtval should be invalid at this time.
423 433
424 bool ok = true; 434 }
425 435
426 if (name == META_CREATE_DATE) { 436 if (name == META_CREATE_DATE) {
427 dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 437 dta->create = dtval;
428 } else if (name == META_VALID_DATE) { 438 } else if (name == META_VALID_DATE) {
429 dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 439 dta->valid = dtval;
430 } else if (name == META_EXPIRE_DATE) { 440 } else if (name == META_EXPIRE_DATE) {
431 dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 441 dta->expire = dtval;
432 } else if (name == META_UPDATE_DATE) { 442 } else if (name == META_UPDATE_DATE) {
433 dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 443 dta->update = dtval;
434 } else if (name == META_UPDATE_INT) { 444 } else if (name == META_UPDATE_INT) {
@@ -442,7 +452,2 @@ bool Serializer::extractMeta(const QDomNode &n,
442 452
443 if (ok == false)
444 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
445
446
447#endif
448 cur = cur.nextSibling(); 453 cur = cur.nextSibling();
@@ -606,37 +611,57 @@ bool Serializer::writeMeta(QDomElement *e,
606 611
607 tag = domDoc->createElement(META_CREATE_DATE); 612 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
613 //So do not transform an empty value at all.
614 if (dta.create.isValid())
615 {
616 tag = domDoc->createElement(META_CREATE_DATE);
608#ifndef PWM_EMBEDDED 617#ifndef PWM_EMBEDDED
609 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); 618 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
610#else 619#else
611 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); 620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
612#endif 621#endif
613 tag.appendChild(text); 622 tag.appendChild(text);
614 e->appendChild(tag); 623 e->appendChild(tag);
624 }
615 625
616 tag = domDoc->createElement(META_VALID_DATE); 626 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
627 //So do not transform an empty value at all.
628 if (dta.valid.isValid())
629 {
630 tag = domDoc->createElement(META_VALID_DATE);
617#ifndef PWM_EMBEDDED 631#ifndef PWM_EMBEDDED
618 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); 632 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
619#else 633#else
620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); 634 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
621#endif 635#endif
622 tag.appendChild(text); 636 tag.appendChild(text);
623 e->appendChild(tag); 637 e->appendChild(tag);
638 }
624 639
625 tag = domDoc->createElement(META_EXPIRE_DATE); 640 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
641 //So do not transform an empty value at all.
642 if (dta.expire.isValid())
643 {
644 tag = domDoc->createElement(META_EXPIRE_DATE);
626#ifndef PWM_EMBEDDED 645#ifndef PWM_EMBEDDED
627 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); 646 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
628#else 647#else
629 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); 648 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
630#endif 649#endif
631 tag.appendChild(text); 650 tag.appendChild(text);
632 e->appendChild(tag); 651 e->appendChild(tag);
652 }
633 653
634 tag = domDoc->createElement(META_UPDATE_DATE); 654 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
655 //So do not transform an empty value at all.
656 if (dta.update.isValid())
657 {
658 tag = domDoc->createElement(META_UPDATE_DATE);
635#ifndef PWM_EMBEDDED 659#ifndef PWM_EMBEDDED
636 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); 660 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
637#else 661#else
638 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); 662 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
639#endif 663#endif
640 tag.appendChild(text); 664 tag.appendChild(text);
641 e->appendChild(tag); 665 e->appendChild(tag);
666 }
642 667
@@ -674,3 +699,3 @@ QString Serializer::unescapeEntryData(QString dta)
674#else 699#else
675 dta.replace(QRegExp("$>--endl--<$"), "\n"); 700 dta.replace(QRegExp("\\$>--endl--<\\$"), "\n");
676 dta.replace(QRegExp("||>"), "]]>"); 701 dta.replace(QRegExp("||>"), "]]>");
@@ -732,3 +757,3 @@ bool Serializer::addSyncData(QDomElement *e,
732 QString curId, curDeviceName; 757 QString curId, curDeviceName;
733 QDomElement curSync, curSyncDate; 758 QDomElement curSync;
734 QDomText text; 759 QDomText text;
@@ -747,4 +772,3 @@ bool Serializer::addSyncData(QDomElement *e,
747#endif 772#endif
748 curSyncDate.appendChild(text); 773 curSync.appendChild(text);
749 curSync.appendChild(curSyncDate);
750 774