summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-17 11:55:22 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-01-17 11:55:22 +0000
commitf2722cb870352dedd8bb962f4dfc45e89ce5f71b (patch)
tree11e17dfcfd95800ecbfe0d8d02d9b8c9f0e2e503
parent87b18019b461e5f3a48bc22cdeb49e20a40ce236 (diff)
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
-rw-r--r--ChangeLog14
-rw-r--r--doc/aria2c.19
-rw-r--r--doc/aria2c.1.html15
-rw-r--r--doc/aria2c.1.txt9
-rwxr-xr-xdoc/xmlrpc/aria2rpc3
-rw-r--r--src/DownloadEngine.cc6
-rw-r--r--src/DownloadEngine.h7
-rw-r--r--src/XmlRpcMethodFactory.cc2
-rw-r--r--src/XmlRpcMethodImpl.cc9
-rw-r--r--src/XmlRpcMethodImpl.h11
-rw-r--r--test/XmlRpcMethodTest.cc12
11 files changed, 95 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 636a86f9..6c1597ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
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>
+
Moved generateRandomKey() from bittorrent_helper to util.
* src/DHTBucket.cc
* src/DHTNode.cc
diff --git a/doc/aria2c.1 b/doc/aria2c.1
index 259a22e5..8cffc7e0 100644
--- a/doc/aria2c.1
+++ b/doc/aria2c.1
@@ -2438,6 +2438,15 @@ enabledFeatures
List of enabled features\&. Each feature name is of type string\&.
.RE
.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
.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\&.
diff --git a/doc/aria2c.1.html b/doc/aria2c.1.html
index 282d7291..a35bffa0 100644
--- a/doc/aria2c.1.html
+++ b/doc/aria2c.1.html
@@ -3120,6 +3120,19 @@ enabledFeatures
</p>
</dd>
</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>This methods encapsulates multiple method calls in a single request.
<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="footer">
<div id="footer-text">
-Last updated 2010-01-17 18:53:28 JST
+Last updated 2010-01-17 20:50:31 JST
</div>
</div>
</body>
diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt
index 3978f6a2..68705552 100644
--- a/doc/aria2c.1.txt
+++ b/doc/aria2c.1.txt
@@ -1457,6 +1457,15 @@ enabledFeatures::
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'
This methods encapsulates multiple method calls in a single request.
diff --git a/doc/xmlrpc/aria2rpc b/doc/xmlrpc/aria2rpc
index 7f5fc7dd..18830b8f 100755
--- a/doc/xmlrpc/aria2rpc
+++ b/doc/xmlrpc/aria2rpc
@@ -191,6 +191,7 @@ Usage: #{program_name} addUri URI... [options]
#{program_name} changeOption GID [options]
#{program_name} changeGlobalOption [options]
#{program_name} getVersion [options]
+ #{program_name} getSessionInfo [options]
Options:
EOS
@@ -270,6 +271,8 @@ elsif command == "changeGlobalOption" then
result=client.call("aria2."+command, options)
elsif command == "getVersion" then
result=client.call("aria2."+command)
+elsif command == "getSessionInfo" then
+ result=client.call("aria2."+command)
else
puts "Command not recognized"
exit 1
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 011ff4c0..9bf881cc 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -94,7 +94,11 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll):
_btRegistry(new BtRegistry()),
#endif // ENABLE_BITTORRENT
_dnsCache(new DNSCache())
-{}
+{
+ unsigned char sessionId[20];
+ util::generateRandomKey(sessionId);
+ _sessionId = std::string(&sessionId[0], & sessionId[sizeof(sessionId)]);
+}
DownloadEngine::~DownloadEngine() {
cleanQueue();
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index 8c9fc591..fc282bf3 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -73,6 +73,8 @@ class DownloadEngine {
private:
void waitData();
+ std::string _sessionId;
+
SharedHandle<EventPoll> _eventPoll;
Logger* logger;
@@ -274,6 +276,11 @@ public:
}
void setRefreshInterval(time_t interval);
+
+ const std::string getSessionId() const
+ {
+ return _sessionId;
+ }
};
typedef SharedHandle<DownloadEngine> DownloadEngineHandle;
diff --git a/src/XmlRpcMethodFactory.cc b/src/XmlRpcMethodFactory.cc
index e0d2efa3..b0683420 100644
--- a/src/XmlRpcMethodFactory.cc
+++ b/src/XmlRpcMethodFactory.cc
@@ -89,6 +89,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
} else if(methodName == GetVersionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod());
+ } else if(methodName == GetSessionInfoXmlRpcMethod::getMethodName()) {
+ return SharedHandle<XmlRpcMethod>(new GetSessionInfoXmlRpcMethod());
} else if(methodName == SystemMulticallXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new SystemMulticallXmlRpcMethod());
} else {
diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc
index 92f03328..12aeb826 100644
--- a/src/XmlRpcMethodImpl.cc
+++ b/src/XmlRpcMethodImpl.cc
@@ -115,6 +115,7 @@ const std::string KEY_VERSION = "version";
const std::string KEY_ENABLED_FEATURES = "enabledFeatures";
const std::string KEY_METHOD_NAME = "methodName";
const std::string KEY_PARAMS = "params";
+const std::string KEY_SESSION_ID = "sessionId";
}
static BDE createGIDResponse(int32_t gid)
@@ -789,6 +790,14 @@ BDE ChangePositionXmlRpcMethod::process
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
(const XmlRpcRequest& req, DownloadEngine* e)
{
diff --git a/src/XmlRpcMethodImpl.h b/src/XmlRpcMethodImpl.h
index 5eb576f1..f057d3c7 100644
--- a/src/XmlRpcMethodImpl.h
+++ b/src/XmlRpcMethodImpl.h
@@ -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 {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc
index d610a811..f493347f 100644
--- a/test/XmlRpcMethodTest.cc
+++ b/test/XmlRpcMethodTest.cc
@@ -69,6 +69,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testGatherProgressCommon);
CPPUNIT_TEST(testChangePosition);
CPPUNIT_TEST(testChangePosition_fail);
+ CPPUNIT_TEST(testGetSessionInfo);
CPPUNIT_TEST(testSystemMulticall);
CPPUNIT_TEST(testSystemMulticall_fail);
CPPUNIT_TEST_SUITE_END();
@@ -125,6 +126,7 @@ public:
void testGatherProgressCommon();
void testChangePosition();
void testChangePosition_fail();
+ void testGetSessionInfo();
void testSystemMulticall();
void testSystemMulticall_fail();
};
@@ -749,6 +751,16 @@ void XmlRpcMethodTest::testChangePosition_fail()
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()
{
SystemMulticallXmlRpcMethod m;