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-dtag.h" |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 22 | |
| 23 | #include "ccnb-parser-base-attr.h" |
| 24 | #include "ccnb-parser-base-tag.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ns3 { |
| 27 | namespace CcnbParser { |
| 28 | |
| 29 | Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag) |
| 30 | { |
| 31 | m_dtag = dtag; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 32 | // std::cout << m_dtag << ", position: " << Block::counter << "\n"; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Hack |
| 35 | * |
| 36 | * Stop processing after encountering <Content> dtag. Actual |
| 37 | * content (including virtual payload) will be stored in Packet |
| 38 | * buffer |
| 39 | */ |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 40 | if (dtag == CCN_DTAG_Content) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 41 | return; // hack #1. Do not process nesting block for <Content> |
| 42 | |
| 43 | // parse attributes until first nested block reached |
| 44 | while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE) |
| 45 | { |
| 46 | Ptr<Block> block = Block::ParseBlock (start); |
| 47 | if (DynamicCast<BaseAttr> (block)!=0) |
| 48 | m_attrs.push_back (block); |
| 49 | else |
| 50 | { |
| 51 | m_nestedTags.push_back (block); |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // parse the rest of nested blocks |
| 57 | while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE) |
| 58 | { |
| 59 | // hack #2. Stop processing nested blocks if last block was <Content> |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 60 | if (m_dtag == CCN_DTAG_ContentObject && // we are in <ContentObject> |
| 61 | DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG |
| 62 | DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 63 | { |
| 64 | return; |
| 65 | } |
| 66 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 67 | m_nestedTags.push_back (Block::ParseBlock (start)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 68 | } |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 69 | |
| 70 | // hack #3. Stop processing when last tag was <ContentObject> |
| 71 | if (m_dtag == CCN_DTAG_ContentObject && // we are in <ContentObject> |
| 72 | DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG |
| 73 | DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content) |
| 74 | { |
| 75 | return; |
| 76 | } |
| 77 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 78 | if (start.IsEnd ()) |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 79 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 80 | |
| 81 | start.ReadU8 (); // read CCN_CLOSE |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 82 | // std::cout << "closer, position = " << Block::counter << "\n"; |
| 83 | // Block::counter ++; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | } |
| 87 | } |