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