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 @@ -27,6 +27,14 @@ #include "compiler.h" + //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 #ifndef CONFIG_KEYCARD @@ -73,12 +81,25 @@ void no_keycard_support_msg_box(QWidget *parentWidget); #define array_size(x) (sizeof(x) / sizeof((x)[0])) +//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 */ template <class T> inline std::string tostr(const T &t) { - std::ostringstream s; - s << t; - return s.str(); + QString result; + QTextOStream(&result) << t; + return result.latin1(); } +#endif /** delete the memory and NULL the pointer */ 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 @@ -23,11 +23,17 @@ #include <qsocketnotifier.h> -#include <sys/types.h> #include <sys/socket.h> + +#ifndef PWM_EMBEDDED +#include <sys/types.h> #include <stdio.h> +#else +#include <qsocket.h> +#endif #define END_OF_LINE '\n' #define INIT_LINEBUF_LEN 64 /* byte */ +#ifndef PWM_EMBEDDED Ipc::Ipc() @@ -36,5 +42,4 @@ Ipc::Ipc() , rdBuf (0) { -#ifndef PWM_EMBEDDED if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { throw PwMException(PwMException::EX_GENERIC, @@ -57,8 +62,22 @@ Ipc::Ipc() "Ipc: fdopen() failed"); } + + 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)) { qDebug("Ipc: socketpair() failed"); } + + QSocket* qsock = new QSocket(); + qsock->setSocket(sock[0]); + rdBufSize = INIT_LINEBUF_LEN; rdBuf = (char *)(malloc(rdBufSize)); @@ -68,4 +87,9 @@ Ipc::Ipc() qDebug("Ipc: OOM"); } + + qsock = new QSocket(); + qsock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); if (!stream) { @@ -75,5 +99,5 @@ Ipc::Ipc() qDebug("Ipc: fdopen() failed"); } -#endif + */ notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); @@ -83,4 +107,9 @@ Ipc::Ipc() } +#endif + + +#ifndef PWM_EMBEDDED + Ipc::Ipc(const Ipc *ipc) : stream (0) @@ -88,5 +117,4 @@ Ipc::Ipc(const Ipc *ipc) , rdBuf (0) { -#ifndef PWM_EMBEDDED rdBufSize = INIT_LINEBUF_LEN; rdBuf = static_cast<char *>(malloc(rdBufSize)); @@ -103,5 +131,17 @@ Ipc::Ipc(const Ipc *ipc) "Ipc: fdopen() failed"); } + + 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; rdBuf = (char *)(malloc(rdBufSize)); @@ -111,4 +151,9 @@ Ipc::Ipc(const Ipc *ipc) sock[0] = ipc->sock[1]; sock[1] = ipc->sock[0]; + + qSock = new QSocket(); + qSock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); if (!stream) { @@ -116,5 +161,6 @@ Ipc::Ipc(const Ipc *ipc) qDebug("Ipc: fdopen() failed"); } -#endif + */ + notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); connect(notifier, SIGNAL(activated(int)), @@ -123,27 +169,45 @@ Ipc::Ipc(const Ipc *ipc) } +#endif + Ipc::~Ipc() { +#ifdef PWM_EMBEDDED + delete qSock; +#endif delete_ifnot_null(notifier); if (rdBuf) free(rdBuf); +#ifndef PWM_EMBEDDED if (stream) fclose(stream); +#endif if (host) { close(sock[0]); close(sock[1]); } + } 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)) { emit lineAvailable(rdBuf, rd); } +#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 @@ -21,8 +21,12 @@ #define __PWM_IPC_H +#include <qobject.h> #include <unistd.h> -#include <qobject.h> +#ifndef PWM_EMBEDDED #include <stdio.h> +#else +#include <qsocket.h> +#endif class QSocketNotifier; @@ -45,6 +49,11 @@ public: * (To the connected ipc object) */ +#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 signals: @@ -57,8 +66,17 @@ 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 */ QSocketNotifier *notifier; @@ -67,6 +85,4 @@ protected: /** receive buffer */ 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 @@ -2435,4 +2435,5 @@ PwMerror PwMDoc::importFromText(const QString *file, int format) PwMerror PwMDoc::importText_PwM(const QString *file) { +#ifndef PWM_EMBEDDED PWM_ASSERT(file); FILE *f; @@ -2566,4 +2567,145 @@ PwMerror PwMDoc::importText_PwM(const QString *file) fclose(f); 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 + } |