Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 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 | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 22 | #ifndef CCNX_COMMON_H |
| 23 | #define CCNX_COMMON_H |
| 24 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 25 | extern "C" { |
| 26 | #include <ccn/ccn.h> |
| 27 | #include <ccn/charbuf.h> |
| 28 | #include <ccn/keystore.h> |
| 29 | #include <ccn/uri.h> |
| 30 | #include <ccn/bloom.h> |
| 31 | #include <ccn/signing.h> |
| 32 | } |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 33 | #include <vector> |
| 34 | #include <boost/shared_ptr.hpp> |
| 35 | #include <boost/exception/all.hpp> |
| 36 | #include <boost/function.hpp> |
| 37 | #include <string> |
| 38 | #include <sstream> |
| 39 | #include <map> |
| 40 | #include <utility> |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 41 | #include <string.h> |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 42 | |
| 43 | using namespace std; |
| 44 | namespace Ccnx { |
| 45 | typedef vector<unsigned char> Bytes; |
Zhenkai Zhu | 9bad2bf | 2012-12-28 15:31:46 -0800 | [diff] [blame] | 46 | typedef vector<string>Comps; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 48 | typedef boost::shared_ptr<Bytes> BytesPtr; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 50 | inline |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 51 | const unsigned char * |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 52 | head(const Bytes &bytes) |
| 53 | { |
| 54 | return &bytes[0]; |
| 55 | } |
| 56 | |
| 57 | inline |
| 58 | unsigned char * |
| 59 | head (Bytes &bytes) |
| 60 | { |
| 61 | return &bytes[0]; |
| 62 | } |
| 63 | |
| 64 | // --- Bytes operations start --- |
| 65 | inline void |
| 66 | readRaw(Bytes &bytes, const unsigned char *src, size_t len) |
| 67 | { |
| 68 | if (len > 0) |
| 69 | { |
| 70 | bytes.resize(len); |
| 71 | memcpy (head (bytes), src, len); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | inline BytesPtr |
| 76 | readRawPtr (const unsigned char *src, size_t len) |
| 77 | { |
| 78 | if (len > 0) |
| 79 | { |
| 80 | BytesPtr ret (new Bytes (len)); |
| 81 | memcpy (head (*ret), src, len); |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | else |
| 86 | return BytesPtr (); |
| 87 | } |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 88 | |
Zhenkai Zhu | 9bad2bf | 2012-12-28 15:31:46 -0800 | [diff] [blame] | 89 | // --- Bytes operations end --- |
| 90 | |
Zhenkai Zhu | f47109b | 2013-01-02 19:41:34 -0800 | [diff] [blame] | 91 | // Exceptions |
| 92 | typedef boost::error_info<struct tag_errmsg, std::string> error_info_str; |
Zhenkai Zhu | 9bad2bf | 2012-12-28 15:31:46 -0800 | [diff] [blame] | 93 | |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 94 | } // Ccnx |
| 95 | #endif // CCNX_COMMON_H |