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 @@ -21,18 +21,26 @@ #define __GLOBALSTUFF_H #ifndef PWM_EMBEDDED #include "config.h" #endif #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 class QWidget; void no_keycard_support_msg_box(QWidget *parentWidget); #endif // CONFIG_KEYCARD #ifdef PROG_NAME # undef PROG_NAME @@ -67,24 +75,37 @@ void no_keycard_support_msg_box(QWidget *parentWidget); #define PARAM_UNUSED(x) (void)x /** return the number of elements in an array */ #ifdef array_size # undef array_size #endif #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 */ template<class T> inline void delete_and_null(T *&p) { delete p; p = 0; } 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 @@ * $Id$ **************************************************************************/ #include "ipc.h" #include "pwmexception.h" #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() : stream (0) , notifier (0) , rdBuf (0) { -#ifndef PWM_EMBEDDED if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) { throw PwMException(PwMException::EX_GENERIC, "Ipc: socketpair() failed"); } rdBufSize = INIT_LINEBUF_LEN; rdBuf = static_cast<char *>(malloc(rdBufSize)); if (!rdBuf) { close(sock[0]); @@ -51,102 +56,161 @@ Ipc::Ipc() stream = fdopen(sock[0], "r"); if (!stream) { close(sock[0]); close(sock[1]); free(rdBuf); throw PwMException(PwMException::EX_GENERIC, "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)); if (!rdBuf) { close(sock[0]); close(sock[1]); qDebug("Ipc: OOM"); } + + qsock = new QSocket(); + qsock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); if (!stream) { close(sock[0]); close(sock[1]); free(rdBuf); qDebug("Ipc: fdopen() failed"); } -#endif + */ notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); connect(notifier, SIGNAL(activated(int)), this, SLOT(receiveData(int))); host = true; } +#endif + + +#ifndef PWM_EMBEDDED + Ipc::Ipc(const Ipc *ipc) : stream (0) , notifier (0) , rdBuf (0) { -#ifndef PWM_EMBEDDED rdBufSize = INIT_LINEBUF_LEN; rdBuf = static_cast<char *>(malloc(rdBufSize)); if (!rdBuf) { throw PwMException(PwMException::EX_GENERIC, "Ipc: OOM"); } sock[0] = ipc->sock[1]; sock[1] = ipc->sock[0]; stream = fdopen(sock[0], "r"); if (!stream) { free(rdBuf); throw PwMException(PwMException::EX_GENERIC, "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)); if (!rdBuf) { qDebug("Ipc: OOM"); } 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) { free(rdBuf); qDebug("Ipc: fdopen() failed"); } -#endif + */ + notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); connect(notifier, SIGNAL(activated(int)), this, SLOT(receiveData(int))); host = false; } +#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."); + } #ifndef PWM_EMBEDDED #include "ipc.moc" #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 @@ * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __PWM_IPC_H #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; /** very simple interprocess communication class */ class Ipc : public QObject { Q_OBJECT public: @@ -39,35 +43,47 @@ public: */ Ipc(const Ipc *ipc); /** destructor */ ~Ipc(); /** send data to the other socket end * (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: /** a line is available */ void lineAvailable(const char *buf, size_t size); protected slots: /** received data on socket */ void receiveData(int s); 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; /** are we the host or the client object? */ bool host; /** receive buffer */ char *rdBuf; - /** current receive buffer size */ - size_t rdBufSize; }; #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) // add next format here... return e_fileFormat; } return e_invalidArg; } PwMerror PwMDoc::importText_PwM(const QString *file) { +#ifndef PWM_EMBEDDED PWM_ASSERT(file); FILE *f; int tmp; ssize_t ret; string curCat; unsigned int entriesRead = 0; PwMDataItem currItem; f = fopen(file->latin1(), "r"); @@ -2560,16 +2561,157 @@ PwMerror PwMDoc::importText_PwM(const QString *file) fclose(f); flagDirty(); return e_success; formatError: free(ch_tmp); 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 + } bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) { PWM_ASSERT(in && out); ssize_t i = 0, len = in_size - 1; while (i < len) { if (in[i] == ':') |