mirror of https://github.com/aria2/aria2
2010-06-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed BDE and bencodepull/1/head
parent
8ba97188ce
commit
cb4e25e4b4
|
@ -1,3 +1,7 @@
|
||||||
|
2010-06-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Removed BDE and bencode
|
||||||
|
|
||||||
2010-06-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-06-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Introduced ValueBase class, which is a replacement of BDE. In
|
Introduced ValueBase class, which is a replacement of BDE. In
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
223
src/BDE.cc
223
src/BDE.cc
|
@ -1,223 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
|
|
||||||
#include "BDE.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
const BDE BDE::none;
|
|
||||||
|
|
||||||
BDE::BDE():_type(TYPE_NONE), _bobject(new BObject()) {}
|
|
||||||
|
|
||||||
BDE::BDE(Integer integer):_type(TYPE_INTEGER),
|
|
||||||
_bobject(new BInteger(integer)) {}
|
|
||||||
|
|
||||||
|
|
||||||
BDE::BDE(const std::string& string):_type(TYPE_STRING),
|
|
||||||
_bobject(new BString(std::string(string))) {}
|
|
||||||
|
|
||||||
BDE::BDE(const char* cstring):_type(TYPE_STRING),
|
|
||||||
_bobject(new BString(std::string(cstring))) {}
|
|
||||||
|
|
||||||
BDE::BDE(const char* data, size_t length):
|
|
||||||
_type(TYPE_STRING),
|
|
||||||
_bobject(new BString(std::string(&data[0], &data[length]))) {}
|
|
||||||
|
|
||||||
BDE::BDE(const unsigned char* data, size_t length):
|
|
||||||
_type(TYPE_STRING),
|
|
||||||
_bobject(new BString(std::string(&data[0], &data[length]))) {}
|
|
||||||
|
|
||||||
BDE BDE::dict()
|
|
||||||
{
|
|
||||||
BDE bde;
|
|
||||||
bde._type = TYPE_DICT;
|
|
||||||
bde._bobject.reset(new BDict());
|
|
||||||
return bde;
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE BDE::list()
|
|
||||||
{
|
|
||||||
BDE bde;
|
|
||||||
bde._type = TYPE_LIST;
|
|
||||||
bde._bobject.reset(new BList());
|
|
||||||
return bde;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test for Null data
|
|
||||||
bool BDE::isNone() const
|
|
||||||
{
|
|
||||||
return _type == TYPE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Integer Interface
|
|
||||||
|
|
||||||
bool BDE::isInteger() const
|
|
||||||
{
|
|
||||||
return _type == TYPE_INTEGER;
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::Integer BDE::i() const
|
|
||||||
{
|
|
||||||
return _bobject->i();
|
|
||||||
}
|
|
||||||
|
|
||||||
// String Interface
|
|
||||||
|
|
||||||
bool BDE::isString() const
|
|
||||||
{
|
|
||||||
return _type == TYPE_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& BDE::s() const
|
|
||||||
{
|
|
||||||
return _bobject->s();
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned char* BDE::uc() const
|
|
||||||
{
|
|
||||||
return _bobject->uc();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dictionary Interface
|
|
||||||
|
|
||||||
bool BDE::isDict() const
|
|
||||||
{
|
|
||||||
return _type == TYPE_DICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE& BDE::operator[](const std::string& key)
|
|
||||||
{
|
|
||||||
return _bobject->operator[](key);
|
|
||||||
}
|
|
||||||
|
|
||||||
const BDE& BDE::operator[](const std::string& key) const
|
|
||||||
{
|
|
||||||
if(_bobject->containsKey(key)) {
|
|
||||||
return _bobject->operator[](key);
|
|
||||||
} else {
|
|
||||||
return none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BDE::containsKey(const std::string& key) const
|
|
||||||
{
|
|
||||||
return _bobject->containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDE::removeKey(const std::string& key)
|
|
||||||
{
|
|
||||||
_bobject->removeKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::Dict::iterator BDE::dictBegin()
|
|
||||||
{
|
|
||||||
return _bobject->dictBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::Dict::const_iterator BDE::dictBegin() const
|
|
||||||
{
|
|
||||||
return _bobject->dictBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::Dict::iterator BDE::dictEnd()
|
|
||||||
{
|
|
||||||
return _bobject->dictEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::Dict::const_iterator BDE::dictEnd() const
|
|
||||||
{
|
|
||||||
return _bobject->dictEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
// List Interface
|
|
||||||
|
|
||||||
bool BDE::isList() const
|
|
||||||
{
|
|
||||||
return _type == TYPE_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDE::append(const BDE& bde)
|
|
||||||
{
|
|
||||||
_bobject->append(bde);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDE::operator<<(const BDE& bde)
|
|
||||||
{
|
|
||||||
_bobject->operator<<(bde);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE& BDE::operator[](size_t index)
|
|
||||||
{
|
|
||||||
return _bobject->operator[](index);
|
|
||||||
}
|
|
||||||
|
|
||||||
const BDE& BDE::operator[](size_t index) const
|
|
||||||
{
|
|
||||||
return _bobject->operator[](index);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::List::iterator BDE::listBegin()
|
|
||||||
{
|
|
||||||
return _bobject->listBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::List::const_iterator BDE::listBegin() const
|
|
||||||
{
|
|
||||||
return _bobject->listBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::List::iterator BDE::listEnd()
|
|
||||||
{
|
|
||||||
return _bobject->listEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE::List::const_iterator BDE::listEnd() const
|
|
||||||
{
|
|
||||||
return _bobject->listEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callable from List and Dict
|
|
||||||
size_t BDE::size() const
|
|
||||||
{
|
|
||||||
return _bobject->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callable from List and Dict
|
|
||||||
bool BDE::empty() const
|
|
||||||
{
|
|
||||||
return _bobject->empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
431
src/BDE.h
431
src/BDE.h
|
@ -1,431 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
#ifndef _D_BDE_H_
|
|
||||||
#define _D_BDE_H_
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
|
||||||
#include "DlAbortEx.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
class BDE;
|
|
||||||
|
|
||||||
class BDE {
|
|
||||||
public:
|
|
||||||
typedef std::map<std::string, BDE> Dict;
|
|
||||||
typedef std::vector<BDE> List;
|
|
||||||
typedef int64_t Integer;
|
|
||||||
private:
|
|
||||||
enum TYPE{
|
|
||||||
TYPE_NONE,
|
|
||||||
TYPE_INTEGER,
|
|
||||||
TYPE_STRING,
|
|
||||||
TYPE_DICT,
|
|
||||||
TYPE_LIST,
|
|
||||||
};
|
|
||||||
|
|
||||||
class BObject {
|
|
||||||
public:
|
|
||||||
virtual ~BObject() {}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Integer Interface
|
|
||||||
|
|
||||||
// Returns Integer.
|
|
||||||
virtual Integer i() const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Integer");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
// String Interface
|
|
||||||
|
|
||||||
// Returns std::string.
|
|
||||||
virtual const std::string& s() const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not String");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns std::string.data() casted to unsigned char*.
|
|
||||||
// Use s().size() to get length.
|
|
||||||
virtual const unsigned char* uc() const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not String");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Dictionary Interface
|
|
||||||
|
|
||||||
// Returns the reference to BDE object associated with given key.
|
|
||||||
// If the key is not found, new pair with that key is created
|
|
||||||
// using default values, which is then returned. In other words,
|
|
||||||
// this is the same behavior of std::map's operator[].
|
|
||||||
virtual BDE& operator[](const std::string& key)
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if the given key is found in dict.
|
|
||||||
virtual bool containsKey(const std::string& key) const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes specified key from dict.
|
|
||||||
virtual void removeKey(const std::string& key)
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the first pair in
|
|
||||||
// the dict.
|
|
||||||
virtual Dict::iterator dictBegin()
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to one past
|
|
||||||
// the last pair in the dict.
|
|
||||||
virtual Dict::iterator dictEnd()
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not Dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
// List Interface
|
|
||||||
|
|
||||||
// Appends given bde to list.
|
|
||||||
virtual void append(const BDE& bde)
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alias for append()
|
|
||||||
virtual void operator<<(const BDE& bde)
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the reference of the object at the given index.
|
|
||||||
virtual BDE& operator[](size_t index)
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the first object
|
|
||||||
// in list.
|
|
||||||
virtual List::iterator listBegin()
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the one past the
|
|
||||||
// last object in list.
|
|
||||||
virtual List::iterator listEnd()
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Not List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns size of list or dict.
|
|
||||||
virtual size_t size() const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Neither Dict nor List");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if size of list or dict is 0.
|
|
||||||
virtual bool empty() const
|
|
||||||
{
|
|
||||||
throw DL_ABORT_EX("Neither Dict nor List");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BInteger : public BObject {
|
|
||||||
private:
|
|
||||||
Integer _integer;
|
|
||||||
public:
|
|
||||||
BInteger(Integer i):_integer(i) {}
|
|
||||||
|
|
||||||
virtual BDE::Integer i() const
|
|
||||||
{
|
|
||||||
return _integer;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BString : public BObject {
|
|
||||||
private:
|
|
||||||
std::string _string;
|
|
||||||
public:
|
|
||||||
BString(const std::string& string):_string(string) {}
|
|
||||||
|
|
||||||
virtual const std::string& s() const
|
|
||||||
{
|
|
||||||
return _string;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const unsigned char* uc() const
|
|
||||||
{
|
|
||||||
return reinterpret_cast<const unsigned char*>(_string.data());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BDict : public BObject {
|
|
||||||
private:
|
|
||||||
Dict _dict;
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual BDE& operator[](const std::string& key)
|
|
||||||
{
|
|
||||||
return _dict[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool containsKey(const std::string& key) const
|
|
||||||
{
|
|
||||||
return _dict.find(key) != _dict.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void removeKey(const std::string& key)
|
|
||||||
{
|
|
||||||
_dict.erase(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BDE::Dict::iterator dictBegin()
|
|
||||||
{
|
|
||||||
return _dict.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BDE::Dict::iterator dictEnd()
|
|
||||||
{
|
|
||||||
return _dict.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t size() const
|
|
||||||
{
|
|
||||||
return _dict.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool empty() const
|
|
||||||
{
|
|
||||||
return _dict.empty();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BList : public BObject {
|
|
||||||
private:
|
|
||||||
List _list;
|
|
||||||
public:
|
|
||||||
virtual void append(const BDE& bde)
|
|
||||||
{
|
|
||||||
_list.push_back(bde);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void operator<<(const BDE& bde)
|
|
||||||
{
|
|
||||||
_list.push_back(bde);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BDE& operator[](size_t index)
|
|
||||||
{
|
|
||||||
return _list[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BDE::List::iterator listBegin()
|
|
||||||
{
|
|
||||||
return _list.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BDE::List::iterator listEnd()
|
|
||||||
{
|
|
||||||
return _list.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t size() const
|
|
||||||
{
|
|
||||||
return _list.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool empty() const
|
|
||||||
{
|
|
||||||
return _list.empty();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TYPE _type;
|
|
||||||
|
|
||||||
SharedHandle<BObject> _bobject;
|
|
||||||
public:
|
|
||||||
BDE();
|
|
||||||
|
|
||||||
static BDE dict();
|
|
||||||
|
|
||||||
static BDE list();
|
|
||||||
|
|
||||||
static const BDE none;
|
|
||||||
|
|
||||||
// Test for Null data
|
|
||||||
// Return true if the type of this object is None.
|
|
||||||
bool isNone() const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Integer Interface
|
|
||||||
|
|
||||||
BDE(Integer integer);
|
|
||||||
|
|
||||||
// Returns true if the type of this object is Integer.
|
|
||||||
bool isInteger() const;
|
|
||||||
|
|
||||||
// Returns Integer. Requires this object to be Integer.
|
|
||||||
Integer i() const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// String Interface
|
|
||||||
|
|
||||||
BDE(const std::string& string);
|
|
||||||
|
|
||||||
// Made explicit to avoid ambiguity with BDE(Integer).
|
|
||||||
explicit BDE(const char* cstring);
|
|
||||||
|
|
||||||
BDE(const char* data, size_t length);
|
|
||||||
|
|
||||||
BDE(const unsigned char* data, size_t length);
|
|
||||||
|
|
||||||
// Returns true if the type of this object is String.
|
|
||||||
bool isString() const;
|
|
||||||
|
|
||||||
// Returns std::string. Requires this object to be String
|
|
||||||
const std::string& s() const;
|
|
||||||
|
|
||||||
// Returns std::string.data() casted to unsigned char*.
|
|
||||||
// Use s().size() to get length.
|
|
||||||
const unsigned char* uc() const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Dictionary Interface
|
|
||||||
|
|
||||||
// Returns true if the type of this object is Dict.
|
|
||||||
bool isDict() const;
|
|
||||||
|
|
||||||
// Returns the reference to BDE object associated with given key.
|
|
||||||
// If the key is not found, new pair with that key is created using default
|
|
||||||
// values, which is then returned. In other words, this is the same behavior
|
|
||||||
// of std::map's operator[].
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
BDE& operator[](const std::string& key);
|
|
||||||
|
|
||||||
// Returns the const reference to BDE ojbect associated with given key.
|
|
||||||
// If the key is not found, BDE::none is returned.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
const BDE& operator[](const std::string& key) const;
|
|
||||||
|
|
||||||
// Returns true if the given key is found in dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
bool containsKey(const std::string& key) const;
|
|
||||||
|
|
||||||
// Removes specified key from dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
void removeKey(const std::string& key);
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the first pair in the dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
Dict::iterator dictBegin();
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to the first pair in
|
|
||||||
// the dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
Dict::const_iterator dictBegin() const;
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to one past the last
|
|
||||||
// pair in the dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
Dict::iterator dictEnd();
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to one past the last
|
|
||||||
// pair in the dict.
|
|
||||||
// Requires this object to be Dict.
|
|
||||||
Dict::const_iterator dictEnd() const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// List Interface
|
|
||||||
|
|
||||||
// Returns true if the type of this object is List.
|
|
||||||
bool isList() const;
|
|
||||||
|
|
||||||
// Appends given bde to list. Required the type of this object to be List.
|
|
||||||
void append(const BDE& bde);
|
|
||||||
|
|
||||||
// Alias for append()
|
|
||||||
void operator<<(const BDE& bde);
|
|
||||||
|
|
||||||
// Returns the reference of the object at the given index. Required this
|
|
||||||
// object to be List.
|
|
||||||
BDE& operator[](size_t index);
|
|
||||||
|
|
||||||
// Returns the const reference of the object at the given index.
|
|
||||||
// Required this object to be List.
|
|
||||||
const BDE& operator[](size_t index) const;
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the first object in list.
|
|
||||||
// Required this object to be List.
|
|
||||||
List::iterator listBegin();
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to the first object
|
|
||||||
// in list. Required this object to be List.
|
|
||||||
List::const_iterator listBegin() const;
|
|
||||||
|
|
||||||
// Returns a read/write iterator that points to the one past the last object
|
|
||||||
// in list. Required this object to be List.
|
|
||||||
List::iterator listEnd();
|
|
||||||
|
|
||||||
// Returns a read/write read-only iterator that points to the one past the
|
|
||||||
// last object in list. Required this object to be List.
|
|
||||||
List::const_iterator listEnd() const;
|
|
||||||
|
|
||||||
// For List type: Returns size of list.
|
|
||||||
// For Dict type: Returns size of dict.
|
|
||||||
size_t size() const;
|
|
||||||
|
|
||||||
// For List type: Returns true if size of list is 0.
|
|
||||||
// For Dict type: Returns true if size of dict is 0.
|
|
||||||
bool empty() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
||||||
|
|
||||||
#endif // _D_BDE_H_
|
|
|
@ -42,7 +42,7 @@
|
||||||
#include "DHTMessageFactory.h"
|
#include "DHTMessageFactory.h"
|
||||||
#include "DHTRoutingTable.h"
|
#include "DHTRoutingTable.h"
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -55,12 +55,12 @@ DHTAbstractMessage::~DHTAbstractMessage() {}
|
||||||
|
|
||||||
std::string DHTAbstractMessage::getBencodedMessage()
|
std::string DHTAbstractMessage::getBencodedMessage()
|
||||||
{
|
{
|
||||||
BDE msgDict = BDE::dict();
|
Dict msgDict;
|
||||||
msgDict[T] = getTransactionID();
|
msgDict.put(T, getTransactionID());
|
||||||
msgDict[Y] = getType();
|
msgDict.put(Y, getType());
|
||||||
msgDict[V] = getVersion();
|
msgDict.put(V, getVersion());
|
||||||
fillMessage(msgDict);
|
fillMessage(&msgDict);
|
||||||
return bencode::encode(msgDict);
|
return bencode2::encode(&msgDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DHTAbstractMessage::send()
|
bool DHTAbstractMessage::send()
|
||||||
|
@ -75,22 +75,26 @@ bool DHTAbstractMessage::send()
|
||||||
return r == static_cast<ssize_t>(message.size());
|
return r == static_cast<ssize_t>(message.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAbstractMessage::setConnection(const WeakHandle<DHTConnection>& connection)
|
void DHTAbstractMessage::setConnection
|
||||||
|
(const WeakHandle<DHTConnection>& connection)
|
||||||
{
|
{
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAbstractMessage::setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher)
|
void DHTAbstractMessage::setMessageDispatcher
|
||||||
|
(const WeakHandle<DHTMessageDispatcher>& dispatcher)
|
||||||
{
|
{
|
||||||
_dispatcher = dispatcher;
|
_dispatcher = dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAbstractMessage::setMessageFactory(const WeakHandle<DHTMessageFactory>& factory)
|
void DHTAbstractMessage::setMessageFactory
|
||||||
|
(const WeakHandle<DHTMessageFactory>& factory)
|
||||||
{
|
{
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAbstractMessage::setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable)
|
void DHTAbstractMessage::setRoutingTable
|
||||||
|
(const WeakHandle<DHTRoutingTable>& routingTable)
|
||||||
{
|
{
|
||||||
_routingTable = routingTable;
|
_routingTable = routingTable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,10 @@
|
||||||
|
|
||||||
#include "DHTMessage.h"
|
#include "DHTMessage.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BDE;
|
|
||||||
class DHTConnection;
|
class DHTConnection;
|
||||||
class DHTMessageDispatcher;
|
class DHTMessageDispatcher;
|
||||||
class DHTMessageFactory;
|
class DHTMessageFactory;
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
|
|
||||||
virtual const std::string& getType() const = 0;
|
virtual const std::string& getType() const = 0;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict) = 0;
|
virtual void fillMessage(Dict* msgDict) = 0;
|
||||||
|
|
||||||
std::string getBencodedMessage();
|
std::string getBencodedMessage();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "BtConstants.h"
|
#include "BtConstants.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -87,13 +86,13 @@ void DHTAnnouncePeerMessage::doReceivedAction()
|
||||||
getMessageDispatcher()->addMessageToQueue(reply);
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTAnnouncePeerMessage::getArgument()
|
SharedHandle<Dict> DHTAnnouncePeerMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
aDict->put(INFO_HASH, String::g(_infoHash, DHT_ID_LENGTH));
|
||||||
aDict[PORT] = _tcpPort;
|
aDict->put(PORT, Integer::g(_tcpPort));
|
||||||
aDict[TOKEN] = _token;
|
aDict->put(TOKEN, _token);
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual SharedHandle<Dict> getArgument();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "DHTAnnouncePeerReplyMessage.h"
|
#include "DHTAnnouncePeerReplyMessage.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -51,10 +50,10 @@ DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {}
|
||||||
|
|
||||||
void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
|
void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
|
||||||
|
|
||||||
BDE DHTAnnouncePeerReplyMessage::getResponse()
|
SharedHandle<Dict> DHTAnnouncePeerReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual SharedHandle<Dict> getResponse();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "DHTMessageDispatcher.h"
|
#include "DHTMessageDispatcher.h"
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -71,11 +70,11 @@ void DHTFindNodeMessage::doReceivedAction()
|
||||||
getMessageDispatcher()->addMessageToQueue(reply);
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTFindNodeMessage::getArgument()
|
SharedHandle<Dict> DHTFindNodeMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
aDict[TARGET_NODE] = BDE(_targetNodeID, DHT_ID_LENGTH);
|
aDict->put(TARGET_NODE, String::g(_targetNodeID, DHT_ID_LENGTH));
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual SharedHandle<Dict> getArgument();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -70,10 +69,10 @@ void DHTFindNodeReplyMessage::doReceivedAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTFindNodeReplyMessage::getResponse()
|
SharedHandle<Dict> DHTFindNodeReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
unsigned char buffer[DHTBucket::K*26];
|
unsigned char buffer[DHTBucket::K*26];
|
||||||
// TODO if _closestKNodes.size() > DHTBucket::K ??
|
// TODO if _closestKNodes.size() > DHTBucket::K ??
|
||||||
|
@ -87,7 +86,7 @@ BDE DHTFindNodeReplyMessage::getResponse()
|
||||||
offset += 26;
|
offset += 26;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aDict[NODES] = BDE(buffer, offset);
|
aDict->put(NODES, String::g(buffer, offset));
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual SharedHandle<Dict> getResponse();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "DHTTokenTracker.h"
|
#include "DHTTokenTracker.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -86,11 +85,11 @@ void DHTGetPeersMessage::doReceivedAction()
|
||||||
getMessageDispatcher()->addMessageToQueue(reply);
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTGetPeersMessage::getArgument()
|
SharedHandle<Dict> DHTGetPeersMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
aDict->put(INFO_HASH, String::g(_infoHash, DHT_ID_LENGTH));
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual SharedHandle<Dict> getArgument();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -73,11 +72,11 @@ void DHTGetPeersReplyMessage::doReceivedAction()
|
||||||
// Returned peers and nodes are handled in DHTPeerLookupTask.
|
// Returned peers and nodes are handled in DHTPeerLookupTask.
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTGetPeersReplyMessage::getResponse()
|
SharedHandle<Dict> DHTGetPeersReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
rDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
rDict[TOKEN] = _token;
|
rDict->put(TOKEN, _token);
|
||||||
if(_values.empty()) {
|
if(_values.empty()) {
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
unsigned char buffer[DHTBucket::K*26];
|
unsigned char buffer[DHTBucket::K*26];
|
||||||
|
@ -91,7 +90,7 @@ BDE DHTGetPeersReplyMessage::getResponse()
|
||||||
offset += 26;
|
offset += 26;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rDict[NODES] = BDE(buffer, offset);
|
rDict->put(NODES, String::g(buffer, offset));
|
||||||
} else {
|
} else {
|
||||||
// Limit the size of values list. The maxmum size of UDP datagram
|
// Limit the size of values list. The maxmum size of UDP datagram
|
||||||
// is limited to 65535 bytes. aria2 uses 20bytes token and 2byte
|
// is limited to 65535 bytes. aria2 uses 20bytes token and 2byte
|
||||||
|
@ -113,18 +112,18 @@ BDE DHTGetPeersReplyMessage::getResponse()
|
||||||
// template may get bigger than 87 bytes. So we use 100 as maximum
|
// template may get bigger than 87 bytes. So we use 100 as maximum
|
||||||
// number of peer info that a message can carry.
|
// number of peer info that a message can carry.
|
||||||
static const size_t MAX_VALUES_SIZE = 100;
|
static const size_t MAX_VALUES_SIZE = 100;
|
||||||
BDE valuesList = BDE::list();
|
SharedHandle<List> valuesList = List::g();
|
||||||
for(std::vector<SharedHandle<Peer> >::const_iterator i = _values.begin(),
|
for(std::vector<SharedHandle<Peer> >::const_iterator i = _values.begin(),
|
||||||
eoi = _values.end(); i != eoi && valuesList.size() < MAX_VALUES_SIZE;
|
eoi = _values.end(); i != eoi && valuesList->size() < MAX_VALUES_SIZE;
|
||||||
++i) {
|
++i) {
|
||||||
const SharedHandle<Peer>& peer = *i;
|
const SharedHandle<Peer>& peer = *i;
|
||||||
unsigned char buffer[6];
|
unsigned char buffer[6];
|
||||||
if(bittorrent::createcompact
|
if(bittorrent::createcompact
|
||||||
(buffer, peer->getIPAddress(), peer->getPort())) {
|
(buffer, peer->getIPAddress(), peer->getPort())) {
|
||||||
valuesList << BDE(buffer, sizeof(buffer));
|
valuesList->append(String::g(buffer, sizeof(buffer)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rDict[VALUES] = valuesList;
|
rDict->put(VALUES, valuesList);
|
||||||
}
|
}
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual SharedHandle<Dict> getResponse();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -50,19 +51,18 @@ class DHTQueryMessage;
|
||||||
class DHTResponseMessage;
|
class DHTResponseMessage;
|
||||||
class DHTNode;
|
class DHTNode;
|
||||||
class Peer;
|
class Peer;
|
||||||
class BDE;
|
|
||||||
|
|
||||||
class DHTMessageFactory {
|
class DHTMessageFactory {
|
||||||
public:
|
public:
|
||||||
virtual ~DHTMessageFactory() {}
|
virtual ~DHTMessageFactory() {}
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
createQueryMessage(const BDE& dict,
|
createQueryMessage(const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port) = 0;
|
const std::string& ipaddr, uint16_t port) = 0;
|
||||||
|
|
||||||
virtual SharedHandle<DHTResponseMessage>
|
virtual SharedHandle<DHTResponseMessage>
|
||||||
createResponseMessage(const std::string& messageType,
|
createResponseMessage(const std::string& messageType,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port) = 0;
|
const std::string& ipaddr, uint16_t port) = 0;
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -83,11 +82,10 @@ DHTMessageFactoryImpl::getRemoteNode
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getDictionary(const BDE& dict,
|
static const Dict* getDictionary(const Dict* dict, const std::string& key)
|
||||||
const std::string& key)
|
|
||||||
{
|
{
|
||||||
const BDE& d = dict[key];
|
const Dict* d = asDict(dict->get(key));
|
||||||
if(d.isDict()) {
|
if(d) {
|
||||||
return d;
|
return d;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -95,11 +93,10 @@ static const BDE& getDictionary(const BDE& dict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getString(const BDE& dict,
|
static const String* getString(const Dict* dict, const std::string& key)
|
||||||
const std::string& key)
|
|
||||||
{
|
{
|
||||||
const BDE& c = dict[key];
|
const String* c = asString(dict->get(key));
|
||||||
if(c.isString()) {
|
if(c) {
|
||||||
return c;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -107,11 +104,10 @@ static const BDE& getString(const BDE& dict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getInteger(const BDE& dict,
|
static const Integer* getInteger(const Dict* dict, const std::string& key)
|
||||||
const std::string& key)
|
|
||||||
{
|
{
|
||||||
const BDE& c = dict[key];
|
const Integer* c = asInteger(dict->get(key));
|
||||||
if(c.isInteger()) {
|
if(c) {
|
||||||
return c;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -119,10 +115,10 @@ static const BDE& getInteger(const BDE& dict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getString(const BDE& list, size_t index)
|
static const String* getString(const List* list, size_t index)
|
||||||
{
|
{
|
||||||
const BDE& c = list[index];
|
const String* c = asString(list->get(index));
|
||||||
if(c.isString()) {
|
if(c) {
|
||||||
return c;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -131,10 +127,10 @@ static const BDE& getString(const BDE& list, size_t index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getInteger(const BDE& list, size_t index)
|
static const Integer* getInteger(const List* list, size_t index)
|
||||||
{
|
{
|
||||||
const BDE& c = list[index];
|
const Integer* c = asInteger(list->get(index));
|
||||||
if(c.isInteger()) {
|
if(c) {
|
||||||
return c;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -143,11 +139,10 @@ static const BDE& getInteger(const BDE& list, size_t index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const BDE& getList(const BDE& dict,
|
static const List* getList(const Dict* dict, const std::string& key)
|
||||||
const std::string& key)
|
|
||||||
{
|
{
|
||||||
const BDE& l = dict[key];
|
const List* l = asList(dict->get(key));
|
||||||
if(l.isList()) {
|
if(l) {
|
||||||
return l;
|
return l;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -155,78 +150,73 @@ static const BDE& getList(const BDE& dict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageFactoryImpl::validateID(const BDE& id) const
|
void DHTMessageFactoryImpl::validateID(const String* id) const
|
||||||
{
|
{
|
||||||
if(id.s().size() != DHT_ID_LENGTH) {
|
if(id->s().size() != DHT_ID_LENGTH) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Malformed DHT message. Invalid ID length."
|
(StringFormat("Malformed DHT message. Invalid ID length."
|
||||||
" Expected:%d, Actual:%d",
|
" Expected:%d, Actual:%d",
|
||||||
DHT_ID_LENGTH, id.s().size()).str());
|
DHT_ID_LENGTH, id->s().size()).str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageFactoryImpl::validatePort(const BDE& i) const
|
void DHTMessageFactoryImpl::validatePort(const Integer* port) const
|
||||||
{
|
{
|
||||||
BDE::Integer port = i.i();
|
if(!(0 < port->i() && port->i() < UINT16_MAX)) {
|
||||||
if(!(0 < port && port < UINT16_MAX)) {
|
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Malformed DHT message. Invalid port=%s",
|
(StringFormat("Malformed DHT message. Invalid port=%s",
|
||||||
util::itos(port).c_str()).str());
|
util::itos(port->i()).c_str()).str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setVersion(const SharedHandle<DHTMessage>& msg, const BDE& dict)
|
static void setVersion(const SharedHandle<DHTMessage>& msg, const Dict* dict)
|
||||||
{
|
{
|
||||||
const BDE& v = dict[DHTMessage::V];
|
const String* v = asString(dict->get(DHTMessage::V));
|
||||||
if(v.isString()) {
|
if(v) {
|
||||||
msg->setVersion(v.s());
|
msg->setVersion(v->s());
|
||||||
} else {
|
} else {
|
||||||
msg->setVersion(A2STR::NIL);
|
msg->setVersion(A2STR::NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
|
SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
|
||||||
(const BDE& dict, const std::string& ipaddr, uint16_t port)
|
(const Dict* dict, const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
const BDE& messageType = getString(dict, DHTQueryMessage::Q);
|
const String* messageType = getString(dict, DHTQueryMessage::Q);
|
||||||
const BDE& transactionID = getString(dict, DHTMessage::T);
|
const String* transactionID = getString(dict, DHTMessage::T);
|
||||||
const BDE& y = getString(dict, DHTMessage::Y);
|
const String* y = getString(dict, DHTMessage::Y);
|
||||||
const BDE& aDict = getDictionary(dict, DHTQueryMessage::A);
|
const Dict* aDict = getDictionary(dict, DHTQueryMessage::A);
|
||||||
if(y.s() != DHTQueryMessage::Q) {
|
if(y->s() != DHTQueryMessage::Q) {
|
||||||
throw DL_ABORT_EX("Malformed DHT message. y != q");
|
throw DL_ABORT_EX("Malformed DHT message. y != q");
|
||||||
}
|
}
|
||||||
const BDE& id = getString(aDict, DHTMessage::ID);
|
const String* id = getString(aDict, DHTMessage::ID);
|
||||||
validateID(id);
|
validateID(id);
|
||||||
SharedHandle<DHTNode> remoteNode = getRemoteNode(id.uc(), ipaddr, port);
|
SharedHandle<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
|
||||||
SharedHandle<DHTQueryMessage> msg;
|
SharedHandle<DHTQueryMessage> msg;
|
||||||
if(messageType.s() == DHTPingMessage::PING) {
|
if(messageType->s() == DHTPingMessage::PING) {
|
||||||
msg = createPingMessage(remoteNode, transactionID.s());
|
msg = createPingMessage(remoteNode, transactionID->s());
|
||||||
} else if(messageType.s() == DHTFindNodeMessage::FIND_NODE) {
|
} else if(messageType->s() == DHTFindNodeMessage::FIND_NODE) {
|
||||||
const BDE& targetNodeID =
|
const String* targetNodeID =
|
||||||
getString(aDict, DHTFindNodeMessage::TARGET_NODE);
|
getString(aDict, DHTFindNodeMessage::TARGET_NODE);
|
||||||
validateID(targetNodeID);
|
validateID(targetNodeID);
|
||||||
msg = createFindNodeMessage(remoteNode, targetNodeID.uc(),
|
msg = createFindNodeMessage(remoteNode, targetNodeID->uc(),
|
||||||
transactionID.s());
|
transactionID->s());
|
||||||
} else if(messageType.s() == DHTGetPeersMessage::GET_PEERS) {
|
} else if(messageType->s() == DHTGetPeersMessage::GET_PEERS) {
|
||||||
const BDE& infoHash =
|
const String* infoHash = getString(aDict, DHTGetPeersMessage::INFO_HASH);
|
||||||
getString(aDict, DHTGetPeersMessage::INFO_HASH);
|
|
||||||
validateID(infoHash);
|
validateID(infoHash);
|
||||||
msg = createGetPeersMessage(remoteNode,
|
msg = createGetPeersMessage(remoteNode, infoHash->uc(), transactionID->s());
|
||||||
infoHash.uc(), transactionID.s());
|
} else if(messageType->s() == DHTAnnouncePeerMessage::ANNOUNCE_PEER) {
|
||||||
} else if(messageType.s() == DHTAnnouncePeerMessage::ANNOUNCE_PEER) {
|
const String* infoHash = getString(aDict,DHTAnnouncePeerMessage::INFO_HASH);
|
||||||
const BDE& infoHash =
|
|
||||||
getString(aDict, DHTAnnouncePeerMessage::INFO_HASH);
|
|
||||||
validateID(infoHash);
|
validateID(infoHash);
|
||||||
const BDE& port = getInteger(aDict, DHTAnnouncePeerMessage::PORT);
|
const Integer* port = getInteger(aDict, DHTAnnouncePeerMessage::PORT);
|
||||||
validatePort(port);
|
validatePort(port);
|
||||||
const BDE& token = getString(aDict, DHTAnnouncePeerMessage::TOKEN);
|
const String* token = getString(aDict, DHTAnnouncePeerMessage::TOKEN);
|
||||||
msg = createAnnouncePeerMessage(remoteNode, infoHash.uc(),
|
msg = createAnnouncePeerMessage(remoteNode, infoHash->uc(),
|
||||||
static_cast<uint16_t>(port.i()),
|
static_cast<uint16_t>(port->i()),
|
||||||
token.s(), transactionID.s());
|
token->s(), transactionID->s());
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX(StringFormat("Unsupported message type: %s",
|
||||||
(StringFormat("Unsupported message type: %s",
|
messageType->s().c_str()).str());
|
||||||
messageType.s().c_str()).str());
|
|
||||||
}
|
}
|
||||||
setVersion(msg, dict);
|
setVersion(msg, dict);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -235,20 +225,20 @@ SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createQueryMessage
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
DHTMessageFactoryImpl::createResponseMessage
|
DHTMessageFactoryImpl::createResponseMessage
|
||||||
(const std::string& messageType,
|
(const std::string& messageType,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& ipaddr,
|
const std::string& ipaddr,
|
||||||
uint16_t port)
|
uint16_t port)
|
||||||
{
|
{
|
||||||
const BDE& transactionID = getString(dict, DHTMessage::T);
|
const String* transactionID = getString(dict, DHTMessage::T);
|
||||||
const BDE& y = getString(dict, DHTMessage::Y);
|
const String* y = getString(dict, DHTMessage::Y);
|
||||||
if(y.s() == DHTUnknownMessage::E) {
|
if(y->s() == DHTUnknownMessage::E) {
|
||||||
// for now, just report error message arrived and throw exception.
|
// for now, just report error message arrived and throw exception.
|
||||||
const BDE& e = getList(dict, DHTUnknownMessage::E);
|
const List* e = getList(dict, DHTUnknownMessage::E);
|
||||||
if(e.size() == 2) {
|
if(e->size() == 2) {
|
||||||
if(_logger->info()) {
|
if(_logger->info()) {
|
||||||
_logger->info("Received Error DHT message. code=%s, msg=%s",
|
_logger->info("Received Error DHT message. code=%s, msg=%s",
|
||||||
util::itos(getInteger(e, 0).i()).c_str(),
|
util::itos(getInteger(e, 0)->i()).c_str(),
|
||||||
util::percentEncode(getString(e, 1).s()).c_str());
|
util::percentEncode(getString(e, 1)->s()).c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(_logger->debug()) {
|
if(_logger->debug()) {
|
||||||
|
@ -256,36 +246,38 @@ DHTMessageFactoryImpl::createResponseMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw DL_ABORT_EX("Received Error DHT message.");
|
throw DL_ABORT_EX("Received Error DHT message.");
|
||||||
} else if(y.s() != DHTResponseMessage::R) {
|
} else if(y->s() != DHTResponseMessage::R) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Malformed DHT message. y != r: y=%s",
|
(StringFormat("Malformed DHT message. y != r: y=%s",
|
||||||
util::percentEncode(y.s()).c_str()).str());
|
util::percentEncode(y->s()).c_str()).str());
|
||||||
}
|
}
|
||||||
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
|
const Dict* rDict = getDictionary(dict, DHTResponseMessage::R);
|
||||||
const BDE& id = getString(rDict, DHTMessage::ID);
|
const String* id = getString(rDict, DHTMessage::ID);
|
||||||
validateID(id);
|
validateID(id);
|
||||||
SharedHandle<DHTNode> remoteNode = getRemoteNode(id.uc(), ipaddr, port);
|
SharedHandle<DHTNode> remoteNode = getRemoteNode(id->uc(), ipaddr, port);
|
||||||
SharedHandle<DHTResponseMessage> msg;
|
SharedHandle<DHTResponseMessage> msg;
|
||||||
if(messageType == DHTPingReplyMessage::PING) {
|
if(messageType == DHTPingReplyMessage::PING) {
|
||||||
msg = createPingReplyMessage(remoteNode, id.uc(), transactionID.s());
|
msg = createPingReplyMessage(remoteNode, id->uc(), transactionID->s());
|
||||||
} else if(messageType == DHTFindNodeReplyMessage::FIND_NODE) {
|
} else if(messageType == DHTFindNodeReplyMessage::FIND_NODE) {
|
||||||
msg = createFindNodeReplyMessage(remoteNode, dict, transactionID.s());
|
msg = createFindNodeReplyMessage(remoteNode, dict, transactionID->s());
|
||||||
} else if(messageType == DHTGetPeersReplyMessage::GET_PEERS) {
|
} else if(messageType == DHTGetPeersReplyMessage::GET_PEERS) {
|
||||||
const BDE& valuesList = rDict[DHTGetPeersReplyMessage::VALUES];
|
const List* valuesList =
|
||||||
if(valuesList.isList()) {
|
asList(rDict->get(DHTGetPeersReplyMessage::VALUES));
|
||||||
msg = createGetPeersReplyMessageWithValues(remoteNode, dict,
|
if(valuesList) {
|
||||||
transactionID.s());
|
msg = createGetPeersReplyMessageWithValues
|
||||||
|
(remoteNode, dict, transactionID->s());
|
||||||
} else {
|
} else {
|
||||||
const BDE& nodes = rDict[DHTGetPeersReplyMessage::NODES];
|
const String* nodes = asString
|
||||||
if(nodes.isString()) {
|
(rDict->get(DHTGetPeersReplyMessage::NODES));
|
||||||
msg = createGetPeersReplyMessageWithNodes(remoteNode, dict,
|
if(nodes) {
|
||||||
transactionID.s());
|
msg = createGetPeersReplyMessageWithNodes
|
||||||
|
(remoteNode, dict, transactionID->s());
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX("Malformed DHT message: missing nodes/values");
|
throw DL_ABORT_EX("Malformed DHT message: missing nodes/values");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(messageType == DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER) {
|
} else if(messageType == DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER) {
|
||||||
msg = createAnnouncePeerReplyMessage(remoteNode, transactionID.s());
|
msg = createAnnouncePeerReplyMessage(remoteNode, transactionID->s());
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Unsupported message type: %s", messageType.c_str()).str());
|
(StringFormat("Unsupported message type: %s", messageType.c_str()).str());
|
||||||
|
@ -307,7 +299,8 @@ static const std::string& getDefaultVersion()
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageFactoryImpl::setCommonProperty(const SharedHandle<DHTAbstractMessage>& m)
|
void DHTMessageFactoryImpl::setCommonProperty
|
||||||
|
(const SharedHandle<DHTAbstractMessage>& m)
|
||||||
{
|
{
|
||||||
m->setConnection(_connection);
|
m->setConnection(_connection);
|
||||||
m->setMessageDispatcher(_dispatcher);
|
m->setMessageDispatcher(_dispatcher);
|
||||||
|
@ -320,7 +313,8 @@ void DHTMessageFactoryImpl::setCommonProperty(const SharedHandle<DHTAbstractMess
|
||||||
SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createPingMessage
|
SharedHandle<DHTQueryMessage> DHTMessageFactoryImpl::createPingMessage
|
||||||
(const SharedHandle<DHTNode>& remoteNode, const std::string& transactionID)
|
(const SharedHandle<DHTNode>& remoteNode, const std::string& transactionID)
|
||||||
{
|
{
|
||||||
SharedHandle<DHTPingMessage> m(new DHTPingMessage(_localNode, remoteNode, transactionID));
|
SharedHandle<DHTPingMessage> m
|
||||||
|
(new DHTPingMessage(_localNode, remoteNode, transactionID));
|
||||||
setCommonProperty(m);
|
setCommonProperty(m);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -385,14 +379,14 @@ DHTMessageFactoryImpl::extractNodes(const unsigned char* src, size_t length)
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
DHTMessageFactoryImpl::createFindNodeReplyMessage
|
DHTMessageFactoryImpl::createFindNodeReplyMessage
|
||||||
(const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID)
|
const std::string& transactionID)
|
||||||
{
|
{
|
||||||
const BDE& nodesData =
|
const String* nodesData =
|
||||||
getString(getDictionary(dict, DHTResponseMessage::R),
|
getString(getDictionary(dict, DHTResponseMessage::R),
|
||||||
DHTFindNodeReplyMessage::NODES);
|
DHTFindNodeReplyMessage::NODES);
|
||||||
std::vector<SharedHandle<DHTNode> > nodes =
|
std::vector<SharedHandle<DHTNode> > nodes =
|
||||||
extractNodes(nodesData.uc(), nodesData.s().size());
|
extractNodes(nodesData->uc(), nodesData->s().size());
|
||||||
return createFindNodeReplyMessage(remoteNode, nodes, transactionID);
|
return createFindNodeReplyMessage(remoteNode, nodes, transactionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,17 +407,16 @@ DHTMessageFactoryImpl::createGetPeersMessage
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
DHTMessageFactoryImpl::createGetPeersReplyMessageWithNodes
|
DHTMessageFactoryImpl::createGetPeersReplyMessageWithNodes
|
||||||
(const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID)
|
const std::string& transactionID)
|
||||||
{
|
{
|
||||||
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
|
const Dict* rDict = getDictionary(dict, DHTResponseMessage::R);
|
||||||
const BDE& nodesData = getString(rDict,
|
const String* nodesData = getString(rDict, DHTGetPeersReplyMessage::NODES);
|
||||||
DHTGetPeersReplyMessage::NODES);
|
std::vector<SharedHandle<DHTNode> > nodes = extractNodes
|
||||||
std::vector<SharedHandle<DHTNode> > nodes =
|
(nodesData->uc(), nodesData->s().size());
|
||||||
extractNodes(nodesData.uc(), nodesData.s().size());
|
const String* token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
|
||||||
const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
|
return createGetPeersReplyMessage
|
||||||
return createGetPeersReplyMessage(remoteNode, nodes, token.s(),
|
(remoteNode, nodes, token->s(), transactionID);
|
||||||
transactionID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
|
@ -443,26 +436,26 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
|
DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
|
||||||
(const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID)
|
const std::string& transactionID)
|
||||||
{
|
{
|
||||||
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
|
const Dict* rDict = getDictionary(dict, DHTResponseMessage::R);
|
||||||
const BDE& valuesList = getList(rDict,
|
const List* valuesList = getList(rDict,
|
||||||
DHTGetPeersReplyMessage::VALUES);
|
DHTGetPeersReplyMessage::VALUES);
|
||||||
std::vector<SharedHandle<Peer> > peers;
|
std::vector<SharedHandle<Peer> > peers;
|
||||||
for(BDE::List::const_iterator i = valuesList.listBegin(),
|
for(List::ValueType::const_iterator i = valuesList->begin(),
|
||||||
eoi = valuesList.listEnd(); i != eoi; ++i) {
|
eoi = valuesList->end(); i != eoi; ++i) {
|
||||||
const BDE& data = *i;
|
const String* data = asString(*i);
|
||||||
if(data.isString() && data.s().size() == 6) {
|
if(data && data->s().size() == 6) {
|
||||||
std::pair<std::string, uint16_t> addr =
|
std::pair<std::string, uint16_t> addr =
|
||||||
bittorrent::unpackcompact(data.uc());
|
bittorrent::unpackcompact(data->uc());
|
||||||
SharedHandle<Peer> peer(new Peer(addr.first, addr.second));
|
SharedHandle<Peer> peer(new Peer(addr.first, addr.second));
|
||||||
peers.push_back(peer);
|
peers.push_back(peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
|
const String* token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
|
||||||
return createGetPeersReplyMessage(remoteNode, peers, token.s(),
|
return createGetPeersReplyMessage
|
||||||
transactionID);
|
(remoteNode, peers, token->s(), transactionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
|
|
|
@ -69,9 +69,9 @@ private:
|
||||||
SharedHandle<DHTNode> getRemoteNode
|
SharedHandle<DHTNode> getRemoteNode
|
||||||
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
|
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
|
||||||
|
|
||||||
void validateID(const BDE& id) const;
|
void validateID(const String* id) const;
|
||||||
|
|
||||||
void validatePort(const BDE& i) const;
|
void validatePort(const Integer* i) const;
|
||||||
|
|
||||||
std::vector<SharedHandle<DHTNode> >
|
std::vector<SharedHandle<DHTNode> >
|
||||||
extractNodes(const unsigned char* src, size_t length);
|
extractNodes(const unsigned char* src, size_t length);
|
||||||
|
@ -84,12 +84,12 @@ public:
|
||||||
virtual ~DHTMessageFactoryImpl();
|
virtual ~DHTMessageFactoryImpl();
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
createQueryMessage(const BDE& dict,
|
createQueryMessage(const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port);
|
const std::string& ipaddr, uint16_t port);
|
||||||
|
|
||||||
virtual SharedHandle<DHTResponseMessage>
|
virtual SharedHandle<DHTResponseMessage>
|
||||||
createResponseMessage(const std::string& messageType,
|
createResponseMessage(const std::string& messageType,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port);
|
const std::string& ipaddr, uint16_t port);
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
|
@ -108,7 +108,7 @@ public:
|
||||||
|
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
|
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID);
|
const std::string& transactionID);
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public:
|
||||||
|
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
createGetPeersReplyMessageWithNodes(const SharedHandle<DHTNode>& remoteNode,
|
createGetPeersReplyMessageWithNodes(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID);
|
const std::string& transactionID);
|
||||||
|
|
||||||
virtual SharedHandle<DHTResponseMessage>
|
virtual SharedHandle<DHTResponseMessage>
|
||||||
|
@ -144,7 +144,7 @@ public:
|
||||||
|
|
||||||
SharedHandle<DHTResponseMessage>
|
SharedHandle<DHTResponseMessage>
|
||||||
createGetPeersReplyMessageWithValues(const SharedHandle<DHTNode>& remoteNode,
|
createGetPeersReplyMessageWithValues(const SharedHandle<DHTNode>& remoteNode,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& transactionID);
|
const std::string& transactionID);
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -75,11 +75,12 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
|
||||||
return SharedHandle<DHTMessage>();
|
return SharedHandle<DHTMessage>();
|
||||||
}
|
}
|
||||||
bool isReply = false;
|
bool isReply = false;
|
||||||
const BDE dict = bencode::decode(data, length);
|
SharedHandle<ValueBase> decoded = bencode2::decode(data, length);
|
||||||
if(dict.isDict()) {
|
const Dict* dict = asDict(decoded);
|
||||||
const BDE& y = dict[DHTMessage::Y];
|
if(dict) {
|
||||||
if(y.isString()) {
|
const String* y = asString(dict->get(DHTMessage::Y));
|
||||||
if(y.s() == DHTResponseMessage::R || y.s() == DHTUnknownMessage::E) {
|
if(y) {
|
||||||
|
if(y->s() == DHTResponseMessage::R || y->s() == DHTUnknownMessage::E) {
|
||||||
isReply = true;
|
isReply = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "DHTConstants.h"
|
#include "DHTConstants.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -65,20 +64,20 @@ void DHTMessageTracker::addMessage(const SharedHandle<DHTMessage>& message, time
|
||||||
|
|
||||||
std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
|
std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
|
||||||
DHTMessageTracker::messageArrived
|
DHTMessageTracker::messageArrived
|
||||||
(const BDE& dict, const std::string& ipaddr, uint16_t port)
|
(const Dict* dict, const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
const BDE& tid = dict[DHTMessage::T];
|
const String* tid = asString(dict->get(DHTMessage::T));
|
||||||
if(!tid.isString()) {
|
if(!tid) {
|
||||||
throw DL_ABORT_EX(StringFormat("Malformed DHT message. From:%s:%u",
|
throw DL_ABORT_EX(StringFormat("Malformed DHT message. From:%s:%u",
|
||||||
ipaddr.c_str(), port).str());
|
ipaddr.c_str(), port).str());
|
||||||
}
|
}
|
||||||
if(_logger->debug()) {
|
if(_logger->debug()) {
|
||||||
_logger->debug("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
|
_logger->debug("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
|
||||||
util::toHex(tid.s()).c_str(), ipaddr.c_str(), port);
|
util::toHex(tid->s()).c_str(), ipaddr.c_str(), port);
|
||||||
}
|
}
|
||||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
||||||
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
||||||
if((*i)->match(tid.s(), ipaddr, port)) {
|
if((*i)->match(tid->s(), ipaddr, port)) {
|
||||||
SharedHandle<DHTMessageTrackerEntry> entry = *i;
|
SharedHandle<DHTMessageTrackerEntry> entry = *i;
|
||||||
_entries.erase(i);
|
_entries.erase(i);
|
||||||
if(_logger->debug()) {
|
if(_logger->debug()) {
|
||||||
|
@ -162,12 +161,14 @@ size_t DHTMessageTracker::countEntry() const
|
||||||
return _entries.size();
|
return _entries.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageTracker::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
|
void DHTMessageTracker::setRoutingTable
|
||||||
|
(const SharedHandle<DHTRoutingTable>& routingTable)
|
||||||
{
|
{
|
||||||
_routingTable = routingTable;
|
_routingTable = routingTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageTracker::setMessageFactory(const SharedHandle<DHTMessageFactory>& factory)
|
void DHTMessageTracker::setMessageFactory
|
||||||
|
(const SharedHandle<DHTMessageFactory>& factory)
|
||||||
{
|
{
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "a2time.h"
|
#include "a2time.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -52,7 +53,6 @@ class DHTRoutingTable;
|
||||||
class DHTMessageFactory;
|
class DHTMessageFactory;
|
||||||
class DHTMessageTrackerEntry;
|
class DHTMessageTrackerEntry;
|
||||||
class Logger;
|
class Logger;
|
||||||
class BDE;
|
|
||||||
|
|
||||||
class DHTMessageTracker {
|
class DHTMessageTracker {
|
||||||
private:
|
private:
|
||||||
|
@ -74,7 +74,7 @@ public:
|
||||||
SharedHandle<DHTMessageCallback>());
|
SharedHandle<DHTMessageCallback>());
|
||||||
|
|
||||||
std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
|
std::pair<SharedHandle<DHTResponseMessage>, SharedHandle<DHTMessageCallback> >
|
||||||
messageArrived(const BDE& dict,
|
messageArrived(const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port);
|
const std::string& ipaddr, uint16_t port);
|
||||||
|
|
||||||
void handleTimeout();
|
void handleTimeout();
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include "DHTMessageDispatcher.h"
|
#include "DHTMessageDispatcher.h"
|
||||||
#include "DHTMessageFactory.h"
|
#include "DHTMessageFactory.h"
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -60,10 +59,10 @@ void DHTPingMessage::doReceivedAction()
|
||||||
getMessageDispatcher()->addMessageToQueue(reply);
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTPingMessage::getArgument()
|
SharedHandle<Dict> DHTPingMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH));
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual SharedHandle<Dict> getArgument();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -37,17 +37,17 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
const std::string DHTPingReplyMessage::PING("ping");
|
const std::string DHTPingReplyMessage::PING("ping");
|
||||||
|
|
||||||
DHTPingReplyMessage::DHTPingReplyMessage(const SharedHandle<DHTNode>& localNode,
|
DHTPingReplyMessage::DHTPingReplyMessage
|
||||||
const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& localNode,
|
||||||
const unsigned char* id,
|
const SharedHandle<DHTNode>& remoteNode,
|
||||||
const std::string& transactionID):
|
const unsigned char* id,
|
||||||
|
const std::string& transactionID):
|
||||||
DHTResponseMessage(localNode, remoteNode, transactionID)
|
DHTResponseMessage(localNode, remoteNode, transactionID)
|
||||||
{
|
{
|
||||||
memcpy(_id, id, DHT_ID_LENGTH);
|
memcpy(_id, id, DHT_ID_LENGTH);
|
||||||
|
@ -57,10 +57,10 @@ DHTPingReplyMessage::~DHTPingReplyMessage() {}
|
||||||
|
|
||||||
void DHTPingReplyMessage::doReceivedAction() {}
|
void DHTPingReplyMessage::doReceivedAction() {}
|
||||||
|
|
||||||
BDE DHTPingReplyMessage::getResponse()
|
SharedHandle<Dict> DHTPingReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict[DHTMessage::ID] = BDE(_id, DHT_ID_LENGTH);
|
rDict->put(DHTMessage::ID, String::g(_id, DHT_ID_LENGTH));
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual SharedHandle<Dict> getResponse();
|
||||||
|
|
||||||
virtual const std::string& getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include "DHTQueryMessage.h"
|
#include "DHTQueryMessage.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -56,10 +55,10 @@ const std::string& DHTQueryMessage::getType() const
|
||||||
return Q;
|
return Q;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTQueryMessage::fillMessage(BDE& msgDict)
|
void DHTQueryMessage::fillMessage(Dict* msgDict)
|
||||||
{
|
{
|
||||||
msgDict[Q] = getMessageType();
|
msgDict->put(Q, getMessageType());
|
||||||
msgDict[A] = getArgument();
|
msgDict->put(A, getArgument());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DHTQueryMessage::isReply() const
|
bool DHTQueryMessage::isReply() const
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "DHTAbstractMessage.h"
|
#include "DHTAbstractMessage.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -52,9 +53,9 @@ public:
|
||||||
|
|
||||||
virtual const std::string& getType() const;
|
virtual const std::string& getType() const;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict);
|
virtual void fillMessage(Dict* msgDict);
|
||||||
|
|
||||||
virtual BDE getArgument() = 0;
|
virtual SharedHandle<Dict> getArgument() = 0;
|
||||||
|
|
||||||
virtual bool isReply() const;
|
virtual bool isReply() const;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include "DHTResponseMessage.h"
|
#include "DHTResponseMessage.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -54,9 +53,9 @@ const std::string& DHTResponseMessage::getType() const
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTResponseMessage::fillMessage(BDE& msgDict)
|
void DHTResponseMessage::fillMessage(Dict* msgDict)
|
||||||
{
|
{
|
||||||
msgDict[R] = getResponse();
|
msgDict->put(R, getResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DHTResponseMessage::isReply() const
|
bool DHTResponseMessage::isReply() const
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "DHTAbstractMessage.h"
|
#include "DHTAbstractMessage.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -54,9 +55,9 @@ public:
|
||||||
|
|
||||||
virtual const std::string& getType() const;
|
virtual const std::string& getType() const;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict);
|
virtual void fillMessage(Dict* msgDict);
|
||||||
|
|
||||||
virtual BDE getResponse() = 0;
|
virtual SharedHandle<Dict> getResponse() = 0;
|
||||||
|
|
||||||
virtual bool isReply() const;
|
virtual bool isReply() const;
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,10 @@
|
||||||
#include "UTMetadataDataExtensionMessage.h"
|
#include "UTMetadataDataExtensionMessage.h"
|
||||||
#include "UTMetadataRejectExtensionMessage.h"
|
#include "UTMetadataRejectExtensionMessage.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "UTMetadataRequestTracker.h"
|
#include "UTMetadataRequestTracker.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
uint8_t extensionMessageID = *data;
|
uint8_t extensionMessageID = *data;
|
||||||
if(extensionMessageID == 0) {
|
if(extensionMessageID == 0) {
|
||||||
// handshake
|
// handshake
|
||||||
HandshakeExtensionMessageHandle m = HandshakeExtensionMessage::create(data, length);
|
HandshakeExtensionMessageHandle m =
|
||||||
|
HandshakeExtensionMessage::create(data, length);
|
||||||
m->setPeer(_peer);
|
m->setPeer(_peer);
|
||||||
m->setDownloadContext(_dctx);
|
m->setDownloadContext(_dctx);
|
||||||
return m;
|
return m;
|
||||||
|
@ -97,23 +98,24 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
"ut_metadata", length).str());
|
"ut_metadata", length).str());
|
||||||
}
|
}
|
||||||
size_t end;
|
size_t end;
|
||||||
BDE dict = bencode::decode(data+1, length-1, end);
|
SharedHandle<ValueBase> decoded = bencode2::decode(data+1, length-1, end);
|
||||||
if(!dict.isDict()) {
|
const Dict* dict = asDict(decoded);
|
||||||
|
if(!dict) {
|
||||||
throw DL_ABORT_EX("Bad ut_metadata: dictionary not found");
|
throw DL_ABORT_EX("Bad ut_metadata: dictionary not found");
|
||||||
}
|
}
|
||||||
const BDE& msgType = dict["msg_type"];
|
const Integer* msgType = asInteger(dict->get("msg_type"));
|
||||||
if(!msgType.isInteger()) {
|
if(!msgType) {
|
||||||
throw DL_ABORT_EX("Bad ut_metadata: msg_type not found");
|
throw DL_ABORT_EX("Bad ut_metadata: msg_type not found");
|
||||||
}
|
}
|
||||||
const BDE& index = dict["piece"];
|
const Integer* index = asInteger(dict->get("piece"));
|
||||||
if(!index.isInteger()) {
|
if(!index) {
|
||||||
throw DL_ABORT_EX("Bad ut_metadata: piece not found");
|
throw DL_ABORT_EX("Bad ut_metadata: piece not found");
|
||||||
}
|
}
|
||||||
switch(msgType.i()) {
|
switch(msgType->i()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
SharedHandle<UTMetadataRequestExtensionMessage> m
|
SharedHandle<UTMetadataRequestExtensionMessage> m
|
||||||
(new UTMetadataRequestExtensionMessage(extensionMessageID));
|
(new UTMetadataRequestExtensionMessage(extensionMessageID));
|
||||||
m->setIndex(index.i());
|
m->setIndex(index->i());
|
||||||
m->setDownloadContext(_dctx);
|
m->setDownloadContext(_dctx);
|
||||||
m->setPeer(_peer);
|
m->setPeer(_peer);
|
||||||
m->setBtMessageFactory(_messageFactory);
|
m->setBtMessageFactory(_messageFactory);
|
||||||
|
@ -124,14 +126,14 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
if(end == length) {
|
if(end == length) {
|
||||||
throw DL_ABORT_EX("Bad ut_metadata data: data not found");
|
throw DL_ABORT_EX("Bad ut_metadata data: data not found");
|
||||||
}
|
}
|
||||||
const BDE& totalSize = dict["total_size"];
|
const Integer* totalSize = asInteger(dict->get("total_size"));
|
||||||
if(!totalSize.isInteger()) {
|
if(!totalSize) {
|
||||||
throw DL_ABORT_EX("Bad ut_metadata data: total_size not found");
|
throw DL_ABORT_EX("Bad ut_metadata data: total_size not found");
|
||||||
}
|
}
|
||||||
SharedHandle<UTMetadataDataExtensionMessage> m
|
SharedHandle<UTMetadataDataExtensionMessage> m
|
||||||
(new UTMetadataDataExtensionMessage(extensionMessageID));
|
(new UTMetadataDataExtensionMessage(extensionMessageID));
|
||||||
m->setIndex(index.i());
|
m->setIndex(index->i());
|
||||||
m->setTotalSize(totalSize.i());
|
m->setTotalSize(totalSize->i());
|
||||||
m->setData(std::string(&data[1+end], &data[length]));
|
m->setData(std::string(&data[1+end], &data[length]));
|
||||||
m->setUTMetadataRequestTracker(_tracker);
|
m->setUTMetadataRequestTracker(_tracker);
|
||||||
m->setPieceStorage(_dctx->getOwnerRequestGroup()->getPieceStorage());
|
m->setPieceStorage(_dctx->getOwnerRequestGroup()->getPieceStorage());
|
||||||
|
@ -141,17 +143,18 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
case 2: {
|
case 2: {
|
||||||
SharedHandle<UTMetadataRejectExtensionMessage> m
|
SharedHandle<UTMetadataRejectExtensionMessage> m
|
||||||
(new UTMetadataRejectExtensionMessage(extensionMessageID));
|
(new UTMetadataRejectExtensionMessage(extensionMessageID));
|
||||||
m->setIndex(index.i());
|
m->setIndex(index->i());
|
||||||
// No need to inject tracker because peer will be disconnected.
|
// No need to inject tracker because peer will be disconnected.
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw DL_ABORT_EX(StringFormat("Bad ut_metadata: unknown msg_type=%u",
|
throw DL_ABORT_EX(StringFormat("Bad ut_metadata: unknown msg_type=%u",
|
||||||
msgType.i()).str());
|
msgType->i()).str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Unsupported extension message received. extensionMessageID=%u, extensionName=%s",
|
(StringFormat("Unsupported extension message received."
|
||||||
|
" extensionMessageID=%u, extensionName=%s",
|
||||||
extensionMessageID, extensionName.c_str()).str());
|
extensionMessageID, extensionName.c_str()).str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,11 @@ XmlRpcRequestProcessor::parseMemory(const std::string& xml)
|
||||||
if(r == XML_STATUS_ERROR) {
|
if(r == XML_STATUS_ERROR) {
|
||||||
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
|
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
|
||||||
}
|
}
|
||||||
return XmlRpcRequest(_stm->getMethodName(), _stm->getCurrentFrameValue());
|
if(!asList(_stm->getCurrentFrameValue())) {
|
||||||
|
throw DL_ABORT_EX("Bad XML-RPC parameter list");
|
||||||
|
}
|
||||||
|
return XmlRpcRequest(_stm->getMethodName(),
|
||||||
|
static_pointer_cast<List>(_stm->getCurrentFrameValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
@ -59,24 +59,24 @@ HandshakeExtensionMessage::~HandshakeExtensionMessage() {}
|
||||||
|
|
||||||
std::string HandshakeExtensionMessage::getPayload()
|
std::string HandshakeExtensionMessage::getPayload()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
if(!_clientVersion.empty()) {
|
if(!_clientVersion.empty()) {
|
||||||
dict["v"] = _clientVersion;
|
dict.put("v", _clientVersion);
|
||||||
}
|
}
|
||||||
if(_tcpPort > 0) {
|
if(_tcpPort > 0) {
|
||||||
dict["p"] = _tcpPort;
|
dict.put("p", Integer::g(_tcpPort));
|
||||||
}
|
}
|
||||||
BDE extDict = BDE::dict();
|
SharedHandle<Dict> extDict = Dict::g();
|
||||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin(),
|
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin(),
|
||||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||||
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
||||||
extDict[vt.first] = vt.second;
|
extDict->put(vt.first, Integer::g(vt.second));
|
||||||
}
|
}
|
||||||
dict["m"] = extDict;
|
dict.put("m", extDict);
|
||||||
if(_metadataSize) {
|
if(_metadataSize) {
|
||||||
dict["metadata_size"] = _metadataSize;
|
dict.put("metadata_size", Integer::g(_metadataSize));
|
||||||
}
|
}
|
||||||
return bencode::encode(dict);
|
return bencode2::encode(&dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HandshakeExtensionMessage::toString() const
|
std::string HandshakeExtensionMessage::toString() const
|
||||||
|
@ -168,31 +168,34 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
|
||||||
("Creating HandshakeExtensionMessage from %s",
|
("Creating HandshakeExtensionMessage from %s",
|
||||||
util::percentEncode(data, length).c_str());
|
util::percentEncode(data, length).c_str());
|
||||||
}
|
}
|
||||||
const BDE dict = bencode::decode(data+1, length-1);
|
SharedHandle<ValueBase> decoded = bencode2::decode(data+1, length-1);
|
||||||
if(!dict.isDict()) {
|
const Dict* dict = asDict(decoded);
|
||||||
throw DL_ABORT_EX("Unexpected payload format for extended message handshake");
|
if(!dict) {
|
||||||
|
throw DL_ABORT_EX
|
||||||
|
("Unexpected payload format for extended message handshake");
|
||||||
}
|
}
|
||||||
const BDE& port = dict["p"];
|
const Integer* port = asInteger(dict->get("p"));
|
||||||
if(port.isInteger() && 0 < port.i() && port.i() < 65536) {
|
if(port && 0 < port->i() && port->i() < 65536) {
|
||||||
msg->_tcpPort = port.i();
|
msg->_tcpPort = port->i();
|
||||||
}
|
}
|
||||||
const BDE& version = dict["v"];
|
const String* version = asString(dict->get("v"));
|
||||||
if(version.isString()) {
|
if(version) {
|
||||||
msg->_clientVersion = version.s();
|
msg->_clientVersion = version->s();
|
||||||
}
|
}
|
||||||
const BDE& extDict = dict["m"];
|
const Dict* extDict = asDict(dict->get("m"));
|
||||||
if(extDict.isDict()) {
|
if(extDict) {
|
||||||
for(BDE::Dict::const_iterator i = extDict.dictBegin(),
|
for(Dict::ValueType::const_iterator i = extDict->begin(),
|
||||||
eoi = extDict.dictEnd(); i != eoi; ++i) {
|
eoi = extDict->end(); i != eoi; ++i) {
|
||||||
if((*i).second.isInteger()) {
|
const Integer* extId = asInteger((*i).second);
|
||||||
msg->_extensions[(*i).first] = (*i).second.i();
|
if(extId) {
|
||||||
|
msg->_extensions[(*i).first] = extId->i();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const BDE& metadataSize = dict["metadata_size"];
|
const Integer* metadataSize = asInteger(dict->get("metadata_size"));
|
||||||
// Only accept metadata smaller than 1MiB
|
// Only accept metadata smaller than 1MiB
|
||||||
if(metadataSize.isInteger() && metadataSize.i() <= 1024*1024) {
|
if(metadataSize && metadataSize->i() <= 1024*1024) {
|
||||||
msg->_metadataSize = metadataSize.i();
|
msg->_metadataSize = metadataSize->i();
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,6 @@ SRCS = Socket.h\
|
||||||
PieceSelector.h\
|
PieceSelector.h\
|
||||||
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h\
|
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h\
|
||||||
bitfield.cc bitfield.h\
|
bitfield.cc bitfield.h\
|
||||||
BDE.cc BDE.h\
|
|
||||||
CreateRequestCommand.cc CreateRequestCommand.h\
|
CreateRequestCommand.cc CreateRequestCommand.h\
|
||||||
DownloadResultCode.h\
|
DownloadResultCode.h\
|
||||||
wallclock.h\
|
wallclock.h\
|
||||||
|
@ -204,7 +203,6 @@ SRCS = Socket.h\
|
||||||
Event.h\
|
Event.h\
|
||||||
timespec.h\
|
timespec.h\
|
||||||
ValueBase.cc ValueBase.h\
|
ValueBase.cc ValueBase.h\
|
||||||
bencode2.cc bencode2.h\
|
|
||||||
ContextAttribute.h\
|
ContextAttribute.h\
|
||||||
TorrentAttribute.h
|
TorrentAttribute.h
|
||||||
|
|
||||||
|
@ -447,7 +445,6 @@ SRCS += PeerAbstractCommand.cc PeerAbstractCommand.h\
|
||||||
RangeBtMessageValidator.h\
|
RangeBtMessageValidator.h\
|
||||||
IndexBtMessageValidator.h\
|
IndexBtMessageValidator.h\
|
||||||
ExtensionMessageRegistry.h\
|
ExtensionMessageRegistry.h\
|
||||||
bencode.cc bencode.h\
|
|
||||||
bittorrent_helper.cc bittorrent_helper.h\
|
bittorrent_helper.cc bittorrent_helper.h\
|
||||||
BtStopDownloadCommand.cc BtStopDownloadCommand.h\
|
BtStopDownloadCommand.cc BtStopDownloadCommand.h\
|
||||||
PriorityPieceSelector.cc PriorityPieceSelector.h\
|
PriorityPieceSelector.cc PriorityPieceSelector.h\
|
||||||
|
@ -455,7 +452,8 @@ SRCS += PeerAbstractCommand.cc PeerAbstractCommand.h\
|
||||||
LpdMessageReceiver.cc LpdMessageReceiver.h\
|
LpdMessageReceiver.cc LpdMessageReceiver.h\
|
||||||
LpdMessage.h\
|
LpdMessage.h\
|
||||||
LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h\
|
LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h\
|
||||||
LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h
|
LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h\
|
||||||
|
bencode2.cc bencode2.h
|
||||||
endif # ENABLE_BITTORRENT
|
endif # ENABLE_BITTORRENT
|
||||||
|
|
||||||
if ENABLE_METALINK
|
if ENABLE_METALINK
|
||||||
|
|
|
@ -241,7 +241,6 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
||||||
@ENABLE_BITTORRENT_TRUE@ RangeBtMessageValidator.h\
|
@ENABLE_BITTORRENT_TRUE@ RangeBtMessageValidator.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ IndexBtMessageValidator.h\
|
@ENABLE_BITTORRENT_TRUE@ IndexBtMessageValidator.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ ExtensionMessageRegistry.h\
|
@ENABLE_BITTORRENT_TRUE@ ExtensionMessageRegistry.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ bencode.cc bencode.h\
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.cc bittorrent_helper.h\
|
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.cc bittorrent_helper.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.cc BtStopDownloadCommand.h\
|
@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.cc BtStopDownloadCommand.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelector.cc PriorityPieceSelector.h\
|
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelector.cc PriorityPieceSelector.h\
|
||||||
|
@ -249,7 +248,8 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiver.cc LpdMessageReceiver.h\
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiver.cc LpdMessageReceiver.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessage.h\
|
@ENABLE_BITTORRENT_TRUE@ LpdMessage.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h\
|
@ENABLE_BITTORRENT_TRUE@ LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h
|
@ENABLE_BITTORRENT_TRUE@ LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h\
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ bencode2.cc bencode2.h
|
||||||
|
|
||||||
@ENABLE_METALINK_TRUE@am__append_14 = Metalinker.cc Metalinker.h\
|
@ENABLE_METALINK_TRUE@am__append_14 = Metalinker.cc Metalinker.h\
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
|
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
|
||||||
|
@ -433,13 +433,12 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
||||||
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
|
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
|
||||||
SequentialDispatcherCommand.h PieceSelector.h \
|
SequentialDispatcherCommand.h PieceSelector.h \
|
||||||
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
|
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
|
||||||
bitfield.cc bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \
|
bitfield.cc bitfield.h CreateRequestCommand.cc \
|
||||||
CreateRequestCommand.h DownloadResultCode.h wallclock.h \
|
CreateRequestCommand.h DownloadResultCode.h wallclock.h \
|
||||||
download_helper.cc download_helper.h MetadataInfo.cc \
|
download_helper.cc download_helper.h MetadataInfo.cc \
|
||||||
MetadataInfo.h SessionSerializer.cc SessionSerializer.h \
|
MetadataInfo.h SessionSerializer.cc SessionSerializer.h \
|
||||||
Event.h timespec.h ValueBase.cc ValueBase.h bencode2.cc \
|
Event.h timespec.h ValueBase.cc ValueBase.h ContextAttribute.h \
|
||||||
bencode2.h ContextAttribute.h TorrentAttribute.h \
|
TorrentAttribute.h XmlRpcRequestParserController.cc \
|
||||||
XmlRpcRequestParserController.cc \
|
|
||||||
XmlRpcRequestParserController.h \
|
XmlRpcRequestParserController.h \
|
||||||
XmlRpcRequestParserStateMachine.cc \
|
XmlRpcRequestParserStateMachine.cc \
|
||||||
XmlRpcRequestParserStateMachine.h XmlRpcRequestParserState.h \
|
XmlRpcRequestParserStateMachine.h XmlRpcRequestParserState.h \
|
||||||
|
@ -586,25 +585,25 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
||||||
IndexBtMessage.cc IndexBtMessage.h ZeroBtMessage.cc \
|
IndexBtMessage.cc IndexBtMessage.h ZeroBtMessage.cc \
|
||||||
ZeroBtMessage.h RangeBtMessageValidator.h \
|
ZeroBtMessage.h RangeBtMessageValidator.h \
|
||||||
IndexBtMessageValidator.h ExtensionMessageRegistry.h \
|
IndexBtMessageValidator.h ExtensionMessageRegistry.h \
|
||||||
bencode.cc bencode.h bittorrent_helper.cc bittorrent_helper.h \
|
bittorrent_helper.cc bittorrent_helper.h \
|
||||||
BtStopDownloadCommand.cc BtStopDownloadCommand.h \
|
BtStopDownloadCommand.cc BtStopDownloadCommand.h \
|
||||||
PriorityPieceSelector.cc PriorityPieceSelector.h \
|
PriorityPieceSelector.cc PriorityPieceSelector.h \
|
||||||
LpdMessageDispatcher.cc LpdMessageDispatcher.h \
|
LpdMessageDispatcher.cc LpdMessageDispatcher.h \
|
||||||
LpdMessageReceiver.cc LpdMessageReceiver.h LpdMessage.h \
|
LpdMessageReceiver.cc LpdMessageReceiver.h LpdMessage.h \
|
||||||
LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h \
|
LpdReceiveMessageCommand.cc LpdReceiveMessageCommand.h \
|
||||||
LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h \
|
LpdDispatchMessageCommand.cc LpdDispatchMessageCommand.h \
|
||||||
Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \
|
bencode2.cc bencode2.h Metalinker.cc Metalinker.h \
|
||||||
MetalinkResource.cc MetalinkResource.h MetalinkMetaurl.cc \
|
MetalinkEntry.cc MetalinkEntry.h MetalinkResource.cc \
|
||||||
MetalinkMetaurl.h MetalinkProcessor.h \
|
MetalinkResource.h MetalinkMetaurl.cc MetalinkMetaurl.h \
|
||||||
MetalinkParserController.cc MetalinkParserController.h \
|
MetalinkProcessor.h MetalinkParserController.cc \
|
||||||
MetalinkParserStateMachine.cc MetalinkParserStateMachine.h \
|
MetalinkParserController.h MetalinkParserStateMachine.cc \
|
||||||
MetalinkParserState.h MetalinkParserStateImpl.cc \
|
MetalinkParserStateMachine.h MetalinkParserState.h \
|
||||||
MetalinkParserStateImpl.h MetalinkParserStateV3Impl.cc \
|
MetalinkParserStateImpl.cc MetalinkParserStateImpl.h \
|
||||||
MetalinkParserStateV3Impl.h MetalinkParserStateV4Impl.cc \
|
MetalinkParserStateV3Impl.cc MetalinkParserStateV3Impl.h \
|
||||||
MetalinkParserStateV4Impl.h Metalink2RequestGroup.cc \
|
MetalinkParserStateV4Impl.cc MetalinkParserStateV4Impl.h \
|
||||||
Metalink2RequestGroup.h MetalinkPostDownloadHandler.cc \
|
Metalink2RequestGroup.cc Metalink2RequestGroup.h \
|
||||||
MetalinkPostDownloadHandler.h MetalinkHelper.cc \
|
MetalinkPostDownloadHandler.cc MetalinkPostDownloadHandler.h \
|
||||||
MetalinkHelper.h XML2SAXMetalinkProcessor.cc \
|
MetalinkHelper.cc MetalinkHelper.h XML2SAXMetalinkProcessor.cc \
|
||||||
XML2SAXMetalinkProcessor.h ExpatMetalinkProcessor.cc \
|
XML2SAXMetalinkProcessor.h ExpatMetalinkProcessor.cc \
|
||||||
ExpatMetalinkProcessor.h asctime_r.c asctime_r.h libgen.c \
|
ExpatMetalinkProcessor.h asctime_r.c asctime_r.h libgen.c \
|
||||||
libgen.h getaddrinfo.c getaddrinfo.h gai_strerror.c \
|
libgen.h getaddrinfo.c getaddrinfo.h gai_strerror.c \
|
||||||
|
@ -759,14 +758,14 @@ am__objects_6 =
|
||||||
@ENABLE_BITTORRENT_TRUE@ RangeBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ RangeBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ IndexBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ IndexBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ ZeroBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ ZeroBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ bencode.$(OBJEXT) \
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelector.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelector.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcher.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcher.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiver.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiver.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdReceiveMessageCommand.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ LpdReceiveMessageCommand.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdDispatchMessageCommand.$(OBJEXT)
|
@ENABLE_BITTORRENT_TRUE@ LpdDispatchMessageCommand.$(OBJEXT) \
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ bencode2.$(OBJEXT)
|
||||||
@ENABLE_METALINK_TRUE@am__objects_14 = Metalinker.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@am__objects_14 = Metalinker.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
|
||||||
|
@ -873,10 +872,9 @@ am__objects_32 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
|
||||||
SocketBuffer.$(OBJEXT) OptionHandlerException.$(OBJEXT) \
|
SocketBuffer.$(OBJEXT) OptionHandlerException.$(OBJEXT) \
|
||||||
URIResult.$(OBJEXT) SelectEventPoll.$(OBJEXT) \
|
URIResult.$(OBJEXT) SelectEventPoll.$(OBJEXT) \
|
||||||
LongestSequencePieceSelector.$(OBJEXT) bitfield.$(OBJEXT) \
|
LongestSequencePieceSelector.$(OBJEXT) bitfield.$(OBJEXT) \
|
||||||
BDE.$(OBJEXT) CreateRequestCommand.$(OBJEXT) \
|
CreateRequestCommand.$(OBJEXT) download_helper.$(OBJEXT) \
|
||||||
download_helper.$(OBJEXT) MetadataInfo.$(OBJEXT) \
|
MetadataInfo.$(OBJEXT) SessionSerializer.$(OBJEXT) \
|
||||||
SessionSerializer.$(OBJEXT) ValueBase.$(OBJEXT) \
|
ValueBase.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
|
||||||
bencode2.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
|
|
||||||
$(am__objects_3) $(am__objects_4) $(am__objects_5) \
|
$(am__objects_3) $(am__objects_4) $(am__objects_5) \
|
||||||
$(am__objects_6) $(am__objects_7) $(am__objects_8) \
|
$(am__objects_6) $(am__objects_7) $(am__objects_8) \
|
||||||
$(am__objects_9) $(am__objects_10) $(am__objects_11) \
|
$(am__objects_9) $(am__objects_10) $(am__objects_11) \
|
||||||
|
@ -1212,23 +1210,22 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
|
||||||
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
|
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
|
||||||
SequentialDispatcherCommand.h PieceSelector.h \
|
SequentialDispatcherCommand.h PieceSelector.h \
|
||||||
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
|
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
|
||||||
bitfield.cc bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \
|
bitfield.cc bitfield.h CreateRequestCommand.cc \
|
||||||
CreateRequestCommand.h DownloadResultCode.h wallclock.h \
|
CreateRequestCommand.h DownloadResultCode.h wallclock.h \
|
||||||
download_helper.cc download_helper.h MetadataInfo.cc \
|
download_helper.cc download_helper.h MetadataInfo.cc \
|
||||||
MetadataInfo.h SessionSerializer.cc SessionSerializer.h \
|
MetadataInfo.h SessionSerializer.cc SessionSerializer.h \
|
||||||
Event.h timespec.h ValueBase.cc ValueBase.h bencode2.cc \
|
Event.h timespec.h ValueBase.cc ValueBase.h ContextAttribute.h \
|
||||||
bencode2.h ContextAttribute.h TorrentAttribute.h \
|
TorrentAttribute.h $(am__append_1) $(am__append_2) \
|
||||||
$(am__append_1) $(am__append_2) $(am__append_3) \
|
$(am__append_3) $(am__append_4) $(am__append_5) \
|
||||||
$(am__append_4) $(am__append_5) $(am__append_6) \
|
$(am__append_6) $(am__append_7) $(am__append_8) \
|
||||||
$(am__append_7) $(am__append_8) $(am__append_9) \
|
$(am__append_9) $(am__append_10) $(am__append_11) \
|
||||||
$(am__append_10) $(am__append_11) $(am__append_12) \
|
$(am__append_12) $(am__append_13) $(am__append_14) \
|
||||||
$(am__append_13) $(am__append_14) $(am__append_15) \
|
$(am__append_15) $(am__append_16) $(am__append_17) \
|
||||||
$(am__append_16) $(am__append_17) $(am__append_18) \
|
$(am__append_18) $(am__append_19) $(am__append_20) \
|
||||||
$(am__append_19) $(am__append_20) $(am__append_21) \
|
$(am__append_21) $(am__append_22) $(am__append_23) \
|
||||||
$(am__append_22) $(am__append_23) $(am__append_24) \
|
$(am__append_24) $(am__append_25) $(am__append_26) \
|
||||||
$(am__append_25) $(am__append_26) $(am__append_27) \
|
$(am__append_27) $(am__append_28) $(am__append_29) \
|
||||||
$(am__append_28) $(am__append_29) $(am__append_30) \
|
$(am__append_30) $(am__append_31)
|
||||||
$(am__append_31)
|
|
||||||
noinst_LIBRARIES = libaria2c.a
|
noinst_LIBRARIES = libaria2c.a
|
||||||
libaria2c_a_SOURCES = $(SRCS)
|
libaria2c_a_SOURCES = $(SRCS)
|
||||||
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
|
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
|
||||||
|
@ -1348,7 +1345,6 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactory.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactory.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoSaveCommand.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoSaveCommand.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDE.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNode.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNode.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
||||||
|
@ -1631,7 +1627,6 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ZeroBtMessage.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ZeroBtMessage.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asctime_r.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asctime_r.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base32.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base32.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode2.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode2.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitfield.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitfield.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittorrent_helper.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittorrent_helper.Po@am__quote@
|
||||||
|
|
|
@ -40,120 +40,76 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "a2netcompat.h"
|
#include "a2netcompat.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "ValueBase.h"
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class PeerListProcessor {
|
class PeerListProcessor {
|
||||||
private:
|
public:
|
||||||
template<typename OutputIterator>
|
template<typename OutputIterator>
|
||||||
class PeerListValueBaseVisitor:public ValueBaseVisitor {
|
void extractPeer(const ValueBase* peerData, OutputIterator dest)
|
||||||
OutputIterator dest_;
|
{
|
||||||
public:
|
class PeerListValueBaseVisitor:public ValueBaseVisitor {
|
||||||
PeerListValueBaseVisitor(OutputIterator dest):dest_(dest) {}
|
private:
|
||||||
|
OutputIterator dest_;
|
||||||
|
public:
|
||||||
|
PeerListValueBaseVisitor(OutputIterator dest):dest_(dest) {}
|
||||||
|
|
||||||
virtual void visit(const String& peerData)
|
virtual ~PeerListValueBaseVisitor() {}
|
||||||
{
|
|
||||||
size_t length = peerData.s().size();
|
virtual void visit(const String& peerData)
|
||||||
if(length%6 == 0) {
|
{
|
||||||
const char* base = peerData.s().data();
|
size_t length = peerData.s().size();
|
||||||
for(size_t i = 0; i < length; i += 6) {
|
if(length%6 == 0) {
|
||||||
struct in_addr in;
|
const char* base = peerData.s().data();
|
||||||
memcpy(&in.s_addr, base+i, sizeof(uint32_t));
|
for(size_t i = 0; i < length; i += 6) {
|
||||||
std::string ipaddr = inet_ntoa(in);
|
struct in_addr in;
|
||||||
uint16_t port_nworder;
|
memcpy(&in.s_addr, base+i, sizeof(uint32_t));
|
||||||
memcpy(&port_nworder, base+i+4, sizeof(uint16_t));
|
std::string ipaddr = inet_ntoa(in);
|
||||||
uint16_t port = ntohs(port_nworder);
|
uint16_t port_nworder;
|
||||||
*dest_ = SharedHandle<Peer>(new Peer(ipaddr, port));
|
memcpy(&port_nworder, base+i+4, sizeof(uint16_t));
|
||||||
|
uint16_t port = ntohs(port_nworder);
|
||||||
|
*dest_ = SharedHandle<Peer>(new Peer(ipaddr, port));
|
||||||
|
++dest_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void visit(const Integer& v) {}
|
||||||
|
|
||||||
|
virtual void visit(const List& peerData)
|
||||||
|
{
|
||||||
|
for(List::ValueType::const_iterator itr = peerData.begin(),
|
||||||
|
eoi = peerData.end(); itr != eoi; ++itr) {
|
||||||
|
const Dict* peerDict = asDict(*itr);
|
||||||
|
if(!peerDict) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
static const std::string IP = "ip";
|
||||||
|
static const std::string PORT = "port";
|
||||||
|
const String* ip = asString(peerDict->get(IP));
|
||||||
|
const Integer* port = asInteger(peerDict->get(PORT));
|
||||||
|
if(!ip || !port || !(0 < port->i() && port->i() < 65536)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*dest_ = SharedHandle<Peer>(new Peer(ip->s(), port->i()));
|
||||||
++dest_;
|
++dest_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
virtual void visit(const Integer& v) {}
|
virtual void visit(const Dict& v) {}
|
||||||
|
};
|
||||||
virtual void visit(const List& peerData)
|
if(peerData) {
|
||||||
{
|
PeerListValueBaseVisitor visitor(dest);
|
||||||
for(List::ValueType::const_iterator itr = peerData.begin(),
|
|
||||||
eoi = peerData.end(); itr != eoi; ++itr) {
|
|
||||||
const Dict* peerDict = asDict(*itr);
|
|
||||||
if(!peerDict) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
static const std::string IP = "ip";
|
|
||||||
static const std::string PORT = "port";
|
|
||||||
const String* ip = asString(peerDict->get(IP));
|
|
||||||
const Integer* port = asInteger(peerDict->get(PORT));
|
|
||||||
if(!ip || !port || !(0 < port->i() && port->i() < 65536)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*dest_ = SharedHandle<Peer>(new Peer(ip->s(), port->i()));
|
|
||||||
++dest_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void visit(const Dict& v) {}
|
|
||||||
};
|
|
||||||
public:
|
|
||||||
template<typename OutputIterator>
|
|
||||||
void extractPeer(const SharedHandle<ValueBase>& peerData, OutputIterator dest)
|
|
||||||
{
|
|
||||||
if(!peerData.isNull()) {
|
|
||||||
PeerListValueBaseVisitor<OutputIterator> visitor(dest);
|
|
||||||
peerData->accept(visitor);
|
peerData->accept(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputIterator>
|
template<typename OutputIterator>
|
||||||
void extractPeer(const BDE& peerData, OutputIterator dest)
|
void extractPeer(const SharedHandle<ValueBase>& peerData, OutputIterator dest)
|
||||||
{
|
{
|
||||||
if(peerData.isList()) {
|
return extractPeer(peerData.get(), dest);
|
||||||
extractPeerFromList(peerData, dest);
|
|
||||||
} else if(peerData.isString()) {
|
|
||||||
extractPeerFromCompact(peerData, dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename OutputIterator>
|
|
||||||
void extractPeerFromList(const BDE& peerData, OutputIterator dest)
|
|
||||||
{
|
|
||||||
for(BDE::List::const_iterator itr = peerData.listBegin(),
|
|
||||||
eoi = peerData.listEnd(); itr != eoi; ++itr) {
|
|
||||||
const BDE& peerDict = *itr;
|
|
||||||
if(!peerDict.isDict()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
static const std::string IP = "ip";
|
|
||||||
static const std::string PORT = "port";
|
|
||||||
const BDE& ip = peerDict[IP];
|
|
||||||
const BDE& port = peerDict[PORT];
|
|
||||||
if(!ip.isString() || !port.isInteger() ||
|
|
||||||
!(0 < port.i() && port.i() < 65536)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*dest = SharedHandle<Peer>(new Peer(ip.s(), port.i()));
|
|
||||||
++dest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename OutputIterator>
|
|
||||||
void extractPeerFromCompact(const BDE& peerData, OutputIterator dest)
|
|
||||||
{
|
|
||||||
size_t length = peerData.s().size();
|
|
||||||
if(length%6 == 0) {
|
|
||||||
for(size_t i = 0; i < length; i += 6) {
|
|
||||||
struct in_addr in;
|
|
||||||
memcpy(&in.s_addr, peerData.s().c_str()+i, sizeof(uint32_t));
|
|
||||||
std::string ipaddr = inet_ntoa(in);
|
|
||||||
uint16_t port_nworder;
|
|
||||||
memcpy(&port_nworder, peerData.s().c_str()+i+4, sizeof(uint16_t));
|
|
||||||
uint16_t port = ntohs(port_nworder);
|
|
||||||
*dest = SharedHandle<Peer>(new Peer(ipaddr, port));
|
|
||||||
++dest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "UTMetadataDataExtensionMessage.h"
|
#include "UTMetadataDataExtensionMessage.h"
|
||||||
#include "BDE.h"
|
#include "bencode2.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
|
@ -55,11 +54,11 @@ UTMetadataDataExtensionMessage::UTMetadataDataExtensionMessage
|
||||||
|
|
||||||
std::string UTMetadataDataExtensionMessage::getPayload()
|
std::string UTMetadataDataExtensionMessage::getPayload()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["msg_type"] = 1;
|
dict.put("msg_type", Integer::g(1));
|
||||||
dict["piece"] = getIndex();
|
dict.put("piece", Integer::g(getIndex()));
|
||||||
dict["total_size"] = _totalSize;
|
dict.put("total_size", Integer::g(_totalSize));
|
||||||
return bencode::encode(dict)+_data;
|
return bencode2::encode(&dict)+_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UTMetadataDataExtensionMessage::toString() const
|
std::string UTMetadataDataExtensionMessage::toString() const
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "UTMetadataPostDownloadHandler.h"
|
#include "UTMetadataPostDownloadHandler.h"
|
||||||
#include "BDE.h"
|
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "download_helper.h"
|
#include "download_helper.h"
|
||||||
|
@ -46,7 +45,7 @@
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
|
|
@ -33,10 +33,9 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "UTMetadataRejectExtensionMessage.h"
|
#include "UTMetadataRejectExtensionMessage.h"
|
||||||
#include "BDE.h"
|
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
@ -47,10 +46,10 @@ UTMetadataRejectExtensionMessage::UTMetadataRejectExtensionMessage
|
||||||
|
|
||||||
std::string UTMetadataRejectExtensionMessage::getPayload()
|
std::string UTMetadataRejectExtensionMessage::getPayload()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["msg_type"] = 2;
|
dict.put("msg_type", Integer::g(2));
|
||||||
dict["piece"] = getIndex();
|
dict.put("piece", Integer::g(getIndex()));
|
||||||
return bencode::encode(dict);
|
return bencode2::encode(&dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UTMetadataRejectExtensionMessage::toString() const
|
std::string UTMetadataRejectExtensionMessage::toString() const
|
||||||
|
|
|
@ -33,8 +33,7 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "UTMetadataRequestExtensionMessage.h"
|
#include "UTMetadataRequestExtensionMessage.h"
|
||||||
#include "BDE.h"
|
#include "bencode2.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
|
@ -57,10 +56,10 @@ UTMetadataRequestExtensionMessage::UTMetadataRequestExtensionMessage
|
||||||
|
|
||||||
std::string UTMetadataRequestExtensionMessage::getPayload()
|
std::string UTMetadataRequestExtensionMessage::getPayload()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["msg_type"] = 0;
|
dict.put("msg_type", Integer::g(0));
|
||||||
dict["piece"] = getIndex();
|
dict.put("piece", Integer::g(getIndex()));
|
||||||
return bencode::encode(dict);
|
return bencode2::encode(&dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UTMetadataRequestExtensionMessage::toString() const
|
std::string UTMetadataRequestExtensionMessage::toString() const
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include "wallclock.h"
|
#include "wallclock.h"
|
||||||
|
|
||||||
|
@ -64,11 +64,11 @@ std::string UTPexExtensionMessage::getPayload()
|
||||||
std::pair<std::string, std::string> droppedPeerPair =
|
std::pair<std::string, std::string> droppedPeerPair =
|
||||||
createCompactPeerListAndFlag(_droppedPeers);
|
createCompactPeerListAndFlag(_droppedPeers);
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["added"] = freshPeerPair.first;
|
dict.put("added", freshPeerPair.first);
|
||||||
dict["added.f"] = freshPeerPair.second;
|
dict.put("added.f", freshPeerPair.second);
|
||||||
dict["dropped"] = droppedPeerPair.first;
|
dict.put("dropped", droppedPeerPair.first);
|
||||||
return bencode::encode(dict);
|
return bencode2::encode(&dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, std::string>
|
std::pair<std::string, std::string>
|
||||||
|
@ -158,17 +158,17 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len)
|
||||||
}
|
}
|
||||||
UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data));
|
UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data));
|
||||||
|
|
||||||
const BDE dict = bencode::decode(data+1, len-1);
|
SharedHandle<ValueBase> decoded = bencode2::decode(data+1, len-1);
|
||||||
if(dict.isDict()) {
|
const Dict* dict = asDict(decoded);
|
||||||
|
if(dict) {
|
||||||
PeerListProcessor proc;
|
PeerListProcessor proc;
|
||||||
const BDE& added = dict["added"];
|
const String* added = asString(dict->get("added"));
|
||||||
if(added.isString()) {
|
if(added) {
|
||||||
proc.extractPeerFromCompact(added, std::back_inserter(msg->_freshPeers));
|
proc.extractPeer(added, std::back_inserter(msg->_freshPeers));
|
||||||
}
|
}
|
||||||
const BDE& dropped = dict["dropped"];
|
const String* dropped = asString(dict->get("dropped"));
|
||||||
if(dropped.isString()) {
|
if(dropped) {
|
||||||
proc.extractPeerFromCompact(dropped,
|
proc.extractPeer(dropped, std::back_inserter(msg->_droppedPeers));
|
||||||
std::back_inserter(msg->_droppedPeers));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
|
|
|
@ -64,6 +64,11 @@ SharedHandle<String> String::g(const ValueType& string)
|
||||||
return SharedHandle<String>(new String(string));
|
return SharedHandle<String>(new String(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedHandle<String> String::g(const unsigned char* data, size_t length)
|
||||||
|
{
|
||||||
|
return SharedHandle<String>(new String(data, length));
|
||||||
|
}
|
||||||
|
|
||||||
void String::accept(ValueBaseVisitor& v) const
|
void String::accept(ValueBaseVisitor& v) const
|
||||||
{
|
{
|
||||||
v.visit(*this);
|
v.visit(*this);
|
||||||
|
@ -95,11 +100,21 @@ const SharedHandle<ValueBase>& List::get(size_t index) const
|
||||||
return list_[index];
|
return list_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void List::set(size_t index, const SharedHandle<ValueBase>& v)
|
||||||
|
{
|
||||||
|
list_[index] = v;
|
||||||
|
}
|
||||||
|
|
||||||
void List::append(const SharedHandle<ValueBase>& v)
|
void List::append(const SharedHandle<ValueBase>& v)
|
||||||
{
|
{
|
||||||
list_.push_back(v);
|
list_.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void List::append(const String::ValueType& string)
|
||||||
|
{
|
||||||
|
list_.push_back(String::g(string));
|
||||||
|
}
|
||||||
|
|
||||||
List& List::operator<<(const SharedHandle<ValueBase>& v)
|
List& List::operator<<(const SharedHandle<ValueBase>& v)
|
||||||
{
|
{
|
||||||
list_.push_back(v);
|
list_.push_back(v);
|
||||||
|
|
|
@ -96,6 +96,8 @@ public:
|
||||||
|
|
||||||
static SharedHandle<String> g(const ValueType& string);
|
static SharedHandle<String> g(const ValueType& string);
|
||||||
|
|
||||||
|
static SharedHandle<String> g(const unsigned char* data, size_t length);
|
||||||
|
|
||||||
virtual void accept(ValueBaseVisitor& visitor) const;
|
virtual void accept(ValueBaseVisitor& visitor) const;
|
||||||
private:
|
private:
|
||||||
ValueType str_;
|
ValueType str_;
|
||||||
|
@ -128,12 +130,18 @@ public:
|
||||||
// Appends given v to list.
|
// Appends given v to list.
|
||||||
void append(const SharedHandle<ValueBase>& v);
|
void append(const SharedHandle<ValueBase>& v);
|
||||||
|
|
||||||
|
// Appeding string is so common that we provide shortcut function.
|
||||||
|
void append(const String::ValueType& string);
|
||||||
|
|
||||||
// Alias for append()
|
// Alias for append()
|
||||||
List& operator<<(const SharedHandle<ValueBase>& v);
|
List& operator<<(const SharedHandle<ValueBase>& v);
|
||||||
|
|
||||||
// Returns the object at given index.
|
// Returns the object at given index.
|
||||||
const SharedHandle<ValueBase>& get(size_t index) const;
|
const SharedHandle<ValueBase>& get(size_t index) const;
|
||||||
|
|
||||||
|
// Set the object at given index.
|
||||||
|
void set(size_t index, const SharedHandle<ValueBase>& v);
|
||||||
|
|
||||||
// Returns the const reference of the object at the given index.
|
// Returns the const reference of the object at the given index.
|
||||||
const SharedHandle<ValueBase>& operator[](size_t index) const;
|
const SharedHandle<ValueBase>& operator[](size_t index) const;
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,11 @@ XmlRpcRequestProcessor::parseMemory(const std::string& xml)
|
||||||
if(r != 0) {
|
if(r != 0) {
|
||||||
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
|
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
|
||||||
}
|
}
|
||||||
return XmlRpcRequest(_stm->getMethodName(), _stm->getCurrentFrameValue());
|
if(!asList(_stm->getCurrentFrameValue())) {
|
||||||
|
throw DL_ABORT_EX("Bad XML-RPC parameter list");
|
||||||
|
}
|
||||||
|
return XmlRpcRequest(_stm->getMethodName(),
|
||||||
|
static_pointer_cast<List>(_stm->getCurrentFrameValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "XmlRpcMethod.h"
|
#include "XmlRpcMethod.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "BDE.h"
|
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
@ -52,6 +51,7 @@
|
||||||
#include "CheckIntegrityEntry.h"
|
#include "CheckIntegrityEntry.h"
|
||||||
#include "ServerStatMan.h"
|
#include "ServerStatMan.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -61,11 +61,12 @@ XmlRpcMethod::XmlRpcMethod():
|
||||||
_optionParser(OptionParser::getInstance()),
|
_optionParser(OptionParser::getInstance()),
|
||||||
_logger(LogFactory::getInstance()) {}
|
_logger(LogFactory::getInstance()) {}
|
||||||
|
|
||||||
BDE XmlRpcMethod::createErrorResponse(const Exception& e)
|
SharedHandle<ValueBase> XmlRpcMethod::createErrorResponse
|
||||||
|
(const Exception& e)
|
||||||
{
|
{
|
||||||
BDE params = BDE::dict();
|
SharedHandle<Dict> params = Dict::g();
|
||||||
params["faultCode"] = BDE(1);
|
params->put("faultCode", Integer::g(1));
|
||||||
params["faultString"] = BDE(e.what());
|
params->put("faultString", std::string(e.what()));
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,29 +106,35 @@ static void gatherOption
|
||||||
("We don't know how to deal with %s option",
|
("We don't know how to deal with %s option",
|
||||||
optionName.c_str()).str());
|
optionName.c_str()).str());
|
||||||
}
|
}
|
||||||
// header and index-out option can take array as value
|
const String* opval = asString((*first).second);
|
||||||
const BDE& value = (*first).second;
|
if(opval) {
|
||||||
if((optionName == PREF_HEADER || optionName == PREF_INDEX_OUT) &&
|
optionHandler->parse(*option.get(), opval->s());
|
||||||
value.isList()){
|
} else {
|
||||||
for(BDE::List::const_iterator argiter = value.listBegin(),
|
// header and index-out option can take array as value
|
||||||
eoi = value.listEnd(); argiter != eoi; ++argiter) {
|
const List* oplist = asList((*first).second);
|
||||||
if((*argiter).isString()) {
|
if(oplist &&
|
||||||
optionHandler->parse(*option.get(), (*argiter).s());
|
(optionName == PREF_HEADER || optionName == PREF_INDEX_OUT)) {
|
||||||
|
for(List::ValueType::const_iterator argiter = oplist->begin(),
|
||||||
|
eoi = oplist->end(); argiter != eoi; ++argiter) {
|
||||||
|
const String* opval = asString(*argiter);
|
||||||
|
if(opval) {
|
||||||
|
optionHandler->parse(*option.get(), opval->s());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(value.isString()) {
|
|
||||||
optionHandler->parse(*option.get(), value.s());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethod::gatherRequestOption
|
void XmlRpcMethod::gatherRequestOption
|
||||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
(const SharedHandle<Option>& option, const Dict* optionsDict)
|
||||||
{
|
{
|
||||||
gatherOption(optionsDict.dictBegin(), optionsDict.dictEnd(),
|
if(optionsDict) {
|
||||||
listRequestOptions(),
|
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||||
option, _optionParser);
|
listRequestOptions(),
|
||||||
|
option, _optionParser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy option in the range [optNameFirst, optNameLast) from src to
|
// Copy option in the range [optNameFirst, optNameLast) from src to
|
||||||
|
@ -158,11 +165,13 @@ const std::set<std::string>& listChangeableOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethod::gatherChangeableOption
|
void XmlRpcMethod::gatherChangeableOption
|
||||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
(const SharedHandle<Option>& option, const Dict* optionsDict)
|
||||||
{
|
{
|
||||||
gatherOption(optionsDict.dictBegin(), optionsDict.dictEnd(),
|
if(optionsDict) {
|
||||||
listChangeableOptions(),
|
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||||
option, _optionParser);
|
listChangeableOptions(),
|
||||||
|
option, _optionParser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethod::applyChangeableOption(Option* dest, Option* src) const
|
void XmlRpcMethod::applyChangeableOption(Option* dest, Option* src) const
|
||||||
|
@ -183,11 +192,13 @@ const std::set<std::string>& listChangeableGlobalOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethod::gatherChangeableGlobalOption
|
void XmlRpcMethod::gatherChangeableGlobalOption
|
||||||
(const SharedHandle<Option>& option, const BDE& optionsDict)
|
(const SharedHandle<Option>& option, const Dict* optionsDict)
|
||||||
{
|
{
|
||||||
gatherOption(optionsDict.dictBegin(), optionsDict.dictEnd(),
|
if(optionsDict) {
|
||||||
listChangeableGlobalOptions(),
|
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||||
option, _optionParser);
|
listChangeableGlobalOptions(),
|
||||||
|
option, _optionParser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethod::applyChangeableGlobalOption(Option* dest, Option* src) const
|
void XmlRpcMethod::applyChangeableGlobalOption(Option* dest, Option* src) const
|
||||||
|
|
|
@ -40,12 +40,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
class OptionParser;
|
class OptionParser;
|
||||||
class BDE;
|
|
||||||
class Logger;
|
class Logger;
|
||||||
class Option;
|
class Option;
|
||||||
class Exception;
|
class Exception;
|
||||||
|
@ -71,26 +71,27 @@ protected:
|
||||||
// Subclass must implement this function to fulfil XmlRpcRequest
|
// Subclass must implement this function to fulfil XmlRpcRequest
|
||||||
// req. The return value of this method is used as a return value
|
// req. The return value of this method is used as a return value
|
||||||
// of XML-RPC request.
|
// of XML-RPC request.
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e) = 0;
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e) = 0;
|
||||||
|
|
||||||
void gatherRequestOption(const SharedHandle<Option>& option,
|
void gatherRequestOption
|
||||||
const BDE& optionsDict);
|
(const SharedHandle<Option>& option, const Dict* optionsDict);
|
||||||
|
|
||||||
void gatherChangeableOption(const SharedHandle<Option>& option,
|
void gatherChangeableOption
|
||||||
const BDE& optionDict);
|
(const SharedHandle<Option>& option, const Dict* optionDict);
|
||||||
|
|
||||||
// Copy options which is changeable in XML-RPC changeOption command
|
// Copy options which is changeable in XML-RPC changeOption command
|
||||||
// to dest.
|
// to dest.
|
||||||
void applyChangeableOption(Option* dest, Option* src) const;
|
void applyChangeableOption(Option* dest, Option* src) const;
|
||||||
|
|
||||||
void gatherChangeableGlobalOption(const SharedHandle<Option>& option,
|
void gatherChangeableGlobalOption(const SharedHandle<Option>& option,
|
||||||
const BDE& optionDict);
|
const Dict* optionDict);
|
||||||
|
|
||||||
// Copy options which is changeable in XML-RPC changeGlobalOption
|
// Copy options which is changeable in XML-RPC changeGlobalOption
|
||||||
// command to dest.
|
// command to dest.
|
||||||
void applyChangeableGlobalOption(Option* dest, Option* src) const;
|
void applyChangeableGlobalOption(Option* dest, Option* src) const;
|
||||||
|
|
||||||
BDE createErrorResponse(const Exception& e);
|
SharedHandle<ValueBase> createErrorResponse(const Exception& e);
|
||||||
|
|
||||||
const SharedHandle<OptionParser>& getOptionParser() const
|
const SharedHandle<OptionParser>& getOptionParser() const
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -41,10 +41,10 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "BDE.h"
|
|
||||||
#include "XmlRpcRequest.h"
|
#include "XmlRpcRequest.h"
|
||||||
#include "ValueBase.h"
|
#include "ValueBase.h"
|
||||||
#include "TorrentAttribute.h"
|
#include "TorrentAttribute.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -55,7 +55,8 @@ namespace xmlrpc {
|
||||||
|
|
||||||
class AddUriXmlRpcMethod:public XmlRpcMethod {
|
class AddUriXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -66,7 +67,8 @@ public:
|
||||||
|
|
||||||
class RemoveXmlRpcMethod:public XmlRpcMethod {
|
class RemoveXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -77,7 +79,8 @@ public:
|
||||||
|
|
||||||
class ForceRemoveXmlRpcMethod:public XmlRpcMethod {
|
class ForceRemoveXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -88,7 +91,8 @@ public:
|
||||||
|
|
||||||
class PauseXmlRpcMethod:public XmlRpcMethod {
|
class PauseXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -99,7 +103,8 @@ public:
|
||||||
|
|
||||||
class ForcePauseXmlRpcMethod:public XmlRpcMethod {
|
class ForcePauseXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -110,7 +115,8 @@ public:
|
||||||
|
|
||||||
class PauseAllXmlRpcMethod:public XmlRpcMethod {
|
class PauseAllXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -121,7 +127,8 @@ public:
|
||||||
|
|
||||||
class ForcePauseAllXmlRpcMethod:public XmlRpcMethod {
|
class ForcePauseAllXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -132,7 +139,8 @@ public:
|
||||||
|
|
||||||
class UnpauseXmlRpcMethod:public XmlRpcMethod {
|
class UnpauseXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -143,7 +151,8 @@ public:
|
||||||
|
|
||||||
class UnpauseAllXmlRpcMethod:public XmlRpcMethod {
|
class UnpauseAllXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -155,7 +164,8 @@ public:
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
class AddTorrentXmlRpcMethod:public XmlRpcMethod {
|
class AddTorrentXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -168,7 +178,8 @@ public:
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
|
class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -180,7 +191,8 @@ public:
|
||||||
|
|
||||||
class PurgeDownloadResultXmlRpcMethod:public XmlRpcMethod {
|
class PurgeDownloadResultXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -191,7 +203,8 @@ public:
|
||||||
|
|
||||||
class GetUrisXmlRpcMethod:public XmlRpcMethod {
|
class GetUrisXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -202,7 +215,8 @@ public:
|
||||||
|
|
||||||
class GetFilesXmlRpcMethod:public XmlRpcMethod {
|
class GetFilesXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -214,7 +228,8 @@ public:
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
class GetPeersXmlRpcMethod:public XmlRpcMethod {
|
class GetPeersXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -226,7 +241,8 @@ public:
|
||||||
|
|
||||||
class GetServersXmlRpcMethod:public XmlRpcMethod {
|
class GetServersXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -237,7 +253,8 @@ public:
|
||||||
|
|
||||||
class TellStatusXmlRpcMethod:public XmlRpcMethod {
|
class TellStatusXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -248,7 +265,8 @@ public:
|
||||||
|
|
||||||
class TellActiveXmlRpcMethod:public XmlRpcMethod {
|
class TellActiveXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -279,7 +297,6 @@ private:
|
||||||
} else if(size <= (size_t)offset) {
|
} else if(size <= (size_t)offset) {
|
||||||
return std::make_pair(last, last);
|
return std::make_pair(last, last);
|
||||||
}
|
}
|
||||||
BDE list = BDE::list();
|
|
||||||
size_t lastDistance;
|
size_t lastDistance;
|
||||||
if(size < offset+num) {
|
if(size < offset+num) {
|
||||||
lastDistance = size;
|
lastDistance = size;
|
||||||
|
@ -292,34 +309,37 @@ private:
|
||||||
return std::make_pair(first, last);
|
return std::make_pair(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkPaginationParams(const BDE& params) const
|
void checkPaginationParams(const SharedHandle<List>& params) const
|
||||||
{
|
{
|
||||||
assert(params.isList());
|
if(params->size() != 2) {
|
||||||
if(params.size() != 2 ||
|
throw DL_ABORT_EX("Invalid argument. Specify offset and num in integer.");
|
||||||
!params[0].isInteger() || !params[1].isInteger() ||
|
}
|
||||||
params[1].i() < 0) {
|
const Integer* p1 = asInteger(params->get(0));
|
||||||
|
const Integer* p2 = asInteger(params->get(1));
|
||||||
|
if(!p1 || !p2 || p2->i() < 0) {
|
||||||
throw DL_ABORT_EX("Invalid argument. Specify offset and num in integer.");
|
throw DL_ABORT_EX("Invalid argument. Specify offset and num in integer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e)
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
const BDE& params = req.params;
|
const SharedHandle<List>& params = req.params;
|
||||||
checkPaginationParams(params);
|
checkPaginationParams(params);
|
||||||
ssize_t offset = params[0].i();
|
ssize_t offset = asInteger(params->get(0))->i();
|
||||||
size_t num = params[1].i();
|
size_t num = asInteger(params->get(1))->i();
|
||||||
const std::deque<SharedHandle<T> >& items = getItems(e);
|
const std::deque<SharedHandle<T> >& items = getItems(e);
|
||||||
std::pair<typename std::deque<SharedHandle<T> >::const_iterator,
|
std::pair<typename std::deque<SharedHandle<T> >::const_iterator,
|
||||||
typename std::deque<SharedHandle<T> >::const_iterator> range =
|
typename std::deque<SharedHandle<T> >::const_iterator> range =
|
||||||
getPaginationRange(offset, num, items.begin(), items.end());
|
getPaginationRange(offset, num, items.begin(), items.end());
|
||||||
BDE list = BDE::list();
|
SharedHandle<List> list = List::g();
|
||||||
for(; range.first != range.second; ++range.first) {
|
for(; range.first != range.second; ++range.first) {
|
||||||
BDE entryDict = BDE::dict();
|
SharedHandle<Dict> entryDict = Dict::g();
|
||||||
createEntry(entryDict, *range.first, e);
|
createEntry(entryDict, *range.first, e);
|
||||||
list << entryDict;
|
list->append(entryDict);
|
||||||
}
|
}
|
||||||
if(offset < 0) {
|
if(offset < 0) {
|
||||||
std::reverse(list.listBegin(), list.listEnd());
|
std::reverse(list->begin(), list->end());
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -328,7 +348,9 @@ protected:
|
||||||
getItems(DownloadEngine* e) const = 0;
|
getItems(DownloadEngine* e) const = 0;
|
||||||
|
|
||||||
virtual void createEntry
|
virtual void createEntry
|
||||||
(BDE& entryDict, const SharedHandle<T>& item, DownloadEngine* e) const = 0;
|
(const SharedHandle<Dict>& entryDict,
|
||||||
|
const SharedHandle<T>& item,
|
||||||
|
DownloadEngine* e) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TellWaitingXmlRpcMethod:
|
class TellWaitingXmlRpcMethod:
|
||||||
|
@ -338,7 +360,8 @@ protected:
|
||||||
getItems(DownloadEngine* e) const;
|
getItems(DownloadEngine* e) const;
|
||||||
|
|
||||||
virtual void createEntry
|
virtual void createEntry
|
||||||
(BDE& entryDict, const SharedHandle<RequestGroup>& item,
|
(const SharedHandle<Dict>& entryDict,
|
||||||
|
const SharedHandle<RequestGroup>& item,
|
||||||
DownloadEngine* e) const;
|
DownloadEngine* e) const;
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
|
@ -355,7 +378,8 @@ protected:
|
||||||
getItems(DownloadEngine* e) const;
|
getItems(DownloadEngine* e) const;
|
||||||
|
|
||||||
virtual void createEntry
|
virtual void createEntry
|
||||||
(BDE& entryDict, const SharedHandle<DownloadResult>& item,
|
(const SharedHandle<Dict>& entryDict,
|
||||||
|
const SharedHandle<DownloadResult>& item,
|
||||||
DownloadEngine* e) const;
|
DownloadEngine* e) const;
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
|
@ -367,7 +391,8 @@ public:
|
||||||
|
|
||||||
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
|
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -378,7 +403,8 @@ public:
|
||||||
|
|
||||||
class ChangeGlobalOptionXmlRpcMethod:public XmlRpcMethod {
|
class ChangeGlobalOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -389,7 +415,8 @@ public:
|
||||||
|
|
||||||
class GetVersionXmlRpcMethod:public XmlRpcMethod {
|
class GetVersionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -400,7 +427,8 @@ public:
|
||||||
|
|
||||||
class GetOptionXmlRpcMethod:public XmlRpcMethod {
|
class GetOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -411,7 +439,8 @@ public:
|
||||||
|
|
||||||
class GetGlobalOptionXmlRpcMethod:public XmlRpcMethod {
|
class GetGlobalOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -422,7 +451,8 @@ public:
|
||||||
|
|
||||||
class ChangePositionXmlRpcMethod:public XmlRpcMethod {
|
class ChangePositionXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -433,7 +463,8 @@ public:
|
||||||
|
|
||||||
class ChangeUriXmlRpcMethod:public XmlRpcMethod {
|
class ChangeUriXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -444,7 +475,8 @@ public:
|
||||||
|
|
||||||
class GetSessionInfoXmlRpcMethod:public XmlRpcMethod {
|
class GetSessionInfoXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -455,7 +487,8 @@ public:
|
||||||
|
|
||||||
class ShutdownXmlRpcMethod:public XmlRpcMethod {
|
class ShutdownXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -466,7 +499,8 @@ public:
|
||||||
|
|
||||||
class ForceShutdownXmlRpcMethod:public XmlRpcMethod {
|
class ForceShutdownXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -477,7 +511,8 @@ public:
|
||||||
|
|
||||||
class SystemMulticallXmlRpcMethod:public XmlRpcMethod {
|
class SystemMulticallXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
public:
|
public:
|
||||||
static const std::string& getMethodName()
|
static const std::string& getMethodName()
|
||||||
{
|
{
|
||||||
|
@ -488,23 +523,25 @@ public:
|
||||||
|
|
||||||
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
|
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual SharedHandle<ValueBase> process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to store data to entryDict from ds. This function
|
// Helper function to store data to entryDict from ds. This function
|
||||||
// is used by tellStatus method.
|
// is used by tellStatus method.
|
||||||
void gatherStoppedDownload
|
void gatherStoppedDownload
|
||||||
(BDE& entryDict, const SharedHandle<DownloadResult>& ds);
|
(const SharedHandle<Dict>& entryDict, const SharedHandle<DownloadResult>& ds);
|
||||||
|
|
||||||
// Helper function to store data to entryDict from group. This
|
// Helper function to store data to entryDict from group. This
|
||||||
// function is used by tellStatus/tellActive/tellWaiting method
|
// function is used by tellStatus/tellActive/tellWaiting method
|
||||||
void gatherProgressCommon
|
void gatherProgressCommon
|
||||||
(BDE& entryDict, const SharedHandle<RequestGroup>& group);
|
(const SharedHandle<Dict>& entryDict, const SharedHandle<RequestGroup>& group);
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
// Helper function to store BitTorrent metadata from torrentAttrs.
|
// Helper function to store BitTorrent metadata from torrentAttrs.
|
||||||
void gatherBitTorrentMetadata
|
void gatherBitTorrentMetadata
|
||||||
(BDE& btDict, const SharedHandle<TorrentAttribute>& torrentAttrs);
|
(const SharedHandle<Dict>& btDict,
|
||||||
|
const SharedHandle<TorrentAttribute>& torrentAttrs);
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "BDE.h"
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -47,9 +47,10 @@ namespace xmlrpc {
|
||||||
|
|
||||||
struct XmlRpcRequest {
|
struct XmlRpcRequest {
|
||||||
std::string methodName;
|
std::string methodName;
|
||||||
BDE params;
|
SharedHandle<List> params;
|
||||||
|
|
||||||
XmlRpcRequest(const std::string& methodName, const BDE& params):
|
XmlRpcRequest(const std::string& methodName,
|
||||||
|
const SharedHandle<List>& params):
|
||||||
methodName(methodName), params(params) {}
|
methodName(methodName), params(params) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,11 @@ void XmlRpcRequestParserController::popStructFrame()
|
||||||
assert(!_frameStack.empty());
|
assert(!_frameStack.empty());
|
||||||
|
|
||||||
StateFrame parentFrame = _frameStack.top();
|
StateFrame parentFrame = _frameStack.top();
|
||||||
assert(parentFrame._value.isDict());
|
Dict* dict = asDict(parentFrame._value);
|
||||||
|
assert(dict);
|
||||||
_frameStack.pop();
|
_frameStack.pop();
|
||||||
if(_currentFrame.validMember()) {
|
if(_currentFrame.validMember()) {
|
||||||
parentFrame._value[_currentFrame._name] = _currentFrame._value;
|
dict->put(_currentFrame._name, _currentFrame._value);
|
||||||
}
|
}
|
||||||
_currentFrame = parentFrame;
|
_currentFrame = parentFrame;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +65,33 @@ void XmlRpcRequestParserController::popArrayFrame()
|
||||||
assert(!_frameStack.empty());
|
assert(!_frameStack.empty());
|
||||||
|
|
||||||
StateFrame parentFrame = _frameStack.top();
|
StateFrame parentFrame = _frameStack.top();
|
||||||
assert(parentFrame._value.isList());
|
List* list = asList(parentFrame._value);
|
||||||
|
assert(list);
|
||||||
_frameStack.pop();
|
_frameStack.pop();
|
||||||
if(!_currentFrame._value.isNone()) {
|
if(!_currentFrame._value.isNull()) {
|
||||||
parentFrame._value << _currentFrame._value;
|
list->append(_currentFrame._value);
|
||||||
}
|
}
|
||||||
_currentFrame = parentFrame;
|
_currentFrame = parentFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcRequestParserController::setCurrentFrameValue
|
||||||
|
(const SharedHandle<ValueBase>& value)
|
||||||
|
{
|
||||||
|
_currentFrame._value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcRequestParserController::setCurrentFrameName
|
||||||
|
(const std::string& name)
|
||||||
|
{
|
||||||
|
_currentFrame._name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SharedHandle<ValueBase>&
|
||||||
|
XmlRpcRequestParserController::getCurrentFrameValue() const
|
||||||
|
{
|
||||||
|
return _currentFrame._value;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "BDE.h"
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ class XmlRpcRequestParserController {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct StateFrame {
|
struct StateFrame {
|
||||||
BDE _value;
|
SharedHandle<ValueBase> _value;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
|
||||||
bool validMember() const
|
bool validMember() const
|
||||||
{
|
{
|
||||||
return !_value.isNone() && !_name.empty();
|
return !_value.isNull() && !_name.empty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,17 +75,11 @@ public:
|
||||||
// to p and _currentFrame = p;
|
// to p and _currentFrame = p;
|
||||||
void popArrayFrame();
|
void popArrayFrame();
|
||||||
|
|
||||||
void setCurrentFrameValue(const BDE& value)
|
void setCurrentFrameValue(const SharedHandle<ValueBase>& value);
|
||||||
{
|
|
||||||
_currentFrame._value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCurrentFrameName(const std::string& name)
|
void setCurrentFrameName(const std::string& name);
|
||||||
{
|
|
||||||
_currentFrame._name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BDE& getCurrentFrameValue() const { return _currentFrame._value; }
|
const SharedHandle<ValueBase>& getCurrentFrameValue() const;
|
||||||
|
|
||||||
void setMethodName(const std::string& methodName)
|
void setMethodName(const std::string& methodName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,7 +83,7 @@ void MethodCallXmlRpcRequestParserState::beginElement
|
||||||
if(name == elements::METHOD_NAME) {
|
if(name == elements::METHOD_NAME) {
|
||||||
stm->pushMethodNameState();
|
stm->pushMethodNameState();
|
||||||
} else if(name == elements::A2_PARAMS) {
|
} else if(name == elements::A2_PARAMS) {
|
||||||
stm->setCurrentFrameValue(BDE::list());
|
stm->setCurrentFrameValue(List::g());
|
||||||
stm->pushParamsState();
|
stm->pushParamsState();
|
||||||
} else {
|
} else {
|
||||||
stm->pushUnknownElementState();
|
stm->pushUnknownElementState();
|
||||||
|
@ -155,10 +155,10 @@ void ValueXmlRpcRequestParserState::beginElement
|
||||||
if(name == elements::I4 || name == elements::INT) {
|
if(name == elements::I4 || name == elements::INT) {
|
||||||
stm->pushIntState();
|
stm->pushIntState();
|
||||||
} else if(name == elements::STRUCT) {
|
} else if(name == elements::STRUCT) {
|
||||||
stm->setCurrentFrameValue(BDE::dict());
|
stm->setCurrentFrameValue(Dict::g());
|
||||||
stm->pushStructState();
|
stm->pushStructState();
|
||||||
} else if(name == elements::ARRAY) {
|
} else if(name == elements::ARRAY) {
|
||||||
stm->setCurrentFrameValue(BDE::list());
|
stm->setCurrentFrameValue(List::g());
|
||||||
stm->pushArrayState();
|
stm->pushArrayState();
|
||||||
} else if(name == elements::STRING || name == elements::DOUBLE) {
|
} else if(name == elements::STRING || name == elements::DOUBLE) {
|
||||||
stm->pushStringState();
|
stm->pushStringState();
|
||||||
|
@ -186,9 +186,9 @@ void IntXmlRpcRequestParserState::endElement
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
int64_t value = util::parseLLInt(characters);
|
int64_t value = util::parseLLInt(characters);
|
||||||
stm->setCurrentFrameValue(BDE(value));
|
stm->setCurrentFrameValue(Integer::g(value));
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
// nothing to do here: We just leave current frame value to BDE::none
|
// nothing to do here: We just leave current frame value to null.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ void StringXmlRpcRequestParserState::endElement
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& characters)
|
const std::string& characters)
|
||||||
{
|
{
|
||||||
stm->setCurrentFrameValue(BDE(characters));
|
stm->setCurrentFrameValue(String::g(characters));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base64XmlRpcRequestParserState
|
// Base64XmlRpcRequestParserState
|
||||||
|
@ -225,7 +225,7 @@ void Base64XmlRpcRequestParserState::endElement
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& characters)
|
const std::string& characters)
|
||||||
{
|
{
|
||||||
stm->setCurrentFrameValue(BDE(Base64::decode(characters)));
|
stm->setCurrentFrameValue(String::g(Base64::decode(characters)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// StructXmlRpcRequestParserState
|
// StructXmlRpcRequestParserState
|
||||||
|
|
|
@ -41,14 +41,12 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include "BDE.h"
|
|
||||||
#include "XmlRpcRequestParserController.h"
|
#include "XmlRpcRequestParserController.h"
|
||||||
#include "XmlRpcRequestParserStateImpl.h"
|
#include "XmlRpcRequestParserStateImpl.h"
|
||||||
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BDE;
|
|
||||||
|
|
||||||
namespace xmlrpc {
|
namespace xmlrpc {
|
||||||
|
|
||||||
class XmlRpcRequestParserStateMachine {
|
class XmlRpcRequestParserStateMachine {
|
||||||
|
@ -116,12 +114,12 @@ public:
|
||||||
_controller->pushFrame();
|
_controller->pushFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentFrameValue(const BDE& value)
|
void setCurrentFrameValue(const SharedHandle<ValueBase>& value)
|
||||||
{
|
{
|
||||||
_controller->setCurrentFrameValue(value);
|
_controller->setCurrentFrameValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BDE& getCurrentFrameValue() const
|
const SharedHandle<ValueBase>& getCurrentFrameValue() const
|
||||||
{
|
{
|
||||||
return _controller->getCurrentFrameValue();
|
return _controller->getCurrentFrameValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,51 +47,56 @@ namespace aria2 {
|
||||||
namespace xmlrpc {
|
namespace xmlrpc {
|
||||||
|
|
||||||
template<typename OutputStream>
|
template<typename OutputStream>
|
||||||
static void encodeValue(const BDE& value, OutputStream& o);
|
static void encodeValue(const SharedHandle<ValueBase>& value, OutputStream& o)
|
||||||
|
|
||||||
template<typename InputIterator, typename OutputStream>
|
|
||||||
static void encodeArray
|
|
||||||
(InputIterator first, InputIterator last, OutputStream& o)
|
|
||||||
{
|
{
|
||||||
o << "<array>" << "<data>";
|
class XmlValueBaseVisitor:public ValueBaseVisitor {
|
||||||
for(; first != last; ++first) {
|
private:
|
||||||
encodeValue(*first, o);
|
OutputStream& o_;
|
||||||
}
|
public:
|
||||||
o << "</data>" << "</array>";
|
XmlValueBaseVisitor(OutputStream& o):o_(o) {}
|
||||||
}
|
|
||||||
|
|
||||||
template<typename InputIterator, typename OutputStream>
|
virtual ~XmlValueBaseVisitor() {}
|
||||||
static void encodeStruct
|
|
||||||
(InputIterator first, InputIterator last, OutputStream& o)
|
virtual void visit(const String& v)
|
||||||
{
|
{
|
||||||
o << "<struct>";
|
o_ << "<value><string>" << util::htmlEscape(v.s()) << "</string></value>";
|
||||||
for(; first != last; ++first) {
|
}
|
||||||
o << "<member>"
|
|
||||||
<< "<name>" << util::htmlEscape((*first).first) << "</name>";
|
virtual void visit(const Integer& v)
|
||||||
encodeValue((*first).second, o);
|
{
|
||||||
o << "</member>";
|
o_ << "<value><int>" << v.i() << "</int></value>";
|
||||||
}
|
}
|
||||||
o << "</struct>";
|
|
||||||
|
virtual void visit(const List& v)
|
||||||
|
{
|
||||||
|
o_ << "<value><array><data>";
|
||||||
|
for(List::ValueType::const_iterator i = v.begin(), eoi = v.end();
|
||||||
|
i != eoi; ++i) {
|
||||||
|
(*i)->accept(*this);
|
||||||
|
}
|
||||||
|
o_ << "</data></array></value>";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void visit(const Dict& v)
|
||||||
|
{
|
||||||
|
o_ << "<value><struct>";
|
||||||
|
for(Dict::ValueType::const_iterator i = v.begin(), eoi = v.end();
|
||||||
|
i != eoi; ++i) {
|
||||||
|
o_ << "<member><name>" << util::htmlEscape((*i).first) << "</name>";
|
||||||
|
(*i).second->accept(*this);
|
||||||
|
o_ << "</member>";
|
||||||
|
}
|
||||||
|
o_ << "</struct></value>";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
XmlValueBaseVisitor visitor(o);
|
||||||
|
value->accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputStream>
|
template<typename OutputStream>
|
||||||
static void encodeValue(const BDE& value, OutputStream& o)
|
std::string encodeAll
|
||||||
{
|
(OutputStream& o, int code, const SharedHandle<ValueBase>& param)
|
||||||
o << "<value>";
|
|
||||||
if(value.isString()) {
|
|
||||||
o << "<string>" << util::htmlEscape(value.s()) << "</string>";
|
|
||||||
} else if(value.isInteger()) {
|
|
||||||
o << "<int>" << value.i() << "</int>";
|
|
||||||
} else if(value.isList()) {
|
|
||||||
encodeArray(value.listBegin(), value.listEnd(), o);
|
|
||||||
} else if(value.isDict()) {
|
|
||||||
encodeStruct(value.dictBegin(), value.dictEnd(), o);
|
|
||||||
}
|
|
||||||
o << "</value>";
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename OutputStream>
|
|
||||||
std::string encodeAll(OutputStream& o, int code, const BDE& param)
|
|
||||||
{
|
{
|
||||||
o << "<?xml version=\"1.0\"?>" << "<methodResponse>";
|
o << "<?xml version=\"1.0\"?>" << "<methodResponse>";
|
||||||
if(code == 0) {
|
if(code == 0) {
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "BDE.h"
|
#include "ValueBase.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -49,9 +49,10 @@ struct XmlRpcResponse {
|
||||||
// 0 for success, non-zero for error
|
// 0 for success, non-zero for error
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
BDE param;
|
SharedHandle<ValueBase> param;
|
||||||
|
|
||||||
XmlRpcResponse(int code, const BDE& param):code(code), param(param) {}
|
XmlRpcResponse
|
||||||
|
(int code, const SharedHandle<ValueBase>& param):code(code), param(param) {}
|
||||||
|
|
||||||
std::string toXml(bool gzip = false) const;
|
std::string toXml(bool gzip = false) const;
|
||||||
};
|
};
|
||||||
|
|
242
src/bencode.cc
242
src/bencode.cc
|
@ -1,242 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "StringFormat.h"
|
|
||||||
#include "DlAbortEx.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
namespace bencode {
|
|
||||||
|
|
||||||
static BDE decodeiter(std::istream& ss, size_t depth);
|
|
||||||
|
|
||||||
static void checkdelim(std::istream& ss, const char delim = ':')
|
|
||||||
{
|
|
||||||
char d;
|
|
||||||
if(!(ss.get(d) && d == delim)) {
|
|
||||||
throw DL_ABORT_EX
|
|
||||||
(StringFormat("Bencode decoding failed: Delimiter '%c' not found.",
|
|
||||||
delim).str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string decoderawstring(std::istream& ss)
|
|
||||||
{
|
|
||||||
int length;
|
|
||||||
ss >> length;
|
|
||||||
if(!ss || length < 0) {
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed:"
|
|
||||||
" A positive integer expected but none found.");
|
|
||||||
}
|
|
||||||
// TODO check length, it must be less than or equal to INT_MAX
|
|
||||||
checkdelim(ss);
|
|
||||||
char* buf = new char[length];
|
|
||||||
ss.read(buf, length);
|
|
||||||
std::string str(&buf[0], &buf[length]);
|
|
||||||
delete [] buf;
|
|
||||||
if(ss.gcount() != static_cast<int>(length)) {
|
|
||||||
throw DL_ABORT_EX
|
|
||||||
(StringFormat("Bencode decoding failed:"
|
|
||||||
" Expected %lu bytes of data, but only %d read.",
|
|
||||||
static_cast<unsigned long>(length), ss.gcount()).str());
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDE decodestring(std::istream& ss)
|
|
||||||
{
|
|
||||||
return BDE(decoderawstring(ss));
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDE decodeinteger(std::istream& ss)
|
|
||||||
{
|
|
||||||
BDE::Integer integer;
|
|
||||||
ss >> integer;
|
|
||||||
if(!ss) {
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed:"
|
|
||||||
" Integer expected but none found");
|
|
||||||
}
|
|
||||||
checkdelim(ss, 'e');
|
|
||||||
return BDE(integer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDE decodedict(std::istream& ss, size_t depth)
|
|
||||||
{
|
|
||||||
BDE dict = BDE::dict();
|
|
||||||
char c;
|
|
||||||
while(ss.get(c)) {
|
|
||||||
if(c == 'e') {
|
|
||||||
return dict;
|
|
||||||
} else {
|
|
||||||
ss.unget();
|
|
||||||
std::string key = decoderawstring(ss);
|
|
||||||
dict[key] = decodeiter(ss, depth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed:"
|
|
||||||
" Unexpected EOF in dict context. 'e' expected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDE decodelist(std::istream& ss, size_t depth)
|
|
||||||
{
|
|
||||||
BDE list = BDE::list();
|
|
||||||
char c;
|
|
||||||
while(ss.get(c)) {
|
|
||||||
if(c == 'e') {
|
|
||||||
return list;
|
|
||||||
} else {
|
|
||||||
ss.unget();
|
|
||||||
list << decodeiter(ss, depth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed:"
|
|
||||||
" Unexpected EOF in list context. 'e' expected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkDepth(size_t depth)
|
|
||||||
{
|
|
||||||
if(depth >= MAX_STRUCTURE_DEPTH) {
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed: Structure is too deep.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDE decodeiter(std::istream& ss, size_t depth)
|
|
||||||
{
|
|
||||||
checkDepth(depth);
|
|
||||||
char c;
|
|
||||||
if(!ss.get(c)) {
|
|
||||||
throw DL_ABORT_EX("Bencode decoding failed:"
|
|
||||||
" Unexpected EOF in term context."
|
|
||||||
" 'd', 'l', 'i' or digit is expected.");
|
|
||||||
}
|
|
||||||
if(c == 'd') {
|
|
||||||
return decodedict(ss, depth+1);
|
|
||||||
} else if(c == 'l') {
|
|
||||||
return decodelist(ss, depth+1);
|
|
||||||
} else if(c == 'i') {
|
|
||||||
return decodeinteger(ss);
|
|
||||||
} else {
|
|
||||||
ss.unget();
|
|
||||||
return decodestring(ss);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decode(std::istream& in)
|
|
||||||
{
|
|
||||||
return decodeiter(in, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decode(const std::string& s)
|
|
||||||
{
|
|
||||||
size_t end;
|
|
||||||
return decode(s, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decode(const std::string& s, size_t& end)
|
|
||||||
{
|
|
||||||
if(s.empty()) {
|
|
||||||
return BDE::none;
|
|
||||||
}
|
|
||||||
std::istringstream ss(s);
|
|
||||||
|
|
||||||
BDE bde = decodeiter(ss, 0);
|
|
||||||
end = ss.tellg();
|
|
||||||
return bde;
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decode(const unsigned char* data, size_t length)
|
|
||||||
{
|
|
||||||
return decode(std::string(&data[0], &data[length]));
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decode(const unsigned char* data, size_t length, size_t& end)
|
|
||||||
{
|
|
||||||
return decode(std::string(&data[0], &data[length]), end);
|
|
||||||
}
|
|
||||||
|
|
||||||
BDE decodeFromFile(const std::string& filename)
|
|
||||||
{
|
|
||||||
std::ifstream f(filename.c_str(), std::ios::binary);
|
|
||||||
if(f) {
|
|
||||||
return decode(f);
|
|
||||||
} else {
|
|
||||||
throw DL_ABORT_EX
|
|
||||||
(StringFormat("Bencode decoding failed:"
|
|
||||||
" Cannot open file '%s'.", filename.c_str()).str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void encodeIter(std::ostream& o, const BDE& bde)
|
|
||||||
{
|
|
||||||
if(bde.isInteger()) {
|
|
||||||
o << "i" << bde.i() << "e";
|
|
||||||
} else if(bde.isString()) {
|
|
||||||
const std::string& s = bde.s();
|
|
||||||
o << s.size() << ":";
|
|
||||||
o.write(s.data(), s.size());
|
|
||||||
} else if(bde.isDict()) {
|
|
||||||
o << "d";
|
|
||||||
for(BDE::Dict::const_iterator i = bde.dictBegin(), eoi = bde.dictEnd();
|
|
||||||
i != eoi; ++i){
|
|
||||||
const std::string& key = (*i).first;
|
|
||||||
o << key.size() << ":";
|
|
||||||
o.write(key.data(), key.size());
|
|
||||||
encodeIter(o, (*i).second);
|
|
||||||
}
|
|
||||||
o << "e";
|
|
||||||
} else if(bde.isList()) {
|
|
||||||
o << "l";
|
|
||||||
for(BDE::List::const_iterator i = bde.listBegin(), eoi = bde.listEnd();
|
|
||||||
i != eoi; ++i){
|
|
||||||
encodeIter(o, *i);
|
|
||||||
}
|
|
||||||
o << "e";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string encode(const BDE& bde)
|
|
||||||
{
|
|
||||||
std::ostringstream ss;
|
|
||||||
encodeIter(ss, bde);
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace bencode
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
|
@ -1,72 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
#ifndef _D_BENCODE_H_
|
|
||||||
#define _D_BENCODE_H_
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
#include "BDE.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
namespace bencode {
|
|
||||||
|
|
||||||
const size_t MAX_STRUCTURE_DEPTH = 100;
|
|
||||||
|
|
||||||
BDE decode(std::istream& in);
|
|
||||||
|
|
||||||
// Decode the data in s.
|
|
||||||
BDE decode(const std::string& s);
|
|
||||||
|
|
||||||
// Decode the data in s. After decode is done successfully, return the
|
|
||||||
// bencoded string length in end.
|
|
||||||
BDE decode(const std::string& s, size_t& end);
|
|
||||||
|
|
||||||
BDE decode(const unsigned char* data, size_t length);
|
|
||||||
|
|
||||||
BDE decode(const unsigned char* data, size_t length, size_t& end);
|
|
||||||
|
|
||||||
BDE decodeFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
std::string encode(const BDE& bde);
|
|
||||||
|
|
||||||
} // namespace bencode
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
||||||
|
|
||||||
#endif // _D_BENCODE_H_
|
|
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "Randomizer.h"
|
#include "Randomizer.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
149
test/BDETest.cc
149
test/BDETest.cc
|
@ -1,149 +0,0 @@
|
||||||
#include "BDE.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
class BDETest:public CppUnit::TestFixture {
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(BDETest);
|
|
||||||
CPPUNIT_TEST(testString);
|
|
||||||
CPPUNIT_TEST(testInteger);
|
|
||||||
CPPUNIT_TEST(testDict);
|
|
||||||
CPPUNIT_TEST(testDictIter);
|
|
||||||
CPPUNIT_TEST(testList);
|
|
||||||
CPPUNIT_TEST(testListIter);
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
void testString();
|
|
||||||
void testInteger();
|
|
||||||
void testDict();
|
|
||||||
void testDictIter();
|
|
||||||
void testList();
|
|
||||||
void testListIter();
|
|
||||||
void testDecode();
|
|
||||||
void testEncode();
|
|
||||||
};
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( BDETest );
|
|
||||||
|
|
||||||
void BDETest::testString()
|
|
||||||
{
|
|
||||||
BDE s(std::string("aria2"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
|
|
||||||
|
|
||||||
unsigned char dataWithNull[] = { 0xf0, '\0', 0x0f };
|
|
||||||
BDE sWithNull(dataWithNull, sizeof(dataWithNull));
|
|
||||||
CPPUNIT_ASSERT(memcmp(dataWithNull, sWithNull.s().c_str(),
|
|
||||||
sizeof(dataWithNull)) == 0);
|
|
||||||
|
|
||||||
BDE zero("");
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), zero.s());
|
|
||||||
|
|
||||||
const unsigned char uc[] = { 0x08, 0x19, 0x2a, 0x3b };
|
|
||||||
BDE data(uc, sizeof(uc));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(util::toHex(uc, sizeof(uc)),
|
|
||||||
util::toHex(data.uc(), data.s().size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDETest::testInteger()
|
|
||||||
{
|
|
||||||
BDE integer(INT64_MAX);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(INT64_MAX, integer.i());
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDETest::testDict()
|
|
||||||
{
|
|
||||||
BDE dict = BDE::dict();
|
|
||||||
CPPUNIT_ASSERT(dict.empty());
|
|
||||||
|
|
||||||
dict["ki"] = 7;
|
|
||||||
dict["ks"] = std::string("abc");
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
|
|
||||||
CPPUNIT_ASSERT(dict.containsKey("ki"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), dict["ki"].i());
|
|
||||||
CPPUNIT_ASSERT(dict.containsKey("ks"));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("abc"), dict["ks"].s());
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT(dict["kn"].isNone()); // This adds kn key with default value.
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), dict.size());
|
|
||||||
CPPUNIT_ASSERT(dict.containsKey("kn"));
|
|
||||||
|
|
||||||
const BDE& ref = dict;
|
|
||||||
ref["kn2"]; // This doesn't add kn2 key.
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), ref.size());
|
|
||||||
CPPUNIT_ASSERT(!ref.containsKey("kn2"));
|
|
||||||
|
|
||||||
dict.removeKey("kn");
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
|
|
||||||
CPPUNIT_ASSERT(!dict.containsKey("kn"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDETest::testDictIter()
|
|
||||||
{
|
|
||||||
BDE dict = BDE::dict();
|
|
||||||
dict["alpha2"] = std::string("alpha2");
|
|
||||||
dict["charlie"] = std::string("charlie");
|
|
||||||
dict["bravo"] = std::string("bravo");
|
|
||||||
dict["alpha"] = std::string("alpha");
|
|
||||||
|
|
||||||
BDE::Dict::iterator i = dict.dictBegin();
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).first);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).first);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).first);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).first);
|
|
||||||
CPPUNIT_ASSERT(dict.dictEnd() == i);
|
|
||||||
|
|
||||||
const BDE& ref = dict;
|
|
||||||
BDE::Dict::const_iterator ci = ref.dictBegin();
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*ci++).first);
|
|
||||||
std::advance(ci, 3);
|
|
||||||
CPPUNIT_ASSERT(ref.dictEnd() == ci);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDETest::testList()
|
|
||||||
{
|
|
||||||
BDE list = BDE::list();
|
|
||||||
CPPUNIT_ASSERT(list.empty());
|
|
||||||
list << 7;
|
|
||||||
list << std::string("aria2");
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list.size());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), list[0].i());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), list[1].s());
|
|
||||||
|
|
||||||
const BDE& ref = list;
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), ref[0].i());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), ref[1].s());
|
|
||||||
}
|
|
||||||
|
|
||||||
void BDETest::testListIter()
|
|
||||||
{
|
|
||||||
BDE list = BDE::list();
|
|
||||||
list << std::string("alpha2");
|
|
||||||
list << std::string("charlie");
|
|
||||||
list << std::string("bravo");
|
|
||||||
list << std::string("alpha");
|
|
||||||
|
|
||||||
BDE::List::iterator i = list.listBegin();
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).s());
|
|
||||||
CPPUNIT_ASSERT(list.listEnd() == i);
|
|
||||||
|
|
||||||
const BDE& ref = list;
|
|
||||||
BDE::List::const_iterator ci = ref.listBegin();
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*ci++).s());
|
|
||||||
std::advance(ci, 3);
|
|
||||||
CPPUNIT_ASSERT(ref.listEnd() == ci);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
|
@ -1,202 +0,0 @@
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
|
|
||||||
#include "RecoverableException.h"
|
|
||||||
#include "TimeA2.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
class BencodeTest:public CppUnit::TestFixture {
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(BencodeTest);
|
|
||||||
CPPUNIT_TEST(testDecode);
|
|
||||||
CPPUNIT_TEST(testDecode_overflow);
|
|
||||||
CPPUNIT_TEST(testEncode);
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
void testDecode();
|
|
||||||
void testDecode_overflow();
|
|
||||||
void testEncode();
|
|
||||||
};
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( BencodeTest );
|
|
||||||
|
|
||||||
void BencodeTest::testDecode()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
// string, integer and list in dict
|
|
||||||
BDE dict =
|
|
||||||
bencode::decode("d4:name5:aria24:sizei12345678900e5:filesl3:bin3:docee");
|
|
||||||
CPPUNIT_ASSERT(dict.isDict());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), dict["name"].s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(12345678900LL),
|
|
||||||
dict["size"].i());
|
|
||||||
BDE list = dict["files"];
|
|
||||||
CPPUNIT_ASSERT(list.isList());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list.size());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("bin"), list[0].s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("doc"), list[1].s());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// dict in list
|
|
||||||
BDE list = bencode::decode("ld1:ki123eee");
|
|
||||||
CPPUNIT_ASSERT(list.isList());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), list.size());
|
|
||||||
BDE dict = list[0];
|
|
||||||
CPPUNIT_ASSERT(dict.isDict());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(123),
|
|
||||||
dict["k"].i());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// empty key is allowed
|
|
||||||
BDE s = bencode::decode("d0:1:ve");
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// empty string
|
|
||||||
BDE s = bencode::decode("0:");
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), s.s());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// empty dict
|
|
||||||
BDE d = bencode::decode("de");
|
|
||||||
CPPUNIT_ASSERT(d.empty());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// empty list
|
|
||||||
BDE l = bencode::decode("le");
|
|
||||||
CPPUNIT_ASSERT(l.empty());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// integer, without ending 'e'
|
|
||||||
try {
|
|
||||||
bencode::decode("i3");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" Delimiter 'e' not found."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// dict, without ending 'e'
|
|
||||||
try {
|
|
||||||
bencode::decode("d");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" Unexpected EOF in dict context."
|
|
||||||
" 'e' expected."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// list, without ending 'e'
|
|
||||||
try {
|
|
||||||
bencode::decode("l");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" Unexpected EOF in list context."
|
|
||||||
" 'e' expected."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// string, less than the specified length.
|
|
||||||
try {
|
|
||||||
bencode::decode("3:ab");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" Expected 3 bytes of data,"
|
|
||||||
" but only 2 read."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// string, but length is invalid
|
|
||||||
try {
|
|
||||||
bencode::decode("x:abc");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" A positive integer expected"
|
|
||||||
" but none found."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// string with minus length
|
|
||||||
try {
|
|
||||||
bencode::decode("-1:a");
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Bencode decoding failed:"
|
|
||||||
" A positive integer expected"
|
|
||||||
" but none found."),
|
|
||||||
std::string(e.what()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// empty encoded data
|
|
||||||
CPPUNIT_ASSERT(bencode::decode("").isNone());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// ignore trailing garbage at the end of the input.
|
|
||||||
BDE s = bencode::decode("5:aria2trail");
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Get trailing garbage position
|
|
||||||
size_t end;
|
|
||||||
BDE s = bencode::decode("5:aria2trail", end);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)7, end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BencodeTest::testDecode_overflow()
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
size_t depth = bencode::MAX_STRUCTURE_DEPTH+1;
|
|
||||||
for(size_t i = 0; i < depth; ++i) {
|
|
||||||
s += "l";
|
|
||||||
}
|
|
||||||
for(size_t i = 0; i < depth; ++i) {
|
|
||||||
s += "e";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
bencode::decode(s);
|
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
// success
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BencodeTest::testEncode()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
BDE dict = BDE::dict();
|
|
||||||
dict["name"] = std::string("aria2");
|
|
||||||
dict["loc"] = 80000;
|
|
||||||
dict["files"] = BDE::list();
|
|
||||||
dict["files"] << std::string("aria2c");
|
|
||||||
dict["attrs"] = BDE::dict();
|
|
||||||
dict["attrs"]["license"] = std::string("GPL");
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("d"
|
|
||||||
"5:attrsd7:license3:GPLe"
|
|
||||||
"5:filesl6:aria2ce"
|
|
||||||
"3:loci80000e"
|
|
||||||
"4:name5:aria2"
|
|
||||||
"e"),
|
|
||||||
bencode::encode(dict));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "MockDHTMessageDispatcher.h"
|
#include "MockDHTMessageDispatcher.h"
|
||||||
#include "MockDHTMessage.h"
|
#include "MockDHTMessage.h"
|
||||||
#include "DHTPeerAnnounceStorage.h"
|
#include "DHTPeerAnnounceStorage.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -61,19 +61,19 @@ void DHTAnnouncePeerMessageTest::testGetBencodedMessage()
|
||||||
msg.setVersion("A200");
|
msg.setVersion("A200");
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("announce_peer");
|
dict.put("q", "announce_peer");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
aDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
|
aDict->put("info_hash", String::g(infoHash, DHT_ID_LENGTH));
|
||||||
aDict["port"] = port;
|
aDict->put("port", Integer::g(port));
|
||||||
aDict["token"] = token;
|
aDict->put("token", token);
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode2::encode(&dict)),
|
||||||
util::percentEncode(msgbody));
|
util::percentEncode(msgbody));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -38,15 +38,15 @@ void DHTAnnouncePeerReplyMessageTest::testGetBencodedMessage()
|
||||||
msg.setVersion("A200");
|
msg.setVersion("A200");
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "MockDHTMessage.h"
|
#include "MockDHTMessage.h"
|
||||||
#include "MockDHTMessageDispatcher.h"
|
#include "MockDHTMessageDispatcher.h"
|
||||||
#include "DHTRoutingTable.h"
|
#include "DHTRoutingTable.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -62,17 +62,17 @@ void DHTFindNodeMessageTest::testGetBencodedMessage()
|
||||||
msg.setVersion("A200");
|
msg.setVersion("A200");
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("find_node");
|
dict.put("q", "find_node");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
aDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
aDict["target"] = BDE(targetNode->getID(), DHT_ID_LENGTH);
|
aDict->put("target", String::g(targetNode->getID(), DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTFindNodeMessageTest::testDoReceivedAction()
|
void DHTFindNodeMessageTest::testDoReceivedAction()
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -57,16 +57,16 @@ void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
|
||||||
|
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
rDict["nodes"] = compactNodeInfo;
|
rDict->put("nodes", compactNodeInfo);
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "DHTTokenTracker.h"
|
#include "DHTTokenTracker.h"
|
||||||
#include "DHTPeerAnnounceStorage.h"
|
#include "DHTPeerAnnounceStorage.h"
|
||||||
#include "DHTRoutingTable.h"
|
#include "DHTRoutingTable.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -83,17 +83,17 @@ void DHTGetPeersMessageTest::testGetBencodedMessage()
|
||||||
|
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("get_peers");
|
dict.put("q", "get_peers");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
aDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
|
aDict->put("info_hash", String::g(infoHash, DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode2::encode(&dict)),
|
||||||
util::percentEncode(msgbody));
|
util::percentEncode(msgbody));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
|
||||||
|
|
||||||
DHTGetPeersReplyMessage msg(localNode, remoteNode, token, transactionID);
|
DHTGetPeersReplyMessage msg(localNode, remoteNode, token, transactionID);
|
||||||
msg.setVersion("A200");
|
msg.setVersion("A200");
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
rDict["token"] = token;
|
rDict->put("token", token);
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
{
|
{
|
||||||
std::string compactNodeInfo;
|
std::string compactNodeInfo;
|
||||||
SharedHandle<DHTNode> nodes[8];
|
SharedHandle<DHTNode> nodes[8];
|
||||||
|
@ -69,29 +69,29 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
|
||||||
|
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
rDict["nodes"] = compactNodeInfo;
|
rDict->put("nodes", compactNodeInfo);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode2::encode(&dict)),
|
||||||
util::percentEncode(msgbody));
|
util::percentEncode(msgbody));
|
||||||
}
|
}
|
||||||
rDict.removeKey("nodes");
|
rDict->removeKey("nodes");
|
||||||
{
|
{
|
||||||
std::vector<SharedHandle<Peer> > peers;
|
std::vector<SharedHandle<Peer> > peers;
|
||||||
BDE valuesList = BDE::list();
|
SharedHandle<List> valuesList = List::g();
|
||||||
for(size_t i = 0; i < 4; ++i) {
|
for(size_t i = 0; i < 4; ++i) {
|
||||||
SharedHandle<Peer> peer(new Peer("192.168.0."+util::uitos(i+1), 6881+i));
|
SharedHandle<Peer> peer(new Peer("192.168.0."+util::uitos(i+1), 6881+i));
|
||||||
unsigned char buffer[6];
|
unsigned char buffer[6];
|
||||||
CPPUNIT_ASSERT(bittorrent::createcompact
|
CPPUNIT_ASSERT(bittorrent::createcompact
|
||||||
(buffer, peer->getIPAddress(), peer->getPort()));
|
(buffer, peer->getIPAddress(), peer->getPort()));
|
||||||
valuesList << BDE(buffer, sizeof(buffer));
|
valuesList->append(String::g(buffer, sizeof(buffer)));
|
||||||
peers.push_back(peer);
|
peers.push_back(peer);
|
||||||
}
|
}
|
||||||
rDict["values"] = valuesList;
|
rDict->put("values", valuesList);
|
||||||
|
|
||||||
msg.setValues(peers);
|
msg.setValues(peers);
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode::encode(dict)),
|
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode2::encode(&dict)),
|
||||||
util::percentEncode(msgbody));
|
util::percentEncode(msgbody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "DHTGetPeersReplyMessage.h"
|
#include "DHTGetPeersReplyMessage.h"
|
||||||
#include "DHTAnnouncePeerMessage.h"
|
#include "DHTAnnouncePeerMessage.h"
|
||||||
#include "DHTAnnouncePeerReplyMessage.h"
|
#include "DHTAnnouncePeerReplyMessage.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -79,17 +79,17 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTMessageFactoryImplTest);
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testCreatePingMessage()
|
void DHTMessageFactoryImplTest::testCreatePingMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("ping");
|
dict.put("q", "ping");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
aDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
SharedHandle<DHTPingMessage> m
|
SharedHandle<DHTPingMessage> m
|
||||||
(dynamic_pointer_cast<DHTPingMessage>
|
(dynamic_pointer_cast<DHTPingMessage>
|
||||||
(factory->createQueryMessage(dict, "192.168.0.1", 6881)));
|
(factory->createQueryMessage(&dict, "192.168.0.1", 6881)));
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
remoteNode->setPort(6881);
|
remoteNode->setPort(6881);
|
||||||
|
@ -102,12 +102,12 @@ void DHTMessageFactoryImplTest::testCreatePingMessage()
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
|
void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
|
@ -115,7 +115,7 @@ void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
|
||||||
|
|
||||||
SharedHandle<DHTPingReplyMessage> m
|
SharedHandle<DHTPingReplyMessage> m
|
||||||
(dynamic_pointer_cast<DHTPingReplyMessage>
|
(dynamic_pointer_cast<DHTPingReplyMessage>
|
||||||
(factory->createResponseMessage("ping", dict,
|
(factory->createResponseMessage("ping", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort())));
|
remoteNode->getPort())));
|
||||||
|
|
||||||
|
@ -127,20 +127,20 @@ void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
|
void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("find_node");
|
dict.put("q", "find_node");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
aDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
unsigned char targetNodeID[DHT_ID_LENGTH];
|
unsigned char targetNodeID[DHT_ID_LENGTH];
|
||||||
memset(targetNodeID, 0x11, DHT_ID_LENGTH);
|
memset(targetNodeID, 0x11, DHT_ID_LENGTH);
|
||||||
aDict["target"] = BDE(targetNodeID, DHT_ID_LENGTH);
|
aDict->put("target", String::g(targetNodeID, DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
SharedHandle<DHTFindNodeMessage> m
|
SharedHandle<DHTFindNodeMessage> m
|
||||||
(dynamic_pointer_cast<DHTFindNodeMessage>
|
(dynamic_pointer_cast<DHTFindNodeMessage>
|
||||||
(factory->createQueryMessage(dict, "192.168.0.1", 6881)));
|
(factory->createQueryMessage(&dict, "192.168.0.1", 6881)));
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
remoteNode->setPort(6881);
|
remoteNode->setPort(6881);
|
||||||
|
@ -156,11 +156,11 @@ void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
|
||||||
void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
|
void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
std::string compactNodeInfo;
|
std::string compactNodeInfo;
|
||||||
SharedHandle<DHTNode> nodes[8];
|
SharedHandle<DHTNode> nodes[8];
|
||||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||||
|
@ -175,8 +175,8 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
|
||||||
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
||||||
std::string(&buf[0], &buf[sizeof(buf)]);
|
std::string(&buf[0], &buf[sizeof(buf)]);
|
||||||
}
|
}
|
||||||
rDict["nodes"] = compactNodeInfo;
|
rDict->put("nodes", compactNodeInfo);
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
|
@ -184,7 +184,7 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
|
||||||
|
|
||||||
SharedHandle<DHTFindNodeReplyMessage> m
|
SharedHandle<DHTFindNodeReplyMessage> m
|
||||||
(dynamic_pointer_cast<DHTFindNodeReplyMessage>
|
(dynamic_pointer_cast<DHTFindNodeReplyMessage>
|
||||||
(factory->createResponseMessage("find_node", dict,
|
(factory->createResponseMessage("find_node", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort())));
|
remoteNode->getPort())));
|
||||||
|
|
||||||
|
@ -202,20 +202,20 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
|
void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("get_peers");
|
dict.put("q", "get_peers");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
aDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
unsigned char infoHash[DHT_ID_LENGTH];
|
unsigned char infoHash[DHT_ID_LENGTH];
|
||||||
memset(infoHash, 0x11, DHT_ID_LENGTH);
|
memset(infoHash, 0x11, DHT_ID_LENGTH);
|
||||||
aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
|
aDict->put("info_hash", String::g(infoHash, DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
SharedHandle<DHTGetPeersMessage> m
|
SharedHandle<DHTGetPeersMessage> m
|
||||||
(dynamic_pointer_cast<DHTGetPeersMessage>
|
(dynamic_pointer_cast<DHTGetPeersMessage>
|
||||||
(factory->createQueryMessage(dict, "192.168.0.1", 6881)));
|
(factory->createQueryMessage(&dict, "192.168.0.1", 6881)));
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
remoteNode->setPort(6881);
|
remoteNode->setPort(6881);
|
||||||
|
@ -231,11 +231,11 @@ void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
|
||||||
void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
|
void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
std::string compactNodeInfo;
|
std::string compactNodeInfo;
|
||||||
SharedHandle<DHTNode> nodes[8];
|
SharedHandle<DHTNode> nodes[8];
|
||||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||||
|
@ -250,9 +250,9 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
|
||||||
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
||||||
std::string(&buf[0], &buf[sizeof(buf)]);
|
std::string(&buf[0], &buf[sizeof(buf)]);
|
||||||
}
|
}
|
||||||
rDict["nodes"] = compactNodeInfo;
|
rDict->put("nodes", compactNodeInfo);
|
||||||
rDict["token"] = BDE("token");
|
rDict->put("token", "token");
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
|
@ -260,7 +260,7 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
|
||||||
|
|
||||||
SharedHandle<DHTGetPeersReplyMessage> m
|
SharedHandle<DHTGetPeersReplyMessage> m
|
||||||
(dynamic_pointer_cast<DHTGetPeersReplyMessage>
|
(dynamic_pointer_cast<DHTGetPeersReplyMessage>
|
||||||
(factory->createResponseMessage("get_peers", dict,
|
(factory->createResponseMessage("get_peers", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort())));
|
remoteNode->getPort())));
|
||||||
|
|
||||||
|
@ -280,25 +280,25 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
|
||||||
void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
|
void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
|
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
BDE valuesList = BDE::list();
|
SharedHandle<List> valuesList = List::g();
|
||||||
for(size_t i = 0; i < 4; ++i) {
|
for(size_t i = 0; i < 4; ++i) {
|
||||||
SharedHandle<Peer> peer(new Peer("192.168.0."+util::uitos(i+1), 6881+i));
|
SharedHandle<Peer> peer(new Peer("192.168.0."+util::uitos(i+1), 6881+i));
|
||||||
unsigned char buffer[6];
|
unsigned char buffer[6];
|
||||||
CPPUNIT_ASSERT(bittorrent::createcompact
|
CPPUNIT_ASSERT(bittorrent::createcompact
|
||||||
(buffer, peer->getIPAddress(), peer->getPort()));
|
(buffer, peer->getIPAddress(), peer->getPort()));
|
||||||
valuesList << BDE(buffer, sizeof(buffer));
|
valuesList->append(String::g(buffer, sizeof(buffer)));
|
||||||
peers.push_back(peer);
|
peers.push_back(peer);
|
||||||
}
|
}
|
||||||
rDict["values"] = valuesList;
|
rDict->put("values", valuesList);
|
||||||
rDict["token"] = BDE("token");
|
rDict->put("token", "token");
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
|
@ -306,7 +306,7 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
|
||||||
|
|
||||||
SharedHandle<DHTGetPeersReplyMessage> m
|
SharedHandle<DHTGetPeersReplyMessage> m
|
||||||
(dynamic_pointer_cast<DHTGetPeersReplyMessage>
|
(dynamic_pointer_cast<DHTGetPeersReplyMessage>
|
||||||
(factory->createResponseMessage("get_peers", dict,
|
(factory->createResponseMessage("get_peers", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort())));
|
remoteNode->getPort())));
|
||||||
|
|
||||||
|
@ -326,24 +326,24 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
|
||||||
void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
|
void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("announce_peer");
|
dict.put("q", "announce_peer");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
aDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
unsigned char infoHash[DHT_ID_LENGTH];
|
unsigned char infoHash[DHT_ID_LENGTH];
|
||||||
memset(infoHash, 0x11, DHT_ID_LENGTH);
|
memset(infoHash, 0x11, DHT_ID_LENGTH);
|
||||||
aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
|
aDict->put("info_hash", String::g(infoHash, DHT_ID_LENGTH));
|
||||||
std::string token = "ffff";
|
std::string token = "ffff";
|
||||||
uint16_t port = 6881;
|
uint16_t port = 6881;
|
||||||
aDict["port"] = port;
|
aDict->put("port", Integer::g(port));
|
||||||
aDict["token"] = token;
|
aDict->put("token", token);
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
SharedHandle<DHTAnnouncePeerMessage> m
|
SharedHandle<DHTAnnouncePeerMessage> m
|
||||||
(dynamic_pointer_cast<DHTAnnouncePeerMessage>
|
(dynamic_pointer_cast<DHTAnnouncePeerMessage>
|
||||||
(factory->createQueryMessage(dict, "192.168.0.1", 6882)));
|
(factory->createQueryMessage(&dict, "192.168.0.1", 6882)));
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
remoteNode->setPort(6882);
|
remoteNode->setPort(6882);
|
||||||
|
@ -363,12 +363,12 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
|
void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
|
rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
|
@ -376,7 +376,7 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
|
||||||
|
|
||||||
SharedHandle<DHTAnnouncePeerReplyMessage> m
|
SharedHandle<DHTAnnouncePeerReplyMessage> m
|
||||||
(dynamic_pointer_cast<DHTAnnouncePeerReplyMessage>
|
(dynamic_pointer_cast<DHTAnnouncePeerReplyMessage>
|
||||||
(factory->createResponseMessage("announce_peer", dict,
|
(factory->createResponseMessage("announce_peer", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort())));
|
remoteNode->getPort())));
|
||||||
|
|
||||||
|
@ -388,20 +388,20 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
|
||||||
|
|
||||||
void DHTMessageFactoryImplTest::testReceivedErrorMessage()
|
void DHTMessageFactoryImplTest::testReceivedErrorMessage()
|
||||||
{
|
{
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
|
dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
|
||||||
dict["y"] = BDE("e");
|
dict.put("y", "e");
|
||||||
BDE list = BDE::list();
|
SharedHandle<List> list = List::g();
|
||||||
list << 404;
|
list->append(Integer::g(404));
|
||||||
list << BDE("Not found");
|
list->append("Not found");
|
||||||
dict["e"] = list;
|
dict.put("e", list);
|
||||||
|
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
|
||||||
remoteNode->setIPAddress("192.168.0.1");
|
remoteNode->setIPAddress("192.168.0.1");
|
||||||
remoteNode->setPort(6881);
|
remoteNode->setPort(6881);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
factory->createResponseMessage("announce_peer", dict,
|
factory->createResponseMessage("announce_peer", &dict,
|
||||||
remoteNode->getIPAddress(),
|
remoteNode->getIPAddress(),
|
||||||
remoteNode->getPort());
|
remoteNode->getPort());
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
CPPUNIT_FAIL("exception must be thrown.");
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "DHTMessageTrackerEntry.h"
|
#include "DHTMessageTrackerEntry.h"
|
||||||
#include "DHTRoutingTable.h"
|
#include "DHTRoutingTable.h"
|
||||||
#include "MockDHTMessageFactory.h"
|
#include "MockDHTMessageFactory.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -62,11 +61,11 @@ void DHTMessageTrackerTest::testMessageArrived()
|
||||||
tracker.addMessage(m3, DHT_MESSAGE_TIMEOUT);
|
tracker.addMessage(m3, DHT_MESSAGE_TIMEOUT);
|
||||||
|
|
||||||
{
|
{
|
||||||
BDE resDict = BDE::dict();
|
Dict resDict;
|
||||||
resDict["t"] = m2->getTransactionID();
|
resDict.put("t", m2->getTransactionID());
|
||||||
|
|
||||||
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
||||||
tracker.messageArrived(resDict, m2->getRemoteNode()->getIPAddress(),
|
tracker.messageArrived(&resDict, m2->getRemoteNode()->getIPAddress(),
|
||||||
m2->getRemoteNode()->getPort());
|
m2->getRemoteNode()->getPort());
|
||||||
SharedHandle<DHTMessage> reply = p.first;
|
SharedHandle<DHTMessage> reply = p.first;
|
||||||
|
|
||||||
|
@ -75,11 +74,11 @@ void DHTMessageTrackerTest::testMessageArrived()
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, tracker.countEntry());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, tracker.countEntry());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BDE resDict = BDE::dict();
|
Dict resDict;
|
||||||
resDict["t"] = m3->getTransactionID();
|
resDict.put("t", m3->getTransactionID());
|
||||||
|
|
||||||
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
||||||
tracker.messageArrived(resDict, m3->getRemoteNode()->getIPAddress(),
|
tracker.messageArrived(&resDict, m3->getRemoteNode()->getIPAddress(),
|
||||||
m3->getRemoteNode()->getPort());
|
m3->getRemoteNode()->getPort());
|
||||||
SharedHandle<DHTMessage> reply = p.first;
|
SharedHandle<DHTMessage> reply = p.first;
|
||||||
|
|
||||||
|
@ -88,11 +87,11 @@ void DHTMessageTrackerTest::testMessageArrived()
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, tracker.countEntry());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tracker.countEntry());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BDE resDict = BDE::dict();
|
Dict resDict;
|
||||||
resDict["t"] = m1->getTransactionID();
|
resDict.put("t", m1->getTransactionID());
|
||||||
|
|
||||||
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
|
||||||
tracker.messageArrived(resDict, "192.168.1.100", 6889);
|
tracker.messageArrived(&resDict, "192.168.1.100", 6889);
|
||||||
SharedHandle<DHTMessage> reply = p.first;
|
SharedHandle<DHTMessage> reply = p.first;
|
||||||
|
|
||||||
CPPUNIT_ASSERT(reply.isNull());
|
CPPUNIT_ASSERT(reply.isNull());
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "MockDHTMessageFactory.h"
|
#include "MockDHTMessageFactory.h"
|
||||||
#include "MockDHTMessageDispatcher.h"
|
#include "MockDHTMessageDispatcher.h"
|
||||||
#include "MockDHTMessage.h"
|
#include "MockDHTMessage.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -57,16 +57,16 @@ void DHTPingMessageTest::testGetBencodedMessage()
|
||||||
|
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("q");
|
dict.put("y", "q");
|
||||||
dict["q"] = BDE("ping");
|
dict.put("q", "ping");
|
||||||
BDE aDict = BDE::dict();
|
SharedHandle<Dict> aDict = Dict::g();
|
||||||
aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
|
aDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
||||||
dict["a"] = aDict;
|
dict.put("a", aDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPingMessageTest::testDoReceivedAction()
|
void DHTPingMessageTest::testDoReceivedAction()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "bencode.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -41,15 +41,15 @@ void DHTPingReplyMessageTest::testGetBencodedMessage()
|
||||||
msg.setVersion("A200");
|
msg.setVersion("A200");
|
||||||
std::string msgbody = msg.getBencodedMessage();
|
std::string msgbody = msg.getBencodedMessage();
|
||||||
|
|
||||||
BDE dict = BDE::dict();
|
Dict dict;
|
||||||
dict["t"] = transactionID;
|
dict.put("t", transactionID);
|
||||||
dict["v"] = BDE("A200");
|
dict.put("v", "A200");
|
||||||
dict["y"] = BDE("r");
|
dict.put("y", "r");
|
||||||
BDE rDict = BDE::dict();
|
SharedHandle<Dict> rDict = Dict::g();
|
||||||
rDict["id"] = BDE(id, DHT_ID_LENGTH);
|
rDict->put("id", String::g(id, DHT_ID_LENGTH));
|
||||||
dict["r"] = rDict;
|
dict.put("r", rDict);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -70,11 +70,9 @@ aria2c_SOURCES = AllTest.cc\
|
||||||
LongestSequencePieceSelectorTest.cc\
|
LongestSequencePieceSelectorTest.cc\
|
||||||
a2algoTest.cc\
|
a2algoTest.cc\
|
||||||
bitfieldTest.cc\
|
bitfieldTest.cc\
|
||||||
BDETest.cc\
|
|
||||||
DownloadContextTest.cc\
|
DownloadContextTest.cc\
|
||||||
SessionSerializerTest.cc\
|
SessionSerializerTest.cc\
|
||||||
ValueBaseTest.cc\
|
ValueBaseTest.cc
|
||||||
Bencode2Test.cc
|
|
||||||
|
|
||||||
if ENABLE_XML_RPC
|
if ENABLE_XML_RPC
|
||||||
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
|
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
|
||||||
|
@ -190,13 +188,13 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\
|
||||||
MockExtensionMessage.h\
|
MockExtensionMessage.h\
|
||||||
MockExtensionMessageFactory.h\
|
MockExtensionMessageFactory.h\
|
||||||
MockPieceStorage.h\
|
MockPieceStorage.h\
|
||||||
BencodeTest.cc\
|
|
||||||
BittorrentHelperTest.cc\
|
BittorrentHelperTest.cc\
|
||||||
PriorityPieceSelectorTest.cc\
|
PriorityPieceSelectorTest.cc\
|
||||||
MockPieceSelector.h\
|
MockPieceSelector.h\
|
||||||
extension_message_test_helper.h\
|
extension_message_test_helper.h\
|
||||||
LpdMessageDispatcherTest.cc\
|
LpdMessageDispatcherTest.cc\
|
||||||
LpdMessageReceiverTest.cc
|
LpdMessageReceiverTest.cc\
|
||||||
|
Bencode2Test.cc
|
||||||
endif # ENABLE_BITTORRENT
|
endif # ENABLE_BITTORRENT
|
||||||
|
|
||||||
if ENABLE_METALINK
|
if ENABLE_METALINK
|
||||||
|
|
|
@ -137,13 +137,13 @@ check_PROGRAMS = $(am__EXEEXT_1)
|
||||||
@ENABLE_BITTORRENT_TRUE@ MockExtensionMessage.h\
|
@ENABLE_BITTORRENT_TRUE@ MockExtensionMessage.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ MockExtensionMessageFactory.h\
|
@ENABLE_BITTORRENT_TRUE@ MockExtensionMessageFactory.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ MockPieceStorage.h\
|
@ENABLE_BITTORRENT_TRUE@ MockPieceStorage.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ BencodeTest.cc\
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ BittorrentHelperTest.cc\
|
@ENABLE_BITTORRENT_TRUE@ BittorrentHelperTest.cc\
|
||||||
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelectorTest.cc\
|
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelectorTest.cc\
|
||||||
@ENABLE_BITTORRENT_TRUE@ MockPieceSelector.h\
|
@ENABLE_BITTORRENT_TRUE@ MockPieceSelector.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ extension_message_test_helper.h\
|
@ENABLE_BITTORRENT_TRUE@ extension_message_test_helper.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcherTest.cc\
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcherTest.cc\
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiverTest.cc
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiverTest.cc\
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ Bencode2Test.cc
|
||||||
|
|
||||||
@ENABLE_METALINK_TRUE@am__append_7 = MetalinkerTest.cc\
|
@ENABLE_METALINK_TRUE@am__append_7 = MetalinkerTest.cc\
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntryTest.cc\
|
@ENABLE_METALINK_TRUE@ MetalinkEntryTest.cc\
|
||||||
|
@ -212,9 +212,8 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
||||||
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
||||||
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
||||||
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
||||||
a2algoTest.cc bitfieldTest.cc BDETest.cc \
|
a2algoTest.cc bitfieldTest.cc DownloadContextTest.cc \
|
||||||
DownloadContextTest.cc SessionSerializerTest.cc \
|
SessionSerializerTest.cc ValueBaseTest.cc \
|
||||||
ValueBaseTest.cc Bencode2Test.cc \
|
|
||||||
XmlRpcRequestParserControllerTest.cc \
|
XmlRpcRequestParserControllerTest.cc \
|
||||||
XmlRpcRequestProcessorTest.cc XmlRpcMethodTest.cc \
|
XmlRpcRequestProcessorTest.cc XmlRpcMethodTest.cc \
|
||||||
FallocFileAllocationIteratorTest.cc GZipDecoderTest.cc \
|
FallocFileAllocationIteratorTest.cc GZipDecoderTest.cc \
|
||||||
|
@ -268,10 +267,10 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
||||||
MockDHTMessageDispatcher.h MockDHTMessageFactory.h \
|
MockDHTMessageDispatcher.h MockDHTMessageFactory.h \
|
||||||
MockDHTTask.h MockDHTTaskFactory.h MockDHTTaskQueue.h \
|
MockDHTTask.h MockDHTTaskFactory.h MockDHTTaskQueue.h \
|
||||||
MockExtensionMessage.h MockExtensionMessageFactory.h \
|
MockExtensionMessage.h MockExtensionMessageFactory.h \
|
||||||
MockPieceStorage.h BencodeTest.cc BittorrentHelperTest.cc \
|
MockPieceStorage.h BittorrentHelperTest.cc \
|
||||||
PriorityPieceSelectorTest.cc MockPieceSelector.h \
|
PriorityPieceSelectorTest.cc MockPieceSelector.h \
|
||||||
extension_message_test_helper.h LpdMessageDispatcherTest.cc \
|
extension_message_test_helper.h LpdMessageDispatcherTest.cc \
|
||||||
LpdMessageReceiverTest.cc MetalinkerTest.cc \
|
LpdMessageReceiverTest.cc Bencode2Test.cc MetalinkerTest.cc \
|
||||||
MetalinkEntryTest.cc Metalink2RequestGroupTest.cc \
|
MetalinkEntryTest.cc Metalink2RequestGroupTest.cc \
|
||||||
MetalinkPostDownloadHandlerTest.cc MetalinkHelperTest.cc \
|
MetalinkPostDownloadHandlerTest.cc MetalinkHelperTest.cc \
|
||||||
MetalinkParserControllerTest.cc MetalinkProcessorTest.cc
|
MetalinkParserControllerTest.cc MetalinkProcessorTest.cc
|
||||||
|
@ -359,11 +358,11 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
||||||
@ENABLE_BITTORRENT_TRUE@ DHKeyExchangeTest.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ DHKeyExchangeTest.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ ARC4Test.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ ARC4Test.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ MSEHandshakeTest.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ MSEHandshakeTest.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ BencodeTest.$(OBJEXT) \
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ BittorrentHelperTest.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ BittorrentHelperTest.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelectorTest.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ PriorityPieceSelectorTest.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcherTest.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageDispatcherTest.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiverTest.$(OBJEXT)
|
@ENABLE_BITTORRENT_TRUE@ LpdMessageReceiverTest.$(OBJEXT) \
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ Bencode2Test.$(OBJEXT)
|
||||||
@ENABLE_METALINK_TRUE@am__objects_7 = MetalinkerTest.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@am__objects_7 = MetalinkerTest.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntryTest.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ MetalinkEntryTest.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ Metalink2RequestGroupTest.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ Metalink2RequestGroupTest.$(OBJEXT) \
|
||||||
|
@ -407,12 +406,11 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
|
||||||
DownloadHelperTest.$(OBJEXT) SequentialPickerTest.$(OBJEXT) \
|
DownloadHelperTest.$(OBJEXT) SequentialPickerTest.$(OBJEXT) \
|
||||||
RarestPieceSelectorTest.$(OBJEXT) PieceStatManTest.$(OBJEXT) \
|
RarestPieceSelectorTest.$(OBJEXT) PieceStatManTest.$(OBJEXT) \
|
||||||
LongestSequencePieceSelectorTest.$(OBJEXT) \
|
LongestSequencePieceSelectorTest.$(OBJEXT) \
|
||||||
a2algoTest.$(OBJEXT) bitfieldTest.$(OBJEXT) BDETest.$(OBJEXT) \
|
a2algoTest.$(OBJEXT) bitfieldTest.$(OBJEXT) \
|
||||||
DownloadContextTest.$(OBJEXT) SessionSerializerTest.$(OBJEXT) \
|
DownloadContextTest.$(OBJEXT) SessionSerializerTest.$(OBJEXT) \
|
||||||
ValueBaseTest.$(OBJEXT) Bencode2Test.$(OBJEXT) \
|
ValueBaseTest.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
|
||||||
$(am__objects_1) $(am__objects_2) $(am__objects_3) \
|
$(am__objects_3) $(am__objects_4) $(am__objects_5) \
|
||||||
$(am__objects_4) $(am__objects_5) $(am__objects_6) \
|
$(am__objects_6) $(am__objects_7)
|
||||||
$(am__objects_7)
|
|
||||||
aria2c_OBJECTS = $(am_aria2c_OBJECTS)
|
aria2c_OBJECTS = $(am_aria2c_OBJECTS)
|
||||||
am__DEPENDENCIES_1 =
|
am__DEPENDENCIES_1 =
|
||||||
aria2c_DEPENDENCIES = ../src/libaria2c.a $(am__DEPENDENCIES_1)
|
aria2c_DEPENDENCIES = ../src/libaria2c.a $(am__DEPENDENCIES_1)
|
||||||
|
@ -644,9 +642,8 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
|
||||||
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
||||||
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
||||||
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
||||||
a2algoTest.cc bitfieldTest.cc BDETest.cc \
|
a2algoTest.cc bitfieldTest.cc DownloadContextTest.cc \
|
||||||
DownloadContextTest.cc SessionSerializerTest.cc \
|
SessionSerializerTest.cc ValueBaseTest.cc $(am__append_1) \
|
||||||
ValueBaseTest.cc Bencode2Test.cc $(am__append_1) \
|
|
||||||
$(am__append_2) $(am__append_3) $(am__append_4) \
|
$(am__append_2) $(am__append_3) $(am__append_4) \
|
||||||
$(am__append_5) $(am__append_6) $(am__append_7)
|
$(am__append_5) $(am__append_6) $(am__append_7)
|
||||||
|
|
||||||
|
@ -750,12 +747,10 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AlphaNumberDecoratorTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AlphaNumberDecoratorTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceListTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceListTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactoryTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactoryTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDETest.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNodeTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNodeTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base32Test.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base32Test.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64Test.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64Test.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Bencode2Test.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Bencode2Test.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BencodeTest.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BittorrentHelperTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BittorrentHelperTest.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessageTest.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessageTest.Po@am__quote@
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BDE.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ public:
|
||||||
|
|
||||||
virtual std::string toString() const { return "MockDHTMessage"; }
|
virtual std::string toString() const { return "MockDHTMessage"; }
|
||||||
|
|
||||||
virtual BDE getArgument() { return BDE::dict(); }
|
virtual SharedHandle<Dict> getArgument() { return Dict::g(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockDHTResponseMessage:public DHTResponseMessage {
|
class MockDHTResponseMessage:public DHTResponseMessage {
|
||||||
|
@ -109,7 +108,7 @@ public:
|
||||||
|
|
||||||
virtual std::string toString() const { return "MockDHTMessage"; }
|
virtual std::string toString() const { return "MockDHTMessage"; }
|
||||||
|
|
||||||
virtual BDE getResponse() { return BDE::dict(); }
|
virtual SharedHandle<Dict> getResponse() { return Dict::g(); }
|
||||||
|
|
||||||
virtual void accept(DHTMessageCallback* callback) {}
|
virtual void accept(DHTMessageCallback* callback) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "DHTMessageFactory.h"
|
#include "DHTMessageFactory.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "MockDHTMessage.h"
|
#include "MockDHTMessage.h"
|
||||||
#include "bencode.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ public:
|
||||||
virtual ~MockDHTMessageFactory() {}
|
virtual ~MockDHTMessageFactory() {}
|
||||||
|
|
||||||
virtual SharedHandle<DHTQueryMessage>
|
virtual SharedHandle<DHTQueryMessage>
|
||||||
createQueryMessage(const BDE& dict,
|
createQueryMessage(const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port)
|
const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
return SharedHandle<DHTQueryMessage>();
|
return SharedHandle<DHTQueryMessage>();
|
||||||
|
@ -25,7 +24,7 @@ public:
|
||||||
|
|
||||||
virtual SharedHandle<DHTResponseMessage>
|
virtual SharedHandle<DHTResponseMessage>
|
||||||
createResponseMessage(const std::string& messageType,
|
createResponseMessage(const std::string& messageType,
|
||||||
const BDE& dict,
|
const Dict* dict,
|
||||||
const std::string& ipaddr, uint16_t port)
|
const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
SharedHandle<DHTNode> remoteNode(new DHTNode());
|
SharedHandle<DHTNode> remoteNode(new DHTNode());
|
||||||
|
@ -33,7 +32,8 @@ public:
|
||||||
remoteNode->setIPAddress(ipaddr);
|
remoteNode->setIPAddress(ipaddr);
|
||||||
remoteNode->setPort(port);
|
remoteNode->setPort(port);
|
||||||
SharedHandle<MockDHTResponseMessage> m
|
SharedHandle<MockDHTResponseMessage> m
|
||||||
(new MockDHTResponseMessage(_localNode, remoteNode, dict["t"].s()));
|
(new MockDHTResponseMessage(_localNode, remoteNode,
|
||||||
|
asString(dict->get("t"))->s()));
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "bencode.h"
|
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
|
#include "bencode2.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@ void PeerListProcessorTest::testExtractPeerFromList() {
|
||||||
"d5:peersld2:ip11:192.168.0.17:peer id20:aria2-00000000000000"
|
"d5:peersld2:ip11:192.168.0.17:peer id20:aria2-00000000000000"
|
||||||
"4:porti2006eeee";
|
"4:porti2006eeee";
|
||||||
|
|
||||||
const BDE dict = bencode::decode(peersString);
|
SharedHandle<ValueBase> dict = bencode2::decode(peersString);
|
||||||
|
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
proc.extractPeer(asDict(dict)->get("peers"), std::back_inserter(peers));
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
|
||||||
SharedHandle<Peer> peer = *peers.begin();
|
SharedHandle<Peer> peer = *peers.begin();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->getIPAddress());
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->getIPAddress());
|
||||||
|
@ -53,10 +53,10 @@ void PeerListProcessorTest::testExtract2PeersFromList() {
|
||||||
"4:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-00000000000000"
|
"4:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-00000000000000"
|
||||||
"4:porti2007eeee";
|
"4:porti2007eeee";
|
||||||
|
|
||||||
const BDE dict = bencode::decode(peersString);
|
SharedHandle<ValueBase> dict = bencode2::decode(peersString);
|
||||||
|
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
|
proc.extractPeer(asDict(dict)->get("peers"), std::back_inserter(peers));
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size());
|
||||||
SharedHandle<Peer> peer = *peers.begin();
|
SharedHandle<Peer> peer = *peers.begin();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->getIPAddress());
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->getIPAddress());
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "DirectDiskAdaptor.h"
|
#include "DirectDiskAdaptor.h"
|
||||||
#include "ByteArrayDiskWriter.h"
|
#include "ByteArrayDiskWriter.h"
|
||||||
#include "BDE.h"
|
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "MockPieceStorage.h"
|
#include "MockPieceStorage.h"
|
||||||
#include "UTMetadataRequestTracker.h"
|
#include "UTMetadataRequestTracker.h"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,59 +35,59 @@ CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcRequestParserControllerTest);
|
||||||
void XmlRpcRequestParserControllerTest::testPopStructFrame()
|
void XmlRpcRequestParserControllerTest::testPopStructFrame()
|
||||||
{
|
{
|
||||||
XmlRpcRequestParserController controller;
|
XmlRpcRequestParserController controller;
|
||||||
controller.setCurrentFrameValue(BDE::dict());
|
controller.setCurrentFrameValue(Dict::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
controller.setCurrentFrameValue(BDE("Hello, aria2"));
|
controller.setCurrentFrameValue(String::g("Hello, aria2"));
|
||||||
controller.setCurrentFrameName("greeting");
|
controller.setCurrentFrameName("greeting");
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
const BDE& structValue = controller.getCurrentFrameValue();
|
const Dict* structValue = asDict(controller.getCurrentFrameValue());
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, structValue.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, structValue->size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Hello, aria2"),
|
CPPUNIT_ASSERT_EQUAL(std::string("Hello, aria2"),
|
||||||
structValue["greeting"].s());
|
asString(structValue->get("greeting"))->s());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestParserControllerTest::testPopStructFrame_noName()
|
void XmlRpcRequestParserControllerTest::testPopStructFrame_noName()
|
||||||
{
|
{
|
||||||
XmlRpcRequestParserController controller;
|
XmlRpcRequestParserController controller;
|
||||||
controller.setCurrentFrameValue(BDE::dict());
|
controller.setCurrentFrameValue(Dict::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
controller.setCurrentFrameValue(BDE("Hello, aria2"));
|
controller.setCurrentFrameValue(String::g("Hello, aria2"));
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
const BDE& structValue = controller.getCurrentFrameValue();
|
const Dict* structValue = asDict(controller.getCurrentFrameValue());
|
||||||
CPPUNIT_ASSERT(structValue.empty());
|
CPPUNIT_ASSERT(structValue->empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestParserControllerTest::testPopStructFrame_noValue()
|
void XmlRpcRequestParserControllerTest::testPopStructFrame_noValue()
|
||||||
{
|
{
|
||||||
XmlRpcRequestParserController controller;
|
XmlRpcRequestParserController controller;
|
||||||
controller.setCurrentFrameValue(BDE::dict());
|
controller.setCurrentFrameValue(Dict::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
controller.setCurrentFrameName("greeting");
|
controller.setCurrentFrameName("greeting");
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
const BDE& structValue = controller.getCurrentFrameValue();
|
const Dict* structValue = asDict(controller.getCurrentFrameValue());
|
||||||
CPPUNIT_ASSERT(structValue.empty());
|
CPPUNIT_ASSERT(structValue->empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestParserControllerTest::testPopArrayFrame()
|
void XmlRpcRequestParserControllerTest::testPopArrayFrame()
|
||||||
{
|
{
|
||||||
XmlRpcRequestParserController controller;
|
XmlRpcRequestParserController controller;
|
||||||
controller.setCurrentFrameValue(BDE::list());
|
controller.setCurrentFrameValue(List::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
controller.setCurrentFrameValue(BDE(100));
|
controller.setCurrentFrameValue(Integer::g(100));
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
const BDE& array = controller.getCurrentFrameValue();
|
const List* array = asList(controller.getCurrentFrameValue());
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, array.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, array->size());
|
||||||
CPPUNIT_ASSERT_EQUAL((BDE::Integer)100, array[0].i());
|
CPPUNIT_ASSERT_EQUAL((Integer::ValueType)100, asInteger(array->get(0))->i());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestParserControllerTest::testPopArrayFrame_noValue()
|
void XmlRpcRequestParserControllerTest::testPopArrayFrame_noValue()
|
||||||
{
|
{
|
||||||
XmlRpcRequestParserController controller;
|
XmlRpcRequestParserController controller;
|
||||||
controller.setCurrentFrameValue(BDE::list());
|
controller.setCurrentFrameValue(List::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
const BDE& array = controller.getCurrentFrameValue();
|
const List* array = asList(controller.getCurrentFrameValue());
|
||||||
CPPUNIT_ASSERT(array.empty());
|
CPPUNIT_ASSERT(array->empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
|
void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
|
||||||
|
@ -100,32 +100,32 @@ void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
|
||||||
// "options":{ "timeout":120 } },
|
// "options":{ "timeout":120 } },
|
||||||
// [ "jp","us" ] ]
|
// [ "jp","us" ] ]
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE::list());
|
controller.setCurrentFrameValue(List::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE::dict());
|
controller.setCurrentFrameValue(Dict::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameName("uris");
|
controller.setCurrentFrameName("uris");
|
||||||
controller.setCurrentFrameValue(BDE::list());
|
controller.setCurrentFrameValue(List::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE("http://example.org/aria2"));
|
controller.setCurrentFrameValue(String::g("http://example.org/aria2"));
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE("http://aria2.sf.net/"));
|
controller.setCurrentFrameValue(String::g("http://aria2.sf.net/"));
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
|
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameName("options");
|
controller.setCurrentFrameName("options");
|
||||||
controller.setCurrentFrameValue(BDE::dict());
|
controller.setCurrentFrameValue(Dict::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameName("timeout");
|
controller.setCurrentFrameName("timeout");
|
||||||
controller.setCurrentFrameValue(BDE(120));
|
controller.setCurrentFrameValue(Integer::g(120));
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
|
|
||||||
controller.popStructFrame();
|
controller.popStructFrame();
|
||||||
|
@ -133,23 +133,28 @@ void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE::list());
|
controller.setCurrentFrameValue(List::g());
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE("jp"));
|
controller.setCurrentFrameValue(String::g("jp"));
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
controller.pushFrame();
|
controller.pushFrame();
|
||||||
|
|
||||||
controller.setCurrentFrameValue(BDE("us"));
|
controller.setCurrentFrameValue(String::g("us"));
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
|
|
||||||
controller.popArrayFrame();
|
controller.popArrayFrame();
|
||||||
|
|
||||||
const BDE& result = controller.getCurrentFrameValue();
|
const List* result = asList(controller.getCurrentFrameValue());
|
||||||
|
const Dict* dict = asDict(result->get(0));
|
||||||
|
const List* uris = asList(dict->get("uris"));
|
||||||
|
const Dict* options = asDict(dict->get("options"));
|
||||||
|
const List* countryList = asList(result->get(1));
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sf.net/"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sf.net/"),
|
||||||
result[0]["uris"][1].s());
|
asString(uris->get(1))->s());
|
||||||
CPPUNIT_ASSERT_EQUAL((BDE::Integer)120, result[0]["options"]["timeout"].i());
|
CPPUNIT_ASSERT_EQUAL((Integer::ValueType)120,
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("jp"), result[1][0].s());
|
asInteger(options->get("timeout"))->i());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("jp"), asString(countryList->get(0))->s());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
#include "XmlRpcRequestParserStateMachine.h"
|
#include "XmlRpcRequestParserStateMachine.h"
|
||||||
|
#include "RecoverableException.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -65,13 +66,18 @@ void XmlRpcRequestProcessorTest::testParseMemory()
|
||||||
"</methodCall>");
|
"</methodCall>");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2.addURI"), req.methodName);
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2.addURI"), req.methodName);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)3, req.params.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)3, req.params->size());
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)100, req.params[0].i());
|
CPPUNIT_ASSERT_EQUAL((Integer::ValueType)100,
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)65535, req.params[1]["max-count"].i());
|
asInteger(req.params->get(0))->i());
|
||||||
|
const Dict* dict = asDict(req.params->get(1));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((Integer::ValueType)65535,
|
||||||
|
asInteger(dict->get("max-count"))->i());
|
||||||
// Current implementation handles double as string.
|
// Current implementation handles double as string.
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("0.99"), req.params[1]["seed-ratio"].s());
|
CPPUNIT_ASSERT_EQUAL(std::string("0.99"),
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("pudding"), req.params[2][0].s());
|
asString(dict->get("seed-ratio"))->s());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("hello world"), req.params[2][1].s());
|
const List* list = asList(req.params->get(2));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("pudding"), asString(list->get(0))->s());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("hello world"), asString(list->get(1))->s());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
|
void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
|
||||||
|
@ -88,6 +94,24 @@ void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
// success
|
// success
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
XmlRpcRequest req =
|
||||||
|
proc.parseMemory("<methodCall>"
|
||||||
|
" <methodName>aria2.addURI</methodName>"
|
||||||
|
" <params>"
|
||||||
|
" </params>"
|
||||||
|
"</methodCall>");
|
||||||
|
CPPUNIT_ASSERT(!req.params.isNull());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
XmlRpcRequest req =
|
||||||
|
proc.parseMemory("<methodCall>"
|
||||||
|
" <methodName>aria2.addURI</methodName>"
|
||||||
|
"</methodCall>");
|
||||||
|
CPPUNIT_FAIL("exception must be thrown.");
|
||||||
|
} catch(RecoverableException& e) {
|
||||||
|
// success
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
Loading…
Reference in New Issue