ef749a0e01fc858f8f2056c7a50c613f04be8ee0
[senf.git] / Packets / PacketParser.cci
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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::state_type senf::PacketParserBase::state()
43     const
44 {
45     return data_;
46 }
47
48 prefix_ senf::PacketData & senf::PacketParserBase::data()
49     const
50 {
51     return * data_;
52 }
53
54 prefix_ void senf::PacketParserBase::init()
55     const
56 {}
57
58 prefix_ void senf::PacketParserBase::defaultInit()
59     const
60 {}
61
62 prefix_ senf::Packet senf::PacketParserBase::packet()
63     const
64 {
65     // OUCH ... I hate this but for some awkward packet types, access to the packet
66     // from the parser is really needed (e.g. UDP when building the pseudo-header
67     // for calculating the checksum).
68     return Packet(PacketInterpreterBase::ptr(static_cast<PacketInterpreterBase*>(&data())));
69 }
70
71 ////////////////////////////////////////
72 // protected members
73
74 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s)
75     : i_ (i), data_ (s)
76 {}
77
78 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s, 
79                                                  size_type size)
80     : i_ (i), data_ (s)
81 {
82     validate(size);
83 }
84
85 prefix_ bool senf::PacketParserBase::check(size_type size)
86     const
87 {
88     return size <= size_type(std::distance(i(),end()));
89 }
90
91 prefix_ void senf::PacketParserBase::validate(size_type size)
92     const
93 {
94     if (! check(size))
95         throw TruncatedPacketException();
96 }
97
98 ////////////////////////////////////////
99 // private members
100
101 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::end()
102     const
103 {
104     return data_->end();
105 }
106
107 ///////////////////////////////cci.e///////////////////////////////////////
108 #undef prefix_
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"
118 // comment-column: 40
119 // End: