author | ulf69 <ulf69> | 2004-10-15 05:30:12 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-15 05:30:12 (UTC) |
commit | c2fb960297c4b08980921c818a4d347057732390 (patch) (side-by-side diff) | |
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 @@ -28,4 +28,12 @@ + //US BUG: the following code caused compile errors with certain gcccompilers (2.95). + // Because of that I replaced it with a Qt version, which should do the same. #include <string> + +#ifndef PWM_EMBEDDED #include <sstream> +#else +#include <qstring.h> +#include <qtextstream.h> +#endif @@ -74,2 +82,14 @@ void no_keycard_support_msg_box(QWidget *parentWidget); +//US BUG: the following code caused compile errors with certain gcccompilers (2.95). +// Because of that I replaced it with a Qt version, which should do the same. +#ifndef PWM_EMBEDDED +/** convert something to string using ostringstream */ +template <class T> inline +std::string tostr(const T &t) +{ + std::ostringstream s; + s << t; + return s.str(); +} +#else /** convert something to string using ostringstream */ @@ -78,6 +98,7 @@ std::string tostr(const T &t) { - std::ostringstream s; - s << t; - return s.str(); + QString result; + QTextOStream(&result) << t; + return result.latin1(); } +#endif 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 @@ -#include <sys/types.h> #include <sys/socket.h> + +#ifndef PWM_EMBEDDED +#include <sys/types.h> #include <stdio.h> +#else +#include <qsocket.h> +#endif @@ -31,2 +36,3 @@ +#ifndef PWM_EMBEDDED @@ -37,3 +43,2 @@ Ipc::Ipc() { -#ifndef PWM_EMBEDDED if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { @@ -58,3 +63,13 @@ Ipc::Ipc() } + + notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); + connect(notifier, SIGNAL(activated(int)), + this, SLOT(receiveData(int))); + host = true; +} #else +Ipc::Ipc() + : notifier (0) + , rdBuf (0) +{ if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { @@ -62,2 +77,6 @@ Ipc::Ipc() } + + QSocket* qsock = new QSocket(); + qsock->setSocket(sock[0]); + rdBufSize = INIT_LINEBUF_LEN; @@ -69,2 +88,7 @@ Ipc::Ipc() } + + qsock = new QSocket(); + qsock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); @@ -76,3 +100,3 @@ Ipc::Ipc() } -#endif + */ @@ -84,2 +108,7 @@ Ipc::Ipc() +#endif + + +#ifndef PWM_EMBEDDED + Ipc::Ipc(const Ipc *ipc) @@ -89,3 +118,2 @@ Ipc::Ipc(const Ipc *ipc) { -#ifndef PWM_EMBEDDED rdBufSize = INIT_LINEBUF_LEN; @@ -104,3 +132,15 @@ Ipc::Ipc(const Ipc *ipc) } + + notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); + connect(notifier, SIGNAL(activated(int)), + this, SLOT(receiveData(int))); + host = false; +} + #else + +Ipc::Ipc(const Ipc *ipc) + : notifier (0) + , rdBuf (0) +{ rdBufSize = INIT_LINEBUF_LEN; @@ -112,2 +152,7 @@ Ipc::Ipc(const Ipc *ipc) sock[1] = ipc->sock[0]; + + qSock = new QSocket(); + qSock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); @@ -117,3 +162,4 @@ Ipc::Ipc(const Ipc *ipc) } -#endif + */ + notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); @@ -124,4 +170,9 @@ Ipc::Ipc(const Ipc *ipc) +#endif + Ipc::~Ipc() { +#ifdef PWM_EMBEDDED + delete qSock; +#endif delete_ifnot_null(notifier); @@ -129,4 +180,6 @@ Ipc::~Ipc() free(rdBuf); +#ifndef PWM_EMBEDDED if (stream) fclose(stream); +#endif if (host) { @@ -135,2 +188,3 @@ Ipc::~Ipc() } + } @@ -139,7 +193,8 @@ void Ipc::receiveData(int s) { - ssize_t rd; - PWM_ASSERT(s == sock[0]); PARAM_UNUSED(s); - rd = getline(&rdBuf, &rdBufSize, stream); +#ifndef PWM_EMBEDDED + ssize_t rd; + + rd = ::getline(&rdBuf, &rdBufSize, stream); if (likely(rd > 0)) { @@ -147,2 +202,11 @@ void Ipc::receiveData(int s) } +#else + int rd; + rd = qSock->readLine(rdBuf, rdBufSize); + if (rd > 0) { + emit lineAvailable(rdBuf, rd); + } +#endif + qDebug("void Ipc::receiveData(int s) has to be implemented."); + } 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 @@ +#include <qobject.h> #include <unistd.h> -#include <qobject.h> +#ifndef PWM_EMBEDDED #include <stdio.h> +#else +#include <qsocket.h> +#endif @@ -46,4 +50,9 @@ public: */ +#ifndef PWM_EMBEDDED void send(const char *buf, size_t size) { write(sock[0], buf, size); } +#else + void send(const char *buf, size_t size) + { qSock->writeBlock(buf, size); } +#endif @@ -58,6 +67,15 @@ protected slots: protected: - /** full-duplex socket file desciptors */ - int sock[2]; +#ifndef PWM_EMBEDDED /** stream on "this" end of the socket (sock[0]) */ FILE *stream; + /** current receive buffer size */ + size_t rdBufSize; +#else + QSocket* qSock; + /** current receive buffer size */ + unsigned int rdBufSize; +#endif + + /** full-duplex socket file desciptors */ + int sock[2]; /** socket notifier */ @@ -68,4 +86,2 @@ protected: char *rdBuf; - /** current receive buffer size */ - size_t rdBufSize; }; 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) { +#ifndef PWM_EMBEDDED PWM_ASSERT(file); @@ -2567,2 +2568,143 @@ PwMerror PwMDoc::importText_PwM(const QString *file) return e_fileFormat; +#else + PWM_ASSERT(file); + QFile f(file->latin1()); + int tmp; + ssize_t ret; + string curCat; + unsigned int entriesRead = 0; + PwMDataItem currItem; + bool res = f.open(IO_ReadOnly); + if (res == false) + return e_openFile; + + unsigned int ch_tmp_size = 1024; + char *ch_tmp = (char*)malloc(ch_tmp_size); + if (!ch_tmp) { + f.close(); + return e_outOfMem; + } + + // - check header + if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. + goto formatError; + + //US read fileversion first, then check if ok. + if (f.readLine(ch_tmp, ch_tmp_size) == -1) + goto formatError; + + // check version-string and return version in "ch_tmp". + //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { + //US // header not recognized as PwM generated header + //US goto formatError; + //US } + //US set filepointer behind version-string-line previously checked + //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) + //US goto formatError; + // skip next line containing the build-date + if (f.readLine(ch_tmp, ch_tmp_size) == -1) + goto formatError; + // read header termination line + if (f.readLine(ch_tmp, ch_tmp_size) == -1) + goto formatError; + if (strcmp(ch_tmp, "==============================\n")) + goto formatError; + + // - read entries + do { + // find beginning of next category + do { + tmp = f.getch(); + } while (tmp == '\n' && tmp != EOF); + if (tmp == EOF) + break; + + // decrement filepos by one + f.at(f.at()-1); + // read cat-name + if (f.readLine(ch_tmp, ch_tmp_size) == -1) + goto formatError; + // check cat-name format + if (memcmp(ch_tmp, "== Category: ", 13) != 0) + goto formatError; + if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) + goto formatError; + // copy cat-name + curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); + + do { + // find beginning of next entry + do { + tmp = f.getch(); + } while (tmp == '\n' && tmp != EOF && tmp != '='); + if (tmp == EOF) + break; + if (tmp == '=') { + f.at(f.at()-1); + break; + } + // decrement filepos by one + f.at(f.at()-1); + // read desc-line + if (f.readLine(ch_tmp, ch_tmp_size) == -1) + goto formatError; + // check desc-line format + if (memcmp(ch_tmp, "-- ", 3) != 0) + goto formatError; + if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) + goto formatError; + // add desc-line + currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); + + // read username-line + if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) + goto formatError; + if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) + goto formatError; + + // read pw-line + if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) + goto formatError; + if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) + goto formatError; + + // read comment-line + if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) + goto formatError; + if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) + goto formatError; + + // read URL-line + if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) + goto formatError; + if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) + goto formatError; + + // read launcher-line + if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) + goto formatError; + if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) + goto formatError; + + currItem.lockStat = true; + currItem.listViewPos = -1; + addEntry(curCat.c_str(), &currItem, true); + ++entriesRead; + } while (1); + } while (1); + if (!entriesRead) + goto formatError; + + free(ch_tmp); + f.close(); + flagDirty(); + return e_success; + + formatError: + free(ch_tmp); + f.close(); + return e_fileFormat; + +#endif + } |