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 | |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 24 | #include "../syntax-tree/ccnb-parser-block.h" |
| 25 | #include "../syntax-tree/ccnb-parser-dtag.h" |
| 26 | |
Ilya Moiseenko | d26e682 | 2011-08-23 17:48:38 -0700 | [diff] [blame] | 27 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 28 | #include "ns3/assert.h" |
| 29 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 30 | #include "ns3/ccnx-content-object-header.h" |
| 31 | |
| 32 | #include <boost/foreach.hpp> |
| 33 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 34 | namespace ns3 { |
| 35 | namespace CcnbParser { |
| 36 | |
| 37 | // We don't really care about any other fields |
| 38 | void |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 39 | ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 40 | { |
| 41 | // uint32_t n.m_dtag; |
| 42 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 43 | static NameComponentsVisitor nameComponentsVisitor; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 45 | CcnxContentObjectHeader &contentObject = *(boost::any_cast<CcnxContentObjectHeader*> (param)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 46 | |
| 47 | switch (n.m_dtag) |
| 48 | { |
| 49 | case CCN_DTAG_ContentObject: |
| 50 | // process nested blocks |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 51 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 52 | { |
| 53 | block->accept (*this, param); |
| 54 | } |
| 55 | break; |
| 56 | case CCN_DTAG_Name: |
| 57 | { |
| 58 | // process name components |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 59 | Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 61 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 63 | block->accept (nameComponentsVisitor, &(*name)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 64 | } |
| 65 | contentObject.SetName (name); |
| 66 | break; |
| 67 | } |
| 68 | case CCN_DTAG_Signature: // ignoring |
| 69 | break; |
| 70 | case CCN_DTAG_SignedInfo: // ignoring |
| 71 | break; |
| 72 | case CCN_DTAG_Content: // !!! HACK |
| 73 | // 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] | 74 | 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] | 75 | break; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | } // namespace CcnbParser |
| 80 | } // namespace ns3 |