diff --git a/livesupport/modules/authentication/src/WebAuthenticationClient.cxx b/livesupport/modules/authentication/src/WebAuthenticationClient.cxx index 0ab6d7877..812e39c61 100644 --- a/livesupport/modules/authentication/src/WebAuthenticationClient.cxx +++ b/livesupport/modules/authentication/src/WebAuthenticationClient.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -103,6 +103,11 @@ static const std::string loginParamName = "login"; *----------------------------------------------------------------------------*/ 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 */ @@ -114,7 +119,12 @@ static const std::string logoutMethodName = "locstor.logout"; /*------------------------------------------------------------------------------ * 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 */ @@ -209,11 +219,15 @@ WebAuthenticationClient :: login(const std::string & login, return sessionId; } - if (result.getType() != XmlRpcValue::TypeString) { + if (! result.hasMember(outputSessionIdParamName)) { return sessionId; } - - sessionId.reset(new SessionId(result)); + + if (result[outputSessionIdParamName].getType() != XmlRpcValue::TypeString) { + return sessionId; + } + + sessionId.reset(new SessionId(result[outputSessionIdParamName])); return sessionId; } @@ -231,7 +245,7 @@ WebAuthenticationClient :: logout(Ptr::Ref sessionId) XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, storageServerPath.c_str(), false); - parameters[sessionIdParamName] = sessionId->getId().c_str(); + parameters[inputSessionIdParamName] = sessionId->getId().c_str(); if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) { return false; @@ -240,6 +254,18 @@ WebAuthenticationClient :: logout(Ptr::Ref sessionId) if (xmlRpcClient.isFault()) { return false; } + + if (! result.hasMember(statusParamName)) { + return sessionId; + } + + if (result[statusParamName].getType() != XmlRpcValue::TypeBoolean) { + return sessionId; + } + + if (!(bool(result[statusParamName]))) { + return sessionId; + } return true; } diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index c97eed585..3c7d5309f 100644 --- a/livesupport/modules/storage/src/WebStorageClient.cxx +++ b/livesupport/modules/storage/src/WebStorageClient.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -159,6 +159,20 @@ static const std::string errorCodeParamName = "faultCode"; 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 */ /*------------------------------------------------------------------------------ @@ -177,6 +191,11 @@ static const std::string existsAudioClipMethodSessionIdParamName = "sessid"; *----------------------------------------------------------------------------*/ 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 */ @@ -196,9 +215,16 @@ static const std::string getAudioClipMethodSessionIdParamName = "sessid"; *----------------------------------------------------------------------------*/ 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 */ +// TODO: fix; this method does not exist any more + /*------------------------------------------------------------------------------ * The name of the store audio clip method on the storage server *----------------------------------------------------------------------------*/ @@ -444,8 +470,10 @@ WebStorageClient :: existsAudioClip(Ptr::Ref sessionId, throw std::logic_error(eMsg); } - if (xmlRpcClient.isFault() - || result.getType() != XmlRpcValue::TypeBoolean) { + if (xmlRpcClient.isFault() + || ! result.hasMember(existsAudioClipMethodResultParamName) + || result[existsAudioClipMethodResultParamName].getType() + != XmlRpcValue::TypeBoolean) { std::stringstream eMsg; eMsg << "XML-RPC method '" << existsAudioClipMethodName @@ -454,7 +482,7 @@ WebStorageClient :: existsAudioClip(Ptr::Ref sessionId, throw std::logic_error(eMsg.str()); } - return bool(result); + return bool(result[existsAudioClipMethodResultParamName]); } @@ -486,7 +514,9 @@ WebStorageClient :: getAudioClip(Ptr::Ref sessionId, } if (xmlRpcClient.isFault() - || result.getType() != XmlRpcValue::TypeString) { + || ! result.hasMember(getAudioClipMethodResultParamName) + || result[getAudioClipMethodResultParamName].getType() + != XmlRpcValue::TypeString) { std::stringstream eMsg; eMsg << "XML-RPC method '" << getAudioClipMethodName @@ -495,8 +525,8 @@ WebStorageClient :: getAudioClip(Ptr::Ref sessionId, throw std::logic_error(eMsg.str()); } - std::string xmlAudioClip(result); - Ptr::Ref audioClip; + std::string xmlAudioClip(result[getAudioClipMethodResultParamName]); + Ptr::Ref audioClip; try { Ptr::Ref parser(new xmlpp::DomParser()); @@ -644,58 +674,57 @@ WebStorageClient :: getAllAudioClips(Ptr::Ref sessionId) /*------------------------------------------------------------------------------ - * Convert a hex digit to an int. This is used by decodeString(). + * Reset the storage to its initial state. *----------------------------------------------------------------------------*/ -int -WebStorageClient :: hexDigitToChar(const char &hexDigit) const - throw () +Ptr::Ref> >::Ref +WebStorageClient :: reset(void) + throw (std::logic_error) { - if (hexDigit >= '0' && hexDigit <= '9') { - return hexDigit - '0'; - } - else if (hexDigit >= 'a' && hexDigit <= 'f') { - return hexDigit - 'a' + 10; - } - else if (hexDigit >= 'A' && hexDigit <= 'F') { - return hexDigit - 'A' + 10; - } - else { - return 0; - } -} - + XmlRpcValue parameters; + XmlRpcValue result; -/*------------------------------------------------------------------------------ - * Decode an escaped string. - *----------------------------------------------------------------------------*/ -Ptr::Ref -WebStorageClient :: decodeString(const std::string &inputString) const - throw () -{ - Ptr::Ref outputString(new std::string); - char nextChar; + XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, + storageServerPath.c_str(), false); + + parameters["dummy_param"] = "dummy_value"; - std::string::const_iterator it = inputString.begin(); - while (it != inputString.end()) { - nextChar = *(it++); - if (nextChar == '%') { - if (it == inputString.end()) { - nextChar = '?'; - } - else { - nextChar = hexDigitToChar(*(it++)); - if (it == inputString.end()) { - nextChar = '?'; - } - else { - nextChar *= 16; - nextChar += hexDigitToChar(*(it++)); - } - } - } - outputString->push_back(nextChar); + if (!xmlRpcClient.execute(resetStorageMethodName.c_str(), + parameters, result)) { + std::string eMsg = "cannot execute XML-RPC method '"; + eMsg += resetStorageMethodName; + eMsg += "'"; + throw std::logic_error(eMsg); + } + + if (xmlRpcClient.isFault() + || ! result.hasMember(resetStorageMethodResultParamName) + || result[resetStorageMethodResultParamName].getType() + != XmlRpcValue::TypeArray) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << resetStorageMethodName + << "' returned error message:\n" + << result; + throw std::logic_error(eMsg.str()); } - return outputString; + XmlRpcValue uniqueIdArray = result[resetStorageMethodResultParamName]; + Ptr::Ref> >::Ref returnValue( + new std::vector::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::Ref uniqueId(new UniqueId(10001 + i)); // TODO: fix!!! + returnValue->push_back(uniqueId); + } + + return returnValue; } diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index e666fe559..a537350e8 100644 --- a/livesupport/modules/storage/src/WebStorageClient.h +++ b/livesupport/modules/storage/src/WebStorageClient.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -99,7 +99,7 @@ using namespace LiveSupport::Core; * * * @author $Author: fgerlits $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ class WebStorageClient : virtual public Configurable, @@ -131,25 +131,6 @@ class WebStorageClient : */ 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::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: /** @@ -425,6 +406,16 @@ class WebStorageClient : getAllAudioClips(Ptr::Ref sessionId) const 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::Ref> >::Ref + reset(void) + throw (std::logic_error); }; diff --git a/livesupport/modules/storage/src/WebStorageClientTest.cxx b/livesupport/modules/storage/src/WebStorageClientTest.cxx index 6118c1adf..29f732b26 100644 --- a/livesupport/modules/storage/src/WebStorageClientTest.cxx +++ b/livesupport/modules/storage/src/WebStorageClientTest.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -159,10 +159,19 @@ void WebStorageClientTest :: audioClipTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id01(new UniqueId(10001)); + Ptr::Ref id01; Ptr::Ref id77(new UniqueId(10077)); Ptr::Ref sessionId; + Ptr::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; isize(); i++) { + std::cout << uniqueIdVector->at(i)->getId() << std::endl; + } +*/ CPPUNIT_ASSERT( sessionId = authentication->login("root", "q")); CPPUNIT_ASSERT(!wsc->existsAudioClip(sessionId, id77));