blob: d75a7ea6ed06f123577244ca21f21a583ae8794c [file] [log] [blame]
Alexander Afanasyevf278db32013-01-21 14:41:01 -08001/* -*- 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 Zhu43eb2732012-12-28 00:48:26 -080022#ifndef CCNX_CONTENT_OBJECT_H
23#define CCNX_CONTENT_OBJECT_H
24
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080025#include "ccnx-wrapper.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080026#include "ccnx-common.h"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080027#include "ccnx-name.h"
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070028#include "hash-helper.h"
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080029
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080030namespace Ccnx {
31
Alexander Afanasyevf278db32013-01-21 14:41:01 -080032struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { };
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080033
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070034class Key;
35typedef boost::shared_ptr<Key> KeyPtr;
36
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080037class ParsedContentObject
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080038{
39public:
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070040 enum Type
41 {
42 DATA,
43 KEY,
44 OTHER
45 };
46 ParsedContentObject(const unsigned char *data, size_t len, bool integrityChecked = false, bool verified = false);
47 ParsedContentObject(const unsigned char *data, const ccn_parsed_ContentObject &pco, bool integrityChecked = false, bool verified = false);
48 ParsedContentObject(const Bytes &bytes, bool integrityChecked = false, bool verified = false);
49 ParsedContentObject(const ParsedContentObject &other, bool integrityChecked = false, bool verified = false);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080050 virtual ~ParsedContentObject();
51
52 Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080053 content() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080054
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080055 BytesPtr
56 contentPtr() const;
Alexander Afanasyevf278db32013-01-21 14:41:01 -080057
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080058 Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080059 name() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080060
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070061 Name
62 keyName() const;
63
64 HashPtr
65 publisherPublicKeyDigest() const;
66
67 Type
68 type() const;
69
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080070 inline const Bytes &
71 buf () const;
72
Zhenkai Zhu79264a42013-02-07 21:49:42 -080073 bool
74 verified() const { return m_verified; }
75
76 void
77 setVerified(bool verified) { m_verified = verified; }
78
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -070079 bool
80 integrityChecked() const { return m_integrityChecked; }
81
82 void
83 setIntegrityChecked(bool checked) { m_integrityChecked = checked; }
84
Zhenkai Zhu79264a42013-02-07 21:49:42 -080085 const unsigned char *
86 msg() const { return head(m_bytes); }
87
88 const ccn_parsed_ContentObject *
89 pco() const { return &m_pco; }
90
Zhenkai Zhu9f2ef6f2013-01-04 21:46:08 -080091private:
92 void
93 init(const unsigned char *data, size_t len);
94
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080095protected:
Zhenkai Zhu90611802013-01-04 21:30:24 -080096 ccn_parsed_ContentObject m_pco;
97 ccn_indexbuf *m_comps;
98 Bytes m_bytes;
Zhenkai Zhu79264a42013-02-07 21:49:42 -080099 bool m_verified;
Zhenkai Zhudd1f14d2013-03-13 12:04:28 -0700100 bool m_integrityChecked;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -0800101};
102
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -0800103const Bytes &
104ParsedContentObject::buf () const
105{
106 return m_bytes;
107}
108
109
Zhenkai Zhu43eb2732012-12-28 00:48:26 -0800110typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
111
112}
113
114#endif // CCNX_CONTENT_OBJECT_H