| 124 | } |
| 125 | |
| 126 | bool AdminSocketOutput::gather_socket_output() { |
| 127 | |
| 128 | std::cout << "Gathering socket output" << std::endl; |
| 129 | for (const auto& socket : sockets) { |
| 130 | std::string response; |
| 131 | AdminSocketClient client(socket.second); |
| 132 | std::cout << std::endl |
| 133 | << "Sending request to " << socket << std::endl |
| 134 | << std::endl; |
| 135 | std::string err = client.do_request("{\"prefix\":\"help\"}", &response); |
| 136 | if (!err.empty()) { |
| 137 | std::cerr << __func__ << " AdminSocketClient::do_request errored with: " |
| 138 | << err << std::endl; |
| 139 | return false; |
| 140 | } |
| 141 | std::cout << response << '\n'; |
| 142 | |
| 143 | JSONParser parser; |
| 144 | bool ret = parser.parse(response.c_str(), response.size()); |
| 145 | if (!ret) { |
| 146 | cerr << "parse error" << std::endl; |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | socket_results sresults; |
| 151 | JSONObjIter iter = parser.find_first(); |
| 152 | const auto postponed_iter = postponed_commands.find(socket.first); |
| 153 | std::vector<std::string> postponed; |
| 154 | if (postponed_iter != postponed_commands.end()) { |
| 155 | postponed = postponed_iter->second; |
| 156 | } |
| 157 | std::cout << "Sending commands to " << socket.first << " socket" |
| 158 | << std::endl; |
| 159 | for (; !iter.end(); ++iter) { |
| 160 | if (std::find(postponed.begin(), postponed.end(), (*iter)->get_name()) |
| 161 | != std::end(postponed)) { |
| 162 | std::cout << "Command \"" << (*iter)->get_name() << "\" postponed" |
| 163 | << std::endl; |
| 164 | continue; |
| 165 | } |
| 166 | sresults.insert(run_command(client, (*iter)->get_name())); |
| 167 | } |
| 168 | |
| 169 | if (sresults.empty()) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | // Custom commands |
| 174 | const auto seek = custom_commands.find(socket.first); |
| 175 | if (seek != custom_commands.end()) { |
| 176 | std::cout << std::endl << "Sending custom commands:" << std::endl; |
| 177 | for (const auto& raw_command : seek->second) { |
| 178 | sresults.insert(run_command(client, raw_command, true)); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Postponed commands |
| 183 | if (!postponed.empty()) |
nothing calls this directly
no test coverage detected