KNX IoT
KNX IoT Point API stack implementation
oc_helpers.h File Reference

generic helpers More...

#include "util/oc_list.h"
#include "util/oc_mmem.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define _ECHO
 
#define _MAKE_NULL(...)   NULL
 
#define oc_alloc_string(ocstring, size)   _oc_alloc_string((ocstring), (size))
 allocate oc_string More...
 
#define oc_bool_array(ocboolarray)   (oc_cast(ocboolarray, bool))
 
#define oc_bool_array_create_const(f, n, ...)    oc_mmem_create_const(n, f((const bool[n]){ __VA_ARGS__ }))
 
#define oc_bool_array_size(ocboolarray)   ((ocboolarray).size)
 
#define oc_byte_string_array_add_item(ocstringarray, str, str_len)    (_oc_byte_string_array_add_item(&(ocstringarray), str, str_len))
 
#define oc_byte_string_array_get_allocated_size(ocstringarray)    ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN)
 
#define oc_byte_string_array_get_item(ocstringarray, index)    (oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN + 1)
 
#define oc_byte_string_array_get_item_size(ocstringarray, index)    (*(oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN))
 
#define oc_byte_string_array_set_item(ocstringarray, str, str_len, index)    (_oc_copy_byte_string_to_array(&(ocstringarray), str, str_len, index))
 
#define oc_byte_string_len(ocstring)   ((ocstring).size)
 
#define oc_cast(block, type)   ((type *)(OC_MMEM_PTR(&(block))))
 
#define oc_double_array(ocdoublearray)   (oc_cast(ocdoublearray, double))
 
#define oc_double_array_create_const(f, n, ...)    oc_mmem_create_const(n, f((const double[n]){ __VA_ARGS__ }))
 
#define oc_double_array_size(ocdoublearray)   ((ocdoublearray).size)
 
#define oc_float_array(ocfloatarray)   (oc_cast(ocfloatarray, float))
 
#define oc_float_array_create_const(f, n, ...)    oc_mmem_create_const(n, f((const float[n]){ __VA_ARGS__ }))
 
#define oc_float_array_size(ocfloatarray)   ((ocfloatarray).size)
 
#define oc_free_bool_array(ocarray)   (_oc_free_array(ocarray, BYTE_POOL))
 free array of booleans More...
 
#define oc_free_byte_string_array(ocstringarray)    (_oc_free_string(ocstringarray))
 
#define oc_free_double_array(ocarray)   (_oc_free_array(ocarray, DOUBLE_POOL))
 free array of doubles More...
 
#define oc_free_float_array(ocarray)   (_oc_free_array(ocarray, FLOAT_POOL))
 free array of floats More...
 
#define oc_free_int_array(ocarray)   (_oc_free_array(ocarray, INT_POOL))
 free array of integers More...
 
#define oc_free_string(ocstring)   _oc_free_string(ocstring)
 free ocstring More...
 
#define oc_free_string_array(ocstringarray)   (_oc_free_string(ocstringarray))
 free oc string array More...
 
#define oc_int_array(ocintarray)   (oc_cast(ocintarray, int64_t))
 
#define oc_int_array_create_const(f, n, ...)    oc_mmem_create_const(n, f((const int64_t[n]){ __VA_ARGS__ }))
 
#define oc_int_array_size(ocintarray)   ((ocintarray).size)
 
#define oc_mmem_create_const(count, ptr)
 Helper macros to create const versions of oc types These are special and need some help to understand things correctly. More...
 
#define oc_new_bool_array(ocarray, size)    (_oc_new_array(ocarray, size, BYTE_POOL))
 new boolean array More...
 
#define oc_new_byte_string(ocstring, str, str_len)    _oc_new_byte_string(ocstring, str, str_len)
 create new (byte) string from string (not null terminated) More...
 
#define oc_new_byte_string_array(ocstringarray, size)    (_oc_alloc_string_array(ocstringarray, size))
 
#define oc_new_double_array(ocarray, size)    (_oc_new_array(ocarray, size, DOUBLE_POOL))
 new double array More...
 
