summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/globalstuff.h27
-rw-r--r--pwmanager/pwmanager/ipc.cpp80
-rw-r--r--pwmanager/pwmanager/ipc.h26
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp142
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
@@ -26,8 +26,16 @@
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
33class QWidget; 41class QWidget;
@@ -72,14 +80,27 @@ void no_keycard_support_msg_box(QWidget *parentWidget);
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 */
87template <class T> inline
88std::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 */
76template <class T> inline 96template <class T> inline
77std::string tostr(const T &t) 97std::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 */
85template<class T> inline 106template<class T> inline
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
@@ -22,20 +22,25 @@
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
33Ipc::Ipc() 39Ipc::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");
@@ -56,10 +61,24 @@ Ipc::Ipc()
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
71Ipc::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) {
@@ -67,6 +86,11 @@ Ipc::Ipc()
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]);
@@ -74,7 +98,7 @@ Ipc::Ipc()
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)),
@@ -82,12 +106,16 @@ Ipc::Ipc()
82 host = true; 106 host = true;
83} 107}
84 108
109#endif
110
111
112#ifndef PWM_EMBEDDED
113
85Ipc::Ipc(const Ipc *ipc) 114Ipc::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) {
@@ -102,7 +130,19 @@ Ipc::Ipc(const Ipc *ipc)
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
142Ipc::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) {
@@ -110,41 +150,65 @@ Ipc::Ipc(const Ipc *ipc)
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
125Ipc::~Ipc() 173Ipc::~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
138void Ipc::receiveData(int s) 192void 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
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
@@ -20,10 +20,14 @@
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
28class QSocketNotifier; 32class QSocketNotifier;
29 33
@@ -44,8 +48,13 @@ public:
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
50signals: 59signals:
51 /** a line is available */ 60 /** a line is available */
@@ -56,18 +65,25 @@ protected slots:
56 void receiveData(int s); 65 void receiveData(int s);
57 66
58protected: 67protected:
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
@@ -2434,6 +2434,7 @@ PwMerror PwMDoc::importFromText(const QString *file, int format)
2434 2434
2435PwMerror PwMDoc::importText_PwM(const QString *file) 2435PwMerror 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;
@@ -2565,6 +2566,147 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
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
2570bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2712bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)