Skip to content

Commit

Permalink
MINIFICPP-1203 - Fix all leftover linter recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi-dev committed May 20, 2020
1 parent 3170aba commit 4313831
Show file tree
Hide file tree
Showing 51 changed files with 273 additions and 247 deletions.
1 change: 0 additions & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
set noparent
filter=-runtime/reference,-runtime/string,-build/c++11

6 changes: 2 additions & 4 deletions extensions/http-curl/client/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ HTTPClient::~HTTPClient() {
}

void HTTPClient::forceClose() {

if (nullptr != callback) {
callback->stop = true;
}

if (nullptr != write_callback_) {
write_callback_->stop = true;
}

}

int HTTPClient::debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) {
Expand Down Expand Up @@ -184,7 +182,7 @@ bool HTTPClient::setSpecificSSLVersion(SSLVersion specific_version) {
#endif
}

/* If not set, the default will be TLS 1.0, see https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html */
// If not set, the default will be TLS 1.0, see https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html
bool HTTPClient::setMinimumSSLVersion(SSLVersion minimum_version) {
CURLcode ret = CURLE_UNKNOWN_OPTION;
switch (minimum_version) {
Expand Down Expand Up @@ -221,7 +219,7 @@ void HTTPClient::setUploadCallback(HTTPUploadCallback *callbackObj) {
logger_->log_debug("Setting callback for %s", url_);
write_callback_ = callbackObj;
if (method_ == "put" || method_ == "PUT") {
curl_easy_setopt(http_session_, CURLOPT_INFILESIZE_LARGE, (curl_off_t ) callbackObj->ptr->getBufferSize());
curl_easy_setopt(http_session_, CURLOPT_INFILESIZE_LARGE, (curl_off_t) callbackObj->ptr->getBufferSize());
}
curl_easy_setopt(http_session_, CURLOPT_READFUNCTION, &utils::HTTPRequestResponse::send_write);
curl_easy_setopt(http_session_, CURLOPT_READDATA, static_cast<void*>(callbackObj));
Expand Down
53 changes: 25 additions & 28 deletions extensions/http-curl/client/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __HTTP_UTILS_H__
#define __HTTP_UTILS_H__
#ifndef EXTENSIONS_HTTP_CURL_CLIENT_HTTPCLIENT_H_
#define EXTENSIONS_HTTP_CURL_CLIENT_HTTPCLIENT_H_

#include "utils/HTTPClient.h"
#ifdef WIN32
Expand All @@ -29,16 +29,17 @@
#else
#include <curl/curl.h>
#endif
#include <curl/easy.h>
#include <vector>
#include <memory>
#include <iostream>
#include <map>
#include <string>
#include <curl/easy.h>
#ifdef WIN32
#include <regex>
#else
#include <regex.h>
#endif
#include <vector>

#include "utils/ByteArrayCallback.h"
#include "controllers/SSLContextService.h"
Expand All @@ -63,42 +64,41 @@ namespace utils {
*/
class HTTPClient : public BaseHTTPClient, public core::Connectable {
public:

HTTPClient();

HTTPClient(std::string name, utils::Identifier uuid);

HTTPClient(const std::string &url, const std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service = nullptr);
explicit HTTPClient(const std::string &url, const std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service = nullptr);

~HTTPClient();

static int debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr);

virtual void setVerbose(bool use_stderr = false) override;
void setVerbose(bool use_stderr = false) override;

void forceClose();

virtual void initialize(const std::string &method, const std::string url = "", const std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service = nullptr) override;
void initialize(const std::string &method, const std::string url = "", const std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service = nullptr) override;

virtual void setConnectionTimeout(int64_t timeout) override;
void setConnectionTimeout(int64_t timeout) override;

virtual void setReadTimeout(int64_t timeout) override;
void setReadTimeout(int64_t timeout) override;

virtual void setUploadCallback(HTTPUploadCallback *callbackObj) override;
void setUploadCallback(HTTPUploadCallback *callbackObj) override;

virtual void setReadCallback(HTTPReadCallback *callbackObj);

struct curl_slist *build_header_list(std::string regex, const std::map<std::string, std::string> &attributes);

virtual void setContentType(std::string content_type) override;
void setContentType(std::string content_type) override;

virtual std::string escape(std::string string_to_escape) override;
std::string escape(std::string string_to_escape) override;

virtual void setPostFields(const std::string& input) override;
void setPostFields(const std::string& input) override;

void setHeaders(struct curl_slist *list);

virtual void appendHeader(const std::string &new_header) override;
void appendHeader(const std::string &new_header) override;

void appendHeader(const std::string &key, const std::string &value);

Expand All @@ -124,12 +124,12 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {

bool setMinimumSSLVersion(SSLVersion minimum_version) override;

void setKeepAliveProbe(long probe){
void setKeepAliveProbe(long probe) { // NOLINT

This comment has been minimized.

Copy link
@fgerlits

fgerlits Jun 3, 2020

Contributor

out of curiosity, what does the linter complain about here?

This comment has been minimized.

Copy link
@hunyadi-dev

hunyadi-dev Jun 4, 2020

Author Contributor

I think the issue is with using long.

keep_alive_probe_ = probe;
}

void setKeepAliveIdle(long idle){
keep_alive_idle_= idle;
void setKeepAliveIdle(long idle) { // NOLINT
keep_alive_idle_ = idle;
}


Expand All @@ -143,7 +143,7 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {

void setInterface(const std::string &);

virtual const std::map<std::string, std::string> &getParsedHeaders() override {
const std::map<std::string, std::string> &getParsedHeaders() override {
return header_response_.getHeaderMap();
}

Expand All @@ -168,7 +168,7 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {
/**
* Determines if we are connected and operating
*/
virtual bool isRunning() override {
bool isRunning() override {
return true;
}

Expand All @@ -179,15 +179,14 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {
void waitForWork(uint64_t timeoutMs) {
}

virtual void yield() override {

void yield() override {
}

/**
* Determines if work is available by this connectable
* @return boolean if work is available.
*/
virtual bool isWorkAvailable() override {
bool isWorkAvailable() override {
return true;
}

Expand All @@ -206,7 +205,6 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {
}

protected:

inline bool matches(const std::string &value, const std::string &sregex) override;

static CURLcode configure_ssl_context(CURL *curl, void *ctx, void *param) {
Expand Down Expand Up @@ -247,12 +245,11 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {

std::string method_;

long keep_alive_probe_;
long keep_alive_probe_; // NOLINT

long keep_alive_idle_;
long keep_alive_idle_; // NOLINT

std::shared_ptr<logging::Logger> logger_;

};

} /* namespace utils */
Expand All @@ -261,4 +258,4 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable {
} /* namespace apache */
} /* namespace org */

#endif
#endif // EXTENSIONS_HTTP_CURL_CLIENT_HTTPCLIENT_H_
3 changes: 0 additions & 3 deletions extensions/standard-processors/processors/ExecuteProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include <thread>

#ifndef WIN32
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

#endif
Expand Down Expand Up @@ -130,7 +128,6 @@ REGISTER_RESOURCE(ExecuteProcess, "Runs an operating system command specified by
"as it typically does not make sense to split binary data on arbitrary time-based intervals.");
#endif
} // namespace processors
/* namespace processors */
} /* namespace minifi */
} /* namespace nifi */
} /* namespace apache */
Expand Down
2 changes: 1 addition & 1 deletion extensions/standard-processors/processors/GetTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "core/ProcessSession.h"
#include "core/Core.h"
#include "core/Resource.h"
#include "concurrentqueue.h"
#include "concurrentqueue.h" // NOLINT
#include "utils/ThreadPool.h"
#include "core/logging/LoggerConfiguration.h"
#include "controllers/SSLContextService.h"
Expand Down
136 changes: 68 additions & 68 deletions extensions/standard-processors/processors/HashContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,83 +42,83 @@

using HashReturnType = std::pair<std::string, int64_t>;

namespace {
#define HASH_BUFFER_SIZE 16384

HashReturnType MD5Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
MD5_CTX context;
MD5_Init(&context);

size_t ret = 0;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
MD5_Update(&context, buffer, ret);
ret_val.second += ret;
}
} while (ret > 0);

if (ret_val.second > 0) {
unsigned char digest[MD5_DIGEST_LENGTH];
MD5_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, MD5_DIGEST_LENGTH, true /*uppercase*/);
// Without puttng this into its own namespace, the code would export already defined symbols.
namespace { // NOLINT
HashReturnType MD5Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
MD5_CTX context;
MD5_Init(&context);

size_t ret = 0;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
MD5_Update(&context, buffer, ret);
ret_val.second += ret;
}
return ret_val;
}
} while (ret > 0);

HashReturnType SHA1Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
SHA_CTX context;
SHA1_Init(&context);

size_t ret = 0;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
SHA1_Update(&context, buffer, ret);
ret_val.second += ret;
}
} while (ret > 0);

if (ret_val.second > 0) {
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, SHA_DIGEST_LENGTH, true /*uppercase*/);
}
return ret_val;
if (ret_val.second > 0) {
unsigned char digest[MD5_DIGEST_LENGTH];
MD5_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, MD5_DIGEST_LENGTH, true /*uppercase*/);
}
return ret_val;
}

HashReturnType SHA1Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
SHA_CTX context;
SHA1_Init(&context);

size_t ret = 0;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
SHA1_Update(&context, buffer, ret);
ret_val.second += ret;
}
} while (ret > 0);

