author | zautrix <zautrix> | 2004-10-19 20:18:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-19 20:18:42 (UTC) |
commit | 72fcd35606475a620a8aab7dd4cf9cbaf4b0acee (patch) (unidiff) | |
tree | 396f0af18109c1cbc0075d9409743fc2fc1c650b | |
parent | eca49bb06a71980ef61d078904573f25890fc7f2 (diff) | |
download | kdepimpi-72fcd35606475a620a8aab7dd4cf9cbaf4b0acee.zip kdepimpi-72fcd35606475a620a8aab7dd4cf9cbaf4b0acee.tar.gz kdepimpi-72fcd35606475a620a8aab7dd4cf9cbaf4b0acee.tar.bz2 |
crypto changes
-rw-r--r-- | Makefile | 24 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 11 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 2 |
3 files changed, 33 insertions, 4 deletions
@@ -1,338 +1,362 @@ | |||
1 | export KDEPIMDIR = $(shell pwd) | 1 | export KDEPIMDIR = $(shell pwd) |
2 | 2 | ||
3 | export KDEPIM_VERSION=$(shell sed -e 's/.*\"\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/' < version) | 3 | export KDEPIM_VERSION=$(shell sed -e 's/.*\"\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/' < version) |
4 | 4 | ||
5 | ifeq ($(PLATFORM) , zaurus) | 5 | ifeq ($(PLATFORM) , zaurus) |
6 | BUILD_NO_LDAP_PLUGIN=1 | 6 | BUILD_NO_LDAP_PLUGIN=1 |
7 | endif | 7 | endif |
8 | 8 | ||
9 | ifneq ($(PLATFORM) , zaurus) | 9 | ifneq ($(PLATFORM) , zaurus) |
10 | BUILD_NO_SHARP_PLUGIN=1 | 10 | BUILD_NO_SHARP_PLUGIN=1 |
11 | endif | 11 | endif |
12 | 12 | ||
13 | SUBDIRS_MICROKDE = \ | 13 | SUBDIRS_MICROKDE = \ |
14 | libical/src/libical \ | 14 | libical/src/libical \ |
15 | libical/src/libicalss \ | 15 | libical/src/libicalss \ |
16 | qtcompat \ | 16 | qtcompat \ |
17 | microkde \ | 17 | microkde \ |
18 | libkcal \ | 18 | libkcal \ |
19 | libkdepim \ | 19 | libkdepim \ |
20 | kabc \ | 20 | kabc \ |
21 | kabc/formats/binary \ | 21 | kabc/formats/binary \ |
22 | kabc/plugins/file \ | 22 | kabc/plugins/file \ |
23 | kabc/plugins/dir \ | 23 | kabc/plugins/dir \ |
24 | korganizer \ | 24 | korganizer \ |
25 | kalarmd \ | 25 | kalarmd \ |
26 | kaddressbook | 26 | kaddressbook |
27 | 27 | ||
28 | SUBDIRS_QTOPIA_PLUGIN = \ | 28 | SUBDIRS_QTOPIA_PLUGIN = \ |
29 | kabc/plugins/qtopia | 29 | kabc/plugins/qtopia |
30 | 30 | ||
31 | SUBDIRS_OPIE_PLUGIN = \ | 31 | SUBDIRS_OPIE_PLUGIN = \ |
32 | kabc/plugins/opie | 32 | kabc/plugins/opie |
33 | 33 | ||
34 | SUBDIRS_SHARP_PLUGIN = \ | 34 | SUBDIRS_SHARP_PLUGIN = \ |
35 | kabc/plugins/sharpdtm | 35 | kabc/plugins/sharpdtm |
36 | 36 | ||
37 | SUBDIRS_LDAP_PLUGIN = \ | 37 | SUBDIRS_LDAP_PLUGIN = \ |
38 | kabc/plugins/ldap | 38 | kabc/plugins/ldap |
39 | 39 | ||
40 | SUBDIRS_MICROMAIL = \ | 40 | SUBDIRS_MICROMAIL = \ |
41 | kmicromail/libetpan \ | 41 | kmicromail/libetpan \ |
42 | kmicromail/libmailwrapper \ | 42 | kmicromail/libmailwrapper \ |
43 | kmicromail | 43 | kmicromail |
44 | 44 | ||
45 | SUBDIRS_GAMMU = \ | 45 | SUBDIRS_GAMMU = \ |
46 | gammu/emb/common \ | 46 | gammu/emb/common \ |
47 | gammu/emb/gammu | 47 | gammu/emb/gammu |
48 | 48 | ||
49 | SUBDIRS_PWMANAGER = \ | 49 | SUBDIRS_PWMANAGER = \ |
50 | pwmanager/libcrypt/mpi \ | ||
51 | pwmanager/libcrypt/error \ | ||
52 | pwmanager/libcrypt/cipher \ | ||
53 | pwmanager/libcrypt/zlib \ | ||
50 | pwmanager/pwmanager | 54 | pwmanager/pwmanager |
51 | 55 | ||
52 | SUBDIRS = \ | 56 | SUBDIRS = \ |
53 | $(SUBDIRS_MICROKDE) \ | 57 | $(SUBDIRS_MICROKDE) \ |
54 | $(SUBDIRS_QTOPIA_PLUGIN) \ | 58 | $(SUBDIRS_QTOPIA_PLUGIN) \ |
55 | $(SUBDIRS_OPIE_PLUGIN) \ | 59 | $(SUBDIRS_OPIE_PLUGIN) \ |
56 | $(SUBDIRS_SHARP_PLUGIN) \ | 60 | $(SUBDIRS_SHARP_PLUGIN) \ |
57 | $(SUBDIRS_LDAP_PLUGIN) \ | 61 | $(SUBDIRS_LDAP_PLUGIN) \ |
58 | $(SUBDIRS_MICROMAIL) \ | 62 | $(SUBDIRS_MICROMAIL) \ |
59 | $(SUBDIRS_GAMMU) \ | 63 | $(SUBDIRS_GAMMU) \ |
60 | $(SUBDIRS_PWMANAGER) | 64 | $(SUBDIRS_PWMANAGER) |
61 | 65 | ||
62 | 66 | ||
63 | all: build_microkde \ | 67 | all: build_microkde \ |
64 | build_qtopia_plugin \ | 68 | build_qtopia_plugin \ |
65 | build_opie_plugin \ | 69 | build_opie_plugin \ |
66 | build_sharp_plugin \ | 70 | build_sharp_plugin \ |
67 | build_ldap_plugin \ | 71 | build_ldap_plugin \ |
68 | build_micromail \ | 72 | build_micromail \ |
69 | build_gammu \ | 73 | build_gammu \ |
70 | build_pwmanager | 74 | build_pwmanager |
71 | 75 | ||
72 | 76 | ||
73 | build_microkde: variable_test tmake | 77 | build_microkde: variable_test tmake |
74 | for i in $(SUBDIRS_MICROKDE); do pushd $$i; \ | 78 | for i in $(SUBDIRS_MICROKDE); do pushd $$i; \ |
75 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 79 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
76 | done | 80 | done |
77 | 81 | ||
78 | build_qtopia_plugin: build_microkde | 82 | build_qtopia_plugin: build_microkde |
79 | ifdef BUILD_NO_QTOPIA_PLUGIN | 83 | ifdef BUILD_NO_QTOPIA_PLUGIN |
80 | @echo == qtopia plugin not build. | 84 | @echo == qtopia plugin not build. |
81 | else | 85 | else |
82 | for i in $(SUBDIRS_QTOPIA_PLUGIN); do pushd $$i; \ | 86 | for i in $(SUBDIRS_QTOPIA_PLUGIN); do pushd $$i; \ |
83 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 87 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
84 | done | 88 | done |
85 | endif | 89 | endif |
86 | 90 | ||
87 | build_opie_plugin: build_microkde | 91 | build_opie_plugin: build_microkde |
88 | ifdef BUILD_NO_OPIE_PLUGIN | 92 | ifdef BUILD_NO_OPIE_PLUGIN |
89 | @echo == opie plugin not build. | 93 | @echo == opie plugin not build. |
90 | else | 94 | else |
91 | for i in $(SUBDIRS_OPIE_PLUGIN); do pushd $$i; \ | 95 | for i in $(SUBDIRS_OPIE_PLUGIN); do pushd $$i; \ |
92 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 96 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
93 | done | 97 | done |
94 | endif | 98 | endif |
95 | 99 | ||
96 | build_sharp_plugin: build_microkde | 100 | build_sharp_plugin: build_microkde |
97 | ifdef BUILD_NO_SHARP_PLUGIN | 101 | ifdef BUILD_NO_SHARP_PLUGIN |
98 | @echo == ldap plugin not build. | 102 | @echo == ldap plugin not build. |
99 | else | 103 | else |
100 | for i in $(SUBDIRS_SHARP_PLUGIN); do pushd $$i; \ | 104 | for i in $(SUBDIRS_SHARP_PLUGIN); do pushd $$i; \ |
101 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 105 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
102 | done | 106 | done |
103 | endif | 107 | endif |
104 | 108 | ||
105 | build_ldap_plugin: build_microkde | 109 | build_ldap_plugin: build_microkde |
106 | ifdef BUILD_NO_LDAP_PLUGIN | 110 | ifdef BUILD_NO_LDAP_PLUGIN |
107 | @echo == ldap plugin not build. | 111 | @echo == ldap plugin not build. |
108 | else | 112 | else |
109 | for i in $(SUBDIRS_LDAP_PLUGIN); do pushd $$i; \ | 113 | for i in $(SUBDIRS_LDAP_PLUGIN); do pushd $$i; \ |
110 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 114 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
111 | done | 115 | done |
112 | endif | 116 | endif |
113 | 117 | ||
114 | 118 | ||
115 | build_micromail: build_microkde | 119 | build_micromail: build_microkde |
116 | ifdef BUILD_NO_MICROMAIL | 120 | ifdef BUILD_NO_MICROMAIL |
117 | @echo == kmicromail not build. | 121 | @echo == kmicromail not build. |
118 | else | 122 | else |
119 | for i in $(SUBDIRS_MICROMAIL); do pushd $$i; \ | 123 | for i in $(SUBDIRS_MICROMAIL); do pushd $$i; \ |
120 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 124 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
121 | done | 125 | done |
122 | endif | 126 | endif |
123 | 127 | ||
124 | build_gammu: variable_test tmake | 128 | build_gammu: variable_test tmake |
125 | ifdef BUILD_NO_GAMMU | 129 | ifdef BUILD_NO_GAMMU |
126 | @echo == gammu not build. | 130 | @echo == gammu not build. |
127 | else | 131 | else |
128 | for i in $(SUBDIRS_GAMMU); do pushd $$i; \ | 132 | for i in $(SUBDIRS_GAMMU); do pushd $$i; \ |
129 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 133 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
130 | done | 134 | done |
131 | endif | 135 | endif |
132 | 136 | ||
133 | build_pwmanager: build_microkde | 137 | build_pwmanager: build_microkde |
134 | ifdef BUILD_NO_PWMANAGER | 138 | ifdef BUILD_NO_PWMANAGER |
135 | @echo == pwmanager not build. | 139 | @echo == pwmanager not build. |
136 | else | 140 | else |
137 | for i in $(SUBDIRS_PWMANAGER); do pushd $$i; \ | 141 | for i in $(SUBDIRS_PWMANAGER); do pushd $$i; \ |
138 | make -f Makefile$(PLATFORM) || exit 1; popd; \ | 142 | make -f Makefile$(PLATFORM) || exit 1; popd; \ |
139 | done | 143 | done |
140 | endif | 144 | endif |
141 | 145 | ||
142 | 146 | ||
143 | variable_info: | 147 | variable_info: |
144 | @echo -------------------------------------- | 148 | @echo -------------------------------------- |
145 | @echo KDEPIM buildsystem, variableinfo... | 149 | @echo KDEPIM buildsystem, variableinfo... |
146 | @echo KDEPIMDIR=$(KDEPIMDIR) | 150 | @echo KDEPIMDIR=$(KDEPIMDIR) |
147 | @echo QTDIR=$(QTDIR) | 151 | @echo QTDIR=$(QTDIR) |
148 | @echo QPEDIR=$(QPEDIR) | 152 | @echo QPEDIR=$(QPEDIR) |
149 | @echo OPIEDIR=$(OPIEDIR) | 153 | @echo OPIEDIR=$(OPIEDIR) |
150 | @echo PLATFORM=$(PLATFORM) | 154 | @echo PLATFORM=$(PLATFORM) |
151 | @echo RELEASE_DEBUG=$(RELEASE_DEBUG) | 155 | @echo RELEASE_DEBUG=$(RELEASE_DEBUG) |
152 | @echo BUILD_NO_MICROMAIL=$(BUILD_NO_MICROMAIL) | 156 | @echo BUILD_NO_MICROMAIL=$(BUILD_NO_MICROMAIL) |
153 | @echo BUILD_NO_LDAP_PLUGIN=$(BUILD_NO_LDAP_PLUGIN) | 157 | @echo BUILD_NO_LDAP_PLUGIN=$(BUILD_NO_LDAP_PLUGIN) |
154 | @echo BUILD_NO_OPIE_PLUGIN=$(BUILD_NO_OPIE_PLUGIN) | 158 | @echo BUILD_NO_OPIE_PLUGIN=$(BUILD_NO_OPIE_PLUGIN) |
155 | @echo BUILD_NO_QTOPIA_PLUGIN=$(BUILD_NO_QTOPIA_PLUGIN) | 159 | @echo BUILD_NO_QTOPIA_PLUGIN=$(BUILD_NO_QTOPIA_PLUGIN) |
156 | @echo BUILD_NO_SHARP_PLUGIN=$(BUILD_NO_SHARP_PLUGIN) | 160 | @echo BUILD_NO_SHARP_PLUGIN=$(BUILD_NO_SHARP_PLUGIN) |
157 | ifndef BUILD_NO_SHARP_PLUGIN | 161 | ifndef BUILD_NO_SHARP_PLUGIN |
158 | @echo SHARPDTMSDK=$(SHARPDTMSDK) | 162 | @echo SHARPDTMSDK=$(SHARPDTMSDK) |
159 | endif | 163 | endif |
160 | @echo BUILD_NO_GAMMU=$(BUILD_NO_GAMMU) | 164 | @echo BUILD_NO_GAMMU=$(BUILD_NO_GAMMU) |
161 | @echo BUILD_NO_PWMANAGER=$(BUILD_NO_PWMANAGER) | 165 | @echo BUILD_NO_PWMANAGER=$(BUILD_NO_PWMANAGER) |
162 | @echo -------------------------------------- | 166 | @echo -------------------------------------- |
163 | 167 | ||
164 | variable_test: variable_info | 168 | variable_test: variable_info |
165 | @echo KDEPIM buildsystem, variablecheck... | 169 | @echo KDEPIM buildsystem, variablecheck... |
166 | ifndef KDEPIMDIR | 170 | ifndef KDEPIMDIR |
167 | @echo KDEPIMDIR is not defined. | 171 | @echo KDEPIMDIR is not defined. |
168 | $(error KDEPIMDIR is not defined) | 172 | $(error KDEPIMDIR is not defined) |
169 | endif | 173 | endif |
170 | ifndef PLATFORM | 174 | ifndef PLATFORM |
171 | @echo PLATFORM is not defined. | 175 | @echo PLATFORM is not defined. |
172 | $(error PLATFORM is not defined) | 176 | $(error PLATFORM is not defined) |
173 | endif | 177 | endif |
174 | ifdef BUILD_NO_LDAP_PLUGIN | 178 | ifdef BUILD_NO_LDAP_PLUGIN |
175 | @echo LDAP PLUGIN will not be build, because BUILD_NO_LDAP_PLUGIN is set to $(BUILD_NO_LDAP_PLUGIN) | 179 | @echo LDAP PLUGIN will not be build, because BUILD_NO_LDAP_PLUGIN is set to $(BUILD_NO_LDAP_PLUGIN) |
176 | endif | 180 | endif |
177 | ifdef BUILD_NO_OPIE_PLUGIN | 181 | ifdef BUILD_NO_OPIE_PLUGIN |
178 | @echo OPIE PLUGIN will not be build, because BUILD_NO_OPIE_PLUGIN is set to $(BUILD_NO_OPIE_PLUGIN) | 182 | @echo OPIE PLUGIN will not be build, because BUILD_NO_OPIE_PLUGIN is set to $(BUILD_NO_OPIE_PLUGIN) |
179 | endif | 183 | endif |
180 | ifdef BUILD_NO_QTOPIA_PLUGIN | 184 | ifdef BUILD_NO_QTOPIA_PLUGIN |
181 | @echo QTOPIA PLUGIN will not be build, because BUILD_NO__QTOPIA_PLUGIN is set to $(BUILD_NO__QTOPIA_PLUGIN) | 185 | @echo QTOPIA PLUGIN will not be build, because BUILD_NO__QTOPIA_PLUGIN is set to $(BUILD_NO__QTOPIA_PLUGIN) |
182 | endif | 186 | endif |
183 | ifdef BUILD_NO_MICROMAIL | 187 | ifdef BUILD_NO_MICROMAIL |
184 | @echo MICROMAIL will not be build, because BUILD_NO_MICROMAIL is set to $(BUILD_NO_MICROMAIL) | 188 | @echo MICROMAIL will not be build, because BUILD_NO_MICROMAIL is set to $(BUILD_NO_MICROMAIL) |
185 | endif | 189 | endif |
186 | ifdef BUILD_NO_SHARP_PLUGIN | 190 | ifdef BUILD_NO_SHARP_PLUGIN |
187 | @echo SHARP PLUGIN will not be build, because BUILD_NO_SHARP_PLUGIN is set to $(BUILD_NO_SHARP_PLUGIN) | 191 | @echo SHARP PLUGIN will not be build, because BUILD_NO_SHARP_PLUGIN is set to $(BUILD_NO_SHARP_PLUGIN) |
188 | else | 192 | else |
189 | ifndef SHARPDTMSDK | 193 | ifndef SHARPDTMSDK |
190 | @echo SHARP PLUGIN can not be build, because SHARPDTMSDK is set to $(SHARPDTMSDK) | 194 | @echo SHARP PLUGIN can not be build, because SHARPDTMSDK is set to $(SHARPDTMSDK) |
191 | $(error SHARPDTMSDK is not defined) | 195 | $(error SHARPDTMSDK is not defined) |
192 | endif | 196 | endif |
193 | endif | 197 | endif |
194 | ifdef BUILD_NO_GAMMU | 198 | ifdef BUILD_NO_GAMMU |
195 | @echo GAMMU will not be build, because BUILD_NO_GAMMU is set to $(BUILD_NO_GAMMU) | 199 | @echo GAMMU will not be build, because BUILD_NO_GAMMU is set to $(BUILD_NO_GAMMU) |
196 | endif | 200 | endif |
197 | ifdef BUILD_NO_PWMANAGER | 201 | ifdef BUILD_NO_PWMANAGER |
198 | @echo PWMANAGER will not be build, because BUILD_NO_PWMANAGER is set to $(BUILD_NO_PWMANAGER) | 202 | @echo PWMANAGER will not be build, because BUILD_NO_PWMANAGER is set to $(BUILD_NO_PWMANAGER) |
199 | endif | 203 | endif |
200 | @echo -------------------------------------- | 204 | @echo -------------------------------------- |
201 | 205 | ||
202 | 206 | ||
203 | objects: | 207 | objects: |
204 | for i in $(SUBDIRS); do mkdir -p $$i/obj/$(PLATFORM); done | 208 | for i in $(SUBDIRS); do mkdir -p $$i/obj/$(PLATFORM); done |
205 | for i in $(SUBDIRS); do mkdir -p $$i/moc/$(PLATFORM); done | 209 | for i in $(SUBDIRS); do mkdir -p $$i/moc/$(PLATFORM); done |
206 | mkdir -p libical/lib/$(PLATFORM) | 210 | mkdir -p libical/lib/$(PLATFORM) |
211 | mkdir -p pwmanager/libcrypt/$(PLATFORM) | ||
207 | 212 | ||
208 | clean: | 213 | clean: |
209 | rm -rf libical/lib/$(PLATFORM)/*; | 214 | rm -rf libical/lib/$(PLATFORM)/*; |
215 | rm -rf pwmanager/libcrypt/$(PLATFORM)/*; | ||
210 | for i in $(SUBDIRS); do pushd $$i; make clean; rm -f *~;\ | 216 | for i in $(SUBDIRS); do pushd $$i; make clean; rm -f *~;\ |
211 | rm -f obj/$(PLATFORM)/*; rm -f moc/$(PLATFORM)/*; rm Makefile$(PLATFORM); popd; \ | 217 | rm -f obj/$(PLATFORM)/*; rm -f moc/$(PLATFORM)/*; rm Makefile$(PLATFORM); popd; \ |
212 | done | 218 | done |
213 | 219 | ||
214 | install: | 220 | install: |
215 | 221 | ||
216 | cd bin/kdepim; make install | 222 | cd bin/kdepim; make install |
217 | cp -r Pim $(QPEDIR)/apps | 223 | cp -r Pim $(QPEDIR)/apps |
218 | cp db2file/db2file $(QPEDIR)/bin/db2file | 224 | cp db2file/db2file $(QPEDIR)/bin/db2file |
219 | cp korganizer/korganizer.desktop $(QPEDIR)/apps/Pim/korganizer.desktop | 225 | cp korganizer/korganizer.desktop $(QPEDIR)/apps/Pim/korganizer.desktop |
220 | cp kaddressbook/kaddressbook.desktop $(QPEDIR)/apps/Pim/kaddressbook.desktop | 226 | cp kaddressbook/kaddressbook.desktop $(QPEDIR)/apps/Pim/kaddressbook.desktop |
221 | cp kmicromail/kmicromail.desktop $(QPEDIR)/apps/Pim/kopiemail.desktop | 227 | cp kmicromail/kmicromail.desktop $(QPEDIR)/apps/Pim/kopiemail.desktop |
222 | cp pwmanager/pwmanager/pwmanager.desktop $(QPEDIR)/apps/Pim/pwmanager.desktop | 228 | cp pwmanager/pwmanager/pwmanager.desktop $(QPEDIR)/apps/Pim/pwmanager.desktop |
223 | 229 | ||
224 | dist: | 230 | dist: |
225 | @echo Dont forget to do "make install" before "make dist" | 231 | @echo Dont forget to do "make install" before "make dist" |
226 | rm -f *arm.ipk | 232 | rm -f *arm.ipk |
227 | rm -f *~ | 233 | rm -f *~ |
228 | cd ..; tar czf kdepim.src.tar.gz --exclude=obj --exclude=moc --exclude=CVS --exclude=Makefilezaurus --exclude=Makefileqtopia kdepim | 234 | cd ..; tar czf kdepim.src.tar.gz --exclude=obj --exclude=moc --exclude=CVS --exclude=Makefilezaurus --exclude=Makefileqtopia kdepim |
229 | mkipks kmicrokdelibs.control | 235 | mkipks kmicrokdelibs.control |
230 | mkipks korganizer.control | 236 | mkipks korganizer.control |
231 | mkipks kaddressbook.control | 237 | mkipks kaddressbook.control |
232 | ifndef BUILD_NO_MICROMAIL | 238 | ifndef BUILD_NO_MICROMAIL |
233 | mkipks kopiemail.control | 239 | mkipks kopiemail.control |
234 | endif | 240 | endif |
235 | mkipks korganizer-alarm.control | 241 | mkipks korganizer-alarm.control |
236 | ifndef BUILD_NO_GAMMU | 242 | ifndef BUILD_NO_GAMMU |
237 | mkipks phoneaccess.control | 243 | mkipks phoneaccess.control |
238 | endif | 244 | endif |
239 | ifndef BUILD_NO_PWMANAGER | 245 | ifndef BUILD_NO_PWMANAGER |
240 | mkipks pwmanager.control | 246 | mkipks pwmanager.control |
241 | endif | 247 | endif |
242 | mkipks pim_TAB_icon.control | 248 | mkipks pim_TAB_icon.control |
243 | 249 | ||
244 | tmake: objects \ | 250 | tmake: objects \ |
245 | qtcompat/Makefile$(PLATFORM) \ | 251 | qtcompat/Makefile$(PLATFORM) \ |
246 | microkde/Makefile$(PLATFORM) \ | 252 | microkde/Makefile$(PLATFORM) \ |
247 | libkcal/Makefile$(PLATFORM) \ | 253 | libkcal/Makefile$(PLATFORM) \ |
248 | libkdepim/Makefile$(PLATFORM) \ | 254 | libkdepim/Makefile$(PLATFORM) \ |
249 | korganizer/Makefile$(PLATFORM) \ | 255 | korganizer/Makefile$(PLATFORM) \ |
250 | kalarmd/Makefile$(PLATFORM) \ | 256 | kalarmd/Makefile$(PLATFORM) \ |
251 | libical/src/libical/Makefile$(PLATFORM) \ | 257 | libical/src/libical/Makefile$(PLATFORM) \ |
252 | libical/src/libicalss/Makefile$(PLATFORM) \ | 258 | libical/src/libicalss/Makefile$(PLATFORM) \ |
253 | kabc/Makefile$(PLATFORM) \ | 259 | kabc/Makefile$(PLATFORM) \ |
254 | kabc/formats/binary/Makefile$(PLATFORM) \ | 260 | kabc/formats/binary/Makefile$(PLATFORM) \ |
255 | kabc/plugins/file/Makefile$(PLATFORM) \ | 261 | kabc/plugins/file/Makefile$(PLATFORM) \ |
256 | kabc/plugins/dir/Makefile$(PLATFORM) \ | 262 | kabc/plugins/dir/Makefile$(PLATFORM) \ |
257 | kabc/plugins/ldap/Makefile$(PLATFORM) \ | 263 | kabc/plugins/ldap/Makefile$(PLATFORM) \ |
258 | kabc/plugins/opie/Makefile$(PLATFORM) \ | 264 | kabc/plugins/opie/Makefile$(PLATFORM) \ |
259 | kabc/plugins/qtopia/Makefile$(PLATFORM) \ | 265 | kabc/plugins/qtopia/Makefile$(PLATFORM) \ |
260 | kabc/plugins/sharpdtm/Makefile$(PLATFORM) \ | 266 | kabc/plugins/sharpdtm/Makefile$(PLATFORM) \ |
261 | kaddressbook/Makefile$(PLATFORM) \ | 267 | kaddressbook/Makefile$(PLATFORM) \ |
262 | kmicromail/Makefile$(PLATFORM) \ | 268 | kmicromail/Makefile$(PLATFORM) \ |
263 | kmicromail/libetpan/Makefile$(PLATFORM) \ | 269 | kmicromail/libetpan/Makefile$(PLATFORM) \ |
264 | kmicromail/libmailwrapper/Makefile$(PLATFORM) \ | 270 | kmicromail/libmailwrapper/Makefile$(PLATFORM) \ |
265 | gammu/emb/common/Makefile$(PLATFORM) \ | 271 | gammu/emb/common/Makefile$(PLATFORM) \ |
266 | gammu/emb/gammu/Makefile$(PLATFORM) \ | 272 | gammu/emb/gammu/Makefile$(PLATFORM) \ |
267 | pwmanager/pwmanager/Makefile$(PLATFORM) \ | 273 | pwmanager/pwmanager/Makefile$(PLATFORM) \ |
274 | pwmanager/libcrypt/mpi/Makefile$(PLATFORM) \ | ||
275 | pwmanager/libcrypt/error/Makefile$(PLATFORM) \ | ||
276 | pwmanager/libcrypt/cipher/Makefile$(PLATFORM) \ | ||
277 | pwmanager/libcrypt/zlib/Makefile$(PLATFORM) | ||
268 | 278 | ||
269 | qtcompat/Makefile$(PLATFORM): qtcompat/qtcompat.pro | 279 | qtcompat/Makefile$(PLATFORM): qtcompat/qtcompat.pro |
270 | cd qtcompat; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtcompat.pro -o Makefile$(PLATFORM) | 280 | cd qtcompat; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtcompat.pro -o Makefile$(PLATFORM) |
271 | 281 | ||
272 | microkde/Makefile$(PLATFORM): microkde/microkdeE.pro | 282 | microkde/Makefile$(PLATFORM): microkde/microkdeE.pro |
273 | cd microkde; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" microkdeE.pro -o Makefile$(PLATFORM) | 283 | cd microkde; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" microkdeE.pro -o Makefile$(PLATFORM) |
274 | 284 | ||
275 | libkcal/Makefile$(PLATFORM): libkcal/libkcalE.pro | 285 | libkcal/Makefile$(PLATFORM): libkcal/libkcalE.pro |
276 | cd libkcal; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkcalE.pro -o Makefile$(PLATFORM) | 286 | cd libkcal; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkcalE.pro -o Makefile$(PLATFORM) |
277 | 287 | ||
278 | 288 | ||
279 | libkdepim/Makefile$(PLATFORM): libkdepim/libkdepimE.pro | 289 | libkdepim/Makefile$(PLATFORM): libkdepim/libkdepimE.pro |
280 | cd libkdepim; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkdepimE.pro -o Makefile$(PLATFORM) | 290 | cd libkdepim; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkdepimE.pro -o Makefile$(PLATFORM) |
281 | 291 | ||
282 | kalarmd/Makefile$(PLATFORM): kalarmd/kalarmdE.pro | 292 | kalarmd/Makefile$(PLATFORM): kalarmd/kalarmdE.pro |
283 | cd kalarmd; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kalarmdE.pro -o Makefile$(PLATFORM) | 293 | cd kalarmd; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kalarmdE.pro -o Makefile$(PLATFORM) |
284 | 294 | ||
285 | korganizer/Makefile$(PLATFORM): korganizer/korganizerE.pro | 295 | korganizer/Makefile$(PLATFORM): korganizer/korganizerE.pro |
286 | cd korganizer; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" korganizerE.pro -o Makefile$(PLATFORM) | 296 | cd korganizer; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" korganizerE.pro -o Makefile$(PLATFORM) |
287 | 297 | ||
288 | libical/src/libical/Makefile$(PLATFORM): libical/src/libical/libicalE.pro | 298 | libical/src/libical/Makefile$(PLATFORM): libical/src/libical/libicalE.pro |
289 | cd libical/src/libical; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalE.pro -o Makefile$(PLATFORM) | 299 | cd libical/src/libical; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalE.pro -o Makefile$(PLATFORM) |
290 | 300 | ||
291 | libical/src/libicalss/Makefile$(PLATFORM): libical/src/libicalss/libicalssE.pro | 301 | libical/src/libicalss/Makefile$(PLATFORM): libical/src/libicalss/libicalssE.pro |
292 | cd libical/src/libicalss; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalssE.pro -o Makefile$(PLATFORM) | 302 | cd libical/src/libicalss; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalssE.pro -o Makefile$(PLATFORM) |
293 | 303 | ||
294 | kabc/Makefile$(PLATFORM): kabc/kabcE.pro | 304 | kabc/Makefile$(PLATFORM): kabc/kabcE.pro |
295 | cd kabc; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcE.pro -o Makefile$(PLATFORM) | 305 | cd kabc; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcE.pro -o Makefile$(PLATFORM) |
296 | 306 | ||
297 | kabc/formats/binary/Makefile$(PLATFORM): kabc/formats/binary/kabcformat_binaryE.pro | 307 | kabc/formats/binary/Makefile$(PLATFORM): kabc/formats/binary/kabcformat_binaryE.pro |
298 | cd kabc/formats/binary; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcformat_binaryE.pro -o Makefile$(PLATFORM) | 308 | cd kabc/formats/binary; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcformat_binaryE.pro -o Makefile$(PLATFORM) |
299 | 309 | ||
300 | kabc/plugins/file/Makefile$(PLATFORM): kabc/plugins/file/fileE.pro | 310 | kabc/plugins/file/Makefile$(PLATFORM): kabc/plugins/file/fileE.pro |
301 | cd kabc/plugins/file; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" fileE.pro -o Makefile$(PLATFORM) | 311 | cd kabc/plugins/file; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" fileE.pro -o Makefile$(PLATFORM) |
302 | 312 | ||
303 | kabc/plugins/dir/Makefile$(PLATFORM): kabc/plugins/dir/dirE.pro | 313 | kabc/plugins/dir/Makefile$(PLATFORM): kabc/plugins/dir/dirE.pro |
304 | cd kabc/plugins/dir; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" dirE.pro -o Makefile$(PLATFORM) | 314 | cd kabc/plugins/dir; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" dirE.pro -o Makefile$(PLATFORM) |
305 | 315 | ||
306 | kabc/plugins/ldap/Makefile$(PLATFORM): kabc/plugins/ldap/ldapE.pro | 316 | kabc/plugins/ldap/Makefile$(PLATFORM): kabc/plugins/ldap/ldapE.pro |
307 | cd kabc/plugins/ldap; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" ldapE.pro -o Makefile$(PLATFORM) | 317 | cd kabc/plugins/ldap; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" ldapE.pro -o Makefile$(PLATFORM) |
308 | 318 | ||
309 | kabc/plugins/opie/Makefile$(PLATFORM): kabc/plugins/opie/opieE.pro | 319 | kabc/plugins/opie/Makefile$(PLATFORM): kabc/plugins/opie/opieE.pro |
310 | cd kabc/plugins/opie; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" opieE.pro -o Makefile$(PLATFORM) | 320 | cd kabc/plugins/opie; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" opieE.pro -o Makefile$(PLATFORM) |
311 | 321 | ||
312 | kabc/plugins/qtopia/Makefile$(PLATFORM): kabc/plugins/qtopia/qtopiaE.pro | 322 | kabc/plugins/qtopia/Makefile$(PLATFORM): kabc/plugins/qtopia/qtopiaE.pro |
313 | cd kabc/plugins/qtopia; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtopiaE.pro -o Makefile$(PLATFORM) | 323 | cd kabc/plugins/qtopia; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtopiaE.pro -o Makefile$(PLATFORM) |
314 | 324 | ||
315 | kabc/plugins/sharpdtm/Makefile$(PLATFORM): kabc/plugins/sharpdtm/sharpdtmE.pro | 325 | kabc/plugins/sharpdtm/Makefile$(PLATFORM): kabc/plugins/sharpdtm/sharpdtmE.pro |
316 | cd kabc/plugins/sharpdtm; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" sharpdtmE.pro -o Makefile$(PLATFORM) | 326 | cd kabc/plugins/sharpdtm; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" sharpdtmE.pro -o Makefile$(PLATFORM) |
317 | 327 | ||
318 | kaddressbook/Makefile$(PLATFORM): kaddressbook/kaddressbookE.pro | 328 | kaddressbook/Makefile$(PLATFORM): kaddressbook/kaddressbookE.pro |
319 | cd kaddressbook; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kaddressbookE.pro -o Makefile$(PLATFORM) | 329 | cd kaddressbook; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kaddressbookE.pro -o Makefile$(PLATFORM) |
320 | 330 | ||
321 | kmicromail/Makefile$(PLATFORM): kmicromail/kmicromailE.pro | 331 | kmicromail/Makefile$(PLATFORM): kmicromail/kmicromailE.pro |
322 | cd kmicromail; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kmicromailE.pro -o Makefile$(PLATFORM) | 332 | cd kmicromail; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kmicromailE.pro -o Makefile$(PLATFORM) |
323 | 333 | ||
324 | kmicromail/libetpan/Makefile$(PLATFORM): kmicromail/libetpan/libetpanE.pro | 334 | kmicromail/libetpan/Makefile$(PLATFORM): kmicromail/libetpan/libetpanE.pro |
325 | cd kmicromail/libetpan; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libetpanE.pro -o Makefile$(PLATFORM) | 335 | cd kmicromail/libetpan; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libetpanE.pro -o Makefile$(PLATFORM) |
326 | 336 | ||
327 | kmicromail/libmailwrapper/Makefile$(PLATFORM): kmicromail/libmailwrapper/libmailwrapperE.pro | 337 | kmicromail/libmailwrapper/Makefile$(PLATFORM): kmicromail/libmailwrapper/libmailwrapperE.pro |
328 | cd kmicromail/libmailwrapper; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libmailwrapperE.pro -o Makefile$(PLATFORM) | 338 | cd kmicromail/libmailwrapper; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libmailwrapperE.pro -o Makefile$(PLATFORM) |
329 | 339 | ||
330 | gammu/emb/common/Makefile$(PLATFORM): gammu/emb/common/commonE.pro | 340 | gammu/emb/common/Makefile$(PLATFORM): gammu/emb/common/commonE.pro |
331 | cd gammu/emb/common; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" commonE.pro -o Makefile$(PLATFORM) | 341 | cd gammu/emb/common; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" commonE.pro -o Makefile$(PLATFORM) |
332 | 342 | ||
333 | gammu/emb/gammu/Makefile$(PLATFORM): gammu/emb/gammu/gammuE.pro | 343 | gammu/emb/gammu/Makefile$(PLATFORM): gammu/emb/gammu/gammuE.pro |
334 | cd gammu/emb/gammu; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" gammuE.pro -o Makefile$(PLATFORM) | 344 | cd gammu/emb/gammu; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" gammuE.pro -o Makefile$(PLATFORM) |
335 | 345 | ||
336 | pwmanager/pwmanager/Makefile$(PLATFORM): pwmanager/pwmanager/pwmanagerE.pro | 346 | pwmanager/pwmanager/Makefile$(PLATFORM): pwmanager/pwmanager/pwmanagerE.pro |
337 | cd pwmanager/pwmanager; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" pwmanagerE.pro -o Makefile$(PLATFORM) | 347 | cd pwmanager/pwmanager; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" pwmanagerE.pro -o Makefile$(PLATFORM) |
338 | 348 | ||
349 | |||
350 | pwmanager/libcrypt/mpi/Makefile$(PLATFORM): pwmanager/libcrypt/mpi/mpi.pro | ||
351 | cd pwmanager/libcrypt/mpi;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" mpi.pro -o Makefile$(PLATFORM) | ||
352 | |||
353 | pwmanager/libcrypt/error/Makefile$(PLATFORM): pwmanager/libcrypt/error/error.pro | ||
354 | cd pwmanager/libcrypt/error;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" error.pro -o Makefile$(PLATFORM) | ||
355 | |||
356 | pwmanager/libcrypt/cipher/Makefile$(PLATFORM): pwmanager/libcrypt/cipher/cipher.pro | ||
357 | cd pwmanager/libcrypt/cipher;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" cipher.pro -o Makefile$(PLATFORM) | ||
358 | |||
359 | pwmanager/libcrypt/zlib/Makefile$(PLATFORM): pwmanager/libcrypt/zlib/zlib.pro | ||
360 | cd pwmanager/libcrypt/zlib;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" zlib.pro -o Makefile$(PLATFORM) | ||
361 | |||
362 | |||
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro index 4c3a568..6aa0571 100644 --- a/pwmanager/pwmanager/pwmanagerE.pro +++ b/pwmanager/pwmanager/pwmanagerE.pro | |||
@@ -1,163 +1,168 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | 3 | ||
4 | 4 | ||
5 | TARGET = pwmpi | 5 | TARGET = pwmpi |
6 | OBJECTS_DIR = obj/$(PLATFORM) | 6 | OBJECTS_DIR = obj/$(PLATFORM) |
7 | MOC_DIR = moc/$(PLATFORM) | 7 | MOC_DIR = moc/$(PLATFORM) |
8 | DESTDIR=$(QPEDIR)/bin | 8 | DESTDIR=$(QPEDIR)/bin |
9 | 9 | ||
10 | INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include | 10 | INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include |
11 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY | 11 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY |
12 | 12 | ||
13 | #enable this setting if you want debugoutput for pwmanager | 13 | #enable this setting if you want debugoutput for pwmanager |
14 | #DEFINES += CONFIG_DEBUG | 14 | #DEFINES += CONFIG_DEBUG |
15 | 15 | LIBS += -L../libcrypt/$(PLATFORM) | |
16 | LIBS += -lmicrokde | 16 | LIBS += -lmicrokde |
17 | LIBS += -lmicroqtcompat | 17 | LIBS += -lmicroqtcompat |
18 | LIBS += -lmicrokdepim | 18 | LIBS += -lmicrokdepim |
19 | LIBS += -L$(QPEDIR)/lib | 19 | LIBS += -L$(QPEDIR)/lib |
20 | LIBS += -lqpe | 20 | LIBS += -lqpe |
21 | LIBS += -lz | 21 | LIBS += -lzlib |
22 | #LIBS += -lbz2 | 22 | #LIBS += -lbz2 |
23 | LIBS += -lgcrypt | 23 | #LIBS += -lkpmicrogcrypt |
24 | LIBS += -ljpeg | ||
24 | LIBS += $(QTOPIALIB) | 25 | LIBS += $(QTOPIALIB) |
26 | LIBS += -lkpmicrocipher | ||
27 | LIBS += -lkpmicroerror | ||
28 | LIBS += -lkpmicrompi | ||
29 | LIBS += -lstdc++ | ||
25 | 30 | ||
26 | #INTERFACES = \ | 31 | #INTERFACES = \ |
27 | #addentrywnd.ui \ | 32 | #addentrywnd.ui \ |
28 | #configwnd.ui \ | 33 | #configwnd.ui \ |
29 | #findwnd.ui \ | 34 | #findwnd.ui \ |
30 | #getmasterpwwnd.ui \ | 35 | #getmasterpwwnd.ui \ |
31 | #pwgenwnd.ui \ | 36 | #pwgenwnd.ui \ |
32 | #setmasterpwwnd.ui \ | 37 | #setmasterpwwnd.ui \ |
33 | #subtbledit.ui | 38 | #subtbledit.ui |
34 | 39 | ||
35 | #INTERFACES = \ | 40 | #INTERFACES = \ |
36 | #subtbledit.ui \ | 41 | #subtbledit.ui \ |
37 | 42 | ||
38 | 43 | ||
39 | 44 | ||
40 | #HEADERS = \ | 45 | #HEADERS = \ |
41 | #configuration_31compat.h \ | 46 | #configuration_31compat.h \ |
42 | #configuration.h \ | 47 | #configuration.h \ |
43 | #configwnd.h \ | 48 | #configwnd.h \ |
44 | #configwndimpl.h \ | 49 | #configwndimpl.h \ |
45 | #selftest.h | 50 | #selftest.h |
46 | #subtbledit.h \ | 51 | #subtbledit.h \ |
47 | #subtbleditimpl.h \ | 52 | #subtbleditimpl.h \ |
48 | #compressbzip2.h \ | 53 | #compressbzip2.h \ |
49 | 54 | ||
50 | HEADERS = \ | 55 | HEADERS = \ |
51 | addentrywnd_emb.h \ | 56 | addentrywnd_emb.h \ |
52 | addentrywndimpl.h \ | 57 | addentrywndimpl.h \ |
53 | base64.h \ | 58 | base64.h \ |
54 | binentrygen.h \ | 59 | binentrygen.h \ |
55 | blowfish.h \ | 60 | blowfish.h \ |
56 | commentbox.h \ | 61 | commentbox.h \ |
57 | compiler.h \ | 62 | compiler.h \ |
58 | compressgzip.h \ | 63 | compressgzip.h \ |
59 | findwnd_emb.h \ | 64 | findwnd_emb.h \ |
60 | findwndimpl.h \ | 65 | findwndimpl.h \ |
61 | genpasswd.h \ | 66 | genpasswd.h \ |
62 | getkeycardwnd.h \ | 67 | getkeycardwnd.h \ |
63 | getmasterpwwnd_emb.h \ | 68 | getmasterpwwnd_emb.h \ |
64 | getmasterpwwndimpl.h \ | 69 | getmasterpwwndimpl.h \ |
65 | globalstuff.h \ | 70 | globalstuff.h \ |
66 | gpasmanfile.h \ | 71 | gpasmanfile.h \ |
67 | htmlgen.h \ | 72 | htmlgen.h \ |
68 | htmlparse.h \ | 73 | htmlparse.h \ |
69 | ipc.h \ | 74 | ipc.h \ |
70 | libgcryptif.h \ | 75 | libgcryptif.h \ |
71 | listobjselectwnd.h \ | 76 | listobjselectwnd.h \ |
72 | listviewpwm.h \ | 77 | listviewpwm.h \ |
73 | printtext.h \ | 78 | printtext.h \ |
74 | pwgenwnd_emb.h \ | 79 | pwgenwnd_emb.h \ |
75 | pwgenwndimpl.h \ | 80 | pwgenwndimpl.h \ |
76 | pwmdoc.h \ | 81 | pwmdoc.h \ |
77 | pwmdocui.h \ | 82 | pwmdocui.h \ |
78 | pwmexception.h \ | 83 | pwmexception.h \ |
79 | pwm.h \ | 84 | pwm.h \ |
80 | pwminit.h \ | 85 | pwminit.h \ |
81 | pwmprefs.h \ | 86 | pwmprefs.h \ |
82 | pwmprint.h \ | 87 | pwmprint.h \ |
83 | pwmtray.h \ | 88 | pwmtray.h \ |
84 | pwmview.h \ | 89 | pwmview.h \ |
85 | pwmviewstyle_0.h \ | 90 | pwmviewstyle_0.h \ |
86 | pwmviewstyle_1.h \ | 91 | pwmviewstyle_1.h \ |
87 | pwmviewstyle.h \ | 92 | pwmviewstyle.h \ |
88 | randomizer.h \ | 93 | randomizer.h \ |
89 | rc2.h \ | 94 | rc2.h \ |
90 | rencatwnd.h \ | 95 | rencatwnd.h \ |
91 | serializer.h \ | 96 | serializer.h \ |
92 | setmasterpwwnd_emb.h \ | 97 | setmasterpwwnd_emb.h \ |
93 | setmasterpwwndimpl.h \ | 98 | setmasterpwwndimpl.h \ |
94 | sha1.h \ | 99 | sha1.h \ |
95 | waitwnd.h \ | 100 | waitwnd.h \ |
96 | kcmconfigs/kcmpwmconfig.h \ | 101 | kcmconfigs/kcmpwmconfig.h \ |
97 | kcmconfigs/pwmconfigwidget.h | 102 | kcmconfigs/pwmconfigwidget.h |
98 | 103 | ||
99 | #sources that need not be build | 104 | #sources that need not be build |
100 | #SOURCES = \ | 105 | #SOURCES = \ |
101 | #advcommeditimpl.cpp \ | 106 | #advcommeditimpl.cpp \ |
102 | #configuration.cpp \ | 107 | #configuration.cpp \ |
103 | #configwnd.cpp \ | 108 | #configwnd.cpp \ |
104 | #configwndimpl.cpp \ | 109 | #configwndimpl.cpp \ |
105 | #configuration_31compat.cpp \ | 110 | #configuration_31compat.cpp \ |
106 | #htmlparse.cpp \ | 111 | #htmlparse.cpp \ |
107 | #printtext.cpp \ | 112 | #printtext.cpp \ |
108 | #selftest.cpp \ | 113 | #selftest.cpp \ |
109 | #pwmprint.cpp \ | 114 | #pwmprint.cpp \ |
110 | #spinforsignal.cpp | 115 | #spinforsignal.cpp |
111 | #subtbledit.cpp \ | 116 | #subtbledit.cpp \ |
112 | #subtbleditimpl.cpp \ | 117 | #subtbleditimpl.cpp \ |
113 | #compressbzip2.cpp | 118 | #compressbzip2.cpp |
114 | 119 | ||
115 | 120 | ||
116 | SOURCES = \ | 121 | SOURCES = \ |
117 | addentrywnd_emb.cpp \ | 122 | addentrywnd_emb.cpp \ |
118 | addentrywndimpl.cpp \ | 123 | addentrywndimpl.cpp \ |
119 | base64.cpp \ | 124 | base64.cpp \ |
120 | binentrygen.cpp \ | 125 | binentrygen.cpp \ |
121 | blowfish.cpp \ | 126 | blowfish.cpp \ |
122 | commentbox.cpp \ | 127 | commentbox.cpp \ |
123 | compressgzip.cpp \ | 128 | compressgzip.cpp \ |
124 | findwnd_emb.cpp \ | 129 | findwnd_emb.cpp \ |
125 | findwndimpl.cpp \ | 130 | findwndimpl.cpp \ |
126 | genpasswd.cpp \ | 131 | genpasswd.cpp \ |
127 | getkeycardwnd.cpp \ | 132 | getkeycardwnd.cpp \ |
128 | getmasterpwwnd_emb.cpp \ | 133 | getmasterpwwnd_emb.cpp \ |
129 | getmasterpwwndimpl.cpp \ | 134 | getmasterpwwndimpl.cpp \ |
130 | globalstuff.cpp \ | 135 | globalstuff.cpp \ |
131 | gpasmanfile.cpp \ | 136 | gpasmanfile.cpp \ |
132 | htmlgen.cpp \ | 137 | htmlgen.cpp \ |
133 | ipc.cpp \ | 138 | ipc.cpp \ |
134 | libgcryptif.cpp \ | 139 | libgcryptif.cpp \ |
135 | listobjselectwnd.cpp \ | 140 | listobjselectwnd.cpp \ |
136 | listviewpwm.cpp \ | 141 | listviewpwm.cpp \ |
137 | main.cpp \ | 142 | main.cpp \ |
138 | pwgenwnd_emb.cpp \ | 143 | pwgenwnd_emb.cpp \ |
139 | pwgenwndimpl.cpp \ | 144 | pwgenwndimpl.cpp \ |
140 | pwm.cpp \ | 145 | pwm.cpp \ |
141 | pwmdoc.cpp \ | 146 | pwmdoc.cpp \ |
142 | pwmdocui.cpp \ | 147 | pwmdocui.cpp \ |
143 | pwmexception.cpp \ | 148 | pwmexception.cpp \ |
144 | pwminit.cpp \ | 149 | pwminit.cpp \ |
145 | pwmprefs.cpp \ | 150 | pwmprefs.cpp \ |
146 | pwmtray.cpp \ | 151 | pwmtray.cpp \ |
147 | pwmview.cpp \ | 152 | pwmview.cpp \ |
148 | pwmviewstyle_0.cpp \ | 153 | pwmviewstyle_0.cpp \ |
149 | pwmviewstyle_1.cpp \ | 154 | pwmviewstyle_1.cpp \ |
150 | pwmviewstyle.cpp \ | 155 | pwmviewstyle.cpp \ |
151 | randomizer.cpp \ | 156 | randomizer.cpp \ |
152 | rc2.cpp \ | 157 | rc2.cpp \ |
153 | rencatwnd.cpp \ | 158 | rencatwnd.cpp \ |
154 | serializer.cpp \ | 159 | serializer.cpp \ |
155 | setmasterpwwnd_emb.cpp \ | 160 | setmasterpwwnd_emb.cpp \ |
156 | setmasterpwwndimpl.cpp \ | 161 | setmasterpwwndimpl.cpp \ |
157 | sha1.cpp \ | 162 | sha1.cpp \ |
158 | waitwnd.cpp \ | 163 | waitwnd.cpp \ |
159 | kcmconfigs/kcmpwmconfig.cpp \ | 164 | kcmconfigs/kcmpwmconfig.cpp \ |
160 | kcmconfigs/pwmconfigwidget.cpp | 165 | kcmconfigs/pwmconfigwidget.cpp |
161 | 166 | ||
162 | 167 | ||
163 | 168 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index f4a1636..e29e3d1 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,3491 +1,3491 @@ | |||
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 1.1 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 "pwmdoc.h" | 20 | #include "pwmdoc.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "blowfish.h" | 22 | #include "blowfish.h" |
23 | #include "sha1.h" | 23 | #include "sha1.h" |
24 | #include "globalstuff.h" | 24 | #include "globalstuff.h" |
25 | #include "gpasmanfile.h" | 25 | #include "gpasmanfile.h" |
26 | #include "serializer.h" | 26 | #include "serializer.h" |
27 | #include "compressgzip.h" | 27 | #include "compressgzip.h" |
28 | //US#include "compressbzip2.h" | 28 | //US#include "compressbzip2.h" |
29 | #include "randomizer.h" | 29 | #include "randomizer.h" |
30 | #include "pwminit.h" | 30 | #include "pwminit.h" |
31 | #include "libgcryptif.h" | 31 | #include "libgcryptif.h" |
32 | #ifdef PWM_EMBEDDED | 32 | #ifdef PWM_EMBEDDED |
33 | #include "pwmprefs.h" | 33 | #include "pwmprefs.h" |
34 | #include "kglobal.h" | 34 | #include "kglobal.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | 40 | ||
41 | #ifdef CONFIG_KWALLETIF | 41 | #ifdef CONFIG_KWALLETIF |
42 | # include "kwalletemu.h" | 42 | # include "kwalletemu.h" |
43 | #endif // CONFIG_KWALLETIF | 43 | #endif // CONFIG_KWALLETIF |
44 | 44 | ||
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | #include <qsize.h> | 46 | #include <qsize.h> |
47 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | 49 | ||
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | //US#include <iostream> | 54 | //US#include <iostream> |
55 | #include <algorithm> | 55 | #include <algorithm> |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | 57 | #include <sys/stat.h> |
58 | #include <unistd.h> | 58 | #include <unistd.h> |
59 | #include <stdint.h> | 59 | #include <stdint.h> |
60 | 60 | ||
61 | 61 | ||
62 | #ifdef PWM_EMBEDDED | 62 | #ifdef PWM_EMBEDDED |
63 | #ifndef Q_LONG | 63 | #ifndef Q_LONG |
64 | #define Q_LONG long | 64 | #define Q_LONG long |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #ifndef Q_ULONG | 67 | #ifndef Q_ULONG |
68 | #define Q_ULONG unsigned long | 68 | #define Q_ULONG unsigned long |
69 | #endif | 69 | #endif |
70 | #endif //PWM_EMBEDDED | 70 | #endif //PWM_EMBEDDED |
71 | 71 | ||
72 | 72 | ||
73 | //TODO: reset to its normal value. | 73 | //TODO: reset to its normal value. |
74 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 74 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
75 | 75 | ||
76 | using namespace std; | 76 | using namespace std; |
77 | 77 | ||
78 | 78 | ||
79 | void PwMDocList::add(PwMDoc *doc, const string &id) | 79 | void PwMDocList::add(PwMDoc *doc, const string &id) |
80 | { | 80 | { |
81 | #ifdef PWM_DEBUG | 81 | #ifdef PWM_DEBUG |
82 | // check for existance of object in debug mode only. | 82 | // check for existance of object in debug mode only. |
83 | vector<listItem>::iterator begin = docList.begin(), | 83 | vector<listItem>::iterator begin = docList.begin(), |
84 | end = docList.end(), | 84 | end = docList.end(), |
85 | i = begin; | 85 | i = begin; |
86 | while (i != end) { | 86 | while (i != end) { |
87 | if (i->doc == doc) { | 87 | if (i->doc == doc) { |
88 | BUG(); | 88 | BUG(); |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | ++i; | 91 | ++i; |
92 | } | 92 | } |
93 | #endif | 93 | #endif |
94 | listItem newItem; | 94 | listItem newItem; |
95 | newItem.doc = doc; | 95 | newItem.doc = doc; |
96 | newItem.docId = id; | 96 | newItem.docId = id; |
97 | docList.push_back(newItem); | 97 | docList.push_back(newItem); |
98 | } | 98 | } |
99 | 99 | ||
100 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 100 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
101 | { | 101 | { |
102 | vector<listItem>::iterator begin = docList.begin(), | 102 | vector<listItem>::iterator begin = docList.begin(), |
103 | end = docList.end(), | 103 | end = docList.end(), |
104 | i = begin; | 104 | i = begin; |
105 | while (i != end) { | 105 | while (i != end) { |
106 | if (i->doc == doc) { | 106 | if (i->doc == doc) { |
107 | i->docId = newId; | 107 | i->docId = newId; |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | ++i; | 110 | ++i; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | void PwMDocList::del(PwMDoc *doc) | 114 | void PwMDocList::del(PwMDoc *doc) |
115 | { | 115 | { |
116 | vector<listItem>::iterator begin = docList.begin(), | 116 | vector<listItem>::iterator begin = docList.begin(), |
117 | end = docList.end(), | 117 | end = docList.end(), |
118 | i = begin; | 118 | i = begin; |
119 | while (i != end) { | 119 | while (i != end) { |
120 | if (i->doc == doc) { | 120 | if (i->doc == doc) { |
121 | docList.erase(i); | 121 | docList.erase(i); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | ++i; | 124 | ++i; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | bool PwMDocList::find(const string &id, listItem *ret) | 128 | bool PwMDocList::find(const string &id, listItem *ret) |
129 | { | 129 | { |
130 | vector<listItem>::iterator begin = docList.begin(), | 130 | vector<listItem>::iterator begin = docList.begin(), |
131 | end = docList.end(), | 131 | end = docList.end(), |
132 | i = begin; | 132 | i = begin; |
133 | while (i != end) { | 133 | while (i != end) { |
134 | if (i->docId == id) { | 134 | if (i->docId == id) { |
135 | if (ret) | 135 | if (ret) |
136 | *ret = *i; | 136 | *ret = *i; |
137 | return true; | 137 | return true; |
138 | } | 138 | } |
139 | ++i; | 139 | ++i; |
140 | } | 140 | } |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | DocTimer::DocTimer(PwMDoc *_doc) | 146 | DocTimer::DocTimer(PwMDoc *_doc) |
147 | : doc (_doc) | 147 | : doc (_doc) |
148 | , mpwLock (0) | 148 | , mpwLock (0) |
149 | , autoLockLock (0) | 149 | , autoLockLock (0) |
150 | , metaCheckLock (0) | 150 | , metaCheckLock (0) |
151 | { | 151 | { |
152 | mpwTimer = new QTimer; | 152 | mpwTimer = new QTimer; |
153 | autoLockTimer = new QTimer; | 153 | autoLockTimer = new QTimer; |
154 | metaCheckTimer = new QTimer; | 154 | metaCheckTimer = new QTimer; |
155 | connect(mpwTimer, SIGNAL(timeout()), | 155 | connect(mpwTimer, SIGNAL(timeout()), |
156 | this, SLOT(mpwTimeout())); | 156 | this, SLOT(mpwTimeout())); |
157 | connect(autoLockTimer, SIGNAL(timeout()), | 157 | connect(autoLockTimer, SIGNAL(timeout()), |
158 | this, SLOT(autoLockTimeout())); | 158 | this, SLOT(autoLockTimeout())); |
159 | connect(metaCheckTimer, SIGNAL(timeout()), | 159 | connect(metaCheckTimer, SIGNAL(timeout()), |
160 | this, SLOT(metaCheckTimeout())); | 160 | this, SLOT(metaCheckTimeout())); |
161 | } | 161 | } |
162 | 162 | ||
163 | DocTimer::~DocTimer() | 163 | DocTimer::~DocTimer() |
164 | { | 164 | { |
165 | delete mpwTimer; | 165 | delete mpwTimer; |
166 | delete autoLockTimer; | 166 | delete autoLockTimer; |
167 | delete metaCheckTimer; | 167 | delete metaCheckTimer; |
168 | } | 168 | } |
169 | 169 | ||
170 | void DocTimer::start(TimerIDs timer) | 170 | void DocTimer::start(TimerIDs timer) |
171 | { | 171 | { |
172 | switch (timer) { | 172 | switch (timer) { |
173 | case id_mpwTimer: | 173 | case id_mpwTimer: |
174 | if (mpwTimer->isActive()) | 174 | if (mpwTimer->isActive()) |
175 | mpwTimer->stop(); | 175 | mpwTimer->stop(); |
176 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 176 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
177 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 177 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
178 | break; | 178 | break; |
179 | case id_autoLockTimer: | 179 | case id_autoLockTimer: |
180 | if (autoLockTimer->isActive()) | 180 | if (autoLockTimer->isActive()) |
181 | autoLockTimer->stop(); | 181 | autoLockTimer->stop(); |
182 | if (conf()->confGlobLockTimeout() > 0) | 182 | if (conf()->confGlobLockTimeout() > 0) |
183 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 183 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
184 | break; | 184 | break; |
185 | case id_metaCheckTimer: | 185 | case id_metaCheckTimer: |
186 | if (metaCheckTimer->isActive()) | 186 | if (metaCheckTimer->isActive()) |
187 | metaCheckTimer->stop(); | 187 | metaCheckTimer->stop(); |
188 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 188 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
189 | break; | 189 | break; |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | void DocTimer::stop(TimerIDs timer) | 193 | void DocTimer::stop(TimerIDs timer) |
194 | { | 194 | { |
195 | switch (timer) { | 195 | switch (timer) { |
196 | case id_mpwTimer: | 196 | case id_mpwTimer: |
197 | mpwTimer->stop(); | 197 | mpwTimer->stop(); |
198 | break; | 198 | break; |
199 | case id_autoLockTimer: | 199 | case id_autoLockTimer: |
200 | autoLockTimer->stop(); | 200 | autoLockTimer->stop(); |
201 | break; | 201 | break; |
202 | case id_metaCheckTimer: | 202 | case id_metaCheckTimer: |
203 | metaCheckTimer->stop(); | 203 | metaCheckTimer->stop(); |
204 | break; | 204 | break; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | void DocTimer::getLock(TimerIDs timer) | 208 | void DocTimer::getLock(TimerIDs timer) |
209 | { | 209 | { |
210 | switch (timer) { | 210 | switch (timer) { |
211 | case id_mpwTimer: | 211 | case id_mpwTimer: |
212 | ++mpwLock; | 212 | ++mpwLock; |
213 | break; | 213 | break; |
214 | case id_autoLockTimer: | 214 | case id_autoLockTimer: |
215 | ++autoLockLock; | 215 | ++autoLockLock; |
216 | break; | 216 | break; |
217 | case id_metaCheckTimer: | 217 | case id_metaCheckTimer: |
218 | ++metaCheckLock; | 218 | ++metaCheckLock; |
219 | break; | 219 | break; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | void DocTimer::putLock(TimerIDs timer) | 223 | void DocTimer::putLock(TimerIDs timer) |
224 | { | 224 | { |
225 | switch (timer) { | 225 | switch (timer) { |
226 | case id_mpwTimer: | 226 | case id_mpwTimer: |
227 | if (mpwLock) | 227 | if (mpwLock) |
228 | --mpwLock; | 228 | --mpwLock; |
229 | break; | 229 | break; |
230 | case id_autoLockTimer: | 230 | case id_autoLockTimer: |
231 | if (autoLockLock) | 231 | if (autoLockLock) |
232 | --autoLockLock; | 232 | --autoLockLock; |
233 | break; | 233 | break; |
234 | case id_metaCheckTimer: | 234 | case id_metaCheckTimer: |
235 | if (metaCheckLock) | 235 | if (metaCheckLock) |
236 | --metaCheckLock; | 236 | --metaCheckLock; |
237 | break; | 237 | break; |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | void DocTimer::mpwTimeout() | 241 | void DocTimer::mpwTimeout() |
242 | { | 242 | { |
243 | if (mpwLock) { | 243 | if (mpwLock) { |
244 | mpwTimer->start(1000, true); | 244 | mpwTimer->start(1000, true); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 247 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
248 | } | 248 | } |
249 | 249 | ||
250 | void DocTimer::autoLockTimeout() | 250 | void DocTimer::autoLockTimeout() |
251 | { | 251 | { |
252 | if (autoLockLock) { | 252 | if (autoLockLock) { |
253 | autoLockTimer->start(1000, true); | 253 | autoLockTimer->start(1000, true); |
254 | return; | 254 | return; |
255 | } | 255 | } |
256 | if (conf()->confGlobAutoDeepLock() && | 256 | if (conf()->confGlobAutoDeepLock() && |
257 | doc->filename != QString::null && | 257 | doc->filename != QString::null && |
258 | doc->filename != "") { | 258 | doc->filename != "") { |
259 | doc->deepLock(true); | 259 | doc->deepLock(true); |
260 | } else { | 260 | } else { |
261 | doc->lockAll(true); | 261 | doc->lockAll(true); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | void DocTimer::metaCheckTimeout() | 265 | void DocTimer::metaCheckTimeout() |
266 | { | 266 | { |
267 | if (metaCheckLock) { | 267 | if (metaCheckLock) { |
268 | // check again in one second. | 268 | // check again in one second. |
269 | metaCheckTimer->start(1000, true); | 269 | metaCheckTimer->start(1000, true); |
270 | return; | 270 | return; |
271 | } | 271 | } |
272 | if (doc->isDeepLocked()) { | 272 | if (doc->isDeepLocked()) { |
273 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 273 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | if (doc->isDocEmpty()) { | 276 | if (doc->isDocEmpty()) { |
277 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 277 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
278 | return; | 278 | return; |
279 | } | 279 | } |
280 | #ifdef CONFIG_KWALLETIF | 280 | #ifdef CONFIG_KWALLETIF |
281 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 281 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
282 | if (kwlEmu) | 282 | if (kwlEmu) |
283 | kwlEmu->suspendDocSignals(); | 283 | kwlEmu->suspendDocSignals(); |
284 | #endif // CONFIG_KWALLETIF | 284 | #endif // CONFIG_KWALLETIF |
285 | /* We simply trigger all views to update their | 285 | /* We simply trigger all views to update their |
286 | * displayed values. This way they have a chance | 286 | * displayed values. This way they have a chance |
287 | * to get notified when some meta changes over time. | 287 | * to get notified when some meta changes over time. |
288 | * (for example an entry expired). | 288 | * (for example an entry expired). |
289 | * The _view_ is responsive for not updating its | 289 | * The _view_ is responsive for not updating its |
290 | * contents if nothing really changed! | 290 | * contents if nothing really changed! |
291 | */ | 291 | */ |
292 | emit doc->dataChanged(doc); | 292 | emit doc->dataChanged(doc); |
293 | #ifdef CONFIG_KWALLETIF | 293 | #ifdef CONFIG_KWALLETIF |
294 | if (kwlEmu) | 294 | if (kwlEmu) |
295 | kwlEmu->resumeDocSignals(); | 295 | kwlEmu->resumeDocSignals(); |
296 | #endif // CONFIG_KWALLETIF | 296 | #endif // CONFIG_KWALLETIF |
297 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 297 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | 301 | ||
302 | PwMDocList PwMDoc::openDocList; | 302 | PwMDocList PwMDoc::openDocList; |
303 | unsigned int PwMDocList::unnamedDocCnt = 1; | 303 | unsigned int PwMDocList::unnamedDocCnt = 1; |
304 | 304 | ||
305 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 305 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
306 | : PwMDocUi(parent, name) | 306 | : PwMDocUi(parent, name) |
307 | , dataChangedLock (0) | 307 | , dataChangedLock (0) |
308 | { | 308 | { |
309 | deleted = false; | 309 | deleted = false; |
310 | unnamedNum = 0; | 310 | unnamedNum = 0; |
311 | getOpenDocList()->add(this, getTitle().latin1()); | 311 | getOpenDocList()->add(this, getTitle().latin1()); |
312 | curDocStat = 0; | 312 | curDocStat = 0; |
313 | setMaxNumEntries(); | 313 | setMaxNumEntries(); |
314 | _timer = new DocTimer(this); | 314 | _timer = new DocTimer(this); |
315 | timer()->start(DocTimer::id_mpwTimer); | 315 | timer()->start(DocTimer::id_mpwTimer); |
316 | timer()->start(DocTimer::id_autoLockTimer); | 316 | timer()->start(DocTimer::id_autoLockTimer); |
317 | timer()->start(DocTimer::id_metaCheckTimer); | 317 | timer()->start(DocTimer::id_metaCheckTimer); |
318 | addCategory(DEFAULT_CATEGORY, 0, false); | 318 | addCategory(DEFAULT_CATEGORY, 0, false); |
319 | listView = 0; | 319 | listView = 0; |
320 | emit docCreated(this); | 320 | emit docCreated(this); |
321 | } | 321 | } |
322 | 322 | ||
323 | PwMDoc::~PwMDoc() | 323 | PwMDoc::~PwMDoc() |
324 | { | 324 | { |
325 | emit docClosed(this); | 325 | emit docClosed(this); |
326 | getOpenDocList()->del(this); | 326 | getOpenDocList()->del(this); |
327 | delete _timer; | 327 | delete _timer; |
328 | } | 328 | } |
329 | 329 | ||
330 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 330 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
331 | { | 331 | { |
332 | PwMerror ret, e; | 332 | PwMerror ret, e; |
333 | string serialized; | 333 | string serialized; |
334 | QFile f; | 334 | QFile f; |
335 | QString tmpFileMoved(QString::null); | 335 | QString tmpFileMoved(QString::null); |
336 | bool wasDeepLocked; | 336 | bool wasDeepLocked; |
337 | QString savedFilename(filename); | 337 | QString savedFilename(filename); |
338 | 338 | ||
339 | if (!file) { | 339 | if (!file) { |
340 | if (filename == "") | 340 | if (filename == "") |
341 | return e_filename; | 341 | return e_filename; |
342 | if (isDeepLocked()) { | 342 | if (isDeepLocked()) { |
343 | /* We don't need to save any data. | 343 | /* We don't need to save any data. |
344 | * It's already all on disk, because | 344 | * It's already all on disk, because |
345 | * we are deeplocked. | 345 | * we are deeplocked. |
346 | */ | 346 | */ |
347 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 347 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
348 | ret = e_success; | 348 | ret = e_success; |
349 | goto out; | 349 | return ret; |
350 | } | 350 | } |
351 | } else { | 351 | } else { |
352 | if (*file == "" && filename == "") | 352 | if (*file == "" && filename == "") |
353 | return e_filename; | 353 | return e_filename; |
354 | if (*file != "") | 354 | if (*file != "") |
355 | filename = *file; | 355 | filename = *file; |
356 | } | 356 | } |
357 | 357 | ||
358 | wasDeepLocked = isDeepLocked(); | 358 | wasDeepLocked = isDeepLocked(); |
359 | if (wasDeepLocked) { | 359 | if (wasDeepLocked) { |
360 | /* We are deeplocked. That means all data is already | 360 | /* We are deeplocked. That means all data is already |
361 | * on disk. BUT we need to do saving procedure, | 361 | * on disk. BUT we need to do saving procedure, |
362 | * because *file != savedFilename. | 362 | * because *file != savedFilename. |
363 | * Additionally we need to tempoarly restore | 363 | * Additionally we need to tempoarly restore |
364 | * the old "filename", because deepLock() references it. | 364 | * the old "filename", because deepLock() references it. |
365 | */ | 365 | */ |
366 | QString newFilename(filename); | 366 | QString newFilename(filename); |
367 | filename = savedFilename; | 367 | filename = savedFilename; |
368 | getDataChangedLock(); | 368 | getDataChangedLock(); |
369 | e = deepLock(false); | 369 | e = deepLock(false); |
370 | putDataChangedLock(); | 370 | putDataChangedLock(); |
371 | filename = newFilename; | 371 | filename = newFilename; |
372 | switch (e) { | 372 | switch (e) { |
373 | case e_success: | 373 | case e_success: |
374 | break; | 374 | break; |
375 | case e_wrongPw: | 375 | case e_wrongPw: |
376 | case e_noPw: | 376 | case e_noPw: |
377 | emitDataChanged(this); | 377 | emitDataChanged(this); |
378 | return e; | 378 | return e; |
379 | default: | 379 | default: |
380 | emitDataChanged(this); | 380 | emitDataChanged(this); |
381 | return e_openFile; | 381 | return e_openFile; |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | if (!isPwAvailable()) { | 385 | if (!isPwAvailable()) { |
386 | /* password is not available. This means, the | 386 | /* password is not available. This means, the |
387 | * document wasn't saved, yet. | 387 | * document wasn't saved, yet. |
388 | */ | 388 | */ |
389 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 389 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
390 | QString pw(requestNewMpw(&useChipcard)); | 390 | QString pw(requestNewMpw(&useChipcard)); |
391 | if (pw != "") { | 391 | if (pw != "") { |
392 | currentPw = pw; | 392 | currentPw = pw; |
393 | } else { | 393 | } else { |
394 | return e_noPw; | 394 | return e_noPw; |
395 | } | 395 | } |
396 | if (useChipcard) { | 396 | if (useChipcard) { |
397 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 397 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
398 | } else { | 398 | } else { |
399 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 399 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 403 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
404 | int _hashAlgo = conf()->confGlobHashAlgo(); | 404 | int _hashAlgo = conf()->confGlobHashAlgo(); |
405 | 405 | ||
406 | // sanity check for the selected algorithms | 406 | // sanity check for the selected algorithms |
407 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 407 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
408 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 408 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
409 | printWarn("Invalid Crypto-Algorithm selected! " | 409 | printWarn("Invalid Crypto-Algorithm selected! " |
410 | "Config-file seems to be corrupt. " | 410 | "Config-file seems to be corrupt. " |
411 | "Falling back to Blowfish."); | 411 | "Falling back to Blowfish."); |
412 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 412 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
413 | } | 413 | } |
414 | if (_hashAlgo < PWM_HASH_SHA1 || | 414 | if (_hashAlgo < PWM_HASH_SHA1 || |
415 | _hashAlgo > PWM_HASH_TIGER) { | 415 | _hashAlgo > PWM_HASH_TIGER) { |
416 | printWarn("Invalid Hash-Algorithm selected! " | 416 | printWarn("Invalid Hash-Algorithm selected! " |
417 | "Config-file seems to be corrupt. " | 417 | "Config-file seems to be corrupt. " |
418 | "Falling back to SHA1."); | 418 | "Falling back to SHA1."); |
419 | _hashAlgo = PWM_HASH_SHA1; | 419 | _hashAlgo = PWM_HASH_SHA1; |
420 | } | 420 | } |
421 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 421 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
422 | char hashAlgo = static_cast<char>(_hashAlgo); | 422 | char hashAlgo = static_cast<char>(_hashAlgo); |
423 | 423 | ||
424 | if (conf()->confGlobMakeFileBackup()) { | 424 | if (conf()->confGlobMakeFileBackup()) { |
425 | if (!backupFile(filename)) | 425 | if (!backupFile(filename)) |
426 | return e_fileBackup; | 426 | return e_fileBackup; |
427 | } | 427 | } |
428 | if (QFile::exists(filename)) { | 428 | if (QFile::exists(filename)) { |
429 | /* Move the existing file to some tmp file. | 429 | /* Move the existing file to some tmp file. |
430 | * When saving file succeeds, delete tmp file. Otherwise | 430 | * When saving file succeeds, delete tmp file. Otherwise |
431 | * move tmp file back. See below. | 431 | * move tmp file back. See below. |
432 | */ | 432 | */ |
433 | Randomizer *rnd = Randomizer::obj(); | 433 | Randomizer *rnd = Randomizer::obj(); |
434 | char rnd_buf[5]; | 434 | char rnd_buf[5]; |
435 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 435 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
436 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 436 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
437 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 437 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
438 | if (!copyFile(filename, tmpFileMoved)) | 438 | if (!copyFile(filename, tmpFileMoved)) |
439 | return e_openFile; | 439 | return e_openFile; |
440 | if (!QFile::remove(filename)) { | 440 | if (!QFile::remove(filename)) { |
441 | printWarn(string("removing orig file ") | 441 | printWarn(string("removing orig file ") |
442 | + filename.latin1() | 442 | + filename.latin1() |
443 | + " failed!"); | 443 | + " failed!"); |
444 | } | 444 | } |
445 | } | 445 | } |
446 | f.setName(filename); | 446 | f.setName(filename); |
447 | if (!f.open(IO_ReadWrite)) { | 447 | if (!f.open(IO_ReadWrite)) { |
448 | ret = e_openFile; | 448 | ret = e_openFile; |
449 | goto out_moveback; | 449 | goto out_moveback; |
450 | } | 450 | } |
451 | e = writeFileHeader(hashAlgo, hashAlgo, | 451 | e = writeFileHeader(hashAlgo, hashAlgo, |
452 | cryptAlgo, compress, | 452 | cryptAlgo, compress, |
453 | ¤tPw, &f); | 453 | ¤tPw, &f); |
454 | if (e == e_hashNotImpl) { | 454 | if (e == e_hashNotImpl) { |
455 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 455 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
456 | f.close(); | 456 | f.close(); |
457 | ret = e_hashNotImpl; | 457 | ret = e_hashNotImpl; |
458 | goto out_moveback; | 458 | goto out_moveback; |
459 | } else if (e != e_success) { | 459 | } else if (e != e_success) { |
460 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 460 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
461 | f.close(); | 461 | f.close(); |
462 | ret = e_writeHeader; | 462 | ret = e_writeHeader; |
463 | goto out_moveback; | 463 | goto out_moveback; |
464 | } | 464 | } |
465 | if (!serializeDta(&serialized)) { | 465 | if (!serializeDta(&serialized)) { |
466 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 466 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
467 | f.close(); | 467 | f.close(); |
468 | ret = e_serializeDta; | 468 | ret = e_serializeDta; |
469 | goto out_moveback; | 469 | goto out_moveback; |
470 | } | 470 | } |
471 | e = writeDataHash(hashAlgo, &serialized, &f); | 471 | e = writeDataHash(hashAlgo, &serialized, &f); |
472 | if (e == e_hashNotImpl) { | 472 | if (e == e_hashNotImpl) { |
473 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 473 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
474 | f.close(); | 474 | f.close(); |
475 | ret = e_hashNotImpl; | 475 | ret = e_hashNotImpl; |
476 | goto out_moveback; | 476 | goto out_moveback; |
477 | } else if (e != e_success) { | 477 | } else if (e != e_success) { |
478 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 478 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
479 | f.close(); | 479 | f.close(); |
480 | ret = e_writeHeader; | 480 | ret = e_writeHeader; |
481 | goto out_moveback; | 481 | goto out_moveback; |
482 | } | 482 | } |
483 | if (!compressDta(&serialized, compress)) { | 483 | if (!compressDta(&serialized, compress)) { |
484 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 484 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
485 | f.close(); | 485 | f.close(); |
486 | ret = e_enc; | 486 | ret = e_enc; |
487 | goto out_moveback; | 487 | goto out_moveback; |
488 | } | 488 | } |
489 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); | 489 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); |
490 | if (e == e_weakPw) { | 490 | if (e == e_weakPw) { |
491 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 491 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
492 | f.close(); | 492 | f.close(); |
493 | ret = e_weakPw; | 493 | ret = e_weakPw; |
494 | goto out_moveback; | 494 | goto out_moveback; |
495 | } else if (e == e_cryptNotImpl) { | 495 | } else if (e == e_cryptNotImpl) { |
496 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 496 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
497 | f.close(); | 497 | f.close(); |
498 | ret = e_cryptNotImpl; | 498 | ret = e_cryptNotImpl; |
499 | goto out_moveback; | 499 | goto out_moveback; |
500 | } else if (e != e_success) { | 500 | } else if (e != e_success) { |
501 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 501 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
502 | f.close(); | 502 | f.close(); |
503 | ret = e_enc; | 503 | ret = e_enc; |
504 | goto out_moveback; | 504 | goto out_moveback; |
505 | } | 505 | } |
506 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 506 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
507 | f.close(); | 507 | f.close(); |
508 | if (chmod(filename.latin1(), | 508 | if (chmod(filename.latin1(), |
509 | conf()->confGlobFilePermissions())) { | 509 | conf()->confGlobFilePermissions())) { |
510 | printWarn(string("chmod failed: ") + strerror(errno)); | 510 | printWarn(string("chmod failed: ") + strerror(errno)); |
511 | } | 511 | } |
512 | openDocList.edit(this, getTitle().latin1()); | 512 | openDocList.edit(this, getTitle().latin1()); |
513 | if (wasDeepLocked) { | 513 | if (wasDeepLocked) { |
514 | /* Do _not_ save the data with the deepLock() | 514 | /* Do _not_ save the data with the deepLock() |
515 | * call, because this will recurse | 515 | * call, because this will recurse |
516 | * into saveDoc() | 516 | * into saveDoc() |
517 | */ | 517 | */ |
518 | deepLock(true, false); | 518 | deepLock(true, false); |
519 | /* We don't check return value here, because | 519 | /* We don't check return value here, because |
520 | * it won't fail. See NOTE in deepLock() | 520 | * it won't fail. See NOTE in deepLock() |
521 | */ | 521 | */ |
522 | } | 522 | } |
523 | if (tmpFileMoved != QString::null) { | 523 | if (tmpFileMoved != QString::null) { |
524 | // now remove the moved file. | 524 | // now remove the moved file. |
525 | if (!QFile::remove(tmpFileMoved)) { | 525 | if (!QFile::remove(tmpFileMoved)) { |
526 | printWarn(string("removing file ") | 526 | printWarn(string("removing file ") |
527 | + tmpFileMoved.latin1() | 527 | + tmpFileMoved.latin1() |
528 | + " failed!"); | 528 | + " failed!"); |
529 | } | 529 | } |
530 | } | 530 | } |
531 | ret = e_success; | 531 | ret = e_success; |
532 | printDebug(string("writing file { name: ") | 532 | printDebug(string("writing file { name: ") |
533 | + filename.latin1() + " compress: " | 533 | + filename.latin1() + " compress: " |
534 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 534 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
535 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 535 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
536 | + tostr(static_cast<int>(hashAlgo)) | 536 | + tostr(static_cast<int>(hashAlgo)) |
537 | + " }"); | 537 | + " }"); |
538 | goto out; | 538 | goto out; |
539 | out_moveback: | 539 | out_moveback: |
540 | if (tmpFileMoved != QString::null) { | 540 | if (tmpFileMoved != QString::null) { |
541 | if (copyFile(tmpFileMoved, filename)) { | 541 | if (copyFile(tmpFileMoved, filename)) { |
542 | if (!QFile::remove(tmpFileMoved)) { | 542 | if (!QFile::remove(tmpFileMoved)) { |
543 | printWarn(string("removing tmp file ") | 543 | printWarn(string("removing tmp file ") |
544 | + filename.latin1() | 544 | + filename.latin1() |
545 | + " failed!"); | 545 | + " failed!"); |
546 | } | 546 | } |
547 | } else { | 547 | } else { |
548 | printWarn(string("couldn't copy file ") | 548 | printWarn(string("couldn't copy file ") |
549 | + tmpFileMoved.latin1() | 549 | + tmpFileMoved.latin1() |
550 | + " back to " | 550 | + " back to " |
551 | + filename.latin1()); | 551 | + filename.latin1()); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | out: | 554 | out: |
555 | return ret; | 555 | return ret; |
556 | } | 556 | } |
557 | 557 | ||
558 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 558 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
559 | { | 559 | { |
560 | PWM_ASSERT(file); | 560 | PWM_ASSERT(file); |
561 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 561 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
562 | string decrypted, dataHash; | 562 | string decrypted, dataHash; |
563 | PwMerror ret; | 563 | PwMerror ret; |
564 | char cryptAlgo, dataHashType, compress; | 564 | char cryptAlgo, dataHashType, compress; |
565 | unsigned int headerLen; | 565 | unsigned int headerLen; |
566 | 566 | ||
567 | if (*file == "") | 567 | if (*file == "") |
568 | return e_readFile; | 568 | return e_readFile; |
569 | filename = *file; | 569 | filename = *file; |
570 | /* check if this file is already open. | 570 | /* check if this file is already open. |
571 | * This does not catch symlinks! | 571 | * This does not catch symlinks! |
572 | */ | 572 | */ |
573 | if (!isDeepLocked()) { | 573 | if (!isDeepLocked()) { |
574 | if (getOpenDocList()->find(filename.latin1())) | 574 | if (getOpenDocList()->find(filename.latin1())) |
575 | return e_alreadyOpen; | 575 | return e_alreadyOpen; |
576 | } | 576 | } |
577 | QFile f(filename); | 577 | QFile f(filename); |
578 | 578 | ||
579 | if (openLocked == 2) { | 579 | if (openLocked == 2) { |
580 | // open deep-locked | 580 | // open deep-locked |
581 | if (!QFile::exists(filename)) | 581 | if (!QFile::exists(filename)) |
582 | return e_openFile; | 582 | return e_openFile; |
583 | if (deepLock(true, false) != e_success) | 583 | if (deepLock(true, false) != e_success) |
584 | return e_openFile; | 584 | return e_openFile; |
585 | goto out_success; | 585 | goto out_success; |
586 | } | 586 | } |
587 | 587 | ||
588 | if (!f.open(IO_ReadOnly)) | 588 | if (!f.open(IO_ReadOnly)) |
589 | return e_openFile; | 589 | return e_openFile; |
590 | 590 | ||
591 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 591 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
592 | &dataHashType, &dataHash, &f); | 592 | &dataHashType, &dataHash, &f); |
593 | if (ret != e_success) { | 593 | if (ret != e_success) { |
594 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 594 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
595 | f.close(); | 595 | f.close(); |
596 | if (ret == e_wrongPw) { | 596 | if (ret == e_wrongPw) { |
597 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 597 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
598 | return ret; | 598 | return ret; |
599 | } else if (ret == e_noPw || | 599 | } else if (ret == e_noPw || |
600 | ret == e_fileVer || | 600 | ret == e_fileVer || |
601 | ret == e_fileFormat || | 601 | ret == e_fileFormat || |
602 | ret == e_hashNotImpl) { | 602 | ret == e_hashNotImpl) { |
603 | return ret; | 603 | return ret; |
604 | } else | 604 | } else |
605 | return e_readFile; | 605 | return e_readFile; |
606 | } | 606 | } |
607 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 607 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
608 | if (ret == e_cryptNotImpl) { | 608 | if (ret == e_cryptNotImpl) { |
609 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 609 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
610 | f.close(); | 610 | f.close(); |
611 | return e_cryptNotImpl; | 611 | return e_cryptNotImpl; |
612 | } else if (ret != e_success) { | 612 | } else if (ret != e_success) { |
613 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 613 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
614 | f.close(); | 614 | f.close(); |
615 | return e_readFile; | 615 | return e_readFile; |
616 | } | 616 | } |
617 | if (!decompressDta(&decrypted, compress)) { | 617 | if (!decompressDta(&decrypted, compress)) { |
618 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 618 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
619 | f.close(); | 619 | f.close(); |
620 | return e_fileCorrupt; | 620 | return e_fileCorrupt; |
621 | } | 621 | } |
622 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 622 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
623 | if (ret == e_hashNotImpl) { | 623 | if (ret == e_hashNotImpl) { |
624 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 624 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
625 | f.close(); | 625 | f.close(); |
626 | return e_hashNotImpl; | 626 | return e_hashNotImpl; |
627 | } else if (ret != e_success) { | 627 | } else if (ret != e_success) { |
628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
629 | f.close(); | 629 | f.close(); |
630 | return e_fileCorrupt; | 630 | return e_fileCorrupt; |
631 | } | 631 | } |
632 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 632 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
633 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 633 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
634 | f.close(); | 634 | f.close(); |
635 | return e_readFile; | 635 | return e_readFile; |
636 | } | 636 | } |
637 | f.close(); | 637 | f.close(); |
638 | timer()->start(DocTimer::id_mpwTimer); | 638 | timer()->start(DocTimer::id_mpwTimer); |
639 | timer()->start(DocTimer::id_autoLockTimer); | 639 | timer()->start(DocTimer::id_autoLockTimer); |
640 | out_success: | 640 | out_success: |
641 | openDocList.edit(this, getTitle().latin1()); | 641 | openDocList.edit(this, getTitle().latin1()); |
642 | emit docOpened(this); | 642 | emit docOpened(this); |
643 | return e_success; | 643 | return e_success; |
644 | } | 644 | } |
645 | 645 | ||
646 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 646 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
647 | QString *pw, QFile *f) | 647 | QString *pw, QFile *f) |
648 | { | 648 | { |
649 | PWM_ASSERT(pw); | 649 | PWM_ASSERT(pw); |
650 | PWM_ASSERT(f); | 650 | PWM_ASSERT(f); |
651 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else | 651 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
652 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | 652 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion |
653 | //USPWM_ASSERT(listView); | 653 | //USPWM_ASSERT(listView); |
654 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 654 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
655 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 655 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
656 | return e_writeFile; | 656 | return e_writeFile; |
657 | } | 657 | } |
658 | if (f->putch(PWM_FILE_VER) == -1 || | 658 | if (f->putch(PWM_FILE_VER) == -1 || |
659 | f->putch(keyHash) == -1 || | 659 | f->putch(keyHash) == -1 || |
660 | f->putch(dataHash) == -1 || | 660 | f->putch(dataHash) == -1 || |
661 | f->putch(crypt) == -1 || | 661 | f->putch(crypt) == -1 || |
662 | f->putch(compress) == -1 || | 662 | f->putch(compress) == -1 || |
663 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 663 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
664 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 664 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
665 | return e_writeFile; | 665 | return e_writeFile; |
666 | } | 666 | } |
667 | 667 | ||
668 | // write bytes of NUL-data. These bytes are reserved for future-use. | 668 | // write bytes of NUL-data. These bytes are reserved for future-use. |
669 | const int bufSize = 64; | 669 | const int bufSize = 64; |
670 | char tmp_buf[bufSize]; | 670 | char tmp_buf[bufSize]; |
671 | memset(tmp_buf, 0x00, bufSize); | 671 | memset(tmp_buf, 0x00, bufSize); |
672 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 672 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
673 | return e_writeFile; | 673 | return e_writeFile; |
674 | 674 | ||
675 | switch (keyHash) { | 675 | switch (keyHash) { |
676 | case PWM_HASH_SHA1: { | 676 | case PWM_HASH_SHA1: { |
677 | const int hashlen = SHA1_HASH_LEN_BYTE; | 677 | const int hashlen = SHA1_HASH_LEN_BYTE; |
678 | Sha1 hash; | 678 | Sha1 hash; |
679 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 679 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
680 | string ret = hash.sha1_read(); | 680 | string ret = hash.sha1_read(); |
681 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 681 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
682 | return e_writeFile; | 682 | return e_writeFile; |
683 | break; | 683 | break; |
684 | } | 684 | } |
685 | case PWM_HASH_SHA256: | 685 | case PWM_HASH_SHA256: |
686 | /*... fall through */ | 686 | /*... fall through */ |
687 | case PWM_HASH_SHA384: | 687 | case PWM_HASH_SHA384: |
688 | case PWM_HASH_SHA512: | 688 | case PWM_HASH_SHA512: |
689 | case PWM_HASH_MD5: | 689 | case PWM_HASH_MD5: |
690 | case PWM_HASH_RMD160: | 690 | case PWM_HASH_RMD160: |
691 | case PWM_HASH_TIGER: | 691 | case PWM_HASH_TIGER: |
692 | { | 692 | { |
693 | if (!LibGCryptIf::available()) | 693 | if (!LibGCryptIf::available()) |
694 | return e_hashNotImpl; | 694 | return e_hashNotImpl; |
695 | LibGCryptIf gc; | 695 | LibGCryptIf gc; |
696 | PwMerror err; | 696 | PwMerror err; |
697 | unsigned char *buf; | 697 | unsigned char *buf; |
698 | size_t hashLen; | 698 | size_t hashLen; |
699 | err = gc.hash(&buf, | 699 | err = gc.hash(&buf, |
700 | &hashLen, | 700 | &hashLen, |
701 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 701 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
702 | pw->length(), | 702 | pw->length(), |
703 | keyHash); | 703 | keyHash); |
704 | if (err != e_success) | 704 | if (err != e_success) |
705 | return e_hashNotImpl; | 705 | return e_hashNotImpl; |
706 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 706 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
707 | != static_cast<Q_LONG>(hashLen)) { | 707 | != static_cast<Q_LONG>(hashLen)) { |
708 | delete [] buf; | 708 | delete [] buf; |
709 | return e_hashNotImpl; | 709 | return e_hashNotImpl; |
710 | } | 710 | } |
711 | delete [] buf; | 711 | delete [] buf; |
712 | break; | 712 | break; |
713 | } | 713 | } |
714 | default: { | 714 | default: { |
715 | return e_hashNotImpl; | 715 | return e_hashNotImpl; |
716 | } } | 716 | } } |
717 | return e_success; | 717 | return e_success; |
718 | } | 718 | } |
719 | 719 | ||
720 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 720 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
721 | unsigned int *headerLength, char *dataHashType, | 721 | unsigned int *headerLength, char *dataHashType, |
722 | string *dataHash, QFile *f) | 722 | string *dataHash, QFile *f) |
723 | { | 723 | { |
724 | PWM_ASSERT(cryptAlgo); | 724 | PWM_ASSERT(cryptAlgo); |
725 | PWM_ASSERT(pw); | 725 | PWM_ASSERT(pw); |
726 | PWM_ASSERT(headerLength); | 726 | PWM_ASSERT(headerLength); |
727 | PWM_ASSERT(dataHashType); | 727 | PWM_ASSERT(dataHashType); |
728 | PWM_ASSERT(dataHash); | 728 | PWM_ASSERT(dataHash); |
729 | PWM_ASSERT(f); | 729 | PWM_ASSERT(f); |
730 | int tmpRet; | 730 | int tmpRet; |
731 | // check "magic" header | 731 | // check "magic" header |
732 | const char magicHdr[] = FILE_ID_HEADER; | 732 | const char magicHdr[] = FILE_ID_HEADER; |
733 | const int hdrLen = array_size(magicHdr) - 1; | 733 | const int hdrLen = array_size(magicHdr) - 1; |
734 | char tmp[hdrLen]; | 734 | char tmp[hdrLen]; |
735 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 735 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
736 | return e_readFile; | 736 | return e_readFile; |
737 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 737 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
738 | return e_fileFormat; | 738 | return e_fileFormat; |
739 | // read and check file ver | 739 | // read and check file ver |
740 | int fileV = f->getch(); | 740 | int fileV = f->getch(); |
741 | if (fileV == -1) | 741 | if (fileV == -1) |
742 | return e_fileFormat; | 742 | return e_fileFormat; |
743 | if (fileV != PWM_FILE_VER) | 743 | if (fileV != PWM_FILE_VER) |
744 | return e_fileVer; | 744 | return e_fileVer; |
745 | // read hash hash type | 745 | // read hash hash type |
746 | int keyHash = f->getch(); | 746 | int keyHash = f->getch(); |
747 | if (keyHash == -1) | 747 | if (keyHash == -1) |
748 | return e_fileFormat; | 748 | return e_fileFormat; |
749 | // read data hash type | 749 | // read data hash type |
750 | tmpRet = f->getch(); | 750 | tmpRet = f->getch(); |
751 | if (tmpRet == -1) | 751 | if (tmpRet == -1) |
752 | return e_fileFormat; | 752 | return e_fileFormat; |
753 | *dataHashType = tmpRet; | 753 | *dataHashType = tmpRet; |
754 | // read crypt algo | 754 | // read crypt algo |
755 | tmpRet = f->getch(); | 755 | tmpRet = f->getch(); |
756 | if (tmpRet == -1) | 756 | if (tmpRet == -1) |
757 | return e_fileFormat; | 757 | return e_fileFormat; |
758 | *cryptAlgo = tmpRet; | 758 | *cryptAlgo = tmpRet; |
759 | // get compression-algo | 759 | // get compression-algo |
760 | tmpRet = f->getch(); | 760 | tmpRet = f->getch(); |
761 | if (tmpRet == -1) | 761 | if (tmpRet == -1) |
762 | return e_fileFormat; | 762 | return e_fileFormat; |
763 | *compress = tmpRet; | 763 | *compress = tmpRet; |
764 | // get the MPW-flag | 764 | // get the MPW-flag |
765 | int mpw_flag = f->getch(); | 765 | int mpw_flag = f->getch(); |
766 | if (mpw_flag == -1) | 766 | if (mpw_flag == -1) |
767 | return e_fileFormat; | 767 | return e_fileFormat; |
768 | if (mpw_flag == 0x01) | 768 | if (mpw_flag == 0x01) |
769 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 769 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
770 | else | 770 | else |
771 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 771 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
772 | // skip the "RESERVED"-bytes | 772 | // skip the "RESERVED"-bytes |
773 | if (!(f->at(f->at() + 64))) | 773 | if (!(f->at(f->at() + 64))) |
774 | return e_fileFormat; | 774 | return e_fileFormat; |
775 | 775 | ||
776 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 776 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
777 | if (*pw == "") { | 777 | if (*pw == "") { |
778 | /* the user didn't give a master-password | 778 | /* the user didn't give a master-password |
779 | * or didn't insert a chipcard | 779 | * or didn't insert a chipcard |
780 | */ | 780 | */ |
781 | return e_noPw; | 781 | return e_noPw; |
782 | } | 782 | } |
783 | // verify key-hash | 783 | // verify key-hash |
784 | switch (keyHash) { | 784 | switch (keyHash) { |
785 | case PWM_HASH_SHA1: { | 785 | case PWM_HASH_SHA1: { |
786 | // read hash from header | 786 | // read hash from header |
787 | const int hashLen = SHA1_HASH_LEN_BYTE; | 787 | const int hashLen = SHA1_HASH_LEN_BYTE; |
788 | string readHash; | 788 | string readHash; |
789 | int i; | 789 | int i; |
790 | for (i = 0; i < hashLen; ++i) | 790 | for (i = 0; i < hashLen; ++i) |
791 | readHash.push_back(f->getch()); | 791 | readHash.push_back(f->getch()); |
792 | Sha1 hash; | 792 | Sha1 hash; |
793 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 793 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
794 | string ret = hash.sha1_read(); | 794 | string ret = hash.sha1_read(); |
795 | if (ret != readHash) | 795 | if (ret != readHash) |
796 | return e_wrongPw;// hash doesn't match (wrong key) | 796 | return e_wrongPw;// hash doesn't match (wrong key) |
797 | break; | 797 | break; |
798 | } | 798 | } |
799 | case PWM_HASH_SHA256: | 799 | case PWM_HASH_SHA256: |
800 | /*... fall through */ | 800 | /*... fall through */ |
801 | case PWM_HASH_SHA384: | 801 | case PWM_HASH_SHA384: |
802 | case PWM_HASH_SHA512: | 802 | case PWM_HASH_SHA512: |
803 | case PWM_HASH_MD5: | 803 | case PWM_HASH_MD5: |
804 | case PWM_HASH_RMD160: | 804 | case PWM_HASH_RMD160: |
805 | case PWM_HASH_TIGER: { | 805 | case PWM_HASH_TIGER: { |
806 | if (!LibGCryptIf::available()) | 806 | if (!LibGCryptIf::available()) |
807 | return e_hashNotImpl; | 807 | return e_hashNotImpl; |
808 | LibGCryptIf gc; | 808 | LibGCryptIf gc; |
809 | PwMerror err; | 809 | PwMerror err; |
810 | unsigned char *buf; | 810 | unsigned char *buf; |
811 | size_t hashLen; | 811 | size_t hashLen; |
812 | err = gc.hash(&buf, | 812 | err = gc.hash(&buf, |
813 | &hashLen, | 813 | &hashLen, |
814 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 814 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
815 | pw->length(), | 815 | pw->length(), |
816 | keyHash); | 816 | keyHash); |
817 | if (err != e_success) | 817 | if (err != e_success) |
818 | return e_hashNotImpl; | 818 | return e_hashNotImpl; |
819 | string calcHash(reinterpret_cast<const char *>(buf), | 819 | string calcHash(reinterpret_cast<const char *>(buf), |
820 | static_cast<string::size_type>(hashLen)); | 820 | static_cast<string::size_type>(hashLen)); |
821 | delete [] buf; | 821 | delete [] buf; |
822 | // read hash from header | 822 | // read hash from header |
823 | string readHash; | 823 | string readHash; |
824 | size_t i; | 824 | size_t i; |
825 | for (i = 0; i < hashLen; ++i) | 825 | for (i = 0; i < hashLen; ++i) |
826 | readHash.push_back(f->getch()); | 826 | readHash.push_back(f->getch()); |
827 | if (calcHash != readHash) | 827 | if (calcHash != readHash) |
828 | return e_wrongPw;// hash doesn't match (wrong key) | 828 | return e_wrongPw;// hash doesn't match (wrong key) |
829 | break; | 829 | break; |
830 | } | 830 | } |
831 | default: { | 831 | default: { |
832 | return e_hashNotImpl; | 832 | return e_hashNotImpl; |
833 | } } | 833 | } } |
834 | // read the data-hash from the file | 834 | // read the data-hash from the file |
835 | unsigned int hashLen, i; | 835 | unsigned int hashLen, i; |
836 | switch (*dataHashType) { | 836 | switch (*dataHashType) { |
837 | case PWM_HASH_SHA1: | 837 | case PWM_HASH_SHA1: |
838 | hashLen = SHA1_HASH_LEN_BYTE; | 838 | hashLen = SHA1_HASH_LEN_BYTE; |
839 | break; | 839 | break; |
840 | case PWM_HASH_SHA256: | 840 | case PWM_HASH_SHA256: |
841 | /*... fall through */ | 841 | /*... fall through */ |
842 | case PWM_HASH_SHA384: | 842 | case PWM_HASH_SHA384: |
843 | case PWM_HASH_SHA512: | 843 | case PWM_HASH_SHA512: |
844 | case PWM_HASH_MD5: | 844 | case PWM_HASH_MD5: |
845 | case PWM_HASH_RMD160: | 845 | case PWM_HASH_RMD160: |
846 | case PWM_HASH_TIGER: { | 846 | case PWM_HASH_TIGER: { |
847 | if (!LibGCryptIf::available()) | 847 | if (!LibGCryptIf::available()) |
848 | return e_hashNotImpl; | 848 | return e_hashNotImpl; |
849 | LibGCryptIf gc; | 849 | LibGCryptIf gc; |
850 | hashLen = gc.hashLength(*dataHashType); | 850 | hashLen = gc.hashLength(*dataHashType); |
851 | if (hashLen == 0) | 851 | if (hashLen == 0) |
852 | return e_hashNotImpl; | 852 | return e_hashNotImpl; |
853 | break; | 853 | break; |
854 | } | 854 | } |
855 | default: | 855 | default: |
856 | return e_hashNotImpl; | 856 | return e_hashNotImpl; |
857 | } | 857 | } |
858 | *dataHash = ""; | 858 | *dataHash = ""; |
859 | for (i = 0; i < hashLen; ++i) { | 859 | for (i = 0; i < hashLen; ++i) { |
860 | tmpRet = f->getch(); | 860 | tmpRet = f->getch(); |
861 | if (tmpRet == -1) | 861 | if (tmpRet == -1) |
862 | return e_fileFormat; | 862 | return e_fileFormat; |
863 | dataHash->push_back(static_cast<char>(tmpRet)); | 863 | dataHash->push_back(static_cast<char>(tmpRet)); |
864 | } | 864 | } |
865 | *headerLength = f->at(); | 865 | *headerLength = f->at(); |
866 | #ifndef PWM_EMBEDDED | 866 | #ifndef PWM_EMBEDDED |
867 | printDebug(string("opening file { compress: ") | 867 | printDebug(string("opening file { compress: ") |
868 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 868 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
869 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 869 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
870 | + tostr(static_cast<int>(keyHash)) | 870 | + tostr(static_cast<int>(keyHash)) |
871 | + " }"); | 871 | + " }"); |
872 | #else | 872 | #else |
873 | printDebug(string("opening file { compress: ") | 873 | printDebug(string("opening file { compress: ") |
874 | + tostr((int)(*compress)) + " cryptAlgo: " | 874 | + tostr((int)(*compress)) + " cryptAlgo: " |
875 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 875 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
876 | + tostr((int)(keyHash)) | 876 | + tostr((int)(keyHash)) |
877 | + " }"); | 877 | + " }"); |
878 | #endif | 878 | #endif |
879 | 879 | ||
880 | return e_success; | 880 | return e_success; |
881 | } | 881 | } |
882 | 882 | ||
883 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 883 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
884 | { | 884 | { |
885 | PWM_ASSERT(d); | 885 | PWM_ASSERT(d); |
886 | PWM_ASSERT(f); | 886 | PWM_ASSERT(f); |
887 | 887 | ||
888 | switch (dataHash) { | 888 | switch (dataHash) { |
889 | case PWM_HASH_SHA1: { | 889 | case PWM_HASH_SHA1: { |
890 | const int hashLen = SHA1_HASH_LEN_BYTE; | 890 | const int hashLen = SHA1_HASH_LEN_BYTE; |
891 | Sha1 h; | 891 | Sha1 h; |
892 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 892 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
893 | string hRet = h.sha1_read(); | 893 | string hRet = h.sha1_read(); |
894 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 894 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
895 | return e_writeFile; | 895 | return e_writeFile; |
896 | break; | 896 | break; |
897 | } | 897 | } |
898 | case PWM_HASH_SHA256: | 898 | case PWM_HASH_SHA256: |
899 | /*... fall through */ | 899 | /*... fall through */ |
900 | case PWM_HASH_SHA384: | 900 | case PWM_HASH_SHA384: |
901 | case PWM_HASH_SHA512: | 901 | case PWM_HASH_SHA512: |
902 | case PWM_HASH_MD5: | 902 | case PWM_HASH_MD5: |
903 | case PWM_HASH_RMD160: | 903 | case PWM_HASH_RMD160: |
904 | case PWM_HASH_TIGER: { | 904 | case PWM_HASH_TIGER: { |
905 | if (!LibGCryptIf::available()) | 905 | if (!LibGCryptIf::available()) |
906 | return e_hashNotImpl; | 906 | return e_hashNotImpl; |
907 | LibGCryptIf gc; | 907 | LibGCryptIf gc; |
908 | PwMerror err; | 908 | PwMerror err; |
909 | unsigned char *buf; | 909 | unsigned char *buf; |
910 | size_t hashLen; | 910 | size_t hashLen; |
911 | err = gc.hash(&buf, | 911 | err = gc.hash(&buf, |
912 | &hashLen, | 912 | &hashLen, |
913 | reinterpret_cast<const unsigned char *>(d->c_str()), | 913 | reinterpret_cast<const unsigned char *>(d->c_str()), |
914 | d->size(), | 914 | d->size(), |
915 | dataHash); | 915 | dataHash); |
916 | if (err != e_success) | 916 | if (err != e_success) |
917 | return e_hashNotImpl; | 917 | return e_hashNotImpl; |
918 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 918 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
919 | != static_cast<Q_LONG>(hashLen)) { | 919 | != static_cast<Q_LONG>(hashLen)) { |
920 | delete [] buf; | 920 | delete [] buf; |
921 | return e_hashNotImpl; | 921 | return e_hashNotImpl; |
922 | } | 922 | } |
923 | delete [] buf; | 923 | delete [] buf; |
924 | break; | 924 | break; |
925 | } | 925 | } |
926 | default: { | 926 | default: { |
927 | return e_hashNotImpl; | 927 | return e_hashNotImpl; |
928 | } } | 928 | } } |
929 | 929 | ||
930 | return e_success; | 930 | return e_success; |
931 | } | 931 | } |
932 | 932 | ||
933 | bool PwMDoc::backupFile(const QString &filePath) | 933 | bool PwMDoc::backupFile(const QString &filePath) |
934 | { | 934 | { |
935 | QFileInfo fi(filePath); | 935 | QFileInfo fi(filePath); |
936 | if (!fi.exists()) | 936 | if (!fi.exists()) |
937 | return true; // Yes, true is correct. | 937 | return true; // Yes, true is correct. |
938 | QString pathOnly(fi.dirPath(true)); | 938 | QString pathOnly(fi.dirPath(true)); |
939 | QString nameOnly(fi.fileName()); | 939 | QString nameOnly(fi.fileName()); |
940 | QString backupPath = pathOnly | 940 | QString backupPath = pathOnly |
941 | + "/~" | 941 | + "/~" |
942 | + nameOnly | 942 | + nameOnly |
943 | + ".backup"; | 943 | + ".backup"; |
944 | return copyFile(filePath, backupPath); | 944 | return copyFile(filePath, backupPath); |
945 | } | 945 | } |
946 | 946 | ||
947 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 947 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
948 | { | 948 | { |
949 | QFileInfo fi(src); | 949 | QFileInfo fi(src); |
950 | if (!fi.exists()) | 950 | if (!fi.exists()) |
951 | return false; | 951 | return false; |
952 | if (QFile::exists(dst)) { | 952 | if (QFile::exists(dst)) { |
953 | if (!QFile::remove(dst)) | 953 | if (!QFile::remove(dst)) |
954 | return false; | 954 | return false; |
955 | } | 955 | } |
956 | QFile srcFd(src); | 956 | QFile srcFd(src); |
957 | if (!srcFd.open(IO_ReadOnly)) | 957 | if (!srcFd.open(IO_ReadOnly)) |
958 | return false; | 958 | return false; |
959 | QFile dstFd(dst); | 959 | QFile dstFd(dst); |
960 | if (!dstFd.open(IO_ReadWrite)) { | 960 | if (!dstFd.open(IO_ReadWrite)) { |
961 | srcFd.close(); | 961 | srcFd.close(); |
962 | return false; | 962 | return false; |
963 | } | 963 | } |
964 | const int tmpBuf_size = 512; | 964 | const int tmpBuf_size = 512; |
965 | char tmpBuf[tmpBuf_size]; | 965 | char tmpBuf[tmpBuf_size]; |
966 | Q_LONG bytesRead, bytesWritten; | 966 | Q_LONG bytesRead, bytesWritten; |
967 | 967 | ||
968 | while (!srcFd.atEnd()) { | 968 | while (!srcFd.atEnd()) { |
969 | bytesRead = srcFd.readBlock(tmpBuf, | 969 | bytesRead = srcFd.readBlock(tmpBuf, |
970 | static_cast<Q_ULONG>(tmpBuf_size)); | 970 | static_cast<Q_ULONG>(tmpBuf_size)); |
971 | if (bytesRead == -1) { | 971 | if (bytesRead == -1) { |
972 | srcFd.close(); | 972 | srcFd.close(); |
973 | dstFd.close(); | 973 | dstFd.close(); |
974 | return false; | 974 | return false; |
975 | } | 975 | } |
976 | bytesWritten = dstFd.writeBlock(tmpBuf, | 976 | bytesWritten = dstFd.writeBlock(tmpBuf, |
977 | static_cast<Q_ULONG>(bytesRead)); | 977 | static_cast<Q_ULONG>(bytesRead)); |
978 | if (bytesWritten != bytesRead) { | 978 | if (bytesWritten != bytesRead) { |
979 | srcFd.close(); | 979 | srcFd.close(); |
980 | dstFd.close(); | 980 | dstFd.close(); |
981 | return false; | 981 | return false; |
982 | } | 982 | } |
983 | } | 983 | } |
984 | srcFd.close(); | 984 | srcFd.close(); |
985 | dstFd.close(); | 985 | dstFd.close(); |
986 | return true; | 986 | return true; |
987 | } | 987 | } |
988 | 988 | ||
989 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 989 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
990 | bool dontFlagDirty, bool updateMeta) | 990 | bool dontFlagDirty, bool updateMeta) |
991 | { | 991 | { |
992 | PWM_ASSERT(d); | 992 | PWM_ASSERT(d); |
993 | unsigned int cat = 0; | 993 | unsigned int cat = 0; |
994 | 994 | ||
995 | if (isDeepLocked()) { | 995 | if (isDeepLocked()) { |
996 | PwMerror ret; | 996 | PwMerror ret; |
997 | ret = deepLock(false); | 997 | ret = deepLock(false); |
998 | if (ret != e_success) | 998 | if (ret != e_success) |
999 | return e_lock; | 999 | return e_lock; |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | addCategory(category, &cat); | 1002 | addCategory(category, &cat); |
1003 | 1003 | ||
1004 | if (numEntries(category) >= maxEntries) | 1004 | if (numEntries(category) >= maxEntries) |
1005 | return e_maxAllowedEntr; | 1005 | return e_maxAllowedEntr; |
1006 | 1006 | ||
1007 | vector<unsigned int> foundPositions; | 1007 | vector<unsigned int> foundPositions; |
1008 | /* historically this was: | 1008 | /* historically this was: |
1009 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 1009 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
1010 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 1010 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
1011 | * But for now we only search in desc. | 1011 | * But for now we only search in desc. |
1012 | * That's a tweak to be KWallet compatible. But it should not add | 1012 | * That's a tweak to be KWallet compatible. But it should not add |
1013 | * usability-drop onto PwManager, does it? | 1013 | * usability-drop onto PwManager, does it? |
1014 | * (And yes, "int" was a bug. Correct is "unsigned int") | 1014 | * (And yes, "int" was a bug. Correct is "unsigned int") |
1015 | */ | 1015 | */ |
1016 | const unsigned int searchIn = SEARCH_IN_DESC; | 1016 | const unsigned int searchIn = SEARCH_IN_DESC; |
1017 | findEntry(cat, *d, searchIn, &foundPositions, true); | 1017 | findEntry(cat, *d, searchIn, &foundPositions, true); |
1018 | if (foundPositions.size()) { | 1018 | if (foundPositions.size()) { |
1019 | // DOH! We found this entry. | 1019 | // DOH! We found this entry. |
1020 | return e_entryExists; | 1020 | return e_entryExists; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | d->listViewPos = -1; | 1023 | d->listViewPos = -1; |
1024 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1024 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1025 | if (updateMeta) { | 1025 | if (updateMeta) { |
1026 | d->meta.create = QDateTime::currentDateTime(); | 1026 | d->meta.create = QDateTime::currentDateTime(); |
1027 | d->meta.update = d->meta.create; | 1027 | d->meta.update = d->meta.create; |
1028 | } | 1028 | } |
1029 | dti.dta[cat].d.push_back(*d); | 1029 | dti.dta[cat].d.push_back(*d); |
1030 | 1030 | ||
1031 | delAllEmptyCat(true); | 1031 | delAllEmptyCat(true); |
1032 | 1032 | ||
1033 | if (!dontFlagDirty) | 1033 | if (!dontFlagDirty) |
1034 | flagDirty(); | 1034 | flagDirty(); |
1035 | return e_success; | 1035 | return e_success; |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1038 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1039 | bool checkIfExist) | 1039 | bool checkIfExist) |
1040 | { | 1040 | { |
1041 | if (isDeepLocked()) { | 1041 | if (isDeepLocked()) { |
1042 | PwMerror ret; | 1042 | PwMerror ret; |
1043 | ret = deepLock(false); | 1043 | ret = deepLock(false); |
1044 | if (ret != e_success) | 1044 | if (ret != e_success) |
1045 | return e_lock; | 1045 | return e_lock; |
1046 | } | 1046 | } |
1047 | if (checkIfExist) { | 1047 | if (checkIfExist) { |
1048 | if (findCategory(category, categoryIndex)) | 1048 | if (findCategory(category, categoryIndex)) |
1049 | return e_categoryExists; | 1049 | return e_categoryExists; |
1050 | } | 1050 | } |
1051 | PwMCategoryItem item; | 1051 | PwMCategoryItem item; |
1052 | item.name = category.latin1(); | 1052 | item.name = category.latin1(); |
1053 | dti.dta.push_back(item); | 1053 | dti.dta.push_back(item); |
1054 | if (categoryIndex) | 1054 | if (categoryIndex) |
1055 | *categoryIndex = dti.dta.size() - 1; | 1055 | *categoryIndex = dti.dta.size() - 1; |
1056 | return e_success; | 1056 | return e_success; |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1059 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1060 | { | 1060 | { |
1061 | unsigned int cat = 0; | 1061 | unsigned int cat = 0; |
1062 | 1062 | ||
1063 | if (!findCategory(category, &cat)) { | 1063 | if (!findCategory(category, &cat)) { |
1064 | BUG(); | 1064 | BUG(); |
1065 | return false; | 1065 | return false; |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | return delEntry(cat, index, dontFlagDirty); | 1068 | return delEntry(cat, index, dontFlagDirty); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1071 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1072 | { | 1072 | { |
1073 | if (isDeepLocked()) | 1073 | if (isDeepLocked()) |
1074 | return false; | 1074 | return false; |
1075 | if (index > dti.dta[category].d.size() - 1) | 1075 | if (index > dti.dta[category].d.size() - 1) |
1076 | return false; | 1076 | return false; |
1077 | getDataChangedLock(); | 1077 | getDataChangedLock(); |
1078 | if (!lockAt(category, index, false)) { | 1078 | if (!lockAt(category, index, false)) { |
1079 | putDataChangedLock(); | 1079 | putDataChangedLock(); |
1080 | return false; | 1080 | return false; |
1081 | } | 1081 | } |
1082 | putDataChangedLock(); | 1082 | putDataChangedLock(); |
1083 | int lvPos = dti.dta[category].d[index].listViewPos; | 1083 | int lvPos = dti.dta[category].d[index].listViewPos; |
1084 | 1084 | ||
1085 | // delete entry | 1085 | // delete entry |
1086 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); | 1086 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1087 | 1087 | ||
1088 | unsigned int i, entries = numEntries(category); | 1088 | unsigned int i, entries = numEntries(category); |
1089 | if (!entries) { | 1089 | if (!entries) { |
1090 | // no more entries in this category, so | 1090 | // no more entries in this category, so |
1091 | // we can delete it, too. | 1091 | // we can delete it, too. |
1092 | BUG_ON(!delCategory(category)); | 1092 | BUG_ON(!delCategory(category)); |
1093 | // delCategory() flags it dirty, so we need not to do so. | 1093 | // delCategory() flags it dirty, so we need not to do so. |
1094 | return true; | 1094 | return true; |
1095 | } | 1095 | } |
1096 | for (i = 0; i < entries; ++i) { | 1096 | for (i = 0; i < entries; ++i) { |
1097 | // decrement all listViewPositions that are greater than the deleted. | 1097 | // decrement all listViewPositions that are greater than the deleted. |
1098 | if (dti.dta[category].d[i].listViewPos > lvPos) | 1098 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1099 | --dti.dta[category].d[i].listViewPos; | 1099 | --dti.dta[category].d[i].listViewPos; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | if (!dontFlagDirty) | 1102 | if (!dontFlagDirty) |
1103 | flagDirty(); | 1103 | flagDirty(); |
1104 | return true; | 1104 | return true; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1107 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1108 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1108 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1109 | { | 1109 | { |
1110 | PWM_ASSERT(d); | 1110 | PWM_ASSERT(d); |
1111 | unsigned int oldCat = 0; | 1111 | unsigned int oldCat = 0; |
1112 | 1112 | ||
1113 | if (!findCategory(oldCategory, &oldCat)) { | 1113 | if (!findCategory(oldCategory, &oldCat)) { |
1114 | BUG(); | 1114 | BUG(); |
1115 | return false; | 1115 | return false; |
1116 | } | 1116 | } |
1117 | 1117 | ||
1118 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1118 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1121 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1122 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1122 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1123 | { | 1123 | { |
1124 | if (isDeepLocked()) | 1124 | if (isDeepLocked()) |
1125 | return false; | 1125 | return false; |
1126 | if (updateMeta) { | 1126 | if (updateMeta) { |
1127 | d->meta.update = QDateTime::currentDateTime(); | 1127 | d->meta.update = QDateTime::currentDateTime(); |
1128 | if (d->meta.create.isNull()) { | 1128 | if (d->meta.create.isNull()) { |
1129 | d->meta.create = d->meta.update; | 1129 | d->meta.create = d->meta.update; |
1130 | } | 1130 | } |
1131 | } | 1131 | } |
1132 | if (dti.dta[oldCategory].name != newCategory.latin1()) { | 1132 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1133 | // the user changed the category. | 1133 | // the user changed the category. |
1134 | PwMerror ret; | 1134 | PwMerror ret; |
1135 | d->rev = 0; | 1135 | d->rev = 0; |
1136 | ret = addEntry(newCategory, d, true, false); | 1136 | ret = addEntry(newCategory, d, true, false); |
1137 | if (ret != e_success) | 1137 | if (ret != e_success) |
1138 | return false; | 1138 | return false; |
1139 | if (!delEntry(oldCategory, index, true)) | 1139 | if (!delEntry(oldCategory, index, true)) |
1140 | return false; | 1140 | return false; |
1141 | } else { | 1141 | } else { |
1142 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1142 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1143 | dti.dta[oldCategory].d[index] = *d; | 1143 | dti.dta[oldCategory].d[index] = *d; |
1144 | } | 1144 | } |
1145 | flagDirty(); | 1145 | flagDirty(); |
1146 | return true; | 1146 | return true; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | unsigned int PwMDoc::numEntries(const QString &category) | 1149 | unsigned int PwMDoc::numEntries(const QString &category) |
1150 | { | 1150 | { |
1151 | unsigned int cat = 0; | 1151 | unsigned int cat = 0; |
1152 | 1152 | ||
1153 | if (!findCategory(category, &cat)) { | 1153 | if (!findCategory(category, &cat)) { |
1154 | BUG(); | 1154 | BUG(); |
1155 | return 0; | 1155 | return 0; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | return numEntries(cat); | 1158 | return numEntries(cat); |
1159 | } | 1159 | } |
1160 | 1160 | ||
1161 | bool PwMDoc::serializeDta(string *d) | 1161 | bool PwMDoc::serializeDta(string *d) |
1162 | { | 1162 | { |
1163 | PWM_ASSERT(d); | 1163 | PWM_ASSERT(d); |
1164 | Serializer ser; | 1164 | Serializer ser; |
1165 | if (!ser.serialize(dti)) | 1165 | if (!ser.serialize(dti)) |
1166 | return false; | 1166 | return false; |
1167 | d->assign(ser.getXml()); | 1167 | d->assign(ser.getXml()); |
1168 | if (!d->size()) | 1168 | if (!d->size()) |
1169 | return false; | 1169 | return false; |
1170 | return true; | 1170 | return true; |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1173 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1174 | { | 1174 | { |
1175 | PWM_ASSERT(d); | 1175 | PWM_ASSERT(d); |
1176 | #ifndef PWM_EMBEDDED | 1176 | #ifndef PWM_EMBEDDED |
1177 | try { | 1177 | try { |
1178 | 1178 | ||
1179 | Serializer ser(d->c_str()); | 1179 | Serializer ser(d->c_str()); |
1180 | ser.setDefaultLockStat(entriesLocked); | 1180 | ser.setDefaultLockStat(entriesLocked); |
1181 | if (!ser.deSerialize(&dti)) | 1181 | if (!ser.deSerialize(&dti)) |
1182 | return false; | 1182 | return false; |
1183 | } catch (PwMException) { | 1183 | } catch (PwMException) { |
1184 | return false; | 1184 | return false; |
1185 | } | 1185 | } |
1186 | #else | 1186 | #else |
1187 | Serializer ser(d->c_str()); | 1187 | Serializer ser(d->c_str()); |
1188 | ser.setDefaultLockStat(entriesLocked); | 1188 | ser.setDefaultLockStat(entriesLocked); |
1189 | if (!ser.deSerialize(&dti)) | 1189 | if (!ser.deSerialize(&dti)) |
1190 | return false; | 1190 | return false; |
1191 | #endif | 1191 | #endif |
1192 | 1192 | ||
1193 | emitDataChanged(this); | 1193 | emitDataChanged(this); |
1194 | return true; | 1194 | return true; |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1197 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1198 | PwMDataItem * d, bool unlockIfLocked) | 1198 | PwMDataItem * d, bool unlockIfLocked) |
1199 | { | 1199 | { |
1200 | PWM_ASSERT(d); | 1200 | PWM_ASSERT(d); |
1201 | unsigned int cat = 0; | 1201 | unsigned int cat = 0; |
1202 | 1202 | ||
1203 | if (!findCategory(category, &cat)) { | 1203 | if (!findCategory(category, &cat)) { |
1204 | BUG(); | 1204 | BUG(); |
1205 | return false; | 1205 | return false; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | return getEntry(cat, index, d, unlockIfLocked); | 1208 | return getEntry(cat, index, d, unlockIfLocked); |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1211 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1212 | PwMDataItem *d, bool unlockIfLocked) | 1212 | PwMDataItem *d, bool unlockIfLocked) |
1213 | { | 1213 | { |
1214 | if (index > dti.dta[category].d.size() - 1) | 1214 | if (index > dti.dta[category].d.size() - 1) |
1215 | return false; | 1215 | return false; |
1216 | 1216 | ||
1217 | bool locked = isLocked(category, index); | 1217 | bool locked = isLocked(category, index); |
1218 | if (locked) { | 1218 | if (locked) { |
1219 | /* this entry is locked. We don't return a password, | 1219 | /* this entry is locked. We don't return a password, |
1220 | * until it's unlocked by the user by inserting | 1220 | * until it's unlocked by the user by inserting |
1221 | * chipcard or entering the mpw | 1221 | * chipcard or entering the mpw |
1222 | */ | 1222 | */ |
1223 | if (unlockIfLocked) { | 1223 | if (unlockIfLocked) { |
1224 | if (!lockAt(category, index, false)) { | 1224 | if (!lockAt(category, index, false)) { |
1225 | return false; | 1225 | return false; |
1226 | } | 1226 | } |
1227 | locked = false; | 1227 | locked = false; |
1228 | } | 1228 | } |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | *d = dti.dta[category].d[index]; | 1231 | *d = dti.dta[category].d[index]; |
1232 | if (locked) | 1232 | if (locked) |
1233 | d->pw = LOCKED_STRING.latin1(); | 1233 | d->pw = LOCKED_STRING.latin1(); |
1234 | 1234 | ||
1235 | return true; | 1235 | return true; |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1238 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1239 | string *foundComment) | 1239 | string *foundComment) |
1240 | { | 1240 | { |
1241 | PWM_ASSERT(foundComment); | 1241 | PWM_ASSERT(foundComment); |
1242 | unsigned int cat = 0; | 1242 | unsigned int cat = 0; |
1243 | 1243 | ||
1244 | if (!findCategory(category, &cat)) | 1244 | if (!findCategory(category, &cat)) |
1245 | return e_invalidArg; | 1245 | return e_invalidArg; |
1246 | 1246 | ||
1247 | unsigned int i, entries = numEntries(cat); | 1247 | unsigned int i, entries = numEntries(cat); |
1248 | for (i = 0; i < entries; ++i) { | 1248 | for (i = 0; i < entries; ++i) { |
1249 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | 1249 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1250 | *foundComment = dti.dta[cat].d[i].comment; | 1250 | *foundComment = dti.dta[cat].d[i].comment; |
1251 | if (dti.dta[cat].d[i].binary) | 1251 | if (dti.dta[cat].d[i].binary) |
1252 | return e_binEntry; | 1252 | return e_binEntry; |
1253 | return e_normalEntry; | 1253 | return e_normalEntry; |
1254 | } | 1254 | } |
1255 | } | 1255 | } |
1256 | BUG(); | 1256 | BUG(); |
1257 | return e_generic; | 1257 | return e_generic; |
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | bool PwMDoc::compressDta(string *d, char algo) | 1260 | bool PwMDoc::compressDta(string *d, char algo) |
1261 | { | 1261 | { |
1262 | PWM_ASSERT(d); | 1262 | PWM_ASSERT(d); |
1263 | switch (algo) { | 1263 | switch (algo) { |
1264 | case PWM_COMPRESS_GZIP: { | 1264 | case PWM_COMPRESS_GZIP: { |
1265 | CompressGzip comp; | 1265 | CompressGzip comp; |
1266 | return comp.compress(d); | 1266 | return comp.compress(d); |
1267 | /*US } case PWM_COMPRESS_BZIP2: { | 1267 | /*US } case PWM_COMPRESS_BZIP2: { |
1268 | CompressBzip2 comp; | 1268 | CompressBzip2 comp; |
1269 | return comp.compress(d); | 1269 | return comp.compress(d); |
1270 | */ | 1270 | */ |
1271 | } case PWM_COMPRESS_NONE: { | 1271 | } case PWM_COMPRESS_NONE: { |
1272 | return true; | 1272 | return true; |
1273 | } default: { | 1273 | } default: { |
1274 | BUG(); | 1274 | BUG(); |
1275 | } | 1275 | } |
1276 | } | 1276 | } |
1277 | return false; | 1277 | return false; |
1278 | } | 1278 | } |
1279 | 1279 | ||
1280 | bool PwMDoc::decompressDta(string *d, char algo) | 1280 | bool PwMDoc::decompressDta(string *d, char algo) |
1281 | { | 1281 | { |
1282 | PWM_ASSERT(d); | 1282 | PWM_ASSERT(d); |
1283 | switch (algo) { | 1283 | switch (algo) { |
1284 | case PWM_COMPRESS_GZIP: { | 1284 | case PWM_COMPRESS_GZIP: { |
1285 | CompressGzip comp; | 1285 | CompressGzip comp; |
1286 | return comp.decompress(d); | 1286 | return comp.decompress(d); |
1287 | /*US } case PWM_COMPRESS_BZIP2: { | 1287 | /*US } case PWM_COMPRESS_BZIP2: { |
1288 | CompressBzip2 comp; | 1288 | CompressBzip2 comp; |
1289 | return comp.decompress(d); | 1289 | return comp.decompress(d); |
1290 | */ | 1290 | */ |
1291 | } case PWM_COMPRESS_NONE: { | 1291 | } case PWM_COMPRESS_NONE: { |
1292 | return true; | 1292 | return true; |
1293 | } | 1293 | } |
1294 | } | 1294 | } |
1295 | return false; | 1295 | return false; |
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1298 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1299 | { | 1299 | { |
1300 | PWM_ASSERT(d); | 1300 | PWM_ASSERT(d); |
1301 | PWM_ASSERT(pw); | 1301 | PWM_ASSERT(pw); |
1302 | PWM_ASSERT(f); | 1302 | PWM_ASSERT(f); |
1303 | 1303 | ||
1304 | size_t encSize; | 1304 | size_t encSize; |
1305 | byte *encrypted = 0; | 1305 | byte *encrypted = 0; |
1306 | 1306 | ||
1307 | switch (algo) { | 1307 | switch (algo) { |
1308 | case PWM_CRYPT_BLOWFISH: { | 1308 | case PWM_CRYPT_BLOWFISH: { |
1309 | Blowfish::padNull(d); | 1309 | Blowfish::padNull(d); |
1310 | encSize = d->length(); | 1310 | encSize = d->length(); |
1311 | encrypted = new byte[encSize]; | 1311 | encrypted = new byte[encSize]; |
1312 | Blowfish bf; | 1312 | Blowfish bf; |
1313 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1313 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1314 | delete [] encrypted; | 1314 | delete [] encrypted; |
1315 | return e_weakPw; | 1315 | return e_weakPw; |
1316 | } | 1316 | } |
1317 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1317 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1318 | break; | 1318 | break; |
1319 | } | 1319 | } |
1320 | case PWM_CRYPT_AES128: | 1320 | case PWM_CRYPT_AES128: |
1321 | /*... fall through */ | 1321 | /*... fall through */ |
1322 | case PWM_CRYPT_AES192: | 1322 | case PWM_CRYPT_AES192: |
1323 | case PWM_CRYPT_AES256: | 1323 | case PWM_CRYPT_AES256: |
1324 | case PWM_CRYPT_3DES: | 1324 | case PWM_CRYPT_3DES: |
1325 | case PWM_CRYPT_TWOFISH: | 1325 | case PWM_CRYPT_TWOFISH: |
1326 | case PWM_CRYPT_TWOFISH128: { | 1326 | case PWM_CRYPT_TWOFISH128: { |
1327 | if (!LibGCryptIf::available()) | 1327 | if (!LibGCryptIf::available()) |
1328 | return e_cryptNotImpl; | 1328 | return e_cryptNotImpl; |
1329 | LibGCryptIf gc; | 1329 | LibGCryptIf gc; |
1330 | PwMerror err; | 1330 | PwMerror err; |
1331 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1331 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1332 | memcpy(plain, d->c_str(), d->length()); | 1332 | memcpy(plain, d->c_str(), d->length()); |
1333 | err = gc.encrypt(&encrypted, | 1333 | err = gc.encrypt(&encrypted, |
1334 | &encSize, | 1334 | &encSize, |
1335 | plain, | 1335 | plain, |
1336 | d->length(), | 1336 | d->length(), |
1337 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1337 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1338 | pw->length(), | 1338 | pw->length(), |
1339 | algo); | 1339 | algo); |
1340 | delete [] plain; | 1340 | delete [] plain; |
1341 | if (err != e_success) | 1341 | if (err != e_success) |
1342 | return e_cryptNotImpl; | 1342 | return e_cryptNotImpl; |
1343 | break; | 1343 | break; |
1344 | } | 1344 | } |
1345 | default: { | 1345 | default: { |
1346 | delete_ifnot_null_array(encrypted); | 1346 | delete_ifnot_null_array(encrypted); |
1347 | return e_cryptNotImpl; | 1347 | return e_cryptNotImpl; |
1348 | } } | 1348 | } } |
1349 | 1349 | ||
1350 | // write encrypted data to file | 1350 | // write encrypted data to file |
1351 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1351 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1352 | static_cast<Q_ULONG>(encSize)) | 1352 | static_cast<Q_ULONG>(encSize)) |
1353 | != static_cast<Q_LONG>(encSize)) { | 1353 | != static_cast<Q_LONG>(encSize)) { |
1354 | delete_ifnot_null_array(encrypted); | 1354 | delete_ifnot_null_array(encrypted); |
1355 | return e_writeFile; | 1355 | return e_writeFile; |
1356 | } | 1356 | } |
1357 | delete_ifnot_null_array(encrypted); | 1357 | delete_ifnot_null_array(encrypted); |
1358 | return e_success; | 1358 | return e_success; |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1361 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1362 | char algo, QFile *f) | 1362 | char algo, QFile *f) |
1363 | { | 1363 | { |
1364 | PWM_ASSERT(d); | 1364 | PWM_ASSERT(d); |
1365 | PWM_ASSERT(pw); | 1365 | PWM_ASSERT(pw); |
1366 | PWM_ASSERT(f); | 1366 | PWM_ASSERT(f); |
1367 | 1367 | ||
1368 | unsigned int cryptLen = f->size() - pos; | 1368 | unsigned int cryptLen = f->size() - pos; |
1369 | byte *encrypted = new byte[cryptLen]; | 1369 | byte *encrypted = new byte[cryptLen]; |
1370 | byte *decrypted = new byte[cryptLen]; | 1370 | byte *decrypted = new byte[cryptLen]; |
1371 | 1371 | ||
1372 | f->at(pos); | 1372 | f->at(pos); |
1373 | #ifndef PWM_EMBEDDED | 1373 | #ifndef PWM_EMBEDDED |
1374 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1374 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1375 | static_cast<Q_ULONG>(cryptLen)) | 1375 | static_cast<Q_ULONG>(cryptLen)) |
1376 | != static_cast<Q_LONG>(cryptLen)) { | 1376 | != static_cast<Q_LONG>(cryptLen)) { |
1377 | delete [] encrypted; | 1377 | delete [] encrypted; |
1378 | delete [] decrypted; | 1378 | delete [] decrypted; |
1379 | return e_readFile; | 1379 | return e_readFile; |
1380 | } | 1380 | } |
1381 | #else | 1381 | #else |
1382 | if (f->readBlock((char *)(encrypted), | 1382 | if (f->readBlock((char *)(encrypted), |
1383 | (unsigned long)(cryptLen)) | 1383 | (unsigned long)(cryptLen)) |
1384 | != (long)(cryptLen)) { | 1384 | != (long)(cryptLen)) { |
1385 | delete [] encrypted; | 1385 | delete [] encrypted; |
1386 | delete [] decrypted; | 1386 | delete [] decrypted; |
1387 | return e_readFile; | 1387 | return e_readFile; |
1388 | } | 1388 | } |
1389 | #endif | 1389 | #endif |
1390 | switch (algo) { | 1390 | switch (algo) { |
1391 | case PWM_CRYPT_BLOWFISH: { | 1391 | case PWM_CRYPT_BLOWFISH: { |
1392 | Blowfish bf; | 1392 | Blowfish bf; |
1393 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1393 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1394 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1394 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1395 | break; | 1395 | break; |
1396 | } | 1396 | } |
1397 | case PWM_CRYPT_AES128: | 1397 | case PWM_CRYPT_AES128: |
1398 | /*... fall through */ | 1398 | /*... fall through */ |
1399 | case PWM_CRYPT_AES192: | 1399 | case PWM_CRYPT_AES192: |
1400 | case PWM_CRYPT_AES256: | 1400 | case PWM_CRYPT_AES256: |
1401 | case PWM_CRYPT_3DES: | 1401 | case PWM_CRYPT_3DES: |
1402 | case PWM_CRYPT_TWOFISH: | 1402 | case PWM_CRYPT_TWOFISH: |
1403 | case PWM_CRYPT_TWOFISH128: { | 1403 | case PWM_CRYPT_TWOFISH128: { |
1404 | if (!LibGCryptIf::available()) | 1404 | if (!LibGCryptIf::available()) |
1405 | return e_cryptNotImpl; | 1405 | return e_cryptNotImpl; |
1406 | LibGCryptIf gc; | 1406 | LibGCryptIf gc; |
1407 | PwMerror err; | 1407 | PwMerror err; |
1408 | err = gc.decrypt(&decrypted, | 1408 | err = gc.decrypt(&decrypted, |
1409 | &cryptLen, | 1409 | &cryptLen, |
1410 | encrypted, | 1410 | encrypted, |
1411 | cryptLen, | 1411 | cryptLen, |
1412 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1412 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1413 | pw->length(), | 1413 | pw->length(), |
1414 | algo); | 1414 | algo); |
1415 | if (err != e_success) { | 1415 | if (err != e_success) { |
1416 | delete [] encrypted; | 1416 | delete [] encrypted; |
1417 | delete [] decrypted; | 1417 | delete [] decrypted; |
1418 | return e_cryptNotImpl; | 1418 | return e_cryptNotImpl; |
1419 | } | 1419 | } |
1420 | break; | 1420 | break; |
1421 | } | 1421 | } |
1422 | default: { | 1422 | default: { |
1423 | delete [] encrypted; | 1423 | delete [] encrypted; |
1424 | delete [] decrypted; | 1424 | delete [] decrypted; |
1425 | return e_cryptNotImpl; | 1425 | return e_cryptNotImpl; |
1426 | } } | 1426 | } } |
1427 | delete [] encrypted; | 1427 | delete [] encrypted; |
1428 | #ifndef PWM_EMBEDDED | 1428 | #ifndef PWM_EMBEDDED |
1429 | d->assign(reinterpret_cast<const char *>(decrypted), | 1429 | d->assign(reinterpret_cast<const char *>(decrypted), |
1430 | static_cast<string::size_type>(cryptLen)); | 1430 | static_cast<string::size_type>(cryptLen)); |
1431 | #else | 1431 | #else |
1432 | d->assign((const char *)(decrypted), | 1432 | d->assign((const char *)(decrypted), |
1433 | (string::size_type)(cryptLen)); | 1433 | (string::size_type)(cryptLen)); |
1434 | #endif | 1434 | #endif |
1435 | delete [] decrypted; | 1435 | delete [] decrypted; |
1436 | if (algo == PWM_CRYPT_BLOWFISH) { | 1436 | if (algo == PWM_CRYPT_BLOWFISH) { |
1437 | if (!Blowfish::unpadNull(d)) { | 1437 | if (!Blowfish::unpadNull(d)) { |
1438 | BUG(); | 1438 | BUG(); |
1439 | return e_readFile; | 1439 | return e_readFile; |
1440 | } | 1440 | } |
1441 | } | 1441 | } |
1442 | return e_success; | 1442 | return e_success; |
1443 | } | 1443 | } |
1444 | 1444 | ||
1445 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1445 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1446 | const string *dataStream) | 1446 | const string *dataStream) |
1447 | { | 1447 | { |
1448 | PWM_ASSERT(dataHash); | 1448 | PWM_ASSERT(dataHash); |
1449 | PWM_ASSERT(dataStream); | 1449 | PWM_ASSERT(dataStream); |
1450 | switch(dataHashType) { | 1450 | switch(dataHashType) { |
1451 | case PWM_HASH_SHA1: { | 1451 | case PWM_HASH_SHA1: { |
1452 | Sha1 hash; | 1452 | Sha1 hash; |
1453 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1453 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1454 | string ret = hash.sha1_read(); | 1454 | string ret = hash.sha1_read(); |
1455 | if (ret != *dataHash) | 1455 | if (ret != *dataHash) |
1456 | return e_fileCorrupt; | 1456 | return e_fileCorrupt; |
1457 | break; | 1457 | break; |
1458 | } | 1458 | } |
1459 | case PWM_HASH_SHA256: | 1459 | case PWM_HASH_SHA256: |
1460 | /*... fall through */ | 1460 | /*... fall through */ |
1461 | case PWM_HASH_SHA384: | 1461 | case PWM_HASH_SHA384: |
1462 | case PWM_HASH_SHA512: | 1462 | case PWM_HASH_SHA512: |
1463 | case PWM_HASH_MD5: | 1463 | case PWM_HASH_MD5: |
1464 | case PWM_HASH_RMD160: | 1464 | case PWM_HASH_RMD160: |
1465 | case PWM_HASH_TIGER: { | 1465 | case PWM_HASH_TIGER: { |
1466 | if (!LibGCryptIf::available()) | 1466 | if (!LibGCryptIf::available()) |
1467 | return e_hashNotImpl; | 1467 | return e_hashNotImpl; |
1468 | LibGCryptIf gc; | 1468 | LibGCryptIf gc; |
1469 | PwMerror err; | 1469 | PwMerror err; |
1470 | unsigned char *buf; | 1470 | unsigned char *buf; |
1471 | size_t hashLen; | 1471 | size_t hashLen; |
1472 | err = gc.hash(&buf, | 1472 | err = gc.hash(&buf, |
1473 | &hashLen, | 1473 | &hashLen, |
1474 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1474 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1475 | dataStream->length(), | 1475 | dataStream->length(), |
1476 | dataHashType); | 1476 | dataHashType); |
1477 | if (err != e_success) | 1477 | if (err != e_success) |
1478 | return e_hashNotImpl; | 1478 | return e_hashNotImpl; |
1479 | string calcHash(reinterpret_cast<const char *>(buf), | 1479 | string calcHash(reinterpret_cast<const char *>(buf), |
1480 | static_cast<string::size_type>(hashLen)); | 1480 | static_cast<string::size_type>(hashLen)); |
1481 | delete [] buf; | 1481 | delete [] buf; |
1482 | if (calcHash != *dataHash) | 1482 | if (calcHash != *dataHash) |
1483 | return e_fileCorrupt; | 1483 | return e_fileCorrupt; |
1484 | break; | 1484 | break; |
1485 | } | 1485 | } |
1486 | default: | 1486 | default: |
1487 | return e_hashNotImpl; | 1487 | return e_hashNotImpl; |
1488 | } | 1488 | } |
1489 | return e_success; | 1489 | return e_success; |
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1492 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1493 | bool lock) | 1493 | bool lock) |
1494 | { | 1494 | { |
1495 | if (index >= numEntries(category)) { | 1495 | if (index >= numEntries(category)) { |
1496 | BUG(); | 1496 | BUG(); |
1497 | return false; | 1497 | return false; |
1498 | } | 1498 | } |
1499 | if (lock == dti.dta[category].d[index].lockStat) | 1499 | if (lock == dti.dta[category].d[index].lockStat) |
1500 | return true; | 1500 | return true; |
1501 | 1501 | ||
1502 | if (!lock && currentPw != "") { | 1502 | if (!lock && currentPw != "") { |
1503 | // "unlocking" and "password is already set" | 1503 | // "unlocking" and "password is already set" |
1504 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1504 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1505 | // unlocking without pw not allowed | 1505 | // unlocking without pw not allowed |
1506 | QString pw; | 1506 | QString pw; |
1507 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1507 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1508 | if (pw != "") { | 1508 | if (pw != "") { |
1509 | if (pw != currentPw) { | 1509 | if (pw != currentPw) { |
1510 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1510 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1511 | return false; | 1511 | return false; |
1512 | } else { | 1512 | } else { |
1513 | timer()->start(DocTimer::id_mpwTimer); | 1513 | timer()->start(DocTimer::id_mpwTimer); |
1514 | } | 1514 | } |
1515 | } else { | 1515 | } else { |
1516 | return false; | 1516 | return false; |
1517 | } | 1517 | } |
1518 | } else { | 1518 | } else { |
1519 | timer()->start(DocTimer::id_mpwTimer); | 1519 | timer()->start(DocTimer::id_mpwTimer); |
1520 | } | 1520 | } |
1521 | } | 1521 | } |
1522 | 1522 | ||
1523 | dti.dta[category].d[index].lockStat = lock; | 1523 | dti.dta[category].d[index].lockStat = lock; |
1524 | dti.dta[category].d[index].rev++; // increment revision counter. | 1524 | dti.dta[category].d[index].rev++; // increment revision counter. |
1525 | 1525 | ||
1526 | emitDataChanged(this); | 1526 | emitDataChanged(this); |
1527 | if (!lock) | 1527 | if (!lock) |
1528 | timer()->start(DocTimer::id_autoLockTimer); | 1528 | timer()->start(DocTimer::id_autoLockTimer); |
1529 | 1529 | ||
1530 | return true; | 1530 | return true; |
1531 | 1531 | ||
1532 | } | 1532 | } |
1533 | 1533 | ||
1534 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1534 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1535 | bool lock) | 1535 | bool lock) |
1536 | { | 1536 | { |
1537 | unsigned int cat = 0; | 1537 | unsigned int cat = 0; |
1538 | 1538 | ||
1539 | if (!findCategory(category, &cat)) { | 1539 | if (!findCategory(category, &cat)) { |
1540 | BUG(); | 1540 | BUG(); |
1541 | return false; | 1541 | return false; |
1542 | } | 1542 | } |
1543 | 1543 | ||
1544 | return lockAt(cat, index, lock); | 1544 | return lockAt(cat, index, lock); |
1545 | } | 1545 | } |
1546 | 1546 | ||
1547 | bool PwMDoc::lockAll(bool lock) | 1547 | bool PwMDoc::lockAll(bool lock) |
1548 | { | 1548 | { |
1549 | if (!lock && isDeepLocked()) { | 1549 | if (!lock && isDeepLocked()) { |
1550 | PwMerror ret; | 1550 | PwMerror ret; |
1551 | ret = deepLock(false); | 1551 | ret = deepLock(false); |
1552 | if (ret != e_success) | 1552 | if (ret != e_success) |
1553 | return false; | 1553 | return false; |
1554 | return true; | 1554 | return true; |
1555 | } | 1555 | } |
1556 | if (isDocEmpty()) { | 1556 | if (isDocEmpty()) { |
1557 | return true; | 1557 | return true; |
1558 | } | 1558 | } |
1559 | if (!lock && currentPw != "") { | 1559 | if (!lock && currentPw != "") { |
1560 | // unlocking and password is already set | 1560 | // unlocking and password is already set |
1561 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1561 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1562 | // unlocking without pw not allowed | 1562 | // unlocking without pw not allowed |
1563 | QString pw; | 1563 | QString pw; |
1564 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1564 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1565 | if (pw != "") { | 1565 | if (pw != "") { |
1566 | if (pw != currentPw) { | 1566 | if (pw != currentPw) { |
1567 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1567 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1568 | return false; | 1568 | return false; |
1569 | } else { | 1569 | } else { |
1570 | timer()->start(DocTimer::id_mpwTimer); | 1570 | timer()->start(DocTimer::id_mpwTimer); |
1571 | } | 1571 | } |
1572 | } else { | 1572 | } else { |
1573 | return false; | 1573 | return false; |
1574 | } | 1574 | } |
1575 | } else { | 1575 | } else { |
1576 | timer()->start(DocTimer::id_mpwTimer); | 1576 | timer()->start(DocTimer::id_mpwTimer); |
1577 | } | 1577 | } |
1578 | } | 1578 | } |
1579 | 1579 | ||
1580 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1580 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1581 | catEnd = dti.dta.end(), | 1581 | catEnd = dti.dta.end(), |
1582 | catI = catBegin; | 1582 | catI = catBegin; |
1583 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1583 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1584 | while (catI != catEnd) { | 1584 | while (catI != catEnd) { |
1585 | entrBegin = catI->d.begin(); | 1585 | entrBegin = catI->d.begin(); |
1586 | entrEnd = catI->d.end(); | 1586 | entrEnd = catI->d.end(); |
1587 | entrI = entrBegin; | 1587 | entrI = entrBegin; |
1588 | while (entrI != entrEnd) { | 1588 | while (entrI != entrEnd) { |
1589 | entrI->lockStat = lock; | 1589 | entrI->lockStat = lock; |
1590 | entrI->rev++; // increment revision counter. | 1590 | entrI->rev++; // increment revision counter. |
1591 | ++entrI; | 1591 | ++entrI; |
1592 | } | 1592 | } |
1593 | ++catI; | 1593 | ++catI; |
1594 | } | 1594 | } |
1595 | 1595 | ||
1596 | emitDataChanged(this); | 1596 | emitDataChanged(this); |
1597 | if (lock) | 1597 | if (lock) |
1598 | timer()->stop(DocTimer::id_autoLockTimer); | 1598 | timer()->stop(DocTimer::id_autoLockTimer); |
1599 | else | 1599 | else |
1600 | timer()->start(DocTimer::id_autoLockTimer); | 1600 | timer()->start(DocTimer::id_autoLockTimer); |
1601 | 1601 | ||
1602 | return true; | 1602 | return true; |
1603 | } | 1603 | } |
1604 | 1604 | ||
1605 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1605 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1606 | { | 1606 | { |
1607 | unsigned int cat = 0; | 1607 | unsigned int cat = 0; |
1608 | 1608 | ||
1609 | if (!findCategory(category, &cat)) { | 1609 | if (!findCategory(category, &cat)) { |
1610 | BUG(); | 1610 | BUG(); |
1611 | return false; | 1611 | return false; |
1612 | } | 1612 | } |
1613 | 1613 | ||
1614 | return isLocked(cat, index); | 1614 | return isLocked(cat, index); |
1615 | } | 1615 | } |
1616 | 1616 | ||
1617 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1617 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1618 | { | 1618 | { |
1619 | static vector< vector<bool> > *oldLockStates = 0; | 1619 | static vector< vector<bool> > *oldLockStates = 0; |
1620 | static bool wasDeepLocked; | 1620 | static bool wasDeepLocked; |
1621 | 1621 | ||
1622 | if (revert) {// revert the unlocking | 1622 | if (revert) {// revert the unlocking |
1623 | if (oldLockStates) { | 1623 | if (oldLockStates) { |
1624 | /* we actually _have_ unlocked something, because | 1624 | /* we actually _have_ unlocked something, because |
1625 | * we have allocated space for the oldLockStates. | 1625 | * we have allocated space for the oldLockStates. |
1626 | * So, go on and revert them! | 1626 | * So, go on and revert them! |
1627 | */ | 1627 | */ |
1628 | if (wasDeepLocked) { | 1628 | if (wasDeepLocked) { |
1629 | PwMerror ret = deepLock(true); | 1629 | PwMerror ret = deepLock(true); |
1630 | if (ret == e_success) { | 1630 | if (ret == e_success) { |
1631 | /* deep-lock succeed. We are save. | 1631 | /* deep-lock succeed. We are save. |
1632 | * (but if it failed, just go on | 1632 | * (but if it failed, just go on |
1633 | * lock them normally) | 1633 | * lock them normally) |
1634 | */ | 1634 | */ |
1635 | delete_and_null(oldLockStates); | 1635 | delete_and_null(oldLockStates); |
1636 | timer()->start(DocTimer::id_autoLockTimer); | 1636 | timer()->start(DocTimer::id_autoLockTimer); |
1637 | printDebug("tempoary unlocking of dta " | 1637 | printDebug("tempoary unlocking of dta " |
1638 | "reverted by deep-locking."); | 1638 | "reverted by deep-locking."); |
1639 | return true; | 1639 | return true; |
1640 | } | 1640 | } |
1641 | printDebug("deep-lock failed while reverting! " | 1641 | printDebug("deep-lock failed while reverting! " |
1642 | "Falling back to normal-lock."); | 1642 | "Falling back to normal-lock."); |
1643 | } | 1643 | } |
1644 | if (unlikely(!wasDeepLocked && | 1644 | if (unlikely(!wasDeepLocked && |
1645 | numCategories() != oldLockStates->size())) { | 1645 | numCategories() != oldLockStates->size())) { |
1646 | /* DOH! We have modified "dta" while | 1646 | /* DOH! We have modified "dta" while |
1647 | * it was unlocked tempoary. DON'T DO THIS! | 1647 | * it was unlocked tempoary. DON'T DO THIS! |
1648 | */ | 1648 | */ |
1649 | BUG(); | 1649 | BUG(); |
1650 | delete_and_null(oldLockStates); | 1650 | delete_and_null(oldLockStates); |
1651 | timer()->start(DocTimer::id_autoLockTimer); | 1651 | timer()->start(DocTimer::id_autoLockTimer); |
1652 | return false; | 1652 | return false; |
1653 | } | 1653 | } |
1654 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1654 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1655 | catEnd = dti.dta.end(), | 1655 | catEnd = dti.dta.end(), |
1656 | catI = catBegin; | 1656 | catI = catBegin; |
1657 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1657 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1658 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1658 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1659 | vector<bool>::iterator oldEntrStatBegin, | 1659 | vector<bool>::iterator oldEntrStatBegin, |
1660 | oldEntrStatEnd, | 1660 | oldEntrStatEnd, |
1661 | oldEntrStatI; | 1661 | oldEntrStatI; |
1662 | while (catI != catEnd) { | 1662 | while (catI != catEnd) { |
1663 | entrBegin = catI->d.begin(); | 1663 | entrBegin = catI->d.begin(); |
1664 | entrEnd = catI->d.end(); | 1664 | entrEnd = catI->d.end(); |
1665 | entrI = entrBegin; | 1665 | entrI = entrBegin; |
1666 | if (likely(!wasDeepLocked)) { | 1666 | if (likely(!wasDeepLocked)) { |
1667 | oldEntrStatBegin = oldCatStatI->begin(); | 1667 | oldEntrStatBegin = oldCatStatI->begin(); |
1668 | oldEntrStatEnd = oldCatStatI->end(); | 1668 | oldEntrStatEnd = oldCatStatI->end(); |
1669 | oldEntrStatI = oldEntrStatBegin; | 1669 | oldEntrStatI = oldEntrStatBegin; |
1670 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1670 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1671 | /* DOH! We have modified "dta" while | 1671 | /* DOH! We have modified "dta" while |
1672 | * it was unlocked tempoary. DON'T DO THIS! | 1672 | * it was unlocked tempoary. DON'T DO THIS! |
1673 | */ | 1673 | */ |
1674 | BUG(); | 1674 | BUG(); |
1675 | delete_and_null(oldLockStates); | 1675 | delete_and_null(oldLockStates); |
1676 | timer()->start(DocTimer::id_autoLockTimer); | 1676 | timer()->start(DocTimer::id_autoLockTimer); |
1677 | return false; | 1677 | return false; |
1678 | } | 1678 | } |
1679 | } | 1679 | } |
1680 | while (entrI != entrEnd) { | 1680 | while (entrI != entrEnd) { |
1681 | if (wasDeepLocked) { | 1681 | if (wasDeepLocked) { |
1682 | /* this is an error-fallback if | 1682 | /* this is an error-fallback if |
1683 | * deeplock didn't succeed | 1683 | * deeplock didn't succeed |
1684 | */ | 1684 | */ |
1685 | entrI->lockStat = true; | 1685 | entrI->lockStat = true; |
1686 | } else { | 1686 | } else { |
1687 | entrI->lockStat = *oldEntrStatI; | 1687 | entrI->lockStat = *oldEntrStatI; |
1688 | } | 1688 | } |
1689 | ++entrI; | 1689 | ++entrI; |
1690 | if (likely(!wasDeepLocked)) | 1690 | if (likely(!wasDeepLocked)) |
1691 | ++oldEntrStatI; | 1691 | ++oldEntrStatI; |
1692 | } | 1692 | } |
1693 | ++catI; | 1693 | ++catI; |
1694 | if (likely(!wasDeepLocked)) | 1694 | if (likely(!wasDeepLocked)) |
1695 | ++oldCatStatI; | 1695 | ++oldCatStatI; |
1696 | } | 1696 | } |
1697 | delete_and_null(oldLockStates); | 1697 | delete_and_null(oldLockStates); |
1698 | if (unlikely(wasDeepLocked)) { | 1698 | if (unlikely(wasDeepLocked)) { |
1699 | /* error fallback... */ | 1699 | /* error fallback... */ |
1700 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1700 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1701 | emitDataChanged(this); | 1701 | emitDataChanged(this); |
1702 | printDebug("WARNING: unlockAll_tempoary(true) " | 1702 | printDebug("WARNING: unlockAll_tempoary(true) " |
1703 | "deeplock fallback!"); | 1703 | "deeplock fallback!"); |
1704 | } | 1704 | } |
1705 | printDebug("tempoary unlocking of dta reverted."); | 1705 | printDebug("tempoary unlocking of dta reverted."); |
1706 | } else { | 1706 | } else { |
1707 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1707 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1708 | } | 1708 | } |
1709 | timer()->start(DocTimer::id_autoLockTimer); | 1709 | timer()->start(DocTimer::id_autoLockTimer); |
1710 | } else {// unlock all data tempoary | 1710 | } else {// unlock all data tempoary |
1711 | if (unlikely(oldLockStates != 0)) { | 1711 | if (unlikely(oldLockStates != 0)) { |
1712 | /* DOH! We have already unlocked the data tempoarly. | 1712 | /* DOH! We have already unlocked the data tempoarly. |
1713 | * No need to do it twice. ;) | 1713 | * No need to do it twice. ;) |
1714 | */ | 1714 | */ |
1715 | BUG(); | 1715 | BUG(); |
1716 | return false; | 1716 | return false; |
1717 | } | 1717 | } |
1718 | wasDeepLocked = false; | 1718 | wasDeepLocked = false; |
1719 | bool mustUnlock = false; | 1719 | bool mustUnlock = false; |
1720 | if (isDeepLocked()) { | 1720 | if (isDeepLocked()) { |
1721 | PwMerror ret; | 1721 | PwMerror ret; |
1722 | while (1) { | 1722 | while (1) { |
1723 | ret = deepLock(false); | 1723 | ret = deepLock(false); |
1724 | if (ret == e_success) { | 1724 | if (ret == e_success) { |
1725 | break; | 1725 | break; |
1726 | } else if (ret == e_wrongPw) { | 1726 | } else if (ret == e_wrongPw) { |
1727 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1727 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1728 | } else { | 1728 | } else { |
1729 | printDebug("deep-unlocking failed while " | 1729 | printDebug("deep-unlocking failed while " |
1730 | "tempoary unlocking!"); | 1730 | "tempoary unlocking!"); |
1731 | return false; | 1731 | return false; |
1732 | } | 1732 | } |
1733 | } | 1733 | } |
1734 | wasDeepLocked = true; | 1734 | wasDeepLocked = true; |
1735 | mustUnlock = true; | 1735 | mustUnlock = true; |
1736 | } else { | 1736 | } else { |
1737 | // first check if it's needed to unlock some entries | 1737 | // first check if it's needed to unlock some entries |
1738 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1738 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1739 | catEnd = dti.dta.end(), | 1739 | catEnd = dti.dta.end(), |
1740 | catI = catBegin; | 1740 | catI = catBegin; |
1741 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1741 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1742 | while (catI != catEnd) { | 1742 | while (catI != catEnd) { |
1743 | entrBegin = catI->d.begin(); | 1743 | entrBegin = catI->d.begin(); |
1744 | entrEnd = catI->d.end(); | 1744 | entrEnd = catI->d.end(); |
1745 | entrI = entrBegin; | 1745 | entrI = entrBegin; |
1746 | while (entrI != entrEnd) { | 1746 | while (entrI != entrEnd) { |
1747 | if (entrI->lockStat == true) { | 1747 | if (entrI->lockStat == true) { |
1748 | mustUnlock = true; | 1748 | mustUnlock = true; |
1749 | break; | 1749 | break; |
1750 | } | 1750 | } |
1751 | ++entrI; | 1751 | ++entrI; |
1752 | } | 1752 | } |
1753 | if (mustUnlock) | 1753 | if (mustUnlock) |
1754 | break; | 1754 | break; |
1755 | ++catI; | 1755 | ++catI; |
1756 | } | 1756 | } |
1757 | } | 1757 | } |
1758 | if (!mustUnlock) { | 1758 | if (!mustUnlock) { |
1759 | // nothing to do. | 1759 | // nothing to do. |
1760 | timer()->stop(DocTimer::id_autoLockTimer); | 1760 | timer()->stop(DocTimer::id_autoLockTimer); |
1761 | printDebug("unlockAll_tempoary(): nothing to do."); | 1761 | printDebug("unlockAll_tempoary(): nothing to do."); |
1762 | return true; | 1762 | return true; |
1763 | } else if (!wasDeepLocked) { | 1763 | } else if (!wasDeepLocked) { |
1764 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1764 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1765 | currentPw != "") { | 1765 | currentPw != "") { |
1766 | /* we can't unlock without mpw, so | 1766 | /* we can't unlock without mpw, so |
1767 | * we need to ask for it. | 1767 | * we need to ask for it. |
1768 | */ | 1768 | */ |
1769 | QString pw; | 1769 | QString pw; |
1770 | while (1) { | 1770 | while (1) { |
1771 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1771 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1772 | if (pw == "") { | 1772 | if (pw == "") { |
1773 | return false; | 1773 | return false; |
1774 | } else if (pw == currentPw) { | 1774 | } else if (pw == currentPw) { |
1775 | break; | 1775 | break; |
1776 | } | 1776 | } |
1777 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1777 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1778 | } | 1778 | } |
1779 | } | 1779 | } |
1780 | } | 1780 | } |
1781 | timer()->stop(DocTimer::id_autoLockTimer); | 1781 | timer()->stop(DocTimer::id_autoLockTimer); |
1782 | oldLockStates = new vector< vector<bool> >; | 1782 | oldLockStates = new vector< vector<bool> >; |
1783 | vector<bool> tmp_vec; | 1783 | vector<bool> tmp_vec; |
1784 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1784 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1785 | catEnd = dti.dta.end(), | 1785 | catEnd = dti.dta.end(), |
1786 | catI = catBegin; | 1786 | catI = catBegin; |
1787 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1787 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1788 | while (catI != catEnd) { | 1788 | while (catI != catEnd) { |
1789 | entrBegin = catI->d.begin(); | 1789 | entrBegin = catI->d.begin(); |
1790 | entrEnd = catI->d.end(); | 1790 | entrEnd = catI->d.end(); |
1791 | entrI = entrBegin; | 1791 | entrI = entrBegin; |
1792 | while (entrI != entrEnd) { | 1792 | while (entrI != entrEnd) { |
1793 | if (!wasDeepLocked) { | 1793 | if (!wasDeepLocked) { |
1794 | tmp_vec.push_back(entrI->lockStat); | 1794 | tmp_vec.push_back(entrI->lockStat); |
1795 | } | 1795 | } |
1796 | entrI->lockStat = false; | 1796 | entrI->lockStat = false; |
1797 | ++entrI; | 1797 | ++entrI; |
1798 | } | 1798 | } |
1799 | if (!wasDeepLocked) { | 1799 | if (!wasDeepLocked) { |
1800 | oldLockStates->push_back(tmp_vec); | 1800 | oldLockStates->push_back(tmp_vec); |
1801 | tmp_vec.clear(); | 1801 | tmp_vec.clear(); |
1802 | } | 1802 | } |
1803 | ++catI; | 1803 | ++catI; |
1804 | } | 1804 | } |
1805 | printDebug("tempoary unlocked dta."); | 1805 | printDebug("tempoary unlocked dta."); |
1806 | } | 1806 | } |
1807 | 1807 | ||
1808 | return true; | 1808 | return true; |
1809 | } | 1809 | } |
1810 | 1810 | ||
1811 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1811 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1812 | { | 1812 | { |
1813 | PwMerror ret; | 1813 | PwMerror ret; |
1814 | /* NOTE: saveDoc() depends on this function to return | 1814 | /* NOTE: saveDoc() depends on this function to return |
1815 | * e_success if saveToFile == false | 1815 | * e_success if saveToFile == false |
1816 | */ | 1816 | */ |
1817 | 1817 | ||
1818 | if (lock) { | 1818 | if (lock) { |
1819 | if (isDeepLocked()) | 1819 | if (isDeepLocked()) |
1820 | return e_lock; | 1820 | return e_lock; |
1821 | if (saveToFile) { | 1821 | if (saveToFile) { |
1822 | if (isDocEmpty()) | 1822 | if (isDocEmpty()) |
1823 | return e_docIsEmpty; | 1823 | return e_docIsEmpty; |
1824 | ret = saveDoc(conf()->confGlobCompression()); | 1824 | ret = saveDoc(conf()->confGlobCompression()); |
1825 | if (ret == e_filename) { | 1825 | if (ret == e_filename) { |
1826 | /* the doc wasn't saved to a file | 1826 | /* the doc wasn't saved to a file |
1827 | * by the user, yet. | 1827 | * by the user, yet. |
1828 | */ | 1828 | */ |
1829 | cantDeeplock_notSavedMsgBox(); | 1829 | cantDeeplock_notSavedMsgBox(); |
1830 | return e_docNotSaved; | 1830 | return e_docNotSaved; |
1831 | } else if (ret != e_success) { | 1831 | } else if (ret != e_success) { |
1832 | return e_lock; | 1832 | return e_lock; |
1833 | } | 1833 | } |
1834 | } | 1834 | } |
1835 | timer()->stop(DocTimer::id_autoLockTimer); | 1835 | timer()->stop(DocTimer::id_autoLockTimer); |
1836 | clearDoc(); | 1836 | clearDoc(); |
1837 | PwMDataItem d; | 1837 | PwMDataItem d; |
1838 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1838 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1839 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1839 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1840 | d.listViewPos = 0; | 1840 | d.listViewPos = 0; |
1841 | addEntry(DEFAULT_CATEGORY, &d, true); | 1841 | addEntry(DEFAULT_CATEGORY, &d, true); |
1842 | lockAt(DEFAULT_CATEGORY, 0, true); | 1842 | lockAt(DEFAULT_CATEGORY, 0, true); |
1843 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1843 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1844 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1844 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1845 | } else { | 1845 | } else { |
1846 | if (!isDeepLocked()) | 1846 | if (!isDeepLocked()) |
1847 | return e_lock; | 1847 | return e_lock; |
1848 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1848 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1849 | ? 0 : 1); | 1849 | ? 0 : 1); |
1850 | if (ret == e_wrongPw) { | 1850 | if (ret == e_wrongPw) { |
1851 | return e_wrongPw; | 1851 | return e_wrongPw; |
1852 | } else if (ret != e_success) { | 1852 | } else if (ret != e_success) { |
1853 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1853 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1854 | + tostr(static_cast<int>(ret))); | 1854 | + tostr(static_cast<int>(ret))); |
1855 | return e_lock; | 1855 | return e_lock; |
1856 | } | 1856 | } |
1857 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1857 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1858 | timer()->start(DocTimer::id_autoLockTimer); | 1858 | timer()->start(DocTimer::id_autoLockTimer); |
1859 | } | 1859 | } |
1860 | 1860 | ||
1861 | emitDataChanged(this); | 1861 | emitDataChanged(this); |
1862 | return e_success; | 1862 | return e_success; |
1863 | } | 1863 | } |
1864 | 1864 | ||
1865 | void PwMDoc::_deepUnlock() | 1865 | void PwMDoc::_deepUnlock() |
1866 | { | 1866 | { |
1867 | deepLock(false); | 1867 | deepLock(false); |
1868 | } | 1868 | } |
1869 | 1869 | ||
1870 | void PwMDoc::clearDoc() | 1870 | void PwMDoc::clearDoc() |
1871 | { | 1871 | { |
1872 | dti.clear(); | 1872 | dti.clear(); |
1873 | PwMCategoryItem d; | 1873 | PwMCategoryItem d; |
1874 | d.name = DEFAULT_CATEGORY.latin1(); | 1874 | d.name = DEFAULT_CATEGORY.latin1(); |
1875 | dti.dta.push_back(d); | 1875 | dti.dta.push_back(d); |
1876 | currentPw = ""; | 1876 | currentPw = ""; |
1877 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1877 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1878 | } | 1878 | } |
1879 | 1879 | ||
1880 | void PwMDoc::changeCurrentPw() | 1880 | void PwMDoc::changeCurrentPw() |
1881 | { | 1881 | { |
1882 | if (currentPw == "") | 1882 | if (currentPw == "") |
1883 | return; // doc hasn't been saved. No mpw available. | 1883 | return; // doc hasn't been saved. No mpw available. |
1884 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1884 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1885 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1885 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1886 | if (pw == "") | 1886 | if (pw == "") |
1887 | return; | 1887 | return; |
1888 | if (useChipcard) | 1888 | if (useChipcard) |
1889 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1889 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1890 | else | 1890 | else |
1891 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1891 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1892 | setCurrentPw(pw); | 1892 | setCurrentPw(pw); |
1893 | } | 1893 | } |
1894 | 1894 | ||
1895 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1895 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1896 | int pos) | 1896 | int pos) |
1897 | { | 1897 | { |
1898 | unsigned int cat = 0; | 1898 | unsigned int cat = 0; |
1899 | 1899 | ||
1900 | if (!findCategory(category, &cat)) { | 1900 | if (!findCategory(category, &cat)) { |
1901 | BUG(); | 1901 | BUG(); |
1902 | return; | 1902 | return; |
1903 | } | 1903 | } |
1904 | setListViewPos(cat, index, pos); | 1904 | setListViewPos(cat, index, pos); |
1905 | } | 1905 | } |
1906 | 1906 | ||
1907 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1907 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1908 | int pos) | 1908 | int pos) |
1909 | { | 1909 | { |
1910 | dti.dta[category].d[index].listViewPos = pos; | 1910 | dti.dta[category].d[index].listViewPos = pos; |
1911 | 1911 | ||
1912 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1912 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1913 | * get's called when it shouldn't. It's because PwMView assumes | 1913 | * get's called when it shouldn't. It's because PwMView assumes |
1914 | * the user resorted the UI on behalf of signal layoutChanged(). | 1914 | * the user resorted the UI on behalf of signal layoutChanged(). |
1915 | * This is somewhat broken and incorrect, but I've no other | 1915 | * This is somewhat broken and incorrect, but I've no other |
1916 | * solution for now. | 1916 | * solution for now. |
1917 | */ | 1917 | */ |
1918 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1918 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1919 | } | 1919 | } |
1920 | 1920 | ||
1921 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1921 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1922 | { | 1922 | { |
1923 | unsigned int cat = 0; | 1923 | unsigned int cat = 0; |
1924 | 1924 | ||
1925 | if (!findCategory(category, &cat)) { | 1925 | if (!findCategory(category, &cat)) { |
1926 | BUG(); | 1926 | BUG(); |
1927 | return -1; | 1927 | return -1; |
1928 | } | 1928 | } |
1929 | 1929 | ||
1930 | return dti.dta[cat].d[index].listViewPos; | 1930 | return dti.dta[cat].d[index].listViewPos; |
1931 | } | 1931 | } |
1932 | 1932 | ||
1933 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1933 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1934 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1934 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1935 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1935 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1936 | { | 1936 | { |
1937 | PWM_ASSERT(foundPositions); | 1937 | PWM_ASSERT(foundPositions); |
1938 | PWM_ASSERT(searchIn); | 1938 | PWM_ASSERT(searchIn); |
1939 | foundPositions->clear(); | 1939 | foundPositions->clear(); |
1940 | 1940 | ||
1941 | unsigned int i, entries = numEntries(category); | 1941 | unsigned int i, entries = numEntries(category); |
1942 | for (i = 0; i < entries; ++i) { | 1942 | for (i = 0; i < entries; ++i) { |
1943 | if (searchIn & SEARCH_IN_DESC) { | 1943 | if (searchIn & SEARCH_IN_DESC) { |
1944 | if (!compareString(find.desc, dti.dta[category].d[i].desc, | 1944 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1945 | caseSensitive, exactWordMatch)) { | 1945 | caseSensitive, exactWordMatch)) { |
1946 | continue; | 1946 | continue; |
1947 | } | 1947 | } |
1948 | } | 1948 | } |
1949 | if (searchIn & SEARCH_IN_NAME) { | 1949 | if (searchIn & SEARCH_IN_NAME) { |
1950 | if (!compareString(find.name, dti.dta[category].d[i].name, | 1950 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1951 | caseSensitive, exactWordMatch)) { | 1951 | caseSensitive, exactWordMatch)) { |
1952 | continue; | 1952 | continue; |
1953 | } | 1953 | } |
1954 | } | 1954 | } |
1955 | if (searchIn & SEARCH_IN_PW) { | 1955 | if (searchIn & SEARCH_IN_PW) { |
1956 | bool wasLocked = isLocked(category, i); | 1956 | bool wasLocked = isLocked(category, i); |
1957 | getDataChangedLock(); | 1957 | getDataChangedLock(); |
1958 | lockAt(category, i, false); | 1958 | lockAt(category, i, false); |
1959 | if (!compareString(find.pw, dti.dta[category].d[i].pw, | 1959 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1960 | caseSensitive, exactWordMatch)) { | 1960 | caseSensitive, exactWordMatch)) { |
1961 | lockAt(category, i, wasLocked); | 1961 | lockAt(category, i, wasLocked); |
1962 | putDataChangedLock(); | 1962 | putDataChangedLock(); |
1963 | continue; | 1963 | continue; |
1964 | } | 1964 | } |
1965 | lockAt(category, i, wasLocked); | 1965 | lockAt(category, i, wasLocked); |
1966 | putDataChangedLock(); | 1966 | putDataChangedLock(); |
1967 | } | 1967 | } |
1968 | if (searchIn & SEARCH_IN_COMMENT) { | 1968 | if (searchIn & SEARCH_IN_COMMENT) { |
1969 | if (!compareString(find.comment, dti.dta[category].d[i].comment, | 1969 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1970 | caseSensitive, exactWordMatch)) { | 1970 | caseSensitive, exactWordMatch)) { |
1971 | continue; | 1971 | continue; |
1972 | } | 1972 | } |
1973 | } | 1973 | } |
1974 | if (searchIn & SEARCH_IN_URL) { | 1974 | if (searchIn & SEARCH_IN_URL) { |
1975 | if (!compareString(find.url, dti.dta[category].d[i].url, | 1975 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1976 | caseSensitive, exactWordMatch)) { | 1976 | caseSensitive, exactWordMatch)) { |
1977 | continue; | 1977 | continue; |
1978 | } | 1978 | } |
1979 | } | 1979 | } |
1980 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1980 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1981 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, | 1981 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1982 | caseSensitive, exactWordMatch)) { | 1982 | caseSensitive, exactWordMatch)) { |
1983 | continue; | 1983 | continue; |
1984 | } | 1984 | } |
1985 | } | 1985 | } |
1986 | 1986 | ||
1987 | // all selected "searchIn" matched. | 1987 | // all selected "searchIn" matched. |
1988 | foundPositions->push_back(i); | 1988 | foundPositions->push_back(i); |
1989 | if (breakAfterFound) | 1989 | if (breakAfterFound) |
1990 | break; | 1990 | break; |
1991 | } | 1991 | } |
1992 | 1992 | ||
1993 | if (sortByLvp && foundPositions->size() > 1) { | 1993 | if (sortByLvp && foundPositions->size() > 1) { |
1994 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 1994 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
1995 | unsigned int /* lvp-pos */> > tmp_vec; | 1995 | unsigned int /* lvp-pos */> > tmp_vec; |
1996 | 1996 | ||
1997 | unsigned int i, items = foundPositions->size(); | 1997 | unsigned int i, items = foundPositions->size(); |
1998 | pair<unsigned int, unsigned int> tmp_pair; | 1998 | pair<unsigned int, unsigned int> tmp_pair; |
1999 | for (i = 0; i < items; ++i) { | 1999 | for (i = 0; i < items; ++i) { |
2000 | tmp_pair.first = (*foundPositions)[i]; | 2000 | tmp_pair.first = (*foundPositions)[i]; |
2001 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; | 2001 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
2002 | tmp_vec.push_back(tmp_pair); | 2002 | tmp_vec.push_back(tmp_pair); |
2003 | } | 2003 | } |
2004 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 2004 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
2005 | foundPositions->clear(); | 2005 | foundPositions->clear(); |
2006 | for (i = 0; i < items; ++i) { | 2006 | for (i = 0; i < items; ++i) { |
2007 | foundPositions->push_back(tmp_vec[i].first); | 2007 | foundPositions->push_back(tmp_vec[i].first); |
2008 | } | 2008 | } |
2009 | } | 2009 | } |
2010 | } | 2010 | } |
2011 | 2011 | ||
2012 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2012 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2013 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2013 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2014 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2014 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2015 | { | 2015 | { |
2016 | PWM_ASSERT(foundPositions); | 2016 | PWM_ASSERT(foundPositions); |
2017 | unsigned int cat = 0; | 2017 | unsigned int cat = 0; |
2018 | 2018 | ||
2019 | if (!findCategory(category, &cat)) { | 2019 | if (!findCategory(category, &cat)) { |
2020 | foundPositions->clear(); | 2020 | foundPositions->clear(); |
2021 | return; | 2021 | return; |
2022 | } | 2022 | } |
2023 | 2023 | ||
2024 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2024 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2025 | caseSensitive, exactWordMatch, sortByLvp); | 2025 | caseSensitive, exactWordMatch, sortByLvp); |
2026 | } | 2026 | } |
2027 | 2027 | ||
2028 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2028 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2029 | bool exactWordMatch) | 2029 | bool exactWordMatch) |
2030 | { | 2030 | { |
2031 | QString _s1(s1.c_str()); | 2031 | QString _s1(s1.c_str()); |
2032 | QString _s2(s2.c_str()); | 2032 | QString _s2(s2.c_str()); |
2033 | if (!caseSensitive) { | 2033 | if (!caseSensitive) { |
2034 | _s1 = _s1.lower(); | 2034 | _s1 = _s1.lower(); |
2035 | _s2 = _s2.lower(); | 2035 | _s2 = _s2.lower(); |
2036 | } | 2036 | } |
2037 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2037 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2038 | return true; | 2038 | return true; |
2039 | return false; | 2039 | return false; |
2040 | } | 2040 | } |
2041 | 2041 | ||
2042 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2042 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2043 | { | 2043 | { |
2044 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2044 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2045 | end = dti.dta.end(); | 2045 | end = dti.dta.end(); |
2046 | while (i != end) { | 2046 | while (i != end) { |
2047 | if ((*i).name == name.latin1()) { | 2047 | if ((*i).name == name.latin1()) { |
2048 | if (index) { | 2048 | if (index) { |
2049 | *index = i - dti.dta.begin(); | 2049 | *index = i - dti.dta.begin(); |
2050 | } | 2050 | } |
2051 | return true; | 2051 | return true; |
2052 | } | 2052 | } |
2053 | ++i; | 2053 | ++i; |
2054 | } | 2054 | } |
2055 | return false; | 2055 | return false; |
2056 | } | 2056 | } |
2057 | 2057 | ||
2058 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2058 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2059 | { | 2059 | { |
2060 | unsigned int cat = 0; | 2060 | unsigned int cat = 0; |
2061 | 2061 | ||
2062 | if (!findCategory(category, &cat)) | 2062 | if (!findCategory(category, &cat)) |
2063 | return false; | 2063 | return false; |
2064 | 2064 | ||
2065 | return renameCategory(cat, newName); | 2065 | return renameCategory(cat, newName); |
2066 | } | 2066 | } |
2067 | 2067 | ||
2068 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2068 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2069 | bool dontFlagDirty) | 2069 | bool dontFlagDirty) |
2070 | { | 2070 | { |
2071 | if (category > numCategories() - 1) | 2071 | if (category > numCategories() - 1) |
2072 | return false; | 2072 | return false; |
2073 | 2073 | ||
2074 | dti.dta[category].name = newName.latin1(); | 2074 | dti.dta[category].name = newName.latin1(); |
2075 | if (!dontFlagDirty) | 2075 | if (!dontFlagDirty) |
2076 | flagDirty(); | 2076 | flagDirty(); |
2077 | 2077 | ||
2078 | return true; | 2078 | return true; |
2079 | } | 2079 | } |
2080 | 2080 | ||
2081 | bool PwMDoc::delCategory(const QString &category) | 2081 | bool PwMDoc::delCategory(const QString &category) |
2082 | { | 2082 | { |
2083 | unsigned int cat = 0; | 2083 | unsigned int cat = 0; |
2084 | 2084 | ||
2085 | if (!findCategory(category, &cat)) | 2085 | if (!findCategory(category, &cat)) |
2086 | return false; | 2086 | return false; |
2087 | 2087 | ||
2088 | return delCategory(cat); | 2088 | return delCategory(cat); |
2089 | } | 2089 | } |
2090 | 2090 | ||
2091 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2091 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2092 | { | 2092 | { |
2093 | if (category > numCategories() - 1) | 2093 | if (category > numCategories() - 1) |
2094 | return false; | 2094 | return false; |
2095 | 2095 | ||
2096 | // We don't delete it, if it is the last existing | 2096 | // We don't delete it, if it is the last existing |
2097 | // category! Instead we rename it to "Default". | 2097 | // category! Instead we rename it to "Default". |
2098 | if (numCategories() > 1) { | 2098 | if (numCategories() > 1) { |
2099 | dti.dta.erase(dti.dta.begin() + category); | 2099 | dti.dta.erase(dti.dta.begin() + category); |
2100 | } else { | 2100 | } else { |
2101 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2101 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2102 | return true; | 2102 | return true; |
2103 | } | 2103 | } |
2104 | if (!dontFlagDirty) | 2104 | if (!dontFlagDirty) |
2105 | flagDirty(); | 2105 | flagDirty(); |
2106 | 2106 | ||
2107 | return true; | 2107 | return true; |
2108 | } | 2108 | } |
2109 | 2109 | ||
2110 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2110 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2111 | { | 2111 | { |
2112 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), | 2112 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2113 | end = dti.dta.end(), | 2113 | end = dti.dta.end(), |
2114 | i = begin; | 2114 | i = begin; |
2115 | while (i != end) { | 2115 | while (i != end) { |
2116 | if (i->d.empty()) { | 2116 | if (i->d.empty()) { |
2117 | delCategory(begin - i, dontFlagDirty); | 2117 | delCategory(begin - i, dontFlagDirty); |
2118 | } | 2118 | } |
2119 | ++i; | 2119 | ++i; |
2120 | } | 2120 | } |
2121 | } | 2121 | } |
2122 | 2122 | ||
2123 | void PwMDoc::getCategoryList(vector<string> *list) | 2123 | void PwMDoc::getCategoryList(vector<string> *list) |
2124 | { | 2124 | { |
2125 | PWM_ASSERT(list); | 2125 | PWM_ASSERT(list); |
2126 | list->clear(); | 2126 | list->clear(); |
2127 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2127 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2128 | end = dti.dta.end(); | 2128 | end = dti.dta.end(); |
2129 | while (i != end) { | 2129 | while (i != end) { |
2130 | list->push_back(i->name); | 2130 | list->push_back(i->name); |
2131 | ++i; | 2131 | ++i; |
2132 | } | 2132 | } |
2133 | } | 2133 | } |
2134 | 2134 | ||
2135 | void PwMDoc::getCategoryList(QStringList *list) | 2135 | void PwMDoc::getCategoryList(QStringList *list) |
2136 | { | 2136 | { |
2137 | PWM_ASSERT(list); | 2137 | PWM_ASSERT(list); |
2138 | list->clear(); | 2138 | list->clear(); |
2139 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2139 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2140 | end = dti.dta.end(); | 2140 | end = dti.dta.end(); |
2141 | while (i != end) { | 2141 | while (i != end) { |
2142 | #ifndef PWM_EMBEDDED | 2142 | #ifndef PWM_EMBEDDED |
2143 | list->push_back(i->name.c_str()); | 2143 | list->push_back(i->name.c_str()); |
2144 | #else | 2144 | #else |
2145 | list->append(i->name.c_str()); | 2145 | list->append(i->name.c_str()); |
2146 | #endif | 2146 | #endif |
2147 | ++i; | 2147 | ++i; |
2148 | } | 2148 | } |
2149 | } | 2149 | } |
2150 | 2150 | ||
2151 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2151 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2152 | { | 2152 | { |
2153 | PWM_ASSERT(list); | 2153 | PWM_ASSERT(list); |
2154 | unsigned int cat = 0; | 2154 | unsigned int cat = 0; |
2155 | if (!findCategory(category, &cat)) { | 2155 | if (!findCategory(category, &cat)) { |
2156 | list->clear(); | 2156 | list->clear(); |
2157 | return; | 2157 | return; |
2158 | } | 2158 | } |
2159 | getEntryList(cat, list); | 2159 | getEntryList(cat, list); |
2160 | } | 2160 | } |
2161 | 2161 | ||
2162 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2162 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2163 | { | 2163 | { |
2164 | PWM_ASSERT(list); | 2164 | PWM_ASSERT(list); |
2165 | unsigned int cat = 0; | 2165 | unsigned int cat = 0; |
2166 | if (!findCategory(category, &cat)) { | 2166 | if (!findCategory(category, &cat)) { |
2167 | list->clear(); | 2167 | list->clear(); |
2168 | return; | 2168 | return; |
2169 | } | 2169 | } |
2170 | getEntryList(cat, list); | 2170 | getEntryList(cat, list); |
2171 | } | 2171 | } |
2172 | 2172 | ||
2173 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2173 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2174 | { | 2174 | { |
2175 | PWM_ASSERT(list); | 2175 | PWM_ASSERT(list); |
2176 | list->clear(); | 2176 | list->clear(); |
2177 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2177 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2178 | end = dti.dta[category].d.end(), | 2178 | end = dti.dta[category].d.end(), |
2179 | i = begin; | 2179 | i = begin; |
2180 | while (i != end) { | 2180 | while (i != end) { |
2181 | list->push_back(i->desc); | 2181 | list->push_back(i->desc); |
2182 | ++i; | 2182 | ++i; |
2183 | } | 2183 | } |
2184 | } | 2184 | } |
2185 | 2185 | ||
2186 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2186 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2187 | { | 2187 | { |
2188 | PWM_ASSERT(list); | 2188 | PWM_ASSERT(list); |
2189 | list->clear(); | 2189 | list->clear(); |
2190 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2190 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2191 | end = dti.dta[category].d.end(), | 2191 | end = dti.dta[category].d.end(), |
2192 | i = begin; | 2192 | i = begin; |
2193 | while (i != end) { | 2193 | while (i != end) { |
2194 | #ifndef PWM_EMBEDDED | 2194 | #ifndef PWM_EMBEDDED |
2195 | list->push_back(i->desc.c_str()); | 2195 | list->push_back(i->desc.c_str()); |
2196 | #else | 2196 | #else |
2197 | list->append(i->desc.c_str()); | 2197 | list->append(i->desc.c_str()); |
2198 | #endif | 2198 | #endif |
2199 | ++i; | 2199 | ++i; |
2200 | } | 2200 | } |
2201 | } | 2201 | } |
2202 | 2202 | ||
2203 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2203 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2204 | { | 2204 | { |
2205 | unsigned int cat = 0; | 2205 | unsigned int cat = 0; |
2206 | 2206 | ||
2207 | if (!findCategory(category, &cat)) | 2207 | if (!findCategory(category, &cat)) |
2208 | return false; | 2208 | return false; |
2209 | 2209 | ||
2210 | return execLauncher(cat, entryIndex); | 2210 | return execLauncher(cat, entryIndex); |
2211 | } | 2211 | } |
2212 | 2212 | ||
2213 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2213 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2214 | { | 2214 | { |
2215 | if (geteuid() == 0) { | 2215 | if (geteuid() == 0) { |
2216 | rootAlertMsgBox(); | 2216 | rootAlertMsgBox(); |
2217 | return false; | 2217 | return false; |
2218 | } | 2218 | } |
2219 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2219 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2220 | bool wasLocked = isLocked(category, entryIndex); | 2220 | bool wasLocked = isLocked(category, entryIndex); |
2221 | 2221 | ||
2222 | if (command.find("$p") != -1) { | 2222 | if (command.find("$p") != -1) { |
2223 | /* the user requested the password to be included | 2223 | /* the user requested the password to be included |
2224 | * into the command. We have to ask for the password, | 2224 | * into the command. We have to ask for the password, |
2225 | * if it's locked. We do that by unlocking the entry | 2225 | * if it's locked. We do that by unlocking the entry |
2226 | */ | 2226 | */ |
2227 | if (!lockAt(category, entryIndex, false)) | 2227 | if (!lockAt(category, entryIndex, false)) |
2228 | return false; | 2228 | return false; |
2229 | } | 2229 | } |
2230 | #ifndef PWM_EMBEDDED | 2230 | #ifndef PWM_EMBEDDED |
2231 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2231 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2232 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2232 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2233 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2233 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2234 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2234 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2235 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2235 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2236 | #else | 2236 | #else |
2237 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2237 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2238 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2238 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2239 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2239 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2240 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2240 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2241 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2241 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2242 | #endif | 2242 | #endif |
2243 | command.append(" &"); | 2243 | command.append(" &"); |
2244 | 2244 | ||
2245 | QString customXterm(conf()->confGlobXtermCommand()); | 2245 | QString customXterm(conf()->confGlobXtermCommand()); |
2246 | if (!customXterm.isEmpty()) | 2246 | if (!customXterm.isEmpty()) |
2247 | command = customXterm + " " + command; | 2247 | command = customXterm + " " + command; |
2248 | 2248 | ||
2249 | system(command.latin1()); | 2249 | system(command.latin1()); |
2250 | 2250 | ||
2251 | lockAt(category, entryIndex, wasLocked); | 2251 | lockAt(category, entryIndex, wasLocked); |
2252 | return true; | 2252 | return true; |
2253 | } | 2253 | } |
2254 | 2254 | ||
2255 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2255 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2256 | { | 2256 | { |
2257 | unsigned int cat = 0; | 2257 | unsigned int cat = 0; |
2258 | 2258 | ||
2259 | if (!findCategory(category, &cat)) | 2259 | if (!findCategory(category, &cat)) |
2260 | return false; | 2260 | return false; |
2261 | 2261 | ||
2262 | return goToURL(cat, entryIndex); | 2262 | return goToURL(cat, entryIndex); |
2263 | } | 2263 | } |
2264 | 2264 | ||
2265 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2265 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2266 | { | 2266 | { |
2267 | if (geteuid() == 0) { | 2267 | if (geteuid() == 0) { |
2268 | rootAlertMsgBox(); | 2268 | rootAlertMsgBox(); |
2269 | return false; | 2269 | return false; |
2270 | } | 2270 | } |
2271 | QString url(dti.dta[category].d[entryIndex].url.c_str()); | 2271 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2272 | if (url.isEmpty()) | 2272 | if (url.isEmpty()) |
2273 | return false; | 2273 | return false; |
2274 | 2274 | ||
2275 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2275 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2276 | if (!customBrowser.isEmpty()) { | 2276 | if (!customBrowser.isEmpty()) { |
2277 | browserProc.clearArguments(); | 2277 | browserProc.clearArguments(); |
2278 | browserProc << customBrowser << url; | 2278 | browserProc << customBrowser << url; |
2279 | if (browserProc.start(KProcess::DontCare)) | 2279 | if (browserProc.start(KProcess::DontCare)) |
2280 | return true; | 2280 | return true; |
2281 | } | 2281 | } |
2282 | 2282 | ||
2283 | browserProc.clearArguments(); | 2283 | browserProc.clearArguments(); |
2284 | browserProc << "konqueror" << url; | 2284 | browserProc << "konqueror" << url; |
2285 | if (browserProc.start(KProcess::DontCare)) | 2285 | if (browserProc.start(KProcess::DontCare)) |
2286 | return true; | 2286 | return true; |
2287 | 2287 | ||
2288 | browserProc.clearArguments(); | 2288 | browserProc.clearArguments(); |
2289 | browserProc << "mozilla" << url; | 2289 | browserProc << "mozilla" << url; |
2290 | if (browserProc.start(KProcess::DontCare)) | 2290 | if (browserProc.start(KProcess::DontCare)) |
2291 | return true; | 2291 | return true; |
2292 | 2292 | ||
2293 | browserProc.clearArguments(); | 2293 | browserProc.clearArguments(); |
2294 | browserProc << "opera" << url; | 2294 | browserProc << "opera" << url; |
2295 | if (browserProc.start(KProcess::DontCare)) | 2295 | if (browserProc.start(KProcess::DontCare)) |
2296 | return true; | 2296 | return true; |
2297 | return false; | 2297 | return false; |
2298 | } | 2298 | } |
2299 | 2299 | ||
2300 | PwMerror PwMDoc::exportToText(const QString *file) | 2300 | PwMerror PwMDoc::exportToText(const QString *file) |
2301 | { | 2301 | { |
2302 | PWM_ASSERT(file); | 2302 | PWM_ASSERT(file); |
2303 | if (QFile::exists(*file)) { | 2303 | if (QFile::exists(*file)) { |
2304 | if (!QFile::remove(*file)) | 2304 | if (!QFile::remove(*file)) |
2305 | return e_accessFile; | 2305 | return e_accessFile; |
2306 | } | 2306 | } |
2307 | QFile f(*file); | 2307 | QFile f(*file); |
2308 | if (!f.open(IO_ReadWrite)) | 2308 | if (!f.open(IO_ReadWrite)) |
2309 | return e_openFile; | 2309 | return e_openFile; |
2310 | 2310 | ||
2311 | if (!unlockAll_tempoary()) { | 2311 | if (!unlockAll_tempoary()) { |
2312 | f.close(); | 2312 | f.close(); |
2313 | return e_lock; | 2313 | return e_lock; |
2314 | } | 2314 | } |
2315 | 2315 | ||
2316 | // write header | 2316 | // write header |
2317 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2317 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2318 | header += PACKAGE_VER; | 2318 | header += PACKAGE_VER; |
2319 | header += i18n("\non ").latin1(); | 2319 | header += i18n("\non ").latin1(); |
2320 | QDate currDate = QDate::currentDate(); | 2320 | QDate currDate = QDate::currentDate(); |
2321 | QTime currTime = QTime::currentTime(); | 2321 | QTime currTime = QTime::currentTime(); |
2322 | 2322 | ||
2323 | #ifndef PWM_EMBEDDED | 2323 | #ifndef PWM_EMBEDDED |
2324 | header += currDate.toString("ddd MMMM d ").latin1(); | 2324 | header += currDate.toString("ddd MMMM d ").latin1(); |
2325 | header += currTime.toString("hh:mm:ss ").latin1(); | 2325 | header += currTime.toString("hh:mm:ss ").latin1(); |
2326 | #else | 2326 | #else |
2327 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2327 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2328 | bool ampm = KGlobal::locale()->use12Clock(); | 2328 | bool ampm = KGlobal::locale()->use12Clock(); |
2329 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2329 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2330 | KGlobal::locale()->setHore24Format(true); | 2330 | KGlobal::locale()->setHore24Format(true); |
2331 | 2331 | ||
2332 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); | 2332 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); |
2333 | header += KGlobal::locale()->formatTime(currTime, true); | 2333 | header += KGlobal::locale()->formatTime(currTime, true); |
2334 | KGlobal::locale()->setDateFormatShort(dfs); | 2334 | KGlobal::locale()->setDateFormatShort(dfs); |
2335 | KGlobal::locale()->setHore24Format(!ampm); | 2335 | KGlobal::locale()->setHore24Format(!ampm); |
2336 | 2336 | ||
2337 | #endif | 2337 | #endif |
2338 | header += tostr(currDate.year()); | 2338 | header += tostr(currDate.year()); |
2339 | header += "\n==============================\n\n"; | 2339 | header += "\n==============================\n\n"; |
2340 | 2340 | ||
2341 | 2341 | ||
2342 | #ifndef PWM_EMBEDDED | 2342 | #ifndef PWM_EMBEDDED |
2343 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2343 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2344 | unlockAll_tempoary(true); | 2344 | unlockAll_tempoary(true); |
2345 | f.close(); | 2345 | f.close(); |
2346 | return e_writeFile; | 2346 | return e_writeFile; |
2347 | } | 2347 | } |
2348 | #else | 2348 | #else |
2349 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2349 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2350 | unlockAll_tempoary(true); | 2350 | unlockAll_tempoary(true); |
2351 | f.close(); | 2351 | f.close(); |
2352 | return e_writeFile; | 2352 | return e_writeFile; |
2353 | } | 2353 | } |
2354 | #endif | 2354 | #endif |
2355 | unsigned int i, numCat = numCategories(); | 2355 | unsigned int i, numCat = numCategories(); |
2356 | unsigned int j, numEnt; | 2356 | unsigned int j, numEnt; |
2357 | string exp; | 2357 | string exp; |
2358 | for (i = 0; i < numCat; ++i) { | 2358 | for (i = 0; i < numCat; ++i) { |
2359 | numEnt = numEntries(i); | 2359 | numEnt = numEntries(i); |
2360 | 2360 | ||
2361 | exp = "\n== Category: "; | 2361 | exp = "\n== Category: "; |
2362 | exp += dti.dta[i].name; | 2362 | exp += dti.dta[i].name; |
2363 | exp += " ==\n"; | 2363 | exp += " ==\n"; |
2364 | #ifndef PWM_EMBEDDED | 2364 | #ifndef PWM_EMBEDDED |
2365 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2365 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2366 | unlockAll_tempoary(true); | 2366 | unlockAll_tempoary(true); |
2367 | f.close(); | 2367 | f.close(); |
2368 | return e_writeFile; | 2368 | return e_writeFile; |
2369 | } | 2369 | } |
2370 | #else | 2370 | #else |
2371 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2371 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2372 | unlockAll_tempoary(true); | 2372 | unlockAll_tempoary(true); |
2373 | f.close(); | 2373 | f.close(); |
2374 | return e_writeFile; | 2374 | return e_writeFile; |
2375 | } | 2375 | } |
2376 | #endif | 2376 | #endif |
2377 | for (j = 0; j < numEnt; ++j) { | 2377 | for (j = 0; j < numEnt; ++j) { |
2378 | exp = "\n-- "; | 2378 | exp = "\n-- "; |
2379 | exp += dti.dta[i].d[j].desc; | 2379 | exp += dti.dta[i].d[j].desc; |
2380 | exp += " --\n"; | 2380 | exp += " --\n"; |
2381 | 2381 | ||
2382 | exp += i18n("Username: ").latin1(); | 2382 | exp += i18n("Username: ").latin1(); |
2383 | exp += dti.dta[i].d[j].name; | 2383 | exp += dti.dta[i].d[j].name; |
2384 | exp += "\n"; | 2384 | exp += "\n"; |
2385 | 2385 | ||
2386 | exp += i18n("Password: ").latin1(); | 2386 | exp += i18n("Password: ").latin1(); |
2387 | exp += dti.dta[i].d[j].pw; | 2387 | exp += dti.dta[i].d[j].pw; |
2388 | exp += "\n"; | 2388 | exp += "\n"; |
2389 | 2389 | ||
2390 | exp += i18n("Comment: ").latin1(); | 2390 | exp += i18n("Comment: ").latin1(); |
2391 | exp += dti.dta[i].d[j].comment; | 2391 | exp += dti.dta[i].d[j].comment; |
2392 | exp += "\n"; | 2392 | exp += "\n"; |
2393 | 2393 | ||
2394 | exp += i18n("URL: ").latin1(); | 2394 | exp += i18n("URL: ").latin1(); |
2395 | exp += dti.dta[i].d[j].url; | 2395 | exp += dti.dta[i].d[j].url; |
2396 | exp += "\n"; | 2396 | exp += "\n"; |
2397 | 2397 | ||
2398 | exp += i18n("Launcher: ").latin1(); | 2398 | exp += i18n("Launcher: ").latin1(); |
2399 | exp += dti.dta[i].d[j].launcher; | 2399 | exp += dti.dta[i].d[j].launcher; |
2400 | exp += "\n"; | 2400 | exp += "\n"; |
2401 | 2401 | ||
2402 | #ifndef PWM_EMBEDDED | 2402 | #ifndef PWM_EMBEDDED |
2403 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2403 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2404 | unlockAll_tempoary(true); | 2404 | unlockAll_tempoary(true); |
2405 | f.close(); | 2405 | f.close(); |
2406 | return e_writeFile; | 2406 | return e_writeFile; |
2407 | } | 2407 | } |
2408 | #else | 2408 | #else |
2409 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2409 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2410 | unlockAll_tempoary(true); | 2410 | unlockAll_tempoary(true); |
2411 | f.close(); | 2411 | f.close(); |
2412 | return e_writeFile; | 2412 | return e_writeFile; |
2413 | } | 2413 | } |
2414 | #endif | 2414 | #endif |
2415 | } | 2415 | } |
2416 | } | 2416 | } |
2417 | unlockAll_tempoary(true); | 2417 | unlockAll_tempoary(true); |
2418 | f.close(); | 2418 | f.close(); |
2419 | 2419 | ||
2420 | return e_success; | 2420 | return e_success; |
2421 | } | 2421 | } |
2422 | 2422 | ||
2423 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2423 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2424 | { | 2424 | { |
2425 | PWM_ASSERT(file); | 2425 | PWM_ASSERT(file); |
2426 | if (format == 0) | 2426 | if (format == 0) |
2427 | return importText_PwM(file); | 2427 | return importText_PwM(file); |
2428 | else if (format == -1) { | 2428 | else if (format == -1) { |
2429 | // probe for all formats | 2429 | // probe for all formats |
2430 | if (importText_PwM(file) == e_success) | 2430 | if (importText_PwM(file) == e_success) |
2431 | return e_success; | 2431 | return e_success; |
2432 | dti.clear(); | 2432 | dti.clear(); |
2433 | emitDataChanged(this); | 2433 | emitDataChanged(this); |
2434 | // add next format here... | 2434 | // add next format here... |
2435 | return e_fileFormat; | 2435 | return e_fileFormat; |
2436 | } | 2436 | } |
2437 | return e_invalidArg; | 2437 | return e_invalidArg; |
2438 | } | 2438 | } |
2439 | 2439 | ||
2440 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2440 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2441 | { | 2441 | { |
2442 | #ifndef PWM_EMBEDDED | 2442 | #ifndef PWM_EMBEDDED |
2443 | PWM_ASSERT(file); | 2443 | PWM_ASSERT(file); |
2444 | FILE *f; | 2444 | FILE *f; |
2445 | int tmp; | 2445 | int tmp; |
2446 | ssize_t ret; | 2446 | ssize_t ret; |
2447 | string curCat; | 2447 | string curCat; |
2448 | unsigned int entriesRead = 0; | 2448 | unsigned int entriesRead = 0; |
2449 | PwMDataItem currItem; | 2449 | PwMDataItem currItem; |
2450 | f = fopen(file->latin1(), "r"); | 2450 | f = fopen(file->latin1(), "r"); |
2451 | if (!f) | 2451 | if (!f) |
2452 | return e_openFile; | 2452 | return e_openFile; |
2453 | size_t ch_tmp_size = 1024; | 2453 | size_t ch_tmp_size = 1024; |
2454 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2454 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2455 | if (!ch_tmp) { | 2455 | if (!ch_tmp) { |
2456 | fclose(f); | 2456 | fclose(f); |
2457 | return e_outOfMem; | 2457 | return e_outOfMem; |
2458 | } | 2458 | } |
2459 | 2459 | ||
2460 | // - check header | 2460 | // - check header |
2461 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2461 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2462 | goto formatError; | 2462 | goto formatError; |
2463 | // check version-string and return version in "ch_tmp". | 2463 | // check version-string and return version in "ch_tmp". |
2464 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2464 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2465 | // header not recognized as PwM generated header | 2465 | // header not recognized as PwM generated header |
2466 | goto formatError; | 2466 | goto formatError; |
2467 | } | 2467 | } |
2468 | // set filepointer behind version-string-line previously checked | 2468 | // set filepointer behind version-string-line previously checked |
2469 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2469 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2470 | goto formatError; | 2470 | goto formatError; |
2471 | // skip next line containing the build-date | 2471 | // skip next line containing the build-date |
2472 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2472 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2473 | goto formatError; | 2473 | goto formatError; |
2474 | // read header termination line | 2474 | // read header termination line |
2475 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2475 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2476 | goto formatError; | 2476 | goto formatError; |
2477 | if (strcmp(ch_tmp, "==============================\n")) | 2477 | if (strcmp(ch_tmp, "==============================\n")) |
2478 | goto formatError; | 2478 | goto formatError; |
2479 | 2479 | ||
2480 | // - read entries | 2480 | // - read entries |
2481 | do { | 2481 | do { |
2482 | // find beginning of next category | 2482 | // find beginning of next category |
2483 | do { | 2483 | do { |
2484 | tmp = fgetc(f); | 2484 | tmp = fgetc(f); |
2485 | } while (tmp == '\n' && tmp != EOF); | 2485 | } while (tmp == '\n' && tmp != EOF); |
2486 | if (tmp == EOF) | 2486 | if (tmp == EOF) |
2487 | break; | 2487 | break; |
2488 | 2488 | ||
2489 | // decrement filepos by one | 2489 | // decrement filepos by one |
2490 | fseek(f, -1, SEEK_CUR); | 2490 | fseek(f, -1, SEEK_CUR); |
2491 | // read cat-name | 2491 | // read cat-name |
2492 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2492 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2493 | goto formatError; | 2493 | goto formatError; |
2494 | // check cat-name format | 2494 | // check cat-name format |
2495 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2495 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2496 | goto formatError; | 2496 | goto formatError; |
2497 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2497 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2498 | goto formatError; | 2498 | goto formatError; |
2499 | // copy cat-name | 2499 | // copy cat-name |
2500 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2500 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2501 | 2501 | ||
2502 | do { | 2502 | do { |
2503 | // find beginning of next entry | 2503 | // find beginning of next entry |
2504 | do { | 2504 | do { |
2505 | tmp = fgetc(f); | 2505 | tmp = fgetc(f); |
2506 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2506 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2507 | if (tmp == EOF) | 2507 | if (tmp == EOF) |
2508 | break; | 2508 | break; |
2509 | if (tmp == '=') { | 2509 | if (tmp == '=') { |
2510 | fseek(f, -1, SEEK_CUR); | 2510 | fseek(f, -1, SEEK_CUR); |
2511 | break; | 2511 | break; |
2512 | } | 2512 | } |
2513 | // decrement filepos by one | 2513 | // decrement filepos by one |
2514 | fseek(f, -1, SEEK_CUR); | 2514 | fseek(f, -1, SEEK_CUR); |
2515 | // read desc-line | 2515 | // read desc-line |
2516 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2516 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2517 | goto formatError; | 2517 | goto formatError; |
2518 | // check desc-line format | 2518 | // check desc-line format |
2519 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2519 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2520 | goto formatError; | 2520 | goto formatError; |
2521 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2521 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2522 | goto formatError; | 2522 | goto formatError; |
2523 | // add desc-line | 2523 | // add desc-line |
2524 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2524 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2525 | 2525 | ||
2526 | // read username-line | 2526 | // read username-line |
2527 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2527 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2528 | goto formatError; | 2528 | goto formatError; |
2529 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2529 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2530 | goto formatError; | 2530 | goto formatError; |
2531 | 2531 | ||
2532 | // read pw-line | 2532 | // read pw-line |
2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2534 | goto formatError; | 2534 | goto formatError; |
2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2536 | goto formatError; | 2536 | goto formatError; |
2537 | 2537 | ||
2538 | // read comment-line | 2538 | // read comment-line |
2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2540 | goto formatError; | 2540 | goto formatError; |
2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2542 | goto formatError; | 2542 | goto formatError; |
2543 | 2543 | ||
2544 | // read URL-line | 2544 | // read URL-line |
2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2546 | goto formatError; | 2546 | goto formatError; |
2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2548 | goto formatError; | 2548 | goto formatError; |
2549 | 2549 | ||
2550 | // read launcher-line | 2550 | // read launcher-line |
2551 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2551 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2552 | goto formatError; | 2552 | goto formatError; |
2553 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2553 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2554 | goto formatError; | 2554 | goto formatError; |
2555 | 2555 | ||
2556 | currItem.lockStat = true; | 2556 | currItem.lockStat = true; |
2557 | currItem.listViewPos = -1; | 2557 | currItem.listViewPos = -1; |
2558 | addEntry(curCat.c_str(), &currItem, true); | 2558 | addEntry(curCat.c_str(), &currItem, true); |
2559 | ++entriesRead; | 2559 | ++entriesRead; |
2560 | } while (1); | 2560 | } while (1); |
2561 | } while (1); | 2561 | } while (1); |
2562 | if (!entriesRead) | 2562 | if (!entriesRead) |
2563 | goto formatError; | 2563 | goto formatError; |
2564 | 2564 | ||
2565 | free(ch_tmp); | 2565 | free(ch_tmp); |
2566 | fclose(f); | 2566 | fclose(f); |
2567 | flagDirty(); | 2567 | flagDirty(); |
2568 | return e_success; | 2568 | return e_success; |
2569 | 2569 | ||
2570 | formatError: | 2570 | formatError: |
2571 | free(ch_tmp); | 2571 | free(ch_tmp); |
2572 | fclose(f); | 2572 | fclose(f); |
2573 | return e_fileFormat; | 2573 | return e_fileFormat; |
2574 | #else | 2574 | #else |
2575 | PWM_ASSERT(file); | 2575 | PWM_ASSERT(file); |
2576 | QFile f(file->latin1()); | 2576 | QFile f(file->latin1()); |
2577 | int tmp; | 2577 | int tmp; |
2578 | ssize_t ret; | 2578 | ssize_t ret; |
2579 | string curCat; | 2579 | string curCat; |
2580 | unsigned int entriesRead = 0; | 2580 | unsigned int entriesRead = 0; |
2581 | PwMDataItem currItem; | 2581 | PwMDataItem currItem; |
2582 | bool res = f.open(IO_ReadOnly); | 2582 | bool res = f.open(IO_ReadOnly); |
2583 | if (res == false) | 2583 | if (res == false) |
2584 | return e_openFile; | 2584 | return e_openFile; |
2585 | 2585 | ||
2586 | unsigned int ch_tmp_size = 1024; | 2586 | unsigned int ch_tmp_size = 1024; |
2587 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2587 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2588 | if (!ch_tmp) { | 2588 | if (!ch_tmp) { |
2589 | f.close(); | 2589 | f.close(); |
2590 | return e_outOfMem; | 2590 | return e_outOfMem; |
2591 | } | 2591 | } |
2592 | 2592 | ||
2593 | // - check header | 2593 | // - check header |
2594 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. | 2594 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. |
2595 | goto formatError; | 2595 | goto formatError; |
2596 | 2596 | ||
2597 | //US read fileversion first, then check if ok. | 2597 | //US read fileversion first, then check if ok. |
2598 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2598 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2599 | goto formatError; | 2599 | goto formatError; |
2600 | 2600 | ||
2601 | // check version-string and return version in "ch_tmp". | 2601 | // check version-string and return version in "ch_tmp". |
2602 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2602 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2603 | //US // header not recognized as PwM generated header | 2603 | //US // header not recognized as PwM generated header |
2604 | //US goto formatError; | 2604 | //US goto formatError; |
2605 | //US} | 2605 | //US} |
2606 | //US set filepointer behind version-string-line previously checked | 2606 | //US set filepointer behind version-string-line previously checked |
2607 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2607 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2608 | //US goto formatError; | 2608 | //US goto formatError; |
2609 | // skip next line containing the build-date | 2609 | // skip next line containing the build-date |
2610 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2610 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2611 | goto formatError; | 2611 | goto formatError; |
2612 | // read header termination line | 2612 | // read header termination line |
2613 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2613 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2614 | goto formatError; | 2614 | goto formatError; |
2615 | if (strcmp(ch_tmp, "==============================\n")) | 2615 | if (strcmp(ch_tmp, "==============================\n")) |
2616 | goto formatError; | 2616 | goto formatError; |
2617 | 2617 | ||
2618 | // - read entries | 2618 | // - read entries |
2619 | do { | 2619 | do { |
2620 | // find beginning of next category | 2620 | // find beginning of next category |
2621 | do { | 2621 | do { |
2622 | tmp = f.getch(); | 2622 | tmp = f.getch(); |
2623 | } while (tmp == '\n' && tmp != EOF); | 2623 | } while (tmp == '\n' && tmp != EOF); |
2624 | if (tmp == EOF) | 2624 | if (tmp == EOF) |
2625 | break; | 2625 | break; |
2626 | 2626 | ||
2627 | // decrement filepos by one | 2627 | // decrement filepos by one |
2628 | f.at(f.at()-1); | 2628 | f.at(f.at()-1); |
2629 | // read cat-name | 2629 | // read cat-name |
2630 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2630 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2631 | goto formatError; | 2631 | goto formatError; |
2632 | // check cat-name format | 2632 | // check cat-name format |
2633 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2633 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2634 | goto formatError; | 2634 | goto formatError; |
2635 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2635 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2636 | goto formatError; | 2636 | goto formatError; |
2637 | // copy cat-name | 2637 | // copy cat-name |
2638 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2638 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2639 | 2639 | ||
2640 | do { | 2640 | do { |
2641 | // find beginning of next entry | 2641 | // find beginning of next entry |
2642 | do { | 2642 | do { |
2643 | tmp = f.getch(); | 2643 | tmp = f.getch(); |
2644 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2644 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2645 | if (tmp == EOF) | 2645 | if (tmp == EOF) |
2646 | break; | 2646 | break; |
2647 | if (tmp == '=') { | 2647 | if (tmp == '=') { |
2648 | f.at(f.at()-1); | 2648 | f.at(f.at()-1); |
2649 | break; | 2649 | break; |
2650 | } | 2650 | } |
2651 | // decrement filepos by one | 2651 | // decrement filepos by one |
2652 | f.at(f.at()-1); | 2652 | f.at(f.at()-1); |
2653 | // read desc-line | 2653 | // read desc-line |
2654 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2654 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2655 | goto formatError; | 2655 | goto formatError; |
2656 | // check desc-line format | 2656 | // check desc-line format |
2657 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2657 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2658 | goto formatError; | 2658 | goto formatError; |
2659 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2659 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2660 | goto formatError; | 2660 | goto formatError; |
2661 | // add desc-line | 2661 | // add desc-line |
2662 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2662 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2663 | 2663 | ||
2664 | // read username-line | 2664 | // read username-line |
2665 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2665 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2666 | goto formatError; | 2666 | goto formatError; |
2667 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2667 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2668 | goto formatError; | 2668 | goto formatError; |
2669 | 2669 | ||
2670 | // read pw-line | 2670 | // read pw-line |
2671 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2671 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2672 | goto formatError; | 2672 | goto formatError; |
2673 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2673 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2674 | goto formatError; | 2674 | goto formatError; |
2675 | 2675 | ||
2676 | // read comment-line | 2676 | // read comment-line |
2677 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2677 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2678 | goto formatError; | 2678 | goto formatError; |
2679 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2679 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2680 | goto formatError; | 2680 | goto formatError; |
2681 | 2681 | ||
2682 | // read URL-line | 2682 | // read URL-line |
2683 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2683 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2684 | goto formatError; | 2684 | goto formatError; |
2685 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2685 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2686 | goto formatError; | 2686 | goto formatError; |
2687 | 2687 | ||
2688 | // read launcher-line | 2688 | // read launcher-line |
2689 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2689 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2690 | goto formatError; | 2690 | goto formatError; |
2691 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2691 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2692 | goto formatError; | 2692 | goto formatError; |
2693 | 2693 | ||
2694 | currItem.lockStat = true; | 2694 | currItem.lockStat = true; |
2695 | currItem.listViewPos = -1; | 2695 | currItem.listViewPos = -1; |
2696 | addEntry(curCat.c_str(), &currItem, true); | 2696 | addEntry(curCat.c_str(), &currItem, true); |
2697 | ++entriesRead; | 2697 | ++entriesRead; |
2698 | } while (1); | 2698 | } while (1); |
2699 | } while (1); | 2699 | } while (1); |
2700 | if (!entriesRead) | 2700 | if (!entriesRead) |
2701 | goto formatError; | 2701 | goto formatError; |
2702 | 2702 | ||
2703 | free(ch_tmp); | 2703 | free(ch_tmp); |
2704 | f.close(); | 2704 | f.close(); |
2705 | flagDirty(); | 2705 | flagDirty(); |
2706 | return e_success; | 2706 | return e_success; |
2707 | 2707 | ||
2708 | formatError: | 2708 | formatError: |
2709 | free(ch_tmp); | 2709 | free(ch_tmp); |
2710 | f.close(); | 2710 | f.close(); |
2711 | return e_fileFormat; | 2711 | return e_fileFormat; |
2712 | 2712 | ||
2713 | #endif | 2713 | #endif |
2714 | 2714 | ||
2715 | } | 2715 | } |
2716 | 2716 | ||
2717 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2717 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2718 | { | 2718 | { |
2719 | PWM_ASSERT(in && out); | 2719 | PWM_ASSERT(in && out); |
2720 | ssize_t i = 0, len = in_size - 1; | 2720 | ssize_t i = 0, len = in_size - 1; |
2721 | while (i < len) { | 2721 | while (i < len) { |
2722 | if (in[i] == ':') | 2722 | if (in[i] == ':') |
2723 | break; | 2723 | break; |
2724 | ++i; | 2724 | ++i; |
2725 | } | 2725 | } |
2726 | i += 2; | 2726 | i += 2; |
2727 | *out = ""; | 2727 | *out = ""; |
2728 | out->append(in + i, in_size - i - 1); | 2728 | out->append(in + i, in_size - i - 1); |
2729 | return true; | 2729 | return true; |
2730 | } | 2730 | } |
2731 | 2731 | ||
2732 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2732 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2733 | { | 2733 | { |
2734 | PWM_ASSERT(file); | 2734 | PWM_ASSERT(file); |
2735 | GpasmanFile gp; | 2735 | GpasmanFile gp; |
2736 | int ret; | 2736 | int ret; |
2737 | 2737 | ||
2738 | if (!unlockAll_tempoary()) | 2738 | if (!unlockAll_tempoary()) |
2739 | return e_lock; | 2739 | return e_lock; |
2740 | 2740 | ||
2741 | QString gpmPassword; | 2741 | QString gpmPassword; |
2742 | while (1) { | 2742 | while (1) { |
2743 | gpmPassword = requestNewMpw(0); | 2743 | gpmPassword = requestNewMpw(0); |
2744 | if (gpmPassword == "") { | 2744 | if (gpmPassword == "") { |
2745 | unlockAll_tempoary(true); | 2745 | unlockAll_tempoary(true); |
2746 | return e_noPw; | 2746 | return e_noPw; |
2747 | } | 2747 | } |
2748 | if (gpmPassword.length() < 4) { | 2748 | if (gpmPassword.length() < 4) { |
2749 | gpmPwLenErrMsgBox(); | 2749 | gpmPwLenErrMsgBox(); |
2750 | } else { | 2750 | } else { |
2751 | break; | 2751 | break; |
2752 | } | 2752 | } |
2753 | } | 2753 | } |
2754 | 2754 | ||
2755 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2755 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2756 | if (ret != 1) { | 2756 | if (ret != 1) { |
2757 | unlockAll_tempoary(true); | 2757 | unlockAll_tempoary(true); |
2758 | return e_accessFile; | 2758 | return e_accessFile; |
2759 | } | 2759 | } |
2760 | 2760 | ||
2761 | char *entry[4]; | 2761 | char *entry[4]; |
2762 | unsigned int numCat = numCategories(), i; | 2762 | unsigned int numCat = numCategories(), i; |
2763 | unsigned int numEntr, j; | 2763 | unsigned int numEntr, j; |
2764 | int descLen, nameLen, pwLen, commentLen; | 2764 | int descLen, nameLen, pwLen, commentLen; |
2765 | for (i = 0; i < numCat; ++i) { | 2765 | for (i = 0; i < numCat; ++i) { |
2766 | numEntr = numEntries(i); | 2766 | numEntr = numEntries(i); |
2767 | for (j = 0; j < numEntr; ++j) { | 2767 | for (j = 0; j < numEntr; ++j) { |
2768 | descLen = dti.dta[i].d[j].desc.length(); | 2768 | descLen = dti.dta[i].d[j].desc.length(); |
2769 | nameLen = dti.dta[i].d[j].name.length(); | 2769 | nameLen = dti.dta[i].d[j].name.length(); |
2770 | pwLen = dti.dta[i].d[j].pw.length(); | 2770 | pwLen = dti.dta[i].d[j].pw.length(); |
2771 | commentLen = dti.dta[i].d[j].comment.length(); | 2771 | commentLen = dti.dta[i].d[j].comment.length(); |
2772 | entry[0] = new char[descLen + 1]; | 2772 | entry[0] = new char[descLen + 1]; |
2773 | entry[1] = new char[nameLen + 1]; | 2773 | entry[1] = new char[nameLen + 1]; |
2774 | entry[2] = new char[pwLen + 1]; | 2774 | entry[2] = new char[pwLen + 1]; |
2775 | entry[3] = new char[commentLen + 1]; | 2775 | entry[3] = new char[commentLen + 1]; |
2776 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); | 2776 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2777 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); | 2777 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2778 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); | 2778 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2779 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); | 2779 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2780 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2780 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2781 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2781 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2782 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2782 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2783 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2783 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2784 | 2784 | ||
2785 | ret = gp.save_entry(entry); | 2785 | ret = gp.save_entry(entry); |
2786 | if (ret == -1){ | 2786 | if (ret == -1){ |
2787 | delete [] entry[0]; | 2787 | delete [] entry[0]; |
2788 | delete [] entry[1]; | 2788 | delete [] entry[1]; |
2789 | delete [] entry[2]; | 2789 | delete [] entry[2]; |
2790 | delete [] entry[3]; | 2790 | delete [] entry[3]; |
2791 | gp.save_finalize(); | 2791 | gp.save_finalize(); |
2792 | unlockAll_tempoary(true); | 2792 | unlockAll_tempoary(true); |
2793 | return e_writeFile; | 2793 | return e_writeFile; |
2794 | } | 2794 | } |
2795 | 2795 | ||
2796 | delete [] entry[0]; | 2796 | delete [] entry[0]; |
2797 | delete [] entry[1]; | 2797 | delete [] entry[1]; |
2798 | delete [] entry[2]; | 2798 | delete [] entry[2]; |
2799 | delete [] entry[3]; | 2799 | delete [] entry[3]; |
2800 | } | 2800 | } |
2801 | } | 2801 | } |
2802 | unlockAll_tempoary(true); | 2802 | unlockAll_tempoary(true); |
2803 | if (gp.save_finalize() == -1) | 2803 | if (gp.save_finalize() == -1) |
2804 | return e_writeFile; | 2804 | return e_writeFile; |
2805 | 2805 | ||
2806 | return e_success; | 2806 | return e_success; |
2807 | } | 2807 | } |
2808 | 2808 | ||
2809 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2809 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2810 | { | 2810 | { |
2811 | PWM_ASSERT(file); | 2811 | PWM_ASSERT(file); |
2812 | QString pw = requestMpw(false); | 2812 | QString pw = requestMpw(false); |
2813 | if (pw == "") | 2813 | if (pw == "") |
2814 | return e_noPw; | 2814 | return e_noPw; |
2815 | GpasmanFile gp; | 2815 | GpasmanFile gp; |
2816 | int ret, i; | 2816 | int ret, i; |
2817 | PwMerror ret2; | 2817 | PwMerror ret2; |
2818 | char *entry[4]; | 2818 | char *entry[4]; |
2819 | PwMDataItem tmpData; | 2819 | PwMDataItem tmpData; |
2820 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2820 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2821 | if (ret != 1) | 2821 | if (ret != 1) |
2822 | return e_accessFile; | 2822 | return e_accessFile; |
2823 | 2823 | ||
2824 | do { | 2824 | do { |
2825 | ret = gp.load_entry(entry); | 2825 | ret = gp.load_entry(entry); |
2826 | if(ret != 1) | 2826 | if(ret != 1) |
2827 | break; | 2827 | break; |
2828 | tmpData.desc = entry[0]; | 2828 | tmpData.desc = entry[0]; |
2829 | tmpData.name = entry[1]; | 2829 | tmpData.name = entry[1]; |
2830 | tmpData.pw = entry[2]; | 2830 | tmpData.pw = entry[2]; |
2831 | tmpData.comment = entry[3]; | 2831 | tmpData.comment = entry[3]; |
2832 | tmpData.lockStat = true; | 2832 | tmpData.lockStat = true; |
2833 | tmpData.listViewPos = -1; | 2833 | tmpData.listViewPos = -1; |
2834 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2834 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2835 | for (i = 0; i < 4; ++i) | 2835 | for (i = 0; i < 4; ++i) |
2836 | free(entry[i]); | 2836 | free(entry[i]); |
2837 | if (ret2 == e_maxAllowedEntr) { | 2837 | if (ret2 == e_maxAllowedEntr) { |
2838 | gp.load_finalize(); | 2838 | gp.load_finalize(); |
2839 | return e_maxAllowedEntr; | 2839 | return e_maxAllowedEntr; |
2840 | } | 2840 | } |
2841 | } while (1); | 2841 | } while (1); |
2842 | gp.load_finalize(); | 2842 | gp.load_finalize(); |
2843 | if (isDocEmpty()) | 2843 | if (isDocEmpty()) |
2844 | return e_wrongPw; // we assume this. | 2844 | return e_wrongPw; // we assume this. |
2845 | 2845 | ||
2846 | flagDirty(); | 2846 | flagDirty(); |
2847 | return e_success; | 2847 | return e_success; |
2848 | } | 2848 | } |
2849 | 2849 | ||
2850 | 2850 | ||
2851 | //US: we use the stl sort algorythm to sort all elements in the order | 2851 | //US: we use the stl sort algorythm to sort all elements in the order |
2852 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 | 2852 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 |
2853 | struct PwMDataItemListViewPosSort | 2853 | struct PwMDataItemListViewPosSort |
2854 | { | 2854 | { |
2855 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) | 2855 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) |
2856 | { | 2856 | { |
2857 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); | 2857 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); |
2858 | if ((rpEnd)->listViewPos < 0) | 2858 | if ((rpEnd)->listViewPos < 0) |
2859 | return false; | 2859 | return false; |
2860 | else | 2860 | else |
2861 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; | 2861 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; |
2862 | } | 2862 | } |
2863 | }; | 2863 | }; |
2864 | 2864 | ||
2865 | void PwMDoc::ensureLvp() | 2865 | void PwMDoc::ensureLvp() |
2866 | { | 2866 | { |
2867 | if (isDocEmpty()) | 2867 | if (isDocEmpty()) |
2868 | return; | 2868 | return; |
2869 | 2869 | ||
2870 | //US ENH BUG: when using syncronizing, this way of sorting | 2870 | //US ENH BUG: when using syncronizing, this way of sorting |
2871 | //is not sufficient, because there might be empty spaces | 2871 | //is not sufficient, because there might be empty spaces |
2872 | // at the beginning. But the old algorythm only can add elements | 2872 | // at the beginning. But the old algorythm only can add elements |
2873 | //to the end.The result are crashes because of list overflows | 2873 | //to the end.The result are crashes because of list overflows |
2874 | //we need something to fill all gaps. | 2874 | //we need something to fill all gaps. |
2875 | vector<PwMDataItem*> sorted; | 2875 | vector<PwMDataItem*> sorted; |
2876 | vector< PwMDataItem*>::iterator sortedBegin, | 2876 | vector< PwMDataItem*>::iterator sortedBegin, |
2877 | sortedEnd, | 2877 | sortedEnd, |
2878 | sortedI; | 2878 | sortedI; |
2879 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2879 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2880 | catEnd = dti.dta.end(), | 2880 | catEnd = dti.dta.end(), |
2881 | catI = catBegin; | 2881 | catI = catBegin; |
2882 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2882 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2883 | int lvpTop, tmpLvp; | 2883 | int lvpTop, tmpLvp; |
2884 | 2884 | ||
2885 | //qDebug("collect:"); | 2885 | //qDebug("collect:"); |
2886 | 2886 | ||
2887 | while (catI != catEnd) { | 2887 | while (catI != catEnd) { |
2888 | lvpTop = -1; | 2888 | lvpTop = -1; |
2889 | sorted.clear(); | 2889 | sorted.clear(); |
2890 | 2890 | ||
2891 | entrBegin = catI->d.begin(); | 2891 | entrBegin = catI->d.begin(); |
2892 | entrEnd = catI->d.end(); | 2892 | entrEnd = catI->d.end(); |
2893 | entrI = entrBegin; | 2893 | entrI = entrBegin; |
2894 | 2894 | ||
2895 | //US: we use the stl sort algorythm to sort all elements in the order | 2895 | //US: we use the stl sort algorythm to sort all elements in the order |
2896 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 | 2896 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 |
2897 | while (entrI != entrEnd) { | 2897 | while (entrI != entrEnd) { |
2898 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2898 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2899 | sorted.push_back((PwMDataItem*)&(*entrI)); | 2899 | sorted.push_back((PwMDataItem*)&(*entrI)); |
2900 | ++entrI; | 2900 | ++entrI; |
2901 | } | 2901 | } |
2902 | 2902 | ||
2903 | sortedBegin = sorted.begin(); | 2903 | sortedBegin = sorted.begin(); |
2904 | sortedEnd = sorted.end(); | 2904 | sortedEnd = sorted.end(); |
2905 | 2905 | ||
2906 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); | 2906 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); |
2907 | 2907 | ||
2908 | // qDebug("resort:"); | 2908 | // qDebug("resort:"); |
2909 | //now we have all sorted in a collection | 2909 | //now we have all sorted in a collection |
2910 | //Now start with the sorted and reset listviewpos. | 2910 | //Now start with the sorted and reset listviewpos. |
2911 | sortedBegin = sorted.begin(); | 2911 | sortedBegin = sorted.begin(); |
2912 | sortedEnd = sorted.end(); | 2912 | sortedEnd = sorted.end(); |
2913 | sortedI = sortedBegin; | 2913 | sortedI = sortedBegin; |
2914 | 2914 | ||
2915 | while (sortedI != sortedEnd) { | 2915 | while (sortedI != sortedEnd) { |
2916 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); | 2916 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); |
2917 | (*sortedI)->listViewPos = ++lvpTop; | 2917 | (*sortedI)->listViewPos = ++lvpTop; |
2918 | ++sortedI; | 2918 | ++sortedI; |
2919 | } | 2919 | } |
2920 | 2920 | ||
2921 | /*/debug | 2921 | /*/debug |
2922 | entrBegin = catI->d.begin(); | 2922 | entrBegin = catI->d.begin(); |
2923 | entrEnd = catI->d.end(); | 2923 | entrEnd = catI->d.end(); |
2924 | entrI = entrBegin; | 2924 | entrI = entrBegin; |
2925 | 2925 | ||
2926 | while (entrI != entrEnd) { | 2926 | while (entrI != entrEnd) { |
2927 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2927 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2928 | ++entrI; | 2928 | ++entrI; |
2929 | } | 2929 | } |
2930 | */ | 2930 | */ |
2931 | 2931 | ||
2932 | ++catI; | 2932 | ++catI; |
2933 | } | 2933 | } |
2934 | } | 2934 | } |
2935 | 2935 | ||
2936 | QString PwMDoc::getTitle() | 2936 | QString PwMDoc::getTitle() |
2937 | { | 2937 | { |
2938 | /* NOTE: We have to ensure, that the returned title | 2938 | /* NOTE: We have to ensure, that the returned title |
2939 | * is unique and not reused somewhere else while | 2939 | * is unique and not reused somewhere else while |
2940 | * this document is valid (open). | 2940 | * this document is valid (open). |
2941 | */ | 2941 | */ |
2942 | QString title(getFilename()); | 2942 | QString title(getFilename()); |
2943 | 2943 | ||
2944 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | 2944 | //US ENH: The whole filename on PDAs is too long. So use only the last characters |
2945 | if (QApplication::desktop()->width() < 640) | 2945 | if (QApplication::desktop()->width() < 640) |
2946 | { | 2946 | { |
2947 | if (title.length() > 30) | 2947 | if (title.length() > 30) |
2948 | title = "..." + title.right(30); | 2948 | title = "..." + title.right(30); |
2949 | 2949 | ||
2950 | } | 2950 | } |
2951 | 2951 | ||
2952 | 2952 | ||
2953 | if (title.isEmpty()) { | 2953 | if (title.isEmpty()) { |
2954 | if (unnamedNum == 0) { | 2954 | if (unnamedNum == 0) { |
2955 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2955 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2956 | PWM_ASSERT(unnamedNum != 0); | 2956 | PWM_ASSERT(unnamedNum != 0); |
2957 | } | 2957 | } |
2958 | title = DEFAULT_TITLE; | 2958 | title = DEFAULT_TITLE; |
2959 | title += " "; | 2959 | title += " "; |
2960 | title += tostr(unnamedNum).c_str(); | 2960 | title += tostr(unnamedNum).c_str(); |
2961 | } | 2961 | } |
2962 | return title; | 2962 | return title; |
2963 | } | 2963 | } |
2964 | 2964 | ||
2965 | bool PwMDoc::tryDelete() | 2965 | bool PwMDoc::tryDelete() |
2966 | { | 2966 | { |
2967 | if (deleted) | 2967 | if (deleted) |
2968 | return true; | 2968 | return true; |
2969 | int ret; | 2969 | int ret; |
2970 | if (isDirty()) { | 2970 | if (isDirty()) { |
2971 | ret = dirtyAskSave(getTitle()); | 2971 | ret = dirtyAskSave(getTitle()); |
2972 | if (ret == 0) { // save to disk | 2972 | if (ret == 0) { // save to disk |
2973 | if (!saveDocUi(this)) | 2973 | if (!saveDocUi(this)) |
2974 | goto out_ignore; | 2974 | goto out_ignore; |
2975 | } else if (ret == 1) { // don't save and delete | 2975 | } else if (ret == 1) { // don't save and delete |
2976 | goto out_accept; | 2976 | goto out_accept; |
2977 | } else { // cancel operation | 2977 | } else { // cancel operation |
2978 | goto out_ignore; | 2978 | goto out_ignore; |
2979 | } | 2979 | } |
2980 | } | 2980 | } |
2981 | out_accept: | 2981 | out_accept: |
2982 | deleted = true; | 2982 | deleted = true; |
2983 | delete this; | 2983 | delete this; |
2984 | return true; | 2984 | return true; |
2985 | out_ignore: | 2985 | out_ignore: |
2986 | return false; | 2986 | return false; |
2987 | } | 2987 | } |
2988 | 2988 | ||
2989 | 2989 | ||
2990 | 2990 | ||
2991 | #ifdef PWM_EMBEDDED | 2991 | #ifdef PWM_EMBEDDED |
2992 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2992 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2993 | //US it could have been defined as static, but I did not want to. | 2993 | //US it could have been defined as static, but I did not want to. |
2994 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2994 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2995 | { | 2995 | { |
2996 | int addedPasswordsLocal = 0; | 2996 | int addedPasswordsLocal = 0; |
2997 | int addedPasswordsRemote = 0; | 2997 | int addedPasswordsRemote = 0; |
2998 | int deletedPasswordsRemote = 0; | 2998 | int deletedPasswordsRemote = 0; |
2999 | int deletedPasswordsLocal = 0; | 2999 | int deletedPasswordsLocal = 0; |
3000 | int changedLocal = 0; | 3000 | int changedLocal = 0; |
3001 | int changedRemote = 0; | 3001 | int changedRemote = 0; |
3002 | 3002 | ||
3003 | PwMSyncItem* syncItemLocal; | 3003 | PwMSyncItem* syncItemLocal; |
3004 | PwMSyncItem* syncItemRemote; | 3004 | PwMSyncItem* syncItemRemote; |
3005 | 3005 | ||
3006 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 3006 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
3007 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3007 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3008 | 3008 | ||
3009 | bool fullDateRange = false; | 3009 | bool fullDateRange = false; |
3010 | int take; | 3010 | int take; |
3011 | // local->resetTempSyncStat(); | 3011 | // local->resetTempSyncStat(); |
3012 | QDateTime mLastSync = QDateTime::currentDateTime(); | 3012 | QDateTime mLastSync = QDateTime::currentDateTime(); |
3013 | QDateTime modifiedSync = mLastSync; | 3013 | QDateTime modifiedSync = mLastSync; |
3014 | 3014 | ||
3015 | unsigned int index; | 3015 | unsigned int index; |
3016 | //Step 1. Find syncinfo in Local file and create if not existent. | 3016 | //Step 1. Find syncinfo in Local file and create if not existent. |
3017 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3017 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3018 | if (found == false) | 3018 | if (found == false) |
3019 | { | 3019 | { |
3020 | PwMSyncItem newSyncItemLocal; | 3020 | PwMSyncItem newSyncItemLocal; |
3021 | newSyncItemLocal.syncName = mCurrentSyncDevice; | 3021 | newSyncItemLocal.syncName = mCurrentSyncDevice; |
3022 | newSyncItemLocal.lastSyncDate = mLastSync; | 3022 | newSyncItemLocal.lastSyncDate = mLastSync; |
3023 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 3023 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
3024 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3024 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3025 | if (found == false) { | 3025 | if (found == false) { |
3026 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 3026 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
3027 | return e_syncError; | 3027 | return e_syncError; |
3028 | } | 3028 | } |
3029 | } | 3029 | } |
3030 | 3030 | ||
3031 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 3031 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
3032 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 3032 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); |
3033 | 3033 | ||
3034 | //Step 2. Find syncinfo in remote file and create if not existent. | 3034 | //Step 2. Find syncinfo in remote file and create if not existent. |
3035 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3035 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3036 | if (found == false) | 3036 | if (found == false) |
3037 | { | 3037 | { |
3038 | qDebug("FULLDATE 1"); | 3038 | qDebug("FULLDATE 1"); |
3039 | fullDateRange = true; | 3039 | fullDateRange = true; |
3040 | PwMSyncItem newSyncItemRemote; | 3040 | PwMSyncItem newSyncItemRemote; |
3041 | newSyncItemRemote.syncName = mCurrentSyncName; | 3041 | newSyncItemRemote.syncName = mCurrentSyncName; |
3042 | newSyncItemRemote.lastSyncDate = mLastSync; | 3042 | newSyncItemRemote.lastSyncDate = mLastSync; |
3043 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 3043 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
3044 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3044 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3045 | if (found == false) { | 3045 | if (found == false) { |
3046 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 3046 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
3047 | return e_syncError; | 3047 | return e_syncError; |
3048 | } | 3048 | } |
3049 | } | 3049 | } |
3050 | 3050 | ||
3051 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 3051 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
3052 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | 3052 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); |
3053 | //and remove the found entry here. We will reenter it later again. | 3053 | //and remove the found entry here. We will reenter it later again. |
3054 | //US syncRemote->delSyncDataEntry(index, true); | 3054 | //US syncRemote->delSyncDataEntry(index, true); |
3055 | 3055 | ||
3056 | 3056 | ||
3057 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 3057 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
3058 | qDebug("FULLDATE 2"); | 3058 | qDebug("FULLDATE 2"); |
3059 | fullDateRange = true; | 3059 | fullDateRange = true; |
3060 | } | 3060 | } |
3061 | 3061 | ||
3062 | if ( ! fullDateRange ) { | 3062 | if ( ! fullDateRange ) { |
3063 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 3063 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
3064 | 3064 | ||
3065 | fullDateRange = true; | 3065 | fullDateRange = true; |
3066 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3066 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
3067 | } | 3067 | } |
3068 | } | 3068 | } |
3069 | // fullDateRange = true; // debug only! | 3069 | // fullDateRange = true; // debug only! |
3070 | if ( fullDateRange ) | 3070 | if ( fullDateRange ) |
3071 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3071 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
3072 | else | 3072 | else |
3073 | mLastSync = syncItemLocal->lastSyncDate; | 3073 | mLastSync = syncItemLocal->lastSyncDate; |
3074 | 3074 | ||
3075 | 3075 | ||
3076 | qDebug("*************************** "); | 3076 | qDebug("*************************** "); |
3077 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); | 3077 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
3078 | QStringList er = syncRemote->getIDEntryList(); | 3078 | QStringList er = syncRemote->getIDEntryList(); |
3079 | PwMDataItem* inRemote ;//= er.first(); | 3079 | PwMDataItem* inRemote ;//= er.first(); |
3080 | PwMDataItem* inLocal; | 3080 | PwMDataItem* inLocal; |
3081 | unsigned int catLocal, indexLocal; | 3081 | unsigned int catLocal, indexLocal; |
3082 | unsigned int catRemote, indexRemote; | 3082 | unsigned int catRemote, indexRemote; |
3083 | 3083 | ||
3084 | QString uid; | 3084 | QString uid; |
3085 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 3085 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
3086 | 3086 | ||
3087 | int modulo = (er.count()/10)+1; | 3087 | int modulo = (er.count()/10)+1; |
3088 | unsigned int incCounter = 0; | 3088 | unsigned int incCounter = 0; |
3089 | while ( incCounter < er.count()) { | 3089 | while ( incCounter < er.count()) { |
3090 | if (manager->isProgressBarCanceled()) | 3090 | if (manager->isProgressBarCanceled()) |
3091 | return e_syncError; | 3091 | return e_syncError; |
3092 | if ( incCounter % modulo == 0 ) | 3092 | if ( incCounter % modulo == 0 ) |
3093 | manager->showProgressBar(incCounter); | 3093 | manager->showProgressBar(incCounter); |
3094 | 3094 | ||
3095 | uid = er[ incCounter ]; | 3095 | uid = er[ incCounter ]; |
3096 | qDebug("sync uid %s from remote file", uid.latin1()); | 3096 | qDebug("sync uid %s from remote file", uid.latin1()); |
3097 | 3097 | ||
3098 | qApp->processEvents(); | 3098 | qApp->processEvents(); |
3099 | 3099 | ||
3100 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3100 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3101 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3101 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3102 | PWM_ASSERT(inRemote); | 3102 | PWM_ASSERT(inRemote); |
3103 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3103 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3104 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3104 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3105 | qDebug("take %d %s ", take, inLocal->desc.c_str()); | 3105 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3106 | if ( take == 3 ) | 3106 | if ( take == 3 ) |
3107 | return e_syncError; | 3107 | return e_syncError; |
3108 | if ( take == 1 ) {// take local | 3108 | if ( take == 1 ) {// take local |
3109 | int oldlistpos = inRemote->listViewPos; | 3109 | int oldlistpos = inRemote->listViewPos; |
3110 | (*inRemote) = (*inLocal); | 3110 | (*inRemote) = (*inLocal); |
3111 | inRemote->listViewPos = oldlistpos; | 3111 | inRemote->listViewPos = oldlistpos; |
3112 | ++changedRemote; | 3112 | ++changedRemote; |
3113 | } else { // take == 2 take remote | 3113 | } else { // take == 2 take remote |
3114 | int oldlistpos = inLocal->listViewPos; | 3114 | int oldlistpos = inLocal->listViewPos; |
3115 | (*inLocal) = (*inRemote); | 3115 | (*inLocal) = (*inRemote); |
3116 | inLocal->listViewPos = oldlistpos; | 3116 | inLocal->listViewPos = oldlistpos; |
3117 | ++changedLocal; | 3117 | ++changedLocal; |
3118 | } | 3118 | } |
3119 | } | 3119 | } |
3120 | } else { // no conflict | 3120 | } else { // no conflict |
3121 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 3121 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
3122 | inRemote->meta.update = modifiedSync; | 3122 | inRemote->meta.update = modifiedSync; |
3123 | 3123 | ||
3124 | //first check if we have a matching category in the local file | 3124 | //first check if we have a matching category in the local file |
3125 | const string* remotecat = syncRemote->getCategory(catRemote); | 3125 | const string* remotecat = syncRemote->getCategory(catRemote); |
3126 | //US syncRemote->insertAddressee( inRemote, false ); | 3126 | //US syncRemote->insertAddressee( inRemote, false ); |
3127 | //US syncLocal->insertAddressee( inRemote, false ); | 3127 | //US syncLocal->insertAddressee( inRemote, false ); |
3128 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 3128 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
3129 | 3129 | ||
3130 | ++addedPasswordsLocal; | 3130 | ++addedPasswordsLocal; |
3131 | } else { | 3131 | } else { |
3132 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 3132 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
3133 | syncRemote->delEntry(catRemote, indexRemote, true); | 3133 | syncRemote->delEntry(catRemote, indexRemote, true); |
3134 | //USsyncRemote->removeAddressee( inRemote ); | 3134 | //USsyncRemote->removeAddressee( inRemote ); |
3135 | ++deletedPasswordsRemote; | 3135 | ++deletedPasswordsRemote; |
3136 | } | 3136 | } |
3137 | } | 3137 | } |
3138 | 3138 | ||
3139 | ++incCounter; | 3139 | ++incCounter; |
3140 | } | 3140 | } |
3141 | 3141 | ||
3142 | 3142 | ||
3143 | er.clear(); | 3143 | er.clear(); |
3144 | QStringList el = syncLocal->getIDEntryList(); | 3144 | QStringList el = syncLocal->getIDEntryList(); |
3145 | modulo = (el.count()/10)+1; | 3145 | modulo = (el.count()/10)+1; |
3146 | 3146 | ||
3147 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 3147 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
3148 | incCounter = 0; | 3148 | incCounter = 0; |
3149 | while ( incCounter < el.count()) { | 3149 | while ( incCounter < el.count()) { |
3150 | qApp->processEvents(); | 3150 | qApp->processEvents(); |
3151 | if (manager->isProgressBarCanceled()) | 3151 | if (manager->isProgressBarCanceled()) |
3152 | return e_syncError; | 3152 | return e_syncError; |
3153 | if ( incCounter % modulo == 0 ) | 3153 | if ( incCounter % modulo == 0 ) |
3154 | manager->showProgressBar(incCounter); | 3154 | manager->showProgressBar(incCounter); |
3155 | uid = el[ incCounter ]; | 3155 | uid = el[ incCounter ]; |
3156 | qDebug("sync uid %s from local file", uid.latin1()); | 3156 | qDebug("sync uid %s from local file", uid.latin1()); |
3157 | 3157 | ||
3158 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3158 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3159 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3159 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3160 | PWM_ASSERT(inLocal); | 3160 | PWM_ASSERT(inLocal); |
3161 | 3161 | ||
3162 | if ( inRemote == 0 ) { | 3162 | if ( inRemote == 0 ) { |
3163 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 3163 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
3164 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3164 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3165 | syncLocal->delEntry(catLocal, indexLocal, true); | 3165 | syncLocal->delEntry(catLocal, indexLocal, true); |
3166 | //USsyncLocal->removeAddressee( inLocal ); | 3166 | //USsyncLocal->removeAddressee( inLocal ); |
3167 | ++deletedPasswordsLocal; | 3167 | ++deletedPasswordsLocal; |
3168 | } else { | 3168 | } else { |
3169 | if ( ! manager->mWriteBackExistingOnly ) { | 3169 | if ( ! manager->mWriteBackExistingOnly ) { |
3170 | ++addedPasswordsRemote; | 3170 | ++addedPasswordsRemote; |
3171 | inLocal->meta.update = modifiedSync; | 3171 | inLocal->meta.update = modifiedSync; |
3172 | 3172 | ||
3173 | //first check if we have a matching category in the remote file | 3173 | //first check if we have a matching category in the remote file |
3174 | const string* localcat = syncLocal->getCategory(catLocal); | 3174 | const string* localcat = syncLocal->getCategory(catLocal); |
3175 | 3175 | ||
3176 | //USsyncLocal->insertAddressee( inLocal, false ); | 3176 | //USsyncLocal->insertAddressee( inLocal, false ); |
3177 | PwMDataItem newEntry; | 3177 | PwMDataItem newEntry; |
3178 | newEntry = *inLocal; | 3178 | newEntry = *inLocal; |
3179 | inRemote = &newEntry; | 3179 | inRemote = &newEntry; |
3180 | 3180 | ||
3181 | //USsyncRemote->insertAddressee( inRemote, false ); | 3181 | //USsyncRemote->insertAddressee( inRemote, false ); |
3182 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 3182 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
3183 | 3183 | ||
3184 | } | 3184 | } |
3185 | } | 3185 | } |
3186 | 3186 | ||
3187 | } | 3187 | } |
3188 | ++incCounter; | 3188 | ++incCounter; |
3189 | } | 3189 | } |
3190 | el.clear(); | 3190 | el.clear(); |
3191 | manager->hideProgressBar(); | 3191 | manager->hideProgressBar(); |
3192 | 3192 | ||
3193 | // Now write the info back into the sync data space of the files | 3193 | // Now write the info back into the sync data space of the files |
3194 | 3194 | ||
3195 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 3195 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
3196 | // get rid of micro seconds | 3196 | // get rid of micro seconds |
3197 | QTime t = mLastSync.time(); | 3197 | QTime t = mLastSync.time(); |
3198 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3198 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3199 | 3199 | ||
3200 | 3200 | ||
3201 | syncItemLocal->lastSyncDate = mLastSync; | 3201 | syncItemLocal->lastSyncDate = mLastSync; |
3202 | syncItemRemote->lastSyncDate = mLastSync; | 3202 | syncItemRemote->lastSyncDate = mLastSync; |
3203 | 3203 | ||
3204 | QString mes; | 3204 | QString mes; |
3205 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | 3205 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); |
3206 | if ( manager->mShowSyncSummary ) { | 3206 | if ( manager->mShowSyncSummary ) { |
3207 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3207 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3208 | } | 3208 | } |
3209 | qDebug( mes ); | 3209 | qDebug( mes ); |
3210 | return e_success; | 3210 | return e_success; |
3211 | } | 3211 | } |
3212 | 3212 | ||
3213 | 3213 | ||
3214 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3214 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3215 | { | 3215 | { |
3216 | // 0 equal | 3216 | // 0 equal |
3217 | // 1 take local | 3217 | // 1 take local |
3218 | // 2 take remote | 3218 | // 2 take remote |
3219 | // 3 cancel | 3219 | // 3 cancel |
3220 | QDateTime localMod = local->meta.update; | 3220 | QDateTime localMod = local->meta.update; |
3221 | QDateTime remoteMod = remote->meta.update; | 3221 | QDateTime remoteMod = remote->meta.update; |
3222 | 3222 | ||
3223 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3223 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3224 | 3224 | ||
3225 | if ( localMod == remoteMod ) | 3225 | if ( localMod == remoteMod ) |
3226 | return 0; | 3226 | return 0; |
3227 | 3227 | ||
3228 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3228 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3229 | 3229 | ||
3230 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3230 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3231 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3231 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3232 | //full = true; //debug only | 3232 | //full = true; //debug only |
3233 | if ( full ) { | 3233 | if ( full ) { |
3234 | bool equ = ( (*local) == (*remote) ); | 3234 | bool equ = ( (*local) == (*remote) ); |
3235 | if ( equ ) { | 3235 | if ( equ ) { |
3236 | //qDebug("equal "); | 3236 | //qDebug("equal "); |
3237 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3237 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3238 | return 0; | 3238 | return 0; |
3239 | 3239 | ||
3240 | }//else //debug only | 3240 | }//else //debug only |
3241 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); | 3241 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3242 | } | 3242 | } |
3243 | 3243 | ||
3244 | int result; | 3244 | int result; |
3245 | bool localIsNew; | 3245 | bool localIsNew; |
3246 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 3246 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
3247 | 3247 | ||
3248 | if ( full && mode < SYNC_PREF_NEWEST ) | 3248 | if ( full && mode < SYNC_PREF_NEWEST ) |
3249 | mode = SYNC_PREF_ASK; | 3249 | mode = SYNC_PREF_ASK; |
3250 | 3250 | ||
3251 | switch( mode ) { | 3251 | switch( mode ) { |
3252 | case SYNC_PREF_LOCAL: | 3252 | case SYNC_PREF_LOCAL: |
3253 | if ( lastSync > remoteMod ) | 3253 | if ( lastSync > remoteMod ) |
3254 | return 1; | 3254 | return 1; |
3255 | if ( lastSync > localMod ) | 3255 | if ( lastSync > localMod ) |
3256 | return 2; | 3256 | return 2; |
3257 | return 1; | 3257 | return 1; |
3258 | break; | 3258 | break; |
3259 | case SYNC_PREF_REMOTE: | 3259 | case SYNC_PREF_REMOTE: |
3260 | if ( lastSync > remoteMod ) | 3260 | if ( lastSync > remoteMod ) |
3261 | return 1; | 3261 | return 1; |
3262 | if ( lastSync > localMod ) | 3262 | if ( lastSync > localMod ) |
3263 | return 2; | 3263 | return 2; |
3264 | return 2; | 3264 | return 2; |
3265 | break; | 3265 | break; |
3266 | case SYNC_PREF_NEWEST: | 3266 | case SYNC_PREF_NEWEST: |
3267 | if ( localMod > remoteMod ) | 3267 | if ( localMod > remoteMod ) |
3268 | return 1; | 3268 | return 1; |
3269 | else | 3269 | else |
3270 | return 2; | 3270 | return 2; |
3271 | break; | 3271 | break; |
3272 | case SYNC_PREF_ASK: | 3272 | case SYNC_PREF_ASK: |
3273 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3273 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3274 | if ( lastSync > remoteMod ) | 3274 | if ( lastSync > remoteMod ) |
3275 | return 1; | 3275 | return 1; |
3276 | if ( lastSync > localMod ) | 3276 | if ( lastSync > localMod ) |
3277 | return 2; | 3277 | return 2; |
3278 | localIsNew = localMod >= remoteMod; | 3278 | localIsNew = localMod >= remoteMod; |
3279 | //qDebug("conflict! ************************************** "); | 3279 | //qDebug("conflict! ************************************** "); |
3280 | { | 3280 | { |
3281 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3281 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3282 | result = acd.executeD(localIsNew); | 3282 | result = acd.executeD(localIsNew); |
3283 | return result; | 3283 | return result; |
3284 | } | 3284 | } |
3285 | break; | 3285 | break; |
3286 | case SYNC_PREF_FORCE_LOCAL: | 3286 | case SYNC_PREF_FORCE_LOCAL: |
3287 | return 1; | 3287 | return 1; |
3288 | break; | 3288 | break; |
3289 | case SYNC_PREF_FORCE_REMOTE: | 3289 | case SYNC_PREF_FORCE_REMOTE: |
3290 | return 2; | 3290 | return 2; |
3291 | break; | 3291 | break; |
3292 | 3292 | ||
3293 | default: | 3293 | default: |
3294 | // SYNC_PREF_TAKE_BOTH not implemented | 3294 | // SYNC_PREF_TAKE_BOTH not implemented |
3295 | break; | 3295 | break; |
3296 | } | 3296 | } |
3297 | return 0; | 3297 | return 0; |
3298 | } | 3298 | } |
3299 | 3299 | ||
3300 | 3300 | ||
3301 | 3301 | ||
3302 | 3302 | ||
3303 | //this are the overwritten callbackmethods from the syncinterface | 3303 | //this are the overwritten callbackmethods from the syncinterface |
3304 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3304 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3305 | { | 3305 | { |
3306 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3306 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3307 | 3307 | ||
3308 | //1) unlock local file first if necessary (ask for password) | 3308 | //1) unlock local file first if necessary (ask for password) |
3309 | if (this->isDeepLocked()) { | 3309 | if (this->isDeepLocked()) { |
3310 | PwMerror ret = this->deepLock(false); | 3310 | PwMerror ret = this->deepLock(false); |
3311 | if (ret != e_success) | 3311 | if (ret != e_success) |
3312 | return false; | 3312 | return false; |
3313 | } | 3313 | } |
3314 | 3314 | ||
3315 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). | 3315 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). |
3316 | PwMDoc syncTarget(this, "synctarget"); | 3316 | PwMDoc syncTarget(this, "synctarget"); |
3317 | PwMDoc* pSyncTarget = &syncTarget; | 3317 | PwMDoc* pSyncTarget = &syncTarget; |
3318 | 3318 | ||
3319 | 3319 | ||
3320 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3320 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3321 | 3321 | ||
3322 | if (err == e_alreadyOpen) { | 3322 | if (err == e_alreadyOpen) { |
3323 | PwMDocList::listItem li; | 3323 | PwMDocList::listItem li; |
3324 | if (getOpenDocList()->find(filename.latin1(), &li)) | 3324 | if (getOpenDocList()->find(filename.latin1(), &li)) |
3325 | pSyncTarget = li.doc; | 3325 | pSyncTarget = li.doc; |
3326 | else { | 3326 | else { |
3327 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3327 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3328 | return false; | 3328 | return false; |
3329 | } | 3329 | } |
3330 | } | 3330 | } |
3331 | else if (err != e_success) { | 3331 | else if (err != e_success) { |
3332 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3332 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3333 | return false; | 3333 | return false; |
3334 | } | 3334 | } |
3335 | 3335 | ||
3336 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3336 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3337 | 3337 | ||
3338 | 3338 | ||
3339 | //3) unlock remote file first if necessary (ask for password) | 3339 | //3) unlock remote file first if necessary (ask for password) |
3340 | if (pSyncTarget->isDeepLocked()) { | 3340 | if (pSyncTarget->isDeepLocked()) { |
3341 | PwMerror ret = pSyncTarget->deepLock(false); | 3341 | PwMerror ret = pSyncTarget->deepLock(false); |
3342 | if (ret != e_success) | 3342 | if (ret != e_success) |
3343 | return false; | 3343 | return false; |
3344 | } | 3344 | } |
3345 | 3345 | ||
3346 | 3346 | ||
3347 | err = syncronize(manager, this, pSyncTarget, mode ); | 3347 | err = syncronize(manager, this, pSyncTarget, mode ); |
3348 | 3348 | ||
3349 | if (err == e_success) { | 3349 | if (err == e_success) { |
3350 | if ( manager->mWriteBackFile ){ | 3350 | if ( manager->mWriteBackFile ){ |
3351 | qDebug("Saving remote PWManager file"); | 3351 | qDebug("Saving remote PWManager file"); |
3352 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); | 3352 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3353 | if (err != e_success) { | 3353 | if (err != e_success) { |
3354 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); | 3354 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); |
3355 | return false; | 3355 | return false; |
3356 | } | 3356 | } |
3357 | } | 3357 | } |
3358 | 3358 | ||
3359 | flagDirty(); | 3359 | flagDirty(); |
3360 | return true; | 3360 | return true; |
3361 | } | 3361 | } |
3362 | else { | 3362 | else { |
3363 | return false; | 3363 | return false; |
3364 | } | 3364 | } |
3365 | } | 3365 | } |
3366 | 3366 | ||
3367 | #endif | 3367 | #endif |
3368 | 3368 | ||
3369 | 3369 | ||
3370 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3370 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3371 | { | 3371 | { |
3372 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3372 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3373 | end = dti.syncDta.end(); | 3373 | end = dti.syncDta.end(); |
3374 | 3374 | ||
3375 | while (i != end) { | 3375 | while (i != end) { |
3376 | if ((*i).syncName == syncname.latin1()) { | 3376 | if ((*i).syncName == syncname.latin1()) { |
3377 | if (index) { | 3377 | if (index) { |
3378 | *index = i - dti.syncDta.begin(); | 3378 | *index = i - dti.syncDta.begin(); |
3379 | } | 3379 | } |
3380 | return true; | 3380 | return true; |
3381 | } | 3381 | } |
3382 | ++i; | 3382 | ++i; |
3383 | } | 3383 | } |
3384 | return false; | 3384 | return false; |
3385 | }; | 3385 | }; |
3386 | 3386 | ||
3387 | /** add new syncdataentry */ | 3387 | /** add new syncdataentry */ |
3388 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3388 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3389 | { | 3389 | { |
3390 | PWM_ASSERT(d); | 3390 | PWM_ASSERT(d); |
3391 | 3391 | ||
3392 | if (isDeepLocked()) { | 3392 | if (isDeepLocked()) { |
3393 | PwMerror ret; | 3393 | PwMerror ret; |
3394 | ret = deepLock(false); | 3394 | ret = deepLock(false); |
3395 | if (ret != e_success) | 3395 | if (ret != e_success) |
3396 | return e_lock; | 3396 | return e_lock; |
3397 | } | 3397 | } |
3398 | unsigned int index; | 3398 | unsigned int index; |
3399 | 3399 | ||
3400 | const QString tmp = d->syncName.c_str(); | 3400 | const QString tmp = d->syncName.c_str(); |
3401 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3401 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3402 | 3402 | ||
3403 | if (exists == true) { | 3403 | if (exists == true) { |
3404 | // DOH! We found this entry. | 3404 | // DOH! We found this entry. |
3405 | return e_entryExists; | 3405 | return e_entryExists; |
3406 | } | 3406 | } |
3407 | 3407 | ||
3408 | dti.syncDta.push_back(*d); | 3408 | dti.syncDta.push_back(*d); |
3409 | 3409 | ||
3410 | if (!dontFlagDirty) | 3410 | if (!dontFlagDirty) |
3411 | flagDirty(); | 3411 | flagDirty(); |
3412 | return e_success; | 3412 | return e_success; |
3413 | } | 3413 | } |
3414 | 3414 | ||
3415 | 3415 | ||
3416 | 3416 | ||
3417 | /** delete syncdata entry */ | 3417 | /** delete syncdata entry */ |
3418 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3418 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3419 | { | 3419 | { |
3420 | if (isDeepLocked()) | 3420 | if (isDeepLocked()) |
3421 | return false; | 3421 | return false; |
3422 | if (index > dti.syncDta.size() - 1) | 3422 | if (index > dti.syncDta.size() - 1) |
3423 | return false; | 3423 | return false; |
3424 | 3424 | ||
3425 | // delete entry | 3425 | // delete entry |
3426 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3426 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3427 | 3427 | ||
3428 | if (!dontFlagDirty) | 3428 | if (!dontFlagDirty) |
3429 | flagDirty(); | 3429 | flagDirty(); |
3430 | return true; | 3430 | return true; |
3431 | } | 3431 | } |
3432 | 3432 | ||
3433 | 3433 | ||
3434 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3434 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3435 | { | 3435 | { |
3436 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3436 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3437 | catend = dti.dta.end(); | 3437 | catend = dti.dta.end(); |
3438 | 3438 | ||
3439 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3439 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3440 | 3440 | ||
3441 | while (catcounter != catend) { | 3441 | while (catcounter != catend) { |
3442 | entrBegin = catcounter->d.begin(); | 3442 | entrBegin = catcounter->d.begin(); |
3443 | entrEnd = catcounter->d.end(); | 3443 | entrEnd = catcounter->d.end(); |
3444 | entrI = entrBegin; | 3444 | entrI = entrBegin; |
3445 | while (entrI != entrEnd) { | 3445 | while (entrI != entrEnd) { |
3446 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3446 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3447 | if (category) | 3447 | if (category) |
3448 | *category = catcounter - dti.dta.begin(); | 3448 | *category = catcounter - dti.dta.begin(); |
3449 | if (index) | 3449 | if (index) |
3450 | *index = entrI - entrBegin; | 3450 | *index = entrI - entrBegin; |
3451 | 3451 | ||
3452 | return &(*entrI); | 3452 | return &(*entrI); |
3453 | } | 3453 | } |
3454 | ++entrI; | 3454 | ++entrI; |
3455 | } | 3455 | } |
3456 | ++catcounter; | 3456 | ++catcounter; |
3457 | } | 3457 | } |
3458 | 3458 | ||
3459 | return 0; | 3459 | return 0; |
3460 | } | 3460 | } |
3461 | 3461 | ||
3462 | QStringList PwMDoc::getIDEntryList() | 3462 | QStringList PwMDoc::getIDEntryList() |
3463 | { | 3463 | { |
3464 | QStringList results; | 3464 | QStringList results; |
3465 | 3465 | ||
3466 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3466 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3467 | catend = dti.dta.end(); | 3467 | catend = dti.dta.end(); |
3468 | 3468 | ||
3469 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3469 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3470 | 3470 | ||
3471 | while (catcounter != catend) { | 3471 | while (catcounter != catend) { |
3472 | entrBegin = catcounter->d.begin(); | 3472 | entrBegin = catcounter->d.begin(); |
3473 | entrEnd = catcounter->d.end(); | 3473 | entrEnd = catcounter->d.end(); |
3474 | entrI = entrBegin; | 3474 | entrI = entrBegin; |
3475 | while (entrI != entrEnd) { | 3475 | while (entrI != entrEnd) { |
3476 | results.append( (*entrI).meta.uniqueid.c_str() ); | 3476 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3477 | ++entrI; | 3477 | ++entrI; |
3478 | } | 3478 | } |
3479 | ++catcounter; | 3479 | ++catcounter; |
3480 | } | 3480 | } |
3481 | 3481 | ||
3482 | return results; | 3482 | return results; |
3483 | } | 3483 | } |
3484 | 3484 | ||
3485 | 3485 | ||
3486 | 3486 | ||
3487 | 3487 | ||
3488 | 3488 | ||
3489 | #ifndef PWM_EMBEDDED | 3489 | #ifndef PWM_EMBEDDED |
3490 | #include "pwmdoc.moc" | 3490 | #include "pwmdoc.moc" |
3491 | #endif | 3491 | #endif |