summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-19 18:11:34 (UTC)
committer ulf69 <ulf69>2004-10-19 18:11:34 (UTC)
commit695c64501950e0503ed558fbe8d8c06993776eaa (patch) (unidiff)
tree6b860a9512f534ab0c4361cf3d529f57755fef71
parent4f780ff70bc13bf9cb7e7c33f869a59dfcc36e69 (diff)
downloadkdepimpi-695c64501950e0503ed558fbe8d8c06993776eaa.zip
kdepimpi-695c64501950e0503ed558fbe8d8c06993776eaa.tar.gz
kdepimpi-695c64501950e0503ed558fbe8d8c06993776eaa.tar.bz2
changed comments
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/randomizer.cpp2
-rw-r--r--pwmanager/pwmanager/randomizer.h2
-rw-r--r--pwmanager/pwmanager/serializer.cpp4
-rw-r--r--pwmanager/pwmanager/serializer.h2
4 files changed, 5 insertions, 5 deletions
diff --git a/pwmanager/pwmanager/randomizer.cpp b/pwmanager/pwmanager/randomizer.cpp
index 1269c53..e1085ff 100644
--- a/pwmanager/pwmanager/randomizer.cpp
+++ b/pwmanager/pwmanager/randomizer.cpp
@@ -1,221 +1,221 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "randomizer.h" 20#include "randomizer.h"
21#include "pwmexception.h" 21#include "pwmexception.h"
22 22
23#include <qfile.h> 23#include <qfile.h>
24 24
25#include <kapplication.h> 25#include <kapplication.h>
26 26
27#include <stdlib.h> 27#include <stdlib.h>
28#include <time.h> 28#include <time.h>
29 29
30 30
31#ifdef PWM_EMBEDDED 31#ifdef PWM_EMBEDDED
32 32
33#ifndef Q_LONG 33#ifndef Q_LONG
34#define Q_LONG long 34#define Q_LONG long
35#endif 35#endif
36 36
37#endif //PWM_EMBEDDED 37#endif //PWM_EMBEDDED
38 38
39 39
40Randomizer * Randomizer::rndObj (0); 40Randomizer * Randomizer::rndObj (0);
41 41
42Randomizer::Randomizer() 42Randomizer::Randomizer()
43{ 43{
44 rndDev = new QFile; 44 rndDev = new QFile;
45 seed = time(0); 45 seed = time(0);
46 46
47#if 1 // set to 0 to test rand_r() fallback 47#if 1 // set to 0 to test rand_r() fallback
48 48
49 // probe for /dev/urandom 49 // probe for /dev/urandom
50 rndDev->setName("/dev/urandom"); 50 rndDev->setName("/dev/urandom");
51 if (rndDev->exists() && 51 if (rndDev->exists() &&
52 rndDev->open(IO_ReadOnly)) { 52 rndDev->open(IO_ReadOnly)) {
53 printDebug("Randomizer: using /dev/urandom"); 53 printDebug("Randomizer: using /dev/urandom");
54 return; 54 return;
55 } 55 }
56 56
57 // probe for /dev/random 57 // probe for /dev/random
58 rndDev->setName("/dev/random"); 58 rndDev->setName("/dev/random");
59 if (rndDev->exists() && 59 if (rndDev->exists() &&
60 rndDev->open(IO_ReadOnly)) { 60 rndDev->open(IO_ReadOnly)) {
61 printDebug("Randomizer: using /dev/random"); 61 printDebug("Randomizer: using /dev/random");
62 return; 62 return;
63 } 63 }
64 64
65 // probe for EGD 65 // probe for EGD
66 char *fn = getenv("RANDFILE"); 66 char *fn = getenv("RANDFILE");
67 if (fn) { 67 if (fn) {
68 rndDev->setName(fn); 68 rndDev->setName(fn);
69 if (rndDev->exists() && 69 if (rndDev->exists() &&
70 rndDev->open(IO_ReadOnly)) { 70 rndDev->open(IO_ReadOnly)) {
71 printDebug(string("Randomizer: using $RANDFILE \"") 71 printDebug(string("Randomizer: using $RANDFILE \"")
72 + fn 72 + fn
73 + "\" (aka EGD)"); 73 + "\" (aka EGD)");
74 return; 74 return;
75 } 75 }
76 } 76 }
77#endif 77#endif
78 78
79 /* no secure randomizer found. 79 /* no secure randomizer found.
80 * Fall back to stdlib randomizer. 80 * Fall back to stdlib randomizer.
81 */ 81 */
82 delete_and_null(rndDev); 82 delete_and_null(rndDev);
83 printWarn("neither /dev/*random nor EGD found! " 83 printWarn("neither /dev/*random nor EGD found! "
84 "Falling back to insecure rand_r()!"); 84 "Falling back to insecure rand_r()!");
85} 85}
86 86
87Randomizer::~Randomizer() 87Randomizer::~Randomizer()
88{ 88{
89#ifndef PWM_EMBEDDED 89#ifndef PWM_EMBEDDED
90 while (mutex.locked()) { 90 while (mutex.locked()) {
91 /* wait for the mutex to unlock. 91 /* wait for the mutex to unlock.
92 * Don't block the GUI here, so processEvents() 92 * Don't block the GUI here, so processEvents()
93 */ 93 */
94 kapp->processEvents(); 94 kapp->processEvents();
95 } 95 }
96#endif 96#endif
97 if (rndDev) { 97 if (rndDev) {
98 rndDev->close(); 98 rndDev->close();
99 delete rndDev; 99 delete rndDev;
100 } 100 }
101} 101}
102 102
103char Randomizer::genRndChar() 103char Randomizer::genRndChar()
104{ 104{
105 char ret; 105 char ret;
106#ifndef PWM_EMBEDDED 106#ifndef PWM_EMBEDDED
107 mutex.lock(); 107 mutex.lock();
108#endif 108#endif
109 if (rndDev) { 109 if (rndDev) {
110 /* we have a file which provides random data. 110 /* we have a file which provides random data.
111 * Simply read it. 111 * Simply read it.
112 */ 112 */
113 ret = rndDev->getch(); 113 ret = rndDev->getch();
114 } else { 114 } else {
115 /* fall back to rand_r() */ 115 /* fall back to rand_r() */
116 ret = rand_r(&seed) % 0xFF; 116 ret = rand_r(&seed) % 0xFF;
117 } 117 }
118#ifndef PWM_EMBEDDED 118#ifndef PWM_EMBEDDED
119 mutex->unlock(); 119 mutex->unlock();
120#endif 120#endif
121 return ret; 121 return ret;
122} 122}
123 123
124int Randomizer::genRndInt() 124int Randomizer::genRndInt()
125{ 125{
126 int ret; 126 int ret;
127#ifndef PWM_EMBEDDED 127#ifndef PWM_EMBEDDED
128 mutex->lock(); 128 mutex->lock();
129#endif 129#endif
130 if (rndDev) { 130 if (rndDev) {
131 if (sizeof(int) == 4) { 131 if (sizeof(int) == 4) {
132 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch(); 132 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch();
133 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch(); 133 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch();
134 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch(); 134 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch();
135 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch(); 135 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch();
136 } else if (sizeof(int) == 8) { 136 } else if (sizeof(int) == 8) {
137 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch(); 137 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch();
138 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch(); 138 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch();
139 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch(); 139 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch();
140 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch(); 140 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch();
141 (reinterpret_cast<char *>(&ret))[4] = rndDev->getch(); 141 (reinterpret_cast<char *>(&ret))[4] = rndDev->getch();
142 (reinterpret_cast<char *>(&ret))[5] = rndDev->getch(); 142 (reinterpret_cast<char *>(&ret))[5] = rndDev->getch();
143 (reinterpret_cast<char *>(&ret))[6] = rndDev->getch(); 143 (reinterpret_cast<char *>(&ret))[6] = rndDev->getch();
144 (reinterpret_cast<char *>(&ret))[7] = rndDev->getch(); 144 (reinterpret_cast<char *>(&ret))[7] = rndDev->getch();
145 } else { 145 } else {
146 printWarn(string(__FILE__) + ":" + tostr(__LINE__) 146 printWarn(string(__FILE__) + ":" + tostr(__LINE__)
147 + ": sizeof(int) != 4 && sizeof(int) != 8"); 147 + ": sizeof(int) != 4 && sizeof(int) != 8");
148 ret = rand_r(&seed); 148 ret = rand_r(&seed);
149 } 149 }
150 } else { 150 } else {
151 ret = rand_r(&seed); 151 ret = rand_r(&seed);
152 } 152 }
153#ifndef PWM_EMBEDDED 153#ifndef PWM_EMBEDDED
154 mutex->unlock(); 154 mutex->unlock();
155#endif 155#endif
156 return ret; 156 return ret;
157} 157}
158 158
159unsigned int Randomizer::genRndUInt() 159unsigned int Randomizer::genRndUInt()
160{ 160{
161 unsigned int ret; 161 unsigned int ret;
162#ifndef PWM_EMBEDDED 162#ifndef PWM_EMBEDDED
163 mutex->lock(); 163 mutex->lock();
164#endif 164#endif
165 if (rndDev) { 165 if (rndDev) {
166 if (sizeof(unsigned int) == 4) { 166 if (sizeof(unsigned int) == 4) {
167 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch(); 167 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch();
168 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch(); 168 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch();
169 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch(); 169 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch();
170 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch(); 170 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch();
171 } else if (sizeof(unsigned int) == 8) { 171 } else if (sizeof(unsigned int) == 8) {
172 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch(); 172 (reinterpret_cast<char *>(&ret))[0] = rndDev->getch();
173 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch(); 173 (reinterpret_cast<char *>(&ret))[1] = rndDev->getch();
174 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch(); 174 (reinterpret_cast<char *>(&ret))[2] = rndDev->getch();
175 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch(); 175 (reinterpret_cast<char *>(&ret))[3] = rndDev->getch();
176 (reinterpret_cast<char *>(&ret))[4] = rndDev->getch(); 176 (reinterpret_cast<char *>(&ret))[4] = rndDev->getch();
177 (reinterpret_cast<char *>(&ret))[5] = rndDev->getch(); 177 (reinterpret_cast<char *>(&ret))[5] = rndDev->getch();
178 (reinterpret_cast<char *>(&ret))[6] = rndDev->getch(); 178 (reinterpret_cast<char *>(&ret))[6] = rndDev->getch();
179 (reinterpret_cast<char *>(&ret))[7] = rndDev->getch(); 179 (reinterpret_cast<char *>(&ret))[7] = rndDev->getch();
180 } else { 180 } else {
181 printWarn(string(__FILE__) + ":" + tostr(__LINE__) 181 printWarn(string(__FILE__) + ":" + tostr(__LINE__)
182 + ": sizeof(unsigned int) != 4 && sizeof(unsigned int) != 8"); 182 + ": sizeof(unsigned int) != 4 && sizeof(unsigned int) != 8");
183 ret = rand_r(&seed); 183 ret = rand_r(&seed);
184 } 184 }
185 } else { 185 } else {
186 ret = rand_r(&seed); 186 ret = rand_r(&seed);
187 } 187 }
188#ifndef PWM_EMBEDDED 188#ifndef PWM_EMBEDDED
189 mutex->unlock(); 189 mutex->unlock();
190#endif 190#endif
191 return ret; 191 return ret;
192} 192}
193 193
194void Randomizer::genRndBuf(unsigned char *buf, size_t len) 194void Randomizer::genRndBuf(unsigned char *buf, size_t len)
195{ 195{
196#ifndef PWM_EMBEDDED 196#ifndef PWM_EMBEDDED
197 mutex->lock(); 197 mutex->lock();
198#endif 198#endif
199 if (rndDev) { 199 if (rndDev) {
200 Q_LONG n; 200 Q_LONG n;
201 n = rndDev->readBlock(reinterpret_cast<char *>(buf), len); 201 n = rndDev->readBlock(reinterpret_cast<char *>(buf), len);
202 WARN_ON(n != static_cast<Q_LONG>(len)); 202 WARN_ON(n != static_cast<Q_LONG>(len));
203 } else { 203 } else {
204 size_t i; 204 size_t i;
205 for (i = 0; i < len; ++i) 205 for (i = 0; i < len; ++i)
206 buf[i] = rand_r(&seed) % 0xFF; 206 buf[i] = rand_r(&seed) % 0xFF;
207 } 207 }
208#ifndef PWM_EMBEDDED 208#ifndef PWM_EMBEDDED
209 mutex->unlock(); 209 mutex->unlock();
210#endif 210#endif
211} 211}
212 212
213string Randomizer::genRndBuf(size_t len) 213string Randomizer::genRndBuf(size_t len)
214{ 214{
215 string ret; 215 string ret;
216 unsigned char *buf; 216 unsigned char *buf;
217 buf = new unsigned char[len]; 217 buf = new unsigned char[len];
218 genRndBuf(buf, len); 218 genRndBuf(buf, len);
219 ret.assign(reinterpret_cast<const char *>(buf), len); 219 ret.assign(reinterpret_cast<const char *>(buf), len);
220 return ret; 220 return ret;
221} 221}
diff --git a/pwmanager/pwmanager/randomizer.h b/pwmanager/pwmanager/randomizer.h
index 5eb02f1..f2a6015 100644
--- a/pwmanager/pwmanager/randomizer.h
+++ b/pwmanager/pwmanager/randomizer.h
@@ -1,86 +1,86 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __RANDOMIZER_H 20#ifndef __RANDOMIZER_H
21#define __RANDOMIZER_H 21#define __RANDOMIZER_H
22 22
23#include "pwmexception.h" 23#include "pwmexception.h"
24 24
25#ifndef PWM_EMBEDDED 25#ifndef PWM_EMBEDDED
26#include <qmutex.h> 26#include <qmutex.h>
27#endif 27#endif
28 28
29#include <string> 29#include <string>
30 30
31using std::string; 31using std::string;
32 32
33class QFile; 33class QFile;
34 34
35/** Randomizer to get random values. 35/** Randomizer to get random values.
36 * This class is thread-safe. 36 * This class is thread-safe.
37 * You should always use the instance returned by 37 * You should always use the instance returned by
38 * obj() to use it. 38 * obj() to use it.
39 */ 39 */
40class Randomizer 40class Randomizer
41{ 41{
42public: 42public:
43 Randomizer(); 43 Randomizer();
44 ~Randomizer(); 44 ~Randomizer();
45 45
46 static Randomizer * obj() 46 static Randomizer * obj()
47 { 47 {
48 PWM_ASSERT(rndObj); 48 PWM_ASSERT(rndObj);
49 return rndObj; 49 return rndObj;
50 } 50 }
51 static void init() 51 static void init()
52 { 52 {
53 PWM_ASSERT(!rndObj); 53 PWM_ASSERT(!rndObj);
54 rndObj = new Randomizer; 54 rndObj = new Randomizer;
55 } 55 }
56 static void cleanup() 56 static void cleanup()
57 { 57 {
58 delete_ifnot_null(rndObj); 58 delete_ifnot_null(rndObj);
59 } 59 }
60 60
61 /** generate random char */ 61 /** generate random char */
62 char genRndChar(); 62 char genRndChar();
63 /** generate random int */ 63 /** generate random int */
64 int genRndInt(); 64 int genRndInt();
65 /** generate a random unsigned int */ 65 /** generate a random unsigned int */
66 unsigned int genRndUInt(); 66 unsigned int genRndUInt();
67 67
68 /** returns a buffer with random data */ 68 /** returns a buffer with random data */
69 string genRndBuf(size_t len); 69 string genRndBuf(size_t len);
70 /** returns a buffer with random data */ 70 /** returns a buffer with random data */
71 void genRndBuf(unsigned char *buf, size_t len); 71 void genRndBuf(unsigned char *buf, size_t len);
72 72
73protected: 73protected:
74 /** random-device-node (if available. Otherwise NULL) */ 74 /** random-device-node (if available. Otherwise NULL) */
75 QFile *rndDev; 75 QFile *rndDev;
76#ifndef PWM_EMBEDDED 76#ifndef PWM_EMBEDDED
77 /** mutex for accessing the public functions thread-save */ 77 /** mutex for accessing the public functions thread-save */
78 QMutex mutex; 78 QMutex mutex;
79#endif 79#endif
80 /** seed value for fallback - rand_r() */ 80 /** seed value for fallback - rand_r() */
81 unsigned int seed; 81 unsigned int seed;
82 /** static Randomizer object returned by obj() */ 82 /** static Randomizer object returned by obj() */
83 static Randomizer *rndObj; 83 static Randomizer *rndObj;
84}; 84};
85 85
86#endif // __RANDOMIZER_H 86#endif // __RANDOMIZER_H
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index 5c6568f..2d6498e 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -1,542 +1,542 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13/*************************************************************************** 13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk 14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager 15 * This file is originaly based on version 1.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde 16 * and was modified to run on embedded devices that run microkde
17 * 17 *
18 * $Id$ 18 * $Id$
19 **************************************************************************/ 19 **************************************************************************/
20 20
21#include "serializer.h" 21#include "serializer.h"
22#include "pwmexception.h" 22#include "pwmexception.h"
23 23
24#ifdef PWM_EMBEDDED 24#ifdef PWM_EMBEDDED
25#include <kglobal.h> 25#include <kglobal.h>
26#include <klocale.h> 26#include <klocale.h>
27#endif 27#endif
28 28
29/* enable/disable serializer debugging (0/1) */ 29/* enable/disable serializer debugging (0/1) */
30 #define SERIALIZER_DEBUG1 30 #define SERIALIZER_DEBUG0
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) */
34 #define WRITE_CDATA_SEC 0 34 #define WRITE_CDATA_SEC 0
35 35
36 36
37 #define META_CREATE_DATE"c" 37 #define META_CREATE_DATE"c"
38 #define META_VALID_DATE "v" 38 #define META_VALID_DATE "v"
39 #define META_EXPIRE_DATE"e" 39 #define META_EXPIRE_DATE"e"
40 #define META_UPDATE_DATE"u" 40 #define META_UPDATE_DATE"u"
41 #define META_UPDATE_INT "i" 41 #define META_UPDATE_INT "i"
42//US ENH : uniqueid 42//US ENH : uniqueid
43#define META_UNIQUEID "n" 43#define META_UNIQUEID "n"
44#define SYNC_ROOT "s" 44#define SYNC_ROOT "s"
45#define SYNC_TARGET_PREFIX "t" 45#define SYNC_TARGET_PREFIX "t"
46#define SYNC_TARGET_NAME "n" 46#define SYNC_TARGET_NAME "n"
47 47
48 48
49/* This is compatibility stuff. 49/* This is compatibility stuff.
50 * The names of the entries have changed and here are the 50 * The names of the entries have changed and here are the
51 * new and old ones 51 * new and old ones
52 */ 52 */
53 #define ROOT_MAGIC_OLD "PwM-xml-dat" 53 #define ROOT_MAGIC_OLD "PwM-xml-dat"
54 #define VER_STR_OLD "ver" 54 #define VER_STR_OLD "ver"
55 #define COMPAT_VER_OLD "0x02" 55 #define COMPAT_VER_OLD "0x02"
56 #define CAT_ROOT_OLD "categories" 56 #define CAT_ROOT_OLD "categories"
57 #define CAT_PREFIX_OLD "cat_" 57 #define CAT_PREFIX_OLD "cat_"
58 #define CAT_NAME_OLD "name" 58 #define CAT_NAME_OLD "name"
59 #define ENTRY_PREFIX_OLD"entry_" 59 #define ENTRY_PREFIX_OLD"entry_"
60 #define ENTRY_DESC_OLD "desc" 60 #define ENTRY_DESC_OLD "desc"
61 #define ENTRY_NAME_OLD "name" 61 #define ENTRY_NAME_OLD "name"
62 #define ENTRY_PW_OLD "pw" 62 #define ENTRY_PW_OLD "pw"
63 #define ENTRY_COMMENT_OLD"comment" 63 #define ENTRY_COMMENT_OLD"comment"
64 #define ENTRY_URL_OLD "url" 64 #define ENTRY_URL_OLD "url"
65 #define ENTRY_LAUNCHER_OLD"launcher" 65 #define ENTRY_LAUNCHER_OLD"launcher"
66 #define ENTRY_LVP_OLD "listViewPos" 66 #define ENTRY_LVP_OLD "listViewPos"
67 #define ENTRY_BIN_OLD "b" 67 #define ENTRY_BIN_OLD "b"
68 #define ENTRY_META_OLD "m" 68 #define ENTRY_META_OLD "m"
69 69
70 #define ROOT_MAGIC_NEW "P" 70 #define ROOT_MAGIC_NEW "P"
71 #define VER_STR_NEW "v" 71 #define VER_STR_NEW "v"
72 #define COMPAT_VER_NEW "2" 72 #define COMPAT_VER_NEW "2"
73 #define CAT_ROOT_NEW "c" 73 #define CAT_ROOT_NEW "c"
74 #define CAT_PREFIX_NEW "c" 74 #define CAT_PREFIX_NEW "c"
75 #define CAT_NAME_NEW "n" 75 #define CAT_NAME_NEW "n"
76 #define ENTRY_PREFIX_NEW"e" 76 #define ENTRY_PREFIX_NEW"e"
77 #define ENTRY_DESC_NEW "d" 77 #define ENTRY_DESC_NEW "d"
78 #define ENTRY_NAME_NEW "n" 78 #define ENTRY_NAME_NEW "n"
79 #define ENTRY_PW_NEW "p" 79 #define ENTRY_PW_NEW "p"
80 #define ENTRY_COMMENT_NEW"c" 80 #define ENTRY_COMMENT_NEW"c"
81 #define ENTRY_URL_NEW "u" 81 #define ENTRY_URL_NEW "u"
82 #define ENTRY_LAUNCHER_NEW"l" 82 #define ENTRY_LAUNCHER_NEW"l"
83 #define ENTRY_LVP_NEW "v" 83 #define ENTRY_LVP_NEW "v"
84 #define ENTRY_BIN_NEW ENTRY_BIN_OLD 84 #define ENTRY_BIN_NEW ENTRY_BIN_OLD
85 #define ENTRY_META_NEW ENTRY_META_OLD 85 #define ENTRY_META_NEW ENTRY_META_OLD
86 86
87#if USE_OLD_TAGS != 0 87#if USE_OLD_TAGS != 0
88 # define ROOT_MAGIC_WR ROOT_MAGIC_OLD 88 # define ROOT_MAGIC_WR ROOT_MAGIC_OLD
89 # define VER_STR_WR VER_STR_OLD 89 # define VER_STR_WR VER_STR_OLD
90 # define COMPAT_VER_WR COMPAT_VER_OLD 90 # define COMPAT_VER_WR COMPAT_VER_OLD
91 # define CAT_ROOT_WR CAT_ROOT_OLD 91 # define CAT_ROOT_WR CAT_ROOT_OLD
92 # define CAT_PREFIX_WR CAT_PREFIX_OLD 92 # define CAT_PREFIX_WR CAT_PREFIX_OLD
93 # define CAT_NAME_WR CAT_NAME_OLD 93 # define CAT_NAME_WR CAT_NAME_OLD
94 # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD 94 # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD
95 # define ENTRY_DESC_WR ENTRY_DESC_OLD 95 # define ENTRY_DESC_WR ENTRY_DESC_OLD
96 # define ENTRY_NAME_WR ENTRY_NAME_OLD 96 # define ENTRY_NAME_WR ENTRY_NAME_OLD
97 # define ENTRY_PW_WR ENTRY_PW_OLD 97 # define ENTRY_PW_WR ENTRY_PW_OLD
98 # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD 98 # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD
99 # define ENTRY_URL_WR ENTRY_URL_OLD 99 # define ENTRY_URL_WR ENTRY_URL_OLD
100 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD 100 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD
101 # define ENTRY_LVP_WR ENTRY_LVP_OLD 101 # define ENTRY_LVP_WR ENTRY_LVP_OLD
102 # define ENTRY_BIN_WR ENTRY_BIN_OLD 102 # define ENTRY_BIN_WR ENTRY_BIN_OLD
103 # define ENTRY_META_WR ENTRY_META_OLD 103 # define ENTRY_META_WR ENTRY_META_OLD
104#else 104#else
105 # define ROOT_MAGIC_WR ROOT_MAGIC_NEW 105 # define ROOT_MAGIC_WR ROOT_MAGIC_NEW
106 # define VER_STR_WR VER_STR_NEW 106 # define VER_STR_WR VER_STR_NEW
107 # define COMPAT_VER_WR COMPAT_VER_NEW 107 # define COMPAT_VER_WR COMPAT_VER_NEW
108 # define CAT_ROOT_WR CAT_ROOT_NEW 108 # define CAT_ROOT_WR CAT_ROOT_NEW
109 # define CAT_PREFIX_WR CAT_PREFIX_NEW 109 # define CAT_PREFIX_WR CAT_PREFIX_NEW
110 # define CAT_NAME_WR CAT_NAME_NEW 110 # define CAT_NAME_WR CAT_NAME_NEW
111 # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW 111 # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW
112 # define ENTRY_DESC_WR ENTRY_DESC_NEW 112 # define ENTRY_DESC_WR ENTRY_DESC_NEW
113 # define ENTRY_NAME_WR ENTRY_NAME_NEW 113 # define ENTRY_NAME_WR ENTRY_NAME_NEW
114 # define ENTRY_PW_WR ENTRY_PW_NEW 114 # define ENTRY_PW_WR ENTRY_PW_NEW
115 # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW 115 # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW
116 # define ENTRY_URL_WR ENTRY_URL_NEW 116 # define ENTRY_URL_WR ENTRY_URL_NEW
117 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW 117 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW
118 # define ENTRY_LVP_WR ENTRY_LVP_NEW 118 # define ENTRY_LVP_WR ENTRY_LVP_NEW
119 # define ENTRY_BIN_WR ENTRY_BIN_NEW 119 # define ENTRY_BIN_WR ENTRY_BIN_NEW
120 # define ENTRY_META_WR ENTRY_META_NEW 120 # define ENTRY_META_WR ENTRY_META_NEW
121#endif 121#endif
122 122
123 123
124Serializer::Serializer() 124Serializer::Serializer()
125{ 125{
126 defaultLockStat = true; 126 defaultLockStat = true;
127//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing 127//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
128#ifndef PWM_EMBEDDED 128#ifndef PWM_EMBEDDED
129 domDoc = new QDomDocument; 129 domDoc = new QDomDocument;
130#else 130#else
131 domDoc = new QDomDocument("mydoc"); 131 domDoc = new QDomDocument("mydoc");
132#endif 132#endif
133} 133}
134 134
135Serializer::Serializer(const QCString &buffer) 135Serializer::Serializer(const QCString &buffer)
136{ 136{
137 defaultLockStat = true; 137 defaultLockStat = true;
138//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing 138//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
139#ifndef PWM_EMBEDDED 139#ifndef PWM_EMBEDDED
140 domDoc = new QDomDocument; 140 domDoc = new QDomDocument;
141#else 141#else
142 domDoc = new QDomDocument("mydoc"); 142 domDoc = new QDomDocument("mydoc");
143#endif 143#endif
144 144
145 if (!parseXml(buffer)) { 145 if (!parseXml(buffer)) {
146 delete domDoc; 146 delete domDoc;
147#ifndef PWM_EMBEDDED 147#ifndef PWM_EMBEDDED
148 throw PwMException(PwMException::EX_PARSE); 148 throw PwMException(PwMException::EX_PARSE);
149#else 149#else
150 qDebug("Serializer::Serializer : Parse Exception "); 150 qDebug("Serializer::Serializer : Parse Exception ");
151#endif 151#endif
152 } 152 }
153} 153}
154 154
155Serializer::~Serializer() 155Serializer::~Serializer()
156{ 156{
157 delete_ifnot_null(domDoc); 157 delete_ifnot_null(domDoc);
158} 158}
159 159
160void Serializer::clear() 160void Serializer::clear()
161{ 161{
162 delete_ifnot_null(domDoc); 162 delete_ifnot_null(domDoc);
163 domDoc = new QDomDocument; 163 domDoc = new QDomDocument;
164} 164}
165 165
166bool Serializer::parseXml(const QCString &buffer) 166bool Serializer::parseXml(const QCString &buffer)
167{ 167{
168 PWM_ASSERT(domDoc); 168 PWM_ASSERT(domDoc);
169#ifndef PWM_EMBEDDED 169#ifndef PWM_EMBEDDED
170 if (!domDoc->setContent(buffer, true)) 170 if (!domDoc->setContent(buffer, true))
171 return false; 171 return false;
172#else 172#else
173 if (!domDoc->setContent(buffer)) 173 if (!domDoc->setContent(buffer))
174 return false; 174 return false;
175#endif 175#endif
176 if (!checkValid()) 176 if (!checkValid())
177 return false; 177 return false;
178 return true; 178 return true;
179} 179}
180 180
181QCString Serializer::getXml() 181QCString Serializer::getXml()
182{ 182{
183 PWM_ASSERT(domDoc); 183 PWM_ASSERT(domDoc);
184 184
185#ifndef PWM_EMBEDDED 185#ifndef PWM_EMBEDDED
186#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 186#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
187 QCString tmp(domDoc->toCString(8)); 187 QCString tmp(domDoc->toCString(8));
188 printDebug("<BEGIN Serializer::getXml() dump>\n"); 188 printDebug("<BEGIN Serializer::getXml() dump>\n");
189 cout << tmp << endl; 189 cout << tmp << endl;
190 printDebug("<END Serializer::getXml() dump>"); 190 printDebug("<END Serializer::getXml() dump>");
191#endif // DEBUG 191#endif // DEBUG
192 192
193 QCString ret(domDoc->toCString(0)); 193 QCString ret(domDoc->toCString(0));
194 ret.replace('\n', ""); 194 ret.replace('\n', "");
195 return ret; 195 return ret;
196#else 196#else
197 197
198#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 198#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
199 QCString tmp(" " + domDoc->toCString()); 199 QCString tmp(" " + domDoc->toCString());
200 printDebug("<BEGIN Serializer::getXml() dump>\n"); 200 printDebug("<BEGIN Serializer::getXml() dump>\n");
201 qDebug(tmp); 201 qDebug(tmp);
202 cout << tmp << endl; 202 cout << tmp << endl;
203 printDebug("<END Serializer::getXml() dump>"); 203 printDebug("<END Serializer::getXml() dump>");
204#endif // DEBUG 204#endif // DEBUG
205 205
206 QCString ret(domDoc->toCString()); 206 QCString ret(domDoc->toCString());
207 ret.replace(QRegExp("\n"), ""); 207 ret.replace(QRegExp("\n"), "");
208 return ret; 208 return ret;
209 209
210#endif 210#endif
211} 211}
212 212
213bool Serializer::serialize(PwMItem &dta) 213bool Serializer::serialize(PwMItem &dta)
214{ 214{
215 PWM_ASSERT(domDoc); 215 PWM_ASSERT(domDoc);
216 QDomElement root(genNewRoot()); 216 QDomElement root(genNewRoot());
217 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); 217 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
218 QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); 218 QDomElement syncNode(domDoc->createElement(SYNC_ROOT));
219 if (!addSyncData(&syncNode, dta.syncDta)) 219 if (!addSyncData(&syncNode, dta.syncDta))
220 return false; 220 return false;
221 root.appendChild(syncNode); 221 root.appendChild(syncNode);
222 if (!addCategories(&catNode, dta.dta)) 222 if (!addCategories(&catNode, dta.dta))
223 return false; 223 return false;
224 root.appendChild(catNode); 224 root.appendChild(catNode);
225 return true; 225 return true;
226} 226}
227 227
228bool Serializer::deSerialize(PwMItem *dta) 228bool Serializer::deSerialize(PwMItem *dta)
229{ 229{
230 PWM_ASSERT(domDoc); 230 PWM_ASSERT(domDoc);
231 PWM_ASSERT(dta); 231 PWM_ASSERT(dta);
232 QDomElement root(domDoc->documentElement()); 232 QDomElement root(domDoc->documentElement());
233 QDomNode n; 233 QDomNode n;
234 234
235 dta->clear(); 235 dta->clear();
236 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { 236 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
237 // find <categories> ... </categories> 237 // find <categories> ... </categories>
238 // <c> ... </c> 238 // <c> ... </c>
239 if (n.nodeName() == CAT_ROOT_NEW || 239 if (n.nodeName() == CAT_ROOT_NEW ||
240 n.nodeName() == CAT_ROOT_OLD) { 240 n.nodeName() == CAT_ROOT_OLD) {
241 if (!readCategories(n, &(dta->dta))) { 241 if (!readCategories(n, &(dta->dta))) {
242 return false; 242 return false;
243 } 243 }
244 continue; 244 continue;
245 } 245 }
246 else if (n.nodeName() == SYNC_ROOT) { 246 else if (n.nodeName() == SYNC_ROOT) {
247 if (!readSyncData(n, &(dta->syncDta))) { 247 if (!readSyncData(n, &(dta->syncDta))) {
248 return false; 248 return false;
249 } 249 }
250 continue; 250 continue;
251 } 251 }
252 252
253 /* NOTE: We can stop processing here, as we 253 /* NOTE: We can stop processing here, as we
254 * don't have more nodes in root, yet. 254 * don't have more nodes in root, yet.
255 */ 255 */
256 return false; 256 return false;
257 257
258 } 258 }
259 return true; 259 return true;
260} 260}
261 261
262bool Serializer::readCategories(const QDomNode &n, 262bool Serializer::readCategories(const QDomNode &n,
263 vector<PwMCategoryItem> *dta) 263 vector<PwMCategoryItem> *dta)
264{ 264{
265 QDomNodeList nl(n.childNodes()); 265 QDomNodeList nl(n.childNodes());
266 QDomNode cur; 266 QDomNode cur;
267 QString name; 267 QString name;
268 unsigned int numCat = nl.count(), i; 268 unsigned int numCat = nl.count(), i;
269 PwMCategoryItem curCat; 269 PwMCategoryItem curCat;
270 vector<PwMDataItem> curEntr; 270 vector<PwMDataItem> curEntr;
271 271
272 if (!numCat) { 272 if (!numCat) {
273 printDebug("Serializer::readCategories(): empty"); 273 printDebug("Serializer::readCategories(): empty");
274 return false; 274 return false;
275 } 275 }
276 for (i = 0; i < numCat; ++i) { 276 for (i = 0; i < numCat; ++i) {
277 cur = nl.item(i); 277 cur = nl.item(i);
278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW || 278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
279 cur.nodeName().left(4) == CAT_PREFIX_OLD) { 279 cur.nodeName().left(4) == CAT_PREFIX_OLD) {
280 name = cur.toElement().attribute(CAT_NAME_NEW); 280 name = cur.toElement().attribute(CAT_NAME_NEW);
281 if (name == QString::null) 281 if (name == QString::null)
282 name = cur.toElement().attribute(CAT_NAME_OLD); 282 name = cur.toElement().attribute(CAT_NAME_OLD);
283 PWM_ASSERT(name != QString::null); 283 PWM_ASSERT(name != QString::null);
284 PWM_ASSERT(name != ""); 284 PWM_ASSERT(name != "");
285 curCat.clear(); 285 curCat.clear();
286 curCat.name = name.latin1(); 286 curCat.name = name.latin1();
287 if (!readEntries(cur, &curEntr)) { 287 if (!readEntries(cur, &curEntr)) {
288 dta->clear(); 288 dta->clear();
289 return false; 289 return false;
290 } 290 }
291 curCat.d = curEntr; 291 curCat.d = curEntr;
292 dta->push_back(curCat); 292 dta->push_back(curCat);
293 } else { 293 } else {
294 printDebug("Serializer::readCategories(): uh? not a category?"); 294 printDebug("Serializer::readCategories(): uh? not a category?");
295 } 295 }
296 } 296 }
297 return true; 297 return true;
298} 298}
299 299
300bool Serializer::readEntries(const QDomNode &n, 300bool Serializer::readEntries(const QDomNode &n,
301 vector<PwMDataItem> *dta) 301 vector<PwMDataItem> *dta)
302{ 302{
303 QDomNodeList nl(n.childNodes()); 303 QDomNodeList nl(n.childNodes());
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, 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. 308 // we call clear on it. Reason: Information in the file we will read might be incomplete.
309 // e.g. the metadata is missing. 309 // e.g. the metadata is missing.
310 curEntr.clear(true); 310 curEntr.clear(true);
311 311
312 dta->clear(); 312 dta->clear();
313 for (i = 0; i < numEntr; ++i) { 313 for (i = 0; i < numEntr; ++i) {
314 cur = nl.item(i); 314 cur = nl.item(i);
315 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || 315 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
316 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { 316 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
317 if (!extractEntry(cur, &curEntr)) { 317 if (!extractEntry(cur, &curEntr)) {
318 return false; 318 return false;
319 } 319 }
320 dta->push_back(curEntr); 320 dta->push_back(curEntr);
321 } else { 321 } else {
322 printDebug("Serializer::readEntries(): hm? not an entry?"); 322 printDebug("Serializer::readEntries(): hm? not an entry?");
323 } 323 }
324 } 324 }
325 return true; 325 return true;
326} 326}
327 327
328bool Serializer::extractEntry(const QDomNode &n, 328bool Serializer::extractEntry(const QDomNode &n,
329 PwMDataItem *dta) 329 PwMDataItem *dta)
330{ 330{
331 QDomNodeList nl(n.childNodes()); 331 QDomNodeList nl(n.childNodes());
332 QDomNode cur, cdata; 332 QDomNode cur, cdata;
333 unsigned int cnt = nl.count(), i; 333 unsigned int cnt = nl.count(), i;
334 QString name, text; 334 QString name, text;
335 335
336 if (!cnt) { 336 if (!cnt) {
337 printDebug("Serializer::extractEntry(): empty"); 337 printDebug("Serializer::extractEntry(): empty");
338 return false; 338 return false;
339 } 339 }
340 dta->clear(); 340 dta->clear();
341 for (i = 0; i < cnt; ++i) { 341 for (i = 0; i < cnt; ++i) {
342 cur = nl.item(i); 342 cur = nl.item(i);
343 name = cur.nodeName(); 343 name = cur.nodeName();
344 cdata = cur.firstChild(); 344 cdata = cur.firstChild();
345 if (unlikely(cdata.isCDATASection())) { 345 if (unlikely(cdata.isCDATASection())) {
346 text = cdata.toCDATASection().data(); 346 text = cdata.toCDATASection().data();
347 } else if (likely(cur.isElement())) { 347 } else if (likely(cur.isElement())) {
348 text = cur.toElement().text(); 348 text = cur.toElement().text();
349 } else { 349 } else {
350 printDebug("Serializer::extractEntry(): neither CDATA nor element."); 350 printDebug("Serializer::extractEntry(): neither CDATA nor element.");
351 return false; 351 return false;
352 } 352 }
353 if (text == " ") 353 if (text == " ")
354 text = ""; // for backward compatibility. 354 text = ""; // for backward compatibility.
355 if (name == ENTRY_DESC_NEW || 355 if (name == ENTRY_DESC_NEW ||
356 name == ENTRY_DESC_OLD) { 356 name == ENTRY_DESC_OLD) {
357 dta->desc = unescapeEntryData(text).latin1(); 357 dta->desc = unescapeEntryData(text).latin1();
358 } else if (name == ENTRY_NAME_NEW || 358 } else if (name == ENTRY_NAME_NEW ||
359 name == ENTRY_NAME_OLD) { 359 name == ENTRY_NAME_OLD) {
360 dta->name = unescapeEntryData(text).latin1(); 360 dta->name = unescapeEntryData(text).latin1();
361 } else if (name == ENTRY_PW_NEW || 361 } else if (name == ENTRY_PW_NEW ||
362 name == ENTRY_PW_OLD) { 362 name == ENTRY_PW_OLD) {
363 dta->pw = unescapeEntryData(text).latin1(); 363 dta->pw = unescapeEntryData(text).latin1();
364 } else if (name == ENTRY_COMMENT_NEW || 364 } else if (name == ENTRY_COMMENT_NEW ||
365 name == ENTRY_COMMENT_OLD) { 365 name == ENTRY_COMMENT_OLD) {
366 dta->comment = unescapeEntryData(text).latin1(); 366 dta->comment = unescapeEntryData(text).latin1();
367 } else if (name == ENTRY_URL_NEW || 367 } else if (name == ENTRY_URL_NEW ||
368 name == ENTRY_URL_OLD) { 368 name == ENTRY_URL_OLD) {
369 dta->url = unescapeEntryData(text).latin1(); 369 dta->url = unescapeEntryData(text).latin1();
370 } else if (name == ENTRY_LAUNCHER_NEW || 370 } else if (name == ENTRY_LAUNCHER_NEW ||
371 name == ENTRY_LAUNCHER_OLD) { 371 name == ENTRY_LAUNCHER_OLD) {
372 dta->launcher = unescapeEntryData(text).latin1(); 372 dta->launcher = unescapeEntryData(text).latin1();
373 } else if (name == ENTRY_LVP_NEW || 373 } else if (name == ENTRY_LVP_NEW ||
374 name == ENTRY_LVP_OLD) { 374 name == ENTRY_LVP_OLD) {
375 dta->listViewPos = strtol(text.latin1(), 0, 10); 375 dta->listViewPos = strtol(text.latin1(), 0, 10);
376 } else if (name == ENTRY_BIN_NEW) { 376 } else if (name == ENTRY_BIN_NEW) {
377 // ENTRY_BIN_NEW == ENTRY_BIN_OLD 377 // ENTRY_BIN_NEW == ENTRY_BIN_OLD
378 if (text == "0") { 378 if (text == "0") {
379 dta->binary = false; 379 dta->binary = false;
380 } else { 380 } else {
381 dta->binary = true; 381 dta->binary = true;
382 } 382 }
383 } else if (name == ENTRY_META_NEW) { 383 } else if (name == ENTRY_META_NEW) {
384 // ENTRY_META_NEW == ENTRY_META_OLD 384 // ENTRY_META_NEW == ENTRY_META_OLD
385 if (!extractMeta(cur, &dta->meta)) 385 if (!extractMeta(cur, &dta->meta))
386 return false; 386 return false;
387 } else { 387 } else {
388 printDebug(string("Serializer::extractEntry(): invalid: ") 388 printDebug(string("Serializer::extractEntry(): invalid: ")
389 + name.latin1()); 389 + name.latin1());
390 } 390 }
391 } 391 }
392 dta->lockStat = defaultLockStat; 392 dta->lockStat = defaultLockStat;
393 return true; 393 return true;
394} 394}
395 395
396bool Serializer::extractMeta(const QDomNode &n, 396bool Serializer::extractMeta(const QDomNode &n,
397 PwMMetaData *dta) 397 PwMMetaData *dta)
398{ 398{
399 QDomNode cur(n.firstChild()); 399 QDomNode cur(n.firstChild());
400 QString name, val; 400 QString name, val;
401 while (!cur.isNull()) { 401 while (!cur.isNull()) {
402 name = cur.nodeName(); 402 name = cur.nodeName();
403 val = cur.toElement().text(); 403 val = cur.toElement().text();
404 if (val == "") { 404 if (val == "") {
405 cur = cur.nextSibling(); 405 cur = cur.nextSibling();
406 continue; 406 continue;
407 } 407 }
408 408
409 //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. 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. 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. 411 //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates.
412 412
413 QDateTime dtval; //dtval should be invalid by definition. 413 QDateTime dtval; //dtval should be invalid by definition.
414 414
415 if ((name == META_CREATE_DATE) || 415 if ((name == META_CREATE_DATE) ||
416 (name == META_VALID_DATE) || 416 (name == META_VALID_DATE) ||
417 (name == META_EXPIRE_DATE) || 417 (name == META_EXPIRE_DATE) ||
418 (name == META_UPDATE_DATE)) 418 (name == META_UPDATE_DATE))
419 { 419 {
420 //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); 420 //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length());
421 421
422#ifndef PWM_EMBEDDED 422#ifndef PWM_EMBEDDED
423 dtval = QDateTime::fromString(val, Qt::ISODate); 423 dtval = QDateTime::fromString(val, Qt::ISODate);
424#else 424#else
425 bool ok; 425 bool ok;
426 dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 426 dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
427 427
428 if (ok == false) 428 if (ok == false)
429 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); 429 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
430#endif 430#endif
431 431
432 //if the parsed data is wrong, dtval should be invalid at this time. 432 //if the parsed data is wrong, dtval should be invalid at this time.
433 433
434 } 434 }
435 435
436 if (name == META_CREATE_DATE) { 436 if (name == META_CREATE_DATE) {
437 dta->create = dtval; 437 dta->create = dtval;
438 } else if (name == META_VALID_DATE) { 438 } else if (name == META_VALID_DATE) {
439 dta->valid = dtval; 439 dta->valid = dtval;
440 } else if (name == META_EXPIRE_DATE) { 440 } else if (name == META_EXPIRE_DATE) {
441 dta->expire = dtval; 441 dta->expire = dtval;
442 } else if (name == META_UPDATE_DATE) { 442 } else if (name == META_UPDATE_DATE) {
443 dta->update = dtval; 443 dta->update = dtval;
444 } else if (name == META_UPDATE_INT) { 444 } else if (name == META_UPDATE_INT) {
445 dta->updateInt = strtoul(val.latin1(), 0, 10); 445 dta->updateInt = strtoul(val.latin1(), 0, 10);
446 } else if (name == META_UNIQUEID) { 446 } else if (name == META_UNIQUEID) {
447 dta->uniqueid = unescapeEntryData(val).latin1(); 447 dta->uniqueid = unescapeEntryData(val).latin1();
448 } else { 448 } else {
449 printDebug(string("extractMeta(): invalid: ") 449 printDebug(string("extractMeta(): invalid: ")
450 + name.latin1()); 450 + name.latin1());
451 } 451 }
452 452
453 cur = cur.nextSibling(); 453 cur = cur.nextSibling();
454 } 454 }
455 return true; 455 return true;
456} 456}
457 457
458bool Serializer::checkValid() 458bool Serializer::checkValid()
459{ 459{
460 PWM_ASSERT(domDoc); 460 PWM_ASSERT(domDoc);
461 QDomElement root(domDoc->documentElement()); 461 QDomElement root(domDoc->documentElement());
462 if (root.nodeName() != ROOT_MAGIC_NEW && 462 if (root.nodeName() != ROOT_MAGIC_NEW &&
463 root.nodeName() != ROOT_MAGIC_OLD) { 463 root.nodeName() != ROOT_MAGIC_OLD) {
464 printDebug("Serializer: wrong magic"); 464 printDebug("Serializer: wrong magic");
465 return false; 465 return false;
466 } 466 }
467 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && 467 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW &&
468 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { 468 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) {
469 printDebug("Serializer: wrong version"); 469 printDebug("Serializer: wrong version");
470 return false; 470 return false;
471 } 471 }
472 return true; 472 return true;
473} 473}
474 474
475QDomElement Serializer::genNewRoot() 475QDomElement Serializer::genNewRoot()
476{ 476{
477 PWM_ASSERT(domDoc); 477 PWM_ASSERT(domDoc);
478 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); 478 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR));
479 root.setAttribute(VER_STR_WR, COMPAT_VER_WR); 479 root.setAttribute(VER_STR_WR, COMPAT_VER_WR);
480 domDoc->appendChild(root); 480 domDoc->appendChild(root);
481 return root; 481 return root;
482} 482}
483 483
484bool Serializer::addCategories(QDomElement *e, 484bool Serializer::addCategories(QDomElement *e,
485 const vector<PwMCategoryItem> &dta) 485 const vector<PwMCategoryItem> &dta)
486{ 486{
487 unsigned int numCat = dta.size(), i; 487 unsigned int numCat = dta.size(), i;
488 QString curId, curName; 488 QString curId, curName;
489 QDomElement curCat; 489 QDomElement curCat;
490 490
491 for (i = 0; i < numCat; ++i) { 491 for (i = 0; i < numCat; ++i) {
492 curId = CAT_PREFIX_WR; 492 curId = CAT_PREFIX_WR;
493 curId += tostr(i).c_str(); 493 curId += tostr(i).c_str();
494 curName = dta[i].name.c_str(); 494 curName = dta[i].name.c_str();
495 curCat = domDoc->createElement(curId); 495 curCat = domDoc->createElement(curId);
496 curCat.setAttribute(CAT_NAME_WR, curName); 496 curCat.setAttribute(CAT_NAME_WR, curName);
497 if (!addEntries(&curCat, dta[i].d)) { 497 if (!addEntries(&curCat, dta[i].d)) {
498 return false; 498 return false;
499 } 499 }
500 e->appendChild(curCat); 500 e->appendChild(curCat);
501 } 501 }
502 return true; 502 return true;
503} 503}
504 504
505bool Serializer::addEntries(QDomElement *e, 505bool Serializer::addEntries(QDomElement *e,
506 const vector<PwMDataItem> &dta) 506 const vector<PwMDataItem> &dta)
507{ 507{
508 unsigned int numEntr = dta.size(), i; 508 unsigned int numEntr = dta.size(), i;
509 QString curId; 509 QString curId;
510 QDomElement curEntr; 510 QDomElement curEntr;
511 511
512 for (i = 0; i < numEntr; ++i) { 512 for (i = 0; i < numEntr; ++i) {
513 curId = ENTRY_PREFIX_WR; 513 curId = ENTRY_PREFIX_WR;
514 curId += tostr(i).c_str(); 514 curId += tostr(i).c_str();
515 curEntr = domDoc->createElement(curId); 515 curEntr = domDoc->createElement(curId);
516 if (!writeEntry(&curEntr, dta[i])) { 516 if (!writeEntry(&curEntr, dta[i])) {
517 return false; 517 return false;
518 } 518 }
519 e->appendChild(curEntr); 519 e->appendChild(curEntr);
520 } 520 }
521 return true; 521 return true;
522} 522}
523 523
524bool Serializer::writeEntry(QDomElement *e, 524bool Serializer::writeEntry(QDomElement *e,
525 const PwMDataItem &_dta) 525 const PwMDataItem &_dta)
526{ 526{
527#if WRITE_CDATA_SEC != 0 527#if WRITE_CDATA_SEC != 0
528 # define new_text(x)domDoc->createCDATASection(x) 528 # define new_text(x)domDoc->createCDATASection(x)
529 QDomCDATASection curText; 529 QDomCDATASection curText;
530#else 530#else
531 # define new_text(x)domDoc->createTextNode(x) 531 # define new_text(x)domDoc->createTextNode(x)
532 QDomText curText; 532 QDomText curText;
533#endif 533#endif
534 534
535 QDomText plainText; 535 QDomText plainText;
536 QDomElement tag; 536 QDomElement tag;
537 537
538 // begin -- This is for compatibility with the old serializer 538 // begin -- This is for compatibility with the old serializer
539 PwMDataItem dta = _dta; 539 PwMDataItem dta = _dta;
540 if (!dta.desc.size()) 540 if (!dta.desc.size())
541 dta.desc = " "; 541 dta.desc = " ";
542 if (!dta.name.size()) 542 if (!dta.name.size())
diff --git a/pwmanager/pwmanager/serializer.h b/pwmanager/pwmanager/serializer.h
index ee61b94..df50e42 100644
--- a/pwmanager/pwmanager/serializer.h
+++ b/pwmanager/pwmanager/serializer.h
@@ -1,115 +1,115 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13/*************************************************************************** 13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk 14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager 15 * This file is originaly based on version 1.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde 16 * and was modified to run on embedded devices that run microkde
17 * 17 *
18 * $Id$ 18 * $Id$
19 **************************************************************************/ 19 **************************************************************************/
20 20
21#ifndef __SERIALIZER_H 21#ifndef __SERIALIZER_H
22#define __SERIALIZER_H 22#define __SERIALIZER_H
23 23
24#include "pwmdoc.h" 24#include "pwmdoc.h"
25 25
26#include <qcstring.h> 26#include <qcstring.h>
27#include <qdom.h> 27#include <qdom.h>
28 28
29#include <vector> 29#include <vector>
30 30
31using std::vector; 31using std::vector;
32 32
33/** This serializes its input data into 33/** This serializes its input data into
34 * the PwManager-XML-datastream, that becomes 34 * the PwManager-XML-datastream, that becomes
35 * encrypted and maybe compressed 35 * encrypted and maybe compressed
36 */ 36 */
37class Serializer 37class Serializer
38{ 38{
39public: 39public:
40 /** construct an empty serializer document */ 40 /** construct an empty serializer document */
41 Serializer(); 41 Serializer();
42 /** construct a serializer document and parse "buffer" */ 42 /** construct a serializer document and parse "buffer" */
43 Serializer(const QCString &buffer); 43 Serializer(const QCString &buffer);
44 /** destructor */ 44 /** destructor */
45 virtual ~Serializer(); 45 virtual ~Serializer();
46 46
47 /** clears all data */ 47 /** clears all data */
48 void clear(); 48 void clear();
49 /** parse the given data buffer */ 49 /** parse the given data buffer */
50 bool parseXml(const QCString &buffer); 50 bool parseXml(const QCString &buffer);
51 /** returns the current XML data */ 51 /** returns the current XML data */
52 QCString getXml(); 52 QCString getXml();
53 /** serialize "dta" and store it as XML data */ 53 /** serialize "dta" and store it as XML data */
54 //US ENH: we need to serialize and deserialize not only categories, but also synctargets 54 //US ENH: we need to serialize and deserialize not only categories, but also synctargets
55 bool serialize(PwMItem &dta); 55 bool serialize(PwMItem &dta);
56 /** deserialize the (parsed) XML data and store it in "dta" */ 56 /** deserialize the (parsed) XML data and store it in "dta" */
57 bool deSerialize(PwMItem *dta); 57 bool deSerialize(PwMItem *dta);
58 /** sets the initial default lockStat we should assign */ 58 /** sets the initial default lockStat we should assign */
59 void setDefaultLockStat(bool stat) 59 void setDefaultLockStat(bool stat)
60 { defaultLockStat = stat; } 60 { defaultLockStat = stat; }
61 61
62protected: 62protected:
63 /** main data holder */ 63 /** main data holder */
64 QDomDocument *domDoc; 64 QDomDocument *domDoc;
65 /** default lockStat to assign */ 65 /** default lockStat to assign */
66 bool defaultLockStat; 66 bool defaultLockStat;
67 67
68protected: 68protected:
69 /** check if this is valid PwManager XML data */ 69 /** check if this is valid PwManager XML data */
70 bool checkValid(); 70 bool checkValid();
71 /** read the categories in the node "n" */ 71 /** read the categories in the node "n" */
72 bool readCategories(const QDomNode &n, 72 bool readCategories(const QDomNode &n,
73 vector<PwMCategoryItem> *dta); 73 vector<PwMCategoryItem> *dta);
74 /** read the entries in the node "n" */ 74 /** read the entries in the node "n" */
75 bool readEntries(const QDomNode &n, 75 bool readEntries(const QDomNode &n,
76 vector<PwMDataItem> *dta); 76 vector<PwMDataItem> *dta);
77 /** extract the data out of the given item at "n" */ 77 /** extract the data out of the given item at "n" */
78 bool extractEntry(const QDomNode &n, 78 bool extractEntry(const QDomNode &n,
79 PwMDataItem *dta); 79 PwMDataItem *dta);
80 /** extract the meta-data */ 80 /** extract the meta-data */
81 bool extractMeta(const QDomNode &n, 81 bool extractMeta(const QDomNode &n,
82 PwMMetaData *dta); 82 PwMMetaData *dta);
83 /** generates a new root node and sets all initial parameters */ 83 /** generates a new root node and sets all initial parameters */
84 QDomElement genNewRoot(); 84 QDomElement genNewRoot();
85 /** add new categories to the XML data stream in e */ 85 /** add new categories to the XML data stream in e */
86 bool addCategories(QDomElement *e, 86 bool addCategories(QDomElement *e,
87 const vector<PwMCategoryItem> &dta); 87 const vector<PwMCategoryItem> &dta);
88 /** add the given new entries to the XML data stream in e */ 88 /** add the given new entries to the XML data stream in e */
89 bool addEntries(QDomElement *e, 89 bool addEntries(QDomElement *e,
90 const vector<PwMDataItem> &dta); 90 const vector<PwMDataItem> &dta);
91 /** do serialize and write the given entry to the XML stream */ 91 /** do serialize and write the given entry to the XML stream */
92 bool writeEntry(QDomElement *e, 92 bool writeEntry(QDomElement *e,
93 const PwMDataItem &_dta); 93 const PwMDataItem &_dta);
94 /** write the entry meta data to the xml stream */ 94 /** write the entry meta data to the xml stream */
95 bool writeMeta(QDomElement *e, 95 bool writeMeta(QDomElement *e,
96 const PwMMetaData &dta); 96 const PwMMetaData &dta);
97 /** escape illegal characters out of the given entry data string */ 97 /** escape illegal characters out of the given entry data string */
98 QString escapeEntryData(QString dta); 98 QString escapeEntryData(QString dta);
99 /** un-escape illegal characters out of the given entry data string */ 99 /** un-escape illegal characters out of the given entry data string */
100 QString unescapeEntryData(QString dta); 100 QString unescapeEntryData(QString dta);
101 101
102 102
103 103
104 //US ENH: the following methods are getting used to write/read sync entries 104 //US ENH: the following methods are getting used to write/read sync entries
105 /** read the syncentries in the node "n" */ 105 /** read the syncentries in the node "n" */
106 bool readSyncData(const QDomNode &n, 106 bool readSyncData(const QDomNode &n,
107 vector<PwMSyncItem> *dta); 107 vector<PwMSyncItem> *dta);
108 108
109 /** add new syncentries to the XML data stream in e */ 109 /** add new syncentries to the XML data stream in e */
110 bool addSyncData(QDomElement *e, 110 bool addSyncData(QDomElement *e,
111 const vector<PwMSyncItem> &dta); 111 const vector<PwMSyncItem> &dta);
112 112
113}; 113};
114 114
115#endif // __SERIALIZER_H 115#endif // __SERIALIZER_H