From c2fb960297c4b08980921c818a4d347057732390 Mon Sep 17 00:00:00 2001 From: ulf69 Date: Fri, 15 Oct 2004 05:30:12 +0000 Subject: replaced system calls that do nto comply with gcc2.95 --- 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 @@ #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 + +#ifndef PWM_EMBEDDED #include +#else +#include +#include +#endif #ifndef CONFIG_KEYCARD class QWidget; @@ -72,14 +80,27 @@ void no_keycard_support_msg_box(QWidget *parentWidget); #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 inline +std::string tostr(const T &t) +{ + std::ostringstream s; + s << t; + return s.str(); +} +#else /** convert something to string using ostringstream */ template 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 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 @@ #include -#include #include + +#ifndef PWM_EMBEDDED +#include #include +#else +#include +#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"); @@ -56,10 +61,24 @@ Ipc::Ipc() 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) { @@ -67,6 +86,11 @@ Ipc::Ipc() close(sock[1]); qDebug("Ipc: OOM"); } + + qsock = new QSocket(); + qsock->setSocket(sock[0]); + + /*US stream = fdopen(sock[0], "r"); if (!stream) { close(sock[0]); @@ -74,7 +98,7 @@ Ipc::Ipc() free(rdBuf); qDebug("Ipc: fdopen() failed"); } -#endif + */ notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read); connect(notifier, SIGNAL(activated(int)), @@ -82,12 +106,16 @@ Ipc::Ipc() 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(malloc(rdBufSize)); if (!rdBuf) { @@ -102,7 +130,19 @@ Ipc::Ipc(const Ipc *ipc) 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) { @@ -110,41 +150,65 @@ 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) { 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 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 @@ #ifndef __PWM_IPC_H #define __PWM_IPC_H +#include #include -#include +#ifndef PWM_EMBEDDED #include +#else +#include +#endif class QSocketNotifier; @@ -44,8 +48,13 @@ public: /** 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 */ @@ -56,18 +65,25 @@ protected slots: 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 @@ -2434,6 +2434,7 @@ PwMerror PwMDoc::importFromText(const QString *file, int format) PwMerror PwMDoc::importText_PwM(const QString *file) { +#ifndef PWM_EMBEDDED PWM_ASSERT(file); FILE *f; int tmp; @@ -2565,6 +2566,147 @@ PwMerror PwMDoc::importText_PwM(const QString *file) 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) -- cgit v0.9.0.2