#define oc_new_float_array(ocarray, size)    (_oc_new_array(ocarray, size, FLOAT_POOL))
 new float array More...
 
#define oc_new_int_array(ocarray, size)   (_oc_new_array(ocarray, size, INT_POOL))
 new integer array More...
 
#define oc_new_string(ocstring, str, str_len)    _oc_new_string(ocstring, str, str_len)
 create new string from string (null terminated) More...
 
#define oc_new_string_array(ocstringarray, size)    (_oc_alloc_string_array(ocstringarray, size))
 new oc string array More...
 
#define OC_SIZE_MANY(x)   _ECHO, x
 
#define OC_SIZE_ZERO()   _MAKE_NULL, 0
 
#define oc_string(ocstring)   (oc_cast(ocstring, char))
 cast oc_string to string More...
 
#define oc_string_array(ocstringarray)    ((char(*)[STRING_ARRAY_ITEM_MAX_LEN])(OC_MMEM_PTR(&(ocstringarray))))
 
#define oc_string_array_add_item(ocstringarray, str)    (_oc_string_array_add_item(&(ocstringarray), str))
 
#define oc_string_array_create_const(f, n, ...)
 
#define oc_string_array_get_allocated_size(ocstringarray)    ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN)
 
#define oc_string_array_get_item(ocstringarray, index)    (oc_string(ocstringarray) + (index)*STRING_ARRAY_ITEM_MAX_LEN)
 
#define oc_string_array_get_item_size(ocstringarray, index)    (strlen((const char *)oc_string_array_get_item(ocstringarray, index)))
 
#define oc_string_array_set_item(ocstringarray, str, index)    (_oc_copy_string_to_array(&(ocstringarray), str, index))
 
#define oc_string_array_size(ocstringarray)    ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN)
 
#define oc_string_checked(ocstring)    (oc_cast(ocstring, char) ? oc_cast(ocstring, char) : "NULL")
 cast oc_string to string, replace null pointer results with a pointer to "NULL" More...
 
#define oc_string_create_const(s)   oc_mmem_create_const(sizeof(s), s)
 
#define oc_string_len(ocstring)   ((ocstring).size ? (ocstring).size - 1 : 0)
 
#define STRING_ARRAY_ITEM_MAX_LEN   32
 

Typedefs

typedef struct oc_mmem oc_array_t
 
typedef struct oc_mmem oc_byte_string_array_t
 
typedef struct oc_mmem oc_handle_t
 
typedef struct oc_mmem oc_string_array_t
 
typedef struct oc_mmem oc_string_t
 

Enumerations

enum  StringRepresentation { DEC_REPRESENTATION = 0 , HEX_REPRESENTATION }
 

Functions

void _oc_alloc_string (oc_string_t *ocstring, size_t size)
 allocate oc_string More...
 
void _oc_alloc_string_array (oc_string_array_t *ocstringarray, size_t size)
 allocate string array More...
 
bool _oc_byte_string_array_add_item (oc_string_array_t *ocstringarray, const char str[], size_t str_len)
 
bool _oc_copy_byte_string_to_array (oc_string_array_t *ocstringarray, const char str[], size_t str_len, size_t index)
 
bool _oc_copy_string_to_array (oc_string_array_t *ocstringarray, const char str[], size_t index)
 
void _oc_free_array (oc_array_t *ocarray, pool type)
 free array More...
 
void _oc_free_string (oc_string_t *ocstring)
 free oc string More...
 
void _oc_new_array (oc_array_t *ocarray, size_t size, pool type)
 new array More...
 
void _oc_new_byte_string (oc_string_t *ocstring, const char *str, size_t str_len)
 new oc_string byte from string More...
 
void _oc_new_string (oc_string_t *ocstring, const char *str, size_t str_len)
 new oc_string from string More...
 
bool _oc_string_array_add_item (oc_string_array_t *ocstringarray, const char str[])
 
int oc_byte_string_cmp (oc_string_t string1, oc_string_t string2)
 oc_string compare for byte strings (no null terminator) More...
 
int oc_byte_string_copy (oc_string_t *string1, oc_string_t string2)
 copy oc_string used as a byte string More...
 
