blob: 28b039de5f04b9c10fbfa75b57394216171d649e [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 Zhu43eb2732012-12-28 00:48:26 -080028
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080029namespace Ccnx {
30
Alexander Afanasyevf278db32013-01-21 14:41:01 -080031struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { };
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080032
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080033class ParsedContentObject
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080034{
35public:
Zhenkai Zhu79264a42013-02-07 21:49:42 -080036 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 Zhu43eb2732012-12-28 00:48:26 -080040 virtual ~ParsedContentObject();
41
42 Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080043 content() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080044
Alexander Afanasyevdbc06712013-01-08 18:30:28 -080045 BytesPtr
46 contentPtr() const;
Alexander Afanasyevf278db32013-01-21 14:41:01 -080047
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080048 Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080049 name() const;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080050
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080051 inline const Bytes &
52 buf () const;
53
Zhenkai Zhu79264a42013-02-07 21:49:42 -080054 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 Zhu9f2ef6f2013-01-04 21:46:08 -080066private:
67 void
68 init(const unsigned char *data, size_t len);
69
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080070protected:
Zhenkai Zhu90611802013-01-04 21:30:24 -080071 ccn_parsed_ContentObject m_pco;
72 ccn_indexbuf *m_comps;
73 Bytes m_bytes;
Zhenkai Zhu79264a42013-02-07 21:49:42 -080074 bool m_verified;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080075};
76
Alexander Afanasyev053e5ac2013-01-22 20:59:13 -080077const Bytes &
78ParsedContentObject::buf () const
79{
80 return m_bytes;
81}
82
83
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080084typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
85
86}
87
88#endif // CCNX_CONTENT_OBJECT_H