added storageAdmin module to doxygen config file;

added playlength format checking in AudioClip and Playlist in the Core
module so it won't crash just throw an exception;
added try-catch block in Storage::getAudioClip() and getPlaylist() to catch
invalid audio clip or playlist format errors
This commit is contained in:
fgerlits 2005-06-27 19:26:41 +00:00
parent d4557842f6
commit 40ffad79dd
10 changed files with 266 additions and 52 deletions

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.12 $
# Version : $Revision: 1.13 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/etc/doxygen.config,v $
#-------------------------------------------------------------------------------
@ -433,12 +433,13 @@ INPUT = modules/core/include modules/core/src \
modules/widgets/src \
products/scheduler/src \
products/gLiveSupport/src \
modules/storageServer/var \
modules/storageServer/var/xmlrpc \
modules/alib/var \
modules/alib/var/xmlrpc \
modules/getid3/var \
modules/archiveServer/var
modules/archiveServer/var \
modules/storageServer/var \
modules/storageServer/var/xmlrpc \
modules/storageAdmin/var
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.26 $
Version : $Revision: 1.27 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $
------------------------------------------------------------------------------*/
@ -131,7 +131,7 @@ using namespace boost::posix_time;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.26 $
* @version $Revision: 1.27 $
*/
class AudioClip : public Configurable,
public Playable
@ -178,11 +178,13 @@ class AudioClip : public Configurable,
* @param value the new value of the metadata field.
* @param name the name of the metadata field (without prefix)
* @param prefix the prefix of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw ();
throw (std::invalid_argument);
/**
* Convert a time_duration to string, in format HH:MM:SS.ssssss.
@ -197,6 +199,17 @@ class AudioClip : public Configurable,
}
}
/**
* Set the playlength member of this audio clip.
*
* @param timeString the new playlength
* @exception std::invalid_argument if the argument is not
* a valid ISO-8601 time
*/
void
setPlaylength(const std::string & timeString)
throw (std::invalid_argument);
public:
/**
@ -496,11 +509,13 @@ class AudioClip : public Configurable,
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw ();
throw (std::invalid_argument);
/**
@ -589,7 +604,7 @@ class AudioClip : public Configurable,
/**
* Auxilliary method used by satisfiesCondition().
* Auxilliary method used by setMetadata() and getMetadata().
*/
void
separateNameAndNameSpace(const std::string & key,

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.10 $
Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playable.h,v $
------------------------------------------------------------------------------*/
@ -73,7 +73,7 @@ using namespace boost::posix_time;
* It contains the methods which are common to these classes.
*
* @author $Author: fgerlits $
* @version $Revision: 1.10 $
* @version $Revision: 1.11 $
*/
class Playable : public boost::enable_shared_from_this<Playable>
{
@ -208,11 +208,14 @@ class Playable : public boost::enable_shared_from_this<Playable>
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw () = 0;
throw (std::invalid_argument)
= 0;
/**
* Return a partial XML representation of this audio clip or playlist.

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.35 $
Version : $Revision: 1.36 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $
------------------------------------------------------------------------------*/
@ -128,7 +128,7 @@ using namespace boost::posix_time;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.35 $
* @version $Revision: 1.36 $
*/
class Playlist : public Configurable,
public Playable
@ -204,21 +204,34 @@ class Playlist : public Configurable,
* @param value the new value of the metadata field.
* @param name the name of the metadata field (without prefix)
* @param prefix the prefix of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw ();
throw (std::invalid_argument);
/**
* Set the total playing length of this playlist.
*
* @param the playing length in microseconds precision.
* @param playlength the playing length in microseconds precision.
*/
void
setPlaylength(Ptr<time_duration>::Ref playlength)
throw ();
/**
* Set the playlength member of this audio clip.
*
* @param timeString the playing length in microseconds precision.
* @exception std::invalid_argument if the argument is not
* a valid ISO-8601 time
*/
void
setPlaylength(const std::string & timeString)
throw (std::invalid_argument);
/**
* A private iterator type for internal use. It is non-constant;
* otherwise it is the same as Playlist::const_iterator.
@ -679,11 +692,13 @@ class Playlist : public Configurable,
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw ();
throw (std::invalid_argument);
/**

View File

@ -0,0 +1,121 @@
/*------------------------------------------------------------------------------
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/core/include/LiveSupport/Core/XmlRpcInvalidDataException.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcInvalidDataException_h
#define LiveSupport_Core_XmlRpcInvalidDataException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: invalid data returned by the method.
* This could be a malformed AudioClip or Playlist, for example.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class XmlRpcInvalidDataException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcInvalidDataException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcInvalidDataException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcInvalidDataException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcInvalidDataException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcInvalidDataException_h

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.29 $
Version : $Revision: 1.30 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $
------------------------------------------------------------------------------*/
@ -215,7 +215,8 @@ AudioClip :: AudioClip(Ptr<UniqueId>::Ref id,
/*------------------------------------------------------------------------------
* Constructor without ID.
*----------------------------------------------------------------------------*/AudioClip :: AudioClip(Ptr<const Glib::ustring>::Ref title,
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ()
@ -280,6 +281,30 @@ AudioClip :: setTitle(Ptr<const Glib::ustring>::Ref title)
}
/*------------------------------------------------------------------------------
* Set the value of the playlength from a string (private).
*----------------------------------------------------------------------------*/
void
AudioClip :: setPlaylength(const std::string & timeString)
throw (std::invalid_argument)
{
try {
playlength.reset(new time_duration(duration_from_string(timeString)));
} catch (boost::bad_lexical_cast &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch (std::exception &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch ( ... ) {
std::string eMsg = "bad time format in playlength";
throw std::invalid_argument(eMsg);
}
}
/*------------------------------------------------------------------------------
* Create an audio clip object based on an XML element.
*----------------------------------------------------------------------------*/
@ -306,8 +331,6 @@ AudioClip :: configure(const xmlpp::Element & element)
if (!playlength
&& (attribute = element.get_attribute(playlengthAttrName))) {
playlength.reset(new time_duration(duration_from_string(
attribute->get_value() )));
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
attribute->get_value() ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
@ -357,8 +380,7 @@ AudioClip :: configure(const xmlpp::Element & element)
if (!playlength && prefix == extentElementPrefix
&& name == extentElementName) {
if (dataElement->has_child_text()) {
playlength.reset(new time_duration(duration_from_string(
dataElement->get_child_text()->get_content() )));
setPlaylength(dataElement->get_child_text()->get_content());
} else { // or just leave blank? bad either way
playlength.reset(new time_duration(0,0,0,0));
}
@ -457,7 +479,7 @@ AudioClip :: getMetadata(const string &key) const
void
AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw ()
throw (std::invalid_argument)
{
std::string name, prefix;
separateNameAndNameSpace(key, name, prefix);
@ -471,11 +493,10 @@ AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
void
AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw ()
throw (std::invalid_argument)
{
if (prefix == extentElementPrefix && name == extentElementName) {
playlength.reset(new time_duration(
duration_from_string(*value) ));
setPlaylength(*value); // may throw invalid_argument
}
if (prefix == titleElementPrefix && name == titleElementName) {

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.35 $
Version : $Revision: 1.36 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
------------------------------------------------------------------------------*/
@ -274,6 +274,30 @@ Playlist :: setPlaylength(Ptr<time_duration>::Ref playlength)
}
/*------------------------------------------------------------------------------
* Set the value of the playlength from a string (private).
*----------------------------------------------------------------------------*/
void
Playlist :: setPlaylength(const std::string & timeString)
throw (std::invalid_argument)
{
try {
playlength.reset(new time_duration(duration_from_string(timeString)));
} catch (boost::bad_lexical_cast &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch (std::exception &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch ( ... ) {
std::string eMsg = "bad time format in playlength";
throw std::invalid_argument(eMsg);
}
}
/*------------------------------------------------------------------------------
* Create a playlist object based on an XML element.
*----------------------------------------------------------------------------*/
@ -300,8 +324,6 @@ Playlist :: configure(const xmlpp::Element & element)
if (!playlength
&& (attribute = element.get_attribute(playlengthAttrName))) {
playlength.reset(new time_duration(
duration_from_string(attribute->get_value())));
Ptr<Glib::ustring>::Ref playlengthString(new Glib::ustring(
attribute->get_value() ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
@ -358,8 +380,7 @@ Playlist :: configure(const xmlpp::Element & element)
if (!playlength && prefix == extentElementPrefix
&& name == extentElementName) {
if (dataElement->has_child_text()) {
playlength.reset(new time_duration(duration_from_string(
dataElement->get_child_text()->get_content() )));
setPlaylength(dataElement->get_child_text()->get_content());
} else { // or just leave blank? bad either way
playlength.reset(new time_duration(0,0,0,0));
}
@ -641,7 +662,7 @@ Playlist :: getMetadata(const string &key) const
void
Playlist :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw ()
throw (std::invalid_argument)
{
std::string name, prefix;
separateNameAndNameSpace(key, name, prefix);
@ -655,11 +676,10 @@ Playlist :: setMetadata(Ptr<const Glib::ustring>::Ref value,
void
Playlist :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw ()
throw (std::invalid_argument)
{
if (prefix == extentElementPrefix && name == extentElementName) {
playlength.reset(new time_duration(
duration_from_string(*value) ));
setPlaylength(*value);
}
if (prefix == titleElementPrefix && name == titleElementName) {

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.42 $
Version : $Revision: 1.43 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/
@ -54,6 +54,7 @@
#include "LiveSupport/Core/XmlRpcMethodResponseException.h"
#include "LiveSupport/Core/XmlRpcInvalidArgumentException.h"
#include "LiveSupport/Core/XmlRpcIOException.h"
#include "LiveSupport/Core/XmlRpcInvalidDataException.h"
#include "WebStorageClient.h"
using namespace boost::posix_time;
@ -914,10 +915,10 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
playlist->configure(*root);
} catch (std::invalid_argument &e) {
throw XmlRpcMethodResponseException(
throw XmlRpcInvalidDataException(
"semantic error in playlist metafile");
} catch (xmlpp::exception &e) {
throw XmlRpcMethodResponseException(
throw XmlRpcInvalidDataException(
"error parsing playlist metafile");
}
@ -1410,11 +1411,11 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
} catch (std::invalid_argument &e) {
std::string eMsg = "semantic error in audio clip metafile:\n";
eMsg += e.what();
throw XmlRpcMethodResponseException(eMsg);
throw XmlRpcInvalidDataException(eMsg);
} catch (xmlpp::exception &e) {
std::string eMsg = "error parsing audio clip metafile";
eMsg += e.what();
throw XmlRpcMethodResponseException(eMsg);
throw XmlRpcInvalidDataException(eMsg);
}
parameters.clear();

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.29 $
Version : $Revision: 1.30 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
------------------------------------------------------------------------------*/
@ -96,7 +96,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.29 $
* @version $Revision: 1.30 $
*/
class WebStorageClient :
virtual public Configurable,
@ -258,9 +258,10 @@ class WebStorageClient :
* @param sessionId the session ID from the authentication client
* @param id the id of the playlist to return.
* @return the requested playlist.
* @exception XmlRpcInvalidDataException if the audio clip we got
* from the storage is invalid.
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified
* id exists.
* call or no playlist with the specified id exists.
*/
virtual Ptr<Playlist>::Ref
getPlaylist(Ptr<SessionId>::Ref sessionId,
@ -379,9 +380,10 @@ class WebStorageClient :
* @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 XmlRpcInvalidDataException if the audio clip we got
* from the storage is invalid.
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no audio clip with the
* specified id exists.
* call or no audio clip with the specified id exists.
*/
virtual Ptr<AudioClip>::Ref
getAudioClip(Ptr<SessionId>::Ref sessionId,

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.51 $
Version : $Revision: 1.52 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/
@ -42,6 +42,7 @@
#include "LiveSupport/SchedulerClient/SchedulerClientFactory.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/XmlRpcInvalidDataException.h"
#include "MasterPanelWindow.h"
#include "GLiveSupport.h"
@ -1029,13 +1030,27 @@ GLiveSupport :: search(Ptr<SearchCriteria>::Ref criteria)
audioClipIds = storage->getAudioClipIds();
std::vector<Ptr<UniqueId>::Ref>::const_iterator it;
for (it = audioClipIds->begin(); it != audioClipIds->end(); ++it) {
results->push_back(storage->getAudioClip(sessionId, *it));
try {
Ptr<AudioClip>::Ref audioClip
= storage->getAudioClip(sessionId, *it);
results->push_back(audioClip);
} catch (XmlRpcInvalidDataException &e) {
std::cerr << "invalid audio clip in search(): " << e.what()
<< std::endl;
}
}
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref
playlistIds = storage->getPlaylistIds();
for (it = playlistIds->begin(); it != playlistIds->end(); ++it) {
results->push_back(storage->getPlaylist(sessionId, *it));
try {
Ptr<Playlist>::Ref playlist
= storage->getPlaylist(sessionId, *it);
results->push_back(playlist);
} catch (XmlRpcInvalidDataException &e) {
std::cerr << "invalid playlist in search(): " << e.what()
<< std::endl;
}
}
return results;