blob: 4325e670521cc455704223adc707936ab0b6cc6a [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
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080024#include "../syntax-tree/ccnb-parser-block.h"
25#include "../syntax-tree/ccnb-parser-dtag.h"
26
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070027#include "ns3/ccnx-name-components.h"
Alexander Afanasyev8b379052011-08-21 16:58:20 -070028#include "ns3/assert.h"
29
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070030#include "ns3/ccnx-content-object-header.h"
31
32#include <boost/foreach.hpp>
33
Alexander Afanasyev8b379052011-08-21 16:58:20 -070034namespace ns3 {
35namespace CcnbParser {
36
37// We don't really care about any other fields
38void
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070039ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070040{
41 // uint32_t n.m_dtag;
42 // std::list<Ptr<Block> > n.m_nestedBlocks;
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070043 static NameComponentsVisitor nameComponentsVisitor;
Alexander Afanasyev8b379052011-08-21 16:58:20 -070044
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070045 CcnxContentObjectHeader &contentObject = *(boost::any_cast<CcnxContentObjectHeader*> (param));
Alexander Afanasyev8b379052011-08-21 16:58:20 -070046
47 switch (n.m_dtag)
48 {
49 case CCN_DTAG_ContentObject:
50 // process nested blocks
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070051 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070052 {
53 block->accept (*this, param);
54 }
55 break;
56 case CCN_DTAG_Name:
57 {
58 // process name components
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070059 Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070060
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070061 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070062 {
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070063 block->accept (nameComponentsVisitor, &(*name));
Alexander Afanasyev8b379052011-08-21 16:58:20 -070064 }
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 Afanasyeve709f3d2011-08-21 17:55:45 -070074 NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag");
Alexander Afanasyev8b379052011-08-21 16:58:20 -070075 break;
76 }
77}
78
79} // namespace CcnbParser
80} // namespace ns3