str.h
Go to the documentation of this file.
/*
* str.h -- strings to be used in the CoAP library
*
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_STR_H_
#define COAP_STR_H_
#include <string.h>
/*
* Note: string and binary use equivalent objects.
* string is likely to contain readable textual information, binary will not.
*/
typedef struct coap_string_t {
size_t length;
uint8_t *s;
} coap_string_t;
typedef struct coap_str_const_t {
size_t length;
const uint8_t *s;
} coap_str_const_t;
#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
typedef struct coap_binary_t {
size_t length;
uint8_t *s;
} coap_binary_t;
typedef struct coap_bin_const_t {
size_t length;
const uint8_t *s;
} coap_bin_const_t;
coap_string_t *coap_new_string(size_t size);
void coap_delete_string(coap_string_t *string);
coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
void coap_delete_str_const(coap_str_const_t *string);
coap_binary_t *coap_new_binary(size_t size);
void coap_delete_binary(coap_binary_t *binary);
coap_binary_t *coap_resize_binary(coap_binary_t *binary, size_t new_size);
coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
void coap_delete_bin_const(coap_bin_const_t *binary);
#ifndef COAP_MAX_STR_CONST_FUNC
#define COAP_MAX_STR_CONST_FUNC 2
#endif /* COAP_MAX_STR_CONST_FUNC */
coap_str_const_t *coap_make_str_const(const char *string);
#define coap_string_equal(string1,string2) \
((string1)->length == (string2)->length && ((string1)->length == 0 || \
((string1)->s && (string2)->s && \
memcmp((string1)->s, (string2)->s, (string1)->length) == 0)))
#define coap_binary_equal(binary1,binary2) \
((binary1)->length == (binary2)->length && ((binary1)->length == 0 || \
((binary1)->s && (binary2)->s && \
memcmp((binary1)->s, (binary2)->s, (binary1)->length) == 0)))
#endif /* COAP_STR_H_ */
coap_new_string
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
Definition: str.c:15
coap_delete_bin_const
void coap_delete_bin_const(coap_bin_const_t *binary)
Deletes the given const binary data and releases any memory allocated.
Definition: str.c:104
coap_delete_str_const
void coap_delete_str_const(coap_str_const_t *string)
Deletes the given const string and releases any memory allocated.
Definition: str.c:53
coap_str_const_t
struct coap_str_const_t coap_str_const_t
CoAP string data definition with const data.
coap_delete_binary
void coap_delete_binary(coap_binary_t *binary)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition: str.c:91
coap_new_bin_const
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
Definition: str.c:95
coap_binary_t
struct coap_binary_t coap_binary_t
CoAP binary data definition.
coap_new_binary
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
Definition: str.c:67
coap_new_str_const
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
Definition: str.c:44
coap_string_t
struct coap_string_t coap_string_t
CoAP string data definition.
coap_bin_const_t
struct coap_bin_const_t coap_bin_const_t
CoAP binary data definition with const data.
coap_delete_string
void coap_delete_string(coap_string_t *string)
Deletes the given string and releases any memory allocated.
Definition: str.c:40
coap_resize_binary
coap_binary_t * coap_resize_binary(coap_binary_t *binary, size_t new_size)
Resizes the given coap_binary_t object.
Definition: str.c:71
coap_make_str_const
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified byte array (text) and create a coap_str_const_t *.
Definition: str.c:57
coap_bin_const_t
CoAP binary data definition with const data.
Definition: str.h:58
coap_bin_const_t::length
size_t length
length of binary data
Definition: str.h:59
coap_bin_const_t::s
const uint8_t * s
read-only binary data
Definition: str.h:60
coap_binary_t
CoAP binary data definition.
Definition: str.h:50
coap_binary_t::length
size_t length
length of binary data
Definition: str.h:51
coap_binary_t::s
uint8_t * s
binary data
Definition: str.h:52
coap_str_const_t
CoAP string data definition with const data.
Definition: str.h:40
coap_str_const_t::s
const uint8_t * s
read-only string data
Definition: str.h:42
coap_str_const_t::length
size_t length
length of string
Definition: str.h:41
coap_string_t
CoAP string data definition.
Definition: str.h:32
coap_string_t::s
uint8_t * s
string data
Definition: str.h:34
coap_string_t::length
size_t length
length of string
Definition: str.h:33