Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2017, Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
| 21 | #include "json-helper.hpp" |
| 22 | #include <boost/lexical_cast.hpp> |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ndncert { |
| 26 | |
| 27 | const JsonSection |
Zhiyi Zhang | 0fd71cc | 2017-03-01 10:18:58 -0800 | [diff] [blame^] | 28 | genResponseProbeJson(const Name& identifier, const Name& caInformation) |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 29 | { |
| 30 | JsonSection root; |
| 31 | |
| 32 | root.put(JSON_IDNENTIFIER, identifier.toUri()); |
Zhiyi Zhang | 0fd71cc | 2017-03-01 10:18:58 -0800 | [diff] [blame^] | 33 | root.put(JSON_CA_INFO, caInformation.toUri()); |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 34 | |
| 35 | return root; |
| 36 | } |
| 37 | |
| 38 | const JsonSection |
Zhiyi Zhang | 0fd71cc | 2017-03-01 10:18:58 -0800 | [diff] [blame^] | 39 | genResponseNewJson(const std::string& requestId, const std::string& status, |
| 40 | const std::list<std::string>& challenges) |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 41 | { |
| 42 | JsonSection root; |
| 43 | JsonSection challengesSection; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 44 | root.put(JSON_REQUEST_ID, requestId); |
Zhiyi Zhang | 0fd71cc | 2017-03-01 10:18:58 -0800 | [diff] [blame^] | 45 | root.put(JSON_STATUS, status); |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 46 | |
| 47 | for (const auto& entry : challenges) { |
| 48 | JsonSection challenge; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 49 | challenge.put(JSON_CHALLENGE_TYPE, entry); |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 50 | challengesSection.push_back(std::make_pair("", challenge)); |
| 51 | } |
| 52 | root.add_child(JSON_CHALLENGES, challengesSection); |
| 53 | |
| 54 | return root; |
| 55 | } |
| 56 | |
| 57 | const JsonSection |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 58 | genResponseChallengeJson(const std::string& requestId, const std::string& challengeType, |
| 59 | const std::string& status, const Name& name) |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 60 | { |
| 61 | JsonSection root; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 62 | root.put(JSON_REQUEST_ID, requestId); |
| 63 | root.put(JSON_CHALLENGE_TYPE, challengeType); |
| 64 | root.put(JSON_STATUS, status); |
| 65 | if (name.toUri() != "") { |
| 66 | root.put(JSON_CERTIFICATE, name.toUri()); |
| 67 | } |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 68 | return root; |
| 69 | } |
| 70 | |
| 71 | const JsonSection |
| 72 | genErrorJson(const std::string& errorInfo) |
| 73 | { |
| 74 | JsonSection root; |
| 75 | root.put(JSON_STATUS, "error"); |
| 76 | root.put(JSON_ERROR_INFO, errorInfo); |
| 77 | return root; |
| 78 | } |
| 79 | |
| 80 | } // namespace ndncert |
| 81 | } // namespace ndn |