Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ccnb-parser-content-object-visitor.h" |
| 22 | #include "ccnb-parser-name-components-visitor.h" |
| 23 | |
| 24 | #include "ns3/ccnb-parser-block.h" |
| 25 | #include "ns3/ccnb-parser-dtag.h" |
| 26 | #include "ns3/name-components.h" |
| 27 | #include "ns3/assert.h" |
| 28 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 29 | #include "ns3/ccnx-content-object-header.h" |
| 30 | |
| 31 | #include <boost/foreach.hpp> |
| 32 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 33 | namespace ns3 { |
| 34 | namespace CcnbParser { |
| 35 | |
| 36 | // We don't really care about any other fields |
| 37 | void |
| 38 | ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/) |
| 39 | { |
| 40 | // uint32_t n.m_dtag; |
| 41 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 42 | static NameComponentsVisitor nameComponentsVisitor; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 43 | |
| 44 | CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (param); |
| 45 | |
| 46 | switch (n.m_dtag) |
| 47 | { |
| 48 | case CCN_DTAG_ContentObject: |
| 49 | // process nested blocks |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 50 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 51 | { |
| 52 | block->accept (*this, param); |
| 53 | } |
| 54 | break; |
| 55 | case CCN_DTAG_Name: |
| 56 | { |
| 57 | // process name components |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 58 | Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 60 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 61 | { |
| 62 | block->accept (nameComponentsVisitor, *name); |
| 63 | } |
| 64 | contentObject.SetName (name); |
| 65 | break; |
| 66 | } |
| 67 | case CCN_DTAG_Signature: // ignoring |
| 68 | break; |
| 69 | case CCN_DTAG_SignedInfo: // ignoring |
| 70 | break; |
| 71 | case CCN_DTAG_Content: // !!! HACK |
| 72 | // This hack was necessary for memory optimizations (i.e., content is virtual payload) |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 73 | NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag"); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | } // namespace CcnbParser |
| 79 | } // namespace ns3 |