Files
libcoap/include/coap2/str.h
T
Jon Shallow 23b3e6e17e Add in coap_new_client_session_psk2 and coap_context_set_psk2 functions
This fix is in preparation for the full coap_new_client_session_psk2()
and coap_context_set_psk2() functions.  Structures are updated with the
necessary information, as well as provide the high level support.

As new sessions are now created for every genuine incoming session (#333),
coap_context_t will only hold the initial information provided by
coap_context_set_psk2() (server mode), but if there is any updated
(triggered by SNI or Indentity), this will be kept in coap_session_t.

Likewise, the client initial information will be kept in the
coap_session_t, and if modified (triggered by Hint) will be kept separately
in coap_session_t.

This change does not include the support required in the DTLS interface modules
other than changes required to make the code compilable and still run the
existing examples - so it is a standalone change.

Makefile.am:

Make coap_dtls_context_set_cpsk, coap_dtls_context_set_spsk,
coap_session_refresh_psk_key and coap_session_refresh_psk_hint hidden
Remove coap_dtls_context_set_psk

include/coap2/*.h:

Replace call-back with callback for consistency

include/coap2/coap_dtls.h:

Include coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t definitions
Define coap_dtls_spsk_key_t for the new coap_*_psk2 functions.
Include all the new call back function definitions

include/coap2/coap_session.h:

Update coap_session_t with the new PSK information
Define coap_new_client_session_psk2(), coap_session_refresh_psk_key() and
coap_session_refresh_psk_hint() functions

include/coap2/net.h:

Update coap_context_t with the new PSK information
Define the coap_context_set_psk2() function

include/coap2/str.h:

Add in a new struct coap_bin_const_t
Define new functions coap_new_bin_const(), coap_delete_bin_const()
and coap_binary_equal().

libcoap-2.{map|sym}

Expose the new coap_context_set_psk2, coap_new_client_session_psk2,
coap_new_bin_const and coap_delete_bin_const functions

src/coap_gnutls.c:
src/coap_notls.c:
src/coap_tinydtls.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()

src/coap_openssl.c:

Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk()
and coap_dtls_context_set_cpsk()
Update the SSL_CTX_use* and SSL_set_* functions with the new variable
locations

src/coap_session.c:

Free off new information on coap_session_t in coap_session_mfree()

Build parameters for coap_new_client_session_psk2() in
coap_new_client_session_psk() and call coap_new_client_session_psk2() instead
of coap_session_create_client().
Create new coap_new_client_session_psk2().
Create new coap_session_refresh_psk_key() (will be used when DTLS interface
code is updated

src/net.c:

Update coap_get_session_client_psk() to use the new PSK locations.
Update coap_get_session_server_psk() to use the new PSK locations.
Update coap_get_session_server_hint() to use the new PSK locations.
Build parameters for coap_context_set_psk2() in
coap_context_set_psk() and call coap_context_set_psk2().
Create new coap_context_set_psk2().
Cleanup usage of old PSK information in coap_free_context()

src/str.c:

Code for coap_new_bin_const() and coap_delete_bin_const() functions
2019-12-03 14:46:26 +00:00

159 lines
4.6 KiB
C

/*
* str.h -- strings to be used in the CoAP library
*
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
*
* 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>
/**
* @defgroup string String handling support
* API functions for handling strings
* @{
*/
/**
* Coap string data definition
*/
typedef struct coap_string_t {
size_t length; /**< length of string */
uint8_t *s; /**< string data */
} coap_string_t;
/**
* Coap string data definition with const data
*/
typedef struct coap_str_const_t {
size_t length; /**< length of string */
const uint8_t *s; /**< string data */
} coap_str_const_t;
#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
/**
* Coap binary data definition
*/
typedef struct coap_binary_t {
size_t length; /**< length of binary data */
uint8_t *s; /**< binary data */
} coap_binary_t;
/**
* Coap binary data definition with const data
*/
typedef struct coap_bin_const_t {
size_t length; /**< length of binary data */
const uint8_t *s; /**< binary data */
} coap_bin_const_t;
/**
* Returns a new string object with at least size+1 bytes storage allocated.
* The string must be released using coap_delete_string().
*
* @param size The size to allocate for the binary string data.
*
* @return A pointer to the new object or @c NULL on error.
*/
coap_string_t *coap_new_string(size_t size);
/**
* Deletes the given string and releases any memory allocated.
*
* @param string The string to free off.
*/
void coap_delete_string(coap_string_t *string);
/**
* Returns a new const string object with at least size+1 bytes storage
* allocated, and the provided data copied into the string object.
* The string must be released using coap_delete_str_const().
*
* @param data The data to put in the new string object.
* @param size The size to allocate for the binary string data.
*
* @return A pointer to the new object or @c NULL on error.
*/
coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
/**
* Deletes the given const string and releases any memory allocated.
*
* @param string The string to free off.
*/
void coap_delete_str_const(coap_str_const_t *string);
#define COAP_MAX_STR_CONST_FUNC 2
/**
* Take the specified byte array (text) and create a coap_bin_const_t *
* Returns a new const binary object with at least size bytes storage
* allocated, and the provided data copied into the binary object.
* The binary data must be released using coap_delete_bin_const().
*
* @param data The data to put in the new string object.
* @param size The size to allocate for the binary data.
*
* @return A pointer to the new object or @c NULL on error.
*/
coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
/**
* Deletes the given const binary data and releases any memory allocated.
*
* @param binary The binary data to free off.
*/
void coap_delete_bin_const(coap_bin_const_t *binary);
/**
* Take the specified byte array (text) and create a coap_str_const_t *
*
* Note: the array is 2 deep as there are up to two callings of
* coap_make_str_const in a function call. e.g. coap_add_attr().
* Caution: If there are local variable assignments, these will cycle around
* the var[COAP_MAX_STR_CONST_FUNC] set. No current examples do this.
*
* @param string The const string to convert to a coap_str_const_t *
*
* @return A pointer to one of two static variables containing the
* coap_str_const_t * result
*/
coap_str_const_t *coap_make_str_const(const char *string);
/**
* Compares the two strings for equality
*
* @param string1 The first string.
* @param string2 The second string.
*
* @return @c 1 if the strings are equal
* @c 0 otherwise.
*/
#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)))
/**
* Compares the two binary data for equality
*
* @param binary1 The first binary data.
* @param binary2 The second binary data.
*
* @return @c 1 if the binary data is equal
* @c 0 otherwise.
*/
#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_ */