int oc_byte_string_copy_from_char_with_size (oc_string_t *string1, const char *string2, size_t string2_len)
 copy byte string from char* More...
 
int oc_char_convert_to_lower (char *string)
 converts the input string to lower case More...
 
int oc_char_print_hex (const char *str, int str_len)
 prints the string as hex More...
 
int oc_char_println_hex (const char *str, int str_len)
 prints the input as hex string with newline (
) at the end. More...
 
void oc_concat_strings (oc_string_t *concat, const char *str1, const char *str2)
 
int oc_conv_byte_array_to_hex_string (const uint8_t *array, size_t array_len, char *hex_str, size_t *hex_str_len)
 Conversions between hex encoded strings and byte arrays. More...
 
int oc_conv_hex_string_to_byte_array (const char *hex_str, size_t hex_str_len, uint8_t *array, size_t *array_len)
 convert hex string to byte array More...
 
int oc_conv_hex_string_to_oc_string (const char *hex_str, size_t hex_str_len, oc_string_t *out)
 convert hex string to oc_string More...
 
int oc_conv_uint64_to_dec_string (char *str, uint64_t number)
 Converts a uint64_t to a decimal string representation. More...
 
int oc_conv_uint64_to_hex_string (char *str, uint64_t number)
 Converts a uint64_t to a hex string representation. More...
 
int oc_get_sn_from_ep (const char *param, int param_len, char *sn, int sn_len, uint32_t *ia)
 retrieves the serial number and individual address from the ep parameter More...
 
int oc_get_sn_ia_iid_from_ep (const char *param, int param_len, char *sn, int sn_len, uint32_t *ia, uint64_t *iid)
 retrieves the serial number and individual address from the ep parameter More...
 
void oc_join_string_array (oc_string_array_t *ocstringarray, oc_string_t *ocstring)
 
int oc_print_uint64_t (uint64_t number, enum StringRepresentation rep)
 print a uint64_t, in either decimal or hex representation More...
 
int oc_string_cmp (oc_string_t string1, oc_string_t string2)
 oc_string compare More...
 
int oc_string_copy (oc_string_t *string1, oc_string_t string2)
 copy oc_string More...
 
int oc_string_copy_from_char (oc_string_t *string1, const char *string2)
 copy string from char* More...
 
int oc_string_copy_from_char_with_size (oc_string_t *string1, const char *string2, size_t string2_len)
 copy string from char* More...
 
int oc_string_is_hex_array (oc_string_t hex_string)
 checks if the input is an array containing hex values e.g. More...
 
int oc_string_print_hex (oc_string_t hex_string)
 prints the input as hex string More...
 
int oc_string_println_hex (oc_string_t hex_string)
 prints the input as hex string with newline (
) at the end. More...
 
char * oc_strnchr (const char *string, char p, int size)
 search a string (non null terminated) for a character More...
 
bool oc_uri_contains_wildcard (const char *uri)
 checks if the uri contains a wildcard (e.g. More...
 
bool oc_uri_contains_wildcard_value_underscore (const char *uri_resource, size_t uri_len, const char *uri_invoked, size_t invoked_len)
 function to check if in the wild card section is a "_" (underscore) underscores can be used in functional block uri to have more than 1 instance e.g. More...
 
int oc_uri_get_wildcard_value_as_int (const char *uri_resource, size_t uri_len, const char *uri_invoked, size_t invoked_len)
 retrieve the wild card value as integer The invoked URI is checked against the URI of a resource that might contain a wild card, if the resource URI contains a wild card then the invoked URI is compared against this URI and e.g. More...
 
int oc_uri_get_wildcard_value_as_int_after_underscore (const char *uri_resource, size_t uri_len, const char *uri_invoked, size_t invoked_len)
 retrieve the integer after the "_" (underscore) e.g. More...
 
int oc_uri_get_wildcard_value_as_string (const char *uri_resource, size_t uri_len, const char *uri_invoked, size_t invoked_len, const char **value)
 retrieve the wild card value as string The invoked URI is checked against the URI of a resource that might contain a wild card, if the resource URI contains a wild card then the invoked URI is compared against this URI and e.g. More...
 
int oc_url_cmp (oc_string_t string1, oc_string_t string2)
 url compare same as string compare but ignores the leading / of the urls More...
 

Detailed Description

generic helpers

Definition in file oc_helpers.h.

Macro Definition Documentation

◆ oc_alloc_string

#define oc_alloc_string (   ocstring,
  size 
)    _oc_alloc_string((ocstring), (size))

