libcoap  4.2.1
str.h
Go to the documentation of this file.
1 /*
2  * str.h -- strings to be used in the CoAP library
3  *
4  * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
10 #ifndef COAP_STR_H_
11 #define COAP_STR_H_
12 
13 #include <string.h>
14 
15 
25 typedef struct coap_string_t {
26  size_t length;
29 
33 typedef struct coap_str_const_t {
34  size_t length;
35  const uint8_t *s;
37 
38 #define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
39 
43 typedef struct coap_binary_t {
44  size_t length;
47 
56 coap_string_t *coap_new_string(size_t size);
57 
63 void coap_delete_string(coap_string_t *string);
64 
75 coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
76 
83 
84 #define COAP_MAX_STR_CONST_FUNC 2
85 
98 coap_str_const_t *coap_make_str_const(const char *string);
99 
109 #define coap_string_equal(string1,string2) \
110  ((string1)->length == (string2)->length && ((string1)->length == 0 || \
111  memcmp((string1)->s, (string2)->s, (string1)->length) == 0))
112 
115 #endif /* COAP_STR_H_ */
size_t length
length of string
Definition: str.h:34
uint8_t * s
string data
Definition: str.h:27
Coap string data definition.
Definition: str.h:25
Coap string data definition with const data.
Definition: str.h:33
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:13
struct coap_binary_t coap_binary_t
Coap binary data definition.
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified string and create a coap_str_const_t *.
Definition: str.c:44
struct coap_str_const_t coap_str_const_t
Coap string data definition with const data.
Coap binary data definition.
Definition: str.h:43
void coap_delete_string(coap_string_t *string)
Deletes the given string and releases any memory allocated.
Definition: str.c:27
void coap_delete_str_const(coap_str_const_t *string)
Deletes the given const string and releases any memory allocated.
Definition: str.c:40
struct coap_string_t coap_string_t
Coap string data definition.
size_t length
length of string
Definition: str.h:26
const uint8_t * s
string data
Definition: str.h:35
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:31
size_t length
length of binary data
Definition: str.h:44
unsigned char uint8_t
Definition: uthash.h:79
uint8_t * s
binary data
Definition: str.h:45