From 6b616419dfe609b267a36ad4b463837bc10ffc03 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 23 Nov 2004 09:42:36 +0000 Subject: [PATCH] I thought I committed this last night, but apparently not --- .../core/include/LiveSupport/Core/AudioClip.h | 6 +- .../core/include/LiveSupport/Core/FadeInfo.h | 6 +- .../core/include/LiveSupport/Core/Playlist.h | 6 +- .../LiveSupport/Core/PlaylistElement.h | 6 +- .../LiveSupport/Core/StorageClientInterface.h | 89 +++-- livesupport/modules/storage/etc/Makefile.in | 17 +- .../modules/storage/etc/storageClient.xml | 15 +- .../modules/storage/etc/webStorage.xml | 6 +- .../storage/src/StorageClientFactory.cxx | 8 +- .../storage/src/StorageServerLoginTest.cxx | 118 ------ .../storage/src/StorageServerLoginTest.h | 107 ------ .../modules/storage/src/TestStorageClient.cxx | 50 ++- .../modules/storage/src/TestStorageClient.h | 61 +++- .../storage/src/TestStorageClientTest.cxx | 67 ++-- .../storage/src/TestStorageClientTest.h | 9 +- .../modules/storage/src/WebStorageClient.cxx | 342 +++++++++--------- .../modules/storage/src/WebStorageClient.h | 152 ++++---- .../storage/src/WebStorageClientTest.cxx | 224 +++--------- .../storage/src/WebStorageClientTest.h | 62 +--- 19 files changed, 557 insertions(+), 794 deletions(-) delete mode 100644 livesupport/modules/storage/src/StorageServerLoginTest.cxx delete mode 100644 livesupport/modules/storage/src/StorageServerLoginTest.h diff --git a/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h b/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h index 0d1dcc58b..b3214a2fe 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h +++ b/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $ ------------------------------------------------------------------------------*/ @@ -72,7 +72,7 @@ using namespace boost::posix_time; * in a Playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class AudioClip : public Configurable { @@ -161,7 +161,7 @@ class AudioClip : public Configurable * * @return the unique id of the audio clip. */ - Ptr::Ref + Ptr::Ref getId(void) const throw () { return id; diff --git a/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h b/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h index ddb65a8d2..512c11f30 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h +++ b/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h,v $ ------------------------------------------------------------------------------*/ @@ -70,7 +70,7 @@ using namespace boost::posix_time; * contained in a Playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class FadeInfo : public Configurable { @@ -173,7 +173,7 @@ class FadeInfo : public Configurable * * @return the unique id of the fade info instance. */ - Ptr::Ref + Ptr::Ref getId(void) const throw () { return id; diff --git a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h index d2985bd9e..fdf15cf61 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h +++ b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.14 $ + Version : $Revision: 1.15 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $ ------------------------------------------------------------------------------*/ @@ -71,7 +71,7 @@ using namespace boost::posix_time; * the playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ class Playlist : public Configurable { @@ -204,7 +204,7 @@ class Playlist : public Configurable * * @return the unique id of the playlist. */ - Ptr::Ref + Ptr::Ref getId(void) const throw () { return id; diff --git a/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h b/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h index a5cd676f3..f67d9e048 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h +++ b/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h,v $ ------------------------------------------------------------------------------*/ @@ -74,7 +74,7 @@ using namespace LiveSupport::Core; * An item in a playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class PlaylistElement : public Configurable { @@ -196,7 +196,7 @@ class PlaylistElement : public Configurable * * @return the id of the playlist element. */ - Ptr::Ref + Ptr::Ref getId(void) const throw () { return id; diff --git a/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h b/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h index f2b80bc0b..486294ec3 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h +++ b/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.13 $ + Version : $Revision: 1.14 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Attic/StorageClientInterface.h,v $ ------------------------------------------------------------------------------*/ @@ -44,6 +44,7 @@ #include "LiveSupport/Core/UniqueId.h" #include "LiveSupport/Core/Playlist.h" +#include "LiveSupport/Core/SessionId.h" namespace LiveSupport { @@ -61,7 +62,7 @@ namespace Core { * An interface for storage clients. * * @author $Author: fgerlits $ - * @version $Revision: 1.13 $ + * @version $Revision: 1.14 $ */ class StorageClientInterface { @@ -69,39 +70,46 @@ class StorageClientInterface /** * Tell if a playlist with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to check for. * @return true if a playlist with the specified id exists, * false otherwise. */ virtual const bool - existsPlaylist(Ptr::Ref id) const throw () + existsPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) = 0; /** * Return a playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to return. * @return the requested playlist. - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * id exists. */ virtual Ptr::Ref - getPlaylist(Ptr::Ref id) const - throw (std::invalid_argument) + getPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) = 0; /** * Acquire the resources for the playlist. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to acquire. * @return a new Playlist instance containing a uri field which * points to an executable (playable) SMIL representation of * the playlist (in the local storage). - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * specified id exists. */ virtual Ptr::Ref - acquirePlaylist(Ptr::Ref id) const + acquirePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error) = 0; @@ -109,112 +117,135 @@ class StorageClientInterface * Release the resources (audio clips, other playlists) used * in a playlist. * + * @param sessionId the session ID from the authentication client * @param playlist the playlist to release. * @exception std::logic_error if the playlist has no uri field, * or the file does not exist, etc. */ virtual void - releasePlaylist(Ptr::Ref playlist) const + releasePlaylist(Ptr::Ref sessionId, + Ptr::Ref playlist) const throw (std::logic_error) = 0; /** * Delete a playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to be deleted. - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * id exists. */ virtual void - deletePlaylist(Ptr::Ref id) - throw (std::invalid_argument) + deletePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error) = 0; /** * Return a list of all playlists in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the playlists. */ virtual Ptr::Ref> >::Ref - getAllPlaylists(void) const throw () = 0; - + getAllPlaylists(Ptr::Ref sessionId) const + throw (std::logic_error) + = 0; /** * Create a new playlist. * + * @param sessionId the session ID from the authentication client * @return the newly created playlist. */ virtual Ptr::Ref - createPlaylist() throw () = 0; + createPlaylist(Ptr::Ref sessionId) + throw (std::logic_error) + = 0; /** * Tell if an audio clip with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to check for. * @return true if an audio clip with the specified id exists, * false otherwise. */ virtual const bool - existsAudioClip(Ptr::Ref id) const throw () + existsAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) = 0; + /** * Return an audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to return. * @return the requested audio clip. - * @exception std::invalid_argument if no audio clip with the + * @exception std::logic_error if no audio clip with the * specified id exists. */ virtual Ptr::Ref - getAudioClip(Ptr::Ref id) const - throw (std::invalid_argument) + getAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) = 0; /** * Acquire the resources for the audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to acquire. * @return a new AudioClip instance, containing a uri field which * points to (a way of getting) the sound file. - * @exception std::invalid_argument if no audio clip with the + * @exception std::logic_error if no audio clip with the * specified id exists. */ virtual Ptr::Ref - acquireAudioClip(Ptr::Ref id) const - throw (std::logic_error) + acquireAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) = 0; /** * Release the resource (sound file) used by an audio clip. * + * @param sessionId the session ID from the authentication client * @param audioClip the id of the audio clip to release. * @exception std::logic_error if the audio clip has no uri field, * or the file does not exist, etc. */ virtual void - releaseAudioClip(Ptr::Ref audioClip) const - throw (std::logic_error) + releaseAudioClip(Ptr::Ref sessionId, + Ptr::Ref audioClip) const + throw (std::logic_error) = 0; /** * Delete an audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to be deleted. - * @exception std::invalid_argument if no audio clip with the + * @exception std::logic_error if no audio clip with the * specified id exists. */ virtual void - deleteAudioClip(Ptr::Ref id) - throw (std::invalid_argument) + deleteAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error) = 0; /** * Return a list of all audio clips in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the playlists. */ virtual Ptr::Ref> >::Ref - getAllAudioClips(void) const throw () = 0; - + getAllAudioClips(Ptr::Ref sessionId) const + throw (std::logic_error) + = 0; }; diff --git a/livesupport/modules/storage/etc/Makefile.in b/livesupport/modules/storage/etc/Makefile.in index 0fdc29db2..7374872c3 100644 --- a/livesupport/modules/storage/etc/Makefile.in +++ b/livesupport/modules/storage/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.6 $ +# Version : $Revision: 1.7 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/etc/Makefile.in,v $ # # @configure_input@ @@ -63,6 +63,12 @@ CORE_LIB_DIR = ${CORE_DIR}/lib CORE_LIB = livesupport_core CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a +AUTHENTICATION_DIR = ${MODULES_DIR}/authentication +AUTHENTICATION_INCLUDE_DIR = ${AUTHENTICATION_DIR}/include +AUTHENTICATION_LIB_DIR = ${AUTHENTICATION_DIR}/lib +AUTHENTICATION_LIB = livesupport_authentication +AUTHENTICATION_LIB_FILE = ${AUTHENTICATION_LIB_DIR}/lib${AUTHENTICATION_LIB}.a + VPATH = ${SRC_DIR} TEST_RESULTS = ${DOC_DIR}/testResults.xml @@ -86,8 +92,10 @@ CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ \ -I${BOOST_INCLUDE_DIR} \ -I${LIBXMLPP_INCLUDE_DIR} \ -I${CORE_INCLUDE_DIR} \ + -I${AUTHENTICATION_INCLUDE_DIR} \ -I${INCLUDE_DIR} -I${TMP_DIR} -LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR} +LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${CORE_LIB_DIR} \ + -L${AUTHENTICATION_LIB_DIR} -L${LIB_DIR} #------------------------------------------------------------------------------- @@ -98,12 +106,11 @@ STORAGE_LIB_OBJS = ${TMP_DIR}/StorageClientFactory.o \ ${TMP_DIR}/WebStorageClient.o TEST_RUNNER_OBJS = ${TMP_DIR}/TestStorageClientTest.o \ - ${TMP_DIR}/StorageServerLoginTest.o \ ${TMP_DIR}/WebStorageClientTest.o \ ${TMP_DIR}/TestRunner.o -TEST_RUNNER_LIBS = -l${STORAGE_LIB} -l${CORE_LIB} -lxml++-1.0 -lcppunit -ldl \ - -lxmlrpc++ -lssl +TEST_RUNNER_LIBS = -l${STORAGE_LIB} -l${CORE_LIB} -l${AUTHENTICATION_LIB} \ + -lxml++-1.0 -lcppunit -ldl -lxmlrpc++ -lssl #------------------------------------------------------------------------------- diff --git a/livesupport/modules/storage/etc/storageClient.xml b/livesupport/modules/storage/etc/storageClient.xml index 8f471f6f9..03f5ff855 100644 --- a/livesupport/modules/storage/etc/storageClient.xml +++ b/livesupport/modules/storage/etc/storageClient.xml @@ -1,7 +1,7 @@ + @@ -18,6 +18,15 @@ + + + + + + + + + ]> @@ -32,4 +41,8 @@ + + + diff --git a/livesupport/modules/storage/etc/webStorage.xml b/livesupport/modules/storage/etc/webStorage.xml index 8812626c7..cfcc793c2 100644 --- a/livesupport/modules/storage/etc/webStorage.xml +++ b/livesupport/modules/storage/etc/webStorage.xml @@ -1,7 +1,7 @@ + @@ -9,12 +9,8 @@ - - - ]> - diff --git a/livesupport/modules/storage/src/StorageClientFactory.cxx b/livesupport/modules/storage/src/StorageClientFactory.cxx index 3fda862ec..dee4b0f77 100644 --- a/livesupport/modules/storage/src/StorageClientFactory.cxx +++ b/livesupport/modules/storage/src/StorageClientFactory.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/StorageClientFactory.cxx,v $ ------------------------------------------------------------------------------*/ @@ -36,6 +36,7 @@ #include "LiveSupport/Storage/StorageClientFactory.h" #include "TestStorageClient.h" +#include "WebStorageClient.h" using namespace LiveSupport::Core; @@ -93,7 +94,7 @@ StorageClientFactory :: configure(const xmlpp::Element & element) storageClient.reset(); - // try to look for an TestStorageClient configuration element + // try to look for a TestStorageClient configuration element xmlpp::Node::NodeList nodes = element.get_children(TestStorageClient::getConfigElementName()); if (nodes.size() >= 1) { @@ -109,4 +110,3 @@ StorageClientFactory :: configure(const xmlpp::Element & element) } } - diff --git a/livesupport/modules/storage/src/StorageServerLoginTest.cxx b/livesupport/modules/storage/src/StorageServerLoginTest.cxx deleted file mode 100644 index ed9afaad9..000000000 --- a/livesupport/modules/storage/src/StorageServerLoginTest.cxx +++ /dev/null @@ -1,118 +0,0 @@ -/*------------------------------------------------------------------------------ - - Copyright (c) 2004 Media Development Loan Fund - - This file is part of the LiveSupport project. - http://livesupport.campware.org/ - To report bugs, send an e-mail to bugs@campware.org - - LiveSupport 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. - - LiveSupport 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 LiveSupport; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - - Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/StorageServerLoginTest.cxx,v $ - -------------------------------------------------------------------------------*/ - -/* ============================================================ include files */ - -#ifdef HAVE_CONFIG_H -#include "configure.h" -#endif - -#if HAVE_UNISTD_H -#include -#else -#error "Need unistd.h" -#endif - - -#include -#include -#include -#include - -#include "StorageServerLoginTest.h" - - -using namespace std; -using namespace XmlRpc; -using namespace LiveSupport::Storage; - -/* =================================================== local data structures */ - - -/* ================================================ local constants & macros */ - -CPPUNIT_TEST_SUITE_REGISTRATION(StorageServerLoginTest); - -/** - * The name of the configuration file for the ... - */ -// static const std::string configFileName = "etc/..."; - - -/* =============================================== local function prototypes */ - - -/* ============================================================= module code */ - -/*------------------------------------------------------------------------------ - * Set up the test environment - *----------------------------------------------------------------------------*/ -void -StorageServerLoginTest :: setUp(void) throw () -{ -} - - -/*------------------------------------------------------------------------------ - * Clean up the test environment - *----------------------------------------------------------------------------*/ -void -StorageServerLoginTest :: tearDown(void) throw () -{ -} - - -/*------------------------------------------------------------------------------ - * A simple smoke test. - *----------------------------------------------------------------------------*/ -void -StorageServerLoginTest :: firstTest(void) - throw (CPPUNIT_NS::Exception) -{ - XmlRpcValue parameters; - XmlRpcValue result; - - XmlRpcClient xmlRpcClient("localhost", 80, - "/storage/var/xmlrpc/xrLocStor.php", false); - - parameters.clear(); - parameters["login"] = "root"; - parameters["pass"] = "q"; - xmlRpcClient.execute("locstor.login", parameters, result); - - std::string sessionId(result); - - parameters.clear(); - parameters["sessid"] = sessionId; - result.clear(); - xmlRpcClient.execute("locstor.logout", parameters, result); - - std::string byeMessage(result); - CPPUNIT_ASSERT(byeMessage == "Bye"); -} diff --git a/livesupport/modules/storage/src/StorageServerLoginTest.h b/livesupport/modules/storage/src/StorageServerLoginTest.h deleted file mode 100644 index 3e1610a92..000000000 --- a/livesupport/modules/storage/src/StorageServerLoginTest.h +++ /dev/null @@ -1,107 +0,0 @@ -/*------------------------------------------------------------------------------ - - Copyright (c) 2004 Media Development Loan Fund - - This file is part of the LiveSupport project. - http://livesupport.campware.org/ - To report bugs, send an e-mail to bugs@campware.org - - LiveSupport 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. - - LiveSupport 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 LiveSupport; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - - Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/StorageServerLoginTest.h,v $ - -------------------------------------------------------------------------------*/ -#ifndef StorageServerLoginTest_h -#define StorageServerLoginTest_h - -#ifndef __cplusplus -#error This is a C++ include file -#endif - - -/* ============================================================ include files */ - -#ifdef HAVE_CONFIG_H -#include "configure.h" -#endif - -#include - - -namespace LiveSupport { -namespace Storage { - -using namespace LiveSupport; - -/* ================================================================ constants */ - - -/* =================================================================== macros */ - - -/* =============================================================== data types */ - -/** - * Unit test to test the XML-RPC communication with the storage server. - * - * @author $Author: fgerlits $ - * @version $Revision: 1.1 $ - */ -class StorageServerLoginTest : public CPPUNIT_NS::TestFixture -{ - CPPUNIT_TEST_SUITE(StorageServerLoginTest); - CPPUNIT_TEST(firstTest); - CPPUNIT_TEST_SUITE_END(); - - protected: - - /** - * Simple smoke test. - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - firstTest(void) throw (CPPUNIT_NS::Exception); - - public: - - /** - * Set up the environment for the test case. - */ - void - setUp(void) throw (); - - /** - * Clean up the environment after the test case. - */ - void - tearDown(void) throw (); -}; - - -/* ================================================= external data structures */ - - -/* ====================================================== function prototypes */ - - -} // namespace Storage -} // namespace LiveSupport - -#endif // StorageServerLoginTest_h - diff --git a/livesupport/modules/storage/src/TestStorageClient.cxx b/livesupport/modules/storage/src/TestStorageClient.cxx index 2167b4264..a9318decb 100644 --- a/livesupport/modules/storage/src/TestStorageClient.cxx +++ b/livesupport/modules/storage/src/TestStorageClient.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.16 $ + Version : $Revision: 1.17 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $ ------------------------------------------------------------------------------*/ @@ -182,7 +182,8 @@ TestStorageClient :: configure(const xmlpp::Element & element) * Tell if a playlist exists. *----------------------------------------------------------------------------*/ const bool -TestStorageClient :: existsPlaylist(Ptr::Ref id) const +TestStorageClient :: existsPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw () { return playlistMap.count(id->getId()) == 1 ? true : false; @@ -193,7 +194,8 @@ TestStorageClient :: existsPlaylist(Ptr::Ref id) const * Return a playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -TestStorageClient :: getPlaylist(Ptr::Ref id) const +TestStorageClient :: getPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::invalid_argument) { PlaylistMap::const_iterator it = playlistMap.find(id->getId()); @@ -210,7 +212,8 @@ TestStorageClient :: getPlaylist(Ptr::Ref id) const * Acquire resources for a playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -TestStorageClient :: acquirePlaylist(Ptr::Ref id) const +TestStorageClient :: acquirePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error) { PlaylistMap::const_iterator playlistMapIt = playlistMap.find(id->getId()); @@ -241,9 +244,10 @@ TestStorageClient :: acquirePlaylist(Ptr::Ref id) const Playlist::const_iterator it = oldPlaylist->begin(); while (it != oldPlaylist->end()) { - Ptr::Ref audioClip = acquireAudioClip( it->second + Ptr::Ref audioClip + = acquireAudioClip(sessionId, it->second ->getAudioClip() - ->getId() ); + ->getId()); Ptr::Ref relativeOffset(new time_duration( *(it->second->getRelativeOffset()) )); Ptr::Ref oldFadeInfo = it->second->getFadeInfo(); @@ -280,7 +284,8 @@ TestStorageClient :: acquirePlaylist(Ptr::Ref id) const * Release a playlist. *----------------------------------------------------------------------------*/ void -TestStorageClient :: releasePlaylist(Ptr::Ref playlist) const +TestStorageClient :: releasePlaylist(Ptr::Ref sessionId, + Ptr::Ref playlist) const throw (std::logic_error) { if (! playlist->getUri()) { @@ -300,7 +305,7 @@ TestStorageClient :: releasePlaylist(Ptr::Ref playlist) const Playlist::const_iterator it = playlist->begin(); while (it != playlist->end()) { try { - releaseAudioClip(it->second->getAudioClip()); + releaseAudioClip(sessionId, it->second->getAudioClip()); } catch (std::invalid_argument &e) { ++badAudioClips; @@ -324,7 +329,8 @@ TestStorageClient :: releasePlaylist(Ptr::Ref playlist) const * Delete a playlist. *----------------------------------------------------------------------------*/ void -TestStorageClient :: deletePlaylist(Ptr::Ref id) +TestStorageClient :: deletePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) throw (std::invalid_argument) { // erase() returns the number of entries found & erased @@ -338,7 +344,8 @@ TestStorageClient :: deletePlaylist(Ptr::Ref id) * Return a listing of all the playlists in the playlist store. *----------------------------------------------------------------------------*/ Ptr::Ref> >::Ref -TestStorageClient :: getAllPlaylists(void) const +TestStorageClient :: getAllPlaylists(Ptr::Ref sessionId) + const throw () { PlaylistMap::const_iterator it = playlistMap.begin(); @@ -358,7 +365,8 @@ TestStorageClient :: getAllPlaylists(void) const * Create a new playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -TestStorageClient :: createPlaylist() throw () +TestStorageClient :: createPlaylist(Ptr::Ref sessionId) + throw () { // generate a new UniqueId -- TODO: fix UniqueId to make sure // this is really unique; not checked here! @@ -381,8 +389,9 @@ TestStorageClient :: createPlaylist() throw () * Tell if an audio clip exists. *----------------------------------------------------------------------------*/ const bool -TestStorageClient :: existsAudioClip(Ptr::Ref id) const - throw () +TestStorageClient :: existsAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw () { return audioClipMap.count(id->getId()) == 1 ? true : false; } @@ -392,7 +401,8 @@ TestStorageClient :: existsAudioClip(Ptr::Ref id) const * Return an audio clip. *----------------------------------------------------------------------------*/ Ptr::Ref -TestStorageClient :: getAudioClip(Ptr::Ref id) const +TestStorageClient :: getAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::invalid_argument) { AudioClipMap::const_iterator it = audioClipMap.find(id->getId()); @@ -409,7 +419,8 @@ TestStorageClient :: getAudioClip(Ptr::Ref id) const * Acquire resources for an audio clip. *----------------------------------------------------------------------------*/ Ptr::Ref -TestStorageClient :: acquireAudioClip(Ptr::Ref id) const +TestStorageClient :: acquireAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error) { AudioClipMap::const_iterator it = audioClipMap.find(id->getId()); @@ -449,7 +460,8 @@ TestStorageClient :: acquireAudioClip(Ptr::Ref id) const * Release an audio clip. *----------------------------------------------------------------------------*/ void -TestStorageClient :: releaseAudioClip(Ptr::Ref audioClip) const +TestStorageClient :: releaseAudioClip(Ptr::Ref sessionId, + Ptr::Ref audioClip) const throw (std::logic_error) { if (*(audioClip->getUri()) == "") { @@ -465,7 +477,8 @@ TestStorageClient :: releaseAudioClip(Ptr::Ref audioClip) const * Delete an audio clip. *----------------------------------------------------------------------------*/ void -TestStorageClient :: deleteAudioClip(Ptr::Ref id) +TestStorageClient :: deleteAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) throw (std::invalid_argument) { // erase() returns the number of entries found & erased @@ -479,7 +492,8 @@ TestStorageClient :: deleteAudioClip(Ptr::Ref id) * Return a listing of all the audio clips in the audio clip store. *----------------------------------------------------------------------------*/ Ptr::Ref> >::Ref -TestStorageClient :: getAllAudioClips(void) const +TestStorageClient :: getAllAudioClips(Ptr::Ref sessionId) + const throw () { AudioClipMap::const_iterator it = audioClipMap.begin(); diff --git a/livesupport/modules/storage/src/TestStorageClient.h b/livesupport/modules/storage/src/TestStorageClient.h index 325deefec..c6ce3b553 100644 --- a/livesupport/modules/storage/src/TestStorageClient.h +++ b/livesupport/modules/storage/src/TestStorageClient.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.14 $ + Version : $Revision: 1.15 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -47,6 +47,7 @@ #include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/StorageClientInterface.h" +#include "LiveSupport/Core/SessionId.h" namespace LiveSupport { @@ -67,7 +68,7 @@ using namespace LiveSupport::Core; * A dummy storage client, only used for test purposes. * * @author $Author: fgerlits $ - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ class TestStorageClient : virtual public Configurable, @@ -141,28 +142,32 @@ class TestStorageClient : configure(const xmlpp::Element & element) throw (std::invalid_argument, std::logic_error); - + /** * Tell if a playlist with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to check for. * @return true if a playlist with the specified id exists, * false otherwise. */ virtual const bool - existsPlaylist(Ptr::Ref id) const + existsPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (); /** * Return a playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to return. * @return the requested playlist. * @exception std::invalid_argument if no playlist with the specified * id exists. */ virtual Ptr::Ref - getPlaylist(Ptr::Ref id) const + getPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::invalid_argument); /** @@ -173,6 +178,7 @@ class TestStorageClient : * appended to the temp storage path read from the configuration file, * plus a ".smil" extension. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to acquire. * @return a new Playlist instance containing a uri field which * points to an executable (playable) SMIL representation of @@ -181,69 +187,82 @@ class TestStorageClient : * specified id exists. */ virtual Ptr::Ref - acquirePlaylist(Ptr::Ref id) const + acquirePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error); /** * Release the resources (audio clips, other playlists) used * in a playlist. * + * @param sessionId the session ID from the authentication client * @param playlist the playlist to release. * @exception std::logic_error if the playlist has no uri field, * or the file does not exist, etc. */ virtual void - releasePlaylist(Ptr::Ref playlist) const + releasePlaylist(Ptr::Ref sessionId, + Ptr::Ref playlist) const throw (std::logic_error); /** * Delete the playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to be deleted. * @exception std::invalid_argument if no playlist with the specified * id exists. */ virtual void - deletePlaylist(Ptr::Ref id) + deletePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) throw (std::invalid_argument); /** * Return a list of all playlists in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the playlists. */ virtual Ptr::Ref> >::Ref - getAllPlaylists(void) const throw (); + getAllPlaylists(Ptr::Ref sessionId) const + throw (); /** * Create a new playlist. * + * @param sessionId the session ID from the authentication client * @return the newly created playlist. */ virtual Ptr::Ref - createPlaylist() throw (); + createPlaylist(Ptr::Ref sessionId) + throw (); /** * Tell if an audio clip with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to check for. * @return true if an audio clip with the specified id exists, * false otherwise. */ virtual const bool - existsAudioClip(Ptr::Ref id) const + existsAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (); /** * Return an audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to return. * @return the requested audio clip. * @exception std::invalid_argument if no audio clip with the * specified id exists. */ virtual Ptr::Ref - getAudioClip(Ptr::Ref id) const + getAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::invalid_argument); /** @@ -254,6 +273,7 @@ class TestStorageClient : * Assumes URIs in the config file are relative paths prefixed by * "file:"; e.g., "file:var/test1.mp3". * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to acquire. * @return a new AudioClip instance, containing a uri field which * points to (a way of getting) the sound file. @@ -261,38 +281,45 @@ class TestStorageClient : * specified id exists. */ virtual Ptr::Ref - acquireAudioClip(Ptr::Ref id) const + acquireAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error); /** * Release the resource (sound file) used by an audio clip. * - * @param id the id of the audio clip to release. + * @param sessionId the session ID from the authentication client + * @param audioClip the audio clip to release. * @exception std::logic_error if the audio clip has no uri field, * or the file does not exist, etc. */ virtual void - releaseAudioClip(Ptr::Ref audioClip) const + releaseAudioClip(Ptr::Ref sessionId, + Ptr::Ref audioClip) const throw (std::logic_error); /** * Delete the audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to be deleted. * @exception std::invalid_argument if no audio clip with the * specified id exists. */ virtual void - deleteAudioClip(Ptr::Ref id) + deleteAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) throw (std::invalid_argument); /** * Return a list of all audio clips in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the audio clips. */ virtual Ptr::Ref> >::Ref - getAllAudioClips(void) const throw (); + getAllAudioClips(Ptr::Ref sessionId) const + throw (); }; diff --git a/livesupport/modules/storage/src/TestStorageClientTest.cxx b/livesupport/modules/storage/src/TestStorageClientTest.cxx index 1024bdb69..376ecc943 100644 --- a/livesupport/modules/storage/src/TestStorageClientTest.cxx +++ b/livesupport/modules/storage/src/TestStorageClientTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.13 $ + Version : $Revision: 1.14 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -89,6 +89,8 @@ TestStorageClientTest :: setUp(void) throw () } catch (xmlpp::exception &e) { CPPUNIT_FAIL("error parsing configuration file"); } + + dummySessionId.reset(new SessionId("dummy")); } @@ -109,13 +111,13 @@ void TestStorageClientTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id1(new UniqueId(1)); - Ptr::Ref id2(new UniqueId(77)); + Ptr::Ref id1(new UniqueId(1)); + Ptr::Ref id2(new UniqueId(77)); - CPPUNIT_ASSERT(tsc->existsPlaylist(id1)); - CPPUNIT_ASSERT(!tsc->existsPlaylist(id2)); + CPPUNIT_ASSERT(tsc->existsPlaylist(dummySessionId, id1)); + CPPUNIT_ASSERT(!tsc->existsPlaylist(dummySessionId, id2)); - Ptr::Ref playlist = tsc->getPlaylist(id1); + Ptr::Ref playlist = tsc->getPlaylist(dummySessionId, id1); CPPUNIT_ASSERT(playlist->getId()->getId() == id1->getId()); } @@ -131,17 +133,17 @@ TestStorageClientTest :: deletePlaylistTest(void) Ptr::Ref id2(new UniqueId(77)); try { - tsc->deletePlaylist(id2); + tsc->deletePlaylist(dummySessionId, id2); CPPUNIT_FAIL("allowed to delete non-existent playlist"); } catch (std::invalid_argument &e) { } try { - tsc->deletePlaylist(id1); + tsc->deletePlaylist(dummySessionId, id1); } catch (std::invalid_argument &e) { CPPUNIT_FAIL("cannot delete existing playlist"); } try { - tsc->deletePlaylist(id1); + tsc->deletePlaylist(dummySessionId, id1); CPPUNIT_FAIL("allowed to delete non-existent playlist"); } catch (std::invalid_argument &e) { } @@ -155,11 +157,11 @@ void TestStorageClientTest :: getAllPlaylistsTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref> >::Ref playlistVector = - tsc->getAllPlaylists(); + Ptr::Ref> >::Ref + playlistVector = tsc->getAllPlaylists(dummySessionId); CPPUNIT_ASSERT(playlistVector->size() == 1); - Ptr::Ref playlist = (*playlistVector)[0]; + Ptr::Ref playlist = (*playlistVector)[0]; CPPUNIT_ASSERT((int) (playlist->getId()->getId()) == 1); } @@ -171,9 +173,9 @@ void TestStorageClientTest :: createPlaylistTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref playlist = tsc->createPlaylist(); + Ptr::Ref playlist = tsc->createPlaylist(dummySessionId); - CPPUNIT_ASSERT(tsc->existsPlaylist(playlist->getId())); + CPPUNIT_ASSERT(tsc->existsPlaylist(dummySessionId, playlist->getId())); } @@ -184,26 +186,27 @@ void TestStorageClientTest :: audioClipTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id2(new UniqueId(10002)); - Ptr::Ref id77(new UniqueId(10077)); + Ptr::Ref id2(new UniqueId(10002)); + Ptr::Ref id77(new UniqueId(10077)); - CPPUNIT_ASSERT(tsc->existsAudioClip(id2)); - CPPUNIT_ASSERT(!tsc->existsAudioClip(id77)); + CPPUNIT_ASSERT(tsc->existsAudioClip(dummySessionId, id2)); + CPPUNIT_ASSERT(!tsc->existsAudioClip(dummySessionId, id77)); - Ptr::Ref audioClip = tsc->getAudioClip(id2); + Ptr::Ref audioClip = tsc->getAudioClip(dummySessionId, id2); CPPUNIT_ASSERT(audioClip->getId()->getId() == id2->getId()); CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds() == 30*60); - Ptr::Ref> >::Ref audioClipVector = - tsc->getAllAudioClips(); + Ptr::Ref> >::Ref + audioClipVector + = tsc->getAllAudioClips(dummySessionId); CPPUNIT_ASSERT(audioClipVector->size() == 2); audioClip = (*audioClipVector)[0]; CPPUNIT_ASSERT((int) (audioClip->getId()->getId()) == 10001); - tsc->deleteAudioClip(id2); - CPPUNIT_ASSERT(!tsc->existsAudioClip(id2)); + tsc->deleteAudioClip(dummySessionId, id2); + CPPUNIT_ASSERT(!tsc->existsAudioClip(dummySessionId, id2)); } @@ -214,12 +217,12 @@ void TestStorageClientTest :: acquireAudioClipTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id2(new UniqueId(10002)); - Ptr::Ref id77(new UniqueId(10077)); - Ptr::Ref audioClip; + Ptr::Ref id2(new UniqueId(10002)); + Ptr::Ref id77(new UniqueId(10077)); + Ptr::Ref audioClip; try { - audioClip = tsc->acquireAudioClip(id2); + audioClip = tsc->acquireAudioClip(dummySessionId, id2); } catch (std::logic_error &e) { std::string eMsg = "could not acquire audio clip:\n"; @@ -232,7 +235,7 @@ TestStorageClientTest :: acquireAudioClipTest(void) CPPUNIT_ASSERT(*(audioClip->getUri()) == audioClipUri); try { - tsc->releaseAudioClip(audioClip); + tsc->releaseAudioClip(dummySessionId, audioClip); } catch (std::logic_error &e) { std::string eMsg = "could not release audio clip:\n"; @@ -241,7 +244,7 @@ TestStorageClientTest :: acquireAudioClipTest(void) } try { - audioClip = tsc->acquireAudioClip(id77); + audioClip = tsc->acquireAudioClip(dummySessionId, id77); CPPUNIT_FAIL("allowed to acquire non-existent audio clip"); } catch (std::logic_error &e) { @@ -261,7 +264,7 @@ TestStorageClientTest :: acquirePlaylistTest(void) Ptr::Ref playlist; try { - playlist = tsc->acquirePlaylist(id1); + playlist = tsc->acquirePlaylist(dummySessionId, id1); } catch (std::logic_error &e) { std::string eMsg = "could not acquire playlist:\n"; @@ -280,7 +283,7 @@ TestStorageClientTest :: acquirePlaylistTest(void) string savedTempFilePath = playlist->getUri()->substr(7); try { - tsc->releasePlaylist(playlist); + tsc->releasePlaylist(dummySessionId, playlist); } catch (std::logic_error &e) { std::string eMsg = "could not release playlist:\n"; @@ -296,7 +299,7 @@ TestStorageClientTest :: acquirePlaylistTest(void) ifs2.close(); try { - playlist = tsc->acquirePlaylist(id77); + playlist = tsc->acquirePlaylist(dummySessionId, id77); CPPUNIT_FAIL("allowed to acquire non-existent playlist"); } catch (std::logic_error &e) { diff --git a/livesupport/modules/storage/src/TestStorageClientTest.h b/livesupport/modules/storage/src/TestStorageClientTest.h index c2f39094f..930358a48 100644 --- a/livesupport/modules/storage/src/TestStorageClientTest.h +++ b/livesupport/modules/storage/src/TestStorageClientTest.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.h,v $ ------------------------------------------------------------------------------*/ @@ -58,7 +58,7 @@ namespace Storage { * Unit test for the UploadPlaylistMetohd class. * * @author $Author: fgerlits $ - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * @see TestStorageClient */ class TestStorageClientTest : public CPPUNIT_NS::TestFixture @@ -79,6 +79,11 @@ class TestStorageClientTest : public CPPUNIT_NS::TestFixture */ Ptr::Ref tsc; + /** + * A dummy session ID to pass to the storage client. + */ + Ptr::Ref dummySessionId; + protected: /** diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index 5f3f3b189..aabd07118 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.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ ------------------------------------------------------------------------------*/ @@ -90,21 +90,6 @@ static const std::string locationPortAttrName = "port"; *----------------------------------------------------------------------------*/ static const std::string locationPathAttrName = "path"; -/*------------------------------------------------------------------------------ - * The name of the config child element for the storage server login - *----------------------------------------------------------------------------*/ -static const std::string identityConfigElementName = "identity"; - -/*------------------------------------------------------------------------------ - * The name of the config child element for the storage server login name - *----------------------------------------------------------------------------*/ -static const std::string identityLoginAttrName = "login"; - -/*------------------------------------------------------------------------------ - * The name of the config child element for the storage server login password - *----------------------------------------------------------------------------*/ -static const std::string identityPasswordAttrName = "pass"; - /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ constants for the SMIL file */ @@ -174,37 +159,6 @@ static const std::string errorCodeParamName = "faultCode"; static const std::string errorMessageParamName = "faultString"; -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: login */ - -/*------------------------------------------------------------------------------ - * The name of the login method on the storage server - *----------------------------------------------------------------------------*/ -static const std::string loginMethodName = "locstor.login"; - -/*------------------------------------------------------------------------------ - * The name of the login parameter in the input structure - *----------------------------------------------------------------------------*/ -static const std::string loginMethodLoginParamName = "login"; - -/*------------------------------------------------------------------------------ - * The name of the password parameter in the input structure - *----------------------------------------------------------------------------*/ -static const std::string loginMethodPasswordParamName = "pass"; - - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: logout */ - -/*------------------------------------------------------------------------------ - * The name of the logout method on the storage server - *----------------------------------------------------------------------------*/ -static const std::string logoutMethodName = "locstor.logout"; - -/*------------------------------------------------------------------------------ - * The name of the session ID parameter in the input structure - *----------------------------------------------------------------------------*/ -static const std::string logoutMethodSessionIdParamName = "sessid"; - - /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */ /*------------------------------------------------------------------------------ @@ -224,6 +178,25 @@ static const std::string existsAudioClipMethodSessionIdParamName = "sessid"; static const std::string existsAudioClipMethodAudioClipIdParamName = "gunid"; +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: getAudioClip */ + +/*------------------------------------------------------------------------------ + * The name of the get audio clip method on the storage server + *----------------------------------------------------------------------------*/ +static const std::string getAudioClipMethodName + = "locstor.getAudioClip"; + +/*------------------------------------------------------------------------------ + * The name of the session ID parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string getAudioClipMethodSessionIdParamName = "sessid"; + +/*------------------------------------------------------------------------------ + * The name of the audio clip unique ID parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string getAudioClipMethodAudioClipIdParamName = "gunid"; + + /* =============================================== local function prototypes */ @@ -299,96 +272,6 @@ WebStorageClient :: configure(const xmlpp::Element & element) eMsg += " XML element"; throw std::invalid_argument(eMsg); } - - // read the login and password to the storage server - childNodes = element.get_children(identityConfigElementName); - it = childNodes.begin(); - - if (it == childNodes.end()) { - std::string eMsg = "missing "; - eMsg += identityConfigElementName; - eMsg += " XML element"; - throw std::invalid_argument(eMsg); - } - - const xmlpp::Element * identityConfigElement - = dynamic_cast (*it); - if (!(attribute = identityConfigElement - ->get_attribute(identityLoginAttrName))) { - std::string eMsg = "Missing attribute "; - eMsg += identityLoginAttrName; - throw std::invalid_argument(eMsg); - } - storageServerLogin = attribute->get_value(); - - if (!(attribute = identityConfigElement - ->get_attribute(identityPasswordAttrName))) { - std::string eMsg = "Missing attribute "; - eMsg += identityPasswordAttrName; - throw std::invalid_argument(eMsg); - } - storageServerPassword = attribute->get_value(); - - ++it; - if (it != childNodes.end()) { - std::string eMsg = "more than one "; - eMsg += identityConfigElementName; - eMsg += " XML element"; - throw std::invalid_argument(eMsg); - } -} - - -/*------------------------------------------------------------------------------ - * Login to the storage server. - *----------------------------------------------------------------------------*/ -std::string -WebStorageClient :: loginToStorageServer(void) const - throw () -{ - XmlRpcValue parameters; - XmlRpcValue result; - - XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, - storageServerPath.c_str(), false); - - parameters[loginMethodLoginParamName] = storageServerLogin.c_str(); - parameters[loginMethodPasswordParamName] = storageServerPassword.c_str(); - - if (!xmlRpcClient.execute(loginMethodName.c_str(), parameters, result)) { - // throw exception; - } - - if (result.getType() != XmlRpcValue::TypeString) { - return std::string(""); // change to throw exception - } - - return std::string(result); -} - - -/*------------------------------------------------------------------------------ - * Logout from the storage server. - *----------------------------------------------------------------------------*/ -void -WebStorageClient :: logoutFromStorageServer(std::string sessionId) const - throw () -{ - XmlRpcValue parameters; - XmlRpcValue result; - - XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, - storageServerPath.c_str(), false); - - parameters[logoutMethodSessionIdParamName] = sessionId.c_str(); - - if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) { - //throw exception; - } - - if (xmlRpcClient.isFault()) { - // throw exception - } } @@ -396,8 +279,9 @@ WebStorageClient :: logoutFromStorageServer(std::string sessionId) const * Tell if a playlist exists. *----------------------------------------------------------------------------*/ const bool -WebStorageClient :: existsPlaylist(Ptr::Ref id) const - throw () +WebStorageClient :: existsPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) { return false; } @@ -407,8 +291,9 @@ WebStorageClient :: existsPlaylist(Ptr::Ref id) const * Return a playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: getPlaylist(Ptr::Ref id) const - throw (std::invalid_argument) +WebStorageClient :: getPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) { Ptr::Ref playlist(new Playlist); return playlist; @@ -419,7 +304,8 @@ WebStorageClient :: getPlaylist(Ptr::Ref id) const * Acquire resources for a playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: acquirePlaylist(Ptr::Ref id) const +WebStorageClient :: acquirePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error) { Ptr::Ref playlist(new Playlist); @@ -431,7 +317,8 @@ WebStorageClient :: acquirePlaylist(Ptr::Ref id) const * Release a playlist. *----------------------------------------------------------------------------*/ void -WebStorageClient :: releasePlaylist(Ptr::Ref playlist) const +WebStorageClient :: releasePlaylist(Ptr::Ref sessionId, + Ptr::Ref playlist) const throw (std::logic_error) { @@ -442,8 +329,9 @@ WebStorageClient :: releasePlaylist(Ptr::Ref playlist) const * Delete a playlist. *----------------------------------------------------------------------------*/ void -WebStorageClient :: deletePlaylist(Ptr::Ref id) - throw (std::invalid_argument) +WebStorageClient :: deletePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error) { } @@ -453,8 +341,8 @@ WebStorageClient :: deletePlaylist(Ptr::Ref id) * Return a listing of all the playlists in the playlist store. *----------------------------------------------------------------------------*/ Ptr::Ref> >::Ref -WebStorageClient :: getAllPlaylists(void) const - throw () +WebStorageClient :: getAllPlaylists(Ptr::Ref sessionId) const + throw (std::logic_error) { Ptr::Ref> >::Ref playlistVector( new std::vector::Ref>); @@ -466,7 +354,8 @@ WebStorageClient :: getAllPlaylists(void) const * Create a new playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: createPlaylist() throw () +WebStorageClient :: createPlaylist(Ptr::Ref sessionId) + throw (std::logic_error) { Ptr::Ref playlist(new Playlist); return playlist; @@ -477,29 +366,37 @@ WebStorageClient :: createPlaylist() throw () * Tell if an audio clip exists. *----------------------------------------------------------------------------*/ const bool -WebStorageClient :: existsAudioClip(Ptr::Ref id) const - throw () +WebStorageClient :: existsAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) { - std::string sessionId = loginToStorageServer(); - XmlRpcValue parameters; XmlRpcValue result; XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, storageServerPath.c_str(), false); - parameters[existsAudioClipMethodSessionIdParamName] = sessionId.c_str(); - parameters[existsAudioClipMethodAudioClipIdParamName] = int(id->getId()); + parameters[existsAudioClipMethodSessionIdParamName] + = sessionId->getId().c_str(); + parameters[existsAudioClipMethodAudioClipIdParamName] + = int(id->getId()); if (!xmlRpcClient.execute(existsAudioClipMethodName.c_str(), parameters, result)) { - // throw exception + std::string eMsg = "cannot execute XML-RPC method '"; + eMsg += existsAudioClipMethodName; + eMsg += "'"; + throw std::logic_error(eMsg); } - - logoutFromStorageServer(sessionId); - if (result.getType() != XmlRpcValue::TypeBoolean) { - return false; // change to throw exception + if (xmlRpcClient.isFault() + || result.getType() != XmlRpcValue::TypeBoolean) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << existsAudioClipMethodName + << "' returned error message:\n" + << result; + throw std::logic_error(eMsg.str()); } return bool(result); @@ -510,11 +407,57 @@ WebStorageClient :: existsAudioClip(Ptr::Ref id) const * Return an audio clip. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: getAudioClip(Ptr::Ref id) const - throw (std::invalid_argument) +WebStorageClient :: getAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error) { - Ptr::Ref playlist(new AudioClip); - return playlist; + XmlRpcValue parameters; + XmlRpcValue result; + + XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, + storageServerPath.c_str(), false); + + parameters[getAudioClipMethodSessionIdParamName] + = sessionId->getId().c_str(); + parameters[getAudioClipMethodAudioClipIdParamName] + = int(id->getId()); + + if (!xmlRpcClient.execute(getAudioClipMethodName.c_str(), + parameters, result)) { + std::string eMsg = "cannot execute XML-RPC method '"; + eMsg += getAudioClipMethodName; + eMsg += "'"; + throw std::logic_error(eMsg); + } + + if (xmlRpcClient.isFault() + || result.getType() != XmlRpcValue::TypeString) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << getAudioClipMethodName + << "' returned error message:\n" + << result; + throw std::logic_error(eMsg.str()); + } + + Ptr::Ref xmlAudioClip = decodeString(result); + Ptr::Ref audioClip; + + try { + Ptr::Ref parser(new xmlpp::DomParser()); + parser->parse_memory(*xmlAudioClip); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + audioClip.reset(new AudioClip); + audioClip->configure(*root); + } catch (std::invalid_argument &e) { + throw std::logic_error("semantic error in audio clip metafile"); + } catch (xmlpp::exception &e) { + throw std::logic_error("error parsing audio clip metafile"); + } + + return audioClip; } @@ -522,7 +465,8 @@ WebStorageClient :: getAudioClip(Ptr::Ref id) const * Acquire resources for an audio clip. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: acquireAudioClip(Ptr::Ref id) const +WebStorageClient :: acquireAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const throw (std::logic_error) { Ptr::Ref playlist(new AudioClip); @@ -535,7 +479,8 @@ WebStorageClient :: acquireAudioClip(Ptr::Ref id) const * Release an audio clip. *----------------------------------------------------------------------------*/ void -WebStorageClient :: releaseAudioClip(Ptr::Ref audioClip) const +WebStorageClient :: releaseAudioClip(Ptr::Ref sessionId, + Ptr::Ref audioClip) const throw (std::logic_error) { @@ -546,8 +491,9 @@ WebStorageClient :: releaseAudioClip(Ptr::Ref audioClip) const * Delete an audio clip. *----------------------------------------------------------------------------*/ void -WebStorageClient :: deleteAudioClip(Ptr::Ref id) - throw (std::invalid_argument) +WebStorageClient :: deleteAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error) { } @@ -557,11 +503,69 @@ WebStorageClient :: deleteAudioClip(Ptr::Ref id) * Return a listing of all the audio clips in the audio clip store. *----------------------------------------------------------------------------*/ Ptr::Ref> >::Ref -WebStorageClient :: getAllAudioClips(void) const - throw () +WebStorageClient :: getAllAudioClips(Ptr::Ref sessionId) + const + throw (std::logic_error) { Ptr::Ref> >::Ref audioClipVector( new std::vector::Ref>); return audioClipVector; } + +/*------------------------------------------------------------------------------ + * Convert a hex digit to an int. This is used by decodeString(). + *----------------------------------------------------------------------------*/ +int +WebStorageClient :: hexDigitToChar(const char &hexDigit) const + throw () +{ + 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; + } +} + + +/*------------------------------------------------------------------------------ + * Decode an escaped string. + *----------------------------------------------------------------------------*/ +Ptr::Ref +WebStorageClient :: decodeString(const std::string &inputString) const + throw () +{ + Ptr::Ref outputString(new std::string); + char nextChar; + + 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); + } + + return outputString; +} + diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index bd9e1e963..42de63afc 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.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -47,6 +47,7 @@ #include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/StorageClientInterface.h" +#include "LiveSupport/Core/SessionId.h" namespace LiveSupport { @@ -67,7 +68,7 @@ using namespace LiveSupport::Core; * An interface to the (possibly remote) php storage server. * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class WebStorageClient : virtual public Configurable, @@ -100,41 +101,31 @@ class WebStorageClient : std::string storageServerPath; /** - * The login name to the storage server. + * 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. */ - std::string storageServerLogin; - + Ptr::Ref + decodeString(const std::string &inputString) const + throw (); /** - * The password to the storage server. + * 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. */ - std::string storageServerPassword; - - /** - * Login to the storage server, using the data read from the - * configuration file. If successful, a new session ID is returned. - * - * @return the new session ID - */ - std::string - loginToStorageServer(void) const throw (); - - /** - * Logout from the storage server. The parameter is the ID of - * the session to end (returned previously by storageServerLogin()). - * - * @param sessionId the ID of the session to end - */ - void - logoutFromStorageServer(std::string sessionId) const - throw (); - + int + hexDigitToChar(const char &hexDigit) const + throw (); public: /** * A virtual destructor, as this class has virtual functions. */ virtual - ~WebStorageClient(void) throw () + ~WebStorageClient(void) throw () { } @@ -145,7 +136,7 @@ class WebStorageClient : * @return the name of the expected XML configuration element. */ static const std::string - getConfigElementName(void) throw () + getConfigElementName(void) throw () { return configElementNameStr; } @@ -167,25 +158,31 @@ class WebStorageClient : /** * Tell if a playlist with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to check for. * @return true if a playlist with the specified id exists, * false otherwise. + * @exception std::logic_error if we have not logged in yet. */ virtual const bool - existsPlaylist(Ptr::Ref id) const - throw (); + existsPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Return a playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to return. * @return the requested playlist. - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref - getPlaylist(Ptr::Ref id) const - throw (std::invalid_argument); + getPlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Acquire the resources for the playlist. @@ -195,79 +192,100 @@ class WebStorageClient : * appended to the temp storage path read from the configuration file, * plus a ".smil" extension. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to acquire. * @return a new Playlist instance containing a uri field which * points to an executable (playable) SMIL representation of * the playlist (in the local storage). - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * specified id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref - acquirePlaylist(Ptr::Ref id) const - throw (std::logic_error); + acquirePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Release the resources (audio clips, other playlists) used * in a playlist. The uri of the playlist is no longer valid, and * the uri field is deleted. * + * @param sessionId the session ID from the authentication client * @param playlist the playlist to release. * @exception std::logic_error if the playlist has no uri field, * or the file does not exist, etc. + * @exception std::logic_error if we have not logged in yet. */ virtual void - releasePlaylist(Ptr::Ref playlist) const - throw (std::logic_error); + releasePlaylist(Ptr::Ref sessionId, + Ptr::Ref playlist) const + throw (std::logic_error); /** * Delete the playlist with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the playlist to be deleted. - * @exception std::invalid_argument if no playlist with the specified + * @exception std::logic_error if no playlist with the specified * id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual void - deletePlaylist(Ptr::Ref id) - throw (std::invalid_argument); + deletePlaylist(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error); /** * Return a list of all playlists in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the playlists. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref> >::Ref - getAllPlaylists(void) const throw (); + getAllPlaylists(Ptr::Ref sessionId) const + throw (std::logic_error); /** * Create a new playlist. * + * @param sessionId the session ID from the authentication client * @return the newly created playlist. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref - createPlaylist() throw (); + createPlaylist(Ptr::Ref sessionId) + throw (std::logic_error); /** * Tell if an audio clip with a given id exists. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to check for. * @return true if an audio clip with the specified id exists, * false otherwise. + * @exception std::logic_error if we have not logged in yet */ virtual const bool - existsAudioClip(Ptr::Ref id) const - throw (); + existsAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Return an audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to return. * @return the requested audio clip. - * @exception std::invalid_argument if no audio clip with the + * @exception std::logic_error if no audio clip with the * specified id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref - getAudioClip(Ptr::Ref id) const - throw (std::invalid_argument); + getAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Acquire the resources for the audio clip with the specified id. @@ -275,47 +293,59 @@ class WebStorageClient : * Returns an AudioClip instance with a valid uri field, which points * to the binary sound file. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to acquire. * @return a new AudioClip instance, containing a uri field which * points to (a way of getting) the sound file. - * @exception std::invalid_argument if no audio clip with the - * specified id exists. + * @exception std::logic_error if no audio clip with the + * specified id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref - acquireAudioClip(Ptr::Ref id) const - throw (std::logic_error); + acquireAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) const + throw (std::logic_error); /** * Release the resource (sound file) used by an audio clip. The * uri of the audio clip is no longer valid, and the uri field is * deleted. * - * @param id the id of the audio clip to release. + * @param sessionId the session ID from the authentication client + * @param audioClip the audio clip to release. * @exception std::logic_error if the audio clip has no uri field, - * or the file does not exist, etc. + * or the file does not exist, etc. + * @exception std::logic_error if we have not logged in yet. */ virtual void - releaseAudioClip(Ptr::Ref audioClip) const - throw (std::logic_error); + releaseAudioClip(Ptr::Ref sessionId, + Ptr::Ref audioClip) const + throw (std::logic_error); /** * Delete the audio clip with the specified id. * + * @param sessionId the session ID from the authentication client * @param id the id of the audio clip to be deleted. - * @exception std::invalid_argument if no audio clip with the + * @exception std::logic_error if no audio clip with the * specified id exists. + * @exception std::logic_error if we have not logged in yet. */ virtual void - deleteAudioClip(Ptr::Ref id) - throw (std::invalid_argument); + deleteAudioClip(Ptr::Ref sessionId, + Ptr::Ref id) + throw (std::logic_error); /** * Return a list of all audio clips in the playlist store. * + * @param sessionId the session ID from the authentication client * @return a vector containing the audio clips. + * @exception std::logic_error if we have not logged in yet. */ virtual Ptr::Ref> >::Ref - getAllAudioClips(void) const throw (); + getAllAudioClips(Ptr::Ref sessionId) const + throw (std::logic_error); }; diff --git a/livesupport/modules/storage/src/WebStorageClientTest.cxx b/livesupport/modules/storage/src/WebStorageClientTest.cxx index 6cda8f36f..b793757ac 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.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -45,11 +45,13 @@ #include #include "WebStorageClient.h" -#include "WebStorageClientTest.h" +#include "LiveSupport/Core/SessionId.h" +#include "WebStorageClientTest.h" using namespace std; using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; using namespace LiveSupport::Storage; /* =================================================== local data structures */ @@ -60,9 +62,15 @@ using namespace LiveSupport::Storage; CPPUNIT_TEST_SUITE_REGISTRATION(WebStorageClientTest); /** - * The name of the configuration file for the storage client factory daemon. + * The name of the configuration file for the web storage client. */ -static const std::string configFileName = "etc/webStorage.xml"; +static const std::string storageConfigFileName = "etc/webStorage.xml"; + +/** + * The name of the configuration file for the authentication factory. + */ +static const std::string authenticationFactoryConfigFileName + = "etc/authenticationClient.xml"; /* =============================================== local function prototypes */ @@ -76,18 +84,35 @@ static const std::string configFileName = "etc/webStorage.xml"; void WebStorageClientTest :: setUp(void) throw () { + Ptr::Ref acf; + acf = AuthenticationClientFactory::getInstance(); try { Ptr::Ref parser( - new xmlpp::DomParser(configFileName, true)); + new xmlpp::DomParser(authenticationFactoryConfigFileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + acf->configure(*root); + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in authentication configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing authentication configuration file"); + } + + authentication = acf->getAuthenticationClient(); + + try { + Ptr::Ref parser( + new xmlpp::DomParser(storageConfigFileName, true)); const xmlpp::Document * document = parser->get_document(); const xmlpp::Element * root = document->get_root_node(); wsc.reset(new WebStorageClient()); wsc->configure(*root); } catch (std::invalid_argument &e) { - CPPUNIT_FAIL("semantic error in configuration file"); + CPPUNIT_FAIL("semantic error in storage configuration file"); } catch (xmlpp::exception &e) { - CPPUNIT_FAIL("error parsing configuration file"); + CPPUNIT_FAIL("error parsing storage configuration file"); } } @@ -98,6 +123,7 @@ WebStorageClientTest :: setUp(void) throw () void WebStorageClientTest :: tearDown(void) throw () { + authentication.reset(); wsc.reset(); } @@ -109,68 +135,20 @@ void WebStorageClientTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id01(new UniqueId(10001)); - Ptr::Ref id77(new UniqueId(10077)); + Ptr::Ref id77(new UniqueId(10077)); + Ptr::Ref sessionId(new SessionId("bad ID")); - CPPUNIT_ASSERT( wsc->existsAudioClip(id01)); - CPPUNIT_ASSERT(!wsc->existsAudioClip(id77)); -} +// this does not currently work due to a bug in the storage server +// try { +// wsc->existsAudioClip(sessionId, id77); +// CPPUNIT_FAIL("existsAudioClip allowed operation without login"); +// } +// catch (std::logic_error &e) { +// } - -/*------------------------------------------------------------------------------ - * Testing the deletePlaylist method - *----------------------------------------------------------------------------*/ -void -WebStorageClientTest :: deletePlaylistTest(void) - throw (CPPUNIT_NS::Exception) -{ - Ptr::Ref id1(new UniqueId(1)); - Ptr::Ref id2(new UniqueId(77)); - - try { - wsc->deletePlaylist(id2); - CPPUNIT_FAIL("allowed to delete non-existent playlist"); - } catch (std::invalid_argument &e) { - } - try { - wsc->deletePlaylist(id1); - } catch (std::invalid_argument &e) { - CPPUNIT_FAIL("cannot delete existing playlist"); - } - try { - wsc->deletePlaylist(id1); - CPPUNIT_FAIL("allowed to delete non-existent playlist"); - } catch (std::invalid_argument &e) { - } -} - - -/*------------------------------------------------------------------------------ - * Testing the getAllPlaylists method - *----------------------------------------------------------------------------*/ -void -WebStorageClientTest :: getAllPlaylistsTest(void) - throw (CPPUNIT_NS::Exception) -{ - Ptr::Ref> >::Ref playlistVector = - wsc->getAllPlaylists(); - CPPUNIT_ASSERT(playlistVector->size() == 1); - - Ptr::Ref playlist = (*playlistVector)[0]; - CPPUNIT_ASSERT((int) (playlist->getId()->getId()) == 1); -} - - -/*------------------------------------------------------------------------------ - * Testing the createPlaylist method - *----------------------------------------------------------------------------*/ -void -WebStorageClientTest :: createPlaylistTest(void) - throw (CPPUNIT_NS::Exception) -{ - Ptr::Ref playlist = wsc->createPlaylist(); - - CPPUNIT_ASSERT(wsc->existsPlaylist(playlist->getId())); + CPPUNIT_ASSERT( sessionId = authentication->login("root", "q")); + CPPUNIT_ASSERT(!wsc->existsAudioClip(sessionId, id77)); + CPPUNIT_ASSERT( authentication->logout(sessionId)); } @@ -181,8 +159,19 @@ void WebStorageClientTest :: audioClipTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref id2(new UniqueId(10002)); - Ptr::Ref id77(new UniqueId(10077)); +/* + Ptr::Ref id01(new UniqueId(10001)); + Ptr::Ref id77(new UniqueId(10077)); + Ptr::Ref sessionId; + + CPPUNIT_ASSERT( sessionId = authentication->login("root", "q")); +//cerr << "###\n" << sessionId << "\n" << sessionId->getId() << endl; + + CPPUNIT_ASSERT( wsc->existsAudioClip(sessionId, id01)); + +//std::cerr << "\naudio clip: <<<\n" << audioClip->getId()->getId() << ">>>\n"; + + CPPUNIT_ASSERT( authentication->logout(sessionId)); CPPUNIT_ASSERT(wsc->existsAudioClip(id2)); CPPUNIT_ASSERT(!wsc->existsAudioClip(id77)); @@ -201,101 +190,6 @@ WebStorageClientTest :: audioClipTest(void) wsc->deleteAudioClip(id2); CPPUNIT_ASSERT(!wsc->existsAudioClip(id2)); +*/ } - -/*------------------------------------------------------------------------------ - * Testing the acquire / release operations - *----------------------------------------------------------------------------*/ -void -WebStorageClientTest :: acquireAudioClipTest(void) - throw (CPPUNIT_NS::Exception) -{ - Ptr::Ref id2(new UniqueId(10002)); - Ptr::Ref id77(new UniqueId(10077)); - Ptr::Ref audioClip; - - try { - audioClip = wsc->acquireAudioClip(id2); - } - catch (std::logic_error &e) { - std::string eMsg = "could not acquire audio clip:\n"; - eMsg += e.what(); - CPPUNIT_FAIL(eMsg); - } - string audioClipUri("file://"); - audioClipUri += get_current_dir_name(); - audioClipUri += "/var/test2.mp3"; - CPPUNIT_ASSERT(*(audioClip->getUri()) == audioClipUri); - - try { - wsc->releaseAudioClip(audioClip); - } - catch (std::logic_error &e) { - std::string eMsg = "could not release audio clip:\n"; - eMsg += e.what(); - CPPUNIT_FAIL(eMsg); - } - - try { - audioClip = wsc->acquireAudioClip(id77); - CPPUNIT_FAIL("allowed to acquire non-existent audio clip"); - } - catch (std::logic_error &e) { - } -} - - -/*------------------------------------------------------------------------------ - * Testing the acquire / release operations - *----------------------------------------------------------------------------*/ -void -WebStorageClientTest :: acquirePlaylistTest(void) - throw (CPPUNIT_NS::Exception) -{ - Ptr::Ref id1(new UniqueId(1)); - Ptr::Ref id77(new UniqueId(77)); - Ptr::Ref playlist; - - try { - playlist = wsc->acquirePlaylist(id1); - } - catch (std::logic_error &e) { - std::string eMsg = "could not acquire playlist:\n"; - eMsg += e.what(); - CPPUNIT_FAIL(eMsg); - } - CPPUNIT_ASSERT(playlist->getUri()); - CPPUNIT_ASSERT(playlist->getUri()->substr(0,7) == "file://"); - - std::ifstream ifs1(playlist->getUri()->substr(7).c_str()); - if (!ifs1) { - ifs1.close(); - CPPUNIT_FAIL("temp file not created correctly"); - } - ifs1.close(); - - string savedTempFilePath = playlist->getUri()->substr(7); - try { - wsc->releasePlaylist(playlist); - } - catch (std::logic_error &e) { - std::string eMsg = "could not release playlist:\n"; - eMsg += e.what(); - CPPUNIT_FAIL(eMsg); - } - CPPUNIT_ASSERT(!playlist->getUri()); - std::ifstream ifs2(savedTempFilePath.c_str()); - if (ifs2) { - ifs2.close(); - CPPUNIT_FAIL("temp file not destroyed correctly"); - } - ifs2.close(); - - try { - playlist = wsc->acquirePlaylist(id77); - CPPUNIT_FAIL("allowed to acquire non-existent playlist"); - } - catch (std::logic_error &e) { - } -} diff --git a/livesupport/modules/storage/src/WebStorageClientTest.h b/livesupport/modules/storage/src/WebStorageClientTest.h index d74ab2a3f..c5fc76083 100644 --- a/livesupport/modules/storage/src/WebStorageClientTest.h +++ b/livesupport/modules/storage/src/WebStorageClientTest.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.h,v $ ------------------------------------------------------------------------------*/ @@ -42,10 +42,14 @@ #include +#include "LiveSupport/Core/AuthenticationClientInterface.h" +#include "LiveSupport/Authentication/AuthenticationClientFactory.h" namespace LiveSupport { namespace Storage { +using namespace LiveSupport::Core; + /* ================================================================ constants */ @@ -58,26 +62,26 @@ namespace Storage { * Unit test for the UploadPlaylistMetohd class. * * @author $Author: fgerlits $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * @see WebStorageClient */ class WebStorageClientTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(WebStorageClientTest); CPPUNIT_TEST(firstTest); -// CPPUNIT_TEST(getAllPlaylistsTest); -// CPPUNIT_TEST(deletePlaylistTest); -// CPPUNIT_TEST(createPlaylistTest); -// CPPUNIT_TEST(audioClipTest); -// CPPUNIT_TEST(acquireAudioClipTest); -// CPPUNIT_TEST(acquirePlaylistTest); + CPPUNIT_TEST(audioClipTest); CPPUNIT_TEST_SUITE_END(); private: + /** + * An AuthenticationClient instance to login an logout. + */ + Ptr::Ref authentication; + /** * The WebStorageClient instance to test. */ - Ptr::Ref wsc; + Ptr::Ref wsc; protected: @@ -89,30 +93,6 @@ class WebStorageClientTest : public CPPUNIT_NS::TestFixture void firstTest(void) throw (CPPUNIT_NS::Exception); - /** - * Testing deletePlaylist(). - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - deletePlaylistTest(void) - throw (CPPUNIT_NS::Exception); - /** - * Testing getAllPlaylists(). - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - getAllPlaylistsTest(void) - throw (CPPUNIT_NS::Exception); - /** - * Testing createPlaylist(). - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - createPlaylistTest(void) throw (CPPUNIT_NS::Exception); - /** * Testing the audio clip operations. * @@ -121,22 +101,6 @@ class WebStorageClientTest : public CPPUNIT_NS::TestFixture void audioClipTest(void) throw (CPPUNIT_NS::Exception); - /** - * Testing the acquire / release operations on audio clips. - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - acquireAudioClipTest(void) throw (CPPUNIT_NS::Exception); - - /** - * Testing the acquire / release operations on playlists. - * - * @exception CPPUNIT_NS::Exception on test failures. - */ - void - acquirePlaylistTest(void) throw (CPPUNIT_NS::Exception); - public: