summaryrefslogtreecommitdiffabout
Side-by-side diff
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
@@ -23,14 +23,22 @@
#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
@@ -69,20 +77,33 @@ void no_keycard_support_msg_box(QWidget *parentWidget);
/** 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;
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
@@ -19,26 +19,31 @@
#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));
@@ -53,44 +58,67 @@ Ipc::Ipc()
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");
}
@@ -99,54 +127,90 @@ Ipc::Ipc(const Ipc *ipc)
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
@@ -17,16 +17,20 @@
* $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
{
@@ -41,33 +45,45 @@ public:
/** 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
@@ -2431,12 +2431,13 @@ PwMerror PwMDoc::importFromText(const QString *file, int format)
}
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;
@@ -2562,12 +2563,153 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
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;