-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index fcdcec3..9377e3d 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -321,193 +321,193 @@ bool Serializer::extractEntry(const QDomNode &n, | |||
321 | for (i = 0; i < cnt; ++i) { | 321 | for (i = 0; i < cnt; ++i) { |
322 | cur = nl.item(i); | 322 | cur = nl.item(i); |
323 | name = cur.nodeName(); | 323 | name = cur.nodeName(); |
324 | cdata = cur.firstChild(); | 324 | cdata = cur.firstChild(); |
325 | if (unlikely(cdata.isCDATASection())) { | 325 | if (unlikely(cdata.isCDATASection())) { |
326 | text = cdata.toCDATASection().data(); | 326 | text = cdata.toCDATASection().data(); |
327 | } else if (likely(cur.isElement())) { | 327 | } else if (likely(cur.isElement())) { |
328 | text = cur.toElement().text(); | 328 | text = cur.toElement().text(); |
329 | } else { | 329 | } else { |
330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
331 | return false; | 331 | return false; |
332 | } | 332 | } |
333 | if (text == " ") | 333 | if (text == " ") |
334 | text = ""; // for backward compatibility. | 334 | text = ""; // for backward compatibility. |
335 | if (name == ENTRY_DESC_NEW || | 335 | if (name == ENTRY_DESC_NEW || |
336 | name == ENTRY_DESC_OLD) { | 336 | name == ENTRY_DESC_OLD) { |
337 | dta->desc = unescapeEntryData(text).latin1(); | 337 | dta->desc = unescapeEntryData(text).latin1(); |
338 | } else if (name == ENTRY_NAME_NEW || | 338 | } else if (name == ENTRY_NAME_NEW || |
339 | name == ENTRY_NAME_OLD) { | 339 | name == ENTRY_NAME_OLD) { |
340 | dta->name = unescapeEntryData(text).latin1(); | 340 | dta->name = unescapeEntryData(text).latin1(); |
341 | } else if (name == ENTRY_PW_NEW || | 341 | } else if (name == ENTRY_PW_NEW || |
342 | name == ENTRY_PW_OLD) { | 342 | name == ENTRY_PW_OLD) { |
343 | dta->pw = unescapeEntryData(text).latin1(); | 343 | dta->pw = unescapeEntryData(text).latin1(); |
344 | } else if (name == ENTRY_COMMENT_NEW || | 344 | } else if (name == ENTRY_COMMENT_NEW || |
345 | name == ENTRY_COMMENT_OLD) { | 345 | name == ENTRY_COMMENT_OLD) { |
346 | dta->comment = unescapeEntryData(text).latin1(); | 346 | dta->comment = unescapeEntryData(text).latin1(); |
347 | } else if (name == ENTRY_URL_NEW || | 347 | } else if (name == ENTRY_URL_NEW || |
348 | name == ENTRY_URL_OLD) { | 348 | name == ENTRY_URL_OLD) { |
349 | dta->url = unescapeEntryData(text).latin1(); | 349 | dta->url = unescapeEntryData(text).latin1(); |
350 | } else if (name == ENTRY_LAUNCHER_NEW || | 350 | } else if (name == ENTRY_LAUNCHER_NEW || |
351 | name == ENTRY_LAUNCHER_OLD) { | 351 | name == ENTRY_LAUNCHER_OLD) { |
352 | dta->launcher = unescapeEntryData(text).latin1(); | 352 | dta->launcher = unescapeEntryData(text).latin1(); |
353 | } else if (name == ENTRY_LVP_NEW || | 353 | } else if (name == ENTRY_LVP_NEW || |
354 | name == ENTRY_LVP_OLD) { | 354 | name == ENTRY_LVP_OLD) { |
355 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 355 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
356 | } else if (name == ENTRY_BIN_NEW) { | 356 | } else if (name == ENTRY_BIN_NEW) { |
357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
358 | if (text == "0") { | 358 | if (text == "0") { |
359 | dta->binary = false; | 359 | dta->binary = false; |
360 | } else { | 360 | } else { |
361 | dta->binary = true; | 361 | dta->binary = true; |
362 | } | 362 | } |
363 | } else if (name == ENTRY_META_NEW) { | 363 | } else if (name == ENTRY_META_NEW) { |
364 | // ENTRY_META_NEW == ENTRY_META_OLD | 364 | // ENTRY_META_NEW == ENTRY_META_OLD |
365 | if (!extractMeta(cur, &dta->meta)) | 365 | if (!extractMeta(cur, &dta->meta)) |
366 | return false; | 366 | return false; |
367 | } else { | 367 | } else { |
368 | printDebug(string("Serializer::extractEntry(): invalid: ") | 368 | printDebug(string("Serializer::extractEntry(): invalid: ") |
369 | + name.latin1()); | 369 | + name.latin1()); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | dta->lockStat = defaultLockStat; | 372 | dta->lockStat = defaultLockStat; |
373 | return true; | 373 | return true; |
374 | } | 374 | } |
375 | 375 | ||
376 | bool Serializer::extractMeta(const QDomNode &n, | 376 | bool Serializer::extractMeta(const QDomNode &n, |
377 | PwMMetaData *dta) | 377 | PwMMetaData *dta) |
378 | { | 378 | { |
379 | QDomNode cur(n.firstChild()); | 379 | QDomNode cur(n.firstChild()); |
380 | QString name, val; | 380 | QString name, val; |
381 | while (!cur.isNull()) { | 381 | while (!cur.isNull()) { |
382 | name = cur.nodeName(); | 382 | name = cur.nodeName(); |
383 | val = cur.toElement().text(); | 383 | val = cur.toElement().text(); |
384 | if (val == "") { | 384 | if (val == "") { |
385 | cur = cur.nextSibling(); | 385 | cur = cur.nextSibling(); |
386 | continue; | 386 | continue; |
387 | } | 387 | } |
388 | #ifndef PWM_EMBEDDED | 388 | #ifndef PWM_EMBEDDED |
389 | if (name == META_CREATE_DATE) { | 389 | if (name == META_CREATE_DATE) { |
390 | dta->create = QDateTime::fromString(val, Qt::ISODate); | 390 | dta->create = QDateTime::fromString(val, Qt::ISODate); |
391 | } else if (name == META_VALID_DATE) { | 391 | } else if (name == META_VALID_DATE) { |
392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | 392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); |
393 | } else if (name == META_EXPIRE_DATE) { | 393 | } else if (name == META_EXPIRE_DATE) { |
394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | 394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); |
395 | } else if (name == META_UPDATE_DATE) { | 395 | } else if (name == META_UPDATE_DATE) { |
396 | dta->update = QDateTime::fromString(val, Qt::ISODate); | 396 | dta->update = QDateTime::fromString(val, Qt::ISODate); |
397 | } else if (name == META_UPDATE_INT) { | 397 | } else if (name == META_UPDATE_INT) { |
398 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 398 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
399 | } else if (name == META_UNIQUEID) { | 399 | } else if (name == META_UNIQUEID) { |
400 | dta->uniqueid = unescapeEntryData(val).latin1(); | 400 | dta->uniqueid = unescapeEntryData(val).latin1(); |
401 | } else { | 401 | } else { |
402 | printDebug(string("extractMeta(): invalid: ") | 402 | printDebug(string("extractMeta(): invalid: ") |
403 | + name.latin1()); | 403 | + name.latin1()); |
404 | } | 404 | } |
405 | #else | 405 | #else |
406 | 406 | ||
407 | QDateTime m_dt; | 407 | QDateTime m_dt; |
408 | 408 | ||
409 | if ((name == META_CREATE_DATE) || | 409 | if ((name == META_CREATE_DATE) || |
410 | (name == META_VALID_DATE) || | 410 | (name == META_VALID_DATE) || |
411 | (name == META_EXPIRE_DATE) || | 411 | (name == META_EXPIRE_DATE) || |
412 | (name == META_UPDATE_DATE)) | 412 | (name == META_UPDATE_DATE)) |
413 | { | 413 | { |
414 | int pos = val.find("T"); | 414 | int pos = val.find("T"); |
415 | QString date = val.left(pos); | 415 | QString date = val.left(pos); |
416 | QString time = val.mid(pos+1); | 416 | QString time = val.mid(pos+1); |
417 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); | 417 | qDebug("Serializer::extractMeta from %s to date=%s ,time=%s",val.latin1(), date.latin1(), time.latin1() ); |
418 | bool ok1, ok2; | 418 | bool ok1, ok2; |
419 | 419 | ||
420 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); | 420 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); |
421 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); | 421 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); |
422 | if ((ok1 == false) || (ok2 == false)) | 422 | if ((ok1 == false) || (ok2 == false)) |
423 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 423 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
424 | m_dt.setDate(m_date); | 424 | m_dt.setDate(m_date); |
425 | m_dt.setTime(m_time); | 425 | m_dt.setTime(m_time); |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | if (name == META_CREATE_DATE) { | 429 | if (name == META_CREATE_DATE) { |
430 | dta->create = m_dt; | 430 | dta->create = m_dt; |
431 | } else if (name == META_VALID_DATE) { | 431 | } else if (name == META_VALID_DATE) { |
432 | dta->valid = m_dt; | 432 | dta->valid = m_dt; |
433 | } else if (name == META_EXPIRE_DATE) { | 433 | } else if (name == META_EXPIRE_DATE) { |
434 | dta->expire = m_dt; | 434 | dta->expire = m_dt; |
435 | } else if (name == META_UPDATE_DATE) { | 435 | } else if (name == META_UPDATE_DATE) { |
436 | dta->update = m_dt; | 436 | dta->update = m_dt; |
437 | } else if (name == META_UPDATE_INT) { | 437 | } else if (name == META_UPDATE_INT) { |
438 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 438 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
439 | } else if (name == META_UNIQUEID) { | 439 | } else if (name == META_UNIQUEID) { |
440 | dta->uniqueid = unescapeEntryData(val).latin1(); | 440 | dta->uniqueid = unescapeEntryData(val).latin1(); |
441 | } else { | 441 | } else { |
442 | printDebug(string("extractMeta(): invalid: ") | 442 | printDebug(string("extractMeta(): invalid: ") |
443 | + name.latin1()); | 443 | + name.latin1()); |
444 | } | 444 | } |
445 | #endif | 445 | #endif |
446 | cur = cur.nextSibling(); | 446 | cur = cur.nextSibling(); |
447 | } | 447 | } |
448 | return true; | 448 | return true; |
449 | } | 449 | } |
450 | 450 | ||
451 | bool Serializer::checkValid() | 451 | bool Serializer::checkValid() |
452 | { | 452 | { |
453 | PWM_ASSERT(domDoc); | 453 | PWM_ASSERT(domDoc); |
454 | QDomElement root(domDoc->documentElement()); | 454 | QDomElement root(domDoc->documentElement()); |
455 | if (root.nodeName() != ROOT_MAGIC_NEW && | 455 | if (root.nodeName() != ROOT_MAGIC_NEW && |
456 | root.nodeName() != ROOT_MAGIC_OLD) { | 456 | root.nodeName() != ROOT_MAGIC_OLD) { |
457 | printDebug("Serializer: wrong magic"); | 457 | printDebug("Serializer: wrong magic"); |
458 | return false; | 458 | return false; |
459 | } | 459 | } |
460 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 460 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
461 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 461 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
462 | printDebug("Serializer: wrong version"); | 462 | printDebug("Serializer: wrong version"); |
463 | return false; | 463 | return false; |
464 | } | 464 | } |
465 | return true; | 465 | return true; |
466 | } | 466 | } |
467 | 467 | ||
468 | QDomElement Serializer::genNewRoot() | 468 | QDomElement Serializer::genNewRoot() |
469 | { | 469 | { |
470 | PWM_ASSERT(domDoc); | 470 | PWM_ASSERT(domDoc); |
471 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 471 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
472 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 472 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
473 | domDoc->appendChild(root); | 473 | domDoc->appendChild(root); |
474 | return root; | 474 | return root; |
475 | } | 475 | } |
476 | 476 | ||
477 | bool Serializer::addCategories(QDomElement *e, | 477 | bool Serializer::addCategories(QDomElement *e, |
478 | const vector<PwMCategoryItem> &dta) | 478 | const vector<PwMCategoryItem> &dta) |
479 | { | 479 | { |
480 | unsigned int numCat = dta.size(), i; | 480 | unsigned int numCat = dta.size(), i; |
481 | QString curId, curName; | 481 | QString curId, curName; |
482 | QDomElement curCat; | 482 | QDomElement curCat; |
483 | 483 | ||
484 | for (i = 0; i < numCat; ++i) { | 484 | for (i = 0; i < numCat; ++i) { |
485 | curId = CAT_PREFIX_WR; | 485 | curId = CAT_PREFIX_WR; |
486 | curId += tostr(i).c_str(); | 486 | curId += tostr(i).c_str(); |
487 | curName = dta[i].name.c_str(); | 487 | curName = dta[i].name.c_str(); |
488 | curCat = domDoc->createElement(curId); | 488 | curCat = domDoc->createElement(curId); |
489 | curCat.setAttribute(CAT_NAME_WR, curName); | 489 | curCat.setAttribute(CAT_NAME_WR, curName); |
490 | if (!addEntries(&curCat, dta[i].d)) { | 490 | if (!addEntries(&curCat, dta[i].d)) { |
491 | return false; | 491 | return false; |
492 | } | 492 | } |
493 | e->appendChild(curCat); | 493 | e->appendChild(curCat); |
494 | } | 494 | } |
495 | return true; | 495 | return true; |
496 | } | 496 | } |
497 | 497 | ||
498 | bool Serializer::addEntries(QDomElement *e, | 498 | bool Serializer::addEntries(QDomElement *e, |
499 | const vector<PwMDataItem> &dta) | 499 | const vector<PwMDataItem> &dta) |
500 | { | 500 | { |
501 | unsigned int numEntr = dta.size(), i; | 501 | unsigned int numEntr = dta.size(), i; |
502 | QString curId; | 502 | QString curId; |
503 | QDomElement curEntr; | 503 | QDomElement curEntr; |
504 | 504 | ||
505 | for (i = 0; i < numEntr; ++i) { | 505 | for (i = 0; i < numEntr; ++i) { |
506 | curId = ENTRY_PREFIX_WR; | 506 | curId = ENTRY_PREFIX_WR; |
507 | curId += tostr(i).c_str(); | 507 | curId += tostr(i).c_str(); |
508 | curEntr = domDoc->createElement(curId); | 508 | curEntr = domDoc->createElement(curId); |
509 | if (!writeEntry(&curEntr, dta[i])) { | 509 | if (!writeEntry(&curEntr, dta[i])) { |
510 | return false; | 510 | return false; |
511 | } | 511 | } |
512 | e->appendChild(curEntr); | 512 | e->appendChild(curEntr); |
513 | } | 513 | } |