crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
ServerCommandResponse.hpp
Go to the documentation of this file.
1 /*
2  *
3  * ---
4  *
5  * Copyright (C) 2020 Anselm Schmidt (ans[ät]ohai.su)
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version in addition to the terms of any
11  * licences already herein identified.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  *
21  * ---
22  *
23  * ServerCommandResponse.hpp
24  *
25  * Response from the command-and-control server.
26  *
27  * Created on: May 4, 2019
28  * Author: ans
29  */
30 
31 #ifndef STRUCT_SERVERCOMMANDRESPONSE_HPP_
32 #define STRUCT_SERVERCOMMANDRESPONSE_HPP_
33 
34 #include <cstdint> // std::uint64_t
35 #include <string> // std::string
36 
37 namespace crawlservpp::Struct {
38 
43 
45  bool fail{false};
46 
48  bool confirm{false};
49 
51  std::string text;
52 
54  std::uint64_t id{};
55 
59 
61  ServerCommandResponse() = default;
62 
64 
69  explicit ServerCommandResponse(const std::string& response)
70  : text(response) {}
71 
73 
80  ServerCommandResponse(const std::string& response, std::uint64_t newId)
81  : text(response), id(newId) {}
82 
84 
93  ServerCommandResponse(bool failed, bool toBeConfirmed, const std::string& response)
94  : fail(failed), confirm(toBeConfirmed), text(response) {}
95 
99 
101 
106  static ServerCommandResponse failed(const std::string& response) {
107  return ServerCommandResponse(true, false, response);
108  }
109 
111 
116  static ServerCommandResponse toBeConfirmed(const std::string& response) {
117  return ServerCommandResponse(false, true, response);
118  }
119 
121  };
122 
123 } /* namespace crawlservpp::Struct */
124 
125 #endif /* STRUCT_SERVERCOMMANDRESPONSE_HPP_ */
ServerCommandResponse(bool failed, bool toBeConfirmed, const std::string &response)
Constructor initializing a possibly failed or possibly to be confirmed response with text...
Definition: ServerCommandResponse.hpp:93
Response from the command-and-control server.
Definition: ServerCommandResponse.hpp:40
ServerCommandResponse(const std::string &response)
Constructor initializing a successful response with text.
Definition: ServerCommandResponse.hpp:69
ServerCommandResponse()=default
Default constructor.
ServerCommandResponse(const std::string &response, std::uint64_t newId)
Constructor initializing a successful response with text and ID.
Definition: ServerCommandResponse.hpp:80
static ServerCommandResponse toBeConfirmed(const std::string &response)
Helper to initialize a "to be confirmed" response with text.
Definition: ServerCommandResponse.hpp:116
bool confirm
Indicates whether the server command needs to be confirmed.
Definition: ServerCommandResponse.hpp:48
bool fail
Indicates whether the server command failed.
Definition: ServerCommandResponse.hpp:45
std::uint64_t id
Optional ID returned by the server.
Definition: ServerCommandResponse.hpp:54
static ServerCommandResponse failed(const std::string &response)
Helper to initialize a "failed" response with text.
Definition: ServerCommandResponse.hpp:106
Namespace for data structures.
Definition: AlgoThreadProperties.hpp:43
std::string text
The text of the response by the server.
Definition: ServerCommandResponse.hpp:51