blob: 0cfe4bd683567a4be62fb8ced51c39d2e447e9d0 [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-dtag.h"
22#include "ns3/ccnb-parser-common.h"
23
24namespace ns3 {
25namespace CcnbParser {
26
27Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
28{
29 m_dtag = dtag;
30
31 /**
32 * Hack
33 *
34 * Stop processing after encountering <Content> dtag. Actual
35 * content (including virtual payload) will be stored in Packet
36 * buffer
37 */
38 if (dtag == Ccnx::CCN_DTAG_Content)
39 return; // hack #1. Do not process nesting block for <Content>
40
41 // parse attributes until first nested block reached
42 while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
43 {
44 Ptr<Block> block = Block::ParseBlock (start);
45 if (DynamicCast<BaseAttr> (block)!=0)
46 m_attrs.push_back (block);
47 else
48 {
49 m_nestedTags.push_back (block);
50 break;
51 }
52 }
53
54 // parse the rest of nested blocks
55 while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
56 {
57 // hack #2. Stop processing nested blocks if last block was <Content>
58 if (m_dtag == Ccnx::CCN_DTAG_ContentObject && // we are in <ContentObject>
59 DynamicCast<Dtag> (m_nestedBlocks.back())!=0 && // last block is DTAG
60 DynamicCast<Dtag> (m_nestedBlocks.back())->m_dtag == CCN_DTAG_Content)
61 {
62 return;
63 }
64
65 m_nestedBlocks.push_back (Block::ParseBlock (start));
66 }
67 if (start.IsEnd ())
68 throw CcnxDecodingException ();
69
70 start.ReadU8 (); // read CCN_CLOSE
71}
72
73}
74}