Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d057ce8
Replace sprintf usage with snprintf or asprintf
pnoltes Dec 16, 2022
32e3000
Refactor pubsubProtocol_encodeMetadata for improved handling and remo…
pnoltes Dec 28, 2022
b43e184
Add extra content size output argument for encoding metadata in the p…
pnoltes Dec 29, 2022
824d63c
Improve existing buffer handling for the pubsub protocol encoding of …
pnoltes Dec 29, 2022
2b720bd
Replaces use of snprintf for asprint in deployment_admin.c
pnoltes Dec 30, 2022
c809a00
Add check to asprintf return
pnoltes Dec 30, 2022
76aa019
Add __attribute__((format)) usage and add -Wformat=2 compile flag
pnoltes Dec 30, 2022
7951756
Improve and add some missing handling of snprintf return values
pnoltes Dec 30, 2022
32b6061
Add missing __attribute__((format(printf))) to celix log utils.
pnoltes Dec 30, 2022
b37a1e2
Merge remote-tracking branch 'origin/master' into feature/remove_spri…
pnoltes Dec 30, 2022
dc6f2c7
Add CMAKE_DL_LIBS libaries to celix_pswp_common_tests
pnoltes Dec 30, 2022
b74b76f
Remove usage of dlerror in unit test
pnoltes Dec 30, 2022
5dca466
Configure explicit conversion for protocol test
pnoltes Dec 30, 2022
2f75f7e
Configure malloc return null test behind a compile option
pnoltes Dec 30, 2022
5929594
Merge remote-tracking branch 'origin/master' into feature/remove_spri…
pnoltes Dec 31, 2022
e772447
Add __attribute__((format)) to BundleContext.h
pnoltes Dec 31, 2022
61940ed
Replaced some usage of %lu for size_t to %zu
pnoltes Dec 31, 2022
4441d02
Fix C++ wrong log methods usage concerning formatting
pnoltes Dec 31, 2022
cb38595
Update bundles/pubsub/pubsub_spi/include/pubsub_protocol.h
PengZheng Jan 6, 2023
80da770
Update bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c
PengZheng Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ endif ()

