2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added aria2.getSessionInfo XML-RPC method.  This method returns a
	struct containing Session ID, which is generated each time when
	aria2 is invoked.
	* doc/aria2c.1.txt
	* doc/xmlrpc/aria2rpc
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* test/XmlRpcMethodTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-01-17 11:55:22 +00:00
parent 87b18019b4
commit f2722cb870
11 changed files with 95 additions and 2 deletions

View File

@ -1,3 +1,17 @@
2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added aria2.getSessionInfo XML-RPC method. This method returns a
struct containing Session ID, which is generated each time when
aria2 is invoked.
* doc/aria2c.1.txt
* doc/xmlrpc/aria2rpc
* src/DownloadEngine.cc
* src/DownloadEngine.h
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
* test/XmlRpcMethodTest.cc
2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved generateRandomKey() from bittorrent_helper to util. Moved generateRandomKey() from bittorrent_helper to util.

View File

@ -2438,6 +2438,15 @@ enabledFeatures
List of enabled features\&. Each feature name is of type string\&. List of enabled features\&. Each feature name is of type string\&.
.RE .RE
.sp .sp
\fBaria2\&.getSessionInfo\fR
.sp
This method returns session information\&. The response is of type struct and contains following key\&.
.PP
sessionId
.RS 4
Session ID, which is generated each time when aria2 is invoked\&.
.RE
.sp
\fBsystem\&.multicall\fR \fImethods\fR \fBsystem\&.multicall\fR \fImethods\fR
.sp .sp
This methods encapsulates multiple method calls in a single request\&. \fImethods\fR is of type array and its element is struct\&. The struct contains two keys: "methodName" and "params"\&. "methodName" is the method name to call and "params" is array containing parameters to the method\&. This method returns array of responses\&. The element of array will either be a one\-item array containing the return value of each method call or struct of fault element if an encapsulated method call fails\&. This methods encapsulates multiple method calls in a single request\&. \fImethods\fR is of type array and its element is struct\&. The struct contains two keys: "methodName" and "params"\&. "methodName" is the method name to call and "params" is array containing parameters to the method\&. This method returns array of responses\&. The element of array will either be a one\-item array containing the return value of each method call or struct of fault element if an encapsulated method call fails\&.

View File

@ -3120,6 +3120,19 @@ enabledFeatures
</p> </p>
</dd> </dd>
</dl></div> </dl></div>
<div class="paragraph"><p><strong>aria2.getSessionInfo</strong></p></div>
<div class="paragraph"><p>This method returns session information.
The response is of type struct and contains following key.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
sessionId
</dt>
<dd>
<p>
Session ID, which is generated each time when aria2 is invoked.
</p>
</dd>
</dl></div>
<div class="paragraph"><p><strong>system.multicall</strong> <em>methods</em></p></div> <div class="paragraph"><p><strong>system.multicall</strong> <em>methods</em></p></div>
<div class="paragraph"><p>This methods encapsulates multiple method calls in a single request. <div class="paragraph"><p>This methods encapsulates multiple method calls in a single request.
<em>methods</em> is of type array and its element is struct. The struct <em>methods</em> is of type array and its element is struct. The struct
@ -3597,7 +3610,7 @@ files in the program, then also delete it here.</p></div>
<div id="footnotes"><hr /></div> <div id="footnotes"><hr /></div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2010-01-17 18:53:28 JST Last updated 2010-01-17 20:50:31 JST
</div> </div>
</div> </div>
</body> </body>

View File

@ -1457,6 +1457,15 @@ enabledFeatures::
List of enabled features. Each feature name is of type string. List of enabled features. Each feature name is of type string.
*aria2.getSessionInfo*
This method returns session information.
The response is of type struct and contains following key.
sessionId::
Session ID, which is generated each time when aria2 is invoked.
*system.multicall* 'methods' *system.multicall* 'methods'
This methods encapsulates multiple method calls in a single request. This methods encapsulates multiple method calls in a single request.

View File

@ -191,6 +191,7 @@ Usage: #{program_name} addUri URI... [options]
#{program_name} changeOption GID [options] #{program_name} changeOption GID [options]
#{program_name} changeGlobalOption [options] #{program_name} changeGlobalOption [options]
#{program_name} getVersion [options] #{program_name} getVersion [options]
#{program_name} getSessionInfo [options]
Options: Options:
EOS EOS
@ -270,6 +271,8 @@ elsif command == "changeGlobalOption" then
result=client.call("aria2."+command, options) result=client.call("aria2."+command, options)
elsif command == "getVersion" then elsif command == "getVersion" then
result=client.call("aria2."+command) result=client.call("aria2."+command)
elsif command == "getSessionInfo" then
result=client.call("aria2."+command)
else else
puts "Command not recognized" puts "Command not recognized"
exit 1 exit 1

View File

