summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/blowfish.h11
-rw-r--r--pwmanager/pwmanager/gpasmanfile.cpp16
-rw-r--r--pwmanager/pwmanager/htmlgen.cpp2
-rw-r--r--pwmanager/pwmanager/ipc.cpp7
-rw-r--r--pwmanager/pwmanager/ipc.h5
-rw-r--r--pwmanager/pwmanager/libgcryptif.h7
-rw-r--r--pwmanager/pwmanager/pwm.cpp1
-rw-r--r--pwmanager/pwmanager/pwmanager.pro2
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp9
-rw-r--r--pwmanager/pwmanager/spinforsignal.h2
10 files changed, 50 insertions, 12 deletions
diff --git a/pwmanager/pwmanager/blowfish.h b/pwmanager/pwmanager/blowfish.h
index c05de77..5129eab 100644
--- a/pwmanager/pwmanager/blowfish.h
+++ b/pwmanager/pwmanager/blowfish.h
@@ -1,120 +1,129 @@
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 * blowfish.c - Blowfish encryption * 6 * blowfish.c - Blowfish encryption *
7 * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * 7 * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. *
8 * * 8 * *
9 * This program is free software; you can redistribute it and/or modify * 9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 * 10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. * 11 * as published by the Free Software Foundation. *
12 * * 12 * *
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15/*************************************************************************** 15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk 16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager 17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde 18 * and was modified to run on embedded devices that run microkde
19 * 19 *
20 * $Id$ 20 * $Id$
21 **************************************************************************/ 21 **************************************************************************/
22 22
23#ifndef BLOWFISH_H 23#ifndef BLOWFISH_H
24#define BLOWFISH_H 24#define BLOWFISH_H
25 25
26#include "pwmexception.h" 26#include "pwmexception.h"
27 27#ifndef _WIN32_
28#include <stdint.h> 28#include <stdint.h>
29#else
30
31#endif
29#include <string> 32#include <string>
30using std::string; 33using std::string;
31 34
32 #define BLOWFISH_BLOCKSIZE8 35 #define BLOWFISH_BLOCKSIZE8
33 #define BLOWFISH_ROUNDS 16 36 #define BLOWFISH_ROUNDS 16
34 #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */ 37 #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */
35 38
39#ifndef _WIN32_
36 typedef uint8_t byte; 40 typedef uint8_t byte;
41#else
42#define uint8_t Q_UINT8
43#define byte Q_UINT8
44#define uint32_t Q_UINT32
45#endif
37 46
38/** blowfish encryption algorithm. 47/** blowfish encryption algorithm.
39 * Derived from libgcrypt-1.1.12 48 * Derived from libgcrypt-1.1.12
40 */ 49 */
41class Blowfish 50class Blowfish
42{ 51{
43 struct BLOWFISH_context 52 struct BLOWFISH_context
44 { 53 {
45 uint32_t s0[256]; 54 uint32_t s0[256];
46 uint32_t s1[256]; 55 uint32_t s1[256];
47 uint32_t s2[256]; 56 uint32_t s2[256];
48 uint32_t s3[256]; 57 uint32_t s3[256];
49 uint32_t p[BLOWFISH_ROUNDS+2]; 58 uint32_t p[BLOWFISH_ROUNDS+2];
50 }; 59 };
51 60
52public: 61public:
53 Blowfish() {} 62 Blowfish() {}
54 static bool selfTest(); 63 static bool selfTest();
55 64
56 /** set key to encrypt. if return == 1, it is a weak key. */ 65 /** set key to encrypt. if return == 1, it is a weak key. */
57 int bf_setkey( byte *key, unsigned int keylen ); 66 int bf_setkey( byte *key, unsigned int keylen );
58 /** encrypt inbuf and return it in outbuf. 67 /** encrypt inbuf and return it in outbuf.
59 * inbuf and outbuf have to be: buf % 8 == 0 68 * inbuf and outbuf have to be: buf % 8 == 0
60 * You may check this with getPaddedLen() and pad with NULL. 69 * You may check this with getPaddedLen() and pad with NULL.
61 */ 70 */
62 int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); 71 int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
63 /** decrypt inbuf and return it in outbuf. 72 /** decrypt inbuf and return it in outbuf.
64 * inbuf and outbuf have to be: buf % 8 == 0 73 * inbuf and outbuf have to be: buf % 8 == 0
65 * You may check this with getPaddedLen() and pad with NULL. 74 * You may check this with getPaddedLen() and pad with NULL.
66 */ 75 */
67 int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); 76 int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
68 /** returns the length, the sting has to be padded to */ 77 /** returns the length, the sting has to be padded to */
69 static unsigned int getPaddedLen(unsigned int inLen) 78 static unsigned int getPaddedLen(unsigned int inLen)
70 { return ((8 - (inLen % 8)) + inLen); } 79 { return ((8 - (inLen % 8)) + inLen); }
71 /** pad up to 8 bytes. */ 80 /** pad up to 8 bytes. */
72 static void padNull(string *buf); 81 static void padNull(string *buf);
73 /** remove padded data */ 82 /** remove padded data */
74 static bool unpadNull(string *buf); 83 static bool unpadNull(string *buf);
75 84
76protected: 85protected:
77#if BLOWFISH_ROUNDS != 16 86#if BLOWFISH_ROUNDS != 16
78 uint32_t function_F( uint32_t x) 87 uint32_t function_F( uint32_t x)
79 { 88 {
80 uint16_t a, b, c, d; 89 uint16_t a, b, c, d;
81 #ifdef BIG_ENDIAN_HOST 90 #ifdef BIG_ENDIAN_HOST
82 a = ((byte *) & x)[0]; 91 a = ((byte *) & x)[0];
83 b = ((byte *) & x)[1]; 92 b = ((byte *) & x)[1];
84 c = ((byte *) & x)[2]; 93 c = ((byte *) & x)[2];
85 d = ((byte *) & x)[3]; 94 d = ((byte *) & x)[3];
86 #else 95 #else
87 a = ((byte *) & x)[3]; 96 a = ((byte *) & x)[3];
88 b = ((byte *) & x)[2]; 97 b = ((byte *) & x)[2];
89 c = ((byte *) & x)[1]; 98 c = ((byte *) & x)[1];
90 d = ((byte *) & x)[0]; 99 d = ((byte *) & x)[0];
91 #endif 100 #endif
92 return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d]; 101 return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d];
93 } 102 }
94#endif 103#endif
95 void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p, 104 void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p,
96 uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3) 105 uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3)
97 { 106 {
98 l ^= p[i]; 107 l ^= p[i];
99 #ifdef BIG_ENDIAN_HOST 108 #ifdef BIG_ENDIAN_HOST
100 r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]]) 109 r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]])
101 ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]]; 110 ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]];
102 #else 111 #else
103 r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]]) 112 r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]])
104 ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]]; 113 ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]];
105 #endif 114 #endif
106 } 115 }
107 void encrypt_block(byte *outbuf, byte *inbuf); 116 void encrypt_block(byte *outbuf, byte *inbuf);
108 void decrypt_block(byte *outbuf, byte *inbuf); 117 void decrypt_block(byte *outbuf, byte *inbuf);
109 void burn_stack(int bytes); 118 void burn_stack(int bytes);
110 void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr); 119 void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr);
111 void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr); 120 void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr);
112 void do_encrypt_block(byte *outbuf, byte *inbuf); 121 void do_encrypt_block(byte *outbuf, byte *inbuf);
113 void do_decrypt_block(byte *outbuf, byte *inbuf); 122 void do_decrypt_block(byte *outbuf, byte *inbuf);
114 int do_bf_setkey(byte *key, unsigned int keylen); 123 int do_bf_setkey(byte *key, unsigned int keylen);
115 124
116protected: 125protected:
117 struct BLOWFISH_context bc; 126 struct BLOWFISH_context bc;
118}; 127};
119 128
120#endif 129#endif
diff --git a/pwmanager/pwmanager/gpasmanfile.cpp b/pwmanager/pwmanager/gpasmanfile.cpp
index f80bc13..ae34c83 100644
--- a/pwmanager/pwmanager/gpasmanfile.cpp
+++ b/pwmanager/pwmanager/gpasmanfile.cpp
@@ -1,437 +1,447 @@
1/* Gpasman, a password manager 1/* Gpasman, a password manager
2 Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl 2 Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl
3 3
4 file.c, handles file opening and closing 4 file.c, handles file opening and closing
5 5
6 Other code contributors: 6 Other code contributors:
7 Dave Rudder 7 Dave Rudder
8 Chris Halverson 8 Chris Halverson
9 Matthew Palmer 9 Matthew Palmer
10 Guide Berning 10 Guide Berning
11 Jimmy Mason 11 Jimmy Mason
12 website at http://www.student.wau.nl/~olivier/gpasman/ 12 website at http://www.student.wau.nl/~olivier/gpasman/
13 13
14 This program is free software; you can redistribute it and/or modify 14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or 16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version. 17 (at your option) any later version.
18 18
19 This program is distributed in the hope that it will be useful, 19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details. 22 GNU General Public License for more details.
23 23
24 You should have received a copy of the GNU General Public License 24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software 25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27*/ 27*/
28 28
29/* 2003/06/10: 29/* 2003/06/10:
30 * modified by Michael Buesch to work together 30 * modified by Michael Buesch to work together
31 * with PwM as import/export module. 31 * with PwM as import/export module.
32 */ 32 */
33 33
34/*************************************************************************** 34/***************************************************************************
35 * copyright (C) 2004 by Ulf Schenk 35 * copyright (C) 2004 by Ulf Schenk
36 * This file is originaly based on version 1.0.1 of pwmanager 36 * This file is originaly based on version 1.0.1 of pwmanager
37 * and was modified to run on embedded devices that run microkde 37 * and was modified to run on embedded devices that run microkde
38 * 38 *
39 * $Id$ 39 * $Id$
40 **************************************************************************/ 40 **************************************************************************/
41 41
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <fcntl.h> 45#include <fcntl.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#ifndef _WIN32_
47#include <unistd.h> 48#include <unistd.h>
49#else
50#include <io.h>
51#define S_IRUSR _S_IREAD
52#define S_IWUSR _S_IWRITE
53#define creat _creat
54#endif
48#include <string.h> 55#include <string.h>
49#include <errno.h> 56#include <errno.h>
50 57
51#include "gpasmanfile.h" 58#include "gpasmanfile.h"
52#include "globalstuff.h" 59#include "globalstuff.h"
53 60
54#define SAVE_BUFFER_LENGTH 1024 61#define SAVE_BUFFER_LENGTH 1024
55#define LOAD_BUFFER_LENGTH 2048 62#define LOAD_BUFFER_LENGTH 2048
56 63
57#ifndef S_IAMB 64#ifndef S_IAMB
58#define S_IAMB 00777 65#define S_IAMB 00777
59#endif 66#endif
60 67
61// enable/disable debug output 68// enable/disable debug output
62//#define GPASMANFILE_DEBUG 69//#define GPASMANFILE_DEBUG
63#undef GPASMANFILE_DEBUG 70#undef GPASMANFILE_DEBUG
64 71
65 72#ifndef _WIN32_
66#if defined(PWM_DEBUG) && defined(GPASMANFILE_DEBUG) 73#if defined(PWM_DEBUG) && defined(GPASMANFILE_DEBUG)
67 # define DBG(msg,x...)do { fprintf(stderr, msg "\n" , ##x); } while (0) 74 # define DBG(msg,x...)do { fprintf(stderr, msg "\n" , ##x); } while (0)
68#else 75#else
69 # define DBG(msg,x...)do { } while (0) 76 # define DBG(msg,x...)do { } while (0)
70#endif 77#endif
78#else
79# define DBG
80#endif
71 81
72#ifdef BIG_ENDIAN_HOST 82#ifdef BIG_ENDIAN_HOST
73# define WORDS_BIGENDIAN 83# define WORDS_BIGENDIAN
74#else 84#else
75# undef WORDS_BIGENDIAN 85# undef WORDS_BIGENDIAN
76#endif 86#endif
77 87
78 88
79GpasmanFile::GpasmanFile() 89GpasmanFile::GpasmanFile()
80{ 90{
81} 91}
82 92
83GpasmanFile::~GpasmanFile() 93GpasmanFile::~GpasmanFile()
84{ 94{
85} 95}
86 96
87int GpasmanFile::save_init(const char *filename, const char *password) 97int GpasmanFile::save_init(const char *filename, const char *password)
88{ 98{
89 99
90/* 100/*
91 * returncodes: 101 * returncodes:
92 * 1 = success 102 * 1 = success
93 * 0 = can't open filedescriptor / can't create file 103 * 0 = can't open filedescriptor / can't create file
94 * -1 = permissions are bad 104 * -1 = permissions are bad
95 * -2 = is a symlink 105 * -2 = is a symlink
96 * -3 = can't get file status 106 * -3 = can't get file status
97 */ 107 */
98 108
99 unsigned char key[128]; 109 unsigned char key[128];
100 unsigned int j = 0; 110 unsigned int j = 0;
101 unsigned int keylength; 111 unsigned int keylength;
102 int val, count2; 112 int val, count2;
103 113
104 /* first we should check the permissions of the filename */ 114 /* first we should check the permissions of the filename */
105 115
106 if (file_exists(filename)) { 116 if (file_exists(filename)) {
107 val = check_file(filename); 117 val = check_file(filename);
108 if (val != 1) { 118 if (val != 1) {
109 DBG("save_init, return %d", val); 119 DBG("save_init, return %d", val);
110 return val; 120 return val;
111 } 121 }
112 } else { 122 } else {
113 val = creat(filename, (S_IRUSR | S_IWUSR)); 123 val = creat(filename, (S_IRUSR | S_IWUSR));
114 if (val == -1) { 124 if (val == -1) {
115 DBG("%s", "save_init, return 0"); 125 DBG("%s", "save_init, return 0");
116 return 0; 126 return 0;
117 } else { 127 } else {
118 close(val); 128 close(val);
119 } 129 }
120 } 130 }
121 131
122 fd = fopen(filename, "wb"); 132 fd = fopen(filename, "wb");
123 if (fd == NULL) { 133 if (fd == NULL) {
124 return 0; 134 return 0;
125 } 135 }
126 buffer = (char*)malloc(SAVE_BUFFER_LENGTH); 136 buffer = (char*)malloc(SAVE_BUFFER_LENGTH);
127 137
128 /* make the key ready */ 138 /* make the key ready */
129 DBG("save_init, password=%s", password); 139 DBG("save_init, password=%s", password);
130 for (j = 0; password[j] != '\0'; j++) { 140 for (j = 0; password[j] != '\0'; j++) {
131 key[j] = password[j]; 141 key[j] = password[j];
132 } 142 }
133 keylength = j; 143 keylength = j;
134 rc2.rc2_expandkey((char*)key, (int)keylength, 128); 144 rc2.rc2_expandkey((char*)key, (int)keylength, 128);
135 145
136 /* First, we make the IV */ 146 /* First, we make the IV */
137 for (count2 = 0; count2 < 4; count2++) { 147 for (count2 = 0; count2 < 4; count2++) {
138 iv[count2] = rand(); 148 iv[count2] = rand();
139 putc((unsigned char) (iv[count2] >> 8), fd); 149 putc((unsigned char) (iv[count2] >> 8), fd);
140 putc((unsigned char) (iv[count2] & 0xff), fd); 150 putc((unsigned char) (iv[count2] & 0xff), fd);
141 } 151 }
142 152
143 bufferIndex = 0; 153 bufferIndex = 0;
144 return 1; 154 return 1;
145} 155}
146 156
147int GpasmanFile::save_entry(char *entry[4]) 157int GpasmanFile::save_entry(char *entry[4])
148{ 158{
149 159
150 char *text1; 160 char *text1;
151 int count2, count3; 161 int count2, count3;
152 unsigned short ciphertext[4]; 162 unsigned short ciphertext[4];
153 163
154 buffer = (char*)memset(buffer, '\0', SAVE_BUFFER_LENGTH); 164 buffer = (char*)memset(buffer, '\0', SAVE_BUFFER_LENGTH);
155 165
156 for (count2 = 0; count2 < 4; count2++) { 166 for (count2 = 0; count2 < 4; count2++) {
157 text1 = entry[count2]; 167 text1 = entry[count2];
158 if (strlen(text1) == 0) { 168 if (strlen(text1) == 0) {
159 strncpy(text1, " ", strlen(" ")); 169 strncpy(text1, " ", strlen(" "));
160 } 170 }
161 strncat(buffer, text1, strlen(text1)); 171 strncat(buffer, text1, strlen(text1));
162 /* Use 255 as the marker. \n is too tough to test for */ 172 /* Use 255 as the marker. \n is too tough to test for */
163 buffer[strlen(buffer)] = 255; 173 buffer[strlen(buffer)] = 255;
164 174
165 } /*for (count2 = 0; count2 < 4; count2++) */ 175 } /*for (count2 = 0; count2 < 4; count2++) */
166 DBG("save_entry, buffer contains %s", buffer); 176 DBG("save_entry, buffer contains %s", buffer);
167 count2 = 0; 177 count2 = 0;
168 /* I'm using CBC mode and encrypting the data straight from top down. 178 /* I'm using CBC mode and encrypting the data straight from top down.
169 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 179 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
170 * PKCS 5 padding (explained at the code section 180 * PKCS 5 padding (explained at the code section
171 */ 181 */
172 while (count2 < (int)strlen(buffer)) { 182 while (count2 < (int)strlen(buffer)) {
173#ifndef WORDS_BIGENDIAN 183#ifndef WORDS_BIGENDIAN
174 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 184 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
175 plaintext[bufferIndex] += buffer[count2] & 0xff; 185 plaintext[bufferIndex] += buffer[count2] & 0xff;
176#else 186#else
177 plaintext[bufferIndex] = buffer[count2] << 8; 187 plaintext[bufferIndex] = buffer[count2] << 8;
178 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 188 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
179#endif 189#endif
180 bufferIndex++; 190 bufferIndex++;
181 if (bufferIndex == 4) { 191 if (bufferIndex == 4) {
182 rc2.rc2_encrypt(plaintext); 192 rc2.rc2_encrypt(plaintext);
183 193
184 for (count3 = 0; count3 < 4; count3++) { 194 for (count3 = 0; count3 < 4; count3++) {
185 ciphertext[count3] = 195 ciphertext[count3] =
186 iv[count3] ^ plaintext[count3]; 196 iv[count3] ^ plaintext[count3];
187 197
188 /* Now store the ciphertext as the iv */ 198 /* Now store the ciphertext as the iv */
189 iv[count3] = plaintext[count3]; 199 iv[count3] = plaintext[count3];
190 200
191 /* reset the buffer index */ 201 /* reset the buffer index */
192 bufferIndex = 0; 202 bufferIndex = 0;
193 if (putc 203 if (putc
194 ((unsigned char) (ciphertext[count3] >> 8), 204 ((unsigned char) (ciphertext[count3] >> 8),
195 fd) == EOF) 205 fd) == EOF)
196 return -1; 206 return -1;
197 if (putc 207 if (putc
198 ((unsigned char) (ciphertext[count3] & 208 ((unsigned char) (ciphertext[count3] &
199 0xff), fd) == EOF) 209 0xff), fd) == EOF)
200 return -1; 210 return -1;
201 }/*for (count3 = 0; count3 < 4; count3++) */ 211 }/*for (count3 = 0; count3 < 4; count3++) */
202 } 212 }
203 /*if (bufferIndex == 4) */ 213 /*if (bufferIndex == 4) */
204 /* increment a short, not a byte */ 214 /* increment a short, not a byte */
205 count2 += 2; 215 count2 += 2;
206 } /*while (count2 < strlen (buffer)) */ 216 } /*while (count2 < strlen (buffer)) */
207 return 1; 217 return 1;
208} 218}
209 219
210int GpasmanFile::save_finalize(void) 220int GpasmanFile::save_finalize(void)
211{ 221{
212 222
213 int count1, retval = 1; 223 int count1, retval = 1;
214 unsigned short ciphertext[4]; 224 unsigned short ciphertext[4];
215 225
216 /* Tack on the PKCS 5 padding 226 /* Tack on the PKCS 5 padding
217 How it works is we fill up the last n bytes with the value n 227 How it works is we fill up the last n bytes with the value n
218 228
219 So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 229 So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
220 over, leaving us 3 short, so we fill it in with 3's. 230 over, leaving us 3 short, so we fill it in with 3's.
221 231
222 If we come out even, we fill it with 8 8s 232 If we come out even, we fill it with 8 8s
223 233
224 um, except that in this instance we are using 4 shorts instead of 8 bytes. 234 um, except that in this instance we are using 4 shorts instead of 8 bytes.
225 so, half everything 235 so, half everything
226 */ 236 */
227 for (count1 = bufferIndex; count1 < 4; count1++) { 237 for (count1 = bufferIndex; count1 < 4; count1++) {
228 plaintext[count1] = (4 - bufferIndex); 238 plaintext[count1] = (4 - bufferIndex);
229 } 239 }
230 DBG("save_finalize, 4 - bufferIndex = %d", 240 DBG("save_finalize, 4 - bufferIndex = %d",
231 4 - bufferIndex); 241 4 - bufferIndex);
232 DBG("save_finalize, plaintext[3]=%c", plaintext[3]); 242 DBG("save_finalize, plaintext[3]=%c", plaintext[3]);
233 rc2.rc2_encrypt(plaintext); 243 rc2.rc2_encrypt(plaintext);
234 for (count1 = 0; count1 < 4; count1++) { 244 for (count1 = 0; count1 < 4; count1++) {
235 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 245 ciphertext[count1] = iv[count1] ^ plaintext[count1];
236 if (putc((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) 246 if (putc((unsigned char) (ciphertext[count1] >> 8), fd) == EOF)
237 retval = -1; 247 retval = -1;
238 if (putc((unsigned char) (ciphertext[count1] & 0xff), fd) == 248 if (putc((unsigned char) (ciphertext[count1] & 0xff), fd) ==
239 EOF) 249 EOF)
240 retval = -1; 250 retval = -1;
241 } 251 }
242 252
243 fclose(fd); 253 fclose(fd);
244 DBG("%s", "save_finalize, fd is closed"); 254 DBG("%s", "save_finalize, fd is closed");
245 free(buffer); 255 free(buffer);
246 return retval; 256 return retval;
247 257
248} 258}
249 259
250int GpasmanFile::load_init(const char *filename, const char *password) 260int GpasmanFile::load_init(const char *filename, const char *password)
251{ 261{
252/* 262/*
253 * returncodes: 263 * returncodes:
254 * 1 = success 264 * 1 = success
255 * 0 = can't open filedescriptor / can't create file 265 * 0 = can't open filedescriptor / can't create file
256 * -1 = permissions are bad 266 * -1 = permissions are bad
257 * -2 = is a symlink 267 * -2 = is a symlink
258 * -3 = can't get file status 268 * -3 = can't get file status
259 */ 269 */
260 unsigned int j = 0; 270 unsigned int j = 0;
261 unsigned int keylength = 0; 271 unsigned int keylength = 0;
262 int count = 0, count2 = 0, count3 = 0; 272 int count = 0, count2 = 0, count3 = 0;
263 unsigned char charbuf[8]; 273 unsigned char charbuf[8];
264 unsigned short ciphertext[4]; 274 unsigned short ciphertext[4];
265 int val = 0; 275 int val = 0;
266 unsigned char key[128]; 276 unsigned char key[128];
267 277
268 /* first we should check the file permissions */ 278 /* first we should check the file permissions */
269 if (file_exists(filename)) { 279 if (file_exists(filename)) {
270 val = check_file(filename); 280 val = check_file(filename);
271 if (val != 1) { 281 if (val != 1) {
272 return val; 282 return val;
273 } 283 }
274 } else { 284 } else {
275 return 0; 285 return 0;
276 } 286 }
277 287
278 fd = fopen(filename, "rb"); 288 fd = fopen(filename, "rb");
279 if (fd == NULL) { 289 if (fd == NULL) {
280 return 0; 290 return 0;
281 } 291 }
282 292
283 buffer = (char*)malloc(LOAD_BUFFER_LENGTH); 293 buffer = (char*)malloc(LOAD_BUFFER_LENGTH);
284 DBG("load_init, password=\"%s\"", password); 294 DBG("load_init, password=\"%s\"", password);
285 for (j = 0; password[j] != '\0'; j++) { 295 for (j = 0; password[j] != '\0'; j++) {
286 key[j] = password[j]; 296 key[j] = password[j];
287 } 297 }
288 keylength = j; 298 keylength = j;
289 rc2.rc2_expandkey((char*)key, (int)keylength, 128); 299 rc2.rc2_expandkey((char*)key, (int)keylength, 128);
290 300
291 size = read(fileno(fd), (unsigned char *) (charbuf + count), 8); 301 size = read(fileno(fd), (unsigned char *) (charbuf + count), 8);
292 DBG("load_init, size=%d, keylength=%d", size, keylength); 302 DBG("load_init, size=%d, keylength=%d", size, keylength);
293 303
294 if (size < 8) { 304 if (size < 8) {
295 fclose(fd); 305 fclose(fd);
296 free(buffer); 306 free(buffer);
297 return -1; 307 return -1;
298 } 308 }
299 309
300 for (count = 0; count < 4; count++) { 310 for (count = 0; count < 4; count++) {
301 count2 = count << 1; 311 count2 = count << 1;
302 iv[count] = charbuf[count2] << 8; 312 iv[count] = charbuf[count2] << 8;
303 iv[count] += charbuf[count2 + 1]; 313 iv[count] += charbuf[count2 + 1];
304 DBG("load_init iv[%d]=%d", count, iv[count]); 314 DBG("load_init iv[%d]=%d", count, iv[count]);
305 } 315 }
306 316
307 size = 0; 317 size = 0;
308 bufferIndex = 0; 318 bufferIndex = 0;
309 while ((count = read(fileno(fd), (unsigned char *) charbuf, 8)) > 0) { 319 while ((count = read(fileno(fd), (unsigned char *) charbuf, 8)) > 0) {
310 DBG("load_init A, count=%d, count2=%d", count, count2); 320 DBG("load_init A, count=%d, count2=%d", count, count2);
311 while (count < 8) { 321 while (count < 8) {
312 count2 = read(fileno(fd), (unsigned char *) (charbuf + 322 count2 = read(fileno(fd), (unsigned char *) (charbuf +
313 count), 8); 323 count), 8);
314 DBG("load_init B, count=%d, count2=%d", 324 DBG("load_init B, count=%d, count2=%d",
315 count, count2); 325 count, count2);
316 if (count2 == 0) { 326 if (count2 == 0) {
317 printf("bad EOF\n"); 327 printf("bad EOF\n");
318 fclose(fd); 328 fclose(fd);
319 free(buffer); 329 free(buffer);
320 return -1; 330 return -1;
321 } 331 }
322 count += count2; 332 count += count2;
323 } /* while (count < 8) */ 333 } /* while (count < 8) */
324 334
325 size += 8; 335 size += 8;
326 DBG("load_init charbuf[1]=%c", charbuf[1]); 336 DBG("load_init charbuf[1]=%c", charbuf[1]);
327 for (count2 = 0; count2 < 8; count2 += 2) { 337 for (count2 = 0; count2 < 8; count2 += 2) {
328 count3 = count2 >> 1; 338 count3 = count2 >> 1;
329 ciphertext[count3] = charbuf[count2] << 8; 339 ciphertext[count3] = charbuf[count2] << 8;
330 ciphertext[count3] += charbuf[count2 + 1]; 340 ciphertext[count3] += charbuf[count2 + 1];
331 341
332 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 342 plaintext[count3] = ciphertext[count3] ^ iv[count3];
333 iv[count3] = plaintext[count3]; 343 iv[count3] = plaintext[count3];
334 } 344 }
335 345
336 rc2.rc2_decrypt(plaintext); 346 rc2.rc2_decrypt(plaintext);
337 memcpy((unsigned char *) (buffer + bufferIndex), plaintext, 8); 347 memcpy((unsigned char *) (buffer + bufferIndex), plaintext, 8);
338 bufferIndex += 8; 348 bufferIndex += 8;
339 buffer[bufferIndex + 1] = '\0'; 349 buffer[bufferIndex + 1] = '\0';
340 DBG("bufferIndex=%d, buffer=%s", bufferIndex, 350 DBG("bufferIndex=%d, buffer=%s", bufferIndex,
341 buffer); 351 buffer);
342 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 352 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
343 DBG("load_init, size=%d, buffer[size-1]=%d,", size, 353 DBG("load_init, size=%d, buffer[size-1]=%d,", size,
344 buffer[size - 1]); 354 buffer[size - 1]);
345 size -= buffer[size - 1]; 355 size -= buffer[size - 1];
346 DBG("size=%d", size); 356 DBG("size=%d", size);
347 lastcount = 0; 357 lastcount = 0;
348 358
349 /* This will point to the starting index */ 359 /* This will point to the starting index */
350 bufferIndex = 0; 360 bufferIndex = 0;
351 return 1; 361 return 1;
352} 362}
353 363
354int GpasmanFile::load_entry(char *entry[4]) 364int GpasmanFile::load_entry(char *entry[4])
355{ 365{
356/* Strip off PKCS 5 padding 366/* Strip off PKCS 5 padding
357 Should check to make sure it's good here 367 Should check to make sure it's good here
358 */ 368 */
359 int count, count1 = 0; 369 int count, count1 = 0;
360 DBG("load_entry, lastcount=%d, size=%d, entry=%p", 370 DBG("load_entry, lastcount=%d, size=%d, entry=%p",
361 lastcount, size, entry); 371 lastcount, size, entry);
362 372
363 for (count = lastcount; count < size; count++) { 373 for (count = lastcount; count < size; count++) {
364 if ((unsigned char) (buffer[count]) == 255) { 374 if ((unsigned char) (buffer[count]) == 255) {
365 if (buffer[bufferIndex] == '\0') { 375 if (buffer[bufferIndex] == '\0') {
366 bufferIndex++; 376 bufferIndex++;
367 } 377 }
368 entry[count1] = 378 entry[count1] =
369 (char *) malloc(count - bufferIndex + 1); 379 (char *) malloc(count - bufferIndex + 1);
370 DBG("load_entry, entry[%d]=%p", count1, 380 DBG("load_entry, entry[%d]=%p", count1,
371 entry[count1]); 381 entry[count1]);
372 memcpy(entry[count1], 382 memcpy(entry[count1],
373 (unsigned char *) (buffer + bufferIndex), 383 (unsigned char *) (buffer + bufferIndex),
374 count - bufferIndex); 384 count - bufferIndex);
375 entry[count1][count - bufferIndex] = '\0'; 385 entry[count1][count - bufferIndex] = '\0';
376 DBG("load_entry, entry[%d]=%s", count1, 386 DBG("load_entry, entry[%d]=%s", count1,
377 entry[count1]); 387 entry[count1]);
378 count++; 388 count++;
379 bufferIndex = count; 389 bufferIndex = count;
380 count1++; 390 count1++;
381 if (count1 == 4) { 391 if (count1 == 4) {
382 lastcount = count; 392 lastcount = count;
383 DBG("%s", "load_entry, return 1, entry ready"); 393 DBG("%s", "load_entry, return 1, entry ready");
384 return 1; 394 return 1;
385 } 395 }
386 } /* if ((unsigned char) (buffer[count]) == 255) */ 396 } /* if ((unsigned char) (buffer[count]) == 255) */
387 } /* for (count = 0; count < size; count++) */ 397 } /* for (count = 0; count < size; count++) */
388 398
389 DBG("%s", "load_entry, ended no entry anymore"); 399 DBG("%s", "load_entry, ended no entry anymore");
390 return 2; 400 return 2;
391} 401}
392 402
393void GpasmanFile::load_finalize(void) 403void GpasmanFile::load_finalize(void)
394{ 404{
395 fclose(fd); 405 fclose(fd);
396 free(buffer); 406 free(buffer);
397} 407}
398 408
399int GpasmanFile::check_file(const char *filename) 409int GpasmanFile::check_file(const char *filename)
400{ 410{
401 struct stat naamstat; 411 struct stat naamstat;
402 412
403 if (stat(filename, &naamstat) == -1) { 413 if (stat(filename, &naamstat) == -1) {
404 return (-3); 414 return (-3);
405 } 415 }
406 416
407 if (((naamstat.st_mode & S_IAMB) | (S_IRUSR | S_IWUSR)) != (S_IRUSR | 417 if (((naamstat.st_mode & S_IAMB) | (S_IRUSR | S_IWUSR)) != (S_IRUSR |
408 S_IWUSR)) { 418 S_IWUSR)) {
409 DBG("%s perms are bad, they are: %ld, should be -rw------", 419 DBG("%s perms are bad, they are: %ld, should be -rw------",
410 filename, (naamstat.st_mode & (S_IREAD | S_IWRITE))); 420 filename, (naamstat.st_mode & (S_IREAD | S_IWRITE)));
411 return (-1); 421 return (-1);
412 } 422 }
413 423#ifndef _WIN32_
414 if (!S_ISREG(naamstat.st_mode)) { 424 if (!S_ISREG(naamstat.st_mode)) {
415 lstat(filename, &naamstat); 425 lstat(filename, &naamstat);
416 if (S_ISLNK(naamstat.st_mode)) { 426 if (S_ISLNK(naamstat.st_mode)) {
417 DBG("%s is a symlink", filename); 427 DBG("%s is a symlink", filename);
418 return (-2); 428 return (-2);
419 } 429 }
420 } 430 }
421 431#endif
422 return (1); 432 return (1);
423} 433}
424 434
425int GpasmanFile::file_exists(const char *tfile) 435int GpasmanFile::file_exists(const char *tfile)
426{ 436{
427 struct stat naamstat; 437 struct stat naamstat;
428 438
429 if ((stat(tfile, &naamstat) == -1) && (errno == ENOENT)) { 439 if ((stat(tfile, &naamstat) == -1) && (errno == ENOENT)) {
430 DBG("file_exists, %s does NOT exist", tfile); 440 DBG("file_exists, %s does NOT exist", tfile);
431 return (0); 441 return (0);
432 } else { 442 } else {
433 DBG("file_exists, %s DOES exist", tfile); 443 DBG("file_exists, %s DOES exist", tfile);
434 return (1); 444 return (1);
435 } 445 }
436} 446}
437 447
diff --git a/pwmanager/pwmanager/htmlgen.cpp b/pwmanager/pwmanager/htmlgen.cpp
index 166b987..bee8198 100644
--- a/pwmanager/pwmanager/htmlgen.cpp
+++ b/pwmanager/pwmanager/htmlgen.cpp
@@ -1,248 +1,248 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.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 "htmlgen.h" 20#include "htmlgen.h"
21#include "pwmexception.h" 21#include "pwmexception.h"
22 22
23#include <kstandarddirs.h> 23#include <kstandarddirs.h>
24 24
25/** enable/disable HTML-generator debugging (0/1) */ 25/** enable/disable HTML-generator debugging (0/1) */
26 #define HTMLGEN_DEBUG0 26 #define HTMLGEN_DEBUG0
27 27
28 28
29 #define HTML_DOCTYPE_HDR"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" 29 #define HTML_DOCTYPE_HDR"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
30 #define HTML_PWM_HDR "<!-- PwManager generated HTML -->" 30 #define HTML_PWM_HDR "<!-- PwManager generated HTML -->"
31 #define HTML_COMMENT_HDR"<!-- type: comment -->" 31 #define HTML_COMMENT_HDR"<!-- type: comment -->"
32 #define HTML_COMMENTVER_HDR"<!-- ver: 0.1 -->" 32 #define HTML_COMMENTVER_HDR"<!-- ver: 0.1 -->"
33 #define HTML_STYLESHEET_DUMMY"@STYLESHEET@" 33 #define HTML_STYLESHEET_DUMMY"@STYLESHEET@"
34 #define HTML_GLOBTBL_CLASS"\"globtable\"" 34 #define HTML_GLOBTBL_CLASS"\"globtable\""
35 #define HTML_GLOBTITLE_CLASS"\"globtitle\"" 35 #define HTML_GLOBTITLE_CLASS"\"globtitle\""
36 #define HTML_SUBTBL_CLASS"\"subtable\"" 36 #define HTML_SUBTBL_CLASS"\"subtable\""
37 #define HTML_SUBTITLE_CLASS"\"subtitle\"" 37 #define HTML_SUBTITLE_CLASS"\"subtitle\""
38 #define HTML_ENTRY_CLASS"\"entry\"" 38 #define HTML_ENTRY_CLASS"\"entry\""
39 #define HTML_VALUE_CLASS"\"value\"" 39 #define HTML_VALUE_CLASS"\"value\""
40 #define PATH_COMMENTSTYLE_CSS"pwmanager/html/htmlcomment_style.css" 40 #define PATH_COMMENTSTYLE_CSS"pwmanager/html/htmlcomment_style.css"
41#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 41#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0
42 #define HTML_ENDL "\n" 42 #define HTML_ENDL "\n"
43#else // defined(PWM_DEBUG) && ... 43#else // defined(PWM_DEBUG) && ...
44 #define HTML_ENDL "" 44 #define HTML_ENDL ""
45#endif // defined(PWM_DEBUG) && ... 45#endif // defined(PWM_DEBUG) && ...
46 46
47 47
48HtmlGen::HtmlGen() 48HtmlGen::HtmlGen()
49{ 49{
50 useSSDummy = true; 50 useSSDummy = true;
51} 51}
52 52
53HtmlGen::~HtmlGen() 53HtmlGen::~HtmlGen()
54{ 54{
55} 55}
56 56
57QString HtmlGen::escapeHtmlText(const QString &str) 57QString HtmlGen::escapeHtmlText(const QString &str)
58{ 58{
59 QString ret; 59 QString ret;
60 unsigned int len = str.length(), i; 60 unsigned int len = str.length(), i;
61 char c; 61 char c;
62 for (i = 0; i < len; ++i) { 62 for (i = 0; i < len; ++i) {
63 c = str[i]; 63 c = str.at(i);
64 switch (c) { 64 switch (c) {
65 case '<': 65 case '<':
66 ret.append("&lt;"); 66 ret.append("&lt;");
67 break; 67 break;
68 case '>': 68 case '>':
69 ret.append("&gt;"); 69 ret.append("&gt;");
70 break; 70 break;
71 case '&': 71 case '&':
72 ret.append("&amp;"); 72 ret.append("&amp;");
73 break; 73 break;
74 case '\"': 74 case '\"':
75 ret.append("&quot;"); 75 ret.append("&quot;");
76 break; 76 break;
77 case 'ä': 77 case 'ä':
78 ret.append("&auml;"); 78 ret.append("&auml;");
79 break; 79 break;
80 case 'Ä': 80 case 'Ä':
81 ret.append("&Auml;"); 81 ret.append("&Auml;");
82 break; 82 break;
83 case 'ü': 83 case 'ü':
84 ret.append("&uuml;"); 84 ret.append("&uuml;");
85 break; 85 break;
86 case 'Ü': 86 case 'Ü':
87 ret.append("&Uuml;"); 87 ret.append("&Uuml;");
88 break; 88 break;
89 case 'ö': 89 case 'ö':
90 ret.append("&ouml;"); 90 ret.append("&ouml;");
91 break; 91 break;
92 case 'Ö': 92 case 'Ö':
93 ret.append("&Ouml;"); 93 ret.append("&Ouml;");
94 break; 94 break;
95 case 'ß': 95 case 'ß':
96 ret.append("&szlig;"); 96 ret.append("&szlig;");
97 break; 97 break;
98 case '¿': 98 case '¿':
99 ret.append("&euro;"); 99 ret.append("&euro;");
100 break; 100 break;
101 default: 101 default:
102 ret.append(c); 102 ret.append(c);
103 } 103 }
104 } 104 }
105 return ret; 105 return ret;
106} 106}
107 107
108bool HtmlGen::isHtml(const QString &dta) 108bool HtmlGen::isHtml(const QString &dta)
109{ 109{
110 int ret; 110 int ret;
111 ret = dta.find("<html>", 0, false); 111 ret = dta.find("<html>", 0, false);
112 if (ret == -1) 112 if (ret == -1)
113 return false; 113 return false;
114 ret = dta.find("<head>", ret, false); 114 ret = dta.find("<head>", ret, false);
115 if (ret == -1) 115 if (ret == -1)
116 return false; 116 return false;
117 return true; 117 return true;
118} 118}
119 119
120QString HtmlGen::getStyleSheetHtml() 120QString HtmlGen::getStyleSheetHtml()
121{ 121{
122 QString ret; 122 QString ret;
123 ret = "<link rel=\"stylesheet\" href=\""; 123 ret = "<link rel=\"stylesheet\" href=\"";
124 QString cssPath(::locate("data", PATH_COMMENTSTYLE_CSS)); 124 QString cssPath(::locate("data", PATH_COMMENTSTYLE_CSS));
125 if ((cssPath == QString::null) || (cssPath == "")) { 125 if ((cssPath == QString::null) || (cssPath == "")) {
126 printDebug("HtmlGen::getStyleSheetHtml(): not found"); 126 printDebug("HtmlGen::getStyleSheetHtml(): not found");
127 return ""; 127 return "";
128 } 128 }
129 ret += cssPath; 129 ret += cssPath;
130 ret += "\" type=\"text/css\">" HTML_ENDL; 130 ret += "\" type=\"text/css\">" HTML_ENDL;
131 return ret; 131 return ret;
132} 132}
133 133
134bool HtmlGen::replaceSSDummy(QString *doc) 134bool HtmlGen::replaceSSDummy(QString *doc)
135{ 135{
136 int beginPos = doc->find(HTML_STYLESHEET_DUMMY); 136 int beginPos = doc->find(HTML_STYLESHEET_DUMMY);
137 if (beginPos == -1) { 137 if (beginPos == -1) {
138 printDebug("HtmlGen::replaceSSDummy(): not found"); 138 printDebug("HtmlGen::replaceSSDummy(): not found");
139 return false; 139 return false;
140 } 140 }
141 *doc = doc->replace(beginPos, strlen(HTML_STYLESHEET_DUMMY), 141 *doc = doc->replace(beginPos, strlen(HTML_STYLESHEET_DUMMY),
142 getStyleSheetHtml()); 142 getStyleSheetHtml());
143 return true; 143 return true;
144} 144}
145 145
146QString HtmlGen::genHtmlComment(const HtmlComment *dta) 146QString HtmlGen::genHtmlComment(const HtmlComment *dta)
147{ 147{
148 QString ret(HTML_DOCTYPE_HDR 148 QString ret(HTML_DOCTYPE_HDR
149 HTML_PWM_HDRHTML_ENDL 149 HTML_PWM_HDRHTML_ENDL
150 HTML_COMMENT_HDRHTML_ENDL 150 HTML_COMMENT_HDRHTML_ENDL
151 HTML_COMMENTVER_HDRHTML_ENDL); 151 HTML_COMMENTVER_HDRHTML_ENDL);
152 ret += "<html>" HTML_ENDL; 152 ret += "<html>" HTML_ENDL;
153 if (!appendCommentHeader(&ret)) 153 if (!appendCommentHeader(&ret))
154 return ""; 154 return "";
155 if (!appendCommentBody(&ret, dta)) 155 if (!appendCommentBody(&ret, dta))
156 return ""; 156 return "";
157 ret += "</html>" HTML_ENDL; 157 ret += "</html>" HTML_ENDL;
158 158
159#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0 159#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0
160 printDebug("<BEGIN HtmlGen::genHtmlComment() dump>"); 160 printDebug("<BEGIN HtmlGen::genHtmlComment() dump>");
161 cout << ret << endl; 161 cout << ret << endl;
162 printDebug("<END HtmlGen::genHtmlComment() dump>"); 162 printDebug("<END HtmlGen::genHtmlComment() dump>");
163#endif // DEBUG 163#endif // DEBUG
164 return ret; 164 return ret;
165} 165}
166 166
167bool HtmlGen::appendCommentHeader(QString *str) 167bool HtmlGen::appendCommentHeader(QString *str)
168{ 168{
169 *str += "<head>" HTML_ENDL; 169 *str += "<head>" HTML_ENDL;
170 if (useSSDummy) { 170 if (useSSDummy) {
171 *str += HTML_STYLESHEET_DUMMYHTML_ENDL; 171 *str += HTML_STYLESHEET_DUMMYHTML_ENDL;
172 } else { 172 } else {
173 QString ssLine(getStyleSheetHtml()); 173 QString ssLine(getStyleSheetHtml());
174 if (ssLine.isEmpty()) 174 if (ssLine.isEmpty())
175 return false; 175 return false;
176 *str += ssLine; 176 *str += ssLine;
177 } 177 }
178 *str += "</head>" HTML_ENDL; 178 *str += "</head>" HTML_ENDL;
179 return true; 179 return true;
180} 180}
181 181
182bool HtmlGen::appendCommentBody(QString *str, 182bool HtmlGen::appendCommentBody(QString *str,
183 const HtmlComment *dta) 183 const HtmlComment *dta)
184{ 184{
185 *str += "<body>" HTML_ENDL; 185 *str += "<body>" HTML_ENDL;
186 if (!appendCommentGlobTbl(str, dta)) 186 if (!appendCommentGlobTbl(str, dta))
187 return false; 187 return false;
188 *str += "</body>" HTML_ENDL; 188 *str += "</body>" HTML_ENDL;
189 return true; 189 return true;
190} 190}
191 191
192bool HtmlGen::appendCommentGlobTbl(QString *str, 192bool HtmlGen::appendCommentGlobTbl(QString *str,
193 const HtmlComment *dta) 193 const HtmlComment *dta)
194{ 194{
195 *str += "<table class=" HTML_GLOBTBL_CLASS ">" HTML_ENDL; 195 *str += "<table class=" HTML_GLOBTBL_CLASS ">" HTML_ENDL;
196 *str += "<tr><th class=" HTML_GLOBTITLE_CLASS ">"; 196 *str += "<tr><th class=" HTML_GLOBTITLE_CLASS ">";
197 *str += escapeHtmlText(dta->getTitle()); 197 *str += escapeHtmlText(dta->getTitle());
198 *str += "</th></tr>" HTML_ENDL; 198 *str += "</th></tr>" HTML_ENDL;
199 199
200 const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList(); 200 const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList();
201 vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(), 201 vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(),
202 end = subTbls->end(); 202 end = subTbls->end();
203 while (i != end) { 203 while (i != end) {
204 *str += "<tr><td>" HTML_ENDL; 204 *str += "<tr><td>" HTML_ENDL;
205 if (!appendCommentSubTbl(str, &(*i))) 205 if (!appendCommentSubTbl(str, &(*i)))
206 return false; 206 return false;
207 ++i; 207 ++i;
208 *str += "</td></tr>" HTML_ENDL; 208 *str += "</td></tr>" HTML_ENDL;
209 } 209 }
210 210
211 *str += "</table>" HTML_ENDL; 211 *str += "</table>" HTML_ENDL;
212 return true; 212 return true;
213} 213}
214 214
215bool HtmlGen::appendCommentSubTbl(QString *str, 215bool HtmlGen::appendCommentSubTbl(QString *str,
216 const HtmlComment::SubTable *dta) 216 const HtmlComment::SubTable *dta)
217{ 217{
218 *str += "<table class=" HTML_SUBTBL_CLASS ">" HTML_ENDL; 218 *str += "<table class=" HTML_SUBTBL_CLASS ">" HTML_ENDL;
219 *str += "<tr><th colspan=\"2\" class=" HTML_SUBTITLE_CLASS ">"; 219 *str += "<tr><th colspan=\"2\" class=" HTML_SUBTITLE_CLASS ">";
220 *str += escapeHtmlText(dta->getTitle()); 220 *str += escapeHtmlText(dta->getTitle());
221 *str += "</th></tr>" HTML_ENDL; 221 *str += "</th></tr>" HTML_ENDL;
222 222
223 const vector< pair<QString, QString> > *entries = dta->getEntryList(); 223 const vector< pair<QString, QString> > *entries = dta->getEntryList();
224 vector< pair<QString, QString> >::const_iterator i = entries->begin(), 224 vector< pair<QString, QString> >::const_iterator i = entries->begin(),
225 end = entries->end(); 225 end = entries->end();
226 while (i != end) { 226 while (i != end) {
227 *str += "<tr>" HTML_ENDL; 227 *str += "<tr>" HTML_ENDL;
228 if (!appendCommentSubTblEntry(str, &(*i))) 228 if (!appendCommentSubTblEntry(str, &(*i)))
229 return false; 229 return false;
230 *str += "</tr>" HTML_ENDL; 230 *str += "</tr>" HTML_ENDL;
231 ++i; 231 ++i;
232 } 232 }
233 233
234 *str += "</table>" HTML_ENDL; 234 *str += "</table>" HTML_ENDL;
235 return true; 235 return true;
236} 236}
237 237
238bool HtmlGen::appendCommentSubTblEntry(QString *str, 238bool HtmlGen::appendCommentSubTblEntry(QString *str,
239 const pair<QString, QString> *dta) 239 const pair<QString, QString> *dta)
240{ 240{
241 *str += "<td class=" HTML_ENTRY_CLASS ">"; 241 *str += "<td class=" HTML_ENTRY_CLASS ">";
242 *str += escapeHtmlText(dta->first); 242 *str += escapeHtmlText(dta->first);
243 *str += "</td>" HTML_ENDL; 243 *str += "</td>" HTML_ENDL;
244 *str += "<td class=" HTML_VALUE_CLASS ">"; 244 *str += "<td class=" HTML_VALUE_CLASS ">";
245 *str += escapeHtmlText(dta->second); 245 *str += escapeHtmlText(dta->second);
246 *str += "</td>" HTML_ENDL; 246 *str += "</td>" HTML_ENDL;
247 return true; 247 return true;
248} 248}
diff --git a/pwmanager/pwmanager/ipc.cpp b/pwmanager/pwmanager/ipc.cpp
index b1d2c68..643b022 100644
--- a/pwmanager/pwmanager/ipc.cpp
+++ b/pwmanager/pwmanager/ipc.cpp
@@ -1,216 +1,217 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.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 "ipc.h" 20#include "ipc.h"
21#include "pwmexception.h" 21#include "pwmexception.h"
22 22
23#include <qsocketnotifier.h> 23#include <qsocketnotifier.h>
24 24#ifndef _WIN32_
25#include <sys/socket.h> 25#include <sys/socket.h>
26 26#endif
27#ifndef PWM_EMBEDDED 27#ifndef PWM_EMBEDDED
28#include <sys/types.h> 28#include <sys/types.h>
29#include <stdio.h> 29#include <stdio.h>
30#else 30#else
31#include <qsocket.h> 31#include <qsocket.h>
32#endif 32#endif
33 33
34 #define END_OF_LINE '\n' 34 #define END_OF_LINE '\n'
35 #define INIT_LINEBUF_LEN64 /* byte */ 35 #define INIT_LINEBUF_LEN64 /* byte */
36 36
37#ifndef PWM_EMBEDDED 37#ifndef PWM_EMBEDDED
38 38
39Ipc::Ipc() 39Ipc::Ipc()
40 : stream (0) 40 : stream (0)
41 , notifier (0) 41 , notifier (0)
42 , rdBuf (0) 42 , rdBuf (0)
43{ 43{
44 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { 44 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) {
45 throw PwMException(PwMException::EX_GENERIC, 45 throw PwMException(PwMException::EX_GENERIC,
46 "Ipc: socketpair() failed"); 46 "Ipc: socketpair() failed");
47 } 47 }
48 rdBufSize = INIT_LINEBUF_LEN; 48 rdBufSize = INIT_LINEBUF_LEN;
49 rdBuf = static_cast<char *>(malloc(rdBufSize)); 49 rdBuf = static_cast<char *>(malloc(rdBufSize));
50 if (!rdBuf) { 50 if (!rdBuf) {
51 close(sock[0]); 51 close(sock[0]);
52 close(sock[1]); 52 close(sock[1]);
53 throw PwMException(PwMException::EX_GENERIC, 53 throw PwMException(PwMException::EX_GENERIC,
54 "Ipc: OOM"); 54 "Ipc: OOM");
55 } 55 }
56 stream = fdopen(sock[0], "r"); 56 stream = fdopen(sock[0], "r");
57 if (!stream) { 57 if (!stream) {
58 close(sock[0]); 58 close(sock[0]);
59 close(sock[1]); 59 close(sock[1]);
60 free(rdBuf); 60 free(rdBuf);
61 throw PwMException(PwMException::EX_GENERIC, 61 throw PwMException(PwMException::EX_GENERIC,
62 "Ipc: fdopen() failed"); 62 "Ipc: fdopen() failed");
63 } 63 }
64 64
65 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); 65 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
66 connect(notifier, SIGNAL(activated(int)), 66 connect(notifier, SIGNAL(activated(int)),
67 this, SLOT(receiveData(int))); 67 this, SLOT(receiveData(int)));
68 host = true; 68 host = true;
69} 69}
70#else 70#else
71Ipc::Ipc() 71Ipc::Ipc()
72 : notifier (0) 72 : notifier (0)
73 , rdBuf (0) 73 , rdBuf (0)
74{ 74{
75#ifndef _WIN32_
75 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { 76 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) {
76 qDebug("Ipc: socketpair() failed"); 77 qDebug("Ipc: socketpair() failed");
77 } 78 }
78 79#endif
79 QSocket* qsock = new QSocket(); 80 QSocket* qsock = new QSocket();
80 qsock->setSocket(sock[0]); 81 qsock->setSocket(sock[0]);
81 82
82 rdBufSize = INIT_LINEBUF_LEN; 83 rdBufSize = INIT_LINEBUF_LEN;
83 rdBuf = (char *)(malloc(rdBufSize)); 84 rdBuf = (char *)(malloc(rdBufSize));
84 if (!rdBuf) { 85 if (!rdBuf) {
85 close(sock[0]); 86 close(sock[0]);
86 close(sock[1]); 87 close(sock[1]);
87 qDebug("Ipc: OOM"); 88 qDebug("Ipc: OOM");
88 } 89 }
89 90
90 qsock = new QSocket(); 91 qsock = new QSocket();
91 qsock->setSocket(sock[0]); 92 qsock->setSocket(sock[0]);
92 93
93 /*US 94 /*US
94 stream = fdopen(sock[0], "r"); 95 stream = fdopen(sock[0], "r");
95 if (!stream) { 96 if (!stream) {
96 close(sock[0]); 97 close(sock[0]);
97 close(sock[1]); 98 close(sock[1]);
98 free(rdBuf); 99 free(rdBuf);
99 qDebug("Ipc: fdopen() failed"); 100 qDebug("Ipc: fdopen() failed");
100 } 101 }
101 */ 102 */
102 103
103 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); 104 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
104 connect(notifier, SIGNAL(activated(int)), 105 connect(notifier, SIGNAL(activated(int)),
105 this, SLOT(receiveData(int))); 106 this, SLOT(receiveData(int)));
106 host = true; 107 host = true;
107} 108}
108 109
109#endif 110#endif
110 111
111 112
112#ifndef PWM_EMBEDDED 113#ifndef PWM_EMBEDDED
113 114
114Ipc::Ipc(const Ipc *ipc) 115Ipc::Ipc(const Ipc *ipc)
115 : stream (0) 116 : stream (0)
116 , notifier (0) 117 , notifier (0)
117 , rdBuf (0) 118 , rdBuf (0)
118{ 119{
119 rdBufSize = INIT_LINEBUF_LEN; 120 rdBufSize = INIT_LINEBUF_LEN;
120 rdBuf = static_cast<char *>(malloc(rdBufSize)); 121 rdBuf = static_cast<char *>(malloc(rdBufSize));
121 if (!rdBuf) { 122 if (!rdBuf) {
122 throw PwMException(PwMException::EX_GENERIC, 123 throw PwMException(PwMException::EX_GENERIC,
123 "Ipc: OOM"); 124 "Ipc: OOM");
124 } 125 }
125 sock[0] = ipc->sock[1]; 126 sock[0] = ipc->sock[1];
126 sock[1] = ipc->sock[0]; 127 sock[1] = ipc->sock[0];
127 stream = fdopen(sock[0], "r"); 128 stream = fdopen(sock[0], "r");
128 if (!stream) { 129 if (!stream) {
129 free(rdBuf); 130 free(rdBuf);
130 throw PwMException(PwMException::EX_GENERIC, 131 throw PwMException(PwMException::EX_GENERIC,
131 "Ipc: fdopen() failed"); 132 "Ipc: fdopen() failed");
132 } 133 }
133 134
134 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); 135 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
135 connect(notifier, SIGNAL(activated(int)), 136 connect(notifier, SIGNAL(activated(int)),
136 this, SLOT(receiveData(int))); 137 this, SLOT(receiveData(int)));
137 host = false; 138 host = false;
138} 139}
139 140
140#else 141#else
141 142
142Ipc::Ipc(const Ipc *ipc) 143Ipc::Ipc(const Ipc *ipc)
143 : notifier (0) 144 : notifier (0)
144 , rdBuf (0) 145 , rdBuf (0)
145{ 146{
146 rdBufSize = INIT_LINEBUF_LEN; 147 rdBufSize = INIT_LINEBUF_LEN;
147 rdBuf = (char *)(malloc(rdBufSize)); 148 rdBuf = (char *)(malloc(rdBufSize));
148 if (!rdBuf) { 149 if (!rdBuf) {
149 qDebug("Ipc: OOM"); 150 qDebug("Ipc: OOM");
150 } 151 }
151 sock[0] = ipc->sock[1]; 152 sock[0] = ipc->sock[1];
152 sock[1] = ipc->sock[0]; 153 sock[1] = ipc->sock[0];
153 154
154 qSock = new QSocket(); 155 qSock = new QSocket();
155 qSock->setSocket(sock[0]); 156 qSock->setSocket(sock[0]);
156 157
157 /*US 158 /*US
158 stream = fdopen(sock[0], "r"); 159 stream = fdopen(sock[0], "r");
159 if (!stream) { 160 if (!stream) {
160 free(rdBuf); 161 free(rdBuf);
161 qDebug("Ipc: fdopen() failed"); 162 qDebug("Ipc: fdopen() failed");
162 } 163 }
163 */ 164 */
164 165
165 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); 166 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
166 connect(notifier, SIGNAL(activated(int)), 167 connect(notifier, SIGNAL(activated(int)),
167 this, SLOT(receiveData(int))); 168 this, SLOT(receiveData(int)));
168 host = false; 169 host = false;
169} 170}
170 171
171#endif 172#endif
172 173
173Ipc::~Ipc() 174Ipc::~Ipc()
174{ 175{
175#ifdef PWM_EMBEDDED 176#ifdef PWM_EMBEDDED
176 delete qSock; 177 delete qSock;
177#endif 178#endif
178 delete_ifnot_null(notifier); 179 delete_ifnot_null(notifier);
179 if (rdBuf) 180 if (rdBuf)
180 free(rdBuf); 181 free(rdBuf);
181#ifndef PWM_EMBEDDED 182#ifndef PWM_EMBEDDED
182 if (stream) 183 if (stream)
183 fclose(stream); 184 fclose(stream);
184#endif 185#endif
185 if (host) { 186 if (host) {
186 close(sock[0]); 187 close(sock[0]);
187 close(sock[1]); 188 close(sock[1]);
188 } 189 }
189 190
190} 191}
191 192
192void Ipc::receiveData(int s) 193void Ipc::receiveData(int s)
193{ 194{
194 PWM_ASSERT(s == sock[0]); 195 PWM_ASSERT(s == sock[0]);
195 PARAM_UNUSED(s); 196 PARAM_UNUSED(s);
196#ifndef PWM_EMBEDDED 197#ifndef PWM_EMBEDDED
197 ssize_t rd; 198 ssize_t rd;
198 199
199 rd = ::getline(&rdBuf, &rdBufSize, stream); 200 rd = ::getline(&rdBuf, &rdBufSize, stream);
200 if (likely(rd > 0)) { 201 if (likely(rd > 0)) {
201 emit lineAvailable(rdBuf, rd); 202 emit lineAvailable(rdBuf, rd);
202 } 203 }
203#else 204#else
204 int rd; 205 int rd;
205 rd = qSock->readLine(rdBuf, rdBufSize); 206 rd = qSock->readLine(rdBuf, rdBufSize);
206 if (rd > 0) { 207 if (rd > 0) {
207 emit lineAvailable(rdBuf, rd); 208 emit lineAvailable(rdBuf, rd);
208 } 209 }
209#endif 210#endif
210 qDebug("void Ipc::receiveData(int s) has to be implemented."); 211 qDebug("void Ipc::receiveData(int s) has to be implemented.");
211 212
212} 213}
213 214
214#ifndef PWM_EMBEDDED 215#ifndef PWM_EMBEDDED
215#include "ipc.moc" 216#include "ipc.moc"
216#endif 217#endif
diff --git a/pwmanager/pwmanager/ipc.h b/pwmanager/pwmanager/ipc.h
index e5a496d..7bfca02 100644
--- a/pwmanager/pwmanager/ipc.h
+++ b/pwmanager/pwmanager/ipc.h
@@ -1,89 +1,92 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWM_IPC_H 20#ifndef __PWM_IPC_H
21#define __PWM_IPC_H 21#define __PWM_IPC_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#ifndef _WIN32_
24#include <unistd.h> 25#include <unistd.h>
25 26#else
27#include <io.h>
28#endif
26#ifndef PWM_EMBEDDED 29#ifndef PWM_EMBEDDED
27#include <stdio.h> 30#include <stdio.h>
28#else 31#else
29#include <qsocket.h> 32#include <qsocket.h>
30#endif 33#endif
31 34
32class QSocketNotifier; 35class QSocketNotifier;
33 36
34/** very simple interprocess communication class */ 37/** very simple interprocess communication class */
35class Ipc : public QObject 38class Ipc : public QObject
36{ 39{
37 Q_OBJECT 40 Q_OBJECT
38public: 41public:
39 /** create a new Ipc communication object */ 42 /** create a new Ipc communication object */
40 Ipc(); 43 Ipc();
41 /** create a new Ipc communication object and 44 /** create a new Ipc communication object and
42 * connect it to "ipc" 45 * connect it to "ipc"
43 */ 46 */
44 Ipc(const Ipc *ipc); 47 Ipc(const Ipc *ipc);
45 /** destructor */ 48 /** destructor */
46 ~Ipc(); 49 ~Ipc();
47 50
48 /** send data to the other socket end 51 /** send data to the other socket end
49 * (To the connected ipc object) 52 * (To the connected ipc object)
50 */ 53 */
51#ifndef PWM_EMBEDDED 54#ifndef PWM_EMBEDDED
52 void send(const char *buf, size_t size) 55 void send(const char *buf, size_t size)
53 { write(sock[0], buf, size); } 56 { write(sock[0], buf, size); }
54#else 57#else
55 void send(const char *buf, size_t size) 58 void send(const char *buf, size_t size)
56 { qSock->writeBlock(buf, size); } 59 { qSock->writeBlock(buf, size); }
57#endif 60#endif
58 61
59signals: 62signals:
60 /** a line is available */ 63 /** a line is available */
61 void lineAvailable(const char *buf, size_t size); 64 void lineAvailable(const char *buf, size_t size);
62 65
63protected slots: 66protected slots:
64 /** received data on socket */ 67 /** received data on socket */
65 void receiveData(int s); 68 void receiveData(int s);
66 69
67protected: 70protected:
68#ifndef PWM_EMBEDDED 71#ifndef PWM_EMBEDDED
69 /** stream on "this" end of the socket (sock[0]) */ 72 /** stream on "this" end of the socket (sock[0]) */
70 FILE *stream; 73 FILE *stream;
71 /** current receive buffer size */ 74 /** current receive buffer size */
72 size_t rdBufSize; 75 size_t rdBufSize;
73#else 76#else
74 QSocket* qSock; 77 QSocket* qSock;
75 /** current receive buffer size */ 78 /** current receive buffer size */
76 unsigned int rdBufSize; 79 unsigned int rdBufSize;
77#endif 80#endif
78 81
79 /** full-duplex socket file desciptors */ 82 /** full-duplex socket file desciptors */
80 int sock[2]; 83 int sock[2];
81 /** socket notifier */ 84 /** socket notifier */
82 QSocketNotifier *notifier; 85 QSocketNotifier *notifier;
83 /** are we the host or the client object? */ 86 /** are we the host or the client object? */
84 bool host; 87 bool host;
85 /** receive buffer */ 88 /** receive buffer */
86 char *rdBuf; 89 char *rdBuf;
87}; 90};
88 91
89#endif // __PWM_IPC_H 92#endif // __PWM_IPC_H
diff --git a/pwmanager/pwmanager/libgcryptif.h b/pwmanager/pwmanager/libgcryptif.h
index dffd55b..1a7b658 100644
--- a/pwmanager/pwmanager/libgcryptif.h
+++ b/pwmanager/pwmanager/libgcryptif.h
@@ -1,166 +1,171 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * hashPassphrase() is derived from GnuPG and is * 6 * hashPassphrase() is derived from GnuPG and is *
7 * Copyright (C) 1998, 1999, 2000, 2001, 2003 * 7 * Copyright (C) 1998, 1999, 2000, 2001, 2003 *
8 * Free Software Foundation, Inc. * 8 * Free Software Foundation, Inc. *
9 * * 9 * *
10 * This program is free software; you can redistribute it and/or modify * 10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License version 2 * 11 * it under the terms of the GNU General Public License version 2 *
12 * as published by the Free Software Foundation. * 12 * as published by the Free Software Foundation. *
13 * * 13 * *
14 ***************************************************************************/ 14 ***************************************************************************/
15 15
16/*************************************************************************** 16/***************************************************************************
17 * copyright (C) 2004 by Ulf Schenk 17 * copyright (C) 2004 by Ulf Schenk
18 * This file is originaly based on version 1.1 of pwmanager 18 * This file is originaly based on version 1.1 of pwmanager
19 * and was modified to run on embedded devices that run microkde 19 * and was modified to run on embedded devices that run microkde
20 * 20 *
21 * $Id$ 21 * $Id$
22 **************************************************************************/ 22 **************************************************************************/
23 23
24#ifndef __LIBGCRYPTIF_H 24#ifndef __LIBGCRYPTIF_H
25#define __LIBGCRYPTIF_H 25#define __LIBGCRYPTIF_H
26 26
27#include "pwmexception.h" 27#include "pwmexception.h"
28 28
29//#undef CONFIG_PWMANAGER_GCRY // for debugging only. 29//#undef CONFIG_PWMANAGER_GCRY // for debugging only.
30#ifdef CONFIG_PWMANAGER_GCRY 30#ifdef CONFIG_PWMANAGER_GCRY
31 31
32#include <stddef.h> 32#include <stddef.h>
33#include <sys/types.h> 33#include <sys/types.h>
34#ifndef _WIN32_
34#include <stdint.h> 35#include <stdint.h>
35 36#else
37#define uint8_t Q_UINT8
38#define byte Q_UINT8
39#define uint32_t Q_UINT32
40#endif
36 #define STRING2KEY_SALTLEN8 41 #define STRING2KEY_SALTLEN8
37 42
38/** interface class for the libgcrypt cipher and hash algorithms 43/** interface class for the libgcrypt cipher and hash algorithms
39 * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding) 44 * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding)
40 */ 45 */
41class LibGCryptIf 46class LibGCryptIf
42{ 47{
43protected: 48protected:
44 struct STRING2KEY 49 struct STRING2KEY
45 { 50 {
46 int mode; 51 int mode;
47 int hash_algo; 52 int hash_algo;
48 uint8_t salt[STRING2KEY_SALTLEN]; 53 uint8_t salt[STRING2KEY_SALTLEN];
49 uint32_t count; 54 uint32_t count;
50 }; 55 };
51 struct DEK 56 struct DEK
52 { 57 {
53 size_t keylen; 58 size_t keylen;
54 uint8_t key[32]; // this is the largest used keylen (256 bit) 59 uint8_t key[32]; // this is the largest used keylen (256 bit)
55 }; 60 };
56 61
57public: 62public:
58 LibGCryptIf() { } 63 LibGCryptIf() { }
59 /** is libgcrypt available? */ 64 /** is libgcrypt available? */
60 static bool available() 65 static bool available()
61 { return true; } 66 { return true; }
62 /** encrypt data. _algo is the PWM_CRYPT_* ID 67 /** encrypt data. _algo is the PWM_CRYPT_* ID
63 * of the algorithm. 68 * of the algorithm.
64 */ 69 */
65 PwMerror encrypt(unsigned char **outBuf, 70 PwMerror encrypt(unsigned char **outBuf,
66 size_t *outBufLen, 71 size_t *outBufLen,
67 unsigned char *inBuf, 72 unsigned char *inBuf,
68 size_t inBufLen, 73 size_t inBufLen,
69 const unsigned char *key, 74 const unsigned char *key,
70 size_t keylen, 75 size_t keylen,
71 char _algo); 76 char _algo);
72 /** decrypt data. _algo is the PWM_CRYPT_* ID 77 /** decrypt data. _algo is the PWM_CRYPT_* ID
73 * of the algorithm. 78 * of the algorithm.
74 */ 79 */
75 PwMerror decrypt(unsigned char **outBuf, 80 PwMerror decrypt(unsigned char **outBuf,
76 size_t *outBufLen, 81 size_t *outBufLen,
77 const unsigned char *inBuf, 82 const unsigned char *inBuf,
78 size_t inBufLen, 83 size_t inBufLen,
79 const unsigned char *key, 84 const unsigned char *key,
80 size_t keylen, 85 size_t keylen,
81 char _algo); 86 char _algo);
82 /** hash data. _algo is the PWM_HASH_* ID of the hash */ 87 /** hash data. _algo is the PWM_HASH_* ID of the hash */
83 PwMerror hash(unsigned char **outBuf, 88 PwMerror hash(unsigned char **outBuf,
84 size_t *outBufLen, 89 size_t *outBufLen,
85 const unsigned char *inBuf, 90 const unsigned char *inBuf,
86 size_t inBufLen, 91 size_t inBufLen,
87 char _algo); 92 char _algo);
88 /** returns the length of the hash. _algo is the PWM_HASH_* 93 /** returns the length of the hash. _algo is the PWM_HASH_*
89 * id of the hash. returns 0 on error. 94 * id of the hash. returns 0 on error.
90 */ 95 */
91 unsigned int hashLength(char _algo); 96 unsigned int hashLength(char _algo);
92 97
93protected: 98protected:
94 /** returns the total buffer length */ 99 /** returns the total buffer length */
95 size_t getBufLen(size_t inBufLen, size_t boundary) 100 size_t getBufLen(size_t inBufLen, size_t boundary)
96 { 101 {
97 return ((boundary - (inBufLen % boundary)) + inBufLen); 102 return ((boundary - (inBufLen % boundary)) + inBufLen);
98 } 103 }
99 /** pad the data up to the given boundary. 104 /** pad the data up to the given boundary.
100 * "buf" has to be big enough! 105 * "buf" has to be big enough!
101 */ 106 */
102 void padData(unsigned char *buf, 107 void padData(unsigned char *buf,
103 size_t bufLen, 108 size_t bufLen,
104 size_t boundary); 109 size_t boundary);
105 /** unpad the data */ 110 /** unpad the data */
106 void unpadData(const unsigned char *buf, 111 void unpadData(const unsigned char *buf,
107 size_t *bufLen); 112 size_t *bufLen);
108 /** maps the PWM_CRYPT_* ID of an algorithm 113 /** maps the PWM_CRYPT_* ID of an algorithm
109 * to the libgcrypt GCRY_CIPHER_* ID 114 * to the libgcrypt GCRY_CIPHER_* ID
110 */ 115 */
111 int mapCipherId(char algo); 116 int mapCipherId(char algo);
112 /** maps the PWM_HASH_* ID of an algorithm 117 /** maps the PWM_HASH_* ID of an algorithm
113 * to the libgcrypt GCRY_MD_* ID 118 * to the libgcrypt GCRY_MD_* ID
114 */ 119 */
115 int mapHashId(char algo); 120 int mapHashId(char algo);
116 /** hash a passphrase to a cipher key */ 121 /** hash a passphrase to a cipher key */
117 bool hashPassphrase(const unsigned char *pw, 122 bool hashPassphrase(const unsigned char *pw,
118 size_t pwlen, 123 size_t pwlen,
119 unsigned char *salt, 124 unsigned char *salt,
120 unsigned char *key, 125 unsigned char *key,
121 size_t keylen, 126 size_t keylen,
122 bool create); 127 bool create);
123 /** hash a passphrase to a cipher key */ 128 /** hash a passphrase to a cipher key */
124 bool doHashPassphrase(DEK *dek, 129 bool doHashPassphrase(DEK *dek,
125 const unsigned char *pw, 130 const unsigned char *pw,
126 size_t pwlen, 131 size_t pwlen,
127 STRING2KEY *s2k, 132 STRING2KEY *s2k,
128 bool create); 133 bool create);
129}; 134};
130 135
131 136
132#else // CONFIG_PWMANAGER_GCRY 137#else // CONFIG_PWMANAGER_GCRY
133/** libgcrypt is not installed. This is a NOP wrapper. */ 138/** libgcrypt is not installed. This is a NOP wrapper. */
134class LibGCryptIf 139class LibGCryptIf
135{ 140{
136public: 141public:
137 LibGCryptIf() { } 142 LibGCryptIf() { }
138 static bool available() 143 static bool available()
139 { return false; } 144 { return false; }
140 PwMerror encrypt(unsigned char **, 145 PwMerror encrypt(unsigned char **,
141 size_t *, 146 size_t *,
142 unsigned char *, 147 unsigned char *,
143 size_t, 148 size_t,
144 const unsigned char *, 149 const unsigned char *,
145 size_t, 150 size_t,
146 char) 151 char)
147 { return e_cryptNotImpl; } 152 { return e_cryptNotImpl; }
148 PwMerror decrypt(unsigned char **, 153 PwMerror decrypt(unsigned char **,
149 size_t *, 154 size_t *,
150 const unsigned char *, 155 const unsigned char *,
151 size_t, 156 size_t,
152 const unsigned char *, 157 const unsigned char *,
153 size_t, 158 size_t,
154 char) 159 char)
155 { return e_cryptNotImpl; } 160 { return e_cryptNotImpl; }
156 PwMerror hash(unsigned char **, 161 PwMerror hash(unsigned char **,
157 size_t *, 162 size_t *,
158 const unsigned char *, 163 const unsigned char *,
159 size_t, 164 size_t,
160 char) 165 char)
161 { return e_hashNotImpl; } 166 { return e_hashNotImpl; }
162 unsigned int hashLength(char) 167 unsigned int hashLength(char)
163 { return 0; } 168 { return 0; }
164}; 169};
165#endif // CONFIG_PWMANAGER_GCRY 170#endif // CONFIG_PWMANAGER_GCRY
166#endif // __LIBGCRYPTIF_H 171#endif // __LIBGCRYPTIF_H
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index d92c90d..1ab2b71 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -645,821 +645,822 @@ void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc)
645 d.clear(true); 645 d.clear(true);
646 646
647 d.desc = w.getDescription().latin1(); 647 d.desc = w.getDescription().latin1();
648 d.name = w.getUsername().latin1(); 648 d.name = w.getUsername().latin1();
649 d.pw = w.getPassword().latin1(); 649 d.pw = w.getPassword().latin1();
650 d.comment = w.getComment().latin1(); 650 d.comment = w.getComment().latin1();
651 d.url = w.getUrl().latin1(); 651 d.url = w.getUrl().latin1();
652 d.launcher = w.getLauncher().latin1(); 652 d.launcher = w.getLauncher().latin1();
653 PwMerror ret = doc->addEntry(w.getCategory(), &d); 653 PwMerror ret = doc->addEntry(w.getCategory(), &d);
654 if (ret == e_entryExists) { 654 if (ret == e_entryExists) {
655 KMessageBox::error(this, 655 KMessageBox::error(this,
656 i18n 656 i18n
657 ("An entry with this \"Description\",\n" 657 ("An entry with this \"Description\",\n"
658 "does already exist.\n" 658 "does already exist.\n"
659 "Please select another description."), 659 "Please select another description."),
660 i18n("entry already exists.")); 660 i18n("entry already exists."));
661 goto tryAgain; 661 goto tryAgain;
662 } else if (ret == e_maxAllowedEntr) { 662 } else if (ret == e_maxAllowedEntr) {
663 KMessageBox::error(this, i18n("The maximum possible number of\nentries" 663 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
664 "has been reached.\nYou can't add more entries."), 664 "has been reached.\nYou can't add more entries."),
665 i18n("maximum number of entries")); 665 i18n("maximum number of entries"));
666 doc->timer()->putLock(DocTimer::id_autoLockTimer); 666 doc->timer()->putLock(DocTimer::id_autoLockTimer);
667 return; 667 return;
668 } 668 }
669 } 669 }
670 setVirgin(false); 670 setVirgin(false);
671 doc->timer()->putLock(DocTimer::id_autoLockTimer); 671 doc->timer()->putLock(DocTimer::id_autoLockTimer);
672} 672}
673 673
674//US ENH : changed code to run with older MOC 674//US ENH : changed code to run with older MOC
675void PwM::editPwd_slot() 675void PwM::editPwd_slot()
676{ 676{
677 editPwd_slot3(0,0,0); 677 editPwd_slot3(0,0,0);
678} 678}
679 679
680void PwM::editPwd_slot1(const QString *category) 680void PwM::editPwd_slot1(const QString *category)
681{ 681{
682 editPwd_slot3(category, 0, 0); 682 editPwd_slot3(category, 0, 0);
683} 683}
684 684
685void PwM::editPwd_slot3(const QString *category, const int *index, 685void PwM::editPwd_slot3(const QString *category, const int *index,
686 PwMDoc *_doc) 686 PwMDoc *_doc)
687{ 687{
688 PwMDoc *doc; 688 PwMDoc *doc;
689 if (_doc) { 689 if (_doc) {
690 doc = _doc; 690 doc = _doc;
691 } else { 691 } else {
692 doc = curDoc(); 692 doc = curDoc();
693 } 693 }
694 PWM_ASSERT(doc); 694 PWM_ASSERT(doc);
695 if (doc->isDocEmpty()) 695 if (doc->isDocEmpty())
696 return; 696 return;
697 if (doc->isDeepLocked()) 697 if (doc->isDeepLocked())
698 return; 698 return;
699 doc->timer()->getLock(DocTimer::id_autoLockTimer); 699 doc->timer()->getLock(DocTimer::id_autoLockTimer);
700 unsigned int curEntryIndex; 700 unsigned int curEntryIndex;
701 if (index) { 701 if (index) {
702 curEntryIndex = *index; 702 curEntryIndex = *index;
703 } else { 703 } else {
704 if (!(view->getCurEntryIndex(&curEntryIndex))) { 704 if (!(view->getCurEntryIndex(&curEntryIndex))) {
705 printDebug("couldn't get index. Maybe we have a binary entry here."); 705 printDebug("couldn't get index. Maybe we have a binary entry here.");
706 doc->timer()->putLock(DocTimer::id_autoLockTimer); 706 doc->timer()->putLock(DocTimer::id_autoLockTimer);
707 return; 707 return;
708 } 708 }
709 } 709 }
710 QString curCategory; 710 QString curCategory;
711 if (category) { 711 if (category) {
712 curCategory = *category; 712 curCategory = *category;
713 } else { 713 } else {
714 curCategory = view->getCurrentCategory(); 714 curCategory = view->getCurrentCategory();
715 } 715 }
716 PwMDataItem currItem; 716 PwMDataItem currItem;
717 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { 717 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
718 doc->timer()->putLock(DocTimer::id_autoLockTimer); 718 doc->timer()->putLock(DocTimer::id_autoLockTimer);
719 return; 719 return;
720 } 720 }
721 BUG_ON(currItem.binary); 721 BUG_ON(currItem.binary);
722 722
723 AddEntryWndImpl w; 723 AddEntryWndImpl w;
724 vector<string> catList; 724 vector<string> catList;
725 doc->getCategoryList(&catList); 725 doc->getCategoryList(&catList);
726 unsigned i, size = catList.size(); 726 unsigned i, size = catList.size();
727 for (i = 0; i < size; ++i) { 727 for (i = 0; i < size; ++i) {
728 w.addCategory(catList[i].c_str()); 728 w.addCategory(catList[i].c_str());
729 } 729 }
730 w.setCurrCategory(curCategory); 730 w.setCurrCategory(curCategory);
731 w.setDescription(currItem.desc.c_str()); 731 w.setDescription(currItem.desc.c_str());
732 w.setUsername(currItem.name.c_str()); 732 w.setUsername(currItem.name.c_str());
733 w.setPassword(currItem.pw.c_str()); 733 w.setPassword(currItem.pw.c_str());
734 w.setUrl(currItem.url.c_str()); 734 w.setUrl(currItem.url.c_str());
735 w.setLauncher(currItem.launcher.c_str()); 735 w.setLauncher(currItem.launcher.c_str());
736 w.setComment(currItem.comment.c_str()); 736 w.setComment(currItem.comment.c_str());
737 if (w.exec() == 1) { 737 if (w.exec() == 1) {
738 currItem.desc = w.getDescription().latin1(); 738 currItem.desc = w.getDescription().latin1();
739 currItem.name = w.getUsername().latin1(); 739 currItem.name = w.getUsername().latin1();
740 currItem.pw = w.getPassword().latin1(); 740 currItem.pw = w.getPassword().latin1();
741 currItem.comment = w.getComment().latin1(); 741 currItem.comment = w.getComment().latin1();
742 currItem.url = w.getUrl().latin1(); 742 currItem.url = w.getUrl().latin1();
743 currItem.launcher = w.getLauncher().latin1(); 743 currItem.launcher = w.getLauncher().latin1();
744 if (!doc->editEntry(curCategory, w.getCategory(), 744 if (!doc->editEntry(curCategory, w.getCategory(),
745 curEntryIndex, &currItem)) { 745 curEntryIndex, &currItem)) {
746 KMessageBox::error(this, 746 KMessageBox::error(this,
747 i18n("Couldn't edit the entry.\n" 747 i18n("Couldn't edit the entry.\n"
748 "Maybe you changed the category and\n" 748 "Maybe you changed the category and\n"
749 "this entry is already present\nin the new " 749 "this entry is already present\nin the new "
750 "category?"), 750 "category?"),
751 i18n("couldn't edit entry.")); 751 i18n("couldn't edit entry."));
752 doc->timer()->putLock(DocTimer::id_autoLockTimer); 752 doc->timer()->putLock(DocTimer::id_autoLockTimer);
753 return; 753 return;
754 } 754 }
755 } 755 }
756 doc->timer()->putLock(DocTimer::id_autoLockTimer); 756 doc->timer()->putLock(DocTimer::id_autoLockTimer);
757} 757}
758 758
759void PwM::deletePwd_slot() 759void PwM::deletePwd_slot()
760{ 760{
761 PWM_ASSERT(curDoc()); 761 PWM_ASSERT(curDoc());
762 if (curDoc()->isDocEmpty()) 762 if (curDoc()->isDocEmpty())
763 return; 763 return;
764 if (curDoc()->isDeepLocked()) 764 if (curDoc()->isDeepLocked())
765 return; 765 return;
766 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 766 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
767 unsigned int curEntryIndex = 0; 767 unsigned int curEntryIndex = 0;
768 if (!(view->getCurEntryIndex(&curEntryIndex))) { 768 if (!(view->getCurEntryIndex(&curEntryIndex))) {
769 printDebug("couldn't get index"); 769 printDebug("couldn't get index");
770 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 770 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
771 return; 771 return;
772 } 772 }
773 773
774 PwMDataItem currItem; 774 PwMDataItem currItem;
775 QString curCategory = view->getCurrentCategory(); 775 QString curCategory = view->getCurrentCategory();
776 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { 776 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
777 printDebug("couldn't get entry"); 777 printDebug("couldn't get entry");
778 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 778 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
779 return; 779 return;
780 } 780 }
781 if (KMessageBox:: 781 if (KMessageBox::
782 questionYesNo(this, 782 questionYesNo(this,
783 i18n 783 i18n
784 ("Do you really want to delete\nthe selected entry") + 784 ("Do you really want to delete\nthe selected entry") +
785 " \n\"" + QString(currItem.desc.c_str()) 785 " \n\"" + QString(currItem.desc.c_str())
786 + "\" ?", i18n("delete?")) 786 + "\" ?", i18n("delete?"))
787 == KMessageBox::Yes) { 787 == KMessageBox::Yes) {
788 788
789 curDoc()->delEntry(curCategory, curEntryIndex); 789 curDoc()->delEntry(curCategory, curEntryIndex);
790 } 790 }
791 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 791 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
792} 792}
793 793
794void PwM::changeMasterPwd_slot() 794void PwM::changeMasterPwd_slot()
795{ 795{
796 PWM_ASSERT(curDoc()); 796 PWM_ASSERT(curDoc());
797 curDoc()->changeCurrentPw(); 797 curDoc()->changeCurrentPw();
798} 798}
799 799
800void PwM::lockWnd_slot() 800void PwM::lockWnd_slot()
801{ 801{
802 PWM_ASSERT(curDoc()); 802 PWM_ASSERT(curDoc());
803 curDoc()->lockAll(true); 803 curDoc()->lockAll(true);
804} 804}
805 805
806void PwM::deepLockWnd_slot() 806void PwM::deepLockWnd_slot()
807{ 807{
808 PWM_ASSERT(curDoc()); 808 PWM_ASSERT(curDoc());
809 curDoc()->deepLock(); 809 curDoc()->deepLock();
810} 810}
811 811
812void PwM::unlockWnd_slot() 812void PwM::unlockWnd_slot()
813{ 813{
814 PWM_ASSERT(curDoc()); 814 PWM_ASSERT(curDoc());
815 curDoc()->lockAll(false); 815 curDoc()->lockAll(false);
816} 816}
817 817
818void PwM::config_slot() 818void PwM::config_slot()
819{ 819{
820 int oldStyle = conf()->confWndMainViewStyle(); 820 int oldStyle = conf()->confWndMainViewStyle();
821#ifdef PWM_EMBEDDED 821#ifdef PWM_EMBEDDED
822 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); 822 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true );
823 823
824 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); 824 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" );
825 ConfigureDialog->addModule(pwmcfg ); 825 ConfigureDialog->addModule(pwmcfg );
826 826
827 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 827 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
828 ConfigureDialog->addModule(kdelibcfg ); 828 ConfigureDialog->addModule(kdelibcfg );
829 829
830#ifndef DESKTOP_VERSION 830#ifndef DESKTOP_VERSION
831 ConfigureDialog->showMaximized(); 831 ConfigureDialog->showMaximized();
832#endif 832#endif
833 if ( ConfigureDialog->exec() ) 833 if ( ConfigureDialog->exec() )
834 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 834 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
835 delete ConfigureDialog; 835 delete ConfigureDialog;
836 836
837#else //PWM_EMBEDDED 837#else //PWM_EMBEDDED
838 // display the configuration window (modal mode) 838 // display the configuration window (modal mode)
839 if (!conf()->showConfWnd(this)) 839 if (!conf()->showConfWnd(this))
840 return; 840 return;
841#endif 841#endif
842 842
843 int newStyle = conf()->confWndMainViewStyle(); 843 int newStyle = conf()->confWndMainViewStyle();
844 // reinitialize tray 844 // reinitialize tray
845 init->initTray(); 845 init->initTray();
846 // reinitialize KWallet emulation 846 // reinitialize KWallet emulation
847 init->initKWalletEmu(); 847 init->initKWalletEmu();
848 848
849 PwMDocList *_dl = PwMDoc::getOpenDocList(); 849 PwMDocList *_dl = PwMDoc::getOpenDocList();
850 const vector<PwMDocList::listItem> *dl = _dl->getList(); 850 const vector<PwMDocList::listItem> *dl = _dl->getList();
851 vector<PwMDocList::listItem>::const_iterator i = dl->begin(), 851 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
852 end = dl->end(); 852 end = dl->end();
853 PwMDoc *doc; 853 PwMDoc *doc;
854 while (i != end) { 854 while (i != end) {
855 doc = (*i).doc; 855 doc = (*i).doc;
856 // unlock-without-mpw timeout 856 // unlock-without-mpw timeout
857 doc->timer()->start(DocTimer::id_mpwTimer); 857 doc->timer()->start(DocTimer::id_mpwTimer);
858 // auto-lock timeout 858 // auto-lock timeout
859 doc->timer()->start(DocTimer::id_autoLockTimer); 859 doc->timer()->start(DocTimer::id_autoLockTimer);
860 ++i; 860 ++i;
861 } 861 }
862 862
863 const QValueList<PwM *> *ml = init->mainWndList(); 863 const QValueList<PwM *> *ml = init->mainWndList();
864#ifndef PWM_EMBEDDED 864#ifndef PWM_EMBEDDED
865 QValueList<PwM *>::const_iterator i2 = ml->begin(), 865 QValueList<PwM *>::const_iterator i2 = ml->begin(),
866 end2 = ml->end(); 866 end2 = ml->end();
867#else 867#else
868 QValueList<PwM *>::ConstIterator i2 = ml->begin(), 868 QValueList<PwM *>::ConstIterator i2 = ml->begin(),
869 end2 = ml->end(); 869 end2 = ml->end();
870#endif 870#endif
871 PwM *pwm; 871 PwM *pwm;
872 while (i2 != end2) { 872 while (i2 != end2) {
873 pwm = *i2; 873 pwm = *i2;
874 // reinitialize the window style. 874 // reinitialize the window style.
875 if (oldStyle != newStyle) 875 if (oldStyle != newStyle)
876 pwm->curView()->initStyle(newStyle); 876 pwm->curView()->initStyle(newStyle);
877 // set the new font 877 // set the new font
878 pwm->curView()->setFont(conf()->confGlobEntryFont()); 878 pwm->curView()->setFont(conf()->confGlobEntryFont());
879 ++i2; 879 ++i2;
880 } 880 }
881} 881}
882 882
883void PwM::activateMpButton(bool activate) 883void PwM::activateMpButton(bool activate)
884{ 884{
885 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); 885 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
886} 886}
887 887
888void PwM::closeEvent(QCloseEvent *e) 888void PwM::closeEvent(QCloseEvent *e)
889{ 889{
890 e->accept(); 890 e->accept();
891} 891}
892 892
893void PwM::docClosed(PwMDoc *doc) 893void PwM::docClosed(PwMDoc *doc)
894{ 894{
895 PARAM_UNUSED(doc); 895 PARAM_UNUSED(doc);
896 PWM_ASSERT(doc == curDoc()); 896 PWM_ASSERT(doc == curDoc());
897 close(); 897 close();
898} 898}
899 899
900void PwM::find_slot() 900void PwM::find_slot()
901{ 901{
902 PWM_ASSERT(curDoc()); 902 PWM_ASSERT(curDoc());
903 if (curDoc()->isDocEmpty()) 903 if (curDoc()->isDocEmpty())
904 return; 904 return;
905 if (curDoc()->isDeepLocked()) 905 if (curDoc()->isDeepLocked())
906 return; 906 return;
907 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 907 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
908 FindWndImpl findWnd(view); 908 FindWndImpl findWnd(view);
909 findWnd.exec(); 909 findWnd.exec();
910 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 910 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
911} 911}
912 912
913void PwM::exportToText() 913void PwM::exportToText()
914{ 914{
915 PWM_ASSERT(curDoc()); 915 PWM_ASSERT(curDoc());
916 if (curDoc()->isDocEmpty()) { 916 if (curDoc()->isDocEmpty()) {
917 KMessageBox::information(this, 917 KMessageBox::information(this,
918 i18n 918 i18n
919 ("Sorry, there's nothing to export.\n" 919 ("Sorry, there's nothing to export.\n"
920 "Please first add some passwords."), 920 "Please first add some passwords."),
921 i18n("nothing to do")); 921 i18n("nothing to do"));
922 return; 922 return;
923 } 923 }
924 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 924 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
925 QString fn(KFileDialog::getSaveFileName(QString::null, 925 QString fn(KFileDialog::getSaveFileName(QString::null,
926 i18n("*|plain-text file"), 926 i18n("*|plain-text file"),
927 this)); 927 this));
928 if (fn == "") { 928 if (fn == "") {
929 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 929 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
930 return; 930 return;
931 } 931 }
932 932
933 PwMerror ret = curDoc()->exportToText(&fn); 933 PwMerror ret = curDoc()->exportToText(&fn);
934 if (ret != e_success) { 934 if (ret != e_success) {
935 KMessageBox::error(this, 935 KMessageBox::error(this,
936 i18n("Error: Couldn't write to file.\n" 936 i18n("Error: Couldn't write to file.\n"
937 "Please check if you have permission to write\n" 937 "Please check if you have permission to write\n"
938 "to the file in that directory."), 938 "to the file in that directory."),
939 i18n("error while writing")); 939 i18n("error while writing"));
940 } else 940 } else
941 showStatMsg(i18n("Successfully exported data.")); 941 showStatMsg(i18n("Successfully exported data."));
942 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 942 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
943} 943}
944 944
945bool PwM::importFromText() 945bool PwM::importFromText()
946{ 946{
947 if (!isVirgin()) { 947 if (!isVirgin()) {
948 if (KMessageBox::questionYesNo(this, 948 if (KMessageBox::questionYesNo(this,
949 i18n("Do you want to import the data\n" 949 i18n("Do you want to import the data\n"
950 "into the current document? (If you\n" 950 "into the current document? (If you\n"
951 "select \"no\", a new document will be\n" 951 "select \"no\", a new document will be\n"
952 "opened.)"), 952 "opened.)"),
953 i18n("import into this document?")) 953 i18n("import into this document?"))
954 == KMessageBox::No) { 954 == KMessageBox::No) {
955 // import the data to a new window. 955 // import the data to a new window.
956 PwM *newInstance = init->createMainWnd(); 956 PwM *newInstance = init->createMainWnd();
957 bool ok = newInstance->importFromText(); 957 bool ok = newInstance->importFromText();
958 if (!ok) { 958 if (!ok) {
959 newInstance->setForceQuit(true); 959 newInstance->setForceQuit(true);
960 delete_and_null(newInstance); 960 delete_and_null(newInstance);
961 } 961 }
962 return ok; 962 return ok;
963 } 963 }
964 } 964 }
965 965
966 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 966 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
967 PwMerror ret; 967 PwMerror ret;
968 QString path(KFileDialog::getOpenFileName(QString::null, 968 QString path(KFileDialog::getOpenFileName(QString::null,
969 i18n("*|PWM-exported text file"), 969 i18n("*|PWM-exported text file"),
970 this)); 970 this));
971 if (path == "") 971 if (path == "")
972 goto cancelImport; 972 goto cancelImport;
973 973
974 ret = curDoc()->importFromText(&path, 0); 974 ret = curDoc()->importFromText(&path, 0);
975 if (ret == e_fileFormat) { 975 if (ret == e_fileFormat) {
976 KMessageBox::error(this, 976 KMessageBox::error(this,
977 i18n("Could not read file-format.\n" 977 i18n("Could not read file-format.\n"
978 "This seems to be _not_ a valid file\n" 978 "This seems to be _not_ a valid file\n"
979 "exported by PwM."), 979 "exported by PwM."),
980 i18n("invalid file-format")); 980 i18n("invalid file-format"));
981 goto cancelImport; 981 goto cancelImport;
982 } else if (ret == e_invalidArg) { 982 } else if (ret == e_invalidArg) {
983 BUG(); 983 BUG();
984 goto cancelImport; 984 goto cancelImport;
985 } else if (ret != e_success) { 985 } else if (ret != e_success) {
986 KMessageBox::error(this, 986 KMessageBox::error(this,
987 i18n("Could not import file!\n" 987 i18n("Could not import file!\n"
988 "Do you have permission to read this file?\n" 988 "Do you have permission to read this file?\n"
989 "Do you have enough free memory?"), 989 "Do you have enough free memory?"),
990 i18n("import failed")); 990 i18n("import failed"));
991 goto cancelImport; 991 goto cancelImport;
992 } 992 }
993 setVirgin(false); 993 setVirgin(false);
994 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 994 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
995 return true; 995 return true;
996 996
997cancelImport: 997cancelImport:
998 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 998 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
999 return false; 999 return false;
1000} 1000}
1001 1001
1002void PwM::exportToGpasman() 1002void PwM::exportToGpasman()
1003{ 1003{
1004 PWM_ASSERT(curDoc()); 1004 PWM_ASSERT(curDoc());
1005 if (curDoc()->isDocEmpty()) { 1005 if (curDoc()->isDocEmpty()) {
1006 KMessageBox::information(this, 1006 KMessageBox::information(this,
1007 i18n 1007 i18n
1008 ("Sorry, there's nothing to export.\n" 1008 ("Sorry, there's nothing to export.\n"
1009 "Please first add some passwords."), 1009 "Please first add some passwords."),
1010 i18n("nothing to do")); 1010 i18n("nothing to do"));
1011 return; 1011 return;
1012 } 1012 }
1013 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1013 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1014 QString fn(KFileDialog::getSaveFileName(QString::null, 1014 QString fn(KFileDialog::getSaveFileName(QString::null,
1015 i18n("*|Gpasman or Kpasman file"), 1015 i18n("*|Gpasman or Kpasman file"),
1016 this)); 1016 this));
1017 if (fn == "") { 1017 if (fn == "") {
1018 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1018 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1019 return; 1019 return;
1020 } 1020 }
1021 1021
1022 PwMerror ret = curDoc()->exportToGpasman(&fn); 1022 PwMerror ret = curDoc()->exportToGpasman(&fn);
1023 if (ret != e_success) { 1023 if (ret != e_success) {
1024 if (ret == e_noPw) { 1024 if (ret == e_noPw) {
1025 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1025 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1026 return; 1026 return;
1027 } 1027 }
1028 KMessageBox::error(this, 1028 KMessageBox::error(this,
1029 i18n("Error: Couldn't write to file.\n" 1029 i18n("Error: Couldn't write to file.\n"
1030 "Please check if you have permission to write " 1030 "Please check if you have permission to write "
1031 "to the file in that directory."), 1031 "to the file in that directory."),
1032 i18n("error while writing")); 1032 i18n("error while writing"));
1033 } else 1033 } else
1034 showStatMsg(i18n("Successfully exported data.")); 1034 showStatMsg(i18n("Successfully exported data."));
1035 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1035 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1036} 1036}
1037 1037
1038 1038
1039 1039
1040void PwM::exportToCsv() 1040void PwM::exportToCsv()
1041{ 1041{
1042 PWM_ASSERT(curDoc()); 1042 PWM_ASSERT(curDoc());
1043 if (curDoc()->isDocEmpty()) { 1043 if (curDoc()->isDocEmpty()) {
1044 KMessageBox::information(this, 1044 KMessageBox::information(this,
1045 i18n 1045 i18n
1046 ("Sorry, there is nothing to export;\n" 1046 ("Sorry, there is nothing to export;\n"
1047 "please add some passwords first."), 1047 "please add some passwords first."),
1048 i18n("Nothing to Do")); 1048 i18n("Nothing to Do"));
1049 return; 1049 return;
1050 } 1050 }
1051 1051
1052 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1052 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1053 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); 1053 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this));
1054 if (fn.isEmpty()) { 1054 if (fn.isEmpty()) {
1055 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1055 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1056 return; 1056 return;
1057 } 1057 }
1058 1058
1059 Csv csv(this); 1059 Csv csv(this);
1060 if (!csv.exportData(fn, curDoc())) { 1060 if (!csv.exportData(fn, curDoc())) {
1061 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1061 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1062 showStatMsg(i18n("CSV file export failed.")); 1062 showStatMsg(i18n("CSV file export failed."));
1063 return; 1063 return;
1064 } 1064 }
1065 showStatMsg(i18n("Successfully exported data.")); 1065 showStatMsg(i18n("Successfully exported data."));
1066 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1066 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1067} 1067}
1068 1068
1069bool PwM::importCsv() 1069bool PwM::importCsv()
1070{ 1070{
1071 Csv csv(this); 1071 Csv csv(this);
1072 if (!isVirgin()) { 1072 if (!isVirgin()) {
1073 if (KMessageBox::questionYesNo(this, 1073 if (KMessageBox::questionYesNo(this,
1074 i18n("Do you want to import the data\n" 1074 i18n("Do you want to import the data\n"
1075 "into the current document? (If you\n" 1075 "into the current document? (If you\n"
1076 "select \"no\", a new document will be\n" 1076 "select \"no\", a new document will be\n"
1077 "opened.)"), 1077 "opened.)"),
1078 i18n("Import into This Document?")) 1078 i18n("Import into This Document?"))
1079 == KMessageBox::No) { 1079 == KMessageBox::No) {
1080 // import the data to a new window. 1080 // import the data to a new window.
1081 PwM *newInstance = init->createMainWnd(); 1081 PwM *newInstance = init->createMainWnd();
1082 bool ok = newInstance->importCsv(); 1082 bool ok = newInstance->importCsv();
1083 if (!ok) { 1083 if (!ok) {
1084 newInstance->setForceQuit(true); 1084 newInstance->setForceQuit(true);
1085 delete_and_null(newInstance); 1085 delete_and_null(newInstance);
1086 } 1086 }
1087 return ok; 1087 return ok;
1088 } 1088 }
1089 } 1089 }
1090 1090
1091 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); 1091 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this);
1092 if (filename.isEmpty()) 1092 if (filename.isEmpty())
1093 return false; 1093 return false;
1094 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1094 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1095 if (!csv.importData(filename, curDoc())) { 1095 if (!csv.importData(filename, curDoc())) {
1096 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1096 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1097 showStatMsg(i18n("CSV file import failed.")); 1097 showStatMsg(i18n("CSV file import failed."));
1098 return false; 1098 return false;
1099 } 1099 }
1100 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1100 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1101 KMessageBox::information(this, 1101 KMessageBox::information(this,
1102 i18n("Successfully imported the CSV data\n" 1102 i18n("Successfully imported the CSV data\n"
1103 "into the current document."), i18n("Successfully Imported")); 1103 "into the current document."), i18n("Successfully Imported"));
1104 showStatMsg(i18n("Successfully imported")); 1104 showStatMsg(i18n("Successfully imported"));
1105 setVirgin(false); 1105 setVirgin(false);
1106 return true; 1106 return true;
1107} 1107}
1108 1108
1109 1109
1110void PwM::exportToKWallet() 1110void PwM::exportToKWallet()
1111{ 1111{
1112#ifdef CONFIG_KWALLETIF 1112#ifdef CONFIG_KWALLETIF
1113 if (!checkAndAskForKWalletEmu()) 1113 if (!checkAndAskForKWalletEmu())
1114 return; 1114 return;
1115 PWM_ASSERT(curDoc()); 1115 PWM_ASSERT(curDoc());
1116 if (curDoc()->isDocEmpty()) { 1116 if (curDoc()->isDocEmpty()) {
1117 KMessageBox::information(this, 1117 KMessageBox::information(this,
1118 i18n 1118 i18n
1119 ("Sorry, there's nothing to export.\n" 1119 ("Sorry, there's nothing to export.\n"
1120 "Please first add some passwords."), 1120 "Please first add some passwords."),
1121 i18n("nothing to do")); 1121 i18n("nothing to do"));
1122 init->initKWalletEmu(); 1122 init->initKWalletEmu();
1123 return; 1123 return;
1124 } 1124 }
1125 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1125 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1126 KWalletIf walletIf(this); 1126 KWalletIf walletIf(this);
1127 if (walletIf.kwalletExport(curDoc())) { 1127 if (walletIf.kwalletExport(curDoc())) {
1128 KMessageBox::information(this, 1128 KMessageBox::information(this,
1129 i18n("Successfully exported the data of the current " 1129 i18n("Successfully exported the data of the current "
1130 "document to KWallet."), 1130 "document to KWallet."),
1131 i18n("Successfully exported data.")); 1131 i18n("Successfully exported data."));
1132 showStatMsg(i18n("Successfully exported data.")); 1132 showStatMsg(i18n("Successfully exported data."));
1133 } 1133 }
1134 init->initKWalletEmu(); 1134 init->initKWalletEmu();
1135 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1135 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1136#endif // CONFIG_KWALLETIF 1136#endif // CONFIG_KWALLETIF
1137} 1137}
1138 1138
1139bool PwM::importFromGpasman() 1139bool PwM::importFromGpasman()
1140{ 1140{
1141 if (!isVirgin()) { 1141 if (!isVirgin()) {
1142 if (KMessageBox::questionYesNo(this, 1142 if (KMessageBox::questionYesNo(this,
1143 i18n("Do you want to import the data\n" 1143 i18n("Do you want to import the data\n"
1144 "into the current document? (If you\n" 1144 "into the current document? (If you\n"
1145 "select \"no\", a new document will be\n" 1145 "select \"no\", a new document will be\n"
1146 "opened.)"), 1146 "opened.)"),
1147 i18n("import into this document?")) 1147 i18n("import into this document?"))
1148 == KMessageBox::No) { 1148 == KMessageBox::No) {
1149 // import the data to a new window. 1149 // import the data to a new window.
1150 PwM *newInstance = init->createMainWnd(); 1150 PwM *newInstance = init->createMainWnd();
1151 bool ok = newInstance->importFromGpasman(); 1151 bool ok = newInstance->importFromGpasman();
1152 if (!ok) { 1152 if (!ok) {
1153 newInstance->setForceQuit(true); 1153 newInstance->setForceQuit(true);
1154 delete_and_null(newInstance); 1154 delete_and_null(newInstance);
1155 } 1155 }
1156 return ok; 1156 return ok;
1157 } 1157 }
1158 } 1158 }
1159 1159
1160 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1160 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1161 PwMerror ret; 1161 PwMerror ret;
1162 QString path(KFileDialog::getOpenFileName(QString::null, 1162 QString path(KFileDialog::getOpenFileName(QString::null,
1163 i18n("*|Gpasman or Kpasman file"), this)); 1163 i18n("*|Gpasman or Kpasman file"), this));
1164 if (path == "") 1164 if (path == "")
1165 goto cancelImport; 1165 goto cancelImport;
1166 ret = curDoc()->importFromGpasman(&path); 1166 ret = curDoc()->importFromGpasman(&path);
1167 if (ret == e_wrongPw) { 1167 if (ret == e_wrongPw) {
1168 if (KMessageBox::questionYesNo(this, 1168 if (KMessageBox::questionYesNo(this,
1169 i18n 1169 i18n
1170 ("This is probably the wrong master-password\n" 1170 ("This is probably the wrong master-password\n"
1171 "you have typed in.\n" 1171 "you have typed in.\n"
1172 "There is no real way to determine the\n" 1172 "There is no real way to determine the\n"
1173 "correctness of the password in the Gpasman\n" 1173 "correctness of the password in the Gpasman\n"
1174 "file-format. But I think this\n" 1174 "file-format. But I think this\n"
1175 "password ist wrong.\n" 1175 "password ist wrong.\n"
1176 "Do you want to continue nevertheless?"), 1176 "Do you want to continue nevertheless?"),
1177 i18n("password error")) 1177 i18n("password error"))
1178 == KMessageBox::No) { 1178 == KMessageBox::No) {
1179 goto cancelImport; 1179 goto cancelImport;
1180 } 1180 }
1181 } else if (ret != e_success) { 1181 } else if (ret != e_success) {
1182 KMessageBox::error(this, 1182 KMessageBox::error(this,
1183 i18n("Could not import file!\n" 1183 i18n("Could not import file!\n"
1184 "Do you have permission to read this file?"), 1184 "Do you have permission to read this file?"),
1185 i18n("import failed")); 1185 i18n("import failed"));
1186 goto cancelImport; 1186 goto cancelImport;
1187 } 1187 }
1188 setVirgin(false); 1188 setVirgin(false);
1189 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1189 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1190 return true; 1190 return true;
1191 1191
1192cancelImport: 1192cancelImport:
1193 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1193 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1194 return false; 1194 return false;
1195} 1195}
1196 1196
1197#ifdef CONFIG_KWALLETIF 1197#ifdef CONFIG_KWALLETIF
1198bool PwM::checkAndAskForKWalletEmu() 1198bool PwM::checkAndAskForKWalletEmu()
1199{ 1199{
1200 if (init->kwalletEmu()) { 1200 if (init->kwalletEmu()) {
1201 /* KWallet emulation is enabled. We can't import/export 1201 /* KWallet emulation is enabled. We can't import/export
1202 * data from/to it, while emulation is active. 1202 * data from/to it, while emulation is active.
1203 */ 1203 */
1204 if (KMessageBox::questionYesNo(this, 1204 if (KMessageBox::questionYesNo(this,
1205 i18n("KWallet emulation is enabled.\n" 1205 i18n("KWallet emulation is enabled.\n"
1206 "You can't import or export data from/to " 1206 "You can't import or export data from/to "
1207 "the original KWallet, while the emulation " 1207 "the original KWallet, while the emulation "
1208 "is active.\n" 1208 "is active.\n"
1209 "Do you want to tempoarly disable the KWallet emulation?"), 1209 "Do you want to tempoarly disable the KWallet emulation?"),
1210 i18n("Tempoarly disable KWallet emulation?")) 1210 i18n("Tempoarly disable KWallet emulation?"))
1211 == KMessageBox::Yes) { 1211 == KMessageBox::Yes) {
1212 init->initKWalletEmu(true); 1212 init->initKWalletEmu(true);
1213 PWM_ASSERT(!init->kwalletEmu()); 1213 PWM_ASSERT(!init->kwalletEmu());
1214 return true; 1214 return true;
1215 } 1215 }
1216 return false; 1216 return false;
1217 } 1217 }
1218 return true; 1218 return true;
1219} 1219}
1220#endif // CONFIG_KWALLETIF 1220#endif // CONFIG_KWALLETIF
1221 1221
1222bool PwM::importKWallet() 1222bool PwM::importKWallet()
1223{ 1223{
1224#ifdef CONFIG_KWALLETIF 1224#ifdef CONFIG_KWALLETIF
1225 if (!checkAndAskForKWalletEmu()) 1225 if (!checkAndAskForKWalletEmu())
1226 return false; 1226 return false;
1227 KWalletIf walletIf(this); 1227 KWalletIf walletIf(this);
1228 if (!isVirgin()) { 1228 if (!isVirgin()) {
1229 if (KMessageBox::questionYesNo(this, 1229 if (KMessageBox::questionYesNo(this,
1230 i18n("Do you want to import the data " 1230 i18n("Do you want to import the data "
1231 "into the current document? (If you " 1231 "into the current document? (If you "
1232 "select \"no\", a new document will be " 1232 "select \"no\", a new document will be "
1233 "opened.)"), 1233 "opened.)"),
1234 i18n("import into this document?")) 1234 i18n("import into this document?"))
1235 == KMessageBox::No) { 1235 == KMessageBox::No) {
1236 // import the data to a new window. 1236 // import the data to a new window.
1237 PwM *newInstance = init->createMainWnd(); 1237 PwM *newInstance = init->createMainWnd();
1238 bool ok = newInstance->importKWallet(); 1238 bool ok = newInstance->importKWallet();
1239 if (!ok) { 1239 if (!ok) {
1240 newInstance->setForceQuit(true); 1240 newInstance->setForceQuit(true);
1241 delete_and_null(newInstance); 1241 delete_and_null(newInstance);
1242 goto exit_fail; 1242 goto exit_fail;
1243 } else { 1243 } else {
1244 goto exit_ok; 1244 goto exit_ok;
1245 } 1245 }
1246 } 1246 }
1247 } 1247 }
1248 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1248 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1249 if (!walletIf.kwalletImport(curDoc())) { 1249 if (!walletIf.kwalletImport(curDoc())) {
1250 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1250 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1251 showStatMsg(i18n("KWallet import failed")); 1251 showStatMsg(i18n("KWallet import failed"));
1252 goto exit_fail; 1252 goto exit_fail;
1253 } 1253 }
1254 KMessageBox::information(this, 1254 KMessageBox::information(this,
1255 i18n("Successfully imported the KWallet data " 1255 i18n("Successfully imported the KWallet data "
1256 "into the current document."), 1256 "into the current document."),
1257 i18n("successfully imported")); 1257 i18n("successfully imported"));
1258 showStatMsg(i18n("successfully imported")); 1258 showStatMsg(i18n("successfully imported"));
1259 setVirgin(false); 1259 setVirgin(false);
1260 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1260 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1261 1261
1262exit_ok: 1262exit_ok:
1263 init->initKWalletEmu(); 1263 init->initKWalletEmu();
1264 return true; 1264 return true;
1265 1265
1266exit_fail: 1266exit_fail:
1267 init->initKWalletEmu(); 1267 init->initKWalletEmu();
1268#endif // CONFIG_KWALLETIF 1268#endif // CONFIG_KWALLETIF
1269 return false; 1269 return false;
1270} 1270}
1271 1271
1272void PwM::print_slot() 1272void PwM::print_slot()
1273{ 1273{
1274 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1274 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1275#ifndef PWM_EMBEDDED 1275#ifndef PWM_EMBEDDED
1276 PwMPrint p(curDoc(), this); 1276 PwMPrint p(curDoc(), this);
1277 p.printNow(); 1277 p.printNow();
1278#else 1278#else
1279 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); 1279 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
1280#endif 1280#endif
1281 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1281 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1282} 1282}
1283 1283
1284void PwM::genNewCard_slot() 1284void PwM::genNewCard_slot()
1285{ 1285{
1286#ifdef CONFIG_KEYCARD 1286#ifdef CONFIG_KEYCARD
1287 init->keycard()->genNewCard(); 1287 init->keycard()->genNewCard();
1288#endif 1288#endif
1289} 1289}
1290 1290
1291void PwM::eraseCard_slot() 1291void PwM::eraseCard_slot()
1292{ 1292{
1293#ifdef CONFIG_KEYCARD 1293#ifdef CONFIG_KEYCARD
1294 init->keycard()->eraseCard(); 1294 init->keycard()->eraseCard();
1295#endif 1295#endif
1296} 1296}
1297 1297
1298void PwM::readCardId_slot() 1298void PwM::readCardId_slot()
1299{ 1299{
1300#ifdef CONFIG_KEYCARD 1300#ifdef CONFIG_KEYCARD
1301 init->keycard()->displayKey(); 1301 init->keycard()->displayKey();
1302#endif 1302#endif
1303} 1303}
1304 1304
1305void PwM::makeCardBackup_slot() 1305void PwM::makeCardBackup_slot()
1306{ 1306{
1307#ifdef CONFIG_KEYCARD 1307#ifdef CONFIG_KEYCARD
1308 init->keycard()->makeBackupImage(); 1308 init->keycard()->makeBackupImage();
1309#endif 1309#endif
1310} 1310}
1311 1311
1312void PwM::replayCardBackup_slot() 1312void PwM::replayCardBackup_slot()
1313{ 1313{
1314#ifdef CONFIG_KEYCARD 1314#ifdef CONFIG_KEYCARD
1315 init->keycard()->replayBackupImage(); 1315 init->keycard()->replayBackupImage();
1316#endif 1316#endif
1317} 1317}
1318 1318
1319void PwM::execLauncher_slot() 1319void PwM::execLauncher_slot()
1320{ 1320{
1321 PWM_ASSERT(curDoc()); 1321 PWM_ASSERT(curDoc());
1322 if (curDoc()->isDeepLocked()) 1322 if (curDoc()->isDeepLocked())
1323 return; 1323 return;
1324 unsigned int curEntryIndex; 1324 unsigned int curEntryIndex;
1325 if (!view->getCurEntryIndex(&curEntryIndex)) 1325 if (!view->getCurEntryIndex(&curEntryIndex))
1326 return; 1326 return;
1327 bool ret = curDoc()->execLauncher(view->getCurrentCategory(), 1327 bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
1328 curEntryIndex); 1328 curEntryIndex);
1329 if (ret) 1329 if (ret)
1330 showStatMsg(i18n("Executed the \"Launcher\".")); 1330 showStatMsg(i18n("Executed the \"Launcher\"."));
1331 else 1331 else
1332 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); 1332 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
1333} 1333}
1334 1334
1335void PwM::goToURL_slot() 1335void PwM::goToURL_slot()
1336{ 1336{
1337 PWM_ASSERT(curDoc()); 1337 PWM_ASSERT(curDoc());
1338 if (curDoc()->isDeepLocked()) 1338 if (curDoc()->isDeepLocked())
1339 return; 1339 return;
1340 unsigned int curEntryIndex; 1340 unsigned int curEntryIndex;
1341 if (!view->getCurEntryIndex(&curEntryIndex)) 1341 if (!view->getCurEntryIndex(&curEntryIndex))
1342 return; 1342 return;
1343 bool ret = curDoc()->goToURL(view->getCurrentCategory(), 1343 bool ret = curDoc()->goToURL(view->getCurrentCategory(),
1344 curEntryIndex); 1344 curEntryIndex);
1345 if (ret) 1345 if (ret)
1346 showStatMsg(i18n("started browser with current URL.")); 1346 showStatMsg(i18n("started browser with current URL."));
1347 else 1347 else
1348 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); 1348 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
1349} 1349}
1350 1350
1351void PwM::copyToClipboard(const QString &s) 1351void PwM::copyToClipboard(const QString &s)
1352{ 1352{
1353 QClipboard *cb = QApplication::clipboard(); 1353 QClipboard *cb = QApplication::clipboard();
1354#ifndef PWM_EMBEDDED 1354#ifndef PWM_EMBEDDED
1355 if (cb->supportsSelection()) 1355 if (cb->supportsSelection())
1356 cb->setText(s, QClipboard::Selection); 1356 cb->setText(s, QClipboard::Selection);
1357 cb->setText(s, QClipboard::Clipboard); 1357 cb->setText(s, QClipboard::Clipboard);
1358#else 1358#else
1359 cb->setText(s); 1359 cb->setText(s);
1360 1360
1361#endif 1361#endif
1362 1362
1363} 1363}
1364 1364
1365 1365
1366void PwM::showStatMsg(const QString &msg) 1366void PwM::showStatMsg(const QString &msg)
1367{ 1367{
1368#ifdef DESKTOP_VERSION 1368#ifdef DESKTOP_VERSION
1369 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); 1369 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
1370#else 1370#else
1371 qDebug("Statusbar : %s",msg.latin1()); 1371 qDebug("Statusbar : %s",msg.latin1());
1372 Global::statusMessage(msg); 1372 Global::statusMessage(msg);
1373#endif 1373#endif
1374} 1374}
1375 1375
1376void PwM::focusInEvent(QFocusEvent *e) 1376void PwM::focusInEvent(QFocusEvent *e)
1377{ 1377{
1378 if (e->gotFocus()) { 1378 if (e->gotFocus()) {
1379 emit gotFocus(this); 1379 emit gotFocus(this);
1380 } else if (e->lostFocus()) { 1380 } else if (e->lostFocus()) {
1381 emit lostFocus(this); 1381 emit lostFocus(this);
1382 } 1382 }
1383} 1383}
1384 1384
1385 1385
1386#ifdef PWM_EMBEDDED 1386#ifdef PWM_EMBEDDED
1387 1387
1388void PwM::whatsnew_slot() 1388void PwM::whatsnew_slot()
1389{ 1389{
1390 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 1390 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
1391} 1391}
1392 1392
1393void PwM::showLicense_slot() 1393void PwM::showLicense_slot()
1394{ 1394{
1395 KApplication::showLicence(); 1395 KApplication::showLicence();
1396} 1396}
1397 1397
1398void PwM::faq_slot() 1398void PwM::faq_slot()
1399{ 1399{
1400 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); 1400 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
1401} 1401}
1402 1402
1403void PwM::syncHowTo_slot() 1403void PwM::syncHowTo_slot()
1404{ 1404{
1405 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 1405 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
1406} 1406}
1407 1407
1408 1408
1409void PwM::createAboutData_slot() 1409void PwM::createAboutData_slot()
1410{ 1410{
1411 QString version; 1411 QString version;
1412#include <../version> 1412#include <../version>
1413;
1413 QMessageBox::about( this, "About PwManager/Pi", 1414 QMessageBox::about( this, "About PwManager/Pi",
1414 "PwManager/Platform-independent\n" 1415 "PwManager/Platform-independent\n"
1415 "(PWM/Pi) " +version + " - " + 1416 "(PWM/Pi) " +version + " - " +
1416#ifdef DESKTOP_VERSION 1417#ifdef DESKTOP_VERSION
1417 "Desktop Edition\n" 1418 "Desktop Edition\n"
1418#else 1419#else
1419 "PDA-Edition\n" 1420 "PDA-Edition\n"
1420 "for: Zaurus 5500 / 7x0 / 8x0\n" 1421 "for: Zaurus 5500 / 7x0 / 8x0\n"
1421#endif 1422#endif
1422 1423
1423 "(c) 2004 Ulf Schenk\n" 1424 "(c) 2004 Ulf Schenk\n"
1424 "(c) 2004 Lutz Rogowski\n" 1425 "(c) 2004 Lutz Rogowski\n"
1425 "(c) 1997-2004, The KDE PIM Team\n" 1426 "(c) 1997-2004, The KDE PIM Team\n"
1426 1427
1427 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" 1428 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
1428 "Matt Scifo - mscifo@o1.com\n" 1429 "Matt Scifo - mscifo@o1.com\n"
1429 "Elias Probst - elias.probst@gmx.de\n" 1430 "Elias Probst - elias.probst@gmx.de\n"
1430 "George Staikos - staikos@kde.org\n" 1431 "George Staikos - staikos@kde.org\n"
1431 "Matthew Palmer - mjp16@uow.edu.au\n" 1432 "Matthew Palmer - mjp16@uow.edu.au\n"
1432 "Olivier Sessink - gpasman@nl.linux.org\n" 1433 "Olivier Sessink - gpasman@nl.linux.org\n"
1433 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" 1434 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
1434 "Troy Engel - tengel@sonic.net\n" 1435 "Troy Engel - tengel@sonic.net\n"
1435 "Wickey - wickey@gmx.at\n" 1436 "Wickey - wickey@gmx.at\n"
1436 "Ian MacGregor - original documentation author.\n" 1437 "Ian MacGregor - original documentation author.\n"
1437 ); 1438 );
1438} 1439}
1439 1440
1440 1441
1441//this are the overwritten callbackmethods from the syncinterface 1442//this are the overwritten callbackmethods from the syncinterface
1442bool PwM::sync(KSyncManager* manager, QString filename, int mode) 1443bool PwM::sync(KSyncManager* manager, QString filename, int mode)
1443{ 1444{
1444 PWM_ASSERT(curDoc()); 1445 PWM_ASSERT(curDoc());
1445 1446
1446 bool ret = curDoc()->sync(manager, filename, mode); 1447 bool ret = curDoc()->sync(manager, filename, mode);
1447 1448
1448 qDebug("PwM::sync save now: ret=%i", ret); 1449 qDebug("PwM::sync save now: ret=%i", ret);
1449 1450
1450 if (ret == true) { 1451 if (ret == true) {
1451 //US BUG: what can we call here to update the view of the current doc? 1452 //US BUG: what can we call here to update the view of the current doc?
1452 //mViewManager->refreshView(); 1453 //mViewManager->refreshView();
1453 1454
1454 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. 1455 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull.
1455 save(); 1456 save();
1456 } 1457 }
1457 1458
1458 return ret; 1459 return ret;
1459} 1460}
1460#endif 1461#endif
1461 1462
1462 1463
1463#ifndef PWM_EMBEDDED 1464#ifndef PWM_EMBEDDED
1464#include "pwm.moc" 1465#include "pwm.moc"
1465#endif 1466#endif
diff --git a/pwmanager/pwmanager/pwmanager.pro b/pwmanager/pwmanager/pwmanager.pro
index 80b2519..fbc0554 100644
--- a/pwmanager/pwmanager/pwmanager.pro
+++ b/pwmanager/pwmanager/pwmanager.pro
@@ -1,175 +1,175 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG += qt warn_off 2 CONFIG += qt warn_off
3DESTDIR= ../../bin 3DESTDIR= ../../bin
4 TARGET = pwmpi 4 TARGET = pwmpi
5include( ../../variables.pri ) 5include( ../../variables.pri )
6 6
7INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils 7INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils ../libcrypt/crypt ../libcrypt/error ../libcrypt/zlib
8DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION 8DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION
9 9
10#enable this setting if you want debugoutput for pwmanager 10#enable this setting if you want debugoutput for pwmanager
11#DEFINES += CONFIG_DEBUG 11#DEFINES += CONFIG_DEBUG
12LIBS += -L../libcrypt/ 12LIBS += -L../libcrypt/
13LIBS += -L../../bin/ 13LIBS += -L../../bin/
14LIBS += -lmicrokde 14LIBS += -lmicrokde
15LIBS += -lmicrokdepim 15LIBS += -lmicrokdepim
16LIBS += -lzlib 16LIBS += -lzlib
17LIBS += -lkpmicrocipher 17LIBS += -lkpmicrocipher
18LIBS += -lkpmicroerror 18LIBS += -lkpmicroerror
19LIBS += -lkpmicrompi 19LIBS += -lkpmicrompi
20LIBS += -lstdc++ 20LIBS += -lstdc++
21 21
22unix:{ 22unix:{
23OBJECTS_DIR = obj/unix 23OBJECTS_DIR = obj/unix
24MOC_DIR = moc/unix 24MOC_DIR = moc/unix
25 25
26} 26}
27win32:{ 27win32:{
28 28
29DEFINES += _WIN32_ 29DEFINES += _WIN32_
30OBJECTS_DIR = obj/win 30OBJECTS_DIR = obj/win
31MOC_DIR = moc/win 31MOC_DIR = moc/win
32QMAKE_LINK += /NODEFAULTLIB:LIBC 32QMAKE_LINK += /NODEFAULTLIB:LIBC
33QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc 33QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc
34} 34}
35 35
36#INTERFACES = \ 36#INTERFACES = \
37#addentrywnd.ui \ 37#addentrywnd.ui \
38#configwnd.ui \ 38#configwnd.ui \
39#findwnd.ui \ 39#findwnd.ui \
40#getmasterpwwnd.ui \ 40#getmasterpwwnd.ui \
41#pwgenwnd.ui \ 41#pwgenwnd.ui \
42#setmasterpwwnd.ui \ 42#setmasterpwwnd.ui \
43#subtbledit.ui 43#subtbledit.ui
44 44
45#INTERFACES = \ 45#INTERFACES = \
46#subtbledit.ui \ 46#subtbledit.ui \
47 47
48 48
49 49
50#HEADERS = \ 50#HEADERS = \
51#configuration_31compat.h \ 51#configuration_31compat.h \
52#configuration.h \ 52#configuration.h \
53#configwnd.h \ 53#configwnd.h \
54#configwndimpl.h \ 54#configwndimpl.h \
55#selftest.h 55#selftest.h
56#subtbledit.h \ 56#subtbledit.h \
57#subtbleditimpl.h \ 57#subtbleditimpl.h \
58#compressbzip2.h \ 58#compressbzip2.h \
59 59
60HEADERS = \ 60HEADERS = \
61addentrywnd_emb.h \ 61addentrywnd_emb.h \
62addentrywndimpl.h \ 62addentrywndimpl.h \
63base64.h \ 63base64.h \
64binentrygen.h \ 64binentrygen.h \
65blowfish.h \ 65blowfish.h \
66commentbox.h \ 66commentbox.h \
67compiler.h \ 67compiler.h \
68compressgzip.h \ 68compressgzip.h \
69csv.h \ 69csv.h \
70findwnd_emb.h \ 70findwnd_emb.h \
71findwndimpl.h \ 71findwndimpl.h \
72genpasswd.h \ 72genpasswd.h \
73getkeycardwnd.h \ 73getkeycardwnd.h \
74getmasterpwwnd_emb.h \ 74getmasterpwwnd_emb.h \
75getmasterpwwndimpl.h \ 75getmasterpwwndimpl.h \
76globalstuff.h \ 76globalstuff.h \
77gpasmanfile.h \ 77gpasmanfile.h \
78htmlgen.h \ 78htmlgen.h \
79htmlparse.h \ 79htmlparse.h \
80ipc.h \ 80ipc.h \
81libgcryptif.h \ 81libgcryptif.h \
82listobjselectwnd.h \ 82listobjselectwnd.h \
83listviewpwm.h \ 83listviewpwm.h \
84printtext.h \ 84printtext.h \
85pwgenwnd_emb.h \ 85pwgenwnd_emb.h \
86pwgenwndimpl.h \ 86pwgenwndimpl.h \
87pwmdoc.h \ 87pwmdoc.h \
88pwmdocui.h \ 88pwmdocui.h \
89pwmexception.h \ 89pwmexception.h \
90pwm.h \ 90pwm.h \
91pwminit.h \ 91pwminit.h \
92pwmprefs.h \ 92pwmprefs.h \
93pwmprint.h \ 93pwmprint.h \
94pwmtray.h \ 94pwmtray.h \
95pwmview.h \ 95pwmview.h \
96pwmviewstyle_0.h \ 96pwmviewstyle_0.h \
97pwmviewstyle_1.h \ 97pwmviewstyle_1.h \
98pwmviewstyle.h \ 98pwmviewstyle.h \
99randomizer.h \ 99randomizer.h \
100rc2.h \ 100rc2.h \
101rencatwnd.h \ 101rencatwnd.h \
102serializer.h \ 102serializer.h \
103setmasterpwwnd_emb.h \ 103setmasterpwwnd_emb.h \
104setmasterpwwndimpl.h \ 104setmasterpwwndimpl.h \
105sha1.h \ 105sha1.h \
106waitwnd.h \ 106waitwnd.h \
107kcmconfigs/kcmpwmconfig.h \ 107kcmconfigs/kcmpwmconfig.h \
108kcmconfigs/pwmconfigwidget.h 108kcmconfigs/pwmconfigwidget.h
109 109
110#sources that need not be build 110#sources that need not be build
111#SOURCES = \ 111#SOURCES = \
112#advcommeditimpl.cpp \ 112#advcommeditimpl.cpp \
113#configuration.cpp \ 113#configuration.cpp \
114#configwnd.cpp \ 114#configwnd.cpp \
115#configwndimpl.cpp \ 115#configwndimpl.cpp \
116#configuration_31compat.cpp \ 116#configuration_31compat.cpp \
117#htmlparse.cpp \ 117#htmlparse.cpp \
118#printtext.cpp \ 118#printtext.cpp \
119#selftest.cpp \ 119#selftest.cpp \
120#pwmprint.cpp \ 120#pwmprint.cpp \
121#spinforsignal.cpp 121#spinforsignal.cpp
122#subtbledit.cpp \ 122#subtbledit.cpp \
123#subtbleditimpl.cpp \ 123#subtbleditimpl.cpp \
124#compressbzip2.cpp 124#compressbzip2.cpp
125 125
126 126
127SOURCES = \ 127SOURCES = \
128addentrywnd_emb.cpp \ 128addentrywnd_emb.cpp \
129addentrywndimpl.cpp \ 129addentrywndimpl.cpp \
130base64.cpp \ 130base64.cpp \
131binentrygen.cpp \ 131binentrygen.cpp \
132blowfish.cpp \ 132blowfish.cpp \
133commentbox.cpp \ 133commentbox.cpp \
134compressgzip.cpp \ 134compressgzip.cpp \
135csv.cpp \ 135csv.cpp \
136findwnd_emb.cpp \ 136findwnd_emb.cpp \
137findwndimpl.cpp \ 137findwndimpl.cpp \
138genpasswd.cpp \ 138genpasswd.cpp \
139getkeycardwnd.cpp \ 139getkeycardwnd.cpp \
140getmasterpwwnd_emb.cpp \ 140getmasterpwwnd_emb.cpp \
141getmasterpwwndimpl.cpp \ 141getmasterpwwndimpl.cpp \
142globalstuff.cpp \ 142globalstuff.cpp \
143gpasmanfile.cpp \ 143gpasmanfile.cpp \
144htmlgen.cpp \ 144htmlgen.cpp \
145ipc.cpp \ 145ipc.cpp \
146libgcryptif.cpp \ 146libgcryptif.cpp \
147listobjselectwnd.cpp \ 147listobjselectwnd.cpp \
148listviewpwm.cpp \ 148listviewpwm.cpp \
149main.cpp \ 149main.cpp \
150pwgenwnd_emb.cpp \ 150pwgenwnd_emb.cpp \
151pwgenwndimpl.cpp \ 151pwgenwndimpl.cpp \
152pwm.cpp \ 152pwm.cpp \
153pwmdoc.cpp \ 153pwmdoc.cpp \
154pwmdocui.cpp \ 154pwmdocui.cpp \
155pwmexception.cpp \ 155pwmexception.cpp \
156pwminit.cpp \ 156pwminit.cpp \
157pwmprefs.cpp \ 157pwmprefs.cpp \
158pwmtray.cpp \ 158pwmtray.cpp \
159pwmview.cpp \ 159pwmview.cpp \
160pwmviewstyle_0.cpp \ 160pwmviewstyle_0.cpp \
161pwmviewstyle_1.cpp \ 161pwmviewstyle_1.cpp \
162pwmviewstyle.cpp \ 162pwmviewstyle.cpp \
163randomizer.cpp \ 163randomizer.cpp \
164rc2.cpp \ 164rc2.cpp \
165rencatwnd.cpp \ 165rencatwnd.cpp \
166serializer.cpp \ 166serializer.cpp \
167setmasterpwwnd_emb.cpp \ 167setmasterpwwnd_emb.cpp \
168setmasterpwwndimpl.cpp \ 168setmasterpwwndimpl.cpp \
169sha1.cpp \ 169sha1.cpp \
170waitwnd.cpp \ 170waitwnd.cpp \
171kcmconfigs/kcmpwmconfig.cpp \ 171kcmconfigs/kcmpwmconfig.cpp \
172kcmconfigs/pwmconfigwidget.cpp 172kcmconfigs/pwmconfigwidget.cpp
173 173
174 174
175 175
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 86b6273..129bf7b 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1,1279 +1,1282 @@
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#ifndef _WIN32_
58#include <unistd.h> 59#include <unistd.h>
59#include <stdint.h> 60#include <stdint.h>
60 61#endif
61 62
62#ifdef PWM_EMBEDDED 63#ifdef PWM_EMBEDDED
63#ifndef Q_LONG 64#ifndef Q_LONG
64#define Q_LONG long 65#define Q_LONG long
65#endif 66#endif
66 67
67#ifndef Q_ULONG 68#ifndef Q_ULONG
68#define Q_ULONG unsigned long 69#define Q_ULONG unsigned long
69#endif 70#endif
70#endif //PWM_EMBEDDED 71#endif //PWM_EMBEDDED
71 72
72 73
73//TODO: reset to its normal value. 74//TODO: reset to its normal value.
74 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ 75 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */
75 76
76using namespace std; 77using namespace std;
77 78
78 79
79void PwMDocList::add(PwMDoc *doc, const string &id) 80void PwMDocList::add(PwMDoc *doc, const string &id)
80{ 81{
81#ifdef PWM_DEBUG 82#ifdef PWM_DEBUG
82 // check for existance of object in debug mode only. 83 // check for existance of object in debug mode only.
83 vector<listItem>::iterator begin = docList.begin(), 84 vector<listItem>::iterator begin = docList.begin(),
84 end = docList.end(), 85 end = docList.end(),
85 i = begin; 86 i = begin;
86 while (i != end) { 87 while (i != end) {
87 if (i->doc == doc) { 88 if (i->doc == doc) {
88 BUG(); 89 BUG();
89 return; 90 return;
90 } 91 }
91 ++i; 92 ++i;
92 } 93 }
93#endif 94#endif
94 listItem newItem; 95 listItem newItem;
95 newItem.doc = doc; 96 newItem.doc = doc;
96 newItem.docId = id; 97 newItem.docId = id;
97 docList.push_back(newItem); 98 docList.push_back(newItem);
98} 99}
99 100
100void PwMDocList::edit(PwMDoc *doc, const string &newId) 101void PwMDocList::edit(PwMDoc *doc, const string &newId)
101{ 102{
102 vector<listItem>::iterator begin = docList.begin(), 103 vector<listItem>::iterator begin = docList.begin(),
103 end = docList.end(), 104 end = docList.end(),
104 i = begin; 105 i = begin;
105 while (i != end) { 106 while (i != end) {
106 if (i->doc == doc) { 107 if (i->doc == doc) {
107 i->docId = newId; 108 i->docId = newId;
108 return; 109 return;
109 } 110 }
110 ++i; 111 ++i;
111 } 112 }
112} 113}
113 114
114void PwMDocList::del(PwMDoc *doc) 115void PwMDocList::del(PwMDoc *doc)
115{ 116{
116 vector<listItem>::iterator begin = docList.begin(), 117 vector<listItem>::iterator begin = docList.begin(),
117 end = docList.end(), 118 end = docList.end(),
118 i = begin; 119 i = begin;
119 while (i != end) { 120 while (i != end) {
120 if (i->doc == doc) { 121 if (i->doc == doc) {
121 docList.erase(i); 122 docList.erase(i);
122 return; 123 return;
123 } 124 }
124 ++i; 125 ++i;
125 } 126 }
126} 127}
127 128
128bool PwMDocList::find(const string &id, listItem *ret) 129bool PwMDocList::find(const string &id, listItem *ret)
129{ 130{
130 vector<listItem>::iterator begin = docList.begin(), 131 vector<listItem>::iterator begin = docList.begin(),
131 end = docList.end(), 132 end = docList.end(),
132 i = begin; 133 i = begin;
133 while (i != end) { 134 while (i != end) {
134 if (i->docId == id) { 135 if (i->docId == id) {
135 if (ret) 136 if (ret)
136 *ret = *i; 137 *ret = *i;
137 return true; 138 return true;
138 } 139 }
139 ++i; 140 ++i;
140 } 141 }
141 return false; 142 return false;
142} 143}
143 144
144 145
145 146
146DocTimer::DocTimer(PwMDoc *_doc) 147DocTimer::DocTimer(PwMDoc *_doc)
147 : doc (_doc) 148 : doc (_doc)
148 , mpwLock (0) 149 , mpwLock (0)
149 , autoLockLock (0) 150 , autoLockLock (0)
150 , metaCheckLock (0) 151 , metaCheckLock (0)
151{ 152{
152 mpwTimer = new QTimer; 153 mpwTimer = new QTimer;
153 autoLockTimer = new QTimer; 154 autoLockTimer = new QTimer;
154 metaCheckTimer = new QTimer; 155 metaCheckTimer = new QTimer;
155 connect(mpwTimer, SIGNAL(timeout()), 156 connect(mpwTimer, SIGNAL(timeout()),
156 this, SLOT(mpwTimeout())); 157 this, SLOT(mpwTimeout()));
157 connect(autoLockTimer, SIGNAL(timeout()), 158 connect(autoLockTimer, SIGNAL(timeout()),
158 this, SLOT(autoLockTimeout())); 159 this, SLOT(autoLockTimeout()));
159 connect(metaCheckTimer, SIGNAL(timeout()), 160 connect(metaCheckTimer, SIGNAL(timeout()),
160 this, SLOT(metaCheckTimeout())); 161 this, SLOT(metaCheckTimeout()));
161} 162}
162 163
163DocTimer::~DocTimer() 164DocTimer::~DocTimer()
164{ 165{
165 delete mpwTimer; 166 delete mpwTimer;
166 delete autoLockTimer; 167 delete autoLockTimer;
167 delete metaCheckTimer; 168 delete metaCheckTimer;
168} 169}
169 170
170void DocTimer::start(TimerIDs timer) 171void DocTimer::start(TimerIDs timer)
171{ 172{
172 switch (timer) { 173 switch (timer) {
173 case id_mpwTimer: 174 case id_mpwTimer:
174 if (mpwTimer->isActive()) 175 if (mpwTimer->isActive())
175 mpwTimer->stop(); 176 mpwTimer->stop();
176 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 177 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
177 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); 178 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
178 break; 179 break;
179 case id_autoLockTimer: 180 case id_autoLockTimer:
180 if (autoLockTimer->isActive()) 181 if (autoLockTimer->isActive())
181 autoLockTimer->stop(); 182 autoLockTimer->stop();
182 if (conf()->confGlobLockTimeout() > 0) 183 if (conf()->confGlobLockTimeout() > 0)
183 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); 184 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
184 break; 185 break;
185 case id_metaCheckTimer: 186 case id_metaCheckTimer:
186 if (metaCheckTimer->isActive()) 187 if (metaCheckTimer->isActive())
187 metaCheckTimer->stop(); 188 metaCheckTimer->stop();
188 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 189 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
189 break; 190 break;
190 } 191 }
191} 192}
192 193
193void DocTimer::stop(TimerIDs timer) 194void DocTimer::stop(TimerIDs timer)
194{ 195{
195 switch (timer) { 196 switch (timer) {
196 case id_mpwTimer: 197 case id_mpwTimer:
197 mpwTimer->stop(); 198 mpwTimer->stop();
198 break; 199 break;
199 case id_autoLockTimer: 200 case id_autoLockTimer:
200 autoLockTimer->stop(); 201 autoLockTimer->stop();
201 break; 202 break;
202 case id_metaCheckTimer: 203 case id_metaCheckTimer:
203 metaCheckTimer->stop(); 204 metaCheckTimer->stop();
204 break; 205 break;
205 } 206 }
206} 207}
207 208
208void DocTimer::getLock(TimerIDs timer) 209void DocTimer::getLock(TimerIDs timer)
209{ 210{
210 switch (timer) { 211 switch (timer) {
211 case id_mpwTimer: 212 case id_mpwTimer:
212 ++mpwLock; 213 ++mpwLock;
213 break; 214 break;
214 case id_autoLockTimer: 215 case id_autoLockTimer:
215 ++autoLockLock; 216 ++autoLockLock;
216 break; 217 break;
217 case id_metaCheckTimer: 218 case id_metaCheckTimer:
218 ++metaCheckLock; 219 ++metaCheckLock;
219 break; 220 break;
220 } 221 }
221} 222}
222 223
223void DocTimer::putLock(TimerIDs timer) 224void DocTimer::putLock(TimerIDs timer)
224{ 225{
225 switch (timer) { 226 switch (timer) {
226 case id_mpwTimer: 227 case id_mpwTimer:
227 if (mpwLock) 228 if (mpwLock)
228 --mpwLock; 229 --mpwLock;
229 break; 230 break;
230 case id_autoLockTimer: 231 case id_autoLockTimer:
231 if (autoLockLock) 232 if (autoLockLock)
232 --autoLockLock; 233 --autoLockLock;
233 break; 234 break;
234 case id_metaCheckTimer: 235 case id_metaCheckTimer:
235 if (metaCheckLock) 236 if (metaCheckLock)
236 --metaCheckLock; 237 --metaCheckLock;
237 break; 238 break;
238 } 239 }
239} 240}
240 241
241void DocTimer::mpwTimeout() 242void DocTimer::mpwTimeout()
242{ 243{
243 if (mpwLock) { 244 if (mpwLock) {
244 mpwTimer->start(1000, true); 245 mpwTimer->start(1000, true);
245 return; 246 return;
246 } 247 }
247 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 248 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
248} 249}
249 250
250void DocTimer::autoLockTimeout() 251void DocTimer::autoLockTimeout()
251{ 252{
252 if (autoLockLock) { 253 if (autoLockLock) {
253 autoLockTimer->start(1000, true); 254 autoLockTimer->start(1000, true);
254 return; 255 return;
255 } 256 }
256 if (conf()->confGlobAutoDeepLock() && 257 if (conf()->confGlobAutoDeepLock() &&
257 doc->filename != QString::null && 258 doc->filename != QString::null &&
258 doc->filename != "") { 259 doc->filename != "") {
259 doc->deepLock(true); 260 doc->deepLock(true);
260 } else { 261 } else {
261 doc->lockAll(true); 262 doc->lockAll(true);
262 } 263 }
263} 264}
264 265
265void DocTimer::metaCheckTimeout() 266void DocTimer::metaCheckTimeout()
266{ 267{
267 if (metaCheckLock) { 268 if (metaCheckLock) {
268 // check again in one second. 269 // check again in one second.
269 metaCheckTimer->start(1000, true); 270 metaCheckTimer->start(1000, true);
270 return; 271 return;
271 } 272 }
272 if (doc->isDeepLocked()) { 273 if (doc->isDeepLocked()) {
273 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 274 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
274 return; 275 return;
275 } 276 }
276 if (doc->isDocEmpty()) { 277 if (doc->isDocEmpty()) {
277 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 278 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
278 return; 279 return;
279 } 280 }
280#ifdef CONFIG_KWALLETIF 281#ifdef CONFIG_KWALLETIF
281 KWalletEmu *kwlEmu = doc->init->kwalletEmu(); 282 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
282 if (kwlEmu) 283 if (kwlEmu)
283 kwlEmu->suspendDocSignals(); 284 kwlEmu->suspendDocSignals();
284#endif // CONFIG_KWALLETIF 285#endif // CONFIG_KWALLETIF
285 /* We simply trigger all views to update their 286 /* We simply trigger all views to update their
286 * displayed values. This way they have a chance 287 * displayed values. This way they have a chance
287 * to get notified when some meta changes over time. 288 * to get notified when some meta changes over time.
288 * (for example an entry expired). 289 * (for example an entry expired).
289 * The _view_ is responsive for not updating its 290 * The _view_ is responsive for not updating its
290 * contents if nothing really changed! 291 * contents if nothing really changed!
291 */ 292 */
292 emit doc->dataChanged(doc); 293 emit doc->dataChanged(doc);
293#ifdef CONFIG_KWALLETIF 294#ifdef CONFIG_KWALLETIF
294 if (kwlEmu) 295 if (kwlEmu)
295 kwlEmu->resumeDocSignals(); 296 kwlEmu->resumeDocSignals();
296#endif // CONFIG_KWALLETIF 297#endif // CONFIG_KWALLETIF
297 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 298 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
298} 299}
299 300
300 301
301 302
302PwMDocList PwMDoc::openDocList; 303PwMDocList PwMDoc::openDocList;
303unsigned int PwMDocList::unnamedDocCnt = 1; 304unsigned int PwMDocList::unnamedDocCnt = 1;
304 305
305PwMDoc::PwMDoc(QObject *parent, const char *name) 306PwMDoc::PwMDoc(QObject *parent, const char *name)
306 : PwMDocUi(parent, name) 307 : PwMDocUi(parent, name)
307 , dataChangedLock (0) 308 , dataChangedLock (0)
308{ 309{
309 deleted = false; 310 deleted = false;
310 unnamedNum = 0; 311 unnamedNum = 0;
311 getOpenDocList()->add(this, getTitle().latin1()); 312 getOpenDocList()->add(this, getTitle().latin1());
312 curDocStat = 0; 313 curDocStat = 0;
313 setMaxNumEntries(); 314 setMaxNumEntries();
314 _timer = new DocTimer(this); 315 _timer = new DocTimer(this);
315 timer()->start(DocTimer::id_mpwTimer); 316 timer()->start(DocTimer::id_mpwTimer);
316 timer()->start(DocTimer::id_autoLockTimer); 317 timer()->start(DocTimer::id_autoLockTimer);
317 timer()->start(DocTimer::id_metaCheckTimer); 318 timer()->start(DocTimer::id_metaCheckTimer);
318 addCategory(DEFAULT_CATEGORY, 0, false); 319 addCategory(DEFAULT_CATEGORY, 0, false);
319 listView = 0; 320 listView = 0;
320 emit docCreated(this); 321 emit docCreated(this);
321} 322}
322 323
323PwMDoc::~PwMDoc() 324PwMDoc::~PwMDoc()
324{ 325{
325 emit docClosed(this); 326 emit docClosed(this);
326 getOpenDocList()->del(this); 327 getOpenDocList()->del(this);
327 delete _timer; 328 delete _timer;
328} 329}
329 330
330PwMerror PwMDoc::saveDoc(char compress, const QString *file) 331PwMerror PwMDoc::saveDoc(char compress, const QString *file)
331{ 332{
332 PwMerror ret, e; 333 PwMerror ret, e;
333 string serialized; 334 string serialized;
334 QFile f; 335 QFile f;
335 QString tmpFileMoved(QString::null); 336 QString tmpFileMoved(QString::null);
336 bool wasDeepLocked; 337 bool wasDeepLocked;
337 QString savedFilename(filename); 338 QString savedFilename(filename);
338 339
339 if (!file) { 340 if (!file) {
340 if (filename == "") 341 if (filename == "")
341 return e_filename; 342 return e_filename;
342 if (isDeepLocked()) { 343 if (isDeepLocked()) {
343 /* We don't need to save any data. 344 /* We don't need to save any data.
344 * It's already all on disk, because 345 * It's already all on disk, because
345 * we are deeplocked. 346 * we are deeplocked.
346 */ 347 */
347 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 348 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
348 ret = e_success; 349 ret = e_success;
349 return ret; 350 return ret;
350 } 351 }
351 } else { 352 } else {
352 if (*file == "" && filename == "") 353 if (*file == "" && filename == "")
353 return e_filename; 354 return e_filename;
354 if (*file != "") 355 if (*file != "")
355 filename = *file; 356 filename = *file;
356 } 357 }
357 358
358 wasDeepLocked = isDeepLocked(); 359 wasDeepLocked = isDeepLocked();
359 if (wasDeepLocked) { 360 if (wasDeepLocked) {
360 /* We are deeplocked. That means all data is already 361 /* We are deeplocked. That means all data is already
361 * on disk. BUT we need to do saving procedure, 362 * on disk. BUT we need to do saving procedure,
362 * because *file != savedFilename. 363 * because *file != savedFilename.
363 * Additionally we need to tempoarly restore 364 * Additionally we need to tempoarly restore
364 * the old "filename", because deepLock() references it. 365 * the old "filename", because deepLock() references it.
365 */ 366 */
366 QString newFilename(filename); 367 QString newFilename(filename);
367 filename = savedFilename; 368 filename = savedFilename;
368 getDataChangedLock(); 369 getDataChangedLock();
369 e = deepLock(false); 370 e = deepLock(false);
370 putDataChangedLock(); 371 putDataChangedLock();
371 filename = newFilename; 372 filename = newFilename;
372 switch (e) { 373 switch (e) {
373 case e_success: 374 case e_success:
374 break; 375 break;
375 case e_wrongPw: 376 case e_wrongPw:
376 case e_noPw: 377 case e_noPw:
377 emitDataChanged(this); 378 emitDataChanged(this);
378 return e; 379 return e;
379 default: 380 default:
380 emitDataChanged(this); 381 emitDataChanged(this);
381 return e_openFile; 382 return e_openFile;
382 } 383 }
383 } 384 }
384 385
385 if (!isPwAvailable()) { 386 if (!isPwAvailable()) {
386 /* password is not available. This means, the 387 /* password is not available. This means, the
387 * document wasn't saved, yet. 388 * document wasn't saved, yet.
388 */ 389 */
389 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 390 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
390 QString pw(requestNewMpw(&useChipcard)); 391 QString pw(requestNewMpw(&useChipcard));
391 if (pw != "") { 392 if (pw != "") {
392 currentPw = pw; 393 currentPw = pw;
393 } else { 394 } else {
394 return e_noPw; 395 return e_noPw;
395 } 396 }
396 if (useChipcard) { 397 if (useChipcard) {
397 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 398 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
398 } else { 399 } else {
399 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 400 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
400 } 401 }
401 } 402 }
402 403
403 int _cryptAlgo = conf()->confGlobCryptAlgo(); 404 int _cryptAlgo = conf()->confGlobCryptAlgo();
404 int _hashAlgo = conf()->confGlobHashAlgo(); 405 int _hashAlgo = conf()->confGlobHashAlgo();
405 406
406 // sanity check for the selected algorithms 407 // sanity check for the selected algorithms
407 if (_cryptAlgo < PWM_CRYPT_BLOWFISH || 408 if (_cryptAlgo < PWM_CRYPT_BLOWFISH ||
408 _cryptAlgo > PWM_CRYPT_TWOFISH128) { 409 _cryptAlgo > PWM_CRYPT_TWOFISH128) {
409 printWarn("Invalid Crypto-Algorithm selected! " 410 printWarn("Invalid Crypto-Algorithm selected! "
410 "Config-file seems to be corrupt. " 411 "Config-file seems to be corrupt. "
411 "Falling back to Blowfish."); 412 "Falling back to Blowfish.");
412 _cryptAlgo = PWM_CRYPT_BLOWFISH; 413 _cryptAlgo = PWM_CRYPT_BLOWFISH;
413 } 414 }
414 if (_hashAlgo < PWM_HASH_SHA1 || 415 if (_hashAlgo < PWM_HASH_SHA1 ||
415 _hashAlgo > PWM_HASH_TIGER) { 416 _hashAlgo > PWM_HASH_TIGER) {
416 printWarn("Invalid Hash-Algorithm selected! " 417 printWarn("Invalid Hash-Algorithm selected! "
417 "Config-file seems to be corrupt. " 418 "Config-file seems to be corrupt. "
418 "Falling back to SHA1."); 419 "Falling back to SHA1.");
419 _hashAlgo = PWM_HASH_SHA1; 420 _hashAlgo = PWM_HASH_SHA1;
420 } 421 }
421 char cryptAlgo = static_cast<char>(_cryptAlgo); 422 char cryptAlgo = static_cast<char>(_cryptAlgo);
422 char hashAlgo = static_cast<char>(_hashAlgo); 423 char hashAlgo = static_cast<char>(_hashAlgo);
423 424
424 if (conf()->confGlobMakeFileBackup()) { 425 if (conf()->confGlobMakeFileBackup()) {
425 if (!backupFile(filename)) 426 if (!backupFile(filename))
426 return e_fileBackup; 427 return e_fileBackup;
427 } 428 }
428 if (QFile::exists(filename)) { 429 if (QFile::exists(filename)) {
429 /* Move the existing file to some tmp file. 430 /* Move the existing file to some tmp file.
430 * When saving file succeeds, delete tmp file. Otherwise 431 * When saving file succeeds, delete tmp file. Otherwise
431 * move tmp file back. See below. 432 * move tmp file back. See below.
432 */ 433 */
433 Randomizer *rnd = Randomizer::obj(); 434 Randomizer *rnd = Randomizer::obj();
434 char rnd_buf[5]; 435 char rnd_buf[5];
435 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, 436 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF,
436 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); 437 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF);
437 tmpFileMoved = filename + "." + rnd_buf + ".mv"; 438 tmpFileMoved = filename + "." + rnd_buf + ".mv";
438 if (!copyFile(filename, tmpFileMoved)) 439 if (!copyFile(filename, tmpFileMoved))
439 return e_openFile; 440 return e_openFile;
440 if (!QFile::remove(filename)) { 441 if (!QFile::remove(filename)) {
441 printWarn(string("removing orig file ") 442 printWarn(string("removing orig file ")
442 + filename.latin1() 443 + filename.latin1()
443 + " failed!"); 444 + " failed!");
444 } 445 }
445 } 446 }
446 f.setName(filename); 447 f.setName(filename);
447 if (!f.open(IO_ReadWrite)) { 448 if (!f.open(IO_ReadWrite)) {
448 ret = e_openFile; 449 ret = e_openFile;
449 goto out_moveback; 450 goto out_moveback;
450 } 451 }
451 e = writeFileHeader(hashAlgo, hashAlgo, 452 e = writeFileHeader(hashAlgo, hashAlgo,
452 cryptAlgo, compress, 453 cryptAlgo, compress,
453 &currentPw, &f); 454 &currentPw, &f);
454 if (e == e_hashNotImpl) { 455 if (e == e_hashNotImpl) {
455 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); 456 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl");
456 f.close(); 457 f.close();
457 ret = e_hashNotImpl; 458 ret = e_hashNotImpl;
458 goto out_moveback; 459 goto out_moveback;
459 } else if (e != e_success) { 460 } else if (e != e_success) {
460 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); 461 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed");
461 f.close(); 462 f.close();
462 ret = e_writeHeader; 463 ret = e_writeHeader;
463 goto out_moveback; 464 goto out_moveback;
464 } 465 }
465 if (!serializeDta(&serialized)) { 466 if (!serializeDta(&serialized)) {
466 printDebug("PwMDoc::saveDoc(): serializeDta() failed"); 467 printDebug("PwMDoc::saveDoc(): serializeDta() failed");
467 f.close(); 468 f.close();
468 ret = e_serializeDta; 469 ret = e_serializeDta;
469 goto out_moveback; 470 goto out_moveback;
470 } 471 }
471 e = writeDataHash(hashAlgo, &serialized, &f); 472 e = writeDataHash(hashAlgo, &serialized, &f);
472 if (e == e_hashNotImpl) { 473 if (e == e_hashNotImpl) {
473 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); 474 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl");
474 f.close(); 475 f.close();
475 ret = e_hashNotImpl; 476 ret = e_hashNotImpl;
476 goto out_moveback; 477 goto out_moveback;
477 } else if (e != e_success) { 478 } else if (e != e_success) {
478 printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); 479 printDebug("PwMDoc::saveDoc(): writeDataHash() failed");
479 f.close(); 480 f.close();
480 ret = e_writeHeader; 481 ret = e_writeHeader;
481 goto out_moveback; 482 goto out_moveback;
482 } 483 }
483 if (!compressDta(&serialized, compress)) { 484 if (!compressDta(&serialized, compress)) {
484 printDebug("PwMDoc::saveDoc(): compressDta() failed"); 485 printDebug("PwMDoc::saveDoc(): compressDta() failed");
485 f.close(); 486 f.close();
486 ret = e_enc; 487 ret = e_enc;
487 goto out_moveback; 488 goto out_moveback;
488 } 489 }
489 e = encrypt(&serialized, &currentPw, &f, cryptAlgo); 490 e = encrypt(&serialized, &currentPw, &f, cryptAlgo);
490 if (e == e_weakPw) { 491 if (e == e_weakPw) {
491 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); 492 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw");
492 f.close(); 493 f.close();
493 ret = e_weakPw; 494 ret = e_weakPw;
494 goto out_moveback; 495 goto out_moveback;
495 } else if (e == e_cryptNotImpl) { 496 } else if (e == e_cryptNotImpl) {
496 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); 497 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl");
497 f.close(); 498 f.close();
498 ret = e_cryptNotImpl; 499 ret = e_cryptNotImpl;
499 goto out_moveback; 500 goto out_moveback;
500 } else if (e != e_success) { 501 } else if (e != e_success) {
501 printDebug("PwMDoc::saveDoc(): encrypt() failed"); 502 printDebug("PwMDoc::saveDoc(): encrypt() failed");
502 f.close(); 503 f.close();
503 ret = e_enc; 504 ret = e_enc;
504 goto out_moveback; 505 goto out_moveback;
505 } 506 }
506 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 507 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
507 f.close(); 508 f.close();
509#ifndef _WIN32_
508 if (chmod(filename.latin1(), 510 if (chmod(filename.latin1(),
509 conf()->confGlobFilePermissions())) { 511 conf()->confGlobFilePermissions())) {
510 printWarn(string("chmod failed: ") + strerror(errno)); 512 printWarn(string("chmod failed: ") + strerror(errno));
511 } 513 }
514#endif
512 openDocList.edit(this, getTitle().latin1()); 515 openDocList.edit(this, getTitle().latin1());
513 if (wasDeepLocked) { 516 if (wasDeepLocked) {
514 /* Do _not_ save the data with the deepLock() 517 /* Do _not_ save the data with the deepLock()
515 * call, because this will recurse 518 * call, because this will recurse
516 * into saveDoc() 519 * into saveDoc()
517 */ 520 */
518 deepLock(true, false); 521 deepLock(true, false);
519 /* We don't check return value here, because 522 /* We don't check return value here, because
520 * it won't fail. See NOTE in deepLock() 523 * it won't fail. See NOTE in deepLock()
521 */ 524 */
522 } 525 }
523 if (tmpFileMoved != QString::null) { 526 if (tmpFileMoved != QString::null) {
524 // now remove the moved file. 527 // now remove the moved file.
525 if (!QFile::remove(tmpFileMoved)) { 528 if (!QFile::remove(tmpFileMoved)) {
526 printWarn(string("removing file ") 529 printWarn(string("removing file ")
527 + tmpFileMoved.latin1() 530 + tmpFileMoved.latin1()
528 + " failed!"); 531 + " failed!");
529 } 532 }
530 } 533 }
531 ret = e_success; 534 ret = e_success;
532 printDebug(string("writing file { name: ") 535 printDebug(string("writing file { name: ")
533 + filename.latin1() + " compress: " 536 + filename.latin1() + " compress: "
534 + tostr(static_cast<int>(compress)) + " cryptAlgo: " 537 + tostr(static_cast<int>(compress)) + " cryptAlgo: "
535 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " 538 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: "
536 + tostr(static_cast<int>(hashAlgo)) 539 + tostr(static_cast<int>(hashAlgo))
537 + " }"); 540 + " }");
538 goto out; 541 goto out;
539out_moveback: 542out_moveback:
540 if (tmpFileMoved != QString::null) { 543 if (tmpFileMoved != QString::null) {
541 if (copyFile(tmpFileMoved, filename)) { 544 if (copyFile(tmpFileMoved, filename)) {
542 if (!QFile::remove(tmpFileMoved)) { 545 if (!QFile::remove(tmpFileMoved)) {
543 printWarn(string("removing tmp file ") 546 printWarn(string("removing tmp file ")
544 + filename.latin1() 547 + filename.latin1()
545 + " failed!"); 548 + " failed!");
546 } 549 }
547 } else { 550 } else {
548 printWarn(string("couldn't copy file ") 551 printWarn(string("couldn't copy file ")
549 + tmpFileMoved.latin1() 552 + tmpFileMoved.latin1()
550 + " back to " 553 + " back to "
551 + filename.latin1()); 554 + filename.latin1());
552 } 555 }
553 } 556 }
554out: 557out:
555 return ret; 558 return ret;
556} 559}
557 560
558PwMerror PwMDoc::openDoc(const QString *file, int openLocked) 561PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
559{ 562{
560 PWM_ASSERT(file); 563 PWM_ASSERT(file);
561 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); 564 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2);
562 string decrypted, dataHash; 565 string decrypted, dataHash;
563 PwMerror ret; 566 PwMerror ret;
564 char cryptAlgo, dataHashType, compress; 567 char cryptAlgo, dataHashType, compress;
565 unsigned int headerLen; 568 unsigned int headerLen;
566 569
567 if (*file == "") 570 if (*file == "")
568 return e_readFile; 571 return e_readFile;
569 filename = *file; 572 filename = *file;
570 /* check if this file is already open. 573 /* check if this file is already open.
571 * This does not catch symlinks! 574 * This does not catch symlinks!
572 */ 575 */
573 if (!isDeepLocked()) { 576 if (!isDeepLocked()) {
574 if (getOpenDocList()->find(filename.latin1())) 577 if (getOpenDocList()->find(filename.latin1()))
575 return e_alreadyOpen; 578 return e_alreadyOpen;
576 } 579 }
577 QFile f(filename); 580 QFile f(filename);
578 581
579 if (openLocked == 2) { 582 if (openLocked == 2) {
580 // open deep-locked 583 // open deep-locked
581 if (!QFile::exists(filename)) 584 if (!QFile::exists(filename))
582 return e_openFile; 585 return e_openFile;
583 if (deepLock(true, false) != e_success) 586 if (deepLock(true, false) != e_success)
584 return e_openFile; 587 return e_openFile;
585 goto out_success; 588 goto out_success;
586 } 589 }
587 590
588 if (!f.open(IO_ReadOnly)) 591 if (!f.open(IO_ReadOnly))
589 return e_openFile; 592 return e_openFile;
590 593
591 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen, 594 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen,
592 &dataHashType, &dataHash, &f); 595 &dataHashType, &dataHash, &f);
593 if (ret != e_success) { 596 if (ret != e_success) {
594 printDebug("PwMDoc::openDoc(): checkHeader() failed"); 597 printDebug("PwMDoc::openDoc(): checkHeader() failed");
595 f.close(); 598 f.close();
596 if (ret == e_wrongPw) { 599 if (ret == e_wrongPw) {
597 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 600 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
598 return ret; 601 return ret;
599 } else if (ret == e_noPw || 602 } else if (ret == e_noPw ||
600 ret == e_fileVer || 603 ret == e_fileVer ||
601 ret == e_fileFormat || 604 ret == e_fileFormat ||
602 ret == e_hashNotImpl) { 605 ret == e_hashNotImpl) {
603 return ret; 606 return ret;
604 } else 607 } else
605 return e_readFile; 608 return e_readFile;
606 } 609 }
607 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f); 610 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f);
608 if (ret == e_cryptNotImpl) { 611 if (ret == e_cryptNotImpl) {
609 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); 612 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl");
610 f.close(); 613 f.close();
611 return e_cryptNotImpl; 614 return e_cryptNotImpl;
612 } else if (ret != e_success) { 615 } else if (ret != e_success) {
613 printDebug("PwMDoc::openDoc(): decrypt() failed"); 616 printDebug("PwMDoc::openDoc(): decrypt() failed");
614 f.close(); 617 f.close();
615 return e_readFile; 618 return e_readFile;
616 } 619 }
617 if (!decompressDta(&decrypted, compress)) { 620 if (!decompressDta(&decrypted, compress)) {
618 printDebug("PwMDoc::openDoc(): decompressDta() failed"); 621 printDebug("PwMDoc::openDoc(): decompressDta() failed");
619 f.close(); 622 f.close();
620 return e_fileCorrupt; 623 return e_fileCorrupt;
621 } 624 }
622 ret = checkDataHash(dataHashType, &dataHash, &decrypted); 625 ret = checkDataHash(dataHashType, &dataHash, &decrypted);
623 if (ret == e_hashNotImpl) { 626 if (ret == e_hashNotImpl) {
624 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); 627 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl");
625 f.close(); 628 f.close();
626 return e_hashNotImpl; 629 return e_hashNotImpl;
627 } else if (ret != e_success) { 630 } else if (ret != e_success) {
628 printDebug("PwMDoc::openDoc(): checkDataHash() failed"); 631 printDebug("PwMDoc::openDoc(): checkDataHash() failed");
629 f.close(); 632 f.close();
630 return e_fileCorrupt; 633 return e_fileCorrupt;
631 } 634 }
632 if (!deSerializeDta(&decrypted, openLocked == 1)) { 635 if (!deSerializeDta(&decrypted, openLocked == 1)) {
633 printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); 636 printDebug("PwMDoc::openDoc(): deSerializeDta() failed");
634 f.close(); 637 f.close();
635 return e_readFile; 638 return e_readFile;
636 } 639 }
637 f.close(); 640 f.close();
638 timer()->start(DocTimer::id_mpwTimer); 641 timer()->start(DocTimer::id_mpwTimer);
639 timer()->start(DocTimer::id_autoLockTimer); 642 timer()->start(DocTimer::id_autoLockTimer);
640out_success: 643out_success:
641 openDocList.edit(this, getTitle().latin1()); 644 openDocList.edit(this, getTitle().latin1());
642 emit docOpened(this); 645 emit docOpened(this);
643 return e_success; 646 return e_success;
644} 647}
645 648
646PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 649PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
647 QString *pw, QFile *f) 650 QString *pw, QFile *f)
648{ 651{
649 PWM_ASSERT(pw); 652 PWM_ASSERT(pw);
650 PWM_ASSERT(f); 653 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 654 //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 655 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion
653 //USPWM_ASSERT(listView); 656 //USPWM_ASSERT(listView);
654 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != 657 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
655 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { 658 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
656 return e_writeFile; 659 return e_writeFile;
657 } 660 }
658 if (f->putch(PWM_FILE_VER) == -1 || 661 if (f->putch(PWM_FILE_VER) == -1 ||
659 f->putch(keyHash) == -1 || 662 f->putch(keyHash) == -1 ||
660 f->putch(dataHash) == -1 || 663 f->putch(dataHash) == -1 ||
661 f->putch(crypt) == -1 || 664 f->putch(crypt) == -1 ||
662 f->putch(compress) == -1 || 665 f->putch(compress) == -1 ||
663 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? 666 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
664 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { 667 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) {
665 return e_writeFile; 668 return e_writeFile;
666 } 669 }
667 670
668 // write bytes of NUL-data. These bytes are reserved for future-use. 671 // write bytes of NUL-data. These bytes are reserved for future-use.
669 const int bufSize = 64; 672 const int bufSize = 64;
670 char tmp_buf[bufSize]; 673 char tmp_buf[bufSize];
671 memset(tmp_buf, 0x00, bufSize); 674 memset(tmp_buf, 0x00, bufSize);
672 if (f->writeBlock(tmp_buf, bufSize) != bufSize) 675 if (f->writeBlock(tmp_buf, bufSize) != bufSize)
673 return e_writeFile; 676 return e_writeFile;
674 677
675 switch (keyHash) { 678 switch (keyHash) {
676 case PWM_HASH_SHA1: { 679 case PWM_HASH_SHA1: {
677 const int hashlen = SHA1_HASH_LEN_BYTE; 680 const int hashlen = SHA1_HASH_LEN_BYTE;
678 Sha1 hash; 681 Sha1 hash;
679 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 682 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
680 string ret = hash.sha1_read(); 683 string ret = hash.sha1_read();
681 if (f->writeBlock(ret.c_str(), hashlen) != hashlen) 684 if (f->writeBlock(ret.c_str(), hashlen) != hashlen)
682 return e_writeFile; 685 return e_writeFile;
683 break; 686 break;
684 } 687 }
685 case PWM_HASH_SHA256: 688 case PWM_HASH_SHA256:
686 /*... fall through */ 689 /*... fall through */
687 case PWM_HASH_SHA384: 690 case PWM_HASH_SHA384:
688 case PWM_HASH_SHA512: 691 case PWM_HASH_SHA512:
689 case PWM_HASH_MD5: 692 case PWM_HASH_MD5:
690 case PWM_HASH_RMD160: 693 case PWM_HASH_RMD160:
691 case PWM_HASH_TIGER: 694 case PWM_HASH_TIGER:
692 { 695 {
693 if (!LibGCryptIf::available()) 696 if (!LibGCryptIf::available())
694 return e_hashNotImpl; 697 return e_hashNotImpl;
695 LibGCryptIf gc; 698 LibGCryptIf gc;
696 PwMerror err; 699 PwMerror err;
697 unsigned char *buf; 700 unsigned char *buf;
698 size_t hashLen; 701 size_t hashLen;
699 err = gc.hash(&buf, 702 err = gc.hash(&buf,
700 &hashLen, 703 &hashLen,
701 reinterpret_cast<const unsigned char *>(pw->latin1()), 704 reinterpret_cast<const unsigned char *>(pw->latin1()),
702 pw->length(), 705 pw->length(),
703 keyHash); 706 keyHash);
704 if (err != e_success) 707 if (err != e_success)
705 return e_hashNotImpl; 708 return e_hashNotImpl;
706 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 709 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
707 != static_cast<Q_LONG>(hashLen)) { 710 != static_cast<Q_LONG>(hashLen)) {
708 delete [] buf; 711 delete [] buf;
709 return e_hashNotImpl; 712 return e_hashNotImpl;
710 } 713 }
711 delete [] buf; 714 delete [] buf;
712 break; 715 break;
713 } 716 }
714 default: { 717 default: {
715 return e_hashNotImpl; 718 return e_hashNotImpl;
716 } } 719 } }
717 return e_success; 720 return e_success;
718} 721}
719 722
720PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, 723PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
721 unsigned int *headerLength, char *dataHashType, 724 unsigned int *headerLength, char *dataHashType,
722 string *dataHash, QFile *f) 725 string *dataHash, QFile *f)
723{ 726{
724 PWM_ASSERT(cryptAlgo); 727 PWM_ASSERT(cryptAlgo);
725 PWM_ASSERT(pw); 728 PWM_ASSERT(pw);
726 PWM_ASSERT(headerLength); 729 PWM_ASSERT(headerLength);
727 PWM_ASSERT(dataHashType); 730 PWM_ASSERT(dataHashType);
728 PWM_ASSERT(dataHash); 731 PWM_ASSERT(dataHash);
729 PWM_ASSERT(f); 732 PWM_ASSERT(f);
730 int tmpRet; 733 int tmpRet;
731 // check "magic" header 734 // check "magic" header
732 const char magicHdr[] = FILE_ID_HEADER; 735 const char magicHdr[] = FILE_ID_HEADER;
733 const int hdrLen = array_size(magicHdr) - 1; 736 const int hdrLen = array_size(magicHdr) - 1;
734 char tmp[hdrLen]; 737 char tmp[hdrLen];
735 if (f->readBlock(tmp, hdrLen) != hdrLen) 738 if (f->readBlock(tmp, hdrLen) != hdrLen)
736 return e_readFile; 739 return e_readFile;
737 if (memcmp(tmp, magicHdr, hdrLen) != 0) 740 if (memcmp(tmp, magicHdr, hdrLen) != 0)
738 return e_fileFormat; 741 return e_fileFormat;
739 // read and check file ver 742 // read and check file ver
740 int fileV = f->getch(); 743 int fileV = f->getch();
741 if (fileV == -1) 744 if (fileV == -1)
742 return e_fileFormat; 745 return e_fileFormat;
743 if (fileV != PWM_FILE_VER) 746 if (fileV != PWM_FILE_VER)
744 return e_fileVer; 747 return e_fileVer;
745 // read hash hash type 748 // read hash hash type
746 int keyHash = f->getch(); 749 int keyHash = f->getch();
747 if (keyHash == -1) 750 if (keyHash == -1)
748 return e_fileFormat; 751 return e_fileFormat;
749 // read data hash type 752 // read data hash type
750 tmpRet = f->getch(); 753 tmpRet = f->getch();
751 if (tmpRet == -1) 754 if (tmpRet == -1)
752 return e_fileFormat; 755 return e_fileFormat;
753 *dataHashType = tmpRet; 756 *dataHashType = tmpRet;
754 // read crypt algo 757 // read crypt algo
755 tmpRet = f->getch(); 758 tmpRet = f->getch();
756 if (tmpRet == -1) 759 if (tmpRet == -1)
757 return e_fileFormat; 760 return e_fileFormat;
758 *cryptAlgo = tmpRet; 761 *cryptAlgo = tmpRet;
759 // get compression-algo 762 // get compression-algo
760 tmpRet = f->getch(); 763 tmpRet = f->getch();
761 if (tmpRet == -1) 764 if (tmpRet == -1)
762 return e_fileFormat; 765 return e_fileFormat;
763 *compress = tmpRet; 766 *compress = tmpRet;
764 // get the MPW-flag 767 // get the MPW-flag
765 int mpw_flag = f->getch(); 768 int mpw_flag = f->getch();
766 if (mpw_flag == -1) 769 if (mpw_flag == -1)
767 return e_fileFormat; 770 return e_fileFormat;
768 if (mpw_flag == 0x01) 771 if (mpw_flag == 0x01)
769 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 772 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
770 else 773 else
771 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 774 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
772 // skip the "RESERVED"-bytes 775 // skip the "RESERVED"-bytes
773 if (!(f->at(f->at() + 64))) 776 if (!(f->at(f->at() + 64)))
774 return e_fileFormat; 777 return e_fileFormat;
775 778
776 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 779 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
777 if (*pw == "") { 780 if (*pw == "") {
778 /* the user didn't give a master-password 781 /* the user didn't give a master-password
779 * or didn't insert a chipcard 782 * or didn't insert a chipcard
780 */ 783 */
781 return e_noPw; 784 return e_noPw;
782 } 785 }
783 // verify key-hash 786 // verify key-hash
784 switch (keyHash) { 787 switch (keyHash) {
785 case PWM_HASH_SHA1: { 788 case PWM_HASH_SHA1: {
786 // read hash from header 789 // read hash from header
787 const int hashLen = SHA1_HASH_LEN_BYTE; 790 const int hashLen = SHA1_HASH_LEN_BYTE;
788 string readHash; 791 string readHash;
789 int i; 792 int i;
790 for (i = 0; i < hashLen; ++i) 793 for (i = 0; i < hashLen; ++i)
791 readHash.push_back(f->getch()); 794 readHash.push_back(f->getch());
792 Sha1 hash; 795 Sha1 hash;
793 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 796 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
794 string ret = hash.sha1_read(); 797 string ret = hash.sha1_read();
795 if (ret != readHash) 798 if (ret != readHash)
796 return e_wrongPw;// hash doesn't match (wrong key) 799 return e_wrongPw;// hash doesn't match (wrong key)
797 break; 800 break;
798 } 801 }
799 case PWM_HASH_SHA256: 802 case PWM_HASH_SHA256:
800 /*... fall through */ 803 /*... fall through */
801 case PWM_HASH_SHA384: 804 case PWM_HASH_SHA384:
802 case PWM_HASH_SHA512: 805 case PWM_HASH_SHA512:
803 case PWM_HASH_MD5: 806 case PWM_HASH_MD5:
804 case PWM_HASH_RMD160: 807 case PWM_HASH_RMD160:
805 case PWM_HASH_TIGER: { 808 case PWM_HASH_TIGER: {
806 if (!LibGCryptIf::available()) 809 if (!LibGCryptIf::available())
807 return e_hashNotImpl; 810 return e_hashNotImpl;
808 LibGCryptIf gc; 811 LibGCryptIf gc;
809 PwMerror err; 812 PwMerror err;
810 unsigned char *buf; 813 unsigned char *buf;
811 size_t hashLen; 814 size_t hashLen;
812 err = gc.hash(&buf, 815 err = gc.hash(&buf,
813 &hashLen, 816 &hashLen,
814 reinterpret_cast<const unsigned char *>(pw->latin1()), 817 reinterpret_cast<const unsigned char *>(pw->latin1()),
815 pw->length(), 818 pw->length(),
816 keyHash); 819 keyHash);
817 if (err != e_success) 820 if (err != e_success)
818 return e_hashNotImpl; 821 return e_hashNotImpl;
819 string calcHash(reinterpret_cast<const char *>(buf), 822 string calcHash(reinterpret_cast<const char *>(buf),
820 static_cast<string::size_type>(hashLen)); 823 static_cast<string::size_type>(hashLen));
821 delete [] buf; 824 delete [] buf;
822 // read hash from header 825 // read hash from header
823 string readHash; 826 string readHash;
824 size_t i; 827 size_t i;
825 for (i = 0; i < hashLen; ++i) 828 for (i = 0; i < hashLen; ++i)
826 readHash.push_back(f->getch()); 829 readHash.push_back(f->getch());
827 if (calcHash != readHash) 830 if (calcHash != readHash)
828 return e_wrongPw;// hash doesn't match (wrong key) 831 return e_wrongPw;// hash doesn't match (wrong key)
829 break; 832 break;
830 } 833 }
831 default: { 834 default: {
832 return e_hashNotImpl; 835 return e_hashNotImpl;
833 } } 836 } }
834 // read the data-hash from the file 837 // read the data-hash from the file
835 unsigned int hashLen, i; 838 unsigned int hashLen, i;
836 switch (*dataHashType) { 839 switch (*dataHashType) {
837 case PWM_HASH_SHA1: 840 case PWM_HASH_SHA1:
838 hashLen = SHA1_HASH_LEN_BYTE; 841 hashLen = SHA1_HASH_LEN_BYTE;
839 break; 842 break;
840 case PWM_HASH_SHA256: 843 case PWM_HASH_SHA256:
841 /*... fall through */ 844 /*... fall through */
842 case PWM_HASH_SHA384: 845 case PWM_HASH_SHA384:
843 case PWM_HASH_SHA512: 846 case PWM_HASH_SHA512:
844 case PWM_HASH_MD5: 847 case PWM_HASH_MD5:
845 case PWM_HASH_RMD160: 848 case PWM_HASH_RMD160:
846 case PWM_HASH_TIGER: { 849 case PWM_HASH_TIGER: {
847 if (!LibGCryptIf::available()) 850 if (!LibGCryptIf::available())
848 return e_hashNotImpl; 851 return e_hashNotImpl;
849 LibGCryptIf gc; 852 LibGCryptIf gc;
850 hashLen = gc.hashLength(*dataHashType); 853 hashLen = gc.hashLength(*dataHashType);
851 if (hashLen == 0) 854 if (hashLen == 0)
852 return e_hashNotImpl; 855 return e_hashNotImpl;
853 break; 856 break;
854 } 857 }
855 default: 858 default:
856 return e_hashNotImpl; 859 return e_hashNotImpl;
857 } 860 }
858 *dataHash = ""; 861 *dataHash = "";
859 for (i = 0; i < hashLen; ++i) { 862 for (i = 0; i < hashLen; ++i) {
860 tmpRet = f->getch(); 863 tmpRet = f->getch();
861 if (tmpRet == -1) 864 if (tmpRet == -1)
862 return e_fileFormat; 865 return e_fileFormat;
863 dataHash->push_back(static_cast<char>(tmpRet)); 866 dataHash->push_back(static_cast<char>(tmpRet));
864 } 867 }
865 *headerLength = f->at(); 868 *headerLength = f->at();
866#ifndef PWM_EMBEDDED 869#ifndef PWM_EMBEDDED
867 printDebug(string("opening file { compress: ") 870 printDebug(string("opening file { compress: ")
868 + tostr(static_cast<int>(*compress)) + " cryptAlgo: " 871 + tostr(static_cast<int>(*compress)) + " cryptAlgo: "
869 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " 872 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: "
870 + tostr(static_cast<int>(keyHash)) 873 + tostr(static_cast<int>(keyHash))
871 + " }"); 874 + " }");
872#else 875#else
873 printDebug(string("opening file { compress: ") 876 printDebug(string("opening file { compress: ")
874 + tostr((int)(*compress)) + " cryptAlgo: " 877 + tostr((int)(*compress)) + " cryptAlgo: "
875 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " 878 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: "
876 + tostr((int)(keyHash)) 879 + tostr((int)(keyHash))
877 + " }"); 880 + " }");
878#endif 881#endif
879 882
880 return e_success; 883 return e_success;
881} 884}
882 885
883PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) 886PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
884{ 887{
885 PWM_ASSERT(d); 888 PWM_ASSERT(d);
886 PWM_ASSERT(f); 889 PWM_ASSERT(f);
887 890
888 switch (dataHash) { 891 switch (dataHash) {
889 case PWM_HASH_SHA1: { 892 case PWM_HASH_SHA1: {
890 const int hashLen = SHA1_HASH_LEN_BYTE; 893 const int hashLen = SHA1_HASH_LEN_BYTE;
891 Sha1 h; 894 Sha1 h;
892 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); 895 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size());
893 string hRet = h.sha1_read(); 896 string hRet = h.sha1_read();
894 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) 897 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen)
895 return e_writeFile; 898 return e_writeFile;
896 break; 899 break;
897 } 900 }
898 case PWM_HASH_SHA256: 901 case PWM_HASH_SHA256:
899 /*... fall through */ 902 /*... fall through */
900 case PWM_HASH_SHA384: 903 case PWM_HASH_SHA384:
901 case PWM_HASH_SHA512: 904 case PWM_HASH_SHA512:
902 case PWM_HASH_MD5: 905 case PWM_HASH_MD5:
903 case PWM_HASH_RMD160: 906 case PWM_HASH_RMD160:
904 case PWM_HASH_TIGER: { 907 case PWM_HASH_TIGER: {
905 if (!LibGCryptIf::available()) 908 if (!LibGCryptIf::available())
906 return e_hashNotImpl; 909 return e_hashNotImpl;
907 LibGCryptIf gc; 910 LibGCryptIf gc;
908 PwMerror err; 911 PwMerror err;
909 unsigned char *buf; 912 unsigned char *buf;
910 size_t hashLen; 913 size_t hashLen;
911 err = gc.hash(&buf, 914 err = gc.hash(&buf,
912 &hashLen, 915 &hashLen,
913 reinterpret_cast<const unsigned char *>(d->c_str()), 916 reinterpret_cast<const unsigned char *>(d->c_str()),
914 d->size(), 917 d->size(),
915 dataHash); 918 dataHash);
916 if (err != e_success) 919 if (err != e_success)
917 return e_hashNotImpl; 920 return e_hashNotImpl;
918 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 921 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
919 != static_cast<Q_LONG>(hashLen)) { 922 != static_cast<Q_LONG>(hashLen)) {
920 delete [] buf; 923 delete [] buf;
921 return e_hashNotImpl; 924 return e_hashNotImpl;
922 } 925 }
923 delete [] buf; 926 delete [] buf;
924 break; 927 break;
925 } 928 }
926 default: { 929 default: {
927 return e_hashNotImpl; 930 return e_hashNotImpl;
928 } } 931 } }
929 932
930 return e_success; 933 return e_success;
931} 934}
932 935
933bool PwMDoc::backupFile(const QString &filePath) 936bool PwMDoc::backupFile(const QString &filePath)
934{ 937{
935 QFileInfo fi(filePath); 938 QFileInfo fi(filePath);
936 if (!fi.exists()) 939 if (!fi.exists())
937 return true; // Yes, true is correct. 940 return true; // Yes, true is correct.
938 QString pathOnly(fi.dirPath(true)); 941 QString pathOnly(fi.dirPath(true));
939 QString nameOnly(fi.fileName()); 942 QString nameOnly(fi.fileName());
940 QString backupPath = pathOnly 943 QString backupPath = pathOnly
941 + "/~" 944 + "/~"
942 + nameOnly 945 + nameOnly
943 + ".backup"; 946 + ".backup";
944 return copyFile(filePath, backupPath); 947 return copyFile(filePath, backupPath);
945} 948}
946 949
947bool PwMDoc::copyFile(const QString &src, const QString &dst) 950bool PwMDoc::copyFile(const QString &src, const QString &dst)
948{ 951{
949 QFileInfo fi(src); 952 QFileInfo fi(src);
950 if (!fi.exists()) 953 if (!fi.exists())
951 return false; 954 return false;
952 if (QFile::exists(dst)) { 955 if (QFile::exists(dst)) {
953 if (!QFile::remove(dst)) 956 if (!QFile::remove(dst))
954 return false; 957 return false;
955 } 958 }
956 QFile srcFd(src); 959 QFile srcFd(src);
957 if (!srcFd.open(IO_ReadOnly)) 960 if (!srcFd.open(IO_ReadOnly))
958 return false; 961 return false;
959 QFile dstFd(dst); 962 QFile dstFd(dst);
960 if (!dstFd.open(IO_ReadWrite)) { 963 if (!dstFd.open(IO_ReadWrite)) {
961 srcFd.close(); 964 srcFd.close();
962 return false; 965 return false;
963 } 966 }
964 const int tmpBuf_size = 512; 967 const int tmpBuf_size = 512;
965 char tmpBuf[tmpBuf_size]; 968 char tmpBuf[tmpBuf_size];
966 Q_LONG bytesRead, bytesWritten; 969 Q_LONG bytesRead, bytesWritten;
967 970
968 while (!srcFd.atEnd()) { 971 while (!srcFd.atEnd()) {
969 bytesRead = srcFd.readBlock(tmpBuf, 972 bytesRead = srcFd.readBlock(tmpBuf,
970 static_cast<Q_ULONG>(tmpBuf_size)); 973 static_cast<Q_ULONG>(tmpBuf_size));
971 if (bytesRead == -1) { 974 if (bytesRead == -1) {
972 srcFd.close(); 975 srcFd.close();
973 dstFd.close(); 976 dstFd.close();
974 return false; 977 return false;
975 } 978 }
976 bytesWritten = dstFd.writeBlock(tmpBuf, 979 bytesWritten = dstFd.writeBlock(tmpBuf,
977 static_cast<Q_ULONG>(bytesRead)); 980 static_cast<Q_ULONG>(bytesRead));
978 if (bytesWritten != bytesRead) { 981 if (bytesWritten != bytesRead) {
979 srcFd.close(); 982 srcFd.close();
980 dstFd.close(); 983 dstFd.close();
981 return false; 984 return false;
982 } 985 }
983 } 986 }
984 srcFd.close(); 987 srcFd.close();
985 dstFd.close(); 988 dstFd.close();
986 return true; 989 return true;
987} 990}
988 991
989PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, 992PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
990 bool dontFlagDirty, bool updateMeta) 993 bool dontFlagDirty, bool updateMeta)
991{ 994{
992 PWM_ASSERT(d); 995 PWM_ASSERT(d);
993 unsigned int cat = 0; 996 unsigned int cat = 0;
994 997
995 if (isDeepLocked()) { 998 if (isDeepLocked()) {
996 PwMerror ret; 999 PwMerror ret;
997 ret = deepLock(false); 1000 ret = deepLock(false);
998 if (ret != e_success) 1001 if (ret != e_success)
999 return e_lock; 1002 return e_lock;
1000 } 1003 }
1001 1004
1002 addCategory(category, &cat); 1005 addCategory(category, &cat);
1003 1006
1004 if (numEntries(category) >= maxEntries) 1007 if (numEntries(category) >= maxEntries)
1005 return e_maxAllowedEntr; 1008 return e_maxAllowedEntr;
1006 1009
1007 vector<unsigned int> foundPositions; 1010 vector<unsigned int> foundPositions;
1008 /* historically this was: 1011 /* historically this was:
1009 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | 1012 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
1010 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; 1013 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
1011 * But for now we only search in desc. 1014 * But for now we only search in desc.
1012 * That's a tweak to be KWallet compatible. But it should not add 1015 * That's a tweak to be KWallet compatible. But it should not add
1013 * usability-drop onto PwManager, does it? 1016 * usability-drop onto PwManager, does it?
1014 * (And yes, "int" was a bug. Correct is "unsigned int") 1017 * (And yes, "int" was a bug. Correct is "unsigned int")
1015 */ 1018 */
1016 const unsigned int searchIn = SEARCH_IN_DESC; 1019 const unsigned int searchIn = SEARCH_IN_DESC;
1017 findEntry(cat, *d, searchIn, &foundPositions, true); 1020 findEntry(cat, *d, searchIn, &foundPositions, true);
1018 if (foundPositions.size()) { 1021 if (foundPositions.size()) {
1019 // DOH! We found this entry. 1022 // DOH! We found this entry.
1020 return e_entryExists; 1023 return e_entryExists;
1021 } 1024 }
1022 1025
1023 d->listViewPos = -1; 1026 d->listViewPos = -1;
1024 d->lockStat = conf()->confGlobNewEntrLockStat(); 1027 d->lockStat = conf()->confGlobNewEntrLockStat();
1025 if (updateMeta) { 1028 if (updateMeta) {
1026 d->meta.create = QDateTime::currentDateTime(); 1029 d->meta.create = QDateTime::currentDateTime();
1027 d->meta.update = d->meta.create; 1030 d->meta.update = d->meta.create;
1028 } 1031 }
1029 dti.dta[cat].d.push_back(*d); 1032 dti.dta[cat].d.push_back(*d);
1030 1033
1031 delAllEmptyCat(true); 1034 delAllEmptyCat(true);
1032 1035
1033 if (!dontFlagDirty) 1036 if (!dontFlagDirty)
1034 flagDirty(); 1037 flagDirty();
1035 return e_success; 1038 return e_success;
1036} 1039}
1037 1040
1038PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, 1041PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
1039 bool checkIfExist) 1042 bool checkIfExist)
1040{ 1043{
1041 if (isDeepLocked()) { 1044 if (isDeepLocked()) {
1042 PwMerror ret; 1045 PwMerror ret;
1043 ret = deepLock(false); 1046 ret = deepLock(false);
1044 if (ret != e_success) 1047 if (ret != e_success)
1045 return e_lock; 1048 return e_lock;
1046 } 1049 }
1047 if (checkIfExist) { 1050 if (checkIfExist) {
1048 if (findCategory(category, categoryIndex)) 1051 if (findCategory(category, categoryIndex))
1049 return e_categoryExists; 1052 return e_categoryExists;
1050 } 1053 }
1051 PwMCategoryItem item; 1054 PwMCategoryItem item;
1052 item.name = category.latin1(); 1055 item.name = category.latin1();
1053 dti.dta.push_back(item); 1056 dti.dta.push_back(item);
1054 if (categoryIndex) 1057 if (categoryIndex)
1055 *categoryIndex = dti.dta.size() - 1; 1058 *categoryIndex = dti.dta.size() - 1;
1056 return e_success; 1059 return e_success;
1057} 1060}
1058 1061
1059bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) 1062bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1060{ 1063{
1061 unsigned int cat = 0; 1064 unsigned int cat = 0;
1062 1065
1063 if (!findCategory(category, &cat)) { 1066 if (!findCategory(category, &cat)) {
1064 BUG(); 1067 BUG();
1065 return false; 1068 return false;
1066 } 1069 }
1067 1070
1068 return delEntry(cat, index, dontFlagDirty); 1071 return delEntry(cat, index, dontFlagDirty);
1069} 1072}
1070 1073
1071bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) 1074bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1072{ 1075{
1073 if (isDeepLocked()) 1076 if (isDeepLocked())
1074 return false; 1077 return false;
1075 if (index > dti.dta[category].d.size() - 1) 1078 if (index > dti.dta[category].d.size() - 1)
1076 return false; 1079 return false;
1077 getDataChangedLock(); 1080 getDataChangedLock();
1078 if (!lockAt(category, index, false)) { 1081 if (!lockAt(category, index, false)) {
1079 putDataChangedLock(); 1082 putDataChangedLock();
1080 return false; 1083 return false;
1081 } 1084 }
1082 putDataChangedLock(); 1085 putDataChangedLock();
1083 int lvPos = dti.dta[category].d[index].listViewPos; 1086 int lvPos = dti.dta[category].d[index].listViewPos;
1084 1087
1085 // delete entry 1088 // delete entry
1086 dti.dta[category].d.erase(dti.dta[category].d.begin() + index); 1089 dti.dta[category].d.erase(dti.dta[category].d.begin() + index);
1087 1090
1088 unsigned int i, entries = numEntries(category); 1091 unsigned int i, entries = numEntries(category);
1089 if (!entries) { 1092 if (!entries) {
1090 // no more entries in this category, so 1093 // no more entries in this category, so
1091 // we can delete it, too. 1094 // we can delete it, too.
1092 BUG_ON(!delCategory(category)); 1095 BUG_ON(!delCategory(category));
1093 // delCategory() flags it dirty, so we need not to do so. 1096 // delCategory() flags it dirty, so we need not to do so.
1094 return true; 1097 return true;
1095 } 1098 }
1096 for (i = 0; i < entries; ++i) { 1099 for (i = 0; i < entries; ++i) {
1097 // decrement all listViewPositions that are greater than the deleted. 1100 // decrement all listViewPositions that are greater than the deleted.
1098 if (dti.dta[category].d[i].listViewPos > lvPos) 1101 if (dti.dta[category].d[i].listViewPos > lvPos)
1099 --dti.dta[category].d[i].listViewPos; 1102 --dti.dta[category].d[i].listViewPos;
1100 } 1103 }
1101 1104
1102 if (!dontFlagDirty) 1105 if (!dontFlagDirty)
1103 flagDirty(); 1106 flagDirty();
1104 return true; 1107 return true;
1105} 1108}
1106 1109
1107bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, 1110bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1108 unsigned int index, PwMDataItem *d, bool updateMeta) 1111 unsigned int index, PwMDataItem *d, bool updateMeta)
1109{ 1112{
1110 PWM_ASSERT(d); 1113 PWM_ASSERT(d);
1111 unsigned int oldCat = 0; 1114 unsigned int oldCat = 0;
1112 1115
1113 if (!findCategory(oldCategory, &oldCat)) { 1116 if (!findCategory(oldCategory, &oldCat)) {
1114 BUG(); 1117 BUG();
1115 return false; 1118 return false;
1116 } 1119 }
1117 1120
1118 return editEntry(oldCat, newCategory, index, d, updateMeta); 1121 return editEntry(oldCat, newCategory, index, d, updateMeta);
1119} 1122}
1120 1123
1121bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, 1124bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1122 unsigned int index, PwMDataItem *d, bool updateMeta) 1125 unsigned int index, PwMDataItem *d, bool updateMeta)
1123{ 1126{
1124 if (isDeepLocked()) 1127 if (isDeepLocked())
1125 return false; 1128 return false;
1126 if (updateMeta) { 1129 if (updateMeta) {
1127 d->meta.update = QDateTime::currentDateTime(); 1130 d->meta.update = QDateTime::currentDateTime();
1128 if (d->meta.create.isNull()) { 1131 if (d->meta.create.isNull()) {
1129 d->meta.create = d->meta.update; 1132 d->meta.create = d->meta.update;
1130 } 1133 }
1131 } 1134 }
1132 if (dti.dta[oldCategory].name != newCategory.latin1()) { 1135 if (dti.dta[oldCategory].name != newCategory.latin1()) {
1133 // the user changed the category. 1136 // the user changed the category.
1134 PwMerror ret; 1137 PwMerror ret;
1135 d->rev = 0; 1138 d->rev = 0;
1136 ret = addEntry(newCategory, d, true, false); 1139 ret = addEntry(newCategory, d, true, false);
1137 if (ret != e_success) 1140 if (ret != e_success)
1138 return false; 1141 return false;
1139 if (!delEntry(oldCategory, index, true)) 1142 if (!delEntry(oldCategory, index, true))
1140 return false; 1143 return false;
1141 } else { 1144 } else {
1142 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. 1145 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
1143 dti.dta[oldCategory].d[index] = *d; 1146 dti.dta[oldCategory].d[index] = *d;
1144 } 1147 }
1145 flagDirty(); 1148 flagDirty();
1146 return true; 1149 return true;
1147} 1150}
1148 1151
1149unsigned int PwMDoc::numEntries(const QString &category) 1152unsigned int PwMDoc::numEntries(const QString &category)
1150{ 1153{
1151 unsigned int cat = 0; 1154 unsigned int cat = 0;
1152 1155
1153 if (!findCategory(category, &cat)) { 1156 if (!findCategory(category, &cat)) {
1154 BUG(); 1157 BUG();
1155 return 0; 1158 return 0;
1156 } 1159 }
1157 1160
1158 return numEntries(cat); 1161 return numEntries(cat);
1159} 1162}
1160 1163
1161bool PwMDoc::serializeDta(string *d) 1164bool PwMDoc::serializeDta(string *d)
1162{ 1165{
1163 PWM_ASSERT(d); 1166 PWM_ASSERT(d);
1164 Serializer ser; 1167 Serializer ser;
1165 if (!ser.serialize(dti)) 1168 if (!ser.serialize(dti))
1166 return false; 1169 return false;
1167 d->assign(ser.getXml()); 1170 d->assign(ser.getXml());
1168 if (!d->size()) 1171 if (!d->size())
1169 return false; 1172 return false;
1170 return true; 1173 return true;
1171} 1174}
1172 1175
1173bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1176bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1174{ 1177{
1175 PWM_ASSERT(d); 1178 PWM_ASSERT(d);
1176#ifndef PWM_EMBEDDED 1179#ifndef PWM_EMBEDDED
1177 try { 1180 try {
1178 1181
1179 Serializer ser(d->c_str()); 1182 Serializer ser(d->c_str());
1180 ser.setDefaultLockStat(entriesLocked); 1183 ser.setDefaultLockStat(entriesLocked);
1181 if (!ser.deSerialize(&dti)) 1184 if (!ser.deSerialize(&dti))
1182 return false; 1185 return false;
1183 } catch (PwMException) { 1186 } catch (PwMException) {
1184 return false; 1187 return false;
1185 } 1188 }
1186#else 1189#else
1187 Serializer ser(d->c_str()); 1190 Serializer ser(d->c_str());
1188 ser.setDefaultLockStat(entriesLocked); 1191 ser.setDefaultLockStat(entriesLocked);
1189 if (!ser.deSerialize(&dti)) 1192 if (!ser.deSerialize(&dti))
1190 return false; 1193 return false;
1191#endif 1194#endif
1192 1195
1193 emitDataChanged(this); 1196 emitDataChanged(this);
1194 return true; 1197 return true;
1195} 1198}
1196 1199
1197bool PwMDoc::getEntry(const QString &category, unsigned int index, 1200bool PwMDoc::getEntry(const QString &category, unsigned int index,
1198 PwMDataItem * d, bool unlockIfLocked) 1201 PwMDataItem * d, bool unlockIfLocked)
1199{ 1202{
1200 PWM_ASSERT(d); 1203 PWM_ASSERT(d);
1201 unsigned int cat = 0; 1204 unsigned int cat = 0;
1202 1205
1203 if (!findCategory(category, &cat)) { 1206 if (!findCategory(category, &cat)) {
1204 BUG(); 1207 BUG();
1205 return false; 1208 return false;
1206 } 1209 }
1207 1210
1208 return getEntry(cat, index, d, unlockIfLocked); 1211 return getEntry(cat, index, d, unlockIfLocked);
1209} 1212}
1210 1213
1211bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1214bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1212 PwMDataItem *d, bool unlockIfLocked) 1215 PwMDataItem *d, bool unlockIfLocked)
1213{ 1216{
1214 if (index > dti.dta[category].d.size() - 1) 1217 if (index > dti.dta[category].d.size() - 1)
1215 return false; 1218 return false;
1216 1219
1217 bool locked = isLocked(category, index); 1220 bool locked = isLocked(category, index);
1218 if (locked) { 1221 if (locked) {
1219 /* this entry is locked. We don't return a password, 1222 /* this entry is locked. We don't return a password,
1220 * until it's unlocked by the user by inserting 1223 * until it's unlocked by the user by inserting
1221 * chipcard or entering the mpw 1224 * chipcard or entering the mpw
1222 */ 1225 */
1223 if (unlockIfLocked) { 1226 if (unlockIfLocked) {
1224 if (!lockAt(category, index, false)) { 1227 if (!lockAt(category, index, false)) {
1225 return false; 1228 return false;
1226 } 1229 }
1227 locked = false; 1230 locked = false;
1228 } 1231 }
1229 } 1232 }
1230 1233
1231 *d = dti.dta[category].d[index]; 1234 *d = dti.dta[category].d[index];
1232 if (locked) 1235 if (locked)
1233 d->pw = LOCKED_STRING.latin1(); 1236 d->pw = LOCKED_STRING.latin1();
1234 1237
1235 return true; 1238 return true;
1236} 1239}
1237 1240
1238PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1241PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1239 string *foundComment) 1242 string *foundComment)
1240{ 1243{
1241 PWM_ASSERT(foundComment); 1244 PWM_ASSERT(foundComment);
1242 unsigned int cat = 0; 1245 unsigned int cat = 0;
1243 1246
1244 if (!findCategory(category, &cat)) 1247 if (!findCategory(category, &cat))
1245 return e_invalidArg; 1248 return e_invalidArg;
1246 1249
1247 unsigned int i, entries = numEntries(cat); 1250 unsigned int i, entries = numEntries(cat);
1248 for (i = 0; i < entries; ++i) { 1251 for (i = 0; i < entries; ++i) {
1249 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1252 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1250 *foundComment = dti.dta[cat].d[i].comment; 1253 *foundComment = dti.dta[cat].d[i].comment;
1251 if (dti.dta[cat].d[i].binary) 1254 if (dti.dta[cat].d[i].binary)
1252 return e_binEntry; 1255 return e_binEntry;
1253 return e_normalEntry; 1256 return e_normalEntry;
1254 } 1257 }
1255 } 1258 }
1256 BUG(); 1259 BUG();
1257 return e_generic; 1260 return e_generic;
1258} 1261}
1259 1262
1260bool PwMDoc::compressDta(string *d, char algo) 1263bool PwMDoc::compressDta(string *d, char algo)
1261{ 1264{
1262 PWM_ASSERT(d); 1265 PWM_ASSERT(d);
1263 switch (algo) { 1266 switch (algo) {
1264 case PWM_COMPRESS_GZIP: { 1267 case PWM_COMPRESS_GZIP: {
1265 CompressGzip comp; 1268 CompressGzip comp;
1266 return comp.compress(d); 1269 return comp.compress(d);
1267 } 1270 }
1268#ifndef PWM_EMBEDDED 1271#ifndef PWM_EMBEDDED
1269 case PWM_COMPRESS_BZIP2: { 1272 case PWM_COMPRESS_BZIP2: {
1270 CompressBzip2 comp; 1273 CompressBzip2 comp;
1271 return comp.compress(d); 1274 return comp.compress(d);
1272 } 1275 }
1273#endif 1276#endif
1274 case PWM_COMPRESS_NONE: { 1277 case PWM_COMPRESS_NONE: {
1275 return true; 1278 return true;
1276 } default: { 1279 } default: {
1277 BUG(); 1280 BUG();
1278 } 1281 }
1279 } 1282 }
@@ -1453,1592 +1456,1596 @@ PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1453{ 1456{
1454 PWM_ASSERT(dataHash); 1457 PWM_ASSERT(dataHash);
1455 PWM_ASSERT(dataStream); 1458 PWM_ASSERT(dataStream);
1456 switch(dataHashType) { 1459 switch(dataHashType) {
1457 case PWM_HASH_SHA1: { 1460 case PWM_HASH_SHA1: {
1458 Sha1 hash; 1461 Sha1 hash;
1459 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); 1462 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length());
1460 string ret = hash.sha1_read(); 1463 string ret = hash.sha1_read();
1461 if (ret != *dataHash) 1464 if (ret != *dataHash)
1462 return e_fileCorrupt; 1465 return e_fileCorrupt;
1463 break; 1466 break;
1464 } 1467 }
1465 case PWM_HASH_SHA256: 1468 case PWM_HASH_SHA256:
1466 /*... fall through */ 1469 /*... fall through */
1467 case PWM_HASH_SHA384: 1470 case PWM_HASH_SHA384:
1468 case PWM_HASH_SHA512: 1471 case PWM_HASH_SHA512:
1469 case PWM_HASH_MD5: 1472 case PWM_HASH_MD5:
1470 case PWM_HASH_RMD160: 1473 case PWM_HASH_RMD160:
1471 case PWM_HASH_TIGER: { 1474 case PWM_HASH_TIGER: {
1472 if (!LibGCryptIf::available()) 1475 if (!LibGCryptIf::available())
1473 return e_hashNotImpl; 1476 return e_hashNotImpl;
1474 LibGCryptIf gc; 1477 LibGCryptIf gc;
1475 PwMerror err; 1478 PwMerror err;
1476 unsigned char *buf; 1479 unsigned char *buf;
1477 size_t hashLen; 1480 size_t hashLen;
1478 err = gc.hash(&buf, 1481 err = gc.hash(&buf,
1479 &hashLen, 1482 &hashLen,
1480 reinterpret_cast<const unsigned char *>(dataStream->c_str()), 1483 reinterpret_cast<const unsigned char *>(dataStream->c_str()),
1481 dataStream->length(), 1484 dataStream->length(),
1482 dataHashType); 1485 dataHashType);
1483 if (err != e_success) 1486 if (err != e_success)
1484 return e_hashNotImpl; 1487 return e_hashNotImpl;
1485 string calcHash(reinterpret_cast<const char *>(buf), 1488 string calcHash(reinterpret_cast<const char *>(buf),
1486 static_cast<string::size_type>(hashLen)); 1489 static_cast<string::size_type>(hashLen));
1487 delete [] buf; 1490 delete [] buf;
1488 if (calcHash != *dataHash) 1491 if (calcHash != *dataHash)
1489 return e_fileCorrupt; 1492 return e_fileCorrupt;
1490 break; 1493 break;
1491 } 1494 }
1492 default: 1495 default:
1493 return e_hashNotImpl; 1496 return e_hashNotImpl;
1494 } 1497 }
1495 return e_success; 1498 return e_success;
1496} 1499}
1497 1500
1498bool PwMDoc::lockAt(unsigned int category, unsigned int index, 1501bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1499 bool lock) 1502 bool lock)
1500{ 1503{
1501 if (index >= numEntries(category)) { 1504 if (index >= numEntries(category)) {
1502 BUG(); 1505 BUG();
1503 return false; 1506 return false;
1504 } 1507 }
1505 if (lock == dti.dta[category].d[index].lockStat) 1508 if (lock == dti.dta[category].d[index].lockStat)
1506 return true; 1509 return true;
1507 1510
1508 if (!lock && currentPw != "") { 1511 if (!lock && currentPw != "") {
1509 // "unlocking" and "password is already set" 1512 // "unlocking" and "password is already set"
1510 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1513 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1511 // unlocking without pw not allowed 1514 // unlocking without pw not allowed
1512 QString pw; 1515 QString pw;
1513 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1516 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1514 if (pw != "") { 1517 if (pw != "") {
1515 if (pw != currentPw) { 1518 if (pw != currentPw) {
1516 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1519 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1517 return false; 1520 return false;
1518 } else { 1521 } else {
1519 timer()->start(DocTimer::id_mpwTimer); 1522 timer()->start(DocTimer::id_mpwTimer);
1520 } 1523 }
1521 } else { 1524 } else {
1522 return false; 1525 return false;
1523 } 1526 }
1524 } else { 1527 } else {
1525 timer()->start(DocTimer::id_mpwTimer); 1528 timer()->start(DocTimer::id_mpwTimer);
1526 } 1529 }
1527 } 1530 }
1528 1531
1529 dti.dta[category].d[index].lockStat = lock; 1532 dti.dta[category].d[index].lockStat = lock;
1530 dti.dta[category].d[index].rev++; // increment revision counter. 1533 dti.dta[category].d[index].rev++; // increment revision counter.
1531 1534
1532 emitDataChanged(this); 1535 emitDataChanged(this);
1533 if (!lock) 1536 if (!lock)
1534 timer()->start(DocTimer::id_autoLockTimer); 1537 timer()->start(DocTimer::id_autoLockTimer);
1535 1538
1536 return true; 1539 return true;
1537 1540
1538} 1541}
1539 1542
1540bool PwMDoc::lockAt(const QString &category,unsigned int index, 1543bool PwMDoc::lockAt(const QString &category,unsigned int index,
1541 bool lock) 1544 bool lock)
1542{ 1545{
1543 unsigned int cat = 0; 1546 unsigned int cat = 0;
1544 1547
1545 if (!findCategory(category, &cat)) { 1548 if (!findCategory(category, &cat)) {
1546 BUG(); 1549 BUG();
1547 return false; 1550 return false;
1548 } 1551 }
1549 1552
1550 return lockAt(cat, index, lock); 1553 return lockAt(cat, index, lock);
1551} 1554}
1552 1555
1553bool PwMDoc::lockAll(bool lock) 1556bool PwMDoc::lockAll(bool lock)
1554{ 1557{
1555 if (!lock && isDeepLocked()) { 1558 if (!lock && isDeepLocked()) {
1556 PwMerror ret; 1559 PwMerror ret;
1557 ret = deepLock(false); 1560 ret = deepLock(false);
1558 if (ret != e_success) 1561 if (ret != e_success)
1559 return false; 1562 return false;
1560 return true; 1563 return true;
1561 } 1564 }
1562 if (isDocEmpty()) { 1565 if (isDocEmpty()) {
1563 return true; 1566 return true;
1564 } 1567 }
1565 if (!lock && currentPw != "") { 1568 if (!lock && currentPw != "") {
1566 // unlocking and password is already set 1569 // unlocking and password is already set
1567 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1570 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1568 // unlocking without pw not allowed 1571 // unlocking without pw not allowed
1569 QString pw; 1572 QString pw;
1570 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1573 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1571 if (pw != "") { 1574 if (pw != "") {
1572 if (pw != currentPw) { 1575 if (pw != currentPw) {
1573 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1576 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1574 return false; 1577 return false;
1575 } else { 1578 } else {
1576 timer()->start(DocTimer::id_mpwTimer); 1579 timer()->start(DocTimer::id_mpwTimer);
1577 } 1580 }
1578 } else { 1581 } else {
1579 return false; 1582 return false;
1580 } 1583 }
1581 } else { 1584 } else {
1582 timer()->start(DocTimer::id_mpwTimer); 1585 timer()->start(DocTimer::id_mpwTimer);
1583 } 1586 }
1584 } 1587 }
1585 1588
1586 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1589 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1587 catEnd = dti.dta.end(), 1590 catEnd = dti.dta.end(),
1588 catI = catBegin; 1591 catI = catBegin;
1589 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1592 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1590 while (catI != catEnd) { 1593 while (catI != catEnd) {
1591 entrBegin = catI->d.begin(); 1594 entrBegin = catI->d.begin();
1592 entrEnd = catI->d.end(); 1595 entrEnd = catI->d.end();
1593 entrI = entrBegin; 1596 entrI = entrBegin;
1594 while (entrI != entrEnd) { 1597 while (entrI != entrEnd) {
1595 entrI->lockStat = lock; 1598 entrI->lockStat = lock;
1596 entrI->rev++; // increment revision counter. 1599 entrI->rev++; // increment revision counter.
1597 ++entrI; 1600 ++entrI;
1598 } 1601 }
1599 ++catI; 1602 ++catI;
1600 } 1603 }
1601 1604
1602 emitDataChanged(this); 1605 emitDataChanged(this);
1603 if (lock) 1606 if (lock)
1604 timer()->stop(DocTimer::id_autoLockTimer); 1607 timer()->stop(DocTimer::id_autoLockTimer);
1605 else 1608 else
1606 timer()->start(DocTimer::id_autoLockTimer); 1609 timer()->start(DocTimer::id_autoLockTimer);
1607 1610
1608 return true; 1611 return true;
1609} 1612}
1610 1613
1611bool PwMDoc::isLocked(const QString &category, unsigned int index) 1614bool PwMDoc::isLocked(const QString &category, unsigned int index)
1612{ 1615{
1613 unsigned int cat = 0; 1616 unsigned int cat = 0;
1614 1617
1615 if (!findCategory(category, &cat)) { 1618 if (!findCategory(category, &cat)) {
1616 BUG(); 1619 BUG();
1617 return false; 1620 return false;
1618 } 1621 }
1619 1622
1620 return isLocked(cat, index); 1623 return isLocked(cat, index);
1621} 1624}
1622 1625
1623bool PwMDoc::unlockAll_tempoary(bool revert) 1626bool PwMDoc::unlockAll_tempoary(bool revert)
1624{ 1627{
1625 static vector< vector<bool> > *oldLockStates = 0; 1628 static vector< vector<bool> > *oldLockStates = 0;
1626 static bool wasDeepLocked; 1629 static bool wasDeepLocked;
1627 1630
1628 if (revert) {// revert the unlocking 1631 if (revert) {// revert the unlocking
1629 if (oldLockStates) { 1632 if (oldLockStates) {
1630 /* we actually _have_ unlocked something, because 1633 /* we actually _have_ unlocked something, because
1631 * we have allocated space for the oldLockStates. 1634 * we have allocated space for the oldLockStates.
1632 * So, go on and revert them! 1635 * So, go on and revert them!
1633 */ 1636 */
1634 if (wasDeepLocked) { 1637 if (wasDeepLocked) {
1635 PwMerror ret = deepLock(true); 1638 PwMerror ret = deepLock(true);
1636 if (ret == e_success) { 1639 if (ret == e_success) {
1637 /* deep-lock succeed. We are save. 1640 /* deep-lock succeed. We are save.
1638 * (but if it failed, just go on 1641 * (but if it failed, just go on
1639 * lock them normally) 1642 * lock them normally)
1640 */ 1643 */
1641 delete_and_null(oldLockStates); 1644 delete_and_null(oldLockStates);
1642 timer()->start(DocTimer::id_autoLockTimer); 1645 timer()->start(DocTimer::id_autoLockTimer);
1643 printDebug("tempoary unlocking of dta " 1646 printDebug("tempoary unlocking of dta "
1644 "reverted by deep-locking."); 1647 "reverted by deep-locking.");
1645 return true; 1648 return true;
1646 } 1649 }
1647 printDebug("deep-lock failed while reverting! " 1650 printDebug("deep-lock failed while reverting! "
1648 "Falling back to normal-lock."); 1651 "Falling back to normal-lock.");
1649 } 1652 }
1650 if (unlikely(!wasDeepLocked && 1653 if (unlikely(!wasDeepLocked &&
1651 numCategories() != oldLockStates->size())) { 1654 numCategories() != oldLockStates->size())) {
1652 /* DOH! We have modified "dta" while 1655 /* DOH! We have modified "dta" while
1653 * it was unlocked tempoary. DON'T DO THIS! 1656 * it was unlocked tempoary. DON'T DO THIS!
1654 */ 1657 */
1655 BUG(); 1658 BUG();
1656 delete_and_null(oldLockStates); 1659 delete_and_null(oldLockStates);
1657 timer()->start(DocTimer::id_autoLockTimer); 1660 timer()->start(DocTimer::id_autoLockTimer);
1658 return false; 1661 return false;
1659 } 1662 }
1660 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1663 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1661 catEnd = dti.dta.end(), 1664 catEnd = dti.dta.end(),
1662 catI = catBegin; 1665 catI = catBegin;
1663 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1666 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1664 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); 1667 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin();
1665 vector<bool>::iterator oldEntrStatBegin, 1668 vector<bool>::iterator oldEntrStatBegin,
1666 oldEntrStatEnd, 1669 oldEntrStatEnd,
1667 oldEntrStatI; 1670 oldEntrStatI;
1668 while (catI != catEnd) { 1671 while (catI != catEnd) {
1669 entrBegin = catI->d.begin(); 1672 entrBegin = catI->d.begin();
1670 entrEnd = catI->d.end(); 1673 entrEnd = catI->d.end();
1671 entrI = entrBegin; 1674 entrI = entrBegin;
1672 if (likely(!wasDeepLocked)) { 1675 if (likely(!wasDeepLocked)) {
1673 oldEntrStatBegin = oldCatStatI->begin(); 1676 oldEntrStatBegin = oldCatStatI->begin();
1674 oldEntrStatEnd = oldCatStatI->end(); 1677 oldEntrStatEnd = oldCatStatI->end();
1675 oldEntrStatI = oldEntrStatBegin; 1678 oldEntrStatI = oldEntrStatBegin;
1676 if (unlikely(catI->d.size() != oldCatStatI->size())) { 1679 if (unlikely(catI->d.size() != oldCatStatI->size())) {
1677 /* DOH! We have modified "dta" while 1680 /* DOH! We have modified "dta" while
1678 * it was unlocked tempoary. DON'T DO THIS! 1681 * it was unlocked tempoary. DON'T DO THIS!
1679 */ 1682 */
1680 BUG(); 1683 BUG();
1681 delete_and_null(oldLockStates); 1684 delete_and_null(oldLockStates);
1682 timer()->start(DocTimer::id_autoLockTimer); 1685 timer()->start(DocTimer::id_autoLockTimer);
1683 return false; 1686 return false;
1684 } 1687 }
1685 } 1688 }
1686 while (entrI != entrEnd) { 1689 while (entrI != entrEnd) {
1687 if (wasDeepLocked) { 1690 if (wasDeepLocked) {
1688 /* this is an error-fallback if 1691 /* this is an error-fallback if
1689 * deeplock didn't succeed 1692 * deeplock didn't succeed
1690 */ 1693 */
1691 entrI->lockStat = true; 1694 entrI->lockStat = true;
1692 } else { 1695 } else {
1693 entrI->lockStat = *oldEntrStatI; 1696 entrI->lockStat = *oldEntrStatI;
1694 } 1697 }
1695 ++entrI; 1698 ++entrI;
1696 if (likely(!wasDeepLocked)) 1699 if (likely(!wasDeepLocked))
1697 ++oldEntrStatI; 1700 ++oldEntrStatI;
1698 } 1701 }
1699 ++catI; 1702 ++catI;
1700 if (likely(!wasDeepLocked)) 1703 if (likely(!wasDeepLocked))
1701 ++oldCatStatI; 1704 ++oldCatStatI;
1702 } 1705 }
1703 delete_and_null(oldLockStates); 1706 delete_and_null(oldLockStates);
1704 if (unlikely(wasDeepLocked)) { 1707 if (unlikely(wasDeepLocked)) {
1705 /* error fallback... */ 1708 /* error fallback... */
1706 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1709 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1707 emitDataChanged(this); 1710 emitDataChanged(this);
1708 printDebug("WARNING: unlockAll_tempoary(true) " 1711 printDebug("WARNING: unlockAll_tempoary(true) "
1709 "deeplock fallback!"); 1712 "deeplock fallback!");
1710 } 1713 }
1711 printDebug("tempoary unlocking of dta reverted."); 1714 printDebug("tempoary unlocking of dta reverted.");
1712 } else { 1715 } else {
1713 printDebug("unlockAll_tempoary(true): nothing to do."); 1716 printDebug("unlockAll_tempoary(true): nothing to do.");
1714 } 1717 }
1715 timer()->start(DocTimer::id_autoLockTimer); 1718 timer()->start(DocTimer::id_autoLockTimer);
1716 } else {// unlock all data tempoary 1719 } else {// unlock all data tempoary
1717 if (unlikely(oldLockStates != 0)) { 1720 if (unlikely(oldLockStates != 0)) {
1718 /* DOH! We have already unlocked the data tempoarly. 1721 /* DOH! We have already unlocked the data tempoarly.
1719 * No need to do it twice. ;) 1722 * No need to do it twice. ;)
1720 */ 1723 */
1721 BUG(); 1724 BUG();
1722 return false; 1725 return false;
1723 } 1726 }
1724 wasDeepLocked = false; 1727 wasDeepLocked = false;
1725 bool mustUnlock = false; 1728 bool mustUnlock = false;
1726 if (isDeepLocked()) { 1729 if (isDeepLocked()) {
1727 PwMerror ret; 1730 PwMerror ret;
1728 while (1) { 1731 while (1) {
1729 ret = deepLock(false); 1732 ret = deepLock(false);
1730 if (ret == e_success) { 1733 if (ret == e_success) {
1731 break; 1734 break;
1732 } else if (ret == e_wrongPw) { 1735 } else if (ret == e_wrongPw) {
1733 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1736 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1734 } else { 1737 } else {
1735 printDebug("deep-unlocking failed while " 1738 printDebug("deep-unlocking failed while "
1736 "tempoary unlocking!"); 1739 "tempoary unlocking!");
1737 return false; 1740 return false;
1738 } 1741 }
1739 } 1742 }
1740 wasDeepLocked = true; 1743 wasDeepLocked = true;
1741 mustUnlock = true; 1744 mustUnlock = true;
1742 } else { 1745 } else {
1743 // first check if it's needed to unlock some entries 1746 // first check if it's needed to unlock some entries
1744 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1747 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1745 catEnd = dti.dta.end(), 1748 catEnd = dti.dta.end(),
1746 catI = catBegin; 1749 catI = catBegin;
1747 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1750 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1748 while (catI != catEnd) { 1751 while (catI != catEnd) {
1749 entrBegin = catI->d.begin(); 1752 entrBegin = catI->d.begin();
1750 entrEnd = catI->d.end(); 1753 entrEnd = catI->d.end();
1751 entrI = entrBegin; 1754 entrI = entrBegin;
1752 while (entrI != entrEnd) { 1755 while (entrI != entrEnd) {
1753 if (entrI->lockStat == true) { 1756 if (entrI->lockStat == true) {
1754 mustUnlock = true; 1757 mustUnlock = true;
1755 break; 1758 break;
1756 } 1759 }
1757 ++entrI; 1760 ++entrI;
1758 } 1761 }
1759 if (mustUnlock) 1762 if (mustUnlock)
1760 break; 1763 break;
1761 ++catI; 1764 ++catI;
1762 } 1765 }
1763 } 1766 }
1764 if (!mustUnlock) { 1767 if (!mustUnlock) {
1765 // nothing to do. 1768 // nothing to do.
1766 timer()->stop(DocTimer::id_autoLockTimer); 1769 timer()->stop(DocTimer::id_autoLockTimer);
1767 printDebug("unlockAll_tempoary(): nothing to do."); 1770 printDebug("unlockAll_tempoary(): nothing to do.");
1768 return true; 1771 return true;
1769 } else if (!wasDeepLocked) { 1772 } else if (!wasDeepLocked) {
1770 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && 1773 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) &&
1771 currentPw != "") { 1774 currentPw != "") {
1772 /* we can't unlock without mpw, so 1775 /* we can't unlock without mpw, so
1773 * we need to ask for it. 1776 * we need to ask for it.
1774 */ 1777 */
1775 QString pw; 1778 QString pw;
1776 while (1) { 1779 while (1) {
1777 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1780 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1778 if (pw == "") { 1781 if (pw == "") {
1779 return false; 1782 return false;
1780 } else if (pw == currentPw) { 1783 } else if (pw == currentPw) {
1781 break; 1784 break;
1782 } 1785 }
1783 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1786 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1784 } 1787 }
1785 } 1788 }
1786 } 1789 }
1787 timer()->stop(DocTimer::id_autoLockTimer); 1790 timer()->stop(DocTimer::id_autoLockTimer);
1788 oldLockStates = new vector< vector<bool> >; 1791 oldLockStates = new vector< vector<bool> >;
1789 vector<bool> tmp_vec; 1792 vector<bool> tmp_vec;
1790 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1793 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1791 catEnd = dti.dta.end(), 1794 catEnd = dti.dta.end(),
1792 catI = catBegin; 1795 catI = catBegin;
1793 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1796 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1794 while (catI != catEnd) { 1797 while (catI != catEnd) {
1795 entrBegin = catI->d.begin(); 1798 entrBegin = catI->d.begin();
1796 entrEnd = catI->d.end(); 1799 entrEnd = catI->d.end();
1797 entrI = entrBegin; 1800 entrI = entrBegin;
1798 while (entrI != entrEnd) { 1801 while (entrI != entrEnd) {
1799 if (!wasDeepLocked) { 1802 if (!wasDeepLocked) {
1800 tmp_vec.push_back(entrI->lockStat); 1803 tmp_vec.push_back(entrI->lockStat);
1801 } 1804 }
1802 entrI->lockStat = false; 1805 entrI->lockStat = false;
1803 ++entrI; 1806 ++entrI;
1804 } 1807 }
1805 if (!wasDeepLocked) { 1808 if (!wasDeepLocked) {
1806 oldLockStates->push_back(tmp_vec); 1809 oldLockStates->push_back(tmp_vec);
1807 tmp_vec.clear(); 1810 tmp_vec.clear();
1808 } 1811 }
1809 ++catI; 1812 ++catI;
1810 } 1813 }
1811 printDebug("tempoary unlocked dta."); 1814 printDebug("tempoary unlocked dta.");
1812 } 1815 }
1813 1816
1814 return true; 1817 return true;
1815} 1818}
1816 1819
1817PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) 1820PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1818{ 1821{
1819 PwMerror ret; 1822 PwMerror ret;
1820 /* NOTE: saveDoc() depends on this function to return 1823 /* NOTE: saveDoc() depends on this function to return
1821 * e_success if saveToFile == false 1824 * e_success if saveToFile == false
1822 */ 1825 */
1823 1826
1824 if (lock) { 1827 if (lock) {
1825 if (isDeepLocked()) 1828 if (isDeepLocked())
1826 return e_lock; 1829 return e_lock;
1827 if (saveToFile) { 1830 if (saveToFile) {
1828 if (isDocEmpty()) 1831 if (isDocEmpty())
1829 return e_docIsEmpty; 1832 return e_docIsEmpty;
1830 ret = saveDoc(conf()->confGlobCompression()); 1833 ret = saveDoc(conf()->confGlobCompression());
1831 if (ret == e_filename) { 1834 if (ret == e_filename) {
1832 /* the doc wasn't saved to a file 1835 /* the doc wasn't saved to a file
1833 * by the user, yet. 1836 * by the user, yet.
1834 */ 1837 */
1835 cantDeeplock_notSavedMsgBox(); 1838 cantDeeplock_notSavedMsgBox();
1836 return e_docNotSaved; 1839 return e_docNotSaved;
1837 } else if (ret != e_success) { 1840 } else if (ret != e_success) {
1838 return e_lock; 1841 return e_lock;
1839 } 1842 }
1840 } 1843 }
1841 timer()->stop(DocTimer::id_autoLockTimer); 1844 timer()->stop(DocTimer::id_autoLockTimer);
1842 clearDoc(); 1845 clearDoc();
1843 PwMDataItem d; 1846 PwMDataItem d;
1844 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); 1847 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1();
1845 d.comment = IS_DEEPLOCKED_MSG.latin1(); 1848 d.comment = IS_DEEPLOCKED_MSG.latin1();
1846 d.listViewPos = 0; 1849 d.listViewPos = 0;
1847 addEntry(DEFAULT_CATEGORY, &d, true); 1850 addEntry(DEFAULT_CATEGORY, &d, true);
1848 lockAt(DEFAULT_CATEGORY, 0, true); 1851 lockAt(DEFAULT_CATEGORY, 0, true);
1849 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 1852 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
1850 setDocStatFlag(DOC_STAT_DEEPLOCKED); 1853 setDocStatFlag(DOC_STAT_DEEPLOCKED);
1851 } else { 1854 } else {
1852 if (!isDeepLocked()) 1855 if (!isDeepLocked())
1853 return e_lock; 1856 return e_lock;
1854 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) 1857 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen())
1855 ? 0 : 1); 1858 ? 0 : 1);
1856 if (ret == e_wrongPw) { 1859 if (ret == e_wrongPw) {
1857 return e_wrongPw; 1860 return e_wrongPw;
1858 } else if (ret != e_success) { 1861 } else if (ret != e_success) {
1859 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") 1862 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ")
1860 + tostr(static_cast<int>(ret))); 1863 + tostr(static_cast<int>(ret)));
1861 return e_lock; 1864 return e_lock;
1862 } 1865 }
1863 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1866 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1864 timer()->start(DocTimer::id_autoLockTimer); 1867 timer()->start(DocTimer::id_autoLockTimer);
1865 } 1868 }
1866 1869
1867 emitDataChanged(this); 1870 emitDataChanged(this);
1868 return e_success; 1871 return e_success;
1869} 1872}
1870 1873
1871void PwMDoc::_deepUnlock() 1874void PwMDoc::_deepUnlock()
1872{ 1875{
1873 deepLock(false); 1876 deepLock(false);
1874} 1877}
1875 1878
1876void PwMDoc::clearDoc() 1879void PwMDoc::clearDoc()
1877{ 1880{
1878 dti.clear(); 1881 dti.clear();
1879 PwMCategoryItem d; 1882 PwMCategoryItem d;
1880 d.name = DEFAULT_CATEGORY.latin1(); 1883 d.name = DEFAULT_CATEGORY.latin1();
1881 dti.dta.push_back(d); 1884 dti.dta.push_back(d);
1882 currentPw = ""; 1885 currentPw = "";
1883 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 1886 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
1884} 1887}
1885 1888
1886void PwMDoc::changeCurrentPw() 1889void PwMDoc::changeCurrentPw()
1887{ 1890{
1888 if (currentPw == "") 1891 if (currentPw == "")
1889 return; // doc hasn't been saved. No mpw available. 1892 return; // doc hasn't been saved. No mpw available.
1890 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 1893 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
1891 QString pw = requestMpwChange(&currentPw, &useChipcard); 1894 QString pw = requestMpwChange(&currentPw, &useChipcard);
1892 if (pw == "") 1895 if (pw == "")
1893 return; 1896 return;
1894 if (useChipcard) 1897 if (useChipcard)
1895 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 1898 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
1896 else 1899 else
1897 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 1900 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
1898 setCurrentPw(pw); 1901 setCurrentPw(pw);
1899} 1902}
1900 1903
1901void PwMDoc::setListViewPos(const QString &category, unsigned int index, 1904void PwMDoc::setListViewPos(const QString &category, unsigned int index,
1902 int pos) 1905 int pos)
1903{ 1906{
1904 unsigned int cat = 0; 1907 unsigned int cat = 0;
1905 1908
1906 if (!findCategory(category, &cat)) { 1909 if (!findCategory(category, &cat)) {
1907 BUG(); 1910 BUG();
1908 return; 1911 return;
1909 } 1912 }
1910 setListViewPos(cat, index, pos); 1913 setListViewPos(cat, index, pos);
1911} 1914}
1912 1915
1913void PwMDoc::setListViewPos(unsigned int category, unsigned int index, 1916void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
1914 int pos) 1917 int pos)
1915{ 1918{
1916 dti.dta[category].d[index].listViewPos = pos; 1919 dti.dta[category].d[index].listViewPos = pos;
1917 1920
1918/* FIXME workaround: don't flag dirty, because this function sometimes 1921/* FIXME workaround: don't flag dirty, because this function sometimes
1919 * get's called when it shouldn't. It's because PwMView assumes 1922 * get's called when it shouldn't. It's because PwMView assumes
1920 * the user resorted the UI on behalf of signal layoutChanged(). 1923 * the user resorted the UI on behalf of signal layoutChanged().
1921 * This is somewhat broken and incorrect, but I've no other 1924 * This is somewhat broken and incorrect, but I've no other
1922 * solution for now. 1925 * solution for now.
1923 */ 1926 */
1924 //setDocStatFlag(DOC_STAT_DISK_DIRTY); 1927 //setDocStatFlag(DOC_STAT_DISK_DIRTY);
1925} 1928}
1926 1929
1927int PwMDoc::getListViewPos(const QString &category, unsigned int index) 1930int PwMDoc::getListViewPos(const QString &category, unsigned int index)
1928{ 1931{
1929 unsigned int cat = 0; 1932 unsigned int cat = 0;
1930 1933
1931 if (!findCategory(category, &cat)) { 1934 if (!findCategory(category, &cat)) {
1932 BUG(); 1935 BUG();
1933 return -1; 1936 return -1;
1934 } 1937 }
1935 1938
1936 return dti.dta[cat].d[index].listViewPos; 1939 return dti.dta[cat].d[index].listViewPos;
1937} 1940}
1938 1941
1939void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 1942void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
1940 vector<unsigned int> *foundPositions, bool breakAfterFound, 1943 vector<unsigned int> *foundPositions, bool breakAfterFound,
1941 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 1944 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
1942{ 1945{
1943 PWM_ASSERT(foundPositions); 1946 PWM_ASSERT(foundPositions);
1944 PWM_ASSERT(searchIn); 1947 PWM_ASSERT(searchIn);
1945 foundPositions->clear(); 1948 foundPositions->clear();
1946 1949
1947 unsigned int i, entries = numEntries(category); 1950 unsigned int i, entries = numEntries(category);
1948 for (i = 0; i < entries; ++i) { 1951 for (i = 0; i < entries; ++i) {
1949 if (searchIn & SEARCH_IN_DESC) { 1952 if (searchIn & SEARCH_IN_DESC) {
1950 if (!compareString(find.desc, dti.dta[category].d[i].desc, 1953 if (!compareString(find.desc, dti.dta[category].d[i].desc,
1951 caseSensitive, exactWordMatch)) { 1954 caseSensitive, exactWordMatch)) {
1952 continue; 1955 continue;
1953 } 1956 }
1954 } 1957 }
1955 if (searchIn & SEARCH_IN_NAME) { 1958 if (searchIn & SEARCH_IN_NAME) {
1956 if (!compareString(find.name, dti.dta[category].d[i].name, 1959 if (!compareString(find.name, dti.dta[category].d[i].name,
1957 caseSensitive, exactWordMatch)) { 1960 caseSensitive, exactWordMatch)) {
1958 continue; 1961 continue;
1959 } 1962 }
1960 } 1963 }
1961 if (searchIn & SEARCH_IN_PW) { 1964 if (searchIn & SEARCH_IN_PW) {
1962 bool wasLocked = isLocked(category, i); 1965 bool wasLocked = isLocked(category, i);
1963 getDataChangedLock(); 1966 getDataChangedLock();
1964 lockAt(category, i, false); 1967 lockAt(category, i, false);
1965 if (!compareString(find.pw, dti.dta[category].d[i].pw, 1968 if (!compareString(find.pw, dti.dta[category].d[i].pw,
1966 caseSensitive, exactWordMatch)) { 1969 caseSensitive, exactWordMatch)) {
1967 lockAt(category, i, wasLocked); 1970 lockAt(category, i, wasLocked);
1968 putDataChangedLock(); 1971 putDataChangedLock();
1969 continue; 1972 continue;
1970 } 1973 }
1971 lockAt(category, i, wasLocked); 1974 lockAt(category, i, wasLocked);
1972 putDataChangedLock(); 1975 putDataChangedLock();
1973 } 1976 }
1974 if (searchIn & SEARCH_IN_COMMENT) { 1977 if (searchIn & SEARCH_IN_COMMENT) {
1975 if (!compareString(find.comment, dti.dta[category].d[i].comment, 1978 if (!compareString(find.comment, dti.dta[category].d[i].comment,
1976 caseSensitive, exactWordMatch)) { 1979 caseSensitive, exactWordMatch)) {
1977 continue; 1980 continue;
1978 } 1981 }
1979 } 1982 }
1980 if (searchIn & SEARCH_IN_URL) { 1983 if (searchIn & SEARCH_IN_URL) {
1981 if (!compareString(find.url, dti.dta[category].d[i].url, 1984 if (!compareString(find.url, dti.dta[category].d[i].url,
1982 caseSensitive, exactWordMatch)) { 1985 caseSensitive, exactWordMatch)) {
1983 continue; 1986 continue;
1984 } 1987 }
1985 } 1988 }
1986 if (searchIn & SEARCH_IN_LAUNCHER) { 1989 if (searchIn & SEARCH_IN_LAUNCHER) {
1987 if (!compareString(find.launcher, dti.dta[category].d[i].launcher, 1990 if (!compareString(find.launcher, dti.dta[category].d[i].launcher,
1988 caseSensitive, exactWordMatch)) { 1991 caseSensitive, exactWordMatch)) {
1989 continue; 1992 continue;
1990 } 1993 }
1991 } 1994 }
1992 1995
1993 // all selected "searchIn" matched. 1996 // all selected "searchIn" matched.
1994 foundPositions->push_back(i); 1997 foundPositions->push_back(i);
1995 if (breakAfterFound) 1998 if (breakAfterFound)
1996 break; 1999 break;
1997 } 2000 }
1998 2001
1999 if (sortByLvp && foundPositions->size() > 1) { 2002 if (sortByLvp && foundPositions->size() > 1) {
2000 vector< pair<unsigned int /* foundPosition (real doc pos) */, 2003 vector< pair<unsigned int /* foundPosition (real doc pos) */,
2001 unsigned int /* lvp-pos */> > tmp_vec; 2004 unsigned int /* lvp-pos */> > tmp_vec;
2002 2005
2003 unsigned int i, items = foundPositions->size(); 2006 unsigned int i, items = foundPositions->size();
2004 pair<unsigned int, unsigned int> tmp_pair; 2007 pair<unsigned int, unsigned int> tmp_pair;
2005 for (i = 0; i < items; ++i) { 2008 for (i = 0; i < items; ++i) {
2006 tmp_pair.first = (*foundPositions)[i]; 2009 tmp_pair.first = (*foundPositions)[i];
2007 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; 2010 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos;
2008 tmp_vec.push_back(tmp_pair); 2011 tmp_vec.push_back(tmp_pair);
2009 } 2012 }
2010 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); 2013 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater());
2011 foundPositions->clear(); 2014 foundPositions->clear();
2012 for (i = 0; i < items; ++i) { 2015 for (i = 0; i < items; ++i) {
2013 foundPositions->push_back(tmp_vec[i].first); 2016 foundPositions->push_back(tmp_vec[i].first);
2014 } 2017 }
2015 } 2018 }
2016} 2019}
2017 2020
2018void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 2021void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
2019 vector<unsigned int> *foundPositions, bool breakAfterFound, 2022 vector<unsigned int> *foundPositions, bool breakAfterFound,
2020 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 2023 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
2021{ 2024{
2022 PWM_ASSERT(foundPositions); 2025 PWM_ASSERT(foundPositions);
2023 unsigned int cat = 0; 2026 unsigned int cat = 0;
2024 2027
2025 if (!findCategory(category, &cat)) { 2028 if (!findCategory(category, &cat)) {
2026 foundPositions->clear(); 2029 foundPositions->clear();
2027 return; 2030 return;
2028 } 2031 }
2029 2032
2030 findEntry(cat, find, searchIn, foundPositions, breakAfterFound, 2033 findEntry(cat, find, searchIn, foundPositions, breakAfterFound,
2031 caseSensitive, exactWordMatch, sortByLvp); 2034 caseSensitive, exactWordMatch, sortByLvp);
2032} 2035}
2033 2036
2034bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, 2037bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive,
2035 bool exactWordMatch) 2038 bool exactWordMatch)
2036{ 2039{
2037 QString _s1(s1.c_str()); 2040 QString _s1(s1.c_str());
2038 QString _s2(s2.c_str()); 2041 QString _s2(s2.c_str());
2039 if (!caseSensitive) { 2042 if (!caseSensitive) {
2040 _s1 = _s1.lower(); 2043 _s1 = _s1.lower();
2041 _s2 = _s2.lower(); 2044 _s2 = _s2.lower();
2042 } 2045 }
2043 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) 2046 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1))
2044 return true; 2047 return true;
2045 return false; 2048 return false;
2046} 2049}
2047 2050
2048bool PwMDoc::findCategory(const QString &name, unsigned int *index) 2051bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2049{ 2052{
2050 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2053 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2051 end = dti.dta.end(); 2054 end = dti.dta.end();
2052 while (i != end) { 2055 while (i != end) {
2053 if ((*i).name == name.latin1()) { 2056 if ((*i).name == name.latin1()) {
2054 if (index) { 2057 if (index) {
2055 *index = i - dti.dta.begin(); 2058 *index = i - dti.dta.begin();
2056 } 2059 }
2057 return true; 2060 return true;
2058 } 2061 }
2059 ++i; 2062 ++i;
2060 } 2063 }
2061 return false; 2064 return false;
2062} 2065}
2063 2066
2064bool PwMDoc::renameCategory(const QString &category, const QString &newName) 2067bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2065{ 2068{
2066 unsigned int cat = 0; 2069 unsigned int cat = 0;
2067 2070
2068 if (!findCategory(category, &cat)) 2071 if (!findCategory(category, &cat))
2069 return false; 2072 return false;
2070 2073
2071 return renameCategory(cat, newName); 2074 return renameCategory(cat, newName);
2072} 2075}
2073 2076
2074bool PwMDoc::renameCategory(unsigned int category, const QString &newName, 2077bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2075 bool dontFlagDirty) 2078 bool dontFlagDirty)
2076{ 2079{
2077 if (category > numCategories() - 1) 2080 if (category > numCategories() - 1)
2078 return false; 2081 return false;
2079 2082
2080 dti.dta[category].name = newName.latin1(); 2083 dti.dta[category].name = newName.latin1();
2081 if (!dontFlagDirty) 2084 if (!dontFlagDirty)
2082 flagDirty(); 2085 flagDirty();
2083 2086
2084 return true; 2087 return true;
2085} 2088}
2086 2089
2087bool PwMDoc::delCategory(const QString &category) 2090bool PwMDoc::delCategory(const QString &category)
2088{ 2091{
2089 unsigned int cat = 0; 2092 unsigned int cat = 0;
2090 2093
2091 if (!findCategory(category, &cat)) 2094 if (!findCategory(category, &cat))
2092 return false; 2095 return false;
2093 2096
2094 return delCategory(cat); 2097 return delCategory(cat);
2095} 2098}
2096 2099
2097bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) 2100bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2098{ 2101{
2099 if (category > numCategories() - 1) 2102 if (category > numCategories() - 1)
2100 return false; 2103 return false;
2101 2104
2102 // We don't delete it, if it is the last existing 2105 // We don't delete it, if it is the last existing
2103 // category! Instead we rename it to "Default". 2106 // category! Instead we rename it to "Default".
2104 if (numCategories() > 1) { 2107 if (numCategories() > 1) {
2105 dti.dta.erase(dti.dta.begin() + category); 2108 dti.dta.erase(dti.dta.begin() + category);
2106 } else { 2109 } else {
2107 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); 2110 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2108 return true; 2111 return true;
2109 } 2112 }
2110 if (!dontFlagDirty) 2113 if (!dontFlagDirty)
2111 flagDirty(); 2114 flagDirty();
2112 2115
2113 return true; 2116 return true;
2114} 2117}
2115 2118
2116void PwMDoc::delAllEmptyCat(bool dontFlagDirty) 2119void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2117{ 2120{
2118 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), 2121 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
2119 end = dti.dta.end(), 2122 end = dti.dta.end(),
2120 i = begin; 2123 i = begin;
2121 while (i != end) { 2124 while (i != end) {
2122 if (i->d.empty()) { 2125 if (i->d.empty()) {
2123 delCategory(begin - i, dontFlagDirty); 2126 delCategory(begin - i, dontFlagDirty);
2124 } 2127 }
2125 ++i; 2128 ++i;
2126 } 2129 }
2127} 2130}
2128 2131
2129void PwMDoc::getCategoryList(vector<string> *list) 2132void PwMDoc::getCategoryList(vector<string> *list)
2130{ 2133{
2131 PWM_ASSERT(list); 2134 PWM_ASSERT(list);
2132 list->clear(); 2135 list->clear();
2133 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2136 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2134 end = dti.dta.end(); 2137 end = dti.dta.end();
2135 while (i != end) { 2138 while (i != end) {
2136 list->push_back(i->name); 2139 list->push_back(i->name);
2137 ++i; 2140 ++i;
2138 } 2141 }
2139} 2142}
2140 2143
2141void PwMDoc::getCategoryList(QStringList *list) 2144void PwMDoc::getCategoryList(QStringList *list)
2142{ 2145{
2143 PWM_ASSERT(list); 2146 PWM_ASSERT(list);
2144 list->clear(); 2147 list->clear();
2145 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2148 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2146 end = dti.dta.end(); 2149 end = dti.dta.end();
2147 while (i != end) { 2150 while (i != end) {
2148#ifndef PWM_EMBEDDED 2151#ifndef PWM_EMBEDDED
2149 list->push_back(i->name.c_str()); 2152 list->push_back(i->name.c_str());
2150#else 2153#else
2151 list->append(i->name.c_str()); 2154 list->append(i->name.c_str());
2152#endif 2155#endif
2153 ++i; 2156 ++i;
2154 } 2157 }
2155} 2158}
2156 2159
2157void PwMDoc::getEntryList(const QString &category, QStringList *list) 2160void PwMDoc::getEntryList(const QString &category, QStringList *list)
2158{ 2161{
2159 PWM_ASSERT(list); 2162 PWM_ASSERT(list);
2160 unsigned int cat = 0; 2163 unsigned int cat = 0;
2161 if (!findCategory(category, &cat)) { 2164 if (!findCategory(category, &cat)) {
2162 list->clear(); 2165 list->clear();
2163 return; 2166 return;
2164 } 2167 }
2165 getEntryList(cat, list); 2168 getEntryList(cat, list);
2166} 2169}
2167 2170
2168void PwMDoc::getEntryList(const QString &category, vector<string> *list) 2171void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2169{ 2172{
2170 PWM_ASSERT(list); 2173 PWM_ASSERT(list);
2171 unsigned int cat = 0; 2174 unsigned int cat = 0;
2172 if (!findCategory(category, &cat)) { 2175 if (!findCategory(category, &cat)) {
2173 list->clear(); 2176 list->clear();
2174 return; 2177 return;
2175 } 2178 }
2176 getEntryList(cat, list); 2179 getEntryList(cat, list);
2177} 2180}
2178 2181
2179void PwMDoc::getEntryList(unsigned int category, vector<string> *list) 2182void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2180{ 2183{
2181 PWM_ASSERT(list); 2184 PWM_ASSERT(list);
2182 list->clear(); 2185 list->clear();
2183 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2186 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2184 end = dti.dta[category].d.end(), 2187 end = dti.dta[category].d.end(),
2185 i = begin; 2188 i = begin;
2186 while (i != end) { 2189 while (i != end) {
2187 list->push_back(i->desc); 2190 list->push_back(i->desc);
2188 ++i; 2191 ++i;
2189 } 2192 }
2190} 2193}
2191 2194
2192void PwMDoc::getEntryList(unsigned int category, QStringList *list) 2195void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2193{ 2196{
2194 PWM_ASSERT(list); 2197 PWM_ASSERT(list);
2195 list->clear(); 2198 list->clear();
2196 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2199 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2197 end = dti.dta[category].d.end(), 2200 end = dti.dta[category].d.end(),
2198 i = begin; 2201 i = begin;
2199 while (i != end) { 2202 while (i != end) {
2200#ifndef PWM_EMBEDDED 2203#ifndef PWM_EMBEDDED
2201 list->push_back(i->desc.c_str()); 2204 list->push_back(i->desc.c_str());
2202#else 2205#else
2203 list->append(i->desc.c_str()); 2206 list->append(i->desc.c_str());
2204#endif 2207#endif
2205 ++i; 2208 ++i;
2206 } 2209 }
2207} 2210}
2208 2211
2209bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) 2212bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2210{ 2213{
2211 unsigned int cat = 0; 2214 unsigned int cat = 0;
2212 2215
2213 if (!findCategory(category, &cat)) 2216 if (!findCategory(category, &cat))
2214 return false; 2217 return false;
2215 2218
2216 return execLauncher(cat, entryIndex); 2219 return execLauncher(cat, entryIndex);
2217} 2220}
2218 2221
2219bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) 2222bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2220{ 2223{
2224#ifndef _WIN32_
2221 if (geteuid() == 0) { 2225 if (geteuid() == 0) {
2222 rootAlertMsgBox(); 2226 rootAlertMsgBox();
2223 return false; 2227 return false;
2224 } 2228 }
2229#endif
2225 QString command(dti.dta[category].d[entryIndex].launcher.c_str()); 2230 QString command(dti.dta[category].d[entryIndex].launcher.c_str());
2226 bool wasLocked = isLocked(category, entryIndex); 2231 bool wasLocked = isLocked(category, entryIndex);
2227 2232
2228 if (command.find("$p") != -1) { 2233 if (command.find("$p") != -1) {
2229 /* the user requested the password to be included 2234 /* the user requested the password to be included
2230 * into the command. We have to ask for the password, 2235 * into the command. We have to ask for the password,
2231 * if it's locked. We do that by unlocking the entry 2236 * if it's locked. We do that by unlocking the entry
2232 */ 2237 */
2233 if (!lockAt(category, entryIndex, false)) 2238 if (!lockAt(category, entryIndex, false))
2234 return false; 2239 return false;
2235 } 2240 }
2236#ifndef PWM_EMBEDDED 2241#ifndef PWM_EMBEDDED
2237 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); 2242 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
2238 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); 2243 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
2239 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); 2244 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
2240 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); 2245 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
2241 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); 2246 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
2242#else 2247#else
2243 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); 2248 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
2244 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); 2249 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
2245 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); 2250 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
2246 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); 2251 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
2247 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); 2252 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
2248#endif 2253#endif
2249 command.append(" &"); 2254 command.append(" &");
2250 2255
2251 QString customXterm(conf()->confGlobXtermCommand()); 2256 QString customXterm(conf()->confGlobXtermCommand());
2252 if (!customXterm.isEmpty()) 2257 if (!customXterm.isEmpty())
2253 command = customXterm + " " + command; 2258 command = customXterm + " " + command;
2254 2259
2255 system(command.latin1()); 2260 system(command.latin1());
2256 2261
2257 lockAt(category, entryIndex, wasLocked); 2262 lockAt(category, entryIndex, wasLocked);
2258 return true; 2263 return true;
2259} 2264}
2260 2265
2261bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) 2266bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2262{ 2267{
2263 unsigned int cat = 0; 2268 unsigned int cat = 0;
2264 2269
2265 if (!findCategory(category, &cat)) 2270 if (!findCategory(category, &cat))
2266 return false; 2271 return false;
2267 2272
2268 return goToURL(cat, entryIndex); 2273 return goToURL(cat, entryIndex);
2269} 2274}
2270 2275
2271bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) 2276bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2272{ 2277{
2278#ifndef _WIN32_
2273 if (geteuid() == 0) { 2279 if (geteuid() == 0) {
2274 rootAlertMsgBox(); 2280 rootAlertMsgBox();
2275 return false; 2281 return false;
2276 } 2282 }
2283#endif
2277 QString url(dti.dta[category].d[entryIndex].url.c_str()); 2284 QString url(dti.dta[category].d[entryIndex].url.c_str());
2278 if (url.isEmpty()) 2285 if (url.isEmpty())
2279 return false; 2286 return false;
2280 2287
2281 QString customBrowser(conf()->confGlobBrowserCommand()); 2288 QString customBrowser(conf()->confGlobBrowserCommand());
2282 if (!customBrowser.isEmpty()) { 2289 if (!customBrowser.isEmpty()) {
2283 browserProc.clearArguments(); 2290 browserProc.clearArguments();
2284 browserProc << customBrowser << url; 2291 browserProc << customBrowser << url;
2285 if (browserProc.start(KProcess::DontCare)) 2292 if (browserProc.start(KProcess::DontCare))
2286 return true; 2293 return true;
2287 } 2294 }
2288 2295
2289 browserProc.clearArguments(); 2296 browserProc.clearArguments();
2290 browserProc << "konqueror" << url; 2297 browserProc << "konqueror" << url;
2291 if (browserProc.start(KProcess::DontCare)) 2298 if (browserProc.start(KProcess::DontCare))
2292 return true; 2299 return true;
2293 2300
2294 browserProc.clearArguments(); 2301 browserProc.clearArguments();
2295 browserProc << "mozilla" << url; 2302 browserProc << "mozilla" << url;
2296 if (browserProc.start(KProcess::DontCare)) 2303 if (browserProc.start(KProcess::DontCare))
2297 return true; 2304 return true;
2298 2305
2299 browserProc.clearArguments(); 2306 browserProc.clearArguments();
2300 browserProc << "opera" << url; 2307 browserProc << "opera" << url;
2301 if (browserProc.start(KProcess::DontCare)) 2308 if (browserProc.start(KProcess::DontCare))
2302 return true; 2309 return true;
2303 return false; 2310 return false;
2304} 2311}
2305 2312
2306PwMerror PwMDoc::exportToText(const QString *file) 2313PwMerror PwMDoc::exportToText(const QString *file)
2307{ 2314{
2308 PWM_ASSERT(file); 2315 PWM_ASSERT(file);
2309 if (QFile::exists(*file)) { 2316 if (QFile::exists(*file)) {
2310 if (!QFile::remove(*file)) 2317 if (!QFile::remove(*file))
2311 return e_accessFile; 2318 return e_accessFile;
2312 } 2319 }
2313 QFile f(*file); 2320 QFile f(*file);
2314 if (!f.open(IO_ReadWrite)) 2321 if (!f.open(IO_ReadWrite))
2315 return e_openFile; 2322 return e_openFile;
2316 2323
2317 if (!unlockAll_tempoary()) { 2324 if (!unlockAll_tempoary()) {
2318 f.close(); 2325 f.close();
2319 return e_lock; 2326 return e_lock;
2320 } 2327 }
2321 2328
2322 // write header 2329 // write header
2323 string header = i18n("Password table generated by\nPwM v").latin1(); 2330 string header = i18n("Password table generated by\nPwM v").latin1();
2324 header += PACKAGE_VER; 2331 header += PACKAGE_VER;
2325 header += i18n("\non ").latin1(); 2332 header += i18n("\non ").latin1();
2326 QDate currDate = QDate::currentDate(); 2333 QDate currDate = QDate::currentDate();
2327 QTime currTime = QTime::currentTime(); 2334 QTime currTime = QTime::currentTime();
2328 2335
2329#ifndef PWM_EMBEDDED 2336#ifndef PWM_EMBEDDED
2330 header += currDate.toString("ddd MMMM d ").latin1(); 2337 header += currDate.toString("ddd MMMM d ").latin1();
2331 header += currTime.toString("hh:mm:ss ").latin1(); 2338 header += currTime.toString("hh:mm:ss ").latin1();
2332#else 2339#else
2333 QString dfs = KGlobal::locale()->dateFormatShort(); 2340 QString dfs = KGlobal::locale()->dateFormatShort();
2334 bool ampm = KGlobal::locale()->use12Clock(); 2341 bool ampm = KGlobal::locale()->use12Clock();
2335 KGlobal::locale()->setDateFormatShort("%A %B %d"); 2342 KGlobal::locale()->setDateFormatShort("%A %B %d");
2336 KGlobal::locale()->setHore24Format(true); 2343 KGlobal::locale()->setHore24Format(true);
2337 2344
2338 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); 2345 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1();
2339 header += KGlobal::locale()->formatTime(currTime, true).latin1(); 2346 header += KGlobal::locale()->formatTime(currTime, true).latin1();
2340 KGlobal::locale()->setDateFormatShort(dfs); 2347 KGlobal::locale()->setDateFormatShort(dfs);
2341 KGlobal::locale()->setHore24Format(!ampm); 2348 KGlobal::locale()->setHore24Format(!ampm);
2342 2349
2343#endif 2350#endif
2344 header += tostr(currDate.year()); 2351 header += tostr(currDate.year());
2345 header += "\n==============================\n\n"; 2352 header += "\n==============================\n\n";
2346 2353
2347 2354
2348#ifndef PWM_EMBEDDED 2355#ifndef PWM_EMBEDDED
2349 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { 2356 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2350 unlockAll_tempoary(true); 2357 unlockAll_tempoary(true);
2351 f.close(); 2358 f.close();
2352 return e_writeFile; 2359 return e_writeFile;
2353 } 2360 }
2354#else 2361#else
2355 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { 2362 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2356 unlockAll_tempoary(true); 2363 unlockAll_tempoary(true);
2357 f.close(); 2364 f.close();
2358 return e_writeFile; 2365 return e_writeFile;
2359 } 2366 }
2360#endif 2367#endif
2361 unsigned int i, numCat = numCategories(); 2368 unsigned int i, numCat = numCategories();
2362 unsigned int j, numEnt; 2369 unsigned int j, numEnt;
2363 string exp; 2370 string exp;
2364 for (i = 0; i < numCat; ++i) { 2371 for (i = 0; i < numCat; ++i) {
2365 numEnt = numEntries(i); 2372 numEnt = numEntries(i);
2366 2373
2367 exp = "\n== Category: "; 2374 exp = "\n== Category: ";
2368 exp += dti.dta[i].name; 2375 exp += dti.dta[i].name;
2369 exp += " ==\n"; 2376 exp += " ==\n";
2370#ifndef PWM_EMBEDDED 2377#ifndef PWM_EMBEDDED
2371 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2378 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2372 unlockAll_tempoary(true); 2379 unlockAll_tempoary(true);
2373 f.close(); 2380 f.close();
2374 return e_writeFile; 2381 return e_writeFile;
2375 } 2382 }
2376#else 2383#else
2377 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2384 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2378 unlockAll_tempoary(true); 2385 unlockAll_tempoary(true);
2379 f.close(); 2386 f.close();
2380 return e_writeFile; 2387 return e_writeFile;
2381 } 2388 }
2382#endif 2389#endif
2383 for (j = 0; j < numEnt; ++j) { 2390 for (j = 0; j < numEnt; ++j) {
2384 exp = "\n-- "; 2391 exp = "\n-- ";
2385 exp += dti.dta[i].d[j].desc; 2392 exp += dti.dta[i].d[j].desc;
2386 exp += " --\n"; 2393 exp += " --\n";
2387 2394
2388 exp += i18n("Username: ").latin1(); 2395 exp += i18n("Username: ").latin1();
2389 exp += dti.dta[i].d[j].name; 2396 exp += dti.dta[i].d[j].name;
2390 exp += "\n"; 2397 exp += "\n";
2391 2398
2392 exp += i18n("Password: ").latin1(); 2399 exp += i18n("Password: ").latin1();
2393 exp += dti.dta[i].d[j].pw; 2400 exp += dti.dta[i].d[j].pw;
2394 exp += "\n"; 2401 exp += "\n";
2395 2402
2396 exp += i18n("Comment: ").latin1(); 2403 exp += i18n("Comment: ").latin1();
2397 exp += dti.dta[i].d[j].comment; 2404 exp += dti.dta[i].d[j].comment;
2398 exp += "\n"; 2405 exp += "\n";
2399 2406
2400 exp += i18n("URL: ").latin1(); 2407 exp += i18n("URL: ").latin1();
2401 exp += dti.dta[i].d[j].url; 2408 exp += dti.dta[i].d[j].url;
2402 exp += "\n"; 2409 exp += "\n";
2403 2410
2404 exp += i18n("Launcher: ").latin1(); 2411 exp += i18n("Launcher: ").latin1();
2405 exp += dti.dta[i].d[j].launcher; 2412 exp += dti.dta[i].d[j].launcher;
2406 exp += "\n"; 2413 exp += "\n";
2407 2414
2408#ifndef PWM_EMBEDDED 2415#ifndef PWM_EMBEDDED
2409 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2416 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2410 unlockAll_tempoary(true); 2417 unlockAll_tempoary(true);
2411 f.close(); 2418 f.close();
2412 return e_writeFile; 2419 return e_writeFile;
2413 } 2420 }
2414#else 2421#else
2415 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2422 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2416 unlockAll_tempoary(true); 2423 unlockAll_tempoary(true);
2417 f.close(); 2424 f.close();
2418 return e_writeFile; 2425 return e_writeFile;
2419 } 2426 }
2420#endif 2427#endif
2421 } 2428 }
2422 } 2429 }
2423 unlockAll_tempoary(true); 2430 unlockAll_tempoary(true);
2424 f.close(); 2431 f.close();
2425 2432
2426 return e_success; 2433 return e_success;
2427} 2434}
2428 2435
2429PwMerror PwMDoc::importFromText(const QString *file, int format) 2436PwMerror PwMDoc::importFromText(const QString *file, int format)
2430{ 2437{
2431 PWM_ASSERT(file); 2438 PWM_ASSERT(file);
2432 if (format == 0) 2439 if (format == 0)
2433 return importText_PwM(file); 2440 return importText_PwM(file);
2434 else if (format == -1) { 2441 else if (format == -1) {
2435 // probe for all formats 2442 // probe for all formats
2436 if (importText_PwM(file) == e_success) 2443 if (importText_PwM(file) == e_success)
2437 return e_success; 2444 return e_success;
2438 dti.clear(); 2445 dti.clear();
2439 emitDataChanged(this); 2446 emitDataChanged(this);
2440 // add next format here... 2447 // add next format here...
2441 return e_fileFormat; 2448 return e_fileFormat;
2442 } 2449 }
2443 return e_invalidArg; 2450 return e_invalidArg;
2444} 2451}
2445 2452
2446PwMerror PwMDoc::importText_PwM(const QString *file) 2453PwMerror PwMDoc::importText_PwM(const QString *file)
2447{ 2454{
2448#ifndef PWM_EMBEDDED 2455#ifndef PWM_EMBEDDED
2449 PWM_ASSERT(file); 2456 PWM_ASSERT(file);
2450 FILE *f; 2457 FILE *f;
2451 int tmp; 2458 int tmp;
2452 ssize_t ret; 2459 ssize_t ret;
2453 string curCat; 2460 string curCat;
2454 unsigned int entriesRead = 0; 2461 unsigned int entriesRead = 0;
2455 PwMDataItem currItem; 2462 PwMDataItem currItem;
2456 f = fopen(file->latin1(), "r"); 2463 f = fopen(file->latin1(), "r");
2457 if (!f) 2464 if (!f)
2458 return e_openFile; 2465 return e_openFile;
2459 size_t ch_tmp_size = 1024; 2466 size_t ch_tmp_size = 1024;
2460 char *ch_tmp = (char*)malloc(ch_tmp_size); 2467 char *ch_tmp = (char*)malloc(ch_tmp_size);
2461 if (!ch_tmp) { 2468 if (!ch_tmp) {
2462 fclose(f); 2469 fclose(f);
2463 return e_outOfMem; 2470 return e_outOfMem;
2464 } 2471 }
2465 2472
2466 // - check header 2473 // - check header
2467 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. 2474 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2468 goto formatError; 2475 goto formatError;
2469 // check version-string and return version in "ch_tmp". 2476 // check version-string and return version in "ch_tmp".
2470 if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2477 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2471 // header not recognized as PwM generated header 2478 // header not recognized as PwM generated header
2472 goto formatError; 2479 goto formatError;
2473 } 2480 }
2474 // set filepointer behind version-string-line previously checked 2481 // set filepointer behind version-string-line previously checked
2475 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2482 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2476 goto formatError; 2483 goto formatError;
2477 // skip next line containing the build-date 2484 // skip next line containing the build-date
2478 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2485 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2479 goto formatError; 2486 goto formatError;
2480 // read header termination line 2487 // read header termination line
2481 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2488 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2482 goto formatError; 2489 goto formatError;
2483 if (strcmp(ch_tmp, "==============================\n")) 2490 if (strcmp(ch_tmp, "==============================\n"))
2484 goto formatError; 2491 goto formatError;
2485 2492
2486 // - read entries 2493 // - read entries
2487 do { 2494 do {
2488 // find beginning of next category 2495 // find beginning of next category
2489 do { 2496 do {
2490 tmp = fgetc(f); 2497 tmp = fgetc(f);
2491 } while (tmp == '\n' && tmp != EOF); 2498 } while (tmp == '\n' && tmp != EOF);
2492 if (tmp == EOF) 2499 if (tmp == EOF)
2493 break; 2500 break;
2494 2501
2495 // decrement filepos by one 2502 // decrement filepos by one
2496 fseek(f, -1, SEEK_CUR); 2503 fseek(f, -1, SEEK_CUR);
2497 // read cat-name 2504 // read cat-name
2498 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2505 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2499 goto formatError; 2506 goto formatError;
2500 // check cat-name format 2507 // check cat-name format
2501 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2508 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2502 goto formatError; 2509 goto formatError;
2503 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2510 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2504 goto formatError; 2511 goto formatError;
2505 // copy cat-name 2512 // copy cat-name
2506 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2513 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2507 2514
2508 do { 2515 do {
2509 // find beginning of next entry 2516 // find beginning of next entry
2510 do { 2517 do {
2511 tmp = fgetc(f); 2518 tmp = fgetc(f);
2512 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2519 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2513 if (tmp == EOF) 2520 if (tmp == EOF)
2514 break; 2521 break;
2515 if (tmp == '=') { 2522 if (tmp == '=') {
2516 fseek(f, -1, SEEK_CUR); 2523 fseek(f, -1, SEEK_CUR);
2517 break; 2524 break;
2518 } 2525 }
2519 // decrement filepos by one 2526 // decrement filepos by one
2520 fseek(f, -1, SEEK_CUR); 2527 fseek(f, -1, SEEK_CUR);
2521 // read desc-line 2528 // read desc-line
2522 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2529 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2523 goto formatError; 2530 goto formatError;
2524 // check desc-line format 2531 // check desc-line format
2525 if (memcmp(ch_tmp, "-- ", 3) != 0) 2532 if (memcmp(ch_tmp, "-- ", 3) != 0)
2526 goto formatError; 2533 goto formatError;
2527 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2534 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2528 goto formatError; 2535 goto formatError;
2529 // add desc-line 2536 // add desc-line
2530 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2537 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2531 2538
2532 // read username-line 2539 // read username-line
2533 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2540 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2534 goto formatError; 2541 goto formatError;
2535 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2542 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2536 goto formatError; 2543 goto formatError;
2537 2544
2538 // read pw-line 2545 // read pw-line
2539 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2546 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2540 goto formatError; 2547 goto formatError;
2541 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2548 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2542 goto formatError; 2549 goto formatError;
2543 2550
2544 // read comment-line 2551 // read comment-line
2545 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2552 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2546 goto formatError; 2553 goto formatError;
2547 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2554 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2548 goto formatError; 2555 goto formatError;
2549 2556
2550 // read URL-line 2557 // read URL-line
2551 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2558 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2552 goto formatError; 2559 goto formatError;
2553 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2560 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2554 goto formatError; 2561 goto formatError;
2555 2562
2556 // read launcher-line 2563 // read launcher-line
2557 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2564 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2558 goto formatError; 2565 goto formatError;
2559 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2566 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2560 goto formatError; 2567 goto formatError;
2561 2568
2562 currItem.lockStat = true; 2569 currItem.lockStat = true;
2563 currItem.listViewPos = -1; 2570 currItem.listViewPos = -1;
2564 addEntry(curCat.c_str(), &currItem, true); 2571 addEntry(curCat.c_str(), &currItem, true);
2565 ++entriesRead; 2572 ++entriesRead;
2566 } while (1); 2573 } while (1);
2567 } while (1); 2574 } while (1);
2568 if (!entriesRead) 2575 if (!entriesRead)
2569 goto formatError; 2576 goto formatError;
2570 2577
2571 free(ch_tmp); 2578 free(ch_tmp);
2572 fclose(f); 2579 fclose(f);
2573 flagDirty(); 2580 flagDirty();
2574 return e_success; 2581 return e_success;
2575 2582
2576 formatError: 2583 formatError:
2577 free(ch_tmp); 2584 free(ch_tmp);
2578 fclose(f); 2585 fclose(f);
2579 return e_fileFormat; 2586 return e_fileFormat;
2580#else 2587#else
2581 PWM_ASSERT(file); 2588 PWM_ASSERT(file);
2582 QFile f(file->latin1()); 2589 QFile f(file->latin1());
2583 int tmp; 2590 int tmp;
2584 ssize_t ret; 2591 ssize_t ret;
2585 string curCat; 2592 string curCat;
2586 unsigned int entriesRead = 0; 2593 unsigned int entriesRead = 0;
2587 PwMDataItem currItem; 2594 PwMDataItem currItem;
2588 bool res = f.open(IO_ReadOnly); 2595 bool res = f.open(IO_ReadOnly);
2589 if (res == false) 2596 if (res == false)
2590 return e_openFile; 2597 return e_openFile;
2591 2598
2592 unsigned int ch_tmp_size = 1024; 2599 unsigned int ch_tmp_size = 1024;
2593 char *ch_tmp = (char*)malloc(ch_tmp_size); 2600 char *ch_tmp = (char*)malloc(ch_tmp_size);
2594 if (!ch_tmp) { 2601 if (!ch_tmp) {
2595 f.close(); 2602 f.close();
2596 return e_outOfMem; 2603 return e_outOfMem;
2597 } 2604 }
2598 2605
2599 // - check header 2606 // - check header
2600 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2607 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2601 goto formatError; 2608 goto formatError;
2602 2609
2603 //US read fileversion first, then check if ok. 2610 //US read fileversion first, then check if ok.
2604 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2611 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2605 goto formatError; 2612 goto formatError;
2606 2613
2607 // check version-string and return version in "ch_tmp". 2614 // check version-string and return version in "ch_tmp".
2608 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2615 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2609 //US // header not recognized as PwM generated header 2616 //US // header not recognized as PwM generated header
2610 //US goto formatError; 2617 //US goto formatError;
2611 //US} 2618 //US}
2612 //US set filepointer behind version-string-line previously checked 2619 //US set filepointer behind version-string-line previously checked
2613 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2620 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2614 //US goto formatError; 2621 //US goto formatError;
2615 // skip next line containing the build-date 2622 // skip next line containing the build-date
2616 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2623 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2617 goto formatError; 2624 goto formatError;
2618 // read header termination line 2625 // read header termination line
2619 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2626 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2620 goto formatError; 2627 goto formatError;
2621 if (strcmp(ch_tmp, "==============================\n")) 2628 if (strcmp(ch_tmp, "==============================\n"))
2622 goto formatError; 2629 goto formatError;
2623 2630
2624 // - read entries 2631 // - read entries
2625 do { 2632 do {
2626 // find beginning of next category 2633 // find beginning of next category
2627 do { 2634 do {
2628 tmp = f.getch(); 2635 tmp = f.getch();
2629 } while (tmp == '\n' && tmp != EOF); 2636 } while (tmp == '\n' && tmp != EOF);
2630 if (tmp == EOF) 2637 if (tmp == EOF)
2631 break; 2638 break;
2632 2639
2633 // decrement filepos by one 2640 // decrement filepos by one
2634 f.at(f.at()-1); 2641 f.at(f.at()-1);
2635 // read cat-name 2642 // read cat-name
2636 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2643 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2637 goto formatError; 2644 goto formatError;
2638 // check cat-name format 2645 // check cat-name format
2639 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2646 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2640 goto formatError; 2647 goto formatError;
2641 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2648 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2642 goto formatError; 2649 goto formatError;
2643 // copy cat-name 2650 // copy cat-name
2644 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2651 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2645 2652
2646 do { 2653 do {
2647 // find beginning of next entry 2654 // find beginning of next entry
2648 do { 2655 do {
2649 tmp = f.getch(); 2656 tmp = f.getch();
2650 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2657 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2651 if (tmp == EOF) 2658 if (tmp == EOF)
2652 break; 2659 break;
2653 if (tmp == '=') { 2660 if (tmp == '=') {
2654 f.at(f.at()-1); 2661 f.at(f.at()-1);
2655 break; 2662 break;
2656 } 2663 }
2657 // decrement filepos by one 2664 // decrement filepos by one
2658 f.at(f.at()-1); 2665 f.at(f.at()-1);
2659 // read desc-line 2666 // read desc-line
2660 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2667 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2661 goto formatError; 2668 goto formatError;
2662 // check desc-line format 2669 // check desc-line format
2663 if (memcmp(ch_tmp, "-- ", 3) != 0) 2670 if (memcmp(ch_tmp, "-- ", 3) != 0)
2664 goto formatError; 2671 goto formatError;
2665 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2672 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2666 goto formatError; 2673 goto formatError;
2667 // add desc-line 2674 // add desc-line
2668 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2675 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2669 2676
2670 // read username-line 2677 // read username-line
2671 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2678 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2672 goto formatError; 2679 goto formatError;
2673 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2680 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2674 goto formatError; 2681 goto formatError;
2675 2682
2676 // read pw-line 2683 // read pw-line
2677 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2684 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2678 goto formatError; 2685 goto formatError;
2679 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2686 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2680 goto formatError; 2687 goto formatError;
2681 2688
2682 // read comment-line 2689 // read comment-line
2683 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2690 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2684 goto formatError; 2691 goto formatError;
2685 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2692 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2686 goto formatError; 2693 goto formatError;
2687 2694
2688 // read URL-line 2695 // read URL-line
2689 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2696 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2690 goto formatError; 2697 goto formatError;
2691 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2698 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2692 goto formatError; 2699 goto formatError;
2693 2700
2694 // read launcher-line 2701 // read launcher-line
2695 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2702 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2696 goto formatError; 2703 goto formatError;
2697 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2704 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2698 goto formatError; 2705 goto formatError;
2699 2706
2700 currItem.lockStat = true; 2707 currItem.lockStat = true;
2701 currItem.listViewPos = -1; 2708 currItem.listViewPos = -1;
2702 addEntry(curCat.c_str(), &currItem, true); 2709 addEntry(curCat.c_str(), &currItem, true);
2703 ++entriesRead; 2710 ++entriesRead;
2704 } while (1); 2711 } while (1);
2705 } while (1); 2712 } while (1);
2706 if (!entriesRead) 2713 if (!entriesRead)
2707 goto formatError; 2714 goto formatError;
2708 2715
2709 free(ch_tmp); 2716 free(ch_tmp);
2710 f.close(); 2717 f.close();
2711 flagDirty(); 2718 flagDirty();
2712 return e_success; 2719 return e_success;
2713 2720
2714 formatError: 2721 formatError:
2715 free(ch_tmp); 2722 free(ch_tmp);
2716 f.close(); 2723 f.close();
2717 return e_fileFormat; 2724 return e_fileFormat;
2718 2725
2719#endif 2726#endif
2720 2727
2721} 2728}
2722 2729
2723bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2730bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2724{ 2731{
2725 PWM_ASSERT(in && out); 2732 PWM_ASSERT(in && out);
2726 ssize_t i = 0, len = in_size - 1; 2733 ssize_t i = 0, len = in_size - 1;
2727 while (i < len) { 2734 while (i < len) {
2728 if (in[i] == ':') 2735 if (in[i] == ':')
2729 break; 2736 break;
2730 ++i; 2737 ++i;
2731 } 2738 }
2732 i += 2; 2739 i += 2;
2733 *out = ""; 2740 *out = "";
2734 out->append(in + i, in_size - i - 1); 2741 out->append(in + i, in_size - i - 1);
2735 return true; 2742 return true;
2736} 2743}
2737 2744
2738PwMerror PwMDoc::exportToGpasman(const QString *file) 2745PwMerror PwMDoc::exportToGpasman(const QString *file)
2739{ 2746{
2740 PWM_ASSERT(file); 2747 PWM_ASSERT(file);
2741 GpasmanFile gp; 2748 GpasmanFile gp;
2742 int ret; 2749 int ret;
2743 2750
2744 if (!unlockAll_tempoary()) 2751 if (!unlockAll_tempoary())
2745 return e_lock; 2752 return e_lock;
2746 2753
2747 QString gpmPassword; 2754 QString gpmPassword;
2748 while (1) { 2755 while (1) {
2749 gpmPassword = requestNewMpw(0); 2756 gpmPassword = requestNewMpw(0);
2750 if (gpmPassword == "") { 2757 if (gpmPassword == "") {
2751 unlockAll_tempoary(true); 2758 unlockAll_tempoary(true);
2752 return e_noPw; 2759 return e_noPw;
2753 } 2760 }
2754 if (gpmPassword.length() < 4) { 2761 if (gpmPassword.length() < 4) {
2755 gpmPwLenErrMsgBox(); 2762 gpmPwLenErrMsgBox();
2756 } else { 2763 } else {
2757 break; 2764 break;
2758 } 2765 }
2759 } 2766 }
2760 2767
2761 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2768 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2762 if (ret != 1) { 2769 if (ret != 1) {
2763 unlockAll_tempoary(true); 2770 unlockAll_tempoary(true);
2764 return e_accessFile; 2771 return e_accessFile;
2765 } 2772 }
2766 2773
2767 char *entry[4]; 2774 char *entry[4];
2768 unsigned int numCat = numCategories(), i; 2775 unsigned int numCat = numCategories(), i;
2769 unsigned int numEntr, j; 2776 unsigned int numEntr, j;
2770 int descLen, nameLen, pwLen, commentLen; 2777 int descLen, nameLen, pwLen, commentLen;
2771 for (i = 0; i < numCat; ++i) { 2778 for (i = 0; i < numCat; ++i) {
2772 numEntr = numEntries(i); 2779 numEntr = numEntries(i);
2773 for (j = 0; j < numEntr; ++j) { 2780 for (j = 0; j < numEntr; ++j) {
2774 descLen = dti.dta[i].d[j].desc.length(); 2781 descLen = dti.dta[i].d[j].desc.length();
2775 nameLen = dti.dta[i].d[j].name.length(); 2782 nameLen = dti.dta[i].d[j].name.length();
2776 pwLen = dti.dta[i].d[j].pw.length(); 2783 pwLen = dti.dta[i].d[j].pw.length();
2777 commentLen = dti.dta[i].d[j].comment.length(); 2784 commentLen = dti.dta[i].d[j].comment.length();
2778 entry[0] = new char[descLen + 1]; 2785 entry[0] = new char[descLen + 1];
2779 entry[1] = new char[nameLen + 1]; 2786 entry[1] = new char[nameLen + 1];
2780 entry[2] = new char[pwLen + 1]; 2787 entry[2] = new char[pwLen + 1];
2781 entry[3] = new char[commentLen + 1]; 2788 entry[3] = new char[commentLen + 1];
2782 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2789 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2783 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2790 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2784 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2791 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2785 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2792 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2786 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2793 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2787 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2794 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2788 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2795 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2789 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2796 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2790 2797
2791 ret = gp.save_entry(entry); 2798 ret = gp.save_entry(entry);
2792 if (ret == -1){ 2799 if (ret == -1){
2793 delete [] entry[0]; 2800 delete [] entry[0];
2794 delete [] entry[1]; 2801 delete [] entry[1];
2795 delete [] entry[2]; 2802 delete [] entry[2];
2796 delete [] entry[3]; 2803 delete [] entry[3];
2797 gp.save_finalize(); 2804 gp.save_finalize();
2798 unlockAll_tempoary(true); 2805 unlockAll_tempoary(true);
2799 return e_writeFile; 2806 return e_writeFile;
2800 } 2807 }
2801 2808
2802 delete [] entry[0]; 2809 delete [] entry[0];
2803 delete [] entry[1]; 2810 delete [] entry[1];
2804 delete [] entry[2]; 2811 delete [] entry[2];
2805 delete [] entry[3]; 2812 delete [] entry[3];
2806 } 2813 }
2807 } 2814 }
2808 unlockAll_tempoary(true); 2815 unlockAll_tempoary(true);
2809 if (gp.save_finalize() == -1) 2816 if (gp.save_finalize() == -1)
2810 return e_writeFile; 2817 return e_writeFile;
2811 2818
2812 return e_success; 2819 return e_success;
2813} 2820}
2814 2821
2815PwMerror PwMDoc::importFromGpasman(const QString *file) 2822PwMerror PwMDoc::importFromGpasman(const QString *file)
2816{ 2823{
2817 PWM_ASSERT(file); 2824 PWM_ASSERT(file);
2818 QString pw = requestMpw(false); 2825 QString pw = requestMpw(false);
2819 if (pw == "") 2826 if (pw == "")
2820 return e_noPw; 2827 return e_noPw;
2821 GpasmanFile gp; 2828 GpasmanFile gp;
2822 int ret, i; 2829 int ret, i;
2823 PwMerror ret2; 2830 PwMerror ret2;
2824 char *entry[4]; 2831 char *entry[4];
2825 PwMDataItem tmpData; 2832 PwMDataItem tmpData;
2826 ret = gp.load_init(file->latin1(), pw.latin1()); 2833 ret = gp.load_init(file->latin1(), pw.latin1());
2827 if (ret != 1) 2834 if (ret != 1)
2828 return e_accessFile; 2835 return e_accessFile;
2829 2836
2830 do { 2837 do {
2831 ret = gp.load_entry(entry); 2838 ret = gp.load_entry(entry);
2832 if(ret != 1) 2839 if(ret != 1)
2833 break; 2840 break;
2834 tmpData.desc = entry[0]; 2841 tmpData.desc = entry[0];
2835 tmpData.name = entry[1]; 2842 tmpData.name = entry[1];
2836 tmpData.pw = entry[2]; 2843 tmpData.pw = entry[2];
2837 tmpData.comment = entry[3]; 2844 tmpData.comment = entry[3];
2838 tmpData.lockStat = true; 2845 tmpData.lockStat = true;
2839 tmpData.listViewPos = -1; 2846 tmpData.listViewPos = -1;
2840 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2841 for (i = 0; i < 4; ++i) 2848 for (i = 0; i < 4; ++i)
2842 free(entry[i]); 2849 free(entry[i]);
2843 if (ret2 == e_maxAllowedEntr) { 2850 if (ret2 == e_maxAllowedEntr) {
2844 gp.load_finalize(); 2851 gp.load_finalize();
2845 return e_maxAllowedEntr; 2852 return e_maxAllowedEntr;
2846 } 2853 }
2847 } while (1); 2854 } while (1);
2848 gp.load_finalize(); 2855 gp.load_finalize();
2849 if (isDocEmpty()) 2856 if (isDocEmpty())
2850 return e_wrongPw; // we assume this. 2857 return e_wrongPw; // we assume this.
2851 2858
2852 flagDirty(); 2859 flagDirty();
2853 return e_success; 2860 return e_success;
2854} 2861}
2855 2862
2856 2863
2857//US: we use the stl sort algorythm to sort all elements in the order 2864//US: we use the stl sort algorythm to sort all elements in the order
2858//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2859struct PwMDataItemListViewPosSort 2866struct PwMDataItemListViewPosSort
2860{ 2867{
2861 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2862 { 2869 {
2863 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2864 if ((rpEnd)->listViewPos < 0) 2871 if ((rpEnd)->listViewPos < 0)
2865 return false; 2872 return false;
2866 else 2873 else
2867 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2868 } 2875 }
2869}; 2876};
2870 2877
2871void PwMDoc::ensureLvp() 2878void PwMDoc::ensureLvp()
2872{ 2879{
2873 if (isDocEmpty()) 2880 if (isDocEmpty())
2874 return; 2881 return;
2875 2882
2876 //US ENH BUG: when using syncronizing, this way of sorting 2883 //US ENH BUG: when using syncronizing, this way of sorting
2877 //is not sufficient, because there might be empty spaces 2884 //is not sufficient, because there might be empty spaces
2878 // at the beginning. But the old algorythm only can add elements 2885 // at the beginning. But the old algorythm only can add elements
2879 //to the end.The result are crashes because of list overflows 2886 //to the end.The result are crashes because of list overflows
2880 //we need something to fill all gaps. 2887 //we need something to fill all gaps.
2881 vector<PwMDataItem*> sorted; 2888 vector<PwMDataItem*> sorted;
2882 vector< PwMDataItem*>::iterator sortedBegin, 2889 vector< PwMDataItem*>::iterator sortedBegin,
2883 sortedEnd, 2890 sortedEnd,
2884 sortedI; 2891 sortedI;
2885 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2886 catEnd = dti.dta.end(), 2893 catEnd = dti.dta.end(),
2887 catI = catBegin; 2894 catI = catBegin;
2888 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2889 int lvpTop, tmpLvp; 2896 int lvpTop, tmpLvp;
2890 2897
2891 //qDebug("collect:"); 2898 //qDebug("collect:");
2892 2899
2893 while (catI != catEnd) { 2900 while (catI != catEnd) {
2894 lvpTop = -1; 2901 lvpTop = -1;
2895 sorted.clear(); 2902 sorted.clear();
2896 2903
2897 entrBegin = catI->d.begin(); 2904 entrBegin = catI->d.begin();
2898 entrEnd = catI->d.end(); 2905 entrEnd = catI->d.end();
2899 entrI = entrBegin; 2906 entrI = entrBegin;
2900 2907
2901 //US: we use the stl sort algorythm to sort all elements in the order 2908 //US: we use the stl sort algorythm to sort all elements in the order
2902 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2903 while (entrI != entrEnd) { 2910 while (entrI != entrEnd) {
2904 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2905 sorted.push_back((PwMDataItem*)&(*entrI)); 2912 sorted.push_back((PwMDataItem*)&(*entrI));
2906 ++entrI; 2913 ++entrI;
2907 } 2914 }
2908 2915
2909 sortedBegin = sorted.begin(); 2916 sortedBegin = sorted.begin();
2910 sortedEnd = sorted.end(); 2917 sortedEnd = sorted.end();
2911 2918
2912 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2913 2920
2914 // qDebug("resort:"); 2921 // qDebug("resort:");
2915 //now we have all sorted in a collection 2922 //now we have all sorted in a collection
2916 //Now start with the sorted and reset listviewpos. 2923 //Now start with the sorted and reset listviewpos.
2917 sortedBegin = sorted.begin(); 2924 sortedBegin = sorted.begin();
2918 sortedEnd = sorted.end(); 2925 sortedEnd = sorted.end();
2919 sortedI = sortedBegin; 2926 sortedI = sortedBegin;
2920 2927
2921 while (sortedI != sortedEnd) { 2928 while (sortedI != sortedEnd) {
2922 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2923 (*sortedI)->listViewPos = ++lvpTop; 2930 (*sortedI)->listViewPos = ++lvpTop;
2924 ++sortedI; 2931 ++sortedI;
2925 } 2932 }
2926 2933
2927 /*/debug 2934 /*/debug
2928 entrBegin = catI->d.begin(); 2935 entrBegin = catI->d.begin();
2929 entrEnd = catI->d.end(); 2936 entrEnd = catI->d.end();
2930 entrI = entrBegin; 2937 entrI = entrBegin;
2931 2938
2932 while (entrI != entrEnd) { 2939 while (entrI != entrEnd) {
2933 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2934 ++entrI; 2941 ++entrI;
2935 } 2942 }
2936 */ 2943 */
2937 2944
2938 ++catI; 2945 ++catI;
2939 } 2946 }
2940} 2947}
2941 2948
2942QString PwMDoc::getTitle() 2949QString PwMDoc::getTitle()
2943{ 2950{
2944 /* NOTE: We have to ensure, that the returned title 2951 /* NOTE: We have to ensure, that the returned title
2945 * is unique and not reused somewhere else while 2952 * is unique and not reused somewhere else while
2946 * this document is valid (open). 2953 * this document is valid (open).
2947 */ 2954 */
2948 QString title(getFilename()); 2955 QString title(getFilename());
2949 2956
2950 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2951 if (QApplication::desktop()->width() < 640) 2958 if (QApplication::desktop()->width() < 640)
2952 { 2959 {
2953 if (title.length() > 30) 2960 if (title.length() > 30)
2954 title = "..." + title.right(30); 2961 title = "..." + title.right(30);
2955 2962
2956 } 2963 }
2957 2964
2958 2965
2959 if (title.isEmpty()) { 2966 if (title.isEmpty()) {
2960 if (unnamedNum == 0) { 2967 if (unnamedNum == 0) {
2961 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2968 unnamedNum = PwMDocList::getNewUnnamedNumber();
2962 PWM_ASSERT(unnamedNum != 0); 2969 PWM_ASSERT(unnamedNum != 0);
2963 } 2970 }
2964 title = DEFAULT_TITLE; 2971 title = DEFAULT_TITLE;
2965 title += " "; 2972 title += " ";
2966 title += tostr(unnamedNum).c_str(); 2973 title += tostr(unnamedNum).c_str();
2967 } 2974 }
2968 return title; 2975 return title;
2969} 2976}
2970 2977
2971bool PwMDoc::tryDelete() 2978bool PwMDoc::tryDelete()
2972{ 2979{
2973 if (deleted) 2980 if (deleted)
2974 return true; 2981 return true;
2975 int ret; 2982 int ret;
2976 if (isDirty()) { 2983 if (isDirty()) {
2977 ret = dirtyAskSave(getTitle()); 2984 ret = dirtyAskSave(getTitle());
2978 if (ret == 0) { // save to disk 2985 if (ret == 0) { // save to disk
2979 if (!saveDocUi(this)) 2986 if (!saveDocUi(this))
2980 goto out_ignore; 2987 goto out_ignore;
2981 } else if (ret == 1) { // don't save and delete 2988 } else if (ret == 1) { // don't save and delete
2982 goto out_accept; 2989 goto out_accept;
2983 } else { // cancel operation 2990 } else { // cancel operation
2984 goto out_ignore; 2991 goto out_ignore;
2985 } 2992 }
2986 } 2993 }
2987out_accept: 2994out_accept:
2988 deleted = true; 2995 deleted = true;
2989 delete this; 2996 delete this;
2990 return true; 2997 return true;
2991out_ignore: 2998out_ignore:
2992 return false; 2999 return false;
2993} 3000}
2994 3001
2995 3002
2996 3003
2997#ifdef PWM_EMBEDDED 3004#ifdef PWM_EMBEDDED
2998//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3005//US ENH: this is the magic function that syncronizes the this doc with the remote doc
2999//US it could have been defined as static, but I did not want to. 3006//US it could have been defined as static, but I did not want to.
3000PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3007PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3001{ 3008{
3002 int addedPasswordsLocal = 0; 3009 int addedPasswordsLocal = 0;
3003 int addedPasswordsRemote = 0; 3010 int addedPasswordsRemote = 0;
3004 int deletedPasswordsRemote = 0; 3011 int deletedPasswordsRemote = 0;
3005 int deletedPasswordsLocal = 0; 3012 int deletedPasswordsLocal = 0;
3006 int changedLocal = 0; 3013 int changedLocal = 0;
3007 int changedRemote = 0; 3014 int changedRemote = 0;
3008 3015
3009 PwMSyncItem* syncItemLocal; 3016 PwMSyncItem* syncItemLocal;
3010 PwMSyncItem* syncItemRemote; 3017 PwMSyncItem* syncItemRemote;
3011 3018
3012 QString mCurrentSyncName = manager->getCurrentSyncName(); 3019 QString mCurrentSyncName = manager->getCurrentSyncName();
3013 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3020 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3014 3021
3015 bool fullDateRange = false; 3022 bool fullDateRange = false;
3016 int take; 3023 int take;
3017 // local->resetTempSyncStat(); 3024 // local->resetTempSyncStat();
3018 QDateTime mLastSync = QDateTime::currentDateTime(); 3025 QDateTime mLastSync = QDateTime::currentDateTime();
3019 QDateTime modifiedSync = mLastSync; 3026 QDateTime modifiedSync = mLastSync;
3020 3027
3021 unsigned int index; 3028 unsigned int index;
3022 //Step 1. Find syncinfo in Local file and create if not existent. 3029 //Step 1. Find syncinfo in Local file and create if not existent.
3023 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3030 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3024 if (found == false) 3031 if (found == false)
3025 { 3032 {
3026 PwMSyncItem newSyncItemLocal; 3033 PwMSyncItem newSyncItemLocal;
3027 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3034 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3028 newSyncItemLocal.lastSyncDate = mLastSync; 3035 newSyncItemLocal.lastSyncDate = mLastSync;
3029 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3036 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3030 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3037 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3031 if (found == false) { 3038 if (found == false) {
3032 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3039 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3033 return e_syncError; 3040 return e_syncError;
3034 } 3041 }
3035 } 3042 }
3036 3043
3037 syncItemLocal = syncLocal->getSyncDataEntry(index); 3044 syncItemLocal = syncLocal->getSyncDataEntry(index);
3038 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3045 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3039 3046
3040 //Step 2. Find syncinfo in remote file and create if not existent. 3047 //Step 2. Find syncinfo in remote file and create if not existent.
3041 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3048 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3042 if (found == false) 3049 if (found == false)
3043 { 3050 {
3044 qDebug("FULLDATE 1"); 3051 qDebug("FULLDATE 1");
diff --git a/pwmanager/pwmanager/spinforsignal.h b/pwmanager/pwmanager/spinforsignal.h
index ec6103b..f3cabee 100644
--- a/pwmanager/pwmanager/spinforsignal.h
+++ b/pwmanager/pwmanager/spinforsignal.h
@@ -1,55 +1,57 @@
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.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef SPINFORSIGNAL_H 20#ifndef SPINFORSIGNAL_H
21#define SPINFORSIGNAL_H 21#define SPINFORSIGNAL_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24 24
25#ifndef _WIN32_
25#include <stdint.h> 26#include <stdint.h>
27#endif
26#include <string> 28#include <string>
27using std::string; 29using std::string;
28 30
29/** non-ui-blocking spin for a QT-signal */ 31/** non-ui-blocking spin for a QT-signal */
30class SpinForSignal : public QObject 32class SpinForSignal : public QObject
31{ 33{
32 Q_OBJECT 34 Q_OBJECT
33public: 35public:
34 SpinForSignal(); 36 SpinForSignal();
35 ~SpinForSignal() {} 37 ~SpinForSignal() {}
36 38
37 /** do spin for signal */ 39 /** do spin for signal */
38 void spin(uint32_t *u32, string *str); 40 void spin(uint32_t *u32, string *str);
39 /** cancel spinning */ 41 /** cancel spinning */
40 void cancelSpin(); 42 void cancelSpin();
41 43
42public slots: 44public slots:
43 void u32_str_slot(uint32_t u32, const string &str); 45 void u32_str_slot(uint32_t u32, const string &str);
44 46
45protected: 47protected:
46 volatile bool doSpin; 48 volatile bool doSpin;
47 uint32_t u32_storage; 49 uint32_t u32_storage;
48 string str_storage; 50 string str_storage;
49 51
50protected: 52protected:
51 inline void spinSleep(); 53 inline void spinSleep();
52 void _spin(); 54 void _spin();
53}; 55};
54 56
55#endif 57#endif