summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-15 05:30:12 (UTC)
committer ulf69 <ulf69>2004-10-15 05:30:12 (UTC)
commitc2fb960297c4b08980921c818a4d347057732390 (patch) (unidiff)
treeb96dba18fa1af192eeb4bd2da0b2dc1805cf3c96
parent6b6545368e5a5746c6fec02bb8d0708333f894e0 (diff)
downloadkdepimpi-c2fb960297c4b08980921c818a4d347057732390.zip
kdepimpi-c2fb960297c4b08980921c818a4d347057732390.tar.gz
kdepimpi-c2fb960297c4b08980921c818a4d347057732390.tar.bz2
replaced system calls that do nto comply with gcc2.95
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
@@ -28,4 +28,12 @@
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
@@ -74,2 +82,14 @@ void no_keycard_support_msg_box(QWidget *parentWidget);
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 */
@@ -78,6 +98,7 @@ 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
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
@@ -24,5 +24,10 @@
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
@@ -31,2 +36,3 @@
31 36
37#ifndef PWM_EMBEDDED
32 38
@@ -37,3 +43,2 @@ Ipc::Ipc()
37{ 43{
38#ifndef PWM_EMBEDDED
39 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { 44 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) {
@@ -58,3 +63,13 @@ Ipc::Ipc()
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)) {
@@ -62,2 +77,6 @@ Ipc::Ipc()
62 } 77 }
78
79 QSocket* qsock = new QSocket();
80 qsock->setSocket(sock[0]);
81
63 rdBufSize = INIT_LINEBUF_LEN; 82 rdBufSize = INIT_LINEBUF_LEN;
@@ -69,2 +88,7 @@ Ipc::Ipc()
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");
@@ -76,3 +100,3 @@ Ipc::Ipc()
76 } 100 }
77#endif 101 */
78 102
@@ -84,2 +108,7 @@ Ipc::Ipc()
84 108
109#endif
110
111
112#ifndef PWM_EMBEDDED
113
85Ipc::Ipc(const Ipc *ipc) 114Ipc::Ipc(const Ipc *ipc)
@@ -89,3 +118,2 @@ Ipc::Ipc(const Ipc *ipc)
89{ 118{
90#ifndef PWM_EMBEDDED
91 rdBufSize = INIT_LINEBUF_LEN; 119 rdBufSize = INIT_LINEBUF_LEN;
@@ -104,3 +132,15 @@ Ipc::Ipc(const Ipc *ipc)
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;
@@ -112,2 +152,7 @@ Ipc::Ipc(const Ipc *ipc)
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");
@@ -117,3 +162,4 @@ Ipc::Ipc(const Ipc *ipc)
117 } 162 }
118#endif 163 */
164
119 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); 165 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
@@ -124,4 +170,9 @@ Ipc::Ipc(const Ipc *ipc)
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);
@@ -129,4 +180,6 @@ Ipc::~Ipc()
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) {
@@ -135,2 +188,3 @@ Ipc::~Ipc()
135 } 188 }
189
136} 190}
@@ -139,7 +193,8 @@ 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)) {
@@ -147,2 +202,11 @@ void Ipc::receiveData(int s)
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}
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
@@ -22,6 +22,10 @@
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
@@ -46,4 +50,9 @@ public:
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
@@ -58,6 +67,15 @@ protected slots:
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 */
@@ -68,4 +86,2 @@ protected:
68 char *rdBuf; 86 char *rdBuf;
69 /** current receive buffer size */
70 size_t rdBufSize;
71}; 87};
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
@@ -2436,2 +2436,3 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
2436{ 2436{
2437#ifndef PWM_EMBEDDED
2437 PWM_ASSERT(file); 2438 PWM_ASSERT(file);
@@ -2567,2 +2568,143 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
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}