Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OC_API annotations to oc_buffer_settings.h #647

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 28 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(OC_COMPILER_IS_CLANG ON CACHE BOOL "Compiler is clang." FORCE)
endif()

execute_process(
COMMAND ${CMAKE_LINKER} --version
OUTPUT_VARIABLE LINKER_VERSION
RESULT_VARIABLE LINKER_RESULT
ERROR_QUIET
)

set(OC_LINKER_IS_LD OFF CACHE BOOL "Linker is ld." FORCE)
set(OC_LINKER_IS_LDD OFF CACHE BOOL "Linker is ldd." FORCE)
if(LINKER_RESULT EQUAL 0)
string(TOLOWER "${LINKER_VERSION}" LINKER_VERSION)
if(LINKER_VERSION MATCHES "ldd")
set(OC_LINKER_IS_LDD ON CACHE BOOL "Linker is ldd." FORCE)
elseif(LINKER_VERSION MATCHES "ld")
set(OC_LINKER_IS_LD ON CACHE BOOL "Linker is ld." FORCE)
endif()
endif()

set(OC_COVERAGE_ENABLED OFF CACHE BOOL "Gather code coverage")
if(BUILD_TESTING AND UNIX AND (OC_COMPILER_IS_GCC OR OC_COMPILER_IS_CLANG))
if(NOT(OC_ASAN_ENABLED OR OC_LSAN_ENABLED OR OC_TSAN_ENABLED OR OC_UBSAN_ENABLED))
Expand Down Expand Up @@ -155,18 +173,18 @@ if(UNIX OR (WIN32 AND OC_COMPILER_IS_CLANG))
endif()

# Compiler and linker flags
if(OC_COMPILER_IS_GCC)
set(OC_COMPILE_OPTIONS_RELEASE -fdata-sections -ffunction-sections)
# -Wl,--as-needed = Only link libraries that export symbols used by the binary
# -Wl,--gc-sections = Remove unused code resulting from -fdata-sections and -function-sections
# -s = Strip
set(OC_LINK_OPTIONS_RELEASE -Wl,--as-needed -Wl,--gc-sections -s)
if(OC_LINKER_IS_LD)
set(OC_COMPILE_OPTIONS_RELEASE -fdata-sections -ffunction-sections)
# -Wl,--as-needed = Only link libraries that export symbols used by the binary
# -Wl,--gc-sections = Remove unused code resulting from -fdata-sections and -function-sections
# -s = Strip
set(OC_LINK_OPTIONS_RELEASE -Wl,--as-needed -Wl,--gc-sections -s)
endif()

if(OC_COMPILER_IS_CLANG)
# -Wl,-dead_strip = Remove unused code
if(OC_LINKER_IS_LDD)
# -Wl,-dead_strip = Remove unused code
# -s = Strip
set(OC_LINK_OPTIONS_RELEASE -Wl,-dead_strip -s)
set(OC_LINK_OPTIONS_RELEASE -Wl,-dead_strip -s)
endif()

set(OC_CLANG_TIDY_ENABLED OFF CACHE BOOL "Enable clang-tidy analysis during compilation.")
Expand Down Expand Up @@ -220,7 +238,7 @@ elseif(OC_COMPILER_IS_GCC OR OC_COMPILER_IS_CLANG)
oc_add_compile_options(GLOBAL FLAGS -Wno-error=cast-align -Wno-error=deprecated-declarations
-Wno-error=documentation)
if(MINGW OR (WIN32 AND OC_COMPILER_IS_CLANG))
oc_add_compile_options(GLOBAL FLAGS -Wno-error=gnu-offsetof-extensions -Wno-error=sign-compare)
oc_add_compile_options(GLOBAL FLAGS -Wno-error=gnu-offsetof-extensions -Wno-error=c23-extensions -Wno-error=sign-compare)
endif()
endif()

Expand Down
5 changes: 4 additions & 1 deletion api/cloud/oc_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
#include "oc_api.h"
#include "oc_collection.h"
#include "oc_core_res.h"
#include "oc_network_monitor.h"
#include "port/oc_assert.h"
#include "util/oc_endpoint_address_internal.h"
#include "util/oc_mmem_internal.h"
#include "util/oc_secure_string_internal.h"

#ifdef OC_NETWORK_MONITOR
#include "oc_network_monitor.h"
#endif /* OC_NETWORK_MONITOR */

#ifdef OC_SECURITY
#include "security/oc_tls_internal.h"
#endif /* OC_SECURITY */
Expand Down
1 change: 1 addition & 0 deletions api/cloud/unittest/cloud_store_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "api/cloud/oc_cloud_resource_internal.h"
#include "api/cloud/oc_cloud_store_internal.h"
#include "api/oc_event_callback_internal.h"
#include "api/oc_rep_internal.h"
#include "api/oc_storage_internal.h"
#include "oc_api.h"
#include "oc_config.h"
Expand Down
172 changes: 172 additions & 0 deletions api/oc_buffer_settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/****************************************************************************
*
* Copyright (c) 2017 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License"),
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

#include "oc_buffer_settings.h"
#include "port/oc_log_internal.h"
#include "util/oc_features.h"

#include <stddef.h>

#ifdef OC_DYNAMIC_ALLOCATION

#include "messaging/coap/conf.h"

#ifdef OC_INOUT_BUFFER_SIZE
static size_t _OC_MTU_SIZE = OC_INOUT_BUFFER_SIZE;
#else /* OC_INOUT_BUFFER_SIZE */
static size_t _OC_MTU_SIZE = 2048 + COAP_MAX_HEADER_SIZE;
#endif /* !OC_INOUT_BUFFER_SIZE */

