[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/network/kmldonkey
From: Aleksey Markelov <markelovai () gmail ! com>
Date: 2009-07-01 19:59:03
Message-ID: 1246478343.221336.20105.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 990142 by amarkelov:
moved common reading operations to DonkeyMessage, fixed callback object owners issue.
M +2 -1 kmldonkey/serverpage.cpp
M +1 -0 kmldonkey/statspageclients.cpp
M +1 -0 kmldonkey/statspageclients.h
M +1 -4 libkmldonkey/clientinfo.cpp
M +35 -11 libkmldonkey/donkeymessage.cpp
M +11 -0 libkmldonkey/donkeymessage.h
M +4 -1 libkmldonkey/donkeyprotocol.cpp
M +6 -15 libkmldonkey/fileinfo.cpp
M +3 -5 libkmldonkey/fileinfo.h
M +10 -16 libkmldonkey/shareinfo.cpp
--- trunk/extragear/network/kmldonkey/kmldonkey/serverpage.cpp #990141:990142
@@ -142,9 +142,10 @@
networkUpdated(0);
action = new KAction(KIcon("list-remove"), i18n("&Remove Server"), this);
- actionCollection->addAction("connect_server", action);
+ actionCollection->addAction("remove_server", action);
connect(action, SIGNAL(triggered()), this, SLOT(actionRemoveServer()));
serverActions.append(action);
+ KMLDonkey::App->addCoreAction(action);
action = new KAction(KIcon("edit-clear"), i18n("Remove &Old Servers"), this);
actionCollection->addAction("remove_old_servers", action);
--- trunk/extragear/network/kmldonkey/kmldonkey/statspageclients.cpp #990141:990142
@@ -121,6 +121,7 @@
{
if (! page) return;
delete page->box;
+ page->callback = 0;
page->box = new KVBox();
QStringList groups = res.split("\n\n");
--- trunk/extragear/network/kmldonkey/kmldonkey/statspageclients.h #990141:990142
@@ -84,6 +84,7 @@
void hideEvent(QHideEvent*);
private:
StatsPageClientsCallback *callback;
+ friend class StatsPageClientsCallback;
};
#endif
--- trunk/extragear/network/kmldonkey/libkmldonkey/clientinfo.cpp #990141:990142
@@ -39,10 +39,7 @@
} break;
case 1: {
QString name = msg->readString();
- QByteArray md4;
- md4.resize(16);
- for (int i = 0; i < 16; i++)
- md4[i] = msg->readInt8();
+ QByteArray md4 = msg->readMd4();
kind = "INDIRECT:" + FileInfo::md4ToString(md4) + ":" + name;
} break;
default:
--- trunk/extragear/network/kmldonkey/libkmldonkey/donkeymessage.cpp #990141:990142
@@ -25,6 +25,7 @@
#include <QHostAddress>
#include <QTextCodec>
#include <QtEndian>
+#include <QStringList>
#include <kdebug.h>
@@ -35,6 +36,7 @@
template <typename T>
T help_readInt(DonkeyMessage *msg)
{
+ Q_ASSERT(msg->m_pos + sizeof(T) <= (uint)msg->m_data.size());
T result = qFromLittleEndian<T>((const uchar*)( msg->m_data.constData() + \
msg->m_pos )); msg->m_pos += sizeof(T);
return result;
@@ -205,27 +207,49 @@
return codec->toUnicode( readByteArray(ok) );
}
-QByteArray DonkeyMessage::readByteArray(bool* ok)
+
+QStringList DonkeyMessage::readStringList(bool *ok)
{
- int sz = (int)readInt16();
- if (sz == 0xffff) sz = (int)readInt32();
+ int size = readInt16();
+ QStringList result;
+ for (int i = 0; i < size; ++i) {
+ result << readString(ok);
+ }
+ return result;
+}
- if ((m_pos + sz) > m_data.size()) {
- QString foo(kBacktrace());
- QString msg(dumpArray());
- kDebug() << "Position " << m_pos + sz << " exceeds buffer size " << \
m_data.size() << "\nMessage: " << msg << "\nBT: " << foo;
- if(ok) {
+QByteArray help_readArray(DonkeyMessage *msg, int size, bool *ok)
+{
+
+ if (msg->m_data.size() < msg->m_pos + size) {
+ kDebug() << "Position " << msg->m_pos + size
+ << "exceeds buffer size " << msg->m_data.size()
+ << "\nMessage: " << msg->dumpArray() << kBacktrace();
+ if (ok) {
*ok = false;
return QByteArray();
}
kFatal() << "Invalid index access.";
}
- QByteArray buf = m_data.mid(m_pos,sz);
- m_pos += sz;
- return buf;
+ QByteArray result = msg->m_data.mid(msg->m_pos,size);
+ msg->m_pos += size;
+ return result;
}
+QByteArray DonkeyMessage::readByteArray(bool* ok)
+{
+ int sz = (int)readInt16();
+ if (sz == 0xffff) sz = (int)readInt32();
+
+ return help_readArray(this, sz, ok);
+}
+
+QByteArray DonkeyMessage::readMd4(bool *ok)
+{
+ return help_readArray(this, 16, ok);
+}
+
int DonkeyMessage::readDate()
{
return QDateTime::currentDateTime().toTime_t() - readInt32();
--- trunk/extragear/network/kmldonkey/libkmldonkey/donkeymessage.h #990141:990142
@@ -115,6 +115,12 @@
* set to FALSE; otherwise *ok is set to TRUE.
* \return A string. */
QString readString(bool* ok = 0);
+ /** Read a string list from the message.
+ * \param ok If ok is not 0: if a "buffer exceeds size"-error occurs, *ok is
+ * set to FALSE; otherwise *ok is set to TRUE.
+ * \return A string list.
+ */
+ QStringList readStringList(bool *ok = 0);
//! Read a byte array from the message.
/*! This is essentially the same as reading a string, but it's not processed
* by the charset decoder.
@@ -122,6 +128,10 @@
* set to FALSE; otherwise *ok is set to TRUE.
* \return A byte array. */
QByteArray readByteArray(bool* ok = 0);
+ /** Read a md4 hash from the message.
+ * same as reading byte array, but no size field
+ */
+ QByteArray readMd4(bool *ok = 0);
//! Read a time_t-value.
/*! This is similar to readInt32() except that it does substract
* the actual time_t as defined with protocol >= 24 to get
@@ -168,6 +178,7 @@
template <typename T> friend T help_readInt(DonkeyMessage *msg);
template <typename T> friend void help_writeInt(DonkeyMessage *msg, T value);
+ friend QByteArray help_readArray(DonkeyMessage *msg, int size, bool *ok);
};
#endif
--- trunk/extragear/network/kmldonkey/libkmldonkey/donkeyprotocol.cpp #990141:990142
@@ -901,7 +901,10 @@
void DonkeyProtocol::sendConsoleMessage(const QString& msg, \
ConsoleCallbackInterface* callback) {
- if (callback) consoleCallbacks.insert(msg, callback);
+ if (callback) {
+ delete consoleCallbacks.take(msg);
+ consoleCallbacks.insert(msg, callback);
+ }
DonkeyMessage out(Command);
out.writeString(msg);
m_socket->sendMessage(out);
--- trunk/extragear/network/kmldonkey/libkmldonkey/fileinfo.cpp #990141:990142
@@ -24,8 +24,6 @@
#include <kdebug.h>
#include <klocale.h>
#include <QRegExp>
-//Added by qt3to4:
-#include <Q3ValueList>
#include <kglobal.h>
@@ -85,13 +83,8 @@
int i,j;
num = msg->readInt32();
network = msg->readInt32();
- j = msg->readInt16();
- names.clear();
- for (i=0; i<j; i++)
- names.append(msg->readString());
- QByteArray md4(16);
- for (i=0; i<16; i++)
- md4[i] = msg->readInt8();
+ names = msg->readStringList();
+ QByteArray md4 = msg->readMd4();
size = msg->readInt64();
downloaded = msg->readInt64();
if (first) {
@@ -239,11 +232,9 @@
priority = msg->readInt32();
if (priority > 0x40000000) priority -= 0x80000000;
comment = msg->readString();
- uids.clear();
- if (proto >= 31) {
- for (i = msg->readInt16(); i; i--)
- uids.append(msg->readString());
- } else uids.append(QString("urn:ed2k:") + md4ToString(md4));
+ uids = proto >= 31
+ ? uids = msg->readStringList()
+ : QStringList(QString("urn:ed2k:") + md4ToString(md4));
}
const int& FileInfo::fileNo() const
@@ -336,7 +327,7 @@
return speed;
}
-const Q3ValueList<time_t>& FileInfo::fileChunksAge() const
+const QList<time_t>& FileInfo::fileChunksAge() const
{
return chunks_age;
}
--- trunk/extragear/network/kmldonkey/libkmldonkey/fileinfo.h #990141:990142
@@ -25,9 +25,7 @@
#include <QString>
#include <QStringList>
-#include <q3valuelist.h>
-#include <qmap.h>
-#include <q3cstring.h>
+#include <QMap>
#include <sys/types.h>
#include <time.h>
@@ -96,7 +94,7 @@
//! Current download speed.
const double& fileSpeed() const;
//! The age of individual chunks.
- const Q3ValueList<time_t>& fileChunksAge() const;
+ const QList<time_t>& fileChunksAge() const;
//! The time the download was started (seconds since Epoch).
const time_t& fileAge() const;
//! The time the download was first seen (seconds since Epoch).
@@ -145,7 +143,7 @@
QByteArray chunks;
QMap<int,QByteArray> availability;
double speed;
- Q3ValueList<time_t> chunks_age;
+ QList<time_t> chunks_age;
time_t age, firsttime;
int format;
QString formatinfo;
--- trunk/extragear/network/kmldonkey/libkmldonkey/shareinfo.cpp #990141:990142
@@ -33,22 +33,15 @@
num = msg->readInt32();
network = msg->readInt32();
QByteArray ba = msg->readByteArray();
- ba.resize(ba.size() + 1); ba[ba.size()-1] = 0;
+ ba += '\0';
name = QFile::decodeName( QByteArray( ba.data(), ba.size() ) ); // the file is \
locally encoded size = msg->readInt64();
uploaded = msg->readInt64();
requests = msg->readInt32();
- uids.clear();
if (msg->opcode() >= 48) {
- if (proto >= 31) {
- for (int i = msg->readInt16(); i; i--)
- uids.append(msg->readString());
- } else {
- QByteArray md4(16);
- for (int i = 0; i < 16; i++)
- md4[i] = msg->readInt8();
- uids.append(QString("urn:ed2k:") + FileInfo::md4ToString(md4));
- }
+ uids = proto >= 31
+ ? msg->readStringList()
+ : QStringList( QString("urn:ed2k:") + FileInfo::md4ToString( \
msg->readMd4() ) ); }
}
@@ -87,16 +80,17 @@
QString ShareInfo::shareUid() const
{
- return uids.first();
+ return uids.isEmpty() ? QString() : uids.first();
}
QString ShareInfo::shareUid(const QString& type) const
{
QRegExp match(QString("^urn:") + type + ":");
- QStringList results = uids.grep(match);
- if (!results.count()) return QString::null;
- QString result(results.first());
- result.replace(match, "");
+ QStringList results = uids.filter(match);
+ if (!results.count()) return QString();
+
+ QString result = results.first();
+ result.remove(match);
return result;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic