| 29 | core::Property ConvertUpdate::SSLContext("SSL Context Service", "The SSL Context Service used to provide client certificate information for TLS/SSL (https) connections.", ""); |
| 30 | |
| 31 | void ConvertUpdate::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession>& /*session*/) { |
| 32 | if (nullptr == mqtt_service_) { |
| 33 | context->yield(); |
| 34 | return; |
| 35 | } |
| 36 | std::vector<uint8_t> update; |
| 37 | bool received_update = false; |
| 38 | while (mqtt_service_->get(100, listening_topic, update)) { |
| 39 | // first we have the input topic string followed by the update URI |
| 40 | if (update.size() > 0) { |
| 41 | |
| 42 | io::BufferStream stream(update.data(), update.size()); |
| 43 | |
| 44 | std::string returnTopic, url; |
| 45 | |
| 46 | if (returnTopic.empty() || url.empty()) { |
| 47 | logger_->log_debug("topic and/or URL are empty"); |
| 48 | break; |
| 49 | } |
| 50 | |
| 51 | stream.read(returnTopic); |
| 52 | stream.read(url); |
| 53 | |
| 54 | /** |
| 55 | * Not having curl support is actually okay for MQTT to be built, but running the update processor requires |
| 56 | * that we have curl available. |
| 57 | */ |
| 58 | auto client_ptr = core::ClassLoader::getDefaultClassLoader().instantiateRaw("HTTPClient", "HTTPClient"); |
| 59 | if (nullptr == client_ptr) { |
| 60 | logger_->log_error("Could not locate HTTPClient. You do not have cURL support!"); |
| 61 | return; |
| 62 | } |
| 63 | std::unique_ptr<utils::BaseHTTPClient> client = std::unique_ptr<utils::BaseHTTPClient>(dynamic_cast<utils::BaseHTTPClient*>(client_ptr)); |
| 64 | client->initialize("GET"); |
| 65 | client->setConnectionTimeout(std::chrono::milliseconds(2000)); |
| 66 | client->setReadTimeout(std::chrono::milliseconds(2000)); |
| 67 | |
| 68 | if (client->submit()) { |
| 69 | auto data = client->getResponseBody(); |
| 70 | std::vector<uint8_t> raw_data; |
| 71 | std::transform(std::begin(data), std::end(data), std::back_inserter(raw_data), [](char c) { |
| 72 | return (uint8_t)c; |
| 73 | }); |
| 74 | mqtt_service_->send(returnTopic, raw_data); |
| 75 | } |
| 76 | |
| 77 | received_update = true; |
| 78 | } else { |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if (!received_update) { |
| 84 | context->yield(); |
| 85 | } |
| 86 | |
| 87 | } |
| 88 |
nothing calls this directly
no test coverage detected