allocate oc_string

Definition at line 101 of file oc_helpers.h.

◆ oc_free_bool_array

#define oc_free_bool_array (   ocarray)    (_oc_free_array(ocarray, BYTE_POOL))

free array of booleans

Definition at line 133 of file oc_helpers.h.

◆ oc_free_double_array

#define oc_free_double_array (   ocarray)    (_oc_free_array(ocarray, DOUBLE_POOL))

free array of doubles

Definition at line 145 of file oc_helpers.h.

◆ oc_free_float_array

#define oc_free_float_array (   ocarray)    (_oc_free_array(ocarray, FLOAT_POOL))

free array of floats

Definition at line 139 of file oc_helpers.h.

◆ oc_free_int_array

#define oc_free_int_array (   ocarray)    (_oc_free_array(ocarray, INT_POOL))

free array of integers

Definition at line 127 of file oc_helpers.h.

◆ oc_free_string

#define oc_free_string (   ocstring)    _oc_free_string(ocstring)

free ocstring

Definition at line 121 of file oc_helpers.h.

◆ oc_free_string_array

#define oc_free_string_array (   ocstringarray)    (_oc_free_string(ocstringarray))

free oc string array

Definition at line 185 of file oc_helpers.h.

◆ oc_mmem_create_const

#define oc_mmem_create_const (   count,
  ptr 
)
Value:
{ \
NULL, count, ptr \
}

Helper macros to create const versions of oc types These are special and need some help to understand things correctly.

creates a const oc_mmem struct unlikely to be used outside of the library

Parameters
countnumber of elements
ptrpointer to const data

Definition at line 208 of file oc_helpers.h.

◆ oc_new_bool_array

#define oc_new_bool_array (   ocarray,
  size 
)     (_oc_new_array(ocarray, size, BYTE_POOL))

new boolean array

Definition at line 157 of file oc_helpers.h.

◆ oc_new_byte_string

#define oc_new_byte_string (   ocstring,
  str,
  str_len 
)     _oc_new_byte_string(ocstring, str, str_len)

create new (byte) string from string (not null terminated)

Definition at line 114 of file oc_helpers.h.

◆ oc_new_double_array

#define oc_new_double_array (   ocarray,
  size 
)     (_oc_new_array(ocarray, size, DOUBLE_POOL))

new double array

Definition at line 171 of file oc_helpers.h.

◆ oc_new_float_array

#define oc_new_float_array (   ocarray,
  size 
)     (_oc_new_array(ocarray, size, FLOAT_POOL))

new float array

Definition at line 164 of file oc_helpers.h.

◆ oc_new_int_array

#define oc_new_int_array (   ocarray,
  size 
)    (_oc_new_array(ocarray, size, INT_POOL))

new integer array

Definition at line 151 of file oc_helpers.h.

◆ oc_new_string

#define oc_new_string (   ocstring,
  str,
  str_len 
)     _oc_new_string(ocstring, str, str_len)

create new string from string (null terminated)

Definition at line 107 of file oc_helpers.h.

◆ oc_new_string_array

#define oc_new_string_array (   ocstringarray,
  size 
)     (_oc_alloc_string_array(ocstringarray, size))

new oc string array

Definition at line 178 of file oc_helpers.h.

◆ oc_string

#define oc_string (   ocstring)    (oc_cast(ocstring, char))

cast oc_string to string

Definition at line 49 of file oc_helpers.h.

◆ oc_string_array_create_const

#define oc_string_array_create_const (   f,
  n,
  ... 
)
Value:
(n * STRING_ARRAY_ITEM_MAX_LEN), \
f((const char[n][STRING_ARRAY_ITEM_MAX_LEN]){ __VA_ARGS__ }))
#define oc_mmem_create_const(count, ptr)
Helper macros to create const versions of oc types These are special and need some help to understand...
Definition: oc_helpers.h:208

