removed some useless spaces; not very important, I know :)
[senf.git] / Packets / PacketParser.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief PacketParser inline non-template implementation */
25
26 // Custom includes
27 #include <iterator>
28 #include "PacketData.hh"
29
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::PacketParserBase
35
36 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i()
37     const
38 {
39     return i_;
40 }
41
42 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i(size_type offset)
43     const
44 {
45     validate(offset);
46     return boost::next(i_, offset);
47 }
48
49 prefix_ senf::PacketParserBase::state_type senf::PacketParserBase::state()
50     const
51 {
52     return data_;
53 }
54
55 prefix_ senf::PacketData & senf::PacketParserBase::data()
56     const
57 {
58     return * data_;
59 }
60
61 prefix_ void senf::PacketParserBase::init()
62     const
63 {}
64
65 prefix_ void senf::PacketParserBase::defaultInit()
66     const
67 {}
68
69 prefix_ senf::Packet senf::PacketParserBase::packet()
70     const
71 {
72     // OUCH ... I hate this but for some awkward packet types, access to the packet
73     // from the parser is really needed (e.g. UDP when building the pseudo-header
74     // for calculating the checksum).
75     return Packet(PacketInterpreterBase::ptr(static_cast<PacketInterpreterBase*>(&data())));
76 }
77
78 ////////////////////////////////////////
79 // protected members
80
81 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s)
82     : i_ (i), data_ (s)
83 {}
84
85 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s, 
86                                                  size_type size)
87     : i_ (i), data_ (s)
88 {
89     validate(size);
90 }
91
92 prefix_ bool senf::PacketParserBase::check(size_type size)
93     const
94 {
95     return size <= size_type(std::distance(i(),end()));
96 }
97
98 prefix_ void senf::PacketParserBase::validate(size_type size)
99     const
100 {
101     if (! check(size))
102         throw TruncatedPacketException();
103 }
104
105 ////////////////////////////////////////
106 // private members
107
108 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::end()
109     const
110 {
111     return data_->end();
112 }
113
114 ///////////////////////////////cci.e///////////////////////////////////////
115 #undef prefix_
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"
125 // comment-column: 40
126 // End: