Skip to content

Commit

Permalink
Silence warnings during build (snowplow#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaskenezlego committed May 16, 2023
1 parent 7fb90d0 commit e1e1d5e
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 53 deletions.
4 changes: 2 additions & 2 deletions include/snowplow/client_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using std::move;

ClientSession::ClientSession(const SessionConfiguration &session_config) :
ClientSession(
move(session_config.get_session_store()),
session_config.get_session_store(),
session_config.get_foreground_timeout(),
session_config.get_background_timeout()
) {
Expand Down Expand Up @@ -85,7 +85,7 @@ SelfDescribingJson ClientSession::update_and_get_session_context(const string &e
session_context_data = this->m_session_context_data;

m_event_index++;
event_index = m_event_index;
event_index = int(m_event_index);
}

if (save_to_storage) {
Expand Down
30 changes: 16 additions & 14 deletions include/snowplow/detail/base64/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "base64.hpp"
#include <iostream>

static const std::string base64_chars =
using unsigned_char_t = unsigned char;

static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
Expand All @@ -47,8 +49,8 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[1] = unsigned_char_t(((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4));
char_array_4[2] = unsigned_char_t(((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6));
char_array_4[3] = char_array_3[2] & 0x3f;

for (i = 0; (i <4) ; i++)
Expand All @@ -62,8 +64,8 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
char_array_3[j] = '\0';

char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[1] = unsigned_char_t(((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4));
char_array_4[2] = unsigned_char_t(((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6));
char_array_4[3] = char_array_3[2] & 0x3f;

for (j = 0; (j < i + 1); j++)
Expand All @@ -77,7 +79,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
}

std::string base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int in_len = int(encoded_string.size());
int i = 0;
int j = 0;
int in_ = 0;
Expand All @@ -88,11 +90,11 @@ std::string base64_decode(std::string const& encoded_string) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i == 4) {
for (i = 0; i < 4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_4[i] = unsigned_char_t(base64_chars.find(char_array_4[i]));

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
char_array_3[0] = unsigned_char_t((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
char_array_3[1] = unsigned_char_t(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
char_array_3[2] = unsigned_char_t(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);

for (i = 0; (i < 3); i++)
ret += char_array_3[i];
Expand All @@ -105,11 +107,11 @@ std::string base64_decode(std::string const& encoded_string) {
char_array_4[j] = 0;

for (j = 0; j < 4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_4[j] = unsigned_char_t(base64_chars.find(char_array_4[j]));

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
char_array_3[0] = unsigned_char_t((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
char_array_3[1] = unsigned_char_t(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
char_array_3[2] = unsigned_char_t(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);

for (j = 0; (j < i - 1); j++)
ret += char_array_3[j];
Expand Down
2 changes: 1 addition & 1 deletion include/snowplow/detail/http/request_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);

return [httpResponse statusCode];
return int([httpResponse statusCode]);
}

#endif
6 changes: 4 additions & 2 deletions include/snowplow/detail/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ string Utils::get_uuid4() {
string Utils::int_list_to_string(const list<int> &int_list, const string &delimiter) {
stringstream s;
int i = 0;
int length = int_list.size();
int length = int(int_list.size());

for (auto const &value : int_list) {
s << value;
Expand All @@ -94,7 +94,7 @@ string Utils::map_to_query_string(map<string, string> m) {
int i;
map<string, string>::iterator it;

int length = m.size();
int length = int(m.size());
for (i = 0, it = m.begin(); it != m.end(); ++it, ++i) {
s << Utils::url_encode(it->first) << "=" << Utils::url_encode(it->second);
if (i < length - 1) {
Expand Down Expand Up @@ -177,6 +177,7 @@ string Utils::get_os_version() {
OSVERSIONINFOEX osviex;
::ZeroMemory(&osviex, sizeof(OSVERSIONINFOEX));
osviex.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma warning(suppress: 4996) // 'GetVersionExW': was declared deprecated
::GetVersionEx((LPOSVERSIONINFO)&osviex);
return to_string(osviex.dwMajorVersion) + "." + to_string(osviex.dwMinorVersion) + "." + to_string(osviex.dwBuildNumber);
}
Expand All @@ -185,6 +186,7 @@ string Utils::get_os_service_pack() {
OSVERSIONINFOEX osviex;
::ZeroMemory(&osviex, sizeof(OSVERSIONINFOEX));
osviex.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma warning(suppress: 4996) // 'GetVersionExW': was declared deprecated
::GetVersionEx((LPOSVERSIONINFO)&osviex);
return to_string(osviex.wServicePackMajor) + "." + to_string(osviex.wServicePackMinor);
}
Expand Down
6 changes: 3 additions & 3 deletions include/snowplow/emitter/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ unique_ptr<HttpClient> createDefaultHttpClient(const string &curl_cookie_file) {

Emitter::Emitter(NetworkConfiguration &network_config, const EmitterConfiguration &emitter_config) :
Emitter(
move(emitter_config.get_event_store()),
emitter_config.get_event_store(),
network_config.get_collector_hostname(),
network_config.get_method(),
network_config.get_protocol(),
emitter_config.get_batch_size(),
emitter_config.get_byte_limit_post(),
emitter_config.get_byte_limit_get(),
move(network_config.move_http_client()),
network_config.move_http_client(),
network_config.get_curl_cookie_file()
) {
m_callback = emitter_config.get_request_callback();
Expand Down Expand Up @@ -223,7 +223,7 @@ void Emitter::do_send(const list<EventRow> &event_rows, list<HttpRequestResult>
int total_byte_size = 0;

for (auto const &row : event_rows) {
unsigned int byte_size = Utils::serialize_payload(row.event).size() + post_stm_bytes;
unsigned int byte_size = unsigned(Utils::serialize_payload(row.event).size() + post_stm_bytes);

if ((byte_size + post_wrapper_bytes) > this->m_byte_limit_post) {
// A single payload has exceeded the Byte Limit
Expand Down
2 changes: 1 addition & 1 deletion include/snowplow/http/http_client_curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ HttpRequestResult HttpClientCurl::http_request(const RequestMethod method, Crack
curl_easy_cleanup(curl);
curl_slist_free_all(headers);

return HttpRequestResult(0, status_code, row_ids, oversize);
return HttpRequestResult(0, int(status_code), row_ids, oversize);
}

#endif
22 changes: 11 additions & 11 deletions include/snowplow/http/http_client_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const string HttpClientWindows::TRACKER_AGENT = string("Snowplow C++ Tracker (Wi

HttpRequestResult HttpClientWindows::http_request(const RequestMethod method, CrackedUrl url, const string &query_string, const string &post_data, list<int> row_ids, bool oversize) {

HINTERNET h_internet = InternetOpen(
TEXT(HttpClientWindows::TRACKER_AGENT.c_str()),
HINTERNET h_internet = InternetOpenA(
HttpClientWindows::TRACKER_AGENT.c_str(),
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
Expand All @@ -42,9 +42,9 @@ HttpRequestResult HttpClientWindows::http_request(const RequestMethod method, Cr
}
}

HINTERNET h_connect = InternetConnect(
HINTERNET h_connect = InternetConnectA(
h_internet,
TEXT(url.get_hostname().c_str()),
url.get_hostname().c_str(),
use_port,
NULL,
NULL,
Expand Down Expand Up @@ -73,14 +73,14 @@ HttpRequestResult HttpClientWindows::http_request(const RequestMethod method, Cr
final_path += "?" + query_string;
} else {
request_method_string = "POST";
post_buf = (LPVOID)TEXT(post_data.c_str());
post_buf_len = strlen(TEXT(post_data.c_str()));
post_buf = (LPVOID)(post_data.c_str());
post_buf_len = int(strlen(post_data.c_str()));
}

HINTERNET h_request = HttpOpenRequest(
HINTERNET h_request = HttpOpenRequestA(
h_connect,
TEXT(request_method_string.c_str()),
TEXT(final_path.c_str()),
request_method_string.c_str(),
final_path.c_str(),
NULL,
NULL,
NULL,
Expand All @@ -93,8 +93,8 @@ HttpRequestResult HttpClientWindows::http_request(const RequestMethod method, Cr
return HttpRequestResult(GetLastError(), 0, row_ids, oversize);
}

LPCSTR hdrs = TEXT("Content-Type: application/json; charset=utf-8");
BOOL is_sent = HttpSendRequest(h_request, hdrs, strlen(hdrs), post_buf, post_buf_len);
LPCSTR hdrs = "Content-Type: application/json; charset=utf-8";
BOOL is_sent = HttpSendRequestA(h_request, hdrs, DWORD(strlen(hdrs)), post_buf, DWORD(post_buf_len));

if (!is_sent) {
InternetCloseHandle(h_internet);
Expand Down
2 changes: 1 addition & 1 deletion include/snowplow/payload/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Payload::add_payload(const Payload &p) {
void Payload::add_json(const json &j, bool base64Encode, const string &encoded, const string &not_encoded) {
if (base64Encode) {
string json_str = j.dump();
this->add(encoded, base64_encode((const unsigned char *)json_str.c_str(), json_str.length()));
this->add(encoded, base64_encode((const unsigned char *)json_str.c_str(), unsigned(json_str.length())));
} else {
this->add(not_encoded, j.dump());
}
Expand Down
19 changes: 9 additions & 10 deletions include/snowplow/snowplow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,37 @@ shared_ptr<Tracker> Snowplow::m_default_tracker = nullptr;

shared_ptr<Tracker> Snowplow::create_tracker(const string &name_space, const string &collector_url, Method method, const string &db_name, shared_ptr<Subject> subject, bool session_tracking) {
auto storage = make_shared<SqliteStorage>(db_name);
return move(
session_tracking ?
return session_tracking ?
create_tracker(name_space, collector_url, method, storage, storage, subject) :
create_tracker(name_space, collector_url, method, storage, subject));
create_tracker(name_space, collector_url, method, storage, subject);
}

shared_ptr<Tracker> Snowplow::create_tracker(const string &name_space, const string &collector_url, Method method, shared_ptr<EventStore> event_store, shared_ptr<Subject> subject) {
NetworkConfiguration network_config(collector_url, method);
return move(create_tracker(
return create_tracker(
TrackerConfiguration(name_space),
network_config,
EmitterConfiguration(move(event_store)),
move(subject)));
move(subject));
}

shared_ptr<Tracker> Snowplow::create_tracker(const string &name_space, const string &collector_url, Method method, shared_ptr<EventStore> event_store, shared_ptr<SessionStore> session_store, shared_ptr<Subject> subject) {
NetworkConfiguration network_config(collector_url, method);
SessionConfiguration session_config(move(session_store));
EmitterConfiguration emitter_config(move(event_store));
return move(create_tracker(
return create_tracker(
TrackerConfiguration(name_space),
network_config,
emitter_config,
session_config,
move(subject)));
move(subject));
}

shared_ptr<Tracker> Snowplow::create_tracker(const TrackerConfiguration &tracker_config, NetworkConfiguration &network_config, const EmitterConfiguration &emitter_config, shared_ptr<Subject> subject) {
auto emitter = make_shared<Emitter>(network_config, emitter_config);
auto tracker = make_shared<Tracker>(tracker_config, move(emitter), move(subject));
register_tracker(tracker);
return move(tracker);
return tracker;
}

shared_ptr<Tracker> Snowplow::create_tracker(const TrackerConfiguration &tracker_config, NetworkConfiguration &network_config, EmitterConfiguration &emitter_config, SessionConfiguration &session_config, shared_ptr<Subject> subject) {
Expand All @@ -68,7 +67,7 @@ shared_ptr<Tracker> Snowplow::create_tracker(const TrackerConfiguration &tracker
auto client_session = make_shared<ClientSession>(session_config);
auto tracker = make_shared<Tracker>(tracker_config, move(emitter), move(subject), move(client_session));
register_tracker(tracker);
return move(tracker);
return tracker;
}

void Snowplow::register_tracker(shared_ptr<Tracker> tracker) {
Expand Down Expand Up @@ -119,7 +118,7 @@ bool Snowplow::remove_tracker(shared_ptr<Tracker> tracker) {

bool Snowplow::remove_tracker(const string &name_space) {
lock_guard<mutex> guard(m_tracker_get);
int num_removed = m_trackers.erase(name_space);
int num_removed = int(m_trackers.erase(name_space));

if (m_default_tracker && m_default_tracker->get_namespace() == name_space) {
m_default_tracker = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions include/snowplow/storage/sqlite_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void SqliteStorage::add_event(const Payload &payload) {

string payload_str = Utils::serialize_payload(payload);

rc = sqlite3_bind_text(this->m_add_stmt, 1, payload_str.c_str(), payload_str.length(), SQLITE_STATIC);
rc = sqlite3_bind_text(this->m_add_stmt, 1, payload_str.c_str(), int(payload_str.length()), SQLITE_STATIC);
if (rc != SQLITE_OK) {
cerr << "ERROR: Failed to bind payload to statement: " << rc << endl;
return;
Expand Down Expand Up @@ -158,7 +158,7 @@ void SqliteStorage::set_session(const json &session_data) {
}

string session_data_str = session_data.dump();
rc = sqlite3_bind_text(insert_stmt, 2, session_data_str.c_str(), session_data_str.length(), SQLITE_STATIC);
rc = sqlite3_bind_text(insert_stmt, 2, session_data_str.c_str(), int(session_data_str.length()), SQLITE_STATIC);
if (rc != SQLITE_OK) {
cerr << "ERROR: Failed to bind data to statement: " << rc << endl;
return;
Expand Down
12 changes: 6 additions & 6 deletions test/integration/micro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ string Micro::request(const string &path) {
NULL,
0);

HINTERNET h_connect = InternetConnect(
HINTERNET h_connect = InternetConnectA(
h_internet,
TEXT(SNOWPLOW_MICRO_HOSTNAME.c_str()),
SNOWPLOW_MICRO_HOSTNAME.c_str(),
9090,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
NULL);

HINTERNET h_request = HttpOpenRequest(
HINTERNET h_request = HttpOpenRequestA(
h_connect,
TEXT("GET"),
TEXT(path.c_str()),
"GET",
path.c_str(),
NULL,
NULL,
NULL,
0 | INTERNET_FLAG_RELOAD,
0);

LPCSTR hdrs = TEXT("Content-Type: application/json; charset=utf-8");
LPCTSTR hdrs = TEXT("Content-Type: application/json; charset=utf-8");
BOOL is_sent = HttpSendRequest(h_request, hdrs, strlen(hdrs), NULL, 0);

string response;
Expand Down

0 comments on commit e1e1d5e

Please sign in to comment.