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 | |||
@@ -2373,128 +2373,129 @@ PwMerror PwMDoc::exportToText(const QString *file) | |||
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 != '='); |
@@ -2504,128 +2505,269 @@ PwMerror PwMDoc::importText_PwM(const QString *file) | |||
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()); |