HashReturnType SHA256Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
SHA256_CTX context;
SHA256_Init(&context);

size_t ret;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
SHA256_Update(&context, buffer, ret);
ret_val.second += ret;
}
} while (ret > 0);

if (ret_val.second > 0) {
unsigned char digest[SHA256_DIGEST_LENGTH];
SHA256_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, SHA256_DIGEST_LENGTH, true /*uppercase*/);
if (ret_val.second > 0) {
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, SHA_DIGEST_LENGTH, true /*uppercase*/);
}
return ret_val;
}

HashReturnType SHA256Hash(const std::shared_ptr<org::apache::nifi::minifi::io::BaseStream>& stream) {
HashReturnType ret_val;
ret_val.second = 0;
uint8_t buffer[HASH_BUFFER_SIZE];
SHA256_CTX context;
SHA256_Init(&context);

size_t ret;
do {
ret = stream->readData(buffer, HASH_BUFFER_SIZE);
if (ret > 0) {
SHA256_Update(&context, buffer, ret);
ret_val.second += ret;
}
return ret_val;
} while (ret > 0);

if (ret_val.second > 0) {
unsigned char digest[SHA256_DIGEST_LENGTH];
SHA256_Final(digest, &context);
ret_val.first = utils::StringUtils::to_hex(digest, SHA256_DIGEST_LENGTH, true /*uppercase*/);
}
return ret_val;
}
} // namespace


namespace org {
namespace apache {
namespace nifi {
Expand Down Expand Up @@ -165,7 +165,7 @@ class HashContent : public core::Processor {
private:
std::shared_ptr<core::FlowFile> flowFile_;
const HashContent& parent_;
};
};

private:
//! Logger
Expand Down
1 change: 0 additions & 1 deletion extensions/standard-processors/processors/ListenSyslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#endif
#include <errno.h>
#include <sys/types.h>

#include <chrono>
#include <thread>
Expand Down

0 comments on commit 4313831

Please sign in to comment.