Definition at line 213 of file oc_helpers.h.

◆ oc_string_checked

#define oc_string_checked (   ocstring)     (oc_cast(ocstring, char) ? oc_cast(ocstring, char) : "NULL")

cast oc_string to string, replace null pointer results with a pointer to "NULL"

Definition at line 56 of file oc_helpers.h.

Function Documentation

◆ _oc_alloc_string()

void _oc_alloc_string ( oc_string_t *  ocstring,
size_t  size 
)

allocate oc_string

Parameters
ocstringthe ocstring to be allocated
sizesize to be allocated

◆ _oc_alloc_string_array()

void _oc_alloc_string_array ( oc_string_array_t *  ocstringarray,
size_t  size 
)

allocate string array

Parameters
ocstringarrayarray to be allocated
sizethe size of the string array

◆ _oc_free_array()

void _oc_free_array ( oc_array_t *  ocarray,
pool  type 
)

free array

Parameters
ocarraythe ocarray to be freed
typepool type

◆ _oc_free_string()

void _oc_free_string ( oc_string_t *  ocstring)

free oc string

Parameters
ocstringthe ocstring to be freed

◆ _oc_new_array()

void _oc_new_array ( oc_array_t *  ocarray,
size_t  size,
pool  type 
)

new array

Parameters
ocarraythe ocarray to be freed
sizethe size to be allocated
typepool type

◆ _oc_new_byte_string()

void _oc_new_byte_string ( oc_string_t *  ocstring,
const char *  str,
size_t  str_len 
)

new oc_string byte from string

Parameters
ocstringthe ocstring to be allocated
strnot terminated string
str_lensize of the string to be copied

◆ _oc_new_string()

void _oc_new_string ( oc_string_t *  ocstring,
const char *  str,
size_t  str_len 
)

new oc_string from string

Parameters
ocstringthe ocstring to be allocated
strterminated string
str_lensize of the string to be copied

◆ oc_byte_string_cmp()

int oc_byte_string_cmp ( oc_string_t  string1,
oc_string_t  string2 
)

oc_string compare for byte strings (no null terminator)

Parameters
string1byte string 1 to be compared
string2byte string 2 to be compared
Returns
int 0 == equal

◆ oc_byte_string_copy()

int oc_byte_string_copy ( oc_string_t *  string1,
oc_string_t  string2 
)

copy oc_string used as a byte string

Parameters
string1the oc_string to copy to
string2the oc_string to copy from
Returns
int 0 == success

◆ oc_byte_string_copy_from_char_with_size()

int oc_byte_string_copy_from_char_with_size ( oc_string_t *  string1,
const char *  string2,
size_t  string2_len 
)

copy byte string from char*

Note: does NOT add a null terminator

Parameters
string1the oc_string to copy to
string2the char* to copy from
string2_lenthe length of string2
Returns
int 0 == success

◆ oc_char_convert_to_lower()

int oc_char_convert_to_lower ( char *  string)

converts the input string to lower case

Parameters
[in]stringthe input string that gets converted
Returns
int 0 success

◆ oc_char_print_hex()

int oc_char_print_hex ( const char *  str,
int  str_len 
)

prints the string as hex

Parameters
[in]strthe input string to be printed
[in]str_lenthe length of the input string
Returns
int printed amount of x

◆ oc_char_println_hex()

int oc_char_println_hex ( const char *  str,
int  str_len 
)

prints the input as hex string with newline (
) at the end.

Parameters
[in]strthe input string to be printed
[in]str_lenthe length of the input string
Returns
int printed amount of x

◆ oc_conv_byte_array_to_hex_string()

int oc_conv_byte_array_to_hex_string ( const uint8_t *  array,
size_t  array_len,
char *  hex_str,
size_t *  hex_str_len 
)

Conversions between hex encoded strings and byte arrays.

convert array to hex

Note: hex_str is pre allocated with hex_str_len