static size_t _OC_MAX_APP_DATA_SIZE = 7168;
#if defined(OC_APP_DATA_BUFFER_SIZE) || !defined(OC_REP_ENCODING_REALLOC)
static size_t _OC_MIN_APP_DATA_SIZE = 7168;
#else /* OC_APP_DATA_BUFFER_SIZE || !OC_REP_ENCODING_REALLOC */
static size_t _OC_MIN_APP_DATA_SIZE = 256;
#endif /* !OC_APP_DATA_BUFFER_SIZE && OC_REP_ENCODING_REALLOC */
static size_t _OC_BLOCK_SIZE = 1024; // FIX
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved

int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
#ifdef OC_INOUT_BUFFER_SIZE
return -1;
#else /* !OC_INOUT_BUFFER_SIZE */
#ifdef OC_BLOCK_WISE
if (mtu_size < (COAP_MAX_HEADER_SIZE + 16)) {
return -1;
}
#ifdef OC_OSCORE
_OC_MTU_SIZE = mtu_size + COAP_MAX_HEADER_SIZE;
#else /* OC_OSCORE */
_OC_MTU_SIZE = mtu_size;
#endif /* !OC_OSCORE */
mtu_size -= COAP_MAX_HEADER_SIZE;
size_t i;
for (i = 10; i >= 4 && (mtu_size >> i) == 0; i--)
;
_OC_BLOCK_SIZE = ((size_t)1) << i;
#endif /* OC_BLOCK_WISE */
return 0;
#endif /* OC_INOUT_BUFFER_SIZE */
}

long
oc_get_mtu_size(void)
{
return (long)_OC_MTU_SIZE;
}

void
oc_set_max_app_data_size(size_t size)
{
#ifdef OC_APP_DATA_BUFFER_SIZE
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE */
_OC_MAX_APP_DATA_SIZE = size;
#ifndef OC_REP_ENCODING_REALLOC
_OC_MIN_APP_DATA_SIZE = size;
#endif /* !OC_REP_ENCODING_REALLOC */
#ifndef OC_BLOCK_WISE
_OC_BLOCK_SIZE = size;
_OC_MTU_SIZE = size + COAP_MAX_HEADER_SIZE;
#endif /* !OC_BLOCK_WISE */
#endif /* OC_APP_DATA_BUFFER_SIZE */
}

long
oc_get_max_app_data_size(void)
{
return (long)_OC_MAX_APP_DATA_SIZE;
}
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved

void
oc_set_min_app_data_size(size_t size)
{
#if defined(OC_APP_DATA_BUFFER_SIZE) || !defined(OC_REP_ENCODING_REALLOC)
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE && !OC_REP_ENCODING_REALLOC */
_OC_MIN_APP_DATA_SIZE = size;
#endif /* OC_APP_DATA_BUFFER_SIZE || !OC_REP_ENCODING_REALLOC */
}

long
oc_get_min_app_data_size(void)
{
return (long)_OC_MIN_APP_DATA_SIZE;
}

long
oc_get_block_size(void)
{
return (long)_OC_BLOCK_SIZE;
}

#else /* !OC_DYNAMIC_ALLOCATION */

int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_mtu_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_max_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_max_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_min_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_min_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_block_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved

#endif /* OC_DYNAMIC_ALLOCATION */
6 changes: 4 additions & 2 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ oc_wkcore_discovery_handler(oc_request_t *request,
}
}

if (rt_request != 0 && rt_device != 0 &&
if (rt_request != NULL && rt_device != NULL &&
strncmp(rt_request, rt_device, rt_len) == 0) {
/* request for specific device type */
matches = 1;
Expand Down Expand Up @@ -1273,7 +1273,9 @@ oc_wkcore_discovery_handler(oc_request_t *request,

length += clf_add_line_to_buffer("/oic/res>;");
length += clf_add_line_to_buffer("rt=\"oic.wk.res ");
length += clf_add_str_to_buffer(rt_device, rt_devlen);
if (rt_device != NULL) {
length += clf_add_str_to_buffer(rt_device, rt_devlen);
}
length += clf_add_line_to_buffer("\";");
length +=
clf_add_line_to_buffer("if=\"oic.if.ll oic.if.baseline\";ct=10000");
Expand Down
7 changes: 4 additions & 3 deletions api/oc_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "port/oc_random.h"
#include "util/oc_macros_internal.h"
#include "util/oc_mmem_internal.h"
#include "util/oc_secure_string_internal.h"
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
Expand Down Expand Up @@ -141,7 +142,7 @@ oc_set_string(oc_string_t *dst, const char *str, size_t str_len)
// oc_free_string
oc_new_string(&copy, str, str_len);
oc_free_string(dst);
oc_new_string(dst, oc_string(copy), oc_string_len(copy));
oc_new_string(dst, oc_string(copy), oc_string_len_unsafe(copy));
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved
oc_free_string(&copy);
#endif /* OC_DYNAMIC_ALLOCATION */
}
Expand Down Expand Up @@ -311,7 +312,7 @@ bool
_oc_copy_string_to_array(oc_string_array_t *ocstringarray, const char str[],
size_t index)
{
size_t len = strlen(str);
size_t len = oc_strnlen(str, STRING_ARRAY_ITEM_MAX_LEN);
if (len >= STRING_ARRAY_ITEM_MAX_LEN) {
return false;
}
Expand Down Expand Up @@ -351,7 +352,7 @@ oc_join_string_array(oc_string_array_t *ocstringarray, oc_string_t *ocstring)
++i) {
const char *item =
(const char *)oc_string_array_get_item(*ocstringarray, i);
size_t item_len = strlen(item);
size_t item_len = oc_strnlen(item, STRING_ARRAY_ITEM_MAX_LEN);
if (item_len != 0) {
if (len > 0) {
oc_string(*ocstring)[len] = ' ';
Expand Down
Loading
Loading