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 | |||
@@ -21,18 +21,26 @@ | |||
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 |
@@ -67,24 +75,37 @@ void no_keycard_support_msg_box(QWidget *parentWidget); | |||
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 | } |
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 | |||
@@ -17,30 +17,35 @@ | |||
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]); |
@@ -51,102 +56,161 @@ Ipc::Ipc() | |||
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 | |||
@@ -15,20 +15,24 @@ | |||
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: |
@@ -39,35 +43,47 @@ public: | |||
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 | |||
@@ -2429,16 +2429,17 @@ PwMerror PwMDoc::importFromText(const QString *file, int format) | |||
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"); |
@@ -2560,16 +2561,157 @@ PwMerror PwMDoc::importText_PwM(const QString *file) | |||
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] == ':') |