author | ulf69 <ulf69> | 2004-10-15 05:30:12 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-15 05:30:12 (UTC) |
commit | c2fb960297c4b08980921c818a4d347057732390 (patch) (unidiff) | |
tree | b96dba18fa1af192eeb4bd2da0b2dc1805cf3c96 | |
parent | 6b6545368e5a5746c6fec02bb8d0708333f894e0 (diff) | |
download | kdepimpi-c2fb960297c4b08980921c818a4d347057732390.zip kdepimpi-c2fb960297c4b08980921c818a4d347057732390.tar.gz kdepimpi-c2fb960297c4b08980921c818a4d347057732390.tar.bz2 |
replaced system calls that do nto comply with gcc2.95
-rw-r--r-- | pwmanager/pwmanager/globalstuff.h | 27 | ||||
-rw-r--r-- | pwmanager/pwmanager/ipc.cpp | 80 | ||||
-rw-r--r-- | pwmanager/pwmanager/ipc.h | 26 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 142 |
4 files changed, 259 insertions, 16 deletions
diff --git a/pwmanager/pwmanager/globalstuff.h b/pwmanager/pwmanager/globalstuff.h index 7bc4173..428ce95 100644 --- a/pwmanager/pwmanager/globalstuff.h +++ b/pwmanager/pwmanager/globalstuff.h | |||
@@ -1,113 +1,134 @@ | |||
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 __GLOBALSTUFF_H | 20 | #ifndef __GLOBALSTUFF_H |
21 | #define __GLOBALSTUFF_H | 21 | #define __GLOBALSTUFF_H |
22 | 22 | ||
23 | #ifndef PWM_EMBEDDED | 23 | #ifndef PWM_EMBEDDED |
24 | #include "config.h" | 24 | #include "config.h" |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #include "compiler.h" | 27 | #include "compiler.h" |
28 | 28 | ||
29 | //US BUG: the following code caused compile errors with certain gcccompilers (2.95). | ||
30 | // Because of that I replaced it with a Qt version, which should do the same. | ||
29 | #include <string> | 31 | #include <string> |
32 | |||
33 | #ifndef PWM_EMBEDDED | ||
30 | #include <sstream> | 34 | #include <sstream> |
35 | #else | ||
36 | #include <qstring.h> | ||
37 | #include <qtextstream.h> | ||
38 | #endif | ||
31 | 39 | ||
32 | #ifndef CONFIG_KEYCARD | 40 | #ifndef CONFIG_KEYCARD |
33 | class QWidget; | 41 | class QWidget; |
34 | void no_keycard_support_msg_box(QWidget *parentWidget); | 42 | void no_keycard_support_msg_box(QWidget *parentWidget); |
35 | #endif // CONFIG_KEYCARD | 43 | #endif // CONFIG_KEYCARD |
36 | 44 | ||
37 | #ifdef PROG_NAME | 45 | #ifdef PROG_NAME |
38 | # undef PROG_NAME | 46 | # undef PROG_NAME |
39 | #endif | 47 | #endif |
40 | #define PROG_NAME"PwManager" | 48 | #define PROG_NAME"PwManager" |
41 | 49 | ||
42 | #ifdef PACKAGE_NAME | 50 | #ifdef PACKAGE_NAME |
43 | # undef PACKAGE_NAME | 51 | # undef PACKAGE_NAME |
44 | #endif | 52 | #endif |
45 | #define PACKAGE_NAME"pwmanager" | 53 | #define PACKAGE_NAME"pwmanager" |
46 | 54 | ||
47 | #ifdef PACKAGE_VER | 55 | #ifdef PACKAGE_VER |
48 | # undef PACKAGE_VER | 56 | # undef PACKAGE_VER |
49 | #endif | 57 | #endif |
50 | #define PACKAGE_VER"1.0.1" | 58 | #define PACKAGE_VER"1.0.1" |
51 | 59 | ||
52 | #ifdef CONFIG_DEBUG | 60 | #ifdef CONFIG_DEBUG |
53 | # define PWM_DEBUG | 61 | # define PWM_DEBUG |
54 | #else | 62 | #else |
55 | # undef PWM_DEBUG | 63 | # undef PWM_DEBUG |
56 | #endif | 64 | #endif |
57 | 65 | ||
58 | #ifdef QT_MAKE_VERSION | 66 | #ifdef QT_MAKE_VERSION |
59 | # undef QT_MAKE_VERSION | 67 | # undef QT_MAKE_VERSION |
60 | #endif | 68 | #endif |
61 | #define QT_MAKE_VERSION(a,b,c)(((a) << 16) | ((b) << 8) | (c)) | 69 | #define QT_MAKE_VERSION(a,b,c)(((a) << 16) | ((b) << 8) | (c)) |
62 | 70 | ||
63 | /** remove "unused parameter" warnings */ | 71 | /** remove "unused parameter" warnings */ |
64 | #ifdef PARAM_UNUSED | 72 | #ifdef PARAM_UNUSED |
65 | # undef PARAM_UNUSED | 73 | # undef PARAM_UNUSED |
66 | #endif | 74 | #endif |
67 | #define PARAM_UNUSED(x)(void)x | 75 | #define PARAM_UNUSED(x)(void)x |
68 | 76 | ||
69 | /** return the number of elements in an array */ | 77 | /** return the number of elements in an array */ |
70 | #ifdef array_size | 78 | #ifdef array_size |
71 | # undef array_size | 79 | # undef array_size |
72 | #endif | 80 | #endif |
73 | #define array_size(x)(sizeof(x) / sizeof((x)[0])) | 81 | #define array_size(x)(sizeof(x) / sizeof((x)[0])) |
74 | 82 | ||
83 | //US BUG: the following code caused compile errors with certain gcccompilers (2.95). | ||
84 | // Because of that I replaced it with a Qt version, which should do the same. | ||
85 | #ifndef PWM_EMBEDDED | ||
86 | /** convert something to string using ostringstream */ | ||
87 | template <class T> inline | ||
88 | std::string tostr(const T &t) | ||
89 | { | ||
90 | std::ostringstream s; | ||
91 | s << t; | ||
92 | return s.str(); | ||
93 | } | ||
94 | #else | ||
75 | /** convert something to string using ostringstream */ | 95 | /** convert something to string using ostringstream */ |
76 | template <class T> inline | 96 | template <class T> inline |
77 | std::string tostr(const T &t) | 97 | std::string tostr(const T &t) |
78 | { | 98 | { |
79 | std::ostringstream s; | 99 | QString result; |
80 | s << t; | 100 | QTextOStream(&result) << t; |
81 | return s.str(); | 101 | return result.latin1(); |
82 | } | 102 | } |
103 | #endif | ||
83 | 104 | ||
84 | /** delete the memory and NULL the pointer */ | 105 | /** delete the memory and NULL the pointer */ |
85 | template<class T> inline | 106 | template<class T> inline |
86 | void delete_and_null(T *&p) | 107 | void delete_and_null(T *&p) |
87 | { | 108 | { |
88 | delete p; | 109 | delete p; |
89 | p = 0; | 110 | p = 0; |
90 | } | 111 | } |
91 | /** delete the memory if the pointer isn't a NULL pointer */ | 112 | /** delete the memory if the pointer isn't a NULL pointer */ |
92 | template<class T> inline | 113 | template<class T> inline |
93 | void delete_ifnot_null(T *&p) | 114 | void delete_ifnot_null(T *&p) |
94 | { | 115 | { |
95 | if (p) | 116 | if (p) |
96 | delete_and_null(p); | 117 | delete_and_null(p); |
97 | } | 118 | } |
98 | 119 | ||
99 | template<class T> inline | 120 | template<class T> inline |
100 | void delete_and_null_array(T *&p) | 121 | void delete_and_null_array(T *&p) |
101 | { | 122 | { |
102 | delete [] p; | 123 | delete [] p; |
103 | p = 0; | 124 | p = 0; |
104 | } | 125 | } |
105 | 126 | ||
106 | template<class T> inline | 127 | template<class T> inline |
107 | void delete_ifnot_null_array(T *&p) | 128 | void delete_ifnot_null_array(T *&p) |
108 | { | 129 | { |
109 | if (p) | 130 | if (p) |
110 | delete_and_null_array(p); | 131 | delete_and_null_array(p); |
111 | } | 132 | } |
112 | 133 | ||
113 | #endif // GLOBALSTUFF_H | 134 | #endif // GLOBALSTUFF_H |
diff --git a/pwmanager/pwmanager/ipc.cpp b/pwmanager/pwmanager/ipc.cpp index 7468357..b1d2c68 100644 --- a/pwmanager/pwmanager/ipc.cpp +++ b/pwmanager/pwmanager/ipc.cpp | |||
@@ -1,152 +1,216 @@ | |||
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 | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/socket.h> | 25 | #include <sys/socket.h> |
26 | |||
27 | #ifndef PWM_EMBEDDED | ||
28 | #include <sys/types.h> | ||
27 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #else | ||
31 | #include <qsocket.h> | ||
32 | #endif | ||
28 | 33 | ||
29 | #define END_OF_LINE '\n' | 34 | #define END_OF_LINE '\n' |
30 | #define INIT_LINEBUF_LEN64 /* byte */ | 35 | #define INIT_LINEBUF_LEN64 /* byte */ |
31 | 36 | ||
37 | #ifndef PWM_EMBEDDED | ||
32 | 38 | ||
33 | Ipc::Ipc() | 39 | Ipc::Ipc() |
34 | : stream (0) | 40 | : stream (0) |
35 | , notifier (0) | 41 | , notifier (0) |
36 | , rdBuf (0) | 42 | , rdBuf (0) |
37 | { | 43 | { |
38 | #ifndef PWM_EMBEDDED | ||
39 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { | 44 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { |
40 | throw PwMException(PwMException::EX_GENERIC, | 45 | throw PwMException(PwMException::EX_GENERIC, |
41 | "Ipc: socketpair() failed"); | 46 | "Ipc: socketpair() failed"); |
42 | } | 47 | } |
43 | rdBufSize = INIT_LINEBUF_LEN; | 48 | rdBufSize = INIT_LINEBUF_LEN; |
44 | rdBuf = static_cast<char *>(malloc(rdBufSize)); | 49 | rdBuf = static_cast<char *>(malloc(rdBufSize)); |
45 | if (!rdBuf) { | 50 | if (!rdBuf) { |
46 | close(sock[0]); | 51 | close(sock[0]); |
47 | close(sock[1]); | 52 | close(sock[1]); |
48 | throw PwMException(PwMException::EX_GENERIC, | 53 | throw PwMException(PwMException::EX_GENERIC, |
49 | "Ipc: OOM"); | 54 | "Ipc: OOM"); |
50 | } | 55 | } |
51 | stream = fdopen(sock[0], "r"); | 56 | stream = fdopen(sock[0], "r"); |
52 | if (!stream) { | 57 | if (!stream) { |
53 | close(sock[0]); | 58 | close(sock[0]); |
54 | close(sock[1]); | 59 | close(sock[1]); |
55 | free(rdBuf); | 60 | free(rdBuf); |
56 | throw PwMException(PwMException::EX_GENERIC, | 61 | throw PwMException(PwMException::EX_GENERIC, |
57 | "Ipc: fdopen() failed"); | 62 | "Ipc: fdopen() failed"); |
58 | } | 63 | } |
64 | |||
65 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | ||
66 | connect(notifier, SIGNAL(activated(int)), | ||
67 | this, SLOT(receiveData(int))); | ||
68 | host = true; | ||
69 | } | ||
59 | #else | 70 | #else |
71 | Ipc::Ipc() | ||
72 | : notifier (0) | ||
73 | , rdBuf (0) | ||
74 | { | ||
60 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { | 75 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { |
61 | qDebug("Ipc: socketpair() failed"); | 76 | qDebug("Ipc: socketpair() failed"); |
62 | } | 77 | } |
78 | |||
79 | QSocket* qsock = new QSocket(); | ||
80 | qsock->setSocket(sock[0]); | ||
81 | |||
63 | rdBufSize = INIT_LINEBUF_LEN; | 82 | rdBufSize = INIT_LINEBUF_LEN; |
64 | rdBuf = (char *)(malloc(rdBufSize)); | 83 | rdBuf = (char *)(malloc(rdBufSize)); |
65 | if (!rdBuf) { | 84 | if (!rdBuf) { |
66 | close(sock[0]); | 85 | close(sock[0]); |
67 | close(sock[1]); | 86 | close(sock[1]); |
68 | qDebug("Ipc: OOM"); | 87 | qDebug("Ipc: OOM"); |
69 | } | 88 | } |
89 | |||
90 | qsock = new QSocket(); | ||
91 | qsock->setSocket(sock[0]); | ||
92 | |||
93 | /*US | ||
70 | stream = fdopen(sock[0], "r"); | 94 | stream = fdopen(sock[0], "r"); |
71 | if (!stream) { | 95 | if (!stream) { |
72 | close(sock[0]); | 96 | close(sock[0]); |
73 | close(sock[1]); | 97 | close(sock[1]); |
74 | free(rdBuf); | 98 | free(rdBuf); |
75 | qDebug("Ipc: fdopen() failed"); | 99 | qDebug("Ipc: fdopen() failed"); |
76 | } | 100 | } |
77 | #endif | 101 | */ |
78 | 102 | ||
79 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 103 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
80 | connect(notifier, SIGNAL(activated(int)), | 104 | connect(notifier, SIGNAL(activated(int)), |
81 | this, SLOT(receiveData(int))); | 105 | this, SLOT(receiveData(int))); |
82 | host = true; | 106 | host = true; |
83 | } | 107 | } |
84 | 108 | ||
109 | #endif | ||
110 | |||
111 | |||
112 | #ifndef PWM_EMBEDDED | ||
113 | |||
85 | Ipc::Ipc(const Ipc *ipc) | 114 | Ipc::Ipc(const Ipc *ipc) |
86 | : stream (0) | 115 | : stream (0) |
87 | , notifier (0) | 116 | , notifier (0) |
88 | , rdBuf (0) | 117 | , rdBuf (0) |
89 | { | 118 | { |
90 | #ifndef PWM_EMBEDDED | ||
91 | rdBufSize = INIT_LINEBUF_LEN; | 119 | rdBufSize = INIT_LINEBUF_LEN; |
92 | rdBuf = static_cast<char *>(malloc(rdBufSize)); | 120 | rdBuf = static_cast<char *>(malloc(rdBufSize)); |
93 | if (!rdBuf) { | 121 | if (!rdBuf) { |
94 | throw PwMException(PwMException::EX_GENERIC, | 122 | throw PwMException(PwMException::EX_GENERIC, |
95 | "Ipc: OOM"); | 123 | "Ipc: OOM"); |
96 | } | 124 | } |
97 | sock[0] = ipc->sock[1]; | 125 | sock[0] = ipc->sock[1]; |
98 | sock[1] = ipc->sock[0]; | 126 | sock[1] = ipc->sock[0]; |
99 | stream = fdopen(sock[0], "r"); | 127 | stream = fdopen(sock[0], "r"); |
100 | if (!stream) { | 128 | if (!stream) { |
101 | free(rdBuf); | 129 | free(rdBuf); |
102 | throw PwMException(PwMException::EX_GENERIC, | 130 | throw PwMException(PwMException::EX_GENERIC, |
103 | "Ipc: fdopen() failed"); | 131 | "Ipc: fdopen() failed"); |
104 | } | 132 | } |
133 | |||
134 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | ||
135 | connect(notifier, SIGNAL(activated(int)), | ||
136 | this, SLOT(receiveData(int))); | ||
137 | host = false; | ||
138 | } | ||
139 | |||
105 | #else | 140 | #else |
141 | |||
142 | Ipc::Ipc(const Ipc *ipc) | ||
143 | : notifier (0) | ||
144 | , rdBuf (0) | ||
145 | { | ||
106 | rdBufSize = INIT_LINEBUF_LEN; | 146 | rdBufSize = INIT_LINEBUF_LEN; |
107 | rdBuf = (char *)(malloc(rdBufSize)); | 147 | rdBuf = (char *)(malloc(rdBufSize)); |
108 | if (!rdBuf) { | 148 | if (!rdBuf) { |
109 | qDebug("Ipc: OOM"); | 149 | qDebug("Ipc: OOM"); |
110 | } | 150 | } |
111 | sock[0] = ipc->sock[1]; | 151 | sock[0] = ipc->sock[1]; |
112 | sock[1] = ipc->sock[0]; | 152 | sock[1] = ipc->sock[0]; |
153 | |||
154 | qSock = new QSocket(); | ||
155 | qSock->setSocket(sock[0]); | ||
156 | |||
157 | /*US | ||
113 | stream = fdopen(sock[0], "r"); | 158 | stream = fdopen(sock[0], "r"); |
114 | if (!stream) { | 159 | if (!stream) { |
115 | free(rdBuf); | 160 | free(rdBuf); |
116 | qDebug("Ipc: fdopen() failed"); | 161 | qDebug("Ipc: fdopen() failed"); |
117 | } | 162 | } |
118 | #endif | 163 | */ |
164 | |||
119 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); | 165 | notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); |
120 | connect(notifier, SIGNAL(activated(int)), | 166 | connect(notifier, SIGNAL(activated(int)), |
121 | this, SLOT(receiveData(int))); | 167 | this, SLOT(receiveData(int))); |
122 | host = false; | 168 | host = false; |
123 | } | 169 | } |
124 | 170 | ||
171 | #endif | ||
172 | |||
125 | Ipc::~Ipc() | 173 | Ipc::~Ipc() |
126 | { | 174 | { |
175 | #ifdef PWM_EMBEDDED | ||
176 | delete qSock; | ||
177 | #endif | ||
127 | delete_ifnot_null(notifier); | 178 | delete_ifnot_null(notifier); |
128 | if (rdBuf) | 179 | if (rdBuf) |
129 | free(rdBuf); | 180 | free(rdBuf); |
181 | #ifndef PWM_EMBEDDED | ||
130 | if (stream) | 182 | if (stream) |
131 | fclose(stream); | 183 | fclose(stream); |
184 | #endif | ||
132 | if (host) { | 185 | if (host) { |
133 | close(sock[0]); | 186 | close(sock[0]); |
134 | close(sock[1]); | 187 | close(sock[1]); |
135 | } | 188 | } |
189 | |||
136 | } | 190 | } |
137 | 191 | ||
138 | void Ipc::receiveData(int s) | 192 | void Ipc::receiveData(int s) |
139 | { | 193 | { |
140 | ssize_t rd; | ||
141 | |||
142 | PWM_ASSERT(s == sock[0]); | 194 | PWM_ASSERT(s == sock[0]); |
143 | PARAM_UNUSED(s); | 195 | PARAM_UNUSED(s); |
144 | rd = getline(&rdBuf, &rdBufSize, stream); | 196 | #ifndef PWM_EMBEDDED |
197 | ssize_t rd; | ||
198 | |||
199 | rd = ::getline(&rdBuf, &rdBufSize, stream); | ||
145 | if (likely(rd > 0)) { | 200 | if (likely(rd > 0)) { |
146 | emit lineAvailable(rdBuf, rd); | 201 | emit lineAvailable(rdBuf, rd); |
147 | } | 202 | } |
203 | #else | ||
204 | int rd; | ||
205 | rd = qSock->readLine(rdBuf, rdBufSize); | ||
206 | if (rd > 0) { | ||
207 | emit lineAvailable(rdBuf, rd); | ||
208 | } | ||
209 | #endif | ||
210 | qDebug("void Ipc::receiveData(int s) has to be implemented."); | ||
211 | |||
148 | } | 212 | } |
149 | 213 | ||
150 | #ifndef PWM_EMBEDDED | 214 | #ifndef PWM_EMBEDDED |
151 | #include "ipc.moc" | 215 | #include "ipc.moc" |
152 | #endif | 216 | #endif |
diff --git a/pwmanager/pwmanager/ipc.h b/pwmanager/pwmanager/ipc.h index ccdaafb..e5a496d 100644 --- a/pwmanager/pwmanager/ipc.h +++ b/pwmanager/pwmanager/ipc.h | |||
@@ -1,73 +1,89 @@ | |||
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 <unistd.h> | 24 | #include <unistd.h> |
24 | 25 | ||
25 | #include <qobject.h> | 26 | #ifndef PWM_EMBEDDED |
26 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #else | ||
29 | #include <qsocket.h> | ||
30 | #endif | ||
27 | 31 | ||
28 | class QSocketNotifier; | 32 | class QSocketNotifier; |
29 | 33 | ||
30 | /** very simple interprocess communication class */ | 34 | /** very simple interprocess communication class */ |
31 | class Ipc : public QObject | 35 | class Ipc : public QObject |
32 | { | 36 | { |
33 | Q_OBJECT | 37 | Q_OBJECT |
34 | public: | 38 | public: |
35 | /** create a new Ipc communication object */ | 39 | /** create a new Ipc communication object */ |
36 | Ipc(); | 40 | Ipc(); |
37 | /** create a new Ipc communication object and | 41 | /** create a new Ipc communication object and |
38 | * connect it to "ipc" | 42 | * connect it to "ipc" |
39 | */ | 43 | */ |
40 | Ipc(const Ipc *ipc); | 44 | Ipc(const Ipc *ipc); |
41 | /** destructor */ | 45 | /** destructor */ |
42 | ~Ipc(); | 46 | ~Ipc(); |
43 | 47 | ||
44 | /** send data to the other socket end | 48 | /** send data to the other socket end |
45 | * (To the connected ipc object) | 49 | * (To the connected ipc object) |
46 | */ | 50 | */ |
51 | #ifndef PWM_EMBEDDED | ||
47 | void send(const char *buf, size_t size) | 52 | void send(const char *buf, size_t size) |
48 | { write(sock[0], buf, size); } | 53 | { write(sock[0], buf, size); } |
54 | #else | ||
55 | void send(const char *buf, size_t size) | ||
56 | { qSock->writeBlock(buf, size); } | ||
57 | #endif | ||
49 | 58 | ||
50 | signals: | 59 | signals: |
51 | /** a line is available */ | 60 | /** a line is available */ |
52 | void lineAvailable(const char *buf, size_t size); | 61 | void lineAvailable(const char *buf, size_t size); |
53 | 62 | ||
54 | protected slots: | 63 | protected slots: |
55 | /** received data on socket */ | 64 | /** received data on socket */ |
56 | void receiveData(int s); | 65 | void receiveData(int s); |
57 | 66 | ||
58 | protected: | 67 | protected: |
59 | /** full-duplex socket file desciptors */ | 68 | #ifndef PWM_EMBEDDED |
60 | int sock[2]; | ||
61 | /** stream on "this" end of the socket (sock[0]) */ | 69 | /** stream on "this" end of the socket (sock[0]) */ |
62 | FILE *stream; | 70 | FILE *stream; |
71 | /** current receive buffer size */ | ||
72 | size_t rdBufSize; | ||
73 | #else | ||
74 | QSocket* qSock; | ||
75 | /** current receive buffer size */ | ||
76 | unsigned int rdBufSize; | ||
77 | #endif | ||
78 | |||
79 | /** full-duplex socket file desciptors */ | ||
80 | int sock[2]; | ||
63 | /** socket notifier */ | 81 | /** socket notifier */ |
64 | QSocketNotifier *notifier; | 82 | QSocketNotifier *notifier; |
65 | /** are we the host or the client object? */ | 83 | /** are we the host or the client object? */ |
66 | bool host; | 84 | bool host; |
67 | /** receive buffer */ | 85 | /** receive buffer */ |
68 | char *rdBuf; | 86 | char *rdBuf; |
69 | /** current receive buffer size */ | ||
70 | size_t rdBufSize; | ||
71 | }; | 87 | }; |
72 | 88 | ||
73 | #endif // __PWM_IPC_H | 89 | #endif // __PWM_IPC_H |
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 3f2f042..4ad392e 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2181,643 +2181,785 @@ void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | |||
2181 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2181 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2182 | { | 2182 | { |
2183 | PWM_ASSERT(list); | 2183 | PWM_ASSERT(list); |
2184 | list->clear(); | 2184 | list->clear(); |
2185 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2185 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2186 | end = dti.dta[category].d.end(), | 2186 | end = dti.dta[category].d.end(), |
2187 | i = begin; | 2187 | i = begin; |
2188 | while (i != end) { | 2188 | while (i != end) { |
2189 | #ifndef PWM_EMBEDDED | 2189 | #ifndef PWM_EMBEDDED |
2190 | list->push_back(i->desc.c_str()); | 2190 | list->push_back(i->desc.c_str()); |
2191 | #else | 2191 | #else |
2192 | list->append(i->desc.c_str()); | 2192 | list->append(i->desc.c_str()); |
2193 | #endif | 2193 | #endif |
2194 | ++i; | 2194 | ++i; |
2195 | } | 2195 | } |
2196 | } | 2196 | } |
2197 | 2197 | ||
2198 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2198 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2199 | { | 2199 | { |
2200 | unsigned int cat = 0; | 2200 | unsigned int cat = 0; |
2201 | 2201 | ||
2202 | if (!findCategory(category, &cat)) | 2202 | if (!findCategory(category, &cat)) |
2203 | return false; | 2203 | return false; |
2204 | 2204 | ||
2205 | return execLauncher(cat, entryIndex); | 2205 | return execLauncher(cat, entryIndex); |
2206 | } | 2206 | } |
2207 | 2207 | ||
2208 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2208 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2209 | { | 2209 | { |
2210 | if (geteuid() == 0) { | 2210 | if (geteuid() == 0) { |
2211 | rootAlertMsgBox(); | 2211 | rootAlertMsgBox(); |
2212 | return false; | 2212 | return false; |
2213 | } | 2213 | } |
2214 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2214 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2215 | bool wasLocked = isLocked(category, entryIndex); | 2215 | bool wasLocked = isLocked(category, entryIndex); |
2216 | 2216 | ||
2217 | if (command.find("$p") != -1) { | 2217 | if (command.find("$p") != -1) { |
2218 | /* the user requested the password to be included | 2218 | /* the user requested the password to be included |
2219 | * into the command. We have to ask for the password, | 2219 | * into the command. We have to ask for the password, |
2220 | * if it's locked. We do that by unlocking the entry | 2220 | * if it's locked. We do that by unlocking the entry |
2221 | */ | 2221 | */ |
2222 | if (!lockAt(category, entryIndex, false)) | 2222 | if (!lockAt(category, entryIndex, false)) |
2223 | return false; | 2223 | return false; |
2224 | } | 2224 | } |
2225 | #ifndef PWM_EMBEDDED | 2225 | #ifndef PWM_EMBEDDED |
2226 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2226 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2227 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2227 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2228 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2228 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2229 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2229 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2230 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2230 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2231 | #else | 2231 | #else |
2232 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2232 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2233 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2233 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2234 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2234 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2235 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2235 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2236 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2236 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2237 | #endif | 2237 | #endif |
2238 | command.append(" &"); | 2238 | command.append(" &"); |
2239 | 2239 | ||
2240 | QString customXterm(conf()->confGlobXtermCommand()); | 2240 | QString customXterm(conf()->confGlobXtermCommand()); |
2241 | if (!customXterm.isEmpty()) | 2241 | if (!customXterm.isEmpty()) |
2242 | command = customXterm + " " + command; | 2242 | command = customXterm + " " + command; |
2243 | 2243 | ||
2244 | system(command.latin1()); | 2244 | system(command.latin1()); |
2245 | 2245 | ||
2246 | lockAt(category, entryIndex, wasLocked); | 2246 | lockAt(category, entryIndex, wasLocked); |
2247 | return true; | 2247 | return true; |
2248 | } | 2248 | } |
2249 | 2249 | ||
2250 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2250 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2251 | { | 2251 | { |
2252 | unsigned int cat = 0; | 2252 | unsigned int cat = 0; |
2253 | 2253 | ||
2254 | if (!findCategory(category, &cat)) | 2254 | if (!findCategory(category, &cat)) |
2255 | return false; | 2255 | return false; |
2256 | 2256 | ||
2257 | return goToURL(cat, entryIndex); | 2257 | return goToURL(cat, entryIndex); |
2258 | } | 2258 | } |
2259 | 2259 | ||
2260 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2260 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2261 | { | 2261 | { |
2262 | if (geteuid() == 0) { | 2262 | if (geteuid() == 0) { |
2263 | rootAlertMsgBox(); | 2263 | rootAlertMsgBox(); |
2264 | return false; | 2264 | return false; |
2265 | } | 2265 | } |
2266 | QString url(dti.dta[category].d[entryIndex].url.c_str()); | 2266 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2267 | if (url.isEmpty()) | 2267 | if (url.isEmpty()) |
2268 | return false; | 2268 | return false; |
2269 | 2269 | ||
2270 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2270 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2271 | if (!customBrowser.isEmpty()) { | 2271 | if (!customBrowser.isEmpty()) { |
2272 | browserProc.clearArguments(); | 2272 | browserProc.clearArguments(); |
2273 | browserProc << customBrowser << url; | 2273 | browserProc << customBrowser << url; |
2274 | if (browserProc.start(KProcess::DontCare)) | 2274 | if (browserProc.start(KProcess::DontCare)) |
2275 | return true; | 2275 | return true; |
2276 | } | 2276 | } |
2277 | 2277 | ||
2278 | browserProc.clearArguments(); | 2278 | browserProc.clearArguments(); |
2279 | browserProc << "konqueror" << url; | 2279 | browserProc << "konqueror" << url; |
2280 | if (browserProc.start(KProcess::DontCare)) | 2280 | if (browserProc.start(KProcess::DontCare)) |
2281 | return true; | 2281 | return true; |
2282 | 2282 | ||
2283 | browserProc.clearArguments(); | 2283 | browserProc.clearArguments(); |
2284 | browserProc << "mozilla" << url; | 2284 | browserProc << "mozilla" << url; |
2285 | if (browserProc.start(KProcess::DontCare)) | 2285 | if (browserProc.start(KProcess::DontCare)) |
2286 | return true; | 2286 | return true; |
2287 | 2287 | ||
2288 | browserProc.clearArguments(); | 2288 | browserProc.clearArguments(); |
2289 | browserProc << "opera" << url; | 2289 | browserProc << "opera" << url; |
2290 | if (browserProc.start(KProcess::DontCare)) | 2290 | if (browserProc.start(KProcess::DontCare)) |
2291 | return true; | 2291 | return true; |
2292 | return false; | 2292 | return false; |
2293 | } | 2293 | } |
2294 | 2294 | ||
2295 | PwMerror PwMDoc::exportToText(const QString *file) | 2295 | PwMerror PwMDoc::exportToText(const QString *file) |
2296 | { | 2296 | { |
2297 | PWM_ASSERT(file); | 2297 | PWM_ASSERT(file); |
2298 | if (QFile::exists(*file)) { | 2298 | if (QFile::exists(*file)) { |
2299 | if (!QFile::remove(*file)) | 2299 | if (!QFile::remove(*file)) |
2300 | return e_accessFile; | 2300 | return e_accessFile; |
2301 | } | 2301 | } |
2302 | QFile f(*file); | 2302 | QFile f(*file); |
2303 | if (!f.open(IO_ReadWrite)) | 2303 | if (!f.open(IO_ReadWrite)) |
2304 | return e_openFile; | 2304 | return e_openFile; |
2305 | 2305 | ||
2306 | if (!unlockAll_tempoary()) { | 2306 | if (!unlockAll_tempoary()) { |
2307 | f.close(); | 2307 | f.close(); |
2308 | return e_lock; | 2308 | return e_lock; |
2309 | } | 2309 | } |
2310 | 2310 | ||
2311 | // write header | 2311 | // write header |
2312 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2312 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2313 | header += PACKAGE_VER; | 2313 | header += PACKAGE_VER; |
2314 | header += i18n("\non ").latin1(); | 2314 | header += i18n("\non ").latin1(); |
2315 | QDate currDate = QDate::currentDate(); | 2315 | QDate currDate = QDate::currentDate(); |
2316 | QTime currTime = QTime::currentTime(); | 2316 | QTime currTime = QTime::currentTime(); |
2317 | 2317 | ||
2318 | #ifndef PWM_EMBEDDED | 2318 | #ifndef PWM_EMBEDDED |
2319 | header += currDate.toString("ddd MMMM d ").latin1(); | 2319 | header += currDate.toString("ddd MMMM d ").latin1(); |
2320 | header += currTime.toString("hh:mm:ss ").latin1(); | 2320 | header += currTime.toString("hh:mm:ss ").latin1(); |
2321 | #else | 2321 | #else |
2322 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2322 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2323 | bool ampm = KGlobal::locale()->use12Clock(); | 2323 | bool ampm = KGlobal::locale()->use12Clock(); |
2324 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2324 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2325 | KGlobal::locale()->setHore24Format(true); | 2325 | KGlobal::locale()->setHore24Format(true); |
2326 | 2326 | ||
2327 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); | 2327 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); |
2328 | header += KGlobal::locale()->formatTime(currTime, true); | 2328 | header += KGlobal::locale()->formatTime(currTime, true); |
2329 | KGlobal::locale()->setDateFormatShort(dfs); | 2329 | KGlobal::locale()->setDateFormatShort(dfs); |
2330 | KGlobal::locale()->setHore24Format(!ampm); | 2330 | KGlobal::locale()->setHore24Format(!ampm); |
2331 | 2331 | ||
2332 | #endif | 2332 | #endif |
2333 | header += tostr(currDate.year()); | 2333 | header += tostr(currDate.year()); |
2334 | header += "\n==============================\n\n"; | 2334 | header += "\n==============================\n\n"; |
2335 | 2335 | ||
2336 | 2336 | ||
2337 | #ifndef PWM_EMBEDDED | 2337 | #ifndef PWM_EMBEDDED |
2338 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2338 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2339 | unlockAll_tempoary(true); | 2339 | unlockAll_tempoary(true); |
2340 | f.close(); | 2340 | f.close(); |
2341 | return e_writeFile; | 2341 | return e_writeFile; |
2342 | } | 2342 | } |
2343 | #else | 2343 | #else |
2344 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2344 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2345 | unlockAll_tempoary(true); | 2345 | unlockAll_tempoary(true); |
2346 | f.close(); | 2346 | f.close(); |
2347 | return e_writeFile; | 2347 | return e_writeFile; |
2348 | } | 2348 | } |
2349 | #endif | 2349 | #endif |
2350 | unsigned int i, numCat = numCategories(); | 2350 | unsigned int i, numCat = numCategories(); |
2351 | unsigned int j, numEnt; | 2351 | unsigned int j, numEnt; |
2352 | string exp; | 2352 | string exp; |
2353 | for (i = 0; i < numCat; ++i) { | 2353 | for (i = 0; i < numCat; ++i) { |
2354 | numEnt = numEntries(i); | 2354 | numEnt = numEntries(i); |
2355 | 2355 | ||
2356 | exp = "\n== Category: "; | 2356 | exp = "\n== Category: "; |
2357 | exp += dti.dta[i].name; | 2357 | exp += dti.dta[i].name; |
2358 | exp += " ==\n"; | 2358 | exp += " ==\n"; |
2359 | #ifndef PWM_EMBEDDED | 2359 | #ifndef PWM_EMBEDDED |
2360 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2360 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2361 | unlockAll_tempoary(true); | 2361 | unlockAll_tempoary(true); |
2362 | f.close(); | 2362 | f.close(); |
2363 | return e_writeFile; | 2363 | return e_writeFile; |
2364 | } | 2364 | } |
2365 | #else | 2365 | #else |
2366 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2366 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2367 | unlockAll_tempoary(true); | 2367 | unlockAll_tempoary(true); |
2368 | f.close(); | 2368 | f.close(); |
2369 | return e_writeFile; | 2369 | return e_writeFile; |
2370 | } | 2370 | } |
2371 | #endif | 2371 | #endif |
2372 | for (j = 0; j < numEnt; ++j) { | 2372 | for (j = 0; j < numEnt; ++j) { |
2373 | exp = "\n-- "; | 2373 | exp = "\n-- "; |
2374 | exp += dti.dta[i].d[j].desc; | 2374 | exp += dti.dta[i].d[j].desc; |
2375 | exp += " --\n"; | 2375 | exp += " --\n"; |
2376 | 2376 | ||
2377 | exp += i18n("Username: ").latin1(); | 2377 | exp += i18n("Username: ").latin1(); |
2378 | exp += dti.dta[i].d[j].name; | 2378 | exp += dti.dta[i].d[j].name; |
2379 | exp += "\n"; | 2379 | exp += "\n"; |
2380 | 2380 | ||
2381 | exp += i18n("Password: ").latin1(); | 2381 | exp += i18n("Password: ").latin1(); |
2382 | exp += dti.dta[i].d[j].pw; | 2382 | exp += dti.dta[i].d[j].pw; |
2383 | exp += "\n"; | 2383 | exp += "\n"; |
2384 | 2384 | ||
2385 | exp += i18n("Comment: ").latin1(); | 2385 | exp += i18n("Comment: ").latin1(); |
2386 | exp += dti.dta[i].d[j].comment; | 2386 | exp += dti.dta[i].d[j].comment; |
2387 | exp += "\n"; | 2387 | exp += "\n"; |
2388 | 2388 | ||
2389 | exp += i18n("URL: ").latin1(); | 2389 | exp += i18n("URL: ").latin1(); |
2390 | exp += dti.dta[i].d[j].url; | 2390 | exp += dti.dta[i].d[j].url; |
2391 | exp += "\n"; | 2391 | exp += "\n"; |
2392 | 2392 | ||
2393 | exp += i18n("Launcher: ").latin1(); | 2393 | exp += i18n("Launcher: ").latin1(); |
2394 | exp += dti.dta[i].d[j].launcher; | 2394 | exp += dti.dta[i].d[j].launcher; |
2395 | exp += "\n"; | 2395 | exp += "\n"; |
2396 | 2396 | ||
2397 | #ifndef PWM_EMBEDDED | 2397 | #ifndef PWM_EMBEDDED |
2398 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2398 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2399 | unlockAll_tempoary(true); | 2399 | unlockAll_tempoary(true); |
2400 | f.close(); | 2400 | f.close(); |
2401 | return e_writeFile; | 2401 | return e_writeFile; |
2402 | } | 2402 | } |
2403 | #else | 2403 | #else |
2404 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2404 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2405 | unlockAll_tempoary(true); | 2405 | unlockAll_tempoary(true); |
2406 | f.close(); | 2406 | f.close(); |
2407 | return e_writeFile; | 2407 | return e_writeFile; |
2408 | } | 2408 | } |
2409 | #endif | 2409 | #endif |
2410 | } | 2410 | } |
2411 | } | 2411 | } |
2412 | unlockAll_tempoary(true); | 2412 | unlockAll_tempoary(true); |
2413 | f.close(); | 2413 | f.close(); |
2414 | 2414 | ||
2415 | return e_success; | 2415 | return e_success; |
2416 | } | 2416 | } |
2417 | 2417 | ||
2418 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2418 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2419 | { | 2419 | { |
2420 | PWM_ASSERT(file); | 2420 | PWM_ASSERT(file); |
2421 | if (format == 0) | 2421 | if (format == 0) |
2422 | return importText_PwM(file); | 2422 | return importText_PwM(file); |
2423 | else if (format == -1) { | 2423 | else if (format == -1) { |
2424 | // probe for all formats | 2424 | // probe for all formats |
2425 | if (importText_PwM(file) == e_success) | 2425 | if (importText_PwM(file) == e_success) |
2426 | return e_success; | 2426 | return e_success; |
2427 | dti.clear(); | 2427 | dti.clear(); |
2428 | emitDataChanged(this); | 2428 | emitDataChanged(this); |
2429 | // add next format here... | 2429 | // add next format here... |
2430 | return e_fileFormat; | 2430 | return e_fileFormat; |
2431 | } | 2431 | } |
2432 | return e_invalidArg; | 2432 | return e_invalidArg; |
2433 | } | 2433 | } |
2434 | 2434 | ||
2435 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2435 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2436 | { | 2436 | { |
2437 | #ifndef PWM_EMBEDDED | ||
2437 | PWM_ASSERT(file); | 2438 | PWM_ASSERT(file); |
2438 | FILE *f; | 2439 | FILE *f; |
2439 | int tmp; | 2440 | int tmp; |
2440 | ssize_t ret; | 2441 | ssize_t ret; |
2441 | string curCat; | 2442 | string curCat; |
2442 | unsigned int entriesRead = 0; | 2443 | unsigned int entriesRead = 0; |
2443 | PwMDataItem currItem; | 2444 | PwMDataItem currItem; |
2444 | f = fopen(file->latin1(), "r"); | 2445 | f = fopen(file->latin1(), "r"); |
2445 | if (!f) | 2446 | if (!f) |
2446 | return e_openFile; | 2447 | return e_openFile; |
2447 | size_t ch_tmp_size = 1024; | 2448 | size_t ch_tmp_size = 1024; |
2448 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2449 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2449 | if (!ch_tmp) { | 2450 | if (!ch_tmp) { |
2450 | fclose(f); | 2451 | fclose(f); |
2451 | return e_outOfMem; | 2452 | return e_outOfMem; |
2452 | } | 2453 | } |
2453 | 2454 | ||
2454 | // - check header | 2455 | // - check header |
2455 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2456 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2456 | goto formatError; | 2457 | goto formatError; |
2457 | // check version-string and return version in "ch_tmp". | 2458 | // check version-string and return version in "ch_tmp". |
2458 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2459 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2459 | // header not recognized as PwM generated header | 2460 | // header not recognized as PwM generated header |
2460 | goto formatError; | 2461 | goto formatError; |
2461 | } | 2462 | } |
2462 | // set filepointer behind version-string-line previously checked | 2463 | // set filepointer behind version-string-line previously checked |
2463 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2464 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2464 | goto formatError; | 2465 | goto formatError; |
2465 | // skip next line containing the build-date | 2466 | // skip next line containing the build-date |
2466 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2467 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2467 | goto formatError; | 2468 | goto formatError; |
2468 | // read header termination line | 2469 | // read header termination line |
2469 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2470 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2470 | goto formatError; | 2471 | goto formatError; |
2471 | if (strcmp(ch_tmp, "==============================\n")) | 2472 | if (strcmp(ch_tmp, "==============================\n")) |
2472 | goto formatError; | 2473 | goto formatError; |
2473 | 2474 | ||
2474 | // - read entries | 2475 | // - read entries |
2475 | do { | 2476 | do { |
2476 | // find beginning of next category | 2477 | // find beginning of next category |
2477 | do { | 2478 | do { |
2478 | tmp = fgetc(f); | 2479 | tmp = fgetc(f); |
2479 | } while (tmp == '\n' && tmp != EOF); | 2480 | } while (tmp == '\n' && tmp != EOF); |
2480 | if (tmp == EOF) | 2481 | if (tmp == EOF) |
2481 | break; | 2482 | break; |
2482 | 2483 | ||
2483 | // decrement filepos by one | 2484 | // decrement filepos by one |
2484 | fseek(f, -1, SEEK_CUR); | 2485 | fseek(f, -1, SEEK_CUR); |
2485 | // read cat-name | 2486 | // read cat-name |
2486 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2487 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2487 | goto formatError; | 2488 | goto formatError; |
2488 | // check cat-name format | 2489 | // check cat-name format |
2489 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2490 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2490 | goto formatError; | 2491 | goto formatError; |
2491 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2492 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2492 | goto formatError; | 2493 | goto formatError; |
2493 | // copy cat-name | 2494 | // copy cat-name |
2494 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2495 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2495 | 2496 | ||
2496 | do { | 2497 | do { |
2497 | // find beginning of next entry | 2498 | // find beginning of next entry |
2498 | do { | 2499 | do { |
2499 | tmp = fgetc(f); | 2500 | tmp = fgetc(f); |
2500 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2501 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2501 | if (tmp == EOF) | 2502 | if (tmp == EOF) |
2502 | break; | 2503 | break; |
2503 | if (tmp == '=') { | 2504 | if (tmp == '=') { |
2504 | fseek(f, -1, SEEK_CUR); | 2505 | fseek(f, -1, SEEK_CUR); |
2505 | break; | 2506 | break; |
2506 | } | 2507 | } |
2507 | // decrement filepos by one | 2508 | // decrement filepos by one |
2508 | fseek(f, -1, SEEK_CUR); | 2509 | fseek(f, -1, SEEK_CUR); |
2509 | // read desc-line | 2510 | // read desc-line |
2510 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2511 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2511 | goto formatError; | 2512 | goto formatError; |
2512 | // check desc-line format | 2513 | // check desc-line format |
2513 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2514 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2514 | goto formatError; | 2515 | goto formatError; |
2515 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2516 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2516 | goto formatError; | 2517 | goto formatError; |
2517 | // add desc-line | 2518 | // add desc-line |
2518 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2519 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2519 | 2520 | ||
2520 | // read username-line | 2521 | // read username-line |
2521 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2522 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2522 | goto formatError; | 2523 | goto formatError; |
2523 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2524 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2524 | goto formatError; | 2525 | goto formatError; |
2525 | 2526 | ||
2526 | // read pw-line | 2527 | // read pw-line |
2527 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2528 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2528 | goto formatError; | 2529 | goto formatError; |
2529 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2530 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2530 | goto formatError; | 2531 | goto formatError; |
2531 | 2532 | ||
2532 | // read comment-line | 2533 | // read comment-line |
2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2534 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2534 | goto formatError; | 2535 | goto formatError; |
2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2536 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2536 | goto formatError; | 2537 | goto formatError; |
2537 | 2538 | ||
2538 | // read URL-line | 2539 | // read URL-line |
2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2540 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2540 | goto formatError; | 2541 | goto formatError; |
2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2542 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2542 | goto formatError; | 2543 | goto formatError; |
2543 | 2544 | ||
2544 | // read launcher-line | 2545 | // read launcher-line |
2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2546 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2546 | goto formatError; | 2547 | goto formatError; |
2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2548 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2548 | goto formatError; | 2549 | goto formatError; |
2549 | 2550 | ||
2550 | currItem.lockStat = true; | 2551 | currItem.lockStat = true; |
2551 | currItem.listViewPos = -1; | 2552 | currItem.listViewPos = -1; |
2552 | addEntry(curCat.c_str(), &currItem, true); | 2553 | addEntry(curCat.c_str(), &currItem, true); |
2553 | ++entriesRead; | 2554 | ++entriesRead; |
2554 | } while (1); | 2555 | } while (1); |
2555 | } while (1); | 2556 | } while (1); |
2556 | if (!entriesRead) | 2557 | if (!entriesRead) |
2557 | goto formatError; | 2558 | goto formatError; |
2558 | 2559 | ||
2559 | free(ch_tmp); | 2560 | free(ch_tmp); |
2560 | fclose(f); | 2561 | fclose(f); |
2561 | flagDirty(); | 2562 | flagDirty(); |
2562 | return e_success; | 2563 | return e_success; |
2563 | 2564 | ||
2564 | formatError: | 2565 | formatError: |
2565 | free(ch_tmp); | 2566 | free(ch_tmp); |
2566 | fclose(f); | 2567 | fclose(f); |
2567 | return e_fileFormat; | 2568 | return e_fileFormat; |
2569 | #else | ||
2570 | PWM_ASSERT(file); | ||
2571 | QFile f(file->latin1()); | ||
2572 | int tmp; | ||
2573 | ssize_t ret; | ||
2574 | string curCat; | ||
2575 | unsigned int entriesRead = 0; | ||
2576 | PwMDataItem currItem; | ||
2577 | bool res = f.open(IO_ReadOnly); | ||
2578 | if (res == false) | ||
2579 | return e_openFile; | ||
2580 | |||
2581 | unsigned int ch_tmp_size = 1024; | ||
2582 | char *ch_tmp = (char*)malloc(ch_tmp_size); | ||
2583 | if (!ch_tmp) { | ||
2584 | f.close(); | ||
2585 | return e_outOfMem; | ||
2586 | } | ||
2587 | |||
2588 | // - check header | ||
2589 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. | ||
2590 | goto formatError; | ||
2591 | |||
2592 | //US read fileversion first, then check if ok. | ||
2593 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2594 | goto formatError; | ||
2595 | |||
2596 | // check version-string and return version in "ch_tmp". | ||
2597 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | ||
2598 | //US // header not recognized as PwM generated header | ||
2599 | //US goto formatError; | ||
2600 | //US} | ||
2601 | //US set filepointer behind version-string-line previously checked | ||
2602 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2603 | //US goto formatError; | ||
2604 | // skip next line containing the build-date | ||
2605 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2606 | goto formatError; | ||
2607 | // read header termination line | ||
2608 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2609 | goto formatError; | ||
2610 | if (strcmp(ch_tmp, "==============================\n")) | ||
2611 | goto formatError; | ||
2612 | |||
2613 | // - read entries | ||
2614 | do { | ||
2615 | // find beginning of next category | ||
2616 | do { | ||
2617 | tmp = f.getch(); | ||
2618 | } while (tmp == '\n' && tmp != EOF); | ||
2619 | if (tmp == EOF) | ||
2620 | break; | ||
2621 | |||
2622 | // decrement filepos by one | ||
2623 | f.at(f.at()-1); | ||
2624 | // read cat-name | ||
2625 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2626 | goto formatError; | ||
2627 | // check cat-name format | ||
2628 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | ||
2629 | goto formatError; | ||
2630 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | ||
2631 | goto formatError; | ||
2632 | // copy cat-name | ||
2633 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | ||
2634 | |||
2635 | do { | ||
2636 | // find beginning of next entry | ||
2637 | do { | ||
2638 | tmp = f.getch(); | ||
2639 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | ||
2640 | if (tmp == EOF) | ||
2641 | break; | ||
2642 | if (tmp == '=') { | ||
2643 | f.at(f.at()-1); | ||
2644 | break; | ||
2645 | } | ||
2646 | // decrement filepos by one | ||
2647 | f.at(f.at()-1); | ||
2648 | // read desc-line | ||
2649 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | ||
2650 | goto formatError; | ||
2651 | // check desc-line format | ||
2652 | if (memcmp(ch_tmp, "-- ", 3) != 0) | ||
2653 | goto formatError; | ||
2654 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | ||
2655 | goto formatError; | ||
2656 | // add desc-line | ||
2657 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | ||
2658 | |||
2659 | // read username-line | ||
2660 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | ||
2661 | goto formatError; | ||
2662 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | ||
2663 | goto formatError; | ||
2664 | |||
2665 | // read pw-line | ||
2666 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | ||
2667 | goto formatError; | ||
2668 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | ||
2669 | goto formatError; | ||
2670 | |||
2671 | // read comment-line | ||
2672 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | ||
2673 | goto formatError; | ||
2674 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | ||
2675 | goto formatError; | ||
2676 | |||
2677 | // read URL-line | ||
2678 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | ||
2679 | goto formatError; | ||
2680 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | ||
2681 | goto formatError; | ||
2682 | |||
2683 | // read launcher-line | ||
2684 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | ||
2685 | goto formatError; | ||
2686 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | ||
2687 | goto formatError; | ||
2688 | |||
2689 | currItem.lockStat = true; | ||
2690 | currItem.listViewPos = -1; | ||
2691 | addEntry(curCat.c_str(), &currItem, true); | ||
2692 | ++entriesRead; | ||
2693 | } while (1); | ||
2694 | } while (1); | ||
2695 | if (!entriesRead) | ||
2696 | goto formatError; | ||
2697 | |||
2698 | free(ch_tmp); | ||
2699 | f.close(); | ||
2700 | flagDirty(); | ||
2701 | return e_success; | ||
2702 | |||
2703 | formatError: | ||
2704 | free(ch_tmp); | ||
2705 | f.close(); | ||
2706 | return e_fileFormat; | ||
2707 | |||
2708 | #endif | ||
2709 | |||
2568 | } | 2710 | } |
2569 | 2711 | ||
2570 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2712 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2571 | { | 2713 | { |
2572 | PWM_ASSERT(in && out); | 2714 | PWM_ASSERT(in && out); |
2573 | ssize_t i = 0, len = in_size - 1; | 2715 | ssize_t i = 0, len = in_size - 1; |
2574 | while (i < len) { | 2716 | while (i < len) { |
2575 | if (in[i] == ':') | 2717 | if (in[i] == ':') |
2576 | break; | 2718 | break; |
2577 | ++i; | 2719 | ++i; |
2578 | } | 2720 | } |
2579 | i += 2; | 2721 | i += 2; |
2580 | *out = ""; | 2722 | *out = ""; |
2581 | out->append(in + i, in_size - i - 1); | 2723 | out->append(in + i, in_size - i - 1); |
2582 | return true; | 2724 | return true; |
2583 | } | 2725 | } |
2584 | 2726 | ||
2585 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2727 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2586 | { | 2728 | { |
2587 | PWM_ASSERT(file); | 2729 | PWM_ASSERT(file); |
2588 | GpasmanFile gp; | 2730 | GpasmanFile gp; |
2589 | int ret; | 2731 | int ret; |
2590 | 2732 | ||
2591 | if (!unlockAll_tempoary()) | 2733 | if (!unlockAll_tempoary()) |
2592 | return e_lock; | 2734 | return e_lock; |
2593 | 2735 | ||
2594 | QString gpmPassword; | 2736 | QString gpmPassword; |
2595 | while (1) { | 2737 | while (1) { |
2596 | gpmPassword = requestNewMpw(0); | 2738 | gpmPassword = requestNewMpw(0); |
2597 | if (gpmPassword == "") { | 2739 | if (gpmPassword == "") { |
2598 | unlockAll_tempoary(true); | 2740 | unlockAll_tempoary(true); |
2599 | return e_noPw; | 2741 | return e_noPw; |
2600 | } | 2742 | } |
2601 | if (gpmPassword.length() < 4) { | 2743 | if (gpmPassword.length() < 4) { |
2602 | gpmPwLenErrMsgBox(); | 2744 | gpmPwLenErrMsgBox(); |
2603 | } else { | 2745 | } else { |
2604 | break; | 2746 | break; |
2605 | } | 2747 | } |
2606 | } | 2748 | } |
2607 | 2749 | ||
2608 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2750 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2609 | if (ret != 1) { | 2751 | if (ret != 1) { |
2610 | unlockAll_tempoary(true); | 2752 | unlockAll_tempoary(true); |
2611 | return e_accessFile; | 2753 | return e_accessFile; |
2612 | } | 2754 | } |
2613 | 2755 | ||
2614 | char *entry[4]; | 2756 | char *entry[4]; |
2615 | unsigned int numCat = numCategories(), i; | 2757 | unsigned int numCat = numCategories(), i; |
2616 | unsigned int numEntr, j; | 2758 | unsigned int numEntr, j; |
2617 | int descLen, nameLen, pwLen, commentLen; | 2759 | int descLen, nameLen, pwLen, commentLen; |
2618 | for (i = 0; i < numCat; ++i) { | 2760 | for (i = 0; i < numCat; ++i) { |
2619 | numEntr = numEntries(i); | 2761 | numEntr = numEntries(i); |
2620 | for (j = 0; j < numEntr; ++j) { | 2762 | for (j = 0; j < numEntr; ++j) { |
2621 | descLen = dti.dta[i].d[j].desc.length(); | 2763 | descLen = dti.dta[i].d[j].desc.length(); |
2622 | nameLen = dti.dta[i].d[j].name.length(); | 2764 | nameLen = dti.dta[i].d[j].name.length(); |
2623 | pwLen = dti.dta[i].d[j].pw.length(); | 2765 | pwLen = dti.dta[i].d[j].pw.length(); |
2624 | commentLen = dti.dta[i].d[j].comment.length(); | 2766 | commentLen = dti.dta[i].d[j].comment.length(); |
2625 | entry[0] = new char[descLen + 1]; | 2767 | entry[0] = new char[descLen + 1]; |
2626 | entry[1] = new char[nameLen + 1]; | 2768 | entry[1] = new char[nameLen + 1]; |
2627 | entry[2] = new char[pwLen + 1]; | 2769 | entry[2] = new char[pwLen + 1]; |
2628 | entry[3] = new char[commentLen + 1]; | 2770 | entry[3] = new char[commentLen + 1]; |
2629 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); | 2771 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2630 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); | 2772 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2631 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); | 2773 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2632 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); | 2774 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2633 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2775 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2634 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2776 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2635 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2777 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2636 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2778 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2637 | 2779 | ||
2638 | ret = gp.save_entry(entry); | 2780 | ret = gp.save_entry(entry); |
2639 | if (ret == -1){ | 2781 | if (ret == -1){ |
2640 | delete [] entry[0]; | 2782 | delete [] entry[0]; |
2641 | delete [] entry[1]; | 2783 | delete [] entry[1]; |
2642 | delete [] entry[2]; | 2784 | delete [] entry[2]; |
2643 | delete [] entry[3]; | 2785 | delete [] entry[3]; |
2644 | gp.save_finalize(); | 2786 | gp.save_finalize(); |
2645 | unlockAll_tempoary(true); | 2787 | unlockAll_tempoary(true); |
2646 | return e_writeFile; | 2788 | return e_writeFile; |
2647 | } | 2789 | } |
2648 | 2790 | ||
2649 | delete [] entry[0]; | 2791 | delete [] entry[0]; |
2650 | delete [] entry[1]; | 2792 | delete [] entry[1]; |
2651 | delete [] entry[2]; | 2793 | delete [] entry[2]; |
2652 | delete [] entry[3]; | 2794 | delete [] entry[3]; |
2653 | } | 2795 | } |
2654 | } | 2796 | } |
2655 | unlockAll_tempoary(true); | 2797 | unlockAll_tempoary(true); |
2656 | if (gp.save_finalize() == -1) | 2798 | if (gp.save_finalize() == -1) |
2657 | return e_writeFile; | 2799 | return e_writeFile; |
2658 | 2800 | ||
2659 | return e_success; | 2801 | return e_success; |
2660 | } | 2802 | } |
2661 | 2803 | ||
2662 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2804 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2663 | { | 2805 | { |
2664 | PWM_ASSERT(file); | 2806 | PWM_ASSERT(file); |
2665 | QString pw = requestMpw(false); | 2807 | QString pw = requestMpw(false); |
2666 | if (pw == "") | 2808 | if (pw == "") |
2667 | return e_noPw; | 2809 | return e_noPw; |
2668 | GpasmanFile gp; | 2810 | GpasmanFile gp; |
2669 | int ret, i; | 2811 | int ret, i; |
2670 | PwMerror ret2; | 2812 | PwMerror ret2; |
2671 | char *entry[4]; | 2813 | char *entry[4]; |
2672 | PwMDataItem tmpData; | 2814 | PwMDataItem tmpData; |
2673 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2815 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2674 | if (ret != 1) | 2816 | if (ret != 1) |
2675 | return e_accessFile; | 2817 | return e_accessFile; |
2676 | 2818 | ||
2677 | do { | 2819 | do { |
2678 | ret = gp.load_entry(entry); | 2820 | ret = gp.load_entry(entry); |
2679 | if(ret != 1) | 2821 | if(ret != 1) |
2680 | break; | 2822 | break; |
2681 | tmpData.desc = entry[0]; | 2823 | tmpData.desc = entry[0]; |
2682 | tmpData.name = entry[1]; | 2824 | tmpData.name = entry[1]; |
2683 | tmpData.pw = entry[2]; | 2825 | tmpData.pw = entry[2]; |
2684 | tmpData.comment = entry[3]; | 2826 | tmpData.comment = entry[3]; |
2685 | tmpData.lockStat = true; | 2827 | tmpData.lockStat = true; |
2686 | tmpData.listViewPos = -1; | 2828 | tmpData.listViewPos = -1; |
2687 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2829 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2688 | for (i = 0; i < 4; ++i) | 2830 | for (i = 0; i < 4; ++i) |
2689 | free(entry[i]); | 2831 | free(entry[i]); |
2690 | if (ret2 == e_maxAllowedEntr) { | 2832 | if (ret2 == e_maxAllowedEntr) { |
2691 | gp.load_finalize(); | 2833 | gp.load_finalize(); |
2692 | return e_maxAllowedEntr; | 2834 | return e_maxAllowedEntr; |
2693 | } | 2835 | } |
2694 | } while (1); | 2836 | } while (1); |
2695 | gp.load_finalize(); | 2837 | gp.load_finalize(); |
2696 | if (isDocEmpty()) | 2838 | if (isDocEmpty()) |
2697 | return e_wrongPw; // we assume this. | 2839 | return e_wrongPw; // we assume this. |
2698 | 2840 | ||
2699 | flagDirty(); | 2841 | flagDirty(); |
2700 | return e_success; | 2842 | return e_success; |
2701 | } | 2843 | } |
2702 | 2844 | ||
2703 | void PwMDoc::ensureLvp() | 2845 | void PwMDoc::ensureLvp() |
2704 | { | 2846 | { |
2705 | if (isDocEmpty()) | 2847 | if (isDocEmpty()) |
2706 | return; | 2848 | return; |
2707 | 2849 | ||
2708 | vector< vector<PwMDataItem>::iterator > undefined; | 2850 | vector< vector<PwMDataItem>::iterator > undefined; |
2709 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2851 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, |
2710 | undefEnd, | 2852 | undefEnd, |
2711 | undefI; | 2853 | undefI; |
2712 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2854 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2713 | catEnd = dti.dta.end(), | 2855 | catEnd = dti.dta.end(), |
2714 | catI = catBegin; | 2856 | catI = catBegin; |
2715 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2857 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2716 | int lvpTop, tmpLvp; | 2858 | int lvpTop, tmpLvp; |
2717 | 2859 | ||
2718 | while (catI != catEnd) { | 2860 | while (catI != catEnd) { |
2719 | lvpTop = -1; | 2861 | lvpTop = -1; |
2720 | undefined.clear(); | 2862 | undefined.clear(); |
2721 | 2863 | ||
2722 | entrBegin = catI->d.begin(); | 2864 | entrBegin = catI->d.begin(); |
2723 | entrEnd = catI->d.end(); | 2865 | entrEnd = catI->d.end(); |
2724 | entrI = entrBegin; | 2866 | entrI = entrBegin; |
2725 | 2867 | ||
2726 | while (entrI != entrEnd) { | 2868 | while (entrI != entrEnd) { |
2727 | tmpLvp = entrI->listViewPos; | 2869 | tmpLvp = entrI->listViewPos; |
2728 | if (tmpLvp == -1) | 2870 | if (tmpLvp == -1) |
2729 | undefined.push_back(entrI); | 2871 | undefined.push_back(entrI); |
2730 | else if (tmpLvp > lvpTop) | 2872 | else if (tmpLvp > lvpTop) |
2731 | lvpTop = tmpLvp; | 2873 | lvpTop = tmpLvp; |
2732 | ++entrI; | 2874 | ++entrI; |
2733 | } | 2875 | } |
2734 | undefBegin = undefined.begin(); | 2876 | undefBegin = undefined.begin(); |
2735 | undefEnd = undefined.end(); | 2877 | undefEnd = undefined.end(); |
2736 | undefI = undefBegin; | 2878 | undefI = undefBegin; |
2737 | while (undefI != undefEnd) { | 2879 | while (undefI != undefEnd) { |
2738 | (*undefI)->listViewPos = ++lvpTop; | 2880 | (*undefI)->listViewPos = ++lvpTop; |
2739 | ++undefI; | 2881 | ++undefI; |
2740 | } | 2882 | } |
2741 | ++catI; | 2883 | ++catI; |
2742 | } | 2884 | } |
2743 | } | 2885 | } |
2744 | 2886 | ||
2745 | QString PwMDoc::getTitle() | 2887 | QString PwMDoc::getTitle() |
2746 | { | 2888 | { |
2747 | /* NOTE: We have to ensure, that the returned title | 2889 | /* NOTE: We have to ensure, that the returned title |
2748 | * is unique and not reused somewhere else while | 2890 | * is unique and not reused somewhere else while |
2749 | * this document is valid (open). | 2891 | * this document is valid (open). |
2750 | */ | 2892 | */ |
2751 | QString title(getFilename()); | 2893 | QString title(getFilename()); |
2752 | if (title.isEmpty()) { | 2894 | if (title.isEmpty()) { |
2753 | if (unnamedNum == 0) { | 2895 | if (unnamedNum == 0) { |
2754 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2896 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2755 | PWM_ASSERT(unnamedNum != 0); | 2897 | PWM_ASSERT(unnamedNum != 0); |
2756 | } | 2898 | } |
2757 | title = DEFAULT_TITLE; | 2899 | title = DEFAULT_TITLE; |
2758 | title += " "; | 2900 | title += " "; |
2759 | title += tostr(unnamedNum).c_str(); | 2901 | title += tostr(unnamedNum).c_str(); |
2760 | } | 2902 | } |
2761 | return title; | 2903 | return title; |
2762 | } | 2904 | } |
2763 | 2905 | ||
2764 | bool PwMDoc::tryDelete() | 2906 | bool PwMDoc::tryDelete() |
2765 | { | 2907 | { |
2766 | if (deleted) | 2908 | if (deleted) |
2767 | return true; | 2909 | return true; |
2768 | int ret; | 2910 | int ret; |
2769 | if (isDirty()) { | 2911 | if (isDirty()) { |
2770 | ret = dirtyAskSave(getTitle()); | 2912 | ret = dirtyAskSave(getTitle()); |
2771 | if (ret == 0) { // save to disk | 2913 | if (ret == 0) { // save to disk |
2772 | if (!saveDocUi(this)) | 2914 | if (!saveDocUi(this)) |
2773 | goto out_ignore; | 2915 | goto out_ignore; |
2774 | } else if (ret == 1) { // don't save and delete | 2916 | } else if (ret == 1) { // don't save and delete |
2775 | goto out_accept; | 2917 | goto out_accept; |
2776 | } else { // cancel operation | 2918 | } else { // cancel operation |
2777 | goto out_ignore; | 2919 | goto out_ignore; |
2778 | } | 2920 | } |
2779 | } | 2921 | } |
2780 | out_accept: | 2922 | out_accept: |
2781 | deleted = true; | 2923 | deleted = true; |
2782 | delete this; | 2924 | delete this; |
2783 | return true; | 2925 | return true; |
2784 | out_ignore: | 2926 | out_ignore: |
2785 | return false; | 2927 | return false; |
2786 | } | 2928 | } |
2787 | 2929 | ||
2788 | 2930 | ||
2789 | 2931 | ||
2790 | #ifdef PWM_EMBEDDED | 2932 | #ifdef PWM_EMBEDDED |
2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2933 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2792 | //US it could have been defined as static, but I did not want to. | 2934 | //US it could have been defined as static, but I did not want to. |
2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2935 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2794 | { | 2936 | { |
2795 | int addedPasswordsLocal = 0; | 2937 | int addedPasswordsLocal = 0; |
2796 | int addedPasswordsRemote = 0; | 2938 | int addedPasswordsRemote = 0; |
2797 | int deletedPasswordsRemote = 0; | 2939 | int deletedPasswordsRemote = 0; |
2798 | int deletedPasswordsLocal = 0; | 2940 | int deletedPasswordsLocal = 0; |
2799 | int changedLocal = 0; | 2941 | int changedLocal = 0; |
2800 | int changedRemote = 0; | 2942 | int changedRemote = 0; |
2801 | 2943 | ||
2802 | PwMSyncItem* syncItemLocal; | 2944 | PwMSyncItem* syncItemLocal; |
2803 | PwMSyncItem* syncItemRemote; | 2945 | PwMSyncItem* syncItemRemote; |
2804 | 2946 | ||
2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2947 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2948 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2807 | 2949 | ||
2808 | bool fullDateRange = false; | 2950 | bool fullDateRange = false; |
2809 | int take; | 2951 | int take; |
2810 | // local->resetTempSyncStat(); | 2952 | // local->resetTempSyncStat(); |
2811 | QDateTime mLastSync = QDateTime::currentDateTime(); | 2953 | QDateTime mLastSync = QDateTime::currentDateTime(); |
2812 | QDateTime modifiedSync = mLastSync; | 2954 | QDateTime modifiedSync = mLastSync; |
2813 | 2955 | ||
2814 | unsigned int index; | 2956 | unsigned int index; |
2815 | //Step 1. Find syncinfo in Local file and create if not existent. | 2957 | //Step 1. Find syncinfo in Local file and create if not existent. |
2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2958 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2817 | if (found == false) | 2959 | if (found == false) |
2818 | { | 2960 | { |
2819 | PwMSyncItem newSyncItemLocal; | 2961 | PwMSyncItem newSyncItemLocal; |
2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; | 2962 | newSyncItemLocal.syncName = mCurrentSyncDevice; |
2821 | newSyncItemLocal.lastSyncDate = mLastSync; | 2963 | newSyncItemLocal.lastSyncDate = mLastSync; |
2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 2964 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2965 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |