changed methods calling the storage server according to the new specs
This commit is contained in:
parent
4785ebaafb
commit
5e8378a164
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.4 $
|
Version : $Revision: 1.5 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -103,6 +103,11 @@ static const std::string loginParamName = "login";
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static const std::string passwordParamName = "pass";
|
static const std::string passwordParamName = "pass";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the session ID parameter in the output structure
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string outputSessionIdParamName = "sessid";
|
||||||
|
|
||||||
|
|
||||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: logout */
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: logout */
|
||||||
|
|
||||||
|
@ -114,7 +119,12 @@ static const std::string logoutMethodName = "locstor.logout";
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* The name of the session ID parameter in the input structure
|
* The name of the session ID parameter in the input structure
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static const std::string sessionIdParamName = "sessid";
|
static const std::string inputSessionIdParamName = "sessid";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the status parameter in the output structure
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string statusParamName = "status";
|
||||||
|
|
||||||
|
|
||||||
/* =============================================== local function prototypes */
|
/* =============================================== local function prototypes */
|
||||||
|
@ -209,11 +219,15 @@ WebAuthenticationClient :: login(const std::string & login,
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.getType() != XmlRpcValue::TypeString) {
|
if (! result.hasMember(outputSessionIdParamName)) {
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionId.reset(new SessionId(result));
|
if (result[outputSessionIdParamName].getType() != XmlRpcValue::TypeString) {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionId.reset(new SessionId(result[outputSessionIdParamName]));
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +245,7 @@ WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
||||||
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
||||||
storageServerPath.c_str(), false);
|
storageServerPath.c_str(), false);
|
||||||
|
|
||||||
parameters[sessionIdParamName] = sessionId->getId().c_str();
|
parameters[inputSessionIdParamName] = sessionId->getId().c_str();
|
||||||
|
|
||||||
if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) {
|
if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -240,6 +254,18 @@ WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
||||||
if (xmlRpcClient.isFault()) {
|
if (xmlRpcClient.isFault()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! result.hasMember(statusParamName)) {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result[statusParamName].getType() != XmlRpcValue::TypeBoolean) {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(bool(result[statusParamName]))) {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.6 $
|
Version : $Revision: 1.7 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -159,6 +159,20 @@ static const std::string errorCodeParamName = "faultCode";
|
||||||
static const std::string errorMessageParamName = "faultString";
|
static const std::string errorMessageParamName = "faultString";
|
||||||
|
|
||||||
|
|
||||||
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: resetStorage */
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the reset storage method on the storage server
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string resetStorageMethodName
|
||||||
|
= "locstor.resetStorage";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the result parameter returned by the method
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string resetStorageMethodResultParamName = "gunids";
|
||||||
|
|
||||||
|
|
||||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
|
@ -177,6 +191,11 @@ static const std::string existsAudioClipMethodSessionIdParamName = "sessid";
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static const std::string existsAudioClipMethodAudioClipIdParamName = "gunid";
|
static const std::string existsAudioClipMethodAudioClipIdParamName = "gunid";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the result parameter returned by the method
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string existsAudioClipMethodResultParamName = "exists";
|
||||||
|
|
||||||
|
|
||||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: getAudioClip */
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: getAudioClip */
|
||||||
|
|
||||||
|
@ -196,9 +215,16 @@ static const std::string getAudioClipMethodSessionIdParamName = "sessid";
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static const std::string getAudioClipMethodAudioClipIdParamName = "gunid";
|
static const std::string getAudioClipMethodAudioClipIdParamName = "gunid";
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* The name of the result parameter returned by the method
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
static const std::string getAudioClipMethodResultParamName = "metadata";
|
||||||
|
|
||||||
|
|
||||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: storeAudioClip */
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: storeAudioClip */
|
||||||
|
|
||||||
|
// TODO: fix; this method does not exist any more
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* The name of the store audio clip method on the storage server
|
* The name of the store audio clip method on the storage server
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -444,8 +470,10 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
|
||||||
throw std::logic_error(eMsg);
|
throw std::logic_error(eMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmlRpcClient.isFault()
|
if (xmlRpcClient.isFault()
|
||||||
|| result.getType() != XmlRpcValue::TypeBoolean) {
|
|| ! result.hasMember(existsAudioClipMethodResultParamName)
|
||||||
|
|| result[existsAudioClipMethodResultParamName].getType()
|
||||||
|
!= XmlRpcValue::TypeBoolean) {
|
||||||
std::stringstream eMsg;
|
std::stringstream eMsg;
|
||||||
eMsg << "XML-RPC method '"
|
eMsg << "XML-RPC method '"
|
||||||
<< existsAudioClipMethodName
|
<< existsAudioClipMethodName
|
||||||
|
@ -454,7 +482,7 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
|
||||||
throw std::logic_error(eMsg.str());
|
throw std::logic_error(eMsg.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return bool(result);
|
return bool(result[existsAudioClipMethodResultParamName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -486,7 +514,9 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmlRpcClient.isFault()
|
if (xmlRpcClient.isFault()
|
||||||
|| result.getType() != XmlRpcValue::TypeString) {
|
|| ! result.hasMember(getAudioClipMethodResultParamName)
|
||||||
|
|| result[getAudioClipMethodResultParamName].getType()
|
||||||
|
!= XmlRpcValue::TypeString) {
|
||||||
std::stringstream eMsg;
|
std::stringstream eMsg;
|
||||||
eMsg << "XML-RPC method '"
|
eMsg << "XML-RPC method '"
|
||||||
<< getAudioClipMethodName
|
<< getAudioClipMethodName
|
||||||
|
@ -495,8 +525,8 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
|
||||||
throw std::logic_error(eMsg.str());
|
throw std::logic_error(eMsg.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string xmlAudioClip(result);
|
std::string xmlAudioClip(result[getAudioClipMethodResultParamName]);
|
||||||
Ptr<AudioClip>::Ref audioClip;
|
Ptr<AudioClip>::Ref audioClip;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser());
|
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser());
|
||||||
|
@ -644,58 +674,57 @@ WebStorageClient :: getAllAudioClips(Ptr<SessionId>::Ref sessionId)
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Convert a hex digit to an int. This is used by decodeString().
|
* Reset the storage to its initial state.
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
int
|
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref
|
||||||
WebStorageClient :: hexDigitToChar(const char &hexDigit) const
|
WebStorageClient :: reset(void)
|
||||||
throw ()
|
throw (std::logic_error)
|
||||||
{
|
{
|
||||||
if (hexDigit >= '0' && hexDigit <= '9') {
|
XmlRpcValue parameters;
|
||||||
return hexDigit - '0';
|
XmlRpcValue result;
|
||||||
}
|
|
||||||
else if (hexDigit >= 'a' && hexDigit <= 'f') {
|
|
||||||
return hexDigit - 'a' + 10;
|
|
||||||
}
|
|
||||||
else if (hexDigit >= 'A' && hexDigit <= 'F') {
|
|
||||||
return hexDigit - 'A' + 10;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
||||||
* Decode an escaped string.
|
storageServerPath.c_str(), false);
|
||||||
*----------------------------------------------------------------------------*/
|
|
||||||
Ptr<std::string>::Ref
|
parameters["dummy_param"] = "dummy_value";
|
||||||
WebStorageClient :: decodeString(const std::string &inputString) const
|
|
||||||
throw ()
|
|
||||||
{
|
|
||||||
Ptr<std::string>::Ref outputString(new std::string);
|
|
||||||
char nextChar;
|
|
||||||
|
|
||||||
std::string::const_iterator it = inputString.begin();
|
if (!xmlRpcClient.execute(resetStorageMethodName.c_str(),
|
||||||
while (it != inputString.end()) {
|
parameters, result)) {
|
||||||
nextChar = *(it++);
|
std::string eMsg = "cannot execute XML-RPC method '";
|
||||||
if (nextChar == '%') {
|
eMsg += resetStorageMethodName;
|
||||||
if (it == inputString.end()) {
|
eMsg += "'";
|
||||||
nextChar = '?';
|
throw std::logic_error(eMsg);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
nextChar = hexDigitToChar(*(it++));
|
if (xmlRpcClient.isFault()
|
||||||
if (it == inputString.end()) {
|
|| ! result.hasMember(resetStorageMethodResultParamName)
|
||||||
nextChar = '?';
|
|| result[resetStorageMethodResultParamName].getType()
|
||||||
}
|
!= XmlRpcValue::TypeArray) {
|
||||||
else {
|
std::stringstream eMsg;
|
||||||
nextChar *= 16;
|
eMsg << "XML-RPC method '"
|
||||||
nextChar += hexDigitToChar(*(it++));
|
<< resetStorageMethodName
|
||||||
}
|
<< "' returned error message:\n"
|
||||||
}
|
<< result;
|
||||||
}
|
throw std::logic_error(eMsg.str());
|
||||||
outputString->push_back(nextChar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputString;
|
XmlRpcValue uniqueIdArray = result[resetStorageMethodResultParamName];
|
||||||
|
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref returnValue(
|
||||||
|
new std::vector<Ptr<UniqueId>::Ref>);
|
||||||
|
|
||||||
|
for (int i=0; i < uniqueIdArray.size(); i++) {
|
||||||
|
if (uniqueIdArray[i].getType() != XmlRpcValue::TypeString) {
|
||||||
|
std::stringstream eMsg;
|
||||||
|
eMsg << "Non-string gunid returned by XML-RPC method '"
|
||||||
|
<< resetStorageMethodName
|
||||||
|
<< "':\n"
|
||||||
|
<< result;
|
||||||
|
throw std::logic_error(eMsg.str());
|
||||||
|
}
|
||||||
|
Ptr<UniqueId>::Ref uniqueId(new UniqueId(10001 + i)); // TODO: fix!!!
|
||||||
|
returnValue->push_back(uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.8 $
|
Version : $Revision: 1.9 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -99,7 +99,7 @@ using namespace LiveSupport::Core;
|
||||||
* </code></pre>
|
* </code></pre>
|
||||||
*
|
*
|
||||||
* @author $Author: fgerlits $
|
* @author $Author: fgerlits $
|
||||||
* @version $Revision: 1.8 $
|
* @version $Revision: 1.9 $
|
||||||
*/
|
*/
|
||||||
class WebStorageClient :
|
class WebStorageClient :
|
||||||
virtual public Configurable,
|
virtual public Configurable,
|
||||||
|
@ -131,25 +131,6 @@ class WebStorageClient :
|
||||||
*/
|
*/
|
||||||
std::string storageServerPath;
|
std::string storageServerPath;
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode an escaped %73%74%72%69%6E%67 to a normal string.
|
|
||||||
* This is really bad and low-level; to be replaced later.
|
|
||||||
*
|
|
||||||
* @return a pointer to a newly allocated string which contains
|
|
||||||
* the decoded value.
|
|
||||||
*/
|
|
||||||
Ptr<std::string>::Ref
|
|
||||||
decodeString(const std::string &inputString) const
|
|
||||||
throw ();
|
|
||||||
/**
|
|
||||||
* Convert a hex digit 0..9 | a..f | A..F to an int.
|
|
||||||
* This is used in decodeString().
|
|
||||||
*
|
|
||||||
* @return an int with the converted value.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
hexDigitToChar(const char &hexDigit) const
|
|
||||||
throw ();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -425,6 +406,16 @@ class WebStorageClient :
|
||||||
getAllAudioClips(Ptr<SessionId>::Ref sessionId) const
|
getAllAudioClips(Ptr<SessionId>::Ref sessionId) const
|
||||||
throw (std::logic_error);
|
throw (std::logic_error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the storage to its initial state. Used for testing.
|
||||||
|
*
|
||||||
|
* @return a vector containing the UniqueId's of the audio clips
|
||||||
|
* in the storage after the reset.
|
||||||
|
* @exception std::logic_error if the server returns an error.
|
||||||
|
*/
|
||||||
|
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref
|
||||||
|
reset(void)
|
||||||
|
throw (std::logic_error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.6 $
|
Version : $Revision: 1.7 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -159,10 +159,19 @@ void
|
||||||
WebStorageClientTest :: audioClipTest(void)
|
WebStorageClientTest :: audioClipTest(void)
|
||||||
throw (CPPUNIT_NS::Exception)
|
throw (CPPUNIT_NS::Exception)
|
||||||
{
|
{
|
||||||
Ptr<UniqueId>::Ref id01(new UniqueId(10001));
|
Ptr<UniqueId>::Ref id01;
|
||||||
Ptr<UniqueId>::Ref id77(new UniqueId(10077));
|
Ptr<UniqueId>::Ref id77(new UniqueId(10077));
|
||||||
Ptr<SessionId>::Ref sessionId;
|
Ptr<SessionId>::Ref sessionId;
|
||||||
|
|
||||||
|
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref uniqueIdVector = wsc->reset();
|
||||||
|
/*
|
||||||
|
NOTE: this is incorrect, as WebStorageClient fakes the UniqueId's
|
||||||
|
TODO: fix!!!
|
||||||
|
std::cout << "\nReset storage result:\n";
|
||||||
|
for (unsigned i=0; i<uniqueIdVector->size(); i++) {
|
||||||
|
std::cout << uniqueIdVector->at(i)->getId() << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
CPPUNIT_ASSERT( sessionId = authentication->login("root", "q"));
|
CPPUNIT_ASSERT( sessionId = authentication->login("root", "q"));
|
||||||
|
|
||||||
CPPUNIT_ASSERT(!wsc->existsAudioClip(sessionId, id77));
|
CPPUNIT_ASSERT(!wsc->existsAudioClip(sessionId, id77));
|
||||||
|
|
Loading…
Reference in New Issue