From: tho Date: Thu, 19 May 2011 09:31:33 +0000 (+0000) Subject: Packets/80221Bundle: fixed message validation X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=7db21ff4de83edddec7084c5f121a10321b5a42f;p=senf.git Packets/80221Bundle: fixed message validation Utils/Console: made SysInfo::dump() public git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1789 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80221Bundle/Exceptions.hh b/senf/Packets/80221Bundle/Exceptions.hh new file mode 100644 index 0000000..185c146 --- /dev/null +++ b/senf/Packets/80221Bundle/Exceptions.hh @@ -0,0 +1,60 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// This program 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. +// +// This program 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 this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HH_SENF_Packets_80221Bundle_Exceptions_ +#define HH_SENF_Packets_80221Bundle_Exceptions_ 1 + +// Custom includes + +//-///////////////////////////////////////////////////////////////////////////////////////////////// + +namespace senf { + + struct MIHTLVLengthException : public senf::Exception + { + MIHTLVLengthException() + : senf::Exception("MIHTLVLengthException") {} + }; + + struct InvalidMIHPacketException : public senf::Exception + { + InvalidMIHPacketException(std::string const & description) + : senf::Exception("Invalid MIH message: ") { append(description); } + }; +} + +//-///////////////////////////////////////////////////////////////////////////////////////////////// +//#include "Exceptions.cci" +//#include "Exceptions.ct" +//#include "Exceptions.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: diff --git a/senf/Packets/80221Bundle/MIHMessageRegistry.ct b/senf/Packets/80221Bundle/MIHMessageRegistry.ct index 4acf800..0aa2ba2 100644 --- a/senf/Packets/80221Bundle/MIHMessageRegistry.ct +++ b/senf/Packets/80221Bundle/MIHMessageRegistry.ct @@ -24,6 +24,7 @@ \brief MIH Message-Registry non-inline template implementation */ // Custom includes +#include "Exceptions.hh" #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -42,6 +43,16 @@ prefix_ senf::MIHMessageRegistry::RegistrationProxy::RegistrationProx MIHMessageRegistry::instance().registerMessageType(); } +template +prefix_ void senf::detail::MIHMessageRegistryEntry::validate(senf::Packet message) + const +{ + if (! message.is()) + throw InvalidMIHPacketException("invalid packet chain"); + MIHPacket::type::validate(message.as()); +} + + //-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/80221Bundle/MIHMessageRegistry.hh b/senf/Packets/80221Bundle/MIHMessageRegistry.hh index 4daabb7..268d890 100644 --- a/senf/Packets/80221Bundle/MIHMessageRegistry.hh +++ b/senf/Packets/80221Bundle/MIHMessageRegistry.hh @@ -31,50 +31,10 @@ #include #include -//#include "MIHMessageRegistry.mpp" +#include "MIHMessageRegistry.ih" //-///////////////////////////////////////////////////////////////////////////////////////////////// - namespace senf { - namespace detail { - - template - struct has_static_validate_member - { - template - struct helper; - - template - static char test(helper<&U::validate> *); - - template - static char (&test(...))[2]; - - static const bool value = sizeof(test(0))==1; - }; - - struct MIHMessageRegistry_EntryBase { - virtual ~MIHMessageRegistry_EntryBase() {} - virtual void validate(senf::Packet message) const = 0; - }; - - template ::value> - struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase - { - virtual void validate(senf::Packet message) const {} - }; - - template - struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase - { - virtual void validate(senf::Packet message) const { - MIHPacket::type::validate(message.as()); - } - }; - } - - class MIHMessageRegistry : public senf::singleton { diff --git a/senf/Packets/80221Bundle/MIHMessageRegistry.ih b/senf/Packets/80221Bundle/MIHMessageRegistry.ih new file mode 100644 index 0000000..e785f50 --- /dev/null +++ b/senf/Packets/80221Bundle/MIHMessageRegistry.ih @@ -0,0 +1,86 @@ +// $Id$ +// +// Copyright (C) 2010 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// This program 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. +// +// This program 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 this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief MIH Message-Registry internal header */ + +#ifndef IH_SENF_Packets_80221Bundle_MIHMessageRegistry_ +#define IH_SENF_Packets_80221Bundle_MIHMessageRegistry_ 1 + +// Custom includes + +//-///////////////////////////////////////////////////////////////////////////////////////////////// +namespace senf { + + namespace detail { + + template + struct has_static_validate_member + { + template + struct helper; + + template + static char test(helper<&U::validate> *); + + template + static char (&test(...))[2]; + + static const bool value = sizeof(test(0))==1; + }; + + + struct MIHMessageRegistry_EntryBase { + virtual ~MIHMessageRegistry_EntryBase() {} + virtual void validate(senf::Packet message) const = 0; + }; + + + template ::value> + struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase + { + virtual void validate(senf::Packet message) const {} + }; + + template + struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase + { + virtual void validate(senf::Packet message) const; + }; + + } +} +//-///////////////////////////////////////////////////////////////////////////////////////////////// +#endif + + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: diff --git a/senf/Packets/80221Bundle/TLVParser.cc b/senf/Packets/80221Bundle/TLVParser.cc index 729b1ec..7e6b8f2 100644 --- a/senf/Packets/80221Bundle/TLVParser.cc +++ b/senf/Packets/80221Bundle/TLVParser.cc @@ -29,6 +29,7 @@ // Custom includes #include #include +#include "Exceptions.hh" #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/senf/Packets/80221Bundle/TLVParser.hh b/senf/Packets/80221Bundle/TLVParser.hh index 0fd0a71..0a466c6 100644 --- a/senf/Packets/80221Bundle/TLVParser.hh +++ b/senf/Packets/80221Bundle/TLVParser.hh @@ -35,19 +35,6 @@ namespace senf { - struct MIHTLVLengthException : public senf::Exception - { - MIHTLVLengthException() - : senf::Exception("MIHTLVLengthException") {} - }; - - struct InvalidMIHPacketException : public senf::Exception - { - InvalidMIHPacketException(std::string const & description) - : senf::Exception("Invalid MIH message: ") { append(description); } - }; - - class MIHTLVLengthParser : public detail::packet::IntParserOps, public PacketParserBase diff --git a/senf/Packets/80221Bundle/TLVParser.test.cc b/senf/Packets/80221Bundle/TLVParser.test.cc index 81e7831..4d637d0 100644 --- a/senf/Packets/80221Bundle/TLVParser.test.cc +++ b/senf/Packets/80221Bundle/TLVParser.test.cc @@ -27,8 +27,9 @@ //#include "TLVParser.test.ih" // Custom includes -#include "TLVParser.hh" #include +#include "TLVParser.hh" +#include "Exceptions.hh" #include #include diff --git a/senf/Utils/Console/Server.cc b/senf/Utils/Console/Server.cc index e39a44f..6c53f27 100644 --- a/senf/Utils/Console/Server.cc +++ b/senf/Utils/Console/Server.cc @@ -51,7 +51,7 @@ namespace { senf::console::SysInfo::Proxy addSysInfo ( "SENF: The Simple and Extensible Network Framework\n" - " © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research\n" + " © 2006-2011 Fraunhofer Institute for Open Communication Systems, Network Research\n" " Contact: senf-dev@lists.berlios.de\n" " Version: " SENF_LIB_VERSION " Revision number: " SENF_REVISION "\n" " Build-type: " BUILD_TYPE ", SenfLog compile time limit: " + diff --git a/senf/Utils/Console/SysInfo.hh b/senf/Utils/Console/SysInfo.hh index 75dc01e..d955c1b 100644 --- a/senf/Utils/Console/SysInfo.hh +++ b/senf/Utils/Console/SysInfo.hh @@ -38,8 +38,11 @@ namespace console { : public singleton { public: + friend class singleton; using singleton::instance; + void addEntry(std::string const & descr, unsigned pos=-1); + void dump(std::ostream & os) const; struct Proxy { Proxy(std::string const & descr, unsigned pos=-1); @@ -49,9 +52,6 @@ namespace console { std::list descr_; SysInfo(); - void dump(std::ostream & os) const; - - friend class singleton; }; }}