@ -94,7 +94,11 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll):
_btRegistry(new BtRegistry()), _btRegistry(new BtRegistry()),
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
_dnsCache(new DNSCache()) _dnsCache(new DNSCache())
{} {
unsigned char sessionId[20];
util::generateRandomKey(sessionId);
_sessionId = std::string(&sessionId[0], & sessionId[sizeof(sessionId)]);
}
DownloadEngine::~DownloadEngine() { DownloadEngine::~DownloadEngine() {
cleanQueue(); cleanQueue();

View File

@ -73,6 +73,8 @@ class DownloadEngine {
private: private:
void waitData(); void waitData();
std::string _sessionId;
SharedHandle<EventPoll> _eventPoll; SharedHandle<EventPoll> _eventPoll;
Logger* logger; Logger* logger;
@ -274,6 +276,11 @@ public:
} }
void setRefreshInterval(time_t interval); void setRefreshInterval(time_t interval);
const std::string getSessionId() const
{
return _sessionId;
}
}; };
typedef SharedHandle<DownloadEngine> DownloadEngineHandle; typedef SharedHandle<DownloadEngine> DownloadEngineHandle;

View File

@ -89,6 +89,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod()); return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
} else if(methodName == GetVersionXmlRpcMethod::getMethodName()) { } else if(methodName == GetVersionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod()); return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod());
} else if(methodName == GetSessionInfoXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetSessionInfoXmlRpcMethod());
} else if(methodName == SystemMulticallXmlRpcMethod::getMethodName()) { } else if(methodName == SystemMulticallXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new SystemMulticallXmlRpcMethod()); return SharedHandle<XmlRpcMethod>(new SystemMulticallXmlRpcMethod());
} else { } else {

View File

@ -115,6 +115,7 @@ const std::string KEY_VERSION = "version";
const std::string KEY_ENABLED_FEATURES = "enabledFeatures"; const std::string KEY_ENABLED_FEATURES = "enabledFeatures";
const std::string KEY_METHOD_NAME = "methodName"; const std::string KEY_METHOD_NAME = "methodName";
const std::string KEY_PARAMS = "params"; const std::string KEY_PARAMS = "params";
const std::string KEY_SESSION_ID = "sessionId";
} }
static BDE createGIDResponse(int32_t gid) static BDE createGIDResponse(int32_t gid)
@ -789,6 +790,14 @@ BDE ChangePositionXmlRpcMethod::process
return result; return result;
} }
BDE GetSessionInfoXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{
BDE result = BDE::dict();
result[KEY_SESSION_ID] = util::toHex(e->getSessionId());
return result;
}
BDE SystemMulticallXmlRpcMethod::process BDE SystemMulticallXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e) (const XmlRpcRequest& req, DownloadEngine* e)
{ {

View File

@ -332,6 +332,17 @@ public:
} }
}; };
class GetSessionInfoXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
static std::string methodName = "aria2.getSessionInfo";
return methodName;
}
};
class SystemMulticallXmlRpcMethod:public XmlRpcMethod { class SystemMulticallXmlRpcMethod:public XmlRpcMethod {
protected: protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e); virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);

View File

@ -69,6 +69,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testGatherProgressCommon); CPPUNIT_TEST(testGatherProgressCommon);
CPPUNIT_TEST(testChangePosition); CPPUNIT_TEST(testChangePosition);
CPPUNIT_TEST(testChangePosition_fail); CPPUNIT_TEST(testChangePosition_fail);
CPPUNIT_TEST(testGetSessionInfo);
CPPUNIT_TEST(testSystemMulticall); CPPUNIT_TEST(testSystemMulticall);
CPPUNIT_TEST(testSystemMulticall_fail); CPPUNIT_TEST(testSystemMulticall_fail);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -125,6 +126,7 @@ public:
void testGatherProgressCommon(); void testGatherProgressCommon();
void testChangePosition(); void testChangePosition();
void testChangePosition_fail(); void testChangePosition_fail();
void testGetSessionInfo();
void testSystemMulticall(); void testSystemMulticall();
void testSystemMulticall_fail(); void testSystemMulticall_fail();
}; };
@ -749,6 +751,16 @@ void XmlRpcMethodTest::testChangePosition_fail()
CPPUNIT_ASSERT_EQUAL(1, res._code); CPPUNIT_ASSERT_EQUAL(1, res._code);
} }
void XmlRpcMethodTest::testGetSessionInfo()
{
GetSessionInfoXmlRpcMethod m;
XmlRpcRequest req(GetSessionInfoXmlRpcMethod::getMethodName(), BDE::list());
XmlRpcResponse res = m.execute(req, _e.get());
CPPUNIT_ASSERT_EQUAL(0, res._code);
CPPUNIT_ASSERT_EQUAL(util::toHex(_e->getSessionId()),
res._param["sessionId"].s());
}
void XmlRpcMethodTest::testSystemMulticall() void XmlRpcMethodTest::testSystemMulticall()
{ {
SystemMulticallXmlRpcMethod m; SystemMulticallXmlRpcMethod m;