mirror of https://github.com/aria2/aria2
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed Dictionary/List/Data and its related classes. * src/BencodeVisitor.cc: Removed. * src/BencodeVisitor.h: Removed. * src/Data.cc: Removed. * src/Data.h: Removed. * src/Dictionary.cc: Removed. * src/Dictionary.h: Removed. * src/List.cc: Removed. * src/List.h: Removed. * src/Makefile.am * src/MetaEntry.h: Removed. * src/MetaEntryVisitor.h: Removed. * src/MetaFileUtil.cc: Removed. * src/MetaFileUtil.h: Removed. * test/BencodeVisitorTest.cc: Removed. * test/DataTest.cc: Removed. * test/DictionaryTest.cc: Removed. * test/ListTest.cc: Removed. * test/Makefile.am * test/MetaFileUtilTest.cc: Removed.pull/1/head
parent
5de92ff1fc
commit
110749df84
23
ChangeLog
23
ChangeLog
|
@ -1,3 +1,26 @@
|
|||
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Removed Dictionary/List/Data and its related classes.
|
||||
* src/BencodeVisitor.cc: Removed.
|
||||
* src/BencodeVisitor.h: Removed.
|
||||
* src/Data.cc: Removed.
|
||||
* src/Data.h: Removed.
|
||||
* src/Dictionary.cc: Removed.
|
||||
* src/Dictionary.h: Removed.
|
||||
* src/List.cc: Removed.
|
||||
* src/List.h: Removed.
|
||||
* src/Makefile.am
|
||||
* src/MetaEntry.h: Removed.
|
||||
* src/MetaEntryVisitor.h: Removed.
|
||||
* src/MetaFileUtil.cc: Removed.
|
||||
* src/MetaFileUtil.h: Removed.
|
||||
* test/BencodeVisitorTest.cc: Removed.
|
||||
* test/DataTest.cc: Removed.
|
||||
* test/DictionaryTest.cc: Removed.
|
||||
* test/ListTest.cc: Removed.
|
||||
* test/Makefile.am
|
||||
* test/MetaFileUtilTest.cc: Removed.
|
||||
|
||||
2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Removed include of MetaEntry.h
|
||||
|
|
|
@ -1,79 +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 "BencodeVisitor.h"
|
||||
#include "Data.h"
|
||||
#include "List.h"
|
||||
#include "Dictionary.h"
|
||||
#include "Util.h"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
BencodeVisitor::BencodeVisitor() {}
|
||||
|
||||
BencodeVisitor::~BencodeVisitor() {}
|
||||
|
||||
void BencodeVisitor::visit(const Data* d)
|
||||
{
|
||||
if(d->isNumber()) {
|
||||
_bencodedData += "i"+d->toString()+"e";
|
||||
} else {
|
||||
_bencodedData += Util::itos(d->getLen())+":"+d->toString();
|
||||
}
|
||||
}
|
||||
|
||||
void BencodeVisitor::visit(const List* l)
|
||||
{
|
||||
_bencodedData += "l";
|
||||
std::for_each(l->getList().begin(), l->getList().end(),
|
||||
std::bind2nd(std::mem_fun(&MetaEntry::accept), this));
|
||||
_bencodedData += "e";
|
||||
}
|
||||
|
||||
void BencodeVisitor::visit(const Dictionary* d)
|
||||
{
|
||||
_bencodedData += "d";
|
||||
|
||||
for(std::deque<std::string>::const_iterator itr = d->getOrder().begin(); itr != d->getOrder().end(); ++itr) {
|
||||
_bencodedData += Util::uitos((*itr).size());
|
||||
_bencodedData += ":";
|
||||
_bencodedData += *itr;
|
||||
d->get(*itr)->accept(this);
|
||||
}
|
||||
_bencodedData += "e";
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,69 +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_VISITOR_H_
|
||||
#define _D_BENCODE_VISITOR_H_
|
||||
|
||||
#include "MetaEntryVisitor.h"
|
||||
#include <string>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class Data;
|
||||
class Dictionary;
|
||||
class List;
|
||||
class MetaEntry;
|
||||
|
||||
class BencodeVisitor : public MetaEntryVisitor {
|
||||
private:
|
||||
std::string _bencodedData;
|
||||
public:
|
||||
BencodeVisitor();
|
||||
~BencodeVisitor();
|
||||
|
||||
virtual void visit(const Data* d);
|
||||
|
||||
virtual void visit(const Dictionary* d);
|
||||
|
||||
virtual void visit(const List* l);
|
||||
|
||||
const std::string& getBencodedData() const
|
||||
{
|
||||
return _bencodedData;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_BENCODE_VISITOR_H_
|
86
src/Data.cc
86
src/Data.cc
|
@ -1,86 +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 "Data.h"
|
||||
#include "MetaEntryVisitor.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib> // <-- TODO remove this if strtoll is replaced with Util::parseLLInt()
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
Data::Data(const unsigned char* data, size_t len, bool number):
|
||||
_data(reinterpret_cast<const char*>(data), len),
|
||||
number(number) {}
|
||||
|
||||
Data::Data(const char* data, size_t len, bool number):
|
||||
_data(data, len),
|
||||
number(number) {}
|
||||
|
||||
Data::Data(const std::string& data, bool number):_data(data), number(number) {}
|
||||
|
||||
Data::~Data() {}
|
||||
|
||||
const std::string& Data::toString() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
const unsigned char* Data::getData() const {
|
||||
if(_data.empty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return reinterpret_cast<const unsigned char*>(_data.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
size_t Data::getLen() const {
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
int32_t Data::toInt() const {
|
||||
return toLLInt();
|
||||
}
|
||||
|
||||
int64_t Data::toLLInt() const {
|
||||
return strtoll(_data.c_str(), 0, 10);
|
||||
}
|
||||
|
||||
bool Data::isNumber() const {
|
||||
return number;
|
||||
}
|
||||
|
||||
void Data::accept(MetaEntryVisitor* v) const {
|
||||
v->visit(this);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
75
src/Data.h
75
src/Data.h
|
@ -1,75 +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_DATA_H_
|
||||
#define _D_DATA_H_
|
||||
|
||||
#include "MetaEntry.h"
|
||||
#include <string>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class Data : public MetaEntry {
|
||||
private:
|
||||
std::string _data;
|
||||
bool number;
|
||||
|
||||
void init(const unsigned char* data, size_t len);
|
||||
public:
|
||||
/**
|
||||
* This class stores the copy of data. So caller must take care of freeing
|
||||
* memory of data.
|
||||
*/
|
||||
Data(const char* data, size_t len, bool number = false);
|
||||
|
||||
Data(const unsigned char* data, size_t len, bool number = false);
|
||||
|
||||
Data(const std::string& data, bool number = false);
|
||||
|
||||
virtual ~Data();
|
||||
|
||||
const std::string& toString() const;
|
||||
int32_t toInt() const;
|
||||
int64_t toLLInt() const;
|
||||
|
||||
const unsigned char* getData() const;
|
||||
size_t getLen() const;
|
||||
bool isNumber() const;
|
||||
|
||||
void accept(MetaEntryVisitor* v) const;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_DATA_H_
|
|
@ -1,87 +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 "Dictionary.h"
|
||||
#include "MetaEntryVisitor.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
Dictionary::Dictionary() {}
|
||||
|
||||
Dictionary::~Dictionary() {
|
||||
clearTable();
|
||||
}
|
||||
|
||||
void Dictionary::clearTable() {
|
||||
for(std::map<std::string, MetaEntry*>::iterator itr = table.begin();
|
||||
itr != table.end(); itr++) {
|
||||
delete itr->second;
|
||||
}
|
||||
table.clear();
|
||||
}
|
||||
|
||||
const MetaEntry* Dictionary::get(const std::string& name) const {
|
||||
std::map<std::string, MetaEntry*>::const_iterator itr = table.find(name);
|
||||
if(itr == table.end()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
void Dictionary::put(const std::string& name, MetaEntry* entry) {
|
||||
table[name] = entry;
|
||||
order.push_back(name);
|
||||
}
|
||||
|
||||
void Dictionary::remove(const std::string& name)
|
||||
{
|
||||
std::map<std::string, MetaEntry*>::iterator i = table.find(name);
|
||||
if(i != table.end()) {
|
||||
delete i->second;
|
||||
table.erase(i);
|
||||
order.erase(std::remove(order.begin(), order.end(), name), order.end());
|
||||
}
|
||||
}
|
||||
|
||||
void Dictionary::accept(MetaEntryVisitor* v) const {
|
||||
v->visit(this);
|
||||
}
|
||||
|
||||
const std::deque<std::string>& Dictionary::getOrder() const {
|
||||
return order;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,65 +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_DICTIONARY_H_
|
||||
#define _D_DICTIONARY_H_
|
||||
|
||||
#include "MetaEntry.h"
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class Dictionary : public MetaEntry {
|
||||
private:
|
||||
std::map<std::string, MetaEntry*> table;
|
||||
std::deque<std::string> order;
|
||||
void clearTable();
|
||||
public:
|
||||
Dictionary();
|
||||
~Dictionary();
|
||||
|
||||
const MetaEntry* get(const std::string& name) const;
|
||||
void put(const std::string& name, MetaEntry* entry);
|
||||
void remove(const std::string& name);
|
||||
|
||||
void accept(MetaEntryVisitor* v) const;
|
||||
const std::deque<std::string>& getOrder() const;
|
||||
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_DICTIONARY_H_
|
64
src/List.cc
64
src/List.cc
|
@ -1,64 +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 "List.h"
|
||||
#include "MetaEntryVisitor.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
List::List() {}
|
||||
|
||||
List::~List() {
|
||||
clearList();
|
||||
}
|
||||
|
||||
void List::clearList() {
|
||||
for(std::deque<MetaEntry*>::iterator itr = mlist.begin(); itr != mlist.end(); itr++) {
|
||||
delete *itr;
|
||||
}
|
||||
}
|
||||
|
||||
void List::add(MetaEntry* entry) {
|
||||
mlist.push_back(entry);
|
||||
}
|
||||
|
||||
const std::deque<MetaEntry*>& List::getList() const {
|
||||
return mlist;
|
||||
}
|
||||
|
||||
void List::accept(MetaEntryVisitor* v) const {
|
||||
v->visit(this);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
61
src/List.h
61
src/List.h
|
@ -1,61 +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_LIST_H_
|
||||
#define _D_LIST_H_
|
||||
|
||||
#include "MetaEntry.h"
|
||||
#include <deque>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class List : public MetaEntry {
|
||||
private:
|
||||
std::deque<MetaEntry*> mlist;
|
||||
|
||||
void clearList();
|
||||
public:
|
||||
List();
|
||||
~List();
|
||||
|
||||
void add(MetaEntry* entry);
|
||||
|
||||
const std::deque<MetaEntry*>& getList() const;
|
||||
|
||||
void accept(MetaEntryVisitor* v) const;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_LIST_H_
|
|
@ -233,12 +233,6 @@ endif # ENABLE_MESSAGE_DIGEST
|
|||
|
||||
if ENABLE_BITTORRENT
|
||||
SRCS += MetaEntry.h\
|
||||
Data.cc Data.h\
|
||||
Dictionary.cc Dictionary.h\
|
||||
List.cc List.h\
|
||||
MetaFileUtil.cc MetaFileUtil.h\
|
||||
MetaEntryVisitor.h\
|
||||
BencodeVisitor.cc BencodeVisitor.h\
|
||||
PeerMessageUtil.cc PeerMessageUtil.h\
|
||||
PeerAbstractCommand.cc PeerAbstractCommand.h\
|
||||
PeerInitiateConnectionCommand.cc PeerInitiateConnectionCommand.h\
|
||||
|
|
|
@ -51,12 +51,6 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@ENABLE_MESSAGE_DIGEST_TRUE@ ChunkChecksum.h
|
||||
|
||||
@ENABLE_BITTORRENT_TRUE@am__append_8 = MetaEntry.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ Data.cc Data.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ Dictionary.cc Dictionary.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ List.cc List.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ MetaFileUtil.cc MetaFileUtil.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ MetaEntryVisitor.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ BencodeVisitor.cc BencodeVisitor.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessageUtil.cc PeerMessageUtil.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerAbstractCommand.cc PeerAbstractCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerInitiateConnectionCommand.cc PeerInitiateConnectionCommand.h\
|
||||
|
@ -429,11 +423,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
ChecksumCheckIntegrityEntry.cc ChecksumCheckIntegrityEntry.h \
|
||||
messageDigest.cc messageDigest.h MessageDigestHelper.cc \
|
||||
MessageDigestHelper.h Checksum.h ChunkChecksum.h MetaEntry.h \
|
||||
Data.cc Data.h Dictionary.cc Dictionary.h List.cc List.h \
|
||||
MetaFileUtil.cc MetaFileUtil.h MetaEntryVisitor.h \
|
||||
BencodeVisitor.cc BencodeVisitor.h PeerMessageUtil.cc \
|
||||
PeerMessageUtil.h PeerAbstractCommand.cc PeerAbstractCommand.h \
|
||||
PeerInitiateConnectionCommand.cc \
|
||||
PeerMessageUtil.cc PeerMessageUtil.h PeerAbstractCommand.cc \
|
||||
PeerAbstractCommand.h PeerInitiateConnectionCommand.cc \
|
||||
PeerInitiateConnectionCommand.h PeerInteractionCommand.cc \
|
||||
PeerInteractionCommand.h Peer.h PeerListenCommand.cc \
|
||||
PeerListenCommand.h RequestSlot.cc RequestSlot.h \
|
||||
|
@ -590,11 +581,7 @@ am__objects_1 =
|
|||
@ENABLE_MESSAGE_DIGEST_TRUE@ ChecksumCheckIntegrityEntry.$(OBJEXT) \
|
||||
@ENABLE_MESSAGE_DIGEST_TRUE@ messageDigest.$(OBJEXT) \
|
||||
@ENABLE_MESSAGE_DIGEST_TRUE@ MessageDigestHelper.$(OBJEXT)
|
||||
@ENABLE_BITTORRENT_TRUE@am__objects_8 = Data.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ Dictionary.$(OBJEXT) List.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ MetaFileUtil.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BencodeVisitor.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessageUtil.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@am__objects_8 = PeerMessageUtil.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerAbstractCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerInitiateConnectionCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerInteractionCommand.$(OBJEXT) \
|
||||
|
@ -1258,7 +1245,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoSaveCommand.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)/BencodeVisitor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessage.Po@am__quote@
|
||||
|
@ -1353,7 +1339,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTTokenUpdateCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUnknownMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUtil.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Data.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultAuthResolver.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtAnnounce.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtContext.Po@am__quote@
|
||||
|
@ -1371,7 +1356,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPieceStorage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultSegmentManFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DelegatingPeerListProcessor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Dictionary.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DirectDiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DownloadCommand.Po@am__quote@
|
||||
|
@ -1428,12 +1412,10 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LanguageMetalinkParserState.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LibgnutlsTLSContext.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LibsslTLSContext.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/List.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MSEHandshake.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemoryBufferPreDownloadHandler.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MessageDigestHelper.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetaFileUtil.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Metalink2RequestGroup.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetalinkEntry.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetalinkHelper.Po@am__quote@
|
||||
|
|
|
@ -1,59 +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_META_ENTRY_H_
|
||||
#define _D_META_ENTRY_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "SharedHandle.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class MetaEntryVisitor;
|
||||
|
||||
class MetaEntry {
|
||||
protected:
|
||||
MetaEntry() {}
|
||||
public:
|
||||
virtual ~MetaEntry() {}
|
||||
|
||||
virtual void accept(MetaEntryVisitor* v) const = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef SharedHandle<MetaEntry> MetaEntryHandle;
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_META_ENTRY_H_
|
|
@ -1,59 +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_META_ENTRY_VISITOR_H_
|
||||
#define _D_META_ENTRY_VISITOR_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class Data;
|
||||
class Dictionary;
|
||||
class List;
|
||||
|
||||
class MetaEntryVisitor {
|
||||
public:
|
||||
virtual ~MetaEntryVisitor() {}
|
||||
|
||||
virtual void visit(const Data* d) = 0;
|
||||
|
||||
virtual void visit(const Dictionary* d) = 0;
|
||||
|
||||
virtual void visit(const List* l) = 0;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_META_ENTRY_VISITOR_H_
|
|
@ -1,214 +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 "MetaFileUtil.h"
|
||||
#include "Data.h"
|
||||
#include "Dictionary.h"
|
||||
#include "List.h"
|
||||
#include "File.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib> // <-- TODO remove this if strtoul is replaced with Util::parseUInt()
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
MetaEntry* MetaFileUtil::parseMetaFile(const std::string& file) {
|
||||
File f(file);
|
||||
size_t len = f.size();
|
||||
unsigned char* buf = new unsigned char[len];
|
||||
FILE* fp = fopen(file.c_str(), "r+b");
|
||||
try {
|
||||
if(!fp) {
|
||||
throw DlAbortEx("cannot open metainfo file");
|
||||
}
|
||||
if(fread(buf, len, 1, fp) != 1) {
|
||||
fclose(fp);
|
||||
throw DlAbortEx("cannot read metainfo");
|
||||
}
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
MetaEntry* entry = bdecoding(buf, len);
|
||||
delete [] buf;
|
||||
return entry;
|
||||
} catch(RecoverableException& ex) {
|
||||
delete [] buf;
|
||||
if(fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
MetaEntry* MetaFileUtil::bdecoding(const unsigned char* buf, size_t len)
|
||||
{
|
||||
const unsigned char* p = buf;
|
||||
const unsigned char* end = buf+len;
|
||||
return bdecodingR(&p, end);
|
||||
}
|
||||
|
||||
MetaEntry*
|
||||
MetaFileUtil::bdecodingR(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
if(*pp >= end) {
|
||||
throw DlAbortEx("Malformed metainfo");
|
||||
}
|
||||
MetaEntry* e;
|
||||
switch(**pp) {
|
||||
case 'd':
|
||||
(*pp)++;
|
||||
e = parseDictionaryTree(pp, end);
|
||||
break;
|
||||
case 'l':
|
||||
(*pp)++;
|
||||
e = parseListTree(pp, end);
|
||||
break;
|
||||
case 'i':
|
||||
(*pp)++;
|
||||
e = decodeInt(pp, end);
|
||||
break;
|
||||
default:
|
||||
e = decodeWord(pp, end);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
Dictionary*
|
||||
MetaFileUtil::parseDictionaryTree(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
if(*pp >= end) {
|
||||
throw DlAbortEx("Malformed metainfo");
|
||||
}
|
||||
Dictionary* dic = new Dictionary();
|
||||
try {
|
||||
while(1) {
|
||||
if(**pp == 'e') {
|
||||
(*pp)++;
|
||||
break;
|
||||
}
|
||||
std::string name = decodeWordAsString(pp, end);
|
||||
MetaEntry* e = bdecodingR(pp, end);
|
||||
dic->put(name, e);
|
||||
}
|
||||
return dic;
|
||||
} catch(RecoverableException& ex) {
|
||||
delete dic;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
List*
|
||||
MetaFileUtil::parseListTree(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
if(*pp >= end) {
|
||||
throw DlAbortEx("Malformed metainfo");
|
||||
}
|
||||
List* lis = new List();
|
||||
try {
|
||||
while(1) {
|
||||
if(**pp == 'e') {
|
||||
(*pp)++;
|
||||
break;
|
||||
}
|
||||
MetaEntry* e = bdecodingR(pp, end);
|
||||
lis->add(e);
|
||||
}
|
||||
return lis;
|
||||
} catch(RecoverableException& ex) {
|
||||
delete lis;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Data*
|
||||
MetaFileUtil::decodeInt(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
if(*pp >= end) {
|
||||
throw DlAbortEx(EX_MALFORMED_META_INFO);
|
||||
}
|
||||
unsigned char* endTerm = reinterpret_cast<unsigned char*>(memchr(*pp, 'e', end-*pp));
|
||||
// TODO if endTerm is null
|
||||
if(!endTerm) {
|
||||
throw DlAbortEx(EX_MALFORMED_META_INFO);
|
||||
}
|
||||
size_t numSize = endTerm-*pp;
|
||||
|
||||
Data* data = new Data(*pp, numSize, true);
|
||||
*pp += numSize+1;
|
||||
return data;
|
||||
}
|
||||
|
||||
Data*
|
||||
MetaFileUtil::decodeWord(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
if(*pp >= end) {
|
||||
throw DlAbortEx("Malformed metainfo");
|
||||
}
|
||||
unsigned char* delim = reinterpret_cast<unsigned char*>(memchr(*pp, ':', end-*pp));
|
||||
// TODO if delim is null
|
||||
if(delim == *pp || !delim) {
|
||||
throw DlAbortEx(EX_MALFORMED_META_INFO);
|
||||
}
|
||||
size_t numSize = delim-*pp;
|
||||
unsigned char* temp = new unsigned char[numSize+1];
|
||||
memcpy(temp, *pp, numSize);
|
||||
temp[numSize] = '\0';
|
||||
char* endptr;
|
||||
unsigned long int size = strtoul(reinterpret_cast<const char*>(temp),
|
||||
&endptr, 10);
|
||||
if(*endptr != '\0') {
|
||||
delete [] temp;
|
||||
throw DlAbortEx(EX_MALFORMED_META_INFO);
|
||||
}
|
||||
delete [] temp;
|
||||
|
||||
if(delim+1+size > end) {
|
||||
throw DlAbortEx(EX_MALFORMED_META_INFO);
|
||||
}
|
||||
|
||||
Data* data = new Data(delim+1, size);
|
||||
*pp = delim+1+size;
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string
|
||||
MetaFileUtil::decodeWordAsString(const unsigned char** pp, const unsigned char* end)
|
||||
{
|
||||
Data* data = decodeWord(pp, end);
|
||||
std::string str = data->toString();
|
||||
delete data;
|
||||
return str;
|
||||
}
|
||||
|
||||
} // 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_META_FILE_UTIL_H_
|
||||
#define _D_META_FILE_UTIL_H_
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class MetaEntry;
|
||||
class Dictionary;
|
||||
class List;
|
||||
class Data;
|
||||
|
||||
class MetaFileUtil {
|
||||
private:
|
||||
MetaFileUtil() {}
|
||||
|
||||
static MetaEntry* bdecodingR(const unsigned char** pp, const unsigned char* end);
|
||||
static Dictionary* parseDictionaryTree(const unsigned char** pp, const unsigned char* end);
|
||||
static List* parseListTree(const unsigned char** pp, const unsigned char* end);
|
||||
static Data* decodeWord(const unsigned char** pp, const unsigned char* end);
|
||||
static Data* decodeInt(const unsigned char** pp, const unsigned char* end);
|
||||
static std::string decodeWordAsString(const unsigned char** pp, const unsigned char* end);
|
||||
|
||||
public:
|
||||
static MetaEntry* parseMetaFile(const std::string& file);
|
||||
static MetaEntry* bdecoding(const unsigned char* buf, size_t len);
|
||||
|
||||
static MetaEntry* bdecoding(const std::string& content)
|
||||
{
|
||||
return bdecoding(reinterpret_cast<const unsigned char*>(content.c_str()),
|
||||
content.size());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_META_FILE_UTIL_H_
|
|
@ -1,74 +0,0 @@
|
|||
#include "BencodeVisitor.h"
|
||||
#include "Data.h"
|
||||
#include "List.h"
|
||||
#include "Dictionary.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BencodeVisitorTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(BencodeVisitorTest);
|
||||
CPPUNIT_TEST(testVisit_data);
|
||||
CPPUNIT_TEST(testVisit_list);
|
||||
CPPUNIT_TEST(testVisit_dictionary);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testVisit_data();
|
||||
void testVisit_list();
|
||||
void testVisit_dictionary();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( BencodeVisitorTest );
|
||||
|
||||
void BencodeVisitorTest::testVisit_data()
|
||||
{
|
||||
{
|
||||
BencodeVisitor v;
|
||||
std::string str = "apple";
|
||||
MetaEntryHandle m(new Data(str.c_str(), str.size()));
|
||||
m->accept(&v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("5:apple"), v.getBencodedData());
|
||||
}
|
||||
{
|
||||
BencodeVisitor v;
|
||||
std::string str = "123";
|
||||
MetaEntryHandle m(new Data(str.c_str(), str.size(), true));
|
||||
m->accept(&v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("i123e"), v.getBencodedData());
|
||||
}
|
||||
}
|
||||
|
||||
void BencodeVisitorTest::testVisit_list()
|
||||
{
|
||||
BencodeVisitor v;
|
||||
List l;
|
||||
std::string s1 = "alpha";
|
||||
l.add(new Data(s1.c_str(), s1.size()));
|
||||
std::string s2 = "bravo";
|
||||
l.add(new Data(s2.c_str(), s2.size()));
|
||||
std::string s3 = "123";
|
||||
l.add(new Data(s3.c_str(), s3.size(), true));
|
||||
l.accept(&v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("l5:alpha5:bravoi123ee"), v.getBencodedData());
|
||||
}
|
||||
|
||||
void BencodeVisitorTest::testVisit_dictionary()
|
||||
{
|
||||
BencodeVisitor v;
|
||||
Dictionary d;
|
||||
std::string s1 = "alpha";
|
||||
d.put("team", new Data(s1.c_str(), s1.size()));
|
||||
std::string s2 = "123";
|
||||
d.put("score", new Data(s2.c_str(), s2.size(), true));
|
||||
d.accept(&v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("d4:team5:alpha5:scorei123ee"), v.getBencodedData());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,81 +0,0 @@
|
|||
#include "Data.h"
|
||||
#include "A2STR.h"
|
||||
#include <cstring>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class DataTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(DataTest);
|
||||
CPPUNIT_TEST(testToString);
|
||||
CPPUNIT_TEST(testGetData);
|
||||
CPPUNIT_TEST(testToInt);
|
||||
CPPUNIT_TEST(testToLLInt);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testToString();
|
||||
void testGetData();
|
||||
void testToInt();
|
||||
void testToLLInt();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( DataTest );
|
||||
|
||||
void DataTest::testToString() {
|
||||
Data data("aria2", 5);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), data.toString());
|
||||
|
||||
Data null(reinterpret_cast<const char*>(0), 0);
|
||||
CPPUNIT_ASSERT_EQUAL(A2STR::NIL, null.toString());
|
||||
|
||||
Data zeroLengthString(A2STR::NIL);
|
||||
CPPUNIT_ASSERT_EQUAL(A2STR::NIL, zeroLengthString.toString());
|
||||
}
|
||||
|
||||
void DataTest::testGetData() {
|
||||
Data data("aria2", 5);
|
||||
CPPUNIT_ASSERT_EQUAL(0, memcmp("aria2", data.getData(), 5));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)5, data.getLen());
|
||||
|
||||
Data null(reinterpret_cast<const char*>(0), 0);
|
||||
CPPUNIT_ASSERT(null.getData() == 0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, null.getLen());
|
||||
|
||||
Data zeroLengthString(A2STR::NIL);
|
||||
CPPUNIT_ASSERT(zeroLengthString.getData() == 0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, zeroLengthString.getLen());
|
||||
}
|
||||
|
||||
void DataTest::testToInt() {
|
||||
Data data("1000", 4);
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)1000, data.toInt());
|
||||
|
||||
Data null(reinterpret_cast<const char*>(0), 0);
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)0, null.toInt());
|
||||
|
||||
Data alpha("abc", 3);
|
||||
CPPUNIT_ASSERT_EQUAL((int32_t)0, alpha.toInt());
|
||||
|
||||
Data zeroLengthString("");
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int)zeroLengthString.toLLInt());
|
||||
}
|
||||
|
||||
void DataTest::testToLLInt() {
|
||||
Data data("1000", 4);
|
||||
CPPUNIT_ASSERT_EQUAL(1000, (int)data.toLLInt());
|
||||
|
||||
Data null(reinterpret_cast<const char*>(0), 0);
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int)null.toLLInt());
|
||||
|
||||
Data alpha("abc", 3);
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int)alpha.toLLInt());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,36 +0,0 @@
|
|||
#include "Dictionary.h"
|
||||
#include "Data.h"
|
||||
#include <string>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class DictionaryTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(DictionaryTest);
|
||||
CPPUNIT_TEST(testGet);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testGet();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( DictionaryTest );
|
||||
|
||||
void DictionaryTest::testGet() {
|
||||
Dictionary d;
|
||||
Data* data1 = new Data("aria2", 5);
|
||||
d.put("app_name", data1);
|
||||
Data* data2 = new Data("linux", 5);
|
||||
d.put("platform", data2);
|
||||
Data* dataGot = (Data*)d.get("app_name");
|
||||
CPPUNIT_ASSERT(dataGot != NULL);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2"), dataGot->toString());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,34 +0,0 @@
|
|||
#include "List.h"
|
||||
#include "Data.h"
|
||||
#include <string>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ListTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(ListTest);
|
||||
CPPUNIT_TEST(testAdd);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testAdd();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( ListTest );
|
||||
|
||||
void ListTest::testAdd() {
|
||||
List l;
|
||||
Data* data1 = new Data("usr", 3);
|
||||
l.add(data1);
|
||||
Data* data2 = new Data("local", 5);
|
||||
l.add(data2);
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int)l.getList().size());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -110,10 +110,6 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\
|
|||
AnnounceListTest.cc\
|
||||
DefaultPeerStorageTest.cc\
|
||||
MockPeerStorage.h\
|
||||
DataTest.cc\
|
||||
DictionaryTest.cc\
|
||||
ListTest.cc\
|
||||
MetaFileUtilTest.cc\
|
||||
ByteArrayDiskWriterTest.cc\
|
||||
PeerTest.cc\
|
||||
PeerSessionResourceTest.cc\
|
||||
|
@ -123,7 +119,6 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\
|
|||
BtDependencyTest.cc\
|
||||
BtPostDownloadHandlerTest.cc\
|
||||
TimeSeedCriteriaTest.cc\
|
||||
BencodeVisitorTest.cc\
|
||||
BtExtendedMessageTest.cc\
|
||||
HandshakeExtensionMessageTest.cc\
|
||||
UTPexExtensionMessageTest.cc\
|
||||
|
|
|
@ -69,10 +69,6 @@ check_PROGRAMS = $(am__EXEEXT_1)
|
|||
@ENABLE_BITTORRENT_TRUE@ AnnounceListTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorageTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ MockPeerStorage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DataTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ DictionaryTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ ListTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ MetaFileUtilTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ ByteArrayDiskWriterTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerSessionResourceTest.cc\
|
||||
|
@ -82,7 +78,6 @@ check_PROGRAMS = $(am__EXEEXT_1)
|
|||
@ENABLE_BITTORRENT_TRUE@ BtDependencyTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ BtPostDownloadHandlerTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ TimeSeedCriteriaTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ BencodeVisitorTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ BtExtendedMessageTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ HandshakeExtensionMessageTest.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ UTPexExtensionMessageTest.cc\
|
||||
|
@ -214,15 +209,14 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
|||
DefaultBtRequestFactoryTest.cc MockBtMessage.h \
|
||||
MockBtMessageDispatcher.h MockBtMessageFactory.h \
|
||||
DefaultPeerListProcessorTest.cc AnnounceListTest.cc \
|
||||
DefaultPeerStorageTest.cc MockPeerStorage.h DataTest.cc \
|
||||
DictionaryTest.cc ListTest.cc MetaFileUtilTest.cc \
|
||||
DefaultPeerStorageTest.cc MockPeerStorage.h \
|
||||
ByteArrayDiskWriterTest.cc PeerTest.cc \
|
||||
PeerSessionResourceTest.cc PeerMessageUtilTest.cc \
|
||||
ShareRatioSeedCriteriaTest.cc BtRegistryTest.cc \
|
||||
BtDependencyTest.cc BtPostDownloadHandlerTest.cc \
|
||||
TimeSeedCriteriaTest.cc BencodeVisitorTest.cc \
|
||||
BtExtendedMessageTest.cc HandshakeExtensionMessageTest.cc \
|
||||
UTPexExtensionMessageTest.cc DefaultBtMessageFactoryTest.cc \
|
||||
TimeSeedCriteriaTest.cc BtExtendedMessageTest.cc \
|
||||
HandshakeExtensionMessageTest.cc UTPexExtensionMessageTest.cc \
|
||||
DefaultBtMessageFactoryTest.cc \
|
||||
DefaultExtensionMessageFactoryTest.cc DHTNodeTest.cc \
|
||||
DHTBucketTest.cc DHTRoutingTableTest.cc \
|
||||
DHTMessageTrackerEntryTest.cc DHTMessageTrackerTest.cc \
|
||||
|
@ -280,10 +274,6 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
|||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerListProcessorTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ AnnounceListTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorageTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DataTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DictionaryTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ ListTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ MetaFileUtilTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ ByteArrayDiskWriterTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerSessionResourceTest.$(OBJEXT) \
|
||||
|
@ -293,7 +283,6 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
|||
@ENABLE_BITTORRENT_TRUE@ BtDependencyTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BtPostDownloadHandlerTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ TimeSeedCriteriaTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BencodeVisitorTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BtExtendedMessageTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HandshakeExtensionMessageTest.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ UTPexExtensionMessageTest.$(OBJEXT) \
|
||||
|
@ -694,7 +683,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNodeTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64Test.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BencodeTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BencodeVisitorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtBitfieldMessageTest.Po@am__quote@
|
||||
|
@ -747,7 +735,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTTokenTrackerTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUnknownMessageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUtilTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DataTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultAuthResolverTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtAnnounceTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtContextTest.Po@am__quote@
|
||||
|
@ -760,7 +747,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerListProcessorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerStorageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPieceStorageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DictionaryTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DirectDiskAdaptorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DownloadHandlerFactoryTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DownloadHelperTest.Po@am__quote@
|
||||
|
@ -779,10 +765,8 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InOrderURISelectorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IteratableChecksumValidatorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IteratableChunkChecksumValidatorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ListTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MSEHandshakeTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MessageDigestHelperTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetaFileUtilTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Metalink2RequestGroupTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetalinkEntryTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetalinkHelperTest.Po@am__quote@
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
#include "MetaFileUtil.h"
|
||||
#include "Data.h"
|
||||
#include "Dictionary.h"
|
||||
#include "List.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include <string>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class MetaFileUtilTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(MetaFileUtilTest);
|
||||
CPPUNIT_TEST(testParseMetaFile);
|
||||
CPPUNIT_TEST(testBdecoding);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testParseMetaFile();
|
||||
void testBdecoding();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest );
|
||||
|
||||
void MetaFileUtilTest::testParseMetaFile() {
|
||||
SharedHandle<MetaEntry> entry(MetaFileUtil::parseMetaFile("test.torrent"));
|
||||
SharedHandle<Dictionary> d = dynamic_pointer_cast<Dictionary>(entry);
|
||||
CPPUNIT_ASSERT(!d.isNull());
|
||||
}
|
||||
|
||||
void MetaFileUtilTest::testBdecoding() {
|
||||
try {
|
||||
std::string str = "5:abcd";
|
||||
MetaFileUtil::bdecoding(str);
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
} catch(DlAbortEx& ex) {
|
||||
} catch(...) {
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
}
|
||||
|
||||
try {
|
||||
std::string str = "i1234";
|
||||
MetaFileUtil::bdecoding(str);
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
} catch(DlAbortEx& ex) {
|
||||
} catch(...) {
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string str = "5abcd";
|
||||
MetaFileUtil::bdecoding(str);
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
} catch(DlAbortEx& ex) {
|
||||
} catch(...) {
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string str = "d";
|
||||
MetaFileUtil::bdecoding(str);
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
} catch(DlAbortEx& ex) {
|
||||
} catch(...) {
|
||||
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aria2
|
Loading…
Reference in New Issue