blob: d5763118935028730dc109b7d3281dd54305cedb [file] [log] [blame]
Shock Jiang06cd2142014-11-23 17:36:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Davide Pesavento98026122022-03-14 22:00:03 -04003 * Copyright (c) 2014-2022, Regents of the University of California.
Shock Jiang06cd2142014-11-23 17:36:02 -08004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "util.hpp"
Davide Pesaventod01c1a42019-01-21 21:42:45 -050021#include "config.hpp"
Yumin Xia2c509c22017-02-09 14:37:36 -080022
Davide Pesaventod01c1a42019-01-21 21:42:45 -050023#include <ndn-cxx/security/transform/base64-encode.hpp>
24#include <ndn-cxx/security/transform/buffer-source.hpp>
25#include <ndn-cxx/security/transform/stream-sink.hpp>
Shock Jiang06cd2142014-11-23 17:36:02 -080026
27namespace ndn {
28namespace ndns {
29
Davide Pesaventod01c1a42019-01-21 21:42:45 -050030std::string
31getDefaultDatabaseFile()
32{
33 return NDNS_DEFAULT_DBFILE;
34}
Yumin Xia2c509c22017-02-09 14:37:36 -080035
Yumin Xiaa484ba72016-11-10 20:40:12 -080036NdnsContentType
37toNdnsContentType(const std::string& str)
Shock Jiang06cd2142014-11-23 17:36:02 -080038{
39 if (str == "resp")
40 return NDNS_RESP;
41 else if (str == "nack")
42 return NDNS_NACK;
43 else if (str == "auth")
44 return NDNS_AUTH;
Yumin Xiaa484ba72016-11-10 20:40:12 -080045 else if (str == "blob")
46 return NDNS_BLOB;
47 else if (str == "link")
48 return NDNS_LINK;
Yumin Xia3c6b1fd2016-12-11 19:08:47 -080049 else if (str == "key")
Davide Pesavento98026122022-03-14 22:00:03 -040050 return NDNS_KEY;
Shock Jiang06cd2142014-11-23 17:36:02 -080051 else
52 return NDNS_UNKNOWN;
53}
54
55void
Davide Pesaventod01c1a42019-01-21 21:42:45 -050056output(const Data& data, std::ostream& os, bool isPretty)
Shock Jiang06cd2142014-11-23 17:36:02 -080057{
Davide Pesaventod01c1a42019-01-21 21:42:45 -050058 using security::transform::base64Encode;
59 using security::transform::bufferSource;
60 using security::transform::streamSink;
61
Shock Jiang06cd2142014-11-23 17:36:02 -080062 const Block& block = data.wireEncode();
63 if (!isPretty) {
Davide Pesavento98026122022-03-14 22:00:03 -040064 bufferSource(block) >> base64Encode() >> streamSink(os);
Shock Jiang06cd2142014-11-23 17:36:02 -080065 }
66 else {
Davide Pesavento1bff1b22020-06-08 18:46:05 -040067 os << "Name: " << data.getName() << std::endl;
68 auto kl = data.getKeyLocator();
69 if (kl) {
70 os << "KeyLocator: " << kl->getName() << std::endl;
71 }
Davide Pesavento98026122022-03-14 22:00:03 -040072 bufferSource(block) >> base64Encode() >> streamSink(os);
Shock Jiang06cd2142014-11-23 17:36:02 -080073 os << std::endl;
74 }
75}
76
77} // namespace ndns
78} // namespace ndn