Skip to content

Commit

Permalink
Add OC_API annotations to public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Jan 11, 2025
1 parent 563520d commit 4cbd9dc
Show file tree
Hide file tree
Showing 30 changed files with 486 additions and 247 deletions.
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

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;
}

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;
}

#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));
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

0 comments on commit 4cbd9dc

Please sign in to comment.