From: g0dil Date: Fri, 29 Jan 2010 21:43:48 +0000 (+0000) Subject: Packets: Add packet validity checks to ListBParser_Policy constructor X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=6019c18e7b74d3e91293f35df660a80346ef7a1e;p=senf.git Packets: Add packet validity checks to ListBParser_Policy constructor git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1557 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/ListBParser.ct b/senf/Packets/ListBParser.ct new file mode 100644 index 0000000..880aa92 --- /dev/null +++ b/senf/Packets/ListBParser.ct @@ -0,0 +1,69 @@ +// $Id$ +// +// Copyright (C) 2010 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// 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 ListBParser non-inline template implementation */ + +#include "ListBParser.ih" + +// Custom includes + +#define prefix_ +///////////////////////////////ct.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::detail::ListBParser_Policy::container_policy + +template +prefix_ +senf::detail::ListBParser_Policy::container_policy:: +container_policy(parser_policy const & p) + : AuxPolicy (p) +{ + parser_type selfp (parser_type::get(p)); + size_type totalsz (selfp.bytes()); + data_iterator const e (selfp.i(totalsz)); + data_iterator i (AuxPolicy::adjust(selfp.i(), selfp.state())); + n_ = 0; + while (i!=e) { + ElementParser p (i,selfp.state()); + size_type sz (senf::bytes(p)); + SENF_ASSERT(sz); + i = p.i(sz); + ++ n_; + } + container_size_ = selfp.data().size(); +} + +///////////////////////////////ct.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/senf/Packets/ListBParser.cti b/senf/Packets/ListBParser.cti index 7358fad..80a4914 100644 --- a/senf/Packets/ListBParser.cti +++ b/senf/Packets/ListBParser.cti @@ -74,19 +74,6 @@ prefix_ void senf::detail::ListBParser_Policy::init(dat // senf::detail::ListBParser_Policy template -prefix_ -senf::detail::ListBParser_Policy::container_policy:: -container_policy(parser_policy const & p) - : AuxPolicy (p) -{ - data_iterator const e (boost::next(parser_type::get(p).i(),parser_type::get(p).bytes())); - data_iterator i (AuxPolicy::adjust(parser_type::get(p).i(), parser_type::get(p).state())); - for( n_=0; i!=e; - ++n_, std::advance(i,senf::bytes(ElementParser(i,parser_type::get(p).state())))) ; - container_size_ = parser_type::get(p).data().size(); -} - -template prefix_ typename senf::detail::ListBParser_Policy::container_policy::size_type senf::detail::ListBParser_Policy::container_policy::bytes(data_iterator i, state_type s) @@ -157,10 +144,14 @@ update(container_type const & c) { if (container_size_ == c.data().size()) return; +#if 1 data_iterator i (AuxPolicy::adjust(c.i(), c.state())); data_iterator j (i); for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ; aux( std::distance(i,j), c.i(), c.state() ); +#else + aux ( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() ); +#endif container_size_ = c.data().size(); } diff --git a/senf/Packets/ListBParser.hh b/senf/Packets/ListBParser.hh index 76227c0..27671d3 100644 --- a/senf/Packets/ListBParser.hh +++ b/senf/Packets/ListBParser.hh @@ -41,7 +41,7 @@ namespace senf { #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_ListBParser_i_) #define HH_SENF_Packets_ListBParser_i_ //#include "ListBParser.cci" -//#include "ListBParser.ct" +#include "ListBParser.ct" #include "ListBParser.cti" #endif