Parameters
[in]arraythe array of bytes
[in]array_lenlength of the array
hex_strdata as hex
hex_str_lenlength of the hex string
Returns
int 0 success

◆ oc_conv_hex_string_to_byte_array()

int oc_conv_hex_string_to_byte_array ( const char *  hex_str,
size_t  hex_str_len,
uint8_t *  array,
size_t *  array_len 
)

convert hex string to byte array

Parameters
[in]hex_strhex string input
[in]hex_str_lensize of the hex string
arraythe array of bytes
array_lenlength of the byte array
Returns
int 0 success

◆ oc_conv_hex_string_to_oc_string()

int oc_conv_hex_string_to_oc_string ( const char *  hex_str,
size_t  hex_str_len,
oc_string_t *  out 
)

convert hex string to oc_string

Parameters
[in]hex_strhex string input
[in]hex_str_lensize of the hex string
outthe allocated oc_string
Returns
int 0 success

◆ oc_conv_uint64_to_dec_string()

int oc_conv_uint64_to_dec_string ( char *  str,
uint64_t  number 
)

Converts a uint64_t to a decimal string representation.

Parameters
[in]numbernumber to be converted to string
[out]strResulting string after conversion. IMPORTANT: Should have a size of at least 22 bytes (21 + null terminator)
Returns
int always returns 0

◆ oc_conv_uint64_to_hex_string()

int oc_conv_uint64_to_hex_string ( char *  str,
uint64_t  number 
)

Converts a uint64_t to a hex string representation.

Parameters
[in]numbernumber to be converted to hexadecimal string
[out]strResulting string after conversion. IMPORTANT: Should have a size of at least 17 bytes (16 + null terminator)
Returns
int always returns 0

◆ oc_get_sn_from_ep()

int oc_get_sn_from_ep ( const char *  param,
int  param_len,
char *  sn,
int  sn_len,
uint32_t *  ia 
)

retrieves the serial number and individual address from the ep parameter

deprecated!!

Parameters
paramthe string to be searched
param_lenthe length of the parameter
snthe sn for storage
sn_lenthe length of the sn for storage
iathe individual address
Returns
0 == ok string

◆ oc_get_sn_ia_iid_from_ep()

int oc_get_sn_ia_iid_from_ep ( const char *  param,
int  param_len,
char *  sn,
int  sn_len,
uint32_t *  ia,
uint64_t *  iid 
)

retrieves the serial number and individual address from the ep parameter

Parameters
paramthe string to be searched
param_lenthe length of the parameter
snthe serial number
sn_lenthe length of the serial number
iathe individual address
iidthe installation id
Returns
0 == ok string

◆ oc_print_uint64_t()

int oc_print_uint64_t ( uint64_t  number,
enum StringRepresentation  rep 
)

print a uint64_t, in either decimal or hex representation

Parameters
number
rep- string representation chosen (decimal or hex)
Returns
int always returns 0

◆ oc_string_cmp()

int oc_string_cmp ( oc_string_t  string1,
oc_string_t  string2 
)

oc_string compare

Parameters
string1string 1 to be compared
string2string 2 to be compared
Returns
int 0 == equal

◆ oc_string_copy()

int oc_string_copy ( oc_string_t *  string1,
oc_string_t  string2 
)

copy oc_string

Parameters
string1the oc_string to copy to
string2the oc_string to copy from
Returns
int 0 == success

◆ oc_string_copy_from_char()

int oc_string_copy_from_char ( oc_string_t *  string1,
const char *  string2 
)

copy string from char*

Parameters
string1the oc_string to copy to
string2the char* to copy from
Returns
int 0 == success

◆ oc_string_copy_from_char_with_size()

int oc_string_copy_from_char_with_size ( oc_string_t *  string1,
const char *  string2,
size_t  string2_len 
)

copy string from char*

Note: adds a null terminator

Parameters
string1the oc_string to copy to
string2the char* to copy from
string2_lenthe length of string2
Returns
int 0 == success

◆ oc_string_is_hex_array()

int oc_string_is_hex_array ( oc_string_t  hex_string)

checks if the input is an array containing hex values e.g.

