blob: 8548598f8533c9ea3b3b00aec13220203fea5067 [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"
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070026#include "ns3/ccnx-name-components.h"
Alexander Afanasyev8b379052011-08-21 16:58:20 -070027#include "ns3/assert.h"
28
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070029#include "ns3/ccnx-content-object-header.h"
30
31#include <boost/foreach.hpp>
32
Alexander Afanasyev8b379052011-08-21 16:58:20 -070033namespace ns3 {
34namespace CcnbParser {
35
36// We don't really care about any other fields
37void
38ContentObjectVisitor::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 Afanasyeve709f3d2011-08-21 17:55:45 -070042 static NameComponentsVisitor nameComponentsVisitor;
Alexander Afanasyev8b379052011-08-21 16:58:20 -070043
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 Afanasyeve709f3d2011-08-21 17:55:45 -070050 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070051 {
52 block->accept (*this, param);
53 }
54 break;
55 case CCN_DTAG_Name:
56 {
57 // process name components
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070058 Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070059
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070060 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070061 {
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 Afanasyeve709f3d2011-08-21 17:55:45 -070073 NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag");
Alexander Afanasyev8b379052011-08-21 16:58:20 -070074 break;
75 }
76}
77
78} // namespace CcnbParser
79} // namespace ns3