# Set C specific flags
set(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 -fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Werror -Wno-error=deprecated-declarations ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Werror -Wformat -Wno-error=deprecated-declarations ${CMAKE_C_FLAGS}")

# Set C++ specific flags
set(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -Weffc++ -Wformat -Wno-error=deprecated-declarations ${CMAKE_CXX_FLAGS}")

if (NOT DEFINED CMAKE_CXX_STANDARD)
#Celix header only C++ supported is based on C++14 and C++17.
#Default using C++14 to ensure the code compiles for C++14.
Expand All @@ -91,9 +94,6 @@ if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif ()

set(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -Weffc++ -Wno-error=deprecated-declarations ${CMAKE_CXX_FLAGS}")

if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif()
Expand Down
28 changes: 7 additions & 21 deletions bundles/deployment_admin/src/deployment_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
/**
* deployment_admin.c
*
* \date Nov 7, 2011
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/

#include <stddef.h>
#include <stdlib.h>
Expand Down Expand Up @@ -136,16 +129,6 @@ celix_status_t deploymentAdmin_create(bundle_context_pt context, deployment_admi
(*admin)->pollUrl = strdup(pollUrl);
(*admin)->auditlogUrl = strdup(auditlogUrl);

// log_store_pt store = NULL;
// log_t *log = NULL;
// log_sync_pt sync = NULL;
// logStore_create(subpool, &store);
// log_create(subpool, store, &log);
// logSync_create(subpool, (*admin)->targetIdentification, store, &sync);
//
// log_log(log, 20000, NULL);


celixThread_create(&(*admin)->poller, NULL, deploymentAdmin_poll, *admin);
}
}
Expand Down Expand Up @@ -199,19 +182,22 @@ static celix_status_t deploymentAdmin_performRequest(deployment_admin_pt admin,
fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Error initializing curl.");
}

char url[strlen(admin->auditlogUrl)+6];
sprintf(url, "%s/send", admin->auditlogUrl);
char* url;
int rc = asprintf(&url, "%s/send", admin->auditlogUrl);
status = rc < 0 ? CELIX_ENOMEM : CELIX_SUCCESS;

if (status == CELIX_SUCCESS) {
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, entry);
res = curl_easy_perform(curl);

if (res != CURLE_OK ) {
status = CELIX_BUNDLE_EXCEPTION;
fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Error sending auditlog, got curl error code %d", res);
fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Error sending auditlog to %s, got curl error code %d", url, res);
}
free(url);
} else {
fw_log(celix_frameworkLogger_globalLogger(), CELIX_LOG_LEVEL_ERROR, "Error creating send url for audit log url: %s", admin->auditlogUrl);
}

return status;
Expand Down
36 changes: 26 additions & 10 deletions bundles/logging/log_service_api/include/celix_log_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,38 @@ typedef struct celix_log_service {
/**
* Logs a trace message, printf style.
*/
void (*trace)(void *handle, const char* format, ...);
void (*trace)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a debug message, printf style.
*/
void (*debug)(void *handle, const char* format, ...);
void (*debug)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a info message, printf style.
*/
void (*info)(void *handle, const char* format, ...);
void (*info)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a warning message, printf style.
*/
void (*warning)(void *handle, const char* format, ...);
void (*warning)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a error message, printf style.
*/
void (*error)(void *handle, const char* format, ...);
void (*error)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a fatal message, printf style.
*/
void (*fatal)(void *handle, const char* format, ...);
void (*fatal)(void *handle, const char* format, ...) __attribute__((format(printf,2,3)));

/**
* Logs a message using the provided log level, printf style
* Silently ignores log level CELIX_LOG_LEVEL_DISABLED.
*/
void (*log)(void *handle, celix_log_level_e level, const char* format, ...);
void (*log)(void *handle, celix_log_level_e level, const char* format, ...) __attribute__((format(printf,3,4)));

/**
* Logs a message using the provided log level, printf style
Expand All @@ -92,13 +92,22 @@ typedef struct celix_log_service {
*
* If the argument file or function is NULL, the arguments file, function and line are not used.
*/
void (*logDetails)(void *handle, celix_log_level_e level, const char* file, const char* function, int line, const char* format, ...);
void (*logDetails)(
void *handle, celix_log_level_e level,
const char* file,
const char* function,
int line,
const char* format, ...) __attribute__((format(printf,6,7)));

/**
* Log a message using a format string and va_list argument (vprintf style)
* Silently ignores log level CELIX_LOG_LEVEL_DISABLED.
*/
void (*vlog)(void *handle, celix_log_level_e level, const char* format, va_list formatArgs);
void (*vlog)(
void *handle,
celix_log_level_e level,
const char* format,
va_list formatArgs) __attribute__((format(printf,3,0)));

/**
* Log a detailed message using a format string and va_list argument (vprintf style)
Expand All @@ -109,7 +118,14 @@ typedef struct celix_log_service {
*
* If the argument file or function is NULL, the arguments file, function and line are not used.
*/
void (*vlogDetails)(void *handle, celix_log_level_e level, const char* file, const char* function, int line, const char* format, va_list formatArgs);
void (*vlogDetails)(
void *handle,
celix_log_level_e level,
const char* file,
const char* function,
int line,
const char* format,
va_list formatArgs) __attribute__((format(printf,6,0)));
} celix_log_service_t;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_F(SyslogWriterTestSuite, LogToSysLog) {
buf[i] = 'A';
}
buf[2047] = '\0';
ls->fatal(ls->handle, buf);
ls->fatal(ls->handle, "%s", buf);
};
bool called = celix_bundleContext_useServiceWithOptions(ctx.get(), &opts);
EXPECT_TRUE(called);
Expand Down
14 changes: 4 additions & 10 deletions bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,16 +1034,13 @@ int pubsub_tcpHandler_write(pubsub_tcpHandler_t *handle, pubsub_protocol_message
message->header.payloadOffset = 0;
message->header.isLastSegment = 1;

void *metadataData = NULL;
size_t metadataSize = 0;
if (message->metadata.metadata) {
metadataSize = entry->writeMetaBufferSize;
metadataData = entry->writeMetaBuffer;
handle->protocol->encodeMetadata(handle->protocol->handle, message, &entry->writeMetaBuffer, &entry->writeMetaBufferSize, &metadataSize);
// When maxMsgSize is smaller then meta data is disabled
if (metadataSize > entry->maxMsgSize) {
if (metadataSize > entry->maxMsgSize) {
metadataSize = 0;
}
handle->protocol->encodeMetadata(handle->protocol->handle, message, &metadataData, &metadataSize);
}

message->header.metadataSize = metadataSize;
Expand Down Expand Up @@ -1119,10 +1116,10 @@ int pubsub_tcpHandler_write(pubsub_tcpHandler_t *handle, pubsub_protocol_message

// Write optional metadata in vector buffer
if (allPayloadAdded &&
(metadataSize != 0 && metadataData) &&
(metadataSize != 0 && entry->writeMetaBuffer) &&
(msgPartSize < maxMsgSize) &&
(msg.msg_iovlen-1 < max_msg_iov_len)) { // header is already included
msg.msg_iov[msg.msg_iovlen].iov_base = metadataData;
msg.msg_iov[msg.msg_iovlen].iov_base = entry->writeMetaBuffer;
msg.msg_iov[msg.msg_iovlen].iov_len = metadataSize;
msg.msg_iovlen++;
msgPartSize += metadataSize;
Expand Down Expand Up @@ -1202,9 +1199,6 @@ int pubsub_tcpHandler_write(pubsub_tcpHandler_t *handle, pubsub_protocol_message
if (payloadData && (payloadData != message->payload.payload)) {
free(payloadData);
}
if (metadataData && metadataSize > 0) {
free(metadataData);
}
}
celixThreadMutex_unlock(&entry->writeMutex);
}
Expand Down
15 changes: 8 additions & 7 deletions bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_topic_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,10 @@ static int psa_zmq_topicPublicationSend(void* handle, unsigned int msgTypeId, co
size_t payloadLength = 0;
sender->protocol->encodePayload(sender->protocol->handle, &message, &payloadData, &payloadLength);

size_t metadataSize = 0;
if (metadata != NULL) {
message.metadata.metadata = metadata;
sender->protocol->encodeMetadata(sender->protocol->handle, &message, &sender->zmqBuffers.metadataBuffer, &sender->zmqBuffers.metadataBufferSize);
sender->protocol->encodeMetadata(sender->protocol->handle, &message, &sender->zmqBuffers.metadataBuffer, &sender->zmqBuffers.metadataBufferSize, &metadataSize);
} else {
message.metadata.metadata = NULL;
}
Expand All @@ -452,7 +453,7 @@ static int psa_zmq_topicPublicationSend(void* handle, unsigned int msgTypeId, co
message.header.msgMajorVersion = majorVersion;
message.header.msgMinorVersion = minorversion;
message.header.payloadSize = payloadLength;
message.header.metadataSize = sender->zmqBuffers.metadataBufferSize;
message.header.metadataSize = metadataSize;
message.header.payloadPartSize = payloadLength;
message.header.payloadOffset = 0;
message.header.isLastSegment = 1;
Expand Down Expand Up @@ -484,7 +485,7 @@ static int psa_zmq_topicPublicationSend(void* handle, unsigned int msgTypeId, co

//send Payload
if (rc > 0) {
int flag = ((sender->zmqBuffers.metadataBufferSize > 0) || (sender->zmqBuffers.footerBufferSize > 0)) ? ZMQ_SNDMORE : 0;
int flag = ((metadataSize > 0) || (sender->zmqBuffers.footerBufferSize > 0)) ? ZMQ_SNDMORE : 0;
zmq_msg_init_data(&msg2, payloadData, payloadLength, psa_zmq_freeMsg, freeMsgEntry);
rc = zmq_msg_send(&msg2, socket, flag);
if (rc == -1) {
Expand All @@ -494,9 +495,9 @@ static int psa_zmq_topicPublicationSend(void* handle, unsigned int msgTypeId, co
}

//send MetaData
if (rc > 0 && sender->zmqBuffers.metadataBufferSize > 0) {
if (rc > 0 && metadataSize > 0) {
int flag = (sender->zmqBuffers.footerBufferSize > 0 ) ? ZMQ_SNDMORE : 0;
zmq_msg_init_data(&msg3, sender->zmqBuffers.metadataBuffer, sender->zmqBuffers.metadataBufferSize, NULL, NULL);
zmq_msg_init_data(&msg3, sender->zmqBuffers.metadataBuffer, metadataSize, NULL, NULL);
rc = zmq_msg_send(&msg3, socket, flag);
if (rc == -1) {
L_WARN("Error sending metadata msg. %s", strerror(errno));
Expand All @@ -519,8 +520,8 @@ static int psa_zmq_topicPublicationSend(void* handle, unsigned int msgTypeId, co
zmsg_t *msg = zmsg_new();
zmsg_addmem(msg, sender->zmqBuffers.headerBuffer, sender->zmqBuffers.headerBufferSize);
zmsg_addmem(msg, payloadData, payloadLength);
if (sender->zmqBuffers.metadataBufferSize > 0) {
zmsg_addmem(msg, sender->zmqBuffers.metadataBuffer, sender->zmqBuffers.metadataBufferSize);
if (metadataSize > 0) {
zmsg_addmem(msg, sender->zmqBuffers.metadataBuffer, metadataSize);
}
if (sender->zmqBuffers.footerBufferSize > 0) {
zmsg_addmem(msg, sender->zmqBuffers.footerBuffer, sender->zmqBuffers.footerBufferSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
# specific language governing permissions and limitations
# under the License.

set(SOURCES
src/main.cc
src/PS_WP_common_tests.cc
)
add_executable(celix_pswp_common_tests ${SOURCES})
#target_include_directories(celix_cxx_pswp_tests SYSTEM PRIVATE gtest)
add_executable(celix_pswp_common_tests src/PS_WP_common_tests.cc)
target_include_directories(celix_pswp_common_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src)
target_link_libraries(celix_pswp_common_tests PRIVATE celix_pubsub_protocol_lib GTest::gtest Celix::pubsub_spi)
target_link_libraries(celix_pswp_common_tests PRIVATE celix_pubsub_protocol_lib GTest::gtest Celix::pubsub_spi GTest::gtest_main ${CMAKE_DL_LIBS})
if (NOT ENABLE_ADDRESS_SANITIZER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge the current malloc mocking. I'll make another PR proposing a general error injector playing nicely with address sanitizers.

target_compile_definitions(celix_pswp_common_tests PRIVATE ENABLE_MALLOC_RETURN_NULL_TESTS)
endif ()

add_test(NAME celix_pswp_common_tests COMMAND celix_pswp_common_tests)
setup_target_for_coverage(celix_pswp_common_tests SCAN_DIR ..)
Loading