[0-9,A-F,a-f]

Parameters
[in]hex_stringthe input string to be checked
Returns
int 0 success

◆ oc_string_print_hex()

int oc_string_print_hex ( oc_string_t  hex_string)

prints the input as hex string

Parameters
[in]hex_stringthe input string to be printed
Returns
int printed amount of x

◆ oc_string_println_hex()

int oc_string_println_hex ( oc_string_t  hex_string)

prints the input as hex string with newline (
) at the end.

Parameters
[in]hex_stringthe input string to be printed
Returns
int printed amount of x

◆ oc_strnchr()

char* oc_strnchr ( const char *  string,
char  p,
int  size 
)

search a string (non null terminated) for a character

Parameters
stringthe string to be searched
pthe character to be found
sizethe size of the string
Returns
NULL = not found, other wise position in string string

◆ oc_uri_contains_wildcard()

bool oc_uri_contains_wildcard ( const char *  uri)

checks if the uri contains a wildcard (e.g.

"*")

Parameters
uriThe URI to be checked.
Returns
true
false

◆ oc_uri_contains_wildcard_value_underscore()

bool oc_uri_contains_wildcard_value_underscore ( const char *  uri_resource,
size_t  uri_len,
const char *  uri_invoked,
size_t  invoked_len 
)

function to check if in the wild card section is a "_" (underscore) underscores can be used in functional block uri to have more than 1 instance e.g.

fb* as wild card and fb333_1 as url

Parameters
uri_resourceThe URI with wild card
uri_lenThe length of the URI with wild card
uri_invokedThe URI that should match a wild card
invoked_lenThe URI length of the invoked URI
Returns
true
false

◆ oc_uri_get_wildcard_value_as_int()

int oc_uri_get_wildcard_value_as_int ( const char *  uri_resource,
size_t  uri_len,
const char *  uri_invoked,
size_t  invoked_len 
)

retrieve the wild card value as integer The invoked URI is checked against the URI of a resource that might contain a wild card, if the resource URI contains a wild card then the invoked URI is compared against this URI and e.g.

resource URI: / abc / * invoked URI: / abc / 1 return will be 1.

NOTE: the wild card part of the URL should only contain a number, e.g. no prefix to the number

Parameters
uri_resourceThe URI with wild card
uri_lenThe length of the URI with wild card
uri_invokedThe URI that should match a wild card
invoked_lenThe URI length of the invoked URI
Returns
int -1 is error, otherwise the value is the integer value which is used as value for the wild card.

◆ oc_uri_get_wildcard_value_as_int_after_underscore()

int oc_uri_get_wildcard_value_as_int_after_underscore ( const char *  uri_resource,
size_t  uri_len,
const char *  uri_invoked,
size_t  invoked_len 
)

retrieve the integer after the "_" (underscore) e.g.

retrieve 1 from fb333_1 as url and fb* as wild card

Parameters
uri_resourceThe URI with wild card
uri_lenThe length of the URI with wild card
uri_invokedThe URI that should match a wild card
invoked_lenThe URI length of the invoked URI
Returns
int

◆ oc_uri_get_wildcard_value_as_string()

int oc_uri_get_wildcard_value_as_string ( const char *  uri_resource,
size_t  uri_len,
const char *  uri_invoked,
size_t  invoked_len,
const char **  value 
)

retrieve the wild card value as string The invoked URI is checked against the URI of a resource that might contain a wild card, if the resource URI contains a wild card then the invoked URI is compared against this URI and e.g.

resource URI: / abc / * invoked URI: / abc / y return will be y.

Parameters
uri_resourceThe URI with wild card
uri_lenThe length of the URI with wild card
uri_invokedThe URI that should match a wild card
invoked_lenThe URI length of the invoked URI
valuethe actual value that represents the wild card
Returns
int -1 is error, otherwise the value is the integer length of the string

◆ oc_url_cmp()

int oc_url_cmp ( oc_string_t  string1,
oc_string_t  string2 
)

url compare same as string compare but ignores the leading / of the urls

Parameters
string1url to be compared
string2url to be compared
Returns
int 0 == equal