Diffstat (limited to 'pwmanager/pwmanager/serializer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 126 |
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 | |||
@@ -27,7 +27,7 @@ | |||
27 | #endif | 27 | #endif |
28 | 28 | ||
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) */ |
32 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
33 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
@@ -304,6 +304,10 @@ bool Serializer::readEntries(const QDomNode &n, | |||
304 | QDomNode cur; | 304 | QDomNode cur; |
305 | unsigned int numEntr = nl.count(), i; | 305 | unsigned int numEntr = nl.count(), i; |
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 | ||
308 | dta->clear(); | 312 | dta->clear(); |
309 | for (i = 0; i < numEntr; ++i) { | 313 | for (i = 0; i < numEntr; ++i) { |
@@ -401,36 +405,42 @@ bool Serializer::extractMeta(const QDomNode &n, | |||
401 | cur = cur.nextSibling(); | 405 | cur = cur.nextSibling(); |
402 | continue; | 406 | continue; |
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) { |
435 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 445 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
436 | } else if (name == META_UNIQUEID) { | 446 | } else if (name == META_UNIQUEID) { |
@@ -440,11 +450,6 @@ bool Serializer::extractMeta(const QDomNode &n, | |||
440 | + name.latin1()); | 450 | + name.latin1()); |
441 | } | 451 | } |
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(); |
449 | } | 454 | } |
450 | return true; | 455 | return true; |
@@ -604,41 +609,61 @@ bool Serializer::writeMeta(QDomElement *e, | |||
604 | QDomText text; | 609 | QDomText text; |
605 | QDomElement tag; | 610 | QDomElement tag; |
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 | ||
643 | tag = domDoc->createElement(META_UPDATE_INT); | 668 | tag = domDoc->createElement(META_UPDATE_INT); |
644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 669 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
@@ -672,7 +697,7 @@ QString Serializer::unescapeEntryData(QString dta) | |||
672 | dta.replace("$>--endl--<$", "\n"); | 697 | dta.replace("$>--endl--<$", "\n"); |
673 | dta.replace("||>", "]]>"); | 698 | dta.replace("||>", "]]>"); |
674 | #else | 699 | #else |
675 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 700 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); |
676 | dta.replace(QRegExp("||>"), "]]>"); | 701 | dta.replace(QRegExp("||>"), "]]>"); |
677 | #endif | 702 | #endif |
678 | return dta; | 703 | return dta; |
@@ -730,7 +755,7 @@ bool Serializer::addSyncData(QDomElement *e, | |||
730 | { | 755 | { |
731 | unsigned int numSync = dta.size(), i; | 756 | unsigned int numSync = dta.size(), i; |
732 | QString curId, curDeviceName; | 757 | QString curId, curDeviceName; |
733 | QDomElement curSync, curSyncDate; | 758 | QDomElement curSync; |
734 | QDomText text; | 759 | QDomText text; |
735 | 760 | ||
736 | for (i = 0; i < numSync; ++i) { | 761 | for (i = 0; i < numSync; ++i) { |
@@ -745,8 +770,7 @@ bool Serializer::addSyncData(QDomElement *e, | |||
745 | #else | 770 | #else |
746 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); | 771 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); |
747 | #endif | 772 | #endif |
748 | curSyncDate.appendChild(text); | 773 | curSync.appendChild(text); |
749 | curSync.appendChild(curSyncDate); | ||
750 | 774 | ||
751 | e->appendChild(curSync); | 775 | e->appendChild(curSync); |
752 | 776 | ||