mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
Replace str with coap_string_t. Make tokens coap_binary_t
New struct coap_binary_t - same as coap_string_t, used for tokens Deprecate struct str with the intent of removing it downstream as it polutes namespace. Make end of coap_string_t data a NUL. Updated coap_make_str_const(), removing .length= and .s= to keep upstream compilers happy. Update Doxygen for str.h Files: examples/client.c examples/coap-rd.c examples/coap-server.c examples/contiki/server.c examples/etsi_iot_01.c include/coap/resource.h include/coap/str.h include/coap/subscribe.h man/coap_observe.txt.in src/net.c src/resource.c src/str.c src/uri.c tests/test_options.c Update
This commit is contained in:
1 parent
e1491dee77
commit
06f57978de
14 files changed
+117
-83
No files matched your search
+5
-5
@@ -35,7 +35,7 @@
|
||||
int flags = 0;
|
||||
|
||||
static unsigned char _token_data[8];
|
||||
str the_token = { 0, _token_data };
|
||||
coap_binary_t the_token = { 0, _token_data };
|
||||
|
||||
#define FLAGS_BLOCK 0x01
|
||||
|
||||
@@ -49,10 +49,10 @@ static uint16_t proxy_port = COAP_DEFAULT_PORT;
|
||||
/* reading is done when this flag is set */
|
||||
static int ready = 0;
|
||||
|
||||
static str output_file = { 0, NULL }; /* output file name */
|
||||
static coap_string_t output_file = { 0, NULL }; /* output file name */
|
||||
static FILE *file = NULL; /* output file stream */
|
||||
|
||||
static str payload = { 0, NULL }; /* optional payload to send */
|
||||
static coap_string_t payload = { 0, NULL }; /* optional payload to send */
|
||||
|
||||
static int reliable = 0;
|
||||
|
||||
@@ -893,7 +893,7 @@ check_segment(const uint8_t *s, size_t length) {
|
||||
}
|
||||
|
||||
static int
|
||||
cmdline_input(char *text, str *buf) {
|
||||
cmdline_input(char *text, coap_string_t *buf) {
|
||||
int len;
|
||||
len = check_segment((unsigned char *)text, strlen(text));
|
||||
|
||||
@@ -910,7 +910,7 @@ cmdline_input(char *text, str *buf) {
|
||||
}
|
||||
|
||||
static int
|
||||
cmdline_input_from_file(char *filename, str *buf) {
|
||||
cmdline_input_from_file(char *filename, coap_string_t *buf) {
|
||||
FILE *inputfile = NULL;
|
||||
ssize_t len;
|
||||
int result = 1;
|
||||
|
||||
+16
-16
@@ -51,12 +51,12 @@
|
||||
|
||||
typedef struct rd_t {
|
||||
UT_hash_handle hh; /**< hash handle (for internal use only) */
|
||||
str uri_path; /**< the actual key for this resource */
|
||||
coap_string_t uri_path; /**< the actual key for this resource */
|
||||
|
||||
size_t etag_len; /**< actual length of @c etag */
|
||||
unsigned char etag[8]; /**< ETag for current description */
|
||||
|
||||
str data; /**< points to the resource description */
|
||||
coap_string_t data; /**< points to the resource description */
|
||||
} rd_t;
|
||||
|
||||
rd_t *resources = NULL;
|
||||
@@ -93,8 +93,8 @@ hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
rd_t *rd = NULL;
|
||||
unsigned char buf[3];
|
||||
@@ -121,8 +121,8 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
#if 1
|
||||
response->code = COAP_RESPONSE_CODE(501);
|
||||
@@ -136,7 +136,7 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
rd_t *rd = NULL;
|
||||
unsigned char code; /* result code */
|
||||
unsigned char *data;
|
||||
str tmp;
|
||||
coap_string_t tmp;
|
||||
|
||||
HASH_FIND(hh, resources, resource->uri_path.s, resource->uri_path.length, rd);
|
||||
if (rd) {
|
||||
@@ -200,8 +200,8 @@ hnd_delete_resource(coap_context_t *ctx,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
rd_t *rd = NULL;
|
||||
|
||||
@@ -222,8 +222,8 @@ hnd_get_rd(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[3];
|
||||
|
||||
@@ -245,10 +245,10 @@ parse_param(const uint8_t *search,
|
||||
size_t search_len,
|
||||
unsigned char *data,
|
||||
size_t data_len,
|
||||
str *result) {
|
||||
coap_string_t *result) {
|
||||
|
||||
if (result)
|
||||
memset(result, 0, sizeof(str));
|
||||
memset(result, 0, sizeof(coap_string_t));
|
||||
|
||||
if (!search_len)
|
||||
return 0;
|
||||
@@ -387,14 +387,14 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
coap_resource_t *r;
|
||||
#define LOCSIZE 68
|
||||
unsigned char *loc;
|
||||
size_t loc_size;
|
||||
str h = {0, NULL}, ins = {0, NULL}, rt = {0, NULL}, lt = {0, NULL}; /* store query parameters */
|
||||
coap_string_t h = {0, NULL}, ins = {0, NULL}, rt = {0, NULL}, lt = {0, NULL}; /* store query parameters */
|
||||
unsigned char *buf;
|
||||
coap_str_const_t attr_val;
|
||||
coap_str_const_t resource_val;
|
||||
|
||||
+15
-15
@@ -83,8 +83,8 @@ hnd_get_index(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[3];
|
||||
|
||||
@@ -108,8 +108,8 @@ hnd_get_time(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
str *token,
|
||||
str *query,
|
||||
coap_binary_t *token,
|
||||
coap_string_t *query,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[40];
|
||||
size_t len;
|
||||
@@ -174,8 +174,8 @@ hnd_put_time(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
coap_tick_t t;
|
||||
size_t size;
|
||||
@@ -190,7 +190,7 @@ hnd_put_time(coap_context_t *ctx UNUSED_PARAM,
|
||||
response->code =
|
||||
my_clock_base ? COAP_RESPONSE_CODE(204) : COAP_RESPONSE_CODE(201);
|
||||
|
||||
coap_resource_set_dirty(resource, NULL);
|
||||
coap_resource_notify_observers(resource, NULL);
|
||||
|
||||
/* coap_get_data() sets size to 0 on error */
|
||||
(void)coap_get_data(request, &size, &data);
|
||||
@@ -224,8 +224,8 @@ hnd_delete_time(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response UNUSED_PARAM) {
|
||||
my_clock_base = 0; /* mark clock as "deleted" */
|
||||
|
||||
@@ -239,8 +239,8 @@ hnd_get_async(coap_context_t *ctx,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
str *token UNUSED_PARAM,
|
||||
str *query UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response) {
|
||||
unsigned long delay = 5;
|
||||
size_t size;
|
||||
@@ -325,7 +325,7 @@ hnd_delete(coap_context_t *ctx,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_string_t *token UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response UNUSED_PARAM
|
||||
) {
|
||||
@@ -369,7 +369,7 @@ hnd_get(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_string_t *token,
|
||||
coap_binary_t *token,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response
|
||||
) {
|
||||
@@ -418,7 +418,7 @@ hnd_put(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
coap_string_t *token UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
coap_pdu_t *response
|
||||
) {
|
||||
@@ -483,7 +483,7 @@ hnd_unknown_put(coap_context_t *ctx,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
coap_string_t *token,
|
||||
coap_binary_t *token,
|
||||
coap_string_t *query,
|
||||
coap_pdu_t *response
|
||||
) {
|
||||
|
||||
@@ -94,7 +94,7 @@ init_coap_server(coap_context_t **ctx) {
|
||||
void
|
||||
hnd_get_time(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
const coap_endpoint_t *local_interface,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
|
||||
@@ -127,7 +127,7 @@ coap_delete_payload(coap_payload_t *payload) {
|
||||
|
||||
void
|
||||
hnd_get_index(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[3];
|
||||
|
||||
@@ -147,7 +147,7 @@ hnd_get_index(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
|
||||
void
|
||||
hnd_get_resource(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_key_t etag;
|
||||
unsigned char buf[2];
|
||||
@@ -225,7 +225,7 @@ hnd_get_resource(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
/* DELETE handler for dynamic resources created by POST /test */
|
||||
void
|
||||
hnd_delete_resource(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_payload_t *payload;
|
||||
|
||||
@@ -241,7 +241,7 @@ hnd_delete_resource(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
|
||||
void
|
||||
hnd_post_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
@@ -307,7 +307,7 @@ hnd_post_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
|
||||
void
|
||||
hnd_put_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
@@ -358,7 +358,7 @@ hnd_put_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
|
||||
void
|
||||
hnd_delete_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
/* the ETSI validation tool does not like empty resources... */
|
||||
#if 0
|
||||
@@ -374,7 +374,7 @@ hnd_delete_test(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
|
||||
void
|
||||
hnd_get_query(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_filter_t f;
|
||||
@@ -414,7 +414,7 @@ hnd_get_query(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
/* handler for TD_COAP_CORE_16 */
|
||||
void
|
||||
hnd_get_separate(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_address_t *peer, coap_pdu_t *request, str *token,
|
||||
coap_address_t *peer, coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
|
||||
Reference in new issue
Block a user