blob: 64f7d0b0eb1b549456d78f25821f565190434ca5 [file] [log] [blame]
Alexander Afanasyev8b379052011-08-21 16:58:20 -07001/* -*- 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
29namespace ns3 {
30namespace CcnbParser {
31
32// We don't really care about any other fields
33void
34ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/)
35{
36 // uint32_t n.m_dtag;
37 // std::list<Ptr<Block> > n.m_nestedBlocks;
38 static NameComponentsVisitor m_nameComponentsVisitor;
39
40 CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (param);
41
42 switch (n.m_dtag)
43 {
44 case CCN_DTAG_ContentObject:
45 // process nested blocks
46 BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
47 {
48 block->accept (*this, param);
49 }
50 break;
51 case CCN_DTAG_Name:
52 {
53 // process name components
54 Ptr<Name::Components> name = Create<Name::Components> ();
55
56 BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
57 {
58 block->accept (nameComponentsVisitor, *name);
59 }
60 contentObject.SetName (name);
61 break;
62 }
63 case CCN_DTAG_Signature: // ignoring
64 break;
65 case CCN_DTAG_SignedInfo: // ignoring
66 break;
67 case CCN_DTAG_Content: // !!! HACK
68 // This hack was necessary for memory optimizations (i.e., content is virtual payload)
69 NS_ASSERT_MSG (n.m_nestedBlocks.size() == 0, "Parser should have stopped just after processing <Content> tag");
70 break;
71 }
72}
73
74} // namespace CcnbParser
75} // namespace ns3