Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 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: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 22 | #ifndef CCNX_CONTENT_OBJECT_H |
| 23 | #define CCNX_CONTENT_OBJECT_H |
| 24 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 25 | #include "ccnx-wrapper.h" |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 26 | #include "ccnx-common.h" |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 27 | #include "ccnx-name.h" |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 28 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 29 | namespace Ccnx { |
| 30 | |
Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 31 | struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { }; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 32 | |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 33 | class ParsedContentObject |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 34 | { |
| 35 | public: |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 36 | ParsedContentObject(const unsigned char *data, size_t len, bool verified = false); |
| 37 | ParsedContentObject(const unsigned char *data, const ccn_parsed_ContentObject &pco, bool verified = false); |
| 38 | ParsedContentObject(const Bytes &bytes, bool verified = false); |
| 39 | ParsedContentObject(const ParsedContentObject &other, bool verified = false); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 40 | virtual ~ParsedContentObject(); |
| 41 | |
| 42 | Bytes |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 43 | content() const; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 45 | BytesPtr |
| 46 | contentPtr() const; |
Alexander Afanasyev | f278db3 | 2013-01-21 14:41:01 -0800 | [diff] [blame] | 47 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 48 | Name |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 49 | name() const; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | 053e5ac | 2013-01-22 20:59:13 -0800 | [diff] [blame] | 51 | inline const Bytes & |
| 52 | buf () const; |
| 53 | |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 54 | bool |
| 55 | verified() const { return m_verified; } |
| 56 | |
| 57 | void |
| 58 | setVerified(bool verified) { m_verified = verified; } |
| 59 | |
| 60 | const unsigned char * |
| 61 | msg() const { return head(m_bytes); } |
| 62 | |
| 63 | const ccn_parsed_ContentObject * |
| 64 | pco() const { return &m_pco; } |
| 65 | |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 66 | private: |
| 67 | void |
| 68 | init(const unsigned char *data, size_t len); |
| 69 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 70 | protected: |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 71 | ccn_parsed_ContentObject m_pco; |
| 72 | ccn_indexbuf *m_comps; |
| 73 | Bytes m_bytes; |
Zhenkai Zhu | 79264a4 | 2013-02-07 21:49:42 -0800 | [diff] [blame] | 74 | bool m_verified; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
Alexander Afanasyev | 053e5ac | 2013-01-22 20:59:13 -0800 | [diff] [blame] | 77 | const Bytes & |
| 78 | ParsedContentObject::buf () const |
| 79 | { |
| 80 | return m_bytes; |
| 81 | } |
| 82 | |
| 83 | |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 84 | typedef boost::shared_ptr<ParsedContentObject> PcoPtr; |
| 85 | |
| 86 | } |
| 87 | |
| 88 | #endif // CCNX_CONTENT_OBJECT_H |