Made Erbium function parameters const where applicable.\nMinor clean-up.
This commit is contained in:
parent
0a4c77dbff
commit
4c3e858df5
@ -191,7 +191,7 @@ coap_get_tid()
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
coap_send_message(uip_ipaddr_t *addr, uint16_t port, uint8_t *data, uint16_t length)
|
||||
coap_send_message(uip_ipaddr_t *addr, uint16_t port, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
/*configure connection to reply to client*/
|
||||
uip_ipaddr_copy(&udp_conn->ripaddr, addr);
|
||||
@ -586,7 +586,7 @@ coap_get_header_etag(void *packet, const uint8_t **etag)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_etag(void *packet, uint8_t *etag, size_t etag_len)
|
||||
coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len)
|
||||
{
|
||||
((coap_packet_t *)packet)->etag_len = MIN(COAP_ETAG_LEN, etag_len);
|
||||
memcpy(((coap_packet_t *)packet)->etag, etag, ((coap_packet_t *)packet)->etag_len);
|
||||
@ -605,9 +605,9 @@ coap_get_header_uri_host(void *packet, const char **host)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_host(void *packet, char *host)
|
||||
coap_set_header_uri_host(void *packet, const char *host)
|
||||
{
|
||||
((coap_packet_t *)packet)->uri_host = (char *) host;
|
||||
((coap_packet_t *)packet)->uri_host = host;
|
||||
((coap_packet_t *)packet)->uri_host_len = strlen(host);
|
||||
|
||||
SET_OPTION((coap_packet_t *)packet, COAP_OPTION_URI_HOST);
|
||||
@ -615,20 +615,20 @@ coap_set_header_uri_host(void *packet, char *host)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int
|
||||
coap_get_header_location(void *packet, const char **uri)
|
||||
coap_get_header_location(void *packet, const char **location)
|
||||
{
|
||||
if (!IS_OPTION((coap_packet_t *)packet, COAP_OPTION_LOCATION_PATH)) return 0;
|
||||
|
||||
*uri = ((coap_packet_t *)packet)->location_path;
|
||||
*location = ((coap_packet_t *)packet)->location_path;
|
||||
return ((coap_packet_t *)packet)->location_path_len;
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_location(void *packet, char *location)
|
||||
coap_set_header_location(void *packet, const char *location)
|
||||
{
|
||||
while (location[0]=='/') ++location;
|
||||
|
||||
((coap_packet_t *)packet)->location_path = (char *) location;
|
||||
((coap_packet_t *)packet)->location_path = location;
|
||||
((coap_packet_t *)packet)->location_path_len = strlen(location);
|
||||
|
||||
SET_OPTION((coap_packet_t *)packet, COAP_OPTION_LOCATION_PATH);
|
||||
@ -645,11 +645,11 @@ coap_get_header_uri_path(void *packet, const char **path)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_path(void *packet, char *path)
|
||||
coap_set_header_uri_path(void *packet, const char *path)
|
||||
{
|
||||
while (path[0]=='/') ++path;
|
||||
|
||||
((coap_packet_t *)packet)->uri_path = (char *) path;
|
||||
((coap_packet_t *)packet)->uri_path = path;
|
||||
((coap_packet_t *)packet)->uri_path_len = strlen(path);
|
||||
|
||||
SET_OPTION((coap_packet_t *)packet, COAP_OPTION_URI_PATH);
|
||||
@ -683,7 +683,7 @@ coap_get_header_token(void *packet, const uint8_t **token)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_token(void *packet, uint8_t *token, size_t token_len)
|
||||
coap_set_header_token(void *packet, const uint8_t *token, size_t token_len)
|
||||
{
|
||||
((coap_packet_t *)packet)->token_len = MIN(COAP_TOKEN_LEN, token_len);
|
||||
memcpy(((coap_packet_t *)packet)->token, token, ((coap_packet_t *)packet)->token_len);
|
||||
@ -731,7 +731,7 @@ coap_get_header_uri_query(void *packet, const char **query)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_query(void *packet, char *query)
|
||||
coap_set_header_uri_query(void *packet, const char *query)
|
||||
{
|
||||
while (query[0]=='?') ++query;
|
||||
|
||||
|
@ -200,11 +200,11 @@ typedef struct {
|
||||
uint8_t etag_len;
|
||||
uint8_t etag[COAP_ETAG_LEN];
|
||||
uint8_t uri_host_len;
|
||||
char *uri_host;
|
||||
const char *uri_host;
|
||||
uint8_t location_path_len;
|
||||
char *location_path;
|
||||
const char *location_path;
|
||||
uint8_t uri_path_len;
|
||||
char *uri_path;
|
||||
const char *uri_path;
|
||||
uint32_t observe; /* 0-4 bytes for coap-03 */
|
||||
uint8_t token_len;
|
||||
uint8_t token[COAP_TOKEN_LEN];
|
||||
@ -213,7 +213,7 @@ typedef struct {
|
||||
uint16_t block_size;
|
||||
uint32_t block_offset;
|
||||
uint8_t uri_query_len;
|
||||
char *uri_query;
|
||||
const char *uri_query;
|
||||
|
||||
uint16_t payload_len;
|
||||
uint8_t *payload;
|
||||
@ -236,7 +236,7 @@ typedef enum
|
||||
|
||||
void coap_init_connection(uint16_t port);
|
||||
uint16_t coap_get_tid(void);
|
||||
void coap_send_message(uip_ipaddr_t *addr, uint16_t port, uint8_t *data, uint16_t length);
|
||||
void coap_send_message(uip_ipaddr_t *addr, uint16_t port, const uint8_t *data, uint16_t length);
|
||||
|
||||
void coap_init_message(void *packet, coap_message_type_t type, uint8_t code, uint16_t tid);
|
||||
int coap_serialize_message(void *packet, uint8_t *buffer);
|
||||
@ -255,28 +255,28 @@ int coap_get_header_max_age(void *packet, uint32_t *age);
|
||||
int coap_set_header_max_age(void *packet, uint32_t age);
|
||||
|
||||
int coap_get_header_etag(void *packet, const uint8_t **etag);
|
||||
int coap_set_header_etag(void *packet, uint8_t *etag, size_t etag_len);
|
||||
int coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len);
|
||||
|
||||
int coap_get_header_uri_host(void *packet, const char **host); /*CAUTION in-place string might not be 0-terminated */
|
||||
int coap_set_header_uri_host(void *packet, char *host);
|
||||
int coap_set_header_uri_host(void *packet, const char *host);
|
||||
|
||||
int coap_get_header_location(void *packet, const char **uri); /*CAUTION in-place string might not be 0-terminated */
|
||||
int coap_set_header_location(void *packet, char *uri);
|
||||
int coap_set_header_location(void *packet, const char *uri);
|
||||
|
||||
int coap_get_header_uri_path(void *packet, const char **uri); /*CAUTION in-place string might not be 0-terminated */
|
||||
int coap_set_header_uri_path(void *packet, char *uri);
|
||||
int coap_set_header_uri_path(void *packet, const char *uri);
|
||||
|
||||
int coap_get_header_observe(void *packet, uint32_t *observe);
|
||||
int coap_set_header_observe(void *packet, uint32_t observe);
|
||||
|
||||
int coap_get_header_token(void *packet, const uint8_t **token);
|
||||
int coap_set_header_token(void *packet, uint8_t *token, size_t token_len);
|
||||
int coap_set_header_token(void *packet, const uint8_t *token, size_t token_len);
|
||||
|
||||
int coap_get_header_block(void *packet, uint32_t *num, uint8_t *more, uint16_t *size, uint32_t *offset);
|
||||
int coap_set_header_block(void *packet, uint32_t num, uint8_t more, uint16_t size);
|
||||
|
||||
int coap_get_header_uri_query(void *packet, const char **query); /*CAUTION in-place string might not be 0-terminated */
|
||||
int coap_set_header_uri_query(void *packet, char *query);
|
||||
int coap_set_header_uri_query(void *packet, const char *query);
|
||||
|
||||
int coap_get_payload(void *packet, const uint8_t **payload);
|
||||
int coap_set_payload(void *packet, uint8_t *payload, size_t length);
|
||||
|
@ -209,6 +209,7 @@ coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option, size_t opt
|
||||
/* Merge multiple options. */
|
||||
if (*dst_len > 0)
|
||||
{
|
||||
/* dst already contains an option: concatenate */
|
||||
(*dst)[*dst_len] = separator;
|
||||
*dst_len += 1;
|
||||
|
||||
@ -219,7 +220,8 @@ coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option, size_t opt
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst = (char *) option; /* thus pointer pointer */
|
||||
/* dst is empty: set to option */
|
||||
*dst = (char *) option;
|
||||
*dst_len = option_len;
|
||||
}
|
||||
}
|
||||
@ -613,7 +615,8 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
||||
PRINTF("Uri-Host [%.*s]\n", ((coap_packet_t *)packet)->uri_host_len, ((coap_packet_t *)packet)->uri_host);
|
||||
break;
|
||||
case COAP_OPTION_LOCATION_PATH:
|
||||
coap_merge_multi_option(&(((coap_packet_t *)packet)->location_path), &(((coap_packet_t *)packet)->location_path_len), current_option, option_len, '/');
|
||||
/* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
|
||||
coap_merge_multi_option( (char **) &(((coap_packet_t *)packet)->location_path), &(((coap_packet_t *)packet)->location_path_len), current_option, option_len, '/');
|
||||
PRINTF("Location-Path [%.*s]\n", ((coap_packet_t *)packet)->location_path_len, ((coap_packet_t *)packet)->location_path);
|
||||
break;
|
||||
case COAP_OPTION_URI_PORT:
|
||||
@ -621,11 +624,13 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
||||
PRINTF("Uri-Port [%u]\n", ((coap_packet_t *)packet)->uri_port);
|
||||
break;
|
||||
case COAP_OPTION_LOCATION_QUERY:
|
||||
coap_merge_multi_option(&(((coap_packet_t *)packet)->location_query), &(((coap_packet_t *)packet)->location_query_len), current_option, option_len, '&');
|
||||
/* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
|
||||
coap_merge_multi_option( (char **) &(((coap_packet_t *)packet)->location_query), &(((coap_packet_t *)packet)->location_query_len), current_option, option_len, '&');
|
||||
PRINTF("Location-Query [%.*s]\n", ((coap_packet_t *)packet)->location_query_len, ((coap_packet_t *)packet)->location_query);
|
||||
break;
|
||||
case COAP_OPTION_URI_PATH:
|
||||
coap_merge_multi_option(&(((coap_packet_t *)packet)->uri_path), &(((coap_packet_t *)packet)->uri_path_len), current_option, option_len, '/');
|
||||
/* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
|
||||
coap_merge_multi_option( (char **) &(((coap_packet_t *)packet)->uri_path), &(((coap_packet_t *)packet)->uri_path_len), current_option, option_len, '/');
|
||||
PRINTF("Uri-Path [%.*s]\n", ((coap_packet_t *)packet)->uri_path_len, ((coap_packet_t *)packet)->uri_path);
|
||||
break;
|
||||
case COAP_OPTION_OBSERVE:
|
||||
@ -673,7 +678,8 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
|
||||
PRINTF("Fence-Post\n");
|
||||
break;
|
||||
case COAP_OPTION_URI_QUERY:
|
||||
coap_merge_multi_option(&(((coap_packet_t *)packet)->uri_query), &(((coap_packet_t *)packet)->uri_query_len), current_option, option_len, '&');
|
||||
/* coap_merge_multi_option() operates in-place on the IPBUF, but final packet field should be const string -> cast to string */
|
||||
coap_merge_multi_option( (char **) &(((coap_packet_t *)packet)->uri_query), &(((coap_packet_t *)packet)->uri_query_len), current_option, option_len, '&');
|
||||
PRINTF("Uri-Query [%.*s]\n", ((coap_packet_t *)packet)->uri_query_len, ((coap_packet_t *)packet)->uri_query);
|
||||
break;
|
||||
case COAP_OPTION_BLOCK2:
|
||||
@ -752,7 +758,7 @@ coap_set_header_content_type(void *packet, unsigned int content_type)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int
|
||||
coap_get_header_accept(void *packet, uint16_t **accept)
|
||||
coap_get_header_accept(void *packet, const uint16_t **accept)
|
||||
{
|
||||
if (!IS_OPTION((coap_packet_t *)packet, COAP_OPTION_ACCEPT)) return 0;
|
||||
|
||||
@ -802,7 +808,7 @@ coap_get_header_etag(void *packet, const uint8_t **etag)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_etag(void *packet, uint8_t *etag, size_t etag_len)
|
||||
coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len)
|
||||
{
|
||||
((coap_packet_t *)packet)->etag_len = MIN(COAP_ETAG_LEN, etag_len);
|
||||
memcpy(((coap_packet_t *)packet)->etag, etag, ((coap_packet_t *)packet)->etag_len);
|
||||
@ -822,7 +828,7 @@ coap_get_header_if_match(void *packet, const uint8_t **etag)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_if_match(void *packet, uint8_t *etag, size_t etag_len)
|
||||
coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len)
|
||||
{
|
||||
((coap_packet_t *)packet)->if_match_len = MIN(COAP_ETAG_LEN, etag_len);
|
||||
memcpy(((coap_packet_t *)packet)->if_match, etag, ((coap_packet_t *)packet)->if_match_len);
|
||||
@ -854,7 +860,7 @@ coap_get_header_token(void *packet, const uint8_t **token)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_token(void *packet, uint8_t *token, size_t token_len)
|
||||
coap_set_header_token(void *packet, const uint8_t *token, size_t token_len)
|
||||
{
|
||||
((coap_packet_t *)packet)->token_len = MIN(COAP_TOKEN_LEN, token_len);
|
||||
memcpy(((coap_packet_t *)packet)->token, token, ((coap_packet_t *)packet)->token_len);
|
||||
@ -873,7 +879,7 @@ coap_get_header_proxy_uri(void *packet, const char **uri)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_proxy_uri(void *packet, char *uri)
|
||||
coap_set_header_proxy_uri(void *packet, const char *uri)
|
||||
{
|
||||
((coap_packet_t *)packet)->proxy_uri = uri;
|
||||
((coap_packet_t *)packet)->proxy_uri_len = strlen(uri);
|
||||
@ -892,7 +898,7 @@ coap_get_header_uri_host(void *packet, const char **host)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_host(void *packet, char *host)
|
||||
coap_set_header_uri_host(void *packet, const char *host)
|
||||
{
|
||||
((coap_packet_t *)packet)->uri_host = host;
|
||||
((coap_packet_t *)packet)->uri_host_len = strlen(host);
|
||||
@ -911,7 +917,7 @@ coap_get_header_uri_path(void *packet, const char **path)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_path(void *packet, char *path)
|
||||
coap_set_header_uri_path(void *packet, const char *path)
|
||||
{
|
||||
while (path[0]=='/') ++path;
|
||||
|
||||
@ -932,7 +938,7 @@ coap_get_header_uri_query(void *packet, const char **query)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_uri_query(void *packet, char *query)
|
||||
coap_set_header_uri_query(void *packet, const char *query)
|
||||
{
|
||||
while (query[0]=='?') ++query;
|
||||
|
||||
@ -953,7 +959,7 @@ coap_get_header_location_path(void *packet, const char **path)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_location_path(void *packet, char *path)
|
||||
coap_set_header_location_path(void *packet, const char *path)
|
||||
{
|
||||
char *query;
|
||||
|
||||
@ -985,7 +991,7 @@ coap_get_header_location_query(void *packet, const char **query)
|
||||
}
|
||||
|
||||
int
|
||||
coap_set_header_location_query(void *packet, char *query)
|
||||
coap_set_header_location_query(void *packet, const char *query)
|
||||
{
|
||||
while (query[0]=='?') ++query;
|
||||
|
||||
|
@ -213,18 +213,18 @@ typedef struct {
|
||||
coap_content_type_t content_type; /* Parse options once and store; allows setting options in random order */
|
||||
uint32_t max_age;
|
||||
size_t proxy_uri_len;
|
||||
char *proxy_uri;
|
||||
const char *proxy_uri;
|
||||
uint8_t etag_len;
|
||||
uint8_t etag[COAP_ETAG_LEN];
|
||||
size_t uri_host_len;
|
||||
char *uri_host;
|
||||
const char *uri_host;
|
||||
size_t location_path_len;
|
||||
char *location_path;
|
||||
const char *location_path;
|
||||
uint16_t uri_port;
|
||||
size_t location_query_len;
|
||||
char *location_query;
|
||||
const char *location_query;
|
||||
size_t uri_path_len;
|
||||
char *uri_path;
|
||||
const char *uri_path;
|
||||
uint16_t observe;
|
||||
uint8_t token_len;
|
||||
uint8_t token[COAP_TOKEN_LEN];
|
||||
@ -241,7 +241,7 @@ typedef struct {
|
||||
uint16_t block1_size;
|
||||
uint32_t block1_offset;
|
||||
size_t uri_query_len;
|
||||
char *uri_query;
|
||||
const char *uri_query;
|
||||
uint8_t if_none_match;
|
||||
|
||||
uint16_t payload_len;
|
||||
@ -268,41 +268,41 @@ int coap_get_post_variable(void *packet, const char *name, const char **output);
|
||||
unsigned int coap_get_header_content_type(void *packet);
|
||||
int coap_set_header_content_type(void *packet, unsigned int content_type);
|
||||
|
||||
int coap_get_header_accept(void *packet, uint16_t **accept);
|
||||
int coap_get_header_accept(void *packet, const uint16_t **accept);
|
||||
int coap_set_header_accept(void *packet, uint16_t accept);
|
||||
|
||||
int coap_get_header_max_age(void *packet, uint32_t *age);
|
||||
int coap_set_header_max_age(void *packet, uint32_t age);
|
||||
|
||||
int coap_get_header_etag(void *packet, const uint8_t **etag);
|
||||
int coap_set_header_etag(void *packet, uint8_t *etag, size_t etag_len);
|
||||
int coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len);
|
||||
|
||||
int coap_get_header_if_match(void *packet, const uint8_t **etag);
|
||||
int coap_set_header_if_match(void *packet, uint8_t *etag, size_t etag_len);
|
||||
int coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len);
|
||||
|
||||
int coap_get_header_if_none_match(void *packet);
|
||||
int coap_set_header_if_none_match(void *packet);
|
||||
|
||||
int coap_get_header_token(void *packet, const uint8_t **token);
|
||||
int coap_set_header_token(void *packet, uint8_t *token, size_t token_len);
|
||||
int coap_set_header_token(void *packet, const uint8_t *token, size_t token_len);
|
||||
|
||||
int coap_get_header_proxy_uri(void *packet, const char **uri); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_proxy_uri(void *packet, char *uri);
|
||||
int coap_set_header_proxy_uri(void *packet, const char *uri);
|
||||
|
||||
int coap_get_header_uri_host(void *packet, const char **host); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_uri_host(void *packet, char *host);
|
||||
int coap_set_header_uri_host(void *packet, const char *host);
|
||||
|
||||
int coap_get_header_uri_path(void *packet, const char **path); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_uri_path(void *packet, char *path);
|
||||
int coap_set_header_uri_path(void *packet, const char *path);
|
||||
|
||||
int coap_get_header_uri_query(void *packet, const char **query); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_uri_query(void *packet, char *query);
|
||||
int coap_set_header_uri_query(void *packet, const char *query);
|
||||
|
||||
int coap_get_header_location_path(void *packet, const char **path); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_location_path(void *packet, char *path); /* Also splits optional query into Location-Query option. */
|
||||
int coap_set_header_location_path(void *packet, const char *path); /* Also splits optional query into Location-Query option. */
|
||||
|
||||
int coap_get_header_location_query(void *packet, const char **query); /* In-place string might not be 0-terminated. */
|
||||
int coap_set_header_location_query(void *packet, char *query);
|
||||
int coap_set_header_location_query(void *packet, const char *query);
|
||||
|
||||
int coap_get_header_observe(void *packet, uint32_t *observe);
|
||||
int coap_set_header_observe(void *packet, uint32_t observe);
|
||||
|
@ -59,33 +59,6 @@ LIST(restful_services);
|
||||
LIST(restful_periodic_services);
|
||||
|
||||
|
||||
#ifdef WITH_HTTP
|
||||
|
||||
char *
|
||||
rest_to_http_max_age(uint32_t age)
|
||||
{
|
||||
/* Cache-Control: max-age=age for HTTP */
|
||||
static char temp_age[19];
|
||||
snprintf(temp_age, sizeof(temp_age), "max-age=%lu", age);
|
||||
return temp_age;
|
||||
}
|
||||
|
||||
char *
|
||||
rest_to_http_etag(uint8_t *etag, uint8_t etag_len)
|
||||
{
|
||||
static char temp_etag[17];
|
||||
int index = 0;
|
||||
|
||||
for (index = 0; index<sizeof(temp_etag) && index<etag_len; ++index) {
|
||||
snprintf(temp_etag+2*index, sizeof(temp_etag), "%02x", etag[index]);
|
||||
}
|
||||
temp_etag[2*index] = '\0';
|
||||
|
||||
return temp_etag;
|
||||
}
|
||||
#endif /*WITH_COAP*/
|
||||
|
||||
|
||||
void
|
||||
rest_init_framework(void)
|
||||
{
|
||||
|
@ -146,7 +146,7 @@ struct rest_implementation {
|
||||
/** Get request URI path */
|
||||
int (* get_url)(void *request, const char **url);
|
||||
|
||||
int (* set_url)(void *request, char *url);
|
||||
int (* set_url)(void *request, const char *url);
|
||||
|
||||
/** Get the method of a request. */
|
||||
rest_resource_flags_t (* get_method_type)(void *request);
|
||||
@ -160,7 +160,7 @@ struct rest_implementation {
|
||||
/** Set the content-type of a response. */
|
||||
int (* set_header_content_type)(void *response, unsigned int content_type);
|
||||
|
||||
int (* get_header_accept)(void *request, uint16_t **accept);
|
||||
int (* get_header_accept)(void *request, const uint16_t **accept);
|
||||
|
||||
/** Get the Max-Age option of a request. */
|
||||
int (* get_header_max_age)(void *request, uint32_t *age);
|
||||
@ -169,7 +169,7 @@ struct rest_implementation {
|
||||
int (* set_header_max_age)(void *response, uint32_t age);
|
||||
|
||||
/** Set the ETag option of a response. */
|
||||
int (* set_header_etag)(void *response, uint8_t *etag, size_t length);
|
||||
int (* set_header_etag)(void *response, const uint8_t *etag, size_t length);
|
||||
|
||||
/** Get the If-Match option of a request. */
|
||||
int (* get_header_if_match)(void *request, const uint8_t **etag);
|
||||
@ -181,7 +181,7 @@ struct rest_implementation {
|
||||
int (* get_header_host)(void *request, const char **host);
|
||||
|
||||
/** Set the location option of a response. */
|
||||
int (* set_header_location)(void *response, char *location);
|
||||
int (* set_header_location)(void *response, const char *location);
|
||||
|
||||
/** Get the payload option of a request. */
|
||||
int (* get_request_payload)(void *request, const uint8_t **payload);
|
||||
|
@ -14,7 +14,7 @@ WITH_UIP6=1
|
||||
UIP_CONF_IPV6=1
|
||||
|
||||
# variable for this Makefile
|
||||
# configure CoAP implementation (3|6|7)
|
||||
# configure CoAP implementation (3|7)
|
||||
WITH_COAP=7
|
||||
|
||||
# must be CFLAGS not variables
|
||||
@ -33,12 +33,6 @@ CFLAGS += -DWITH_COAP=7
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-07
|
||||
else ifeq ($(WITH_COAP), 6)
|
||||
${info INFO: compiling with CoAP-06}
|
||||
CFLAGS += -DWITH_COAP=6
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-06
|
||||
else ifeq ($(WITH_COAP), 3)
|
||||
${info INFO: compiling with CoAP-03}
|
||||
CFLAGS += -DWITH_COAP=3
|
||||
@ -50,7 +44,7 @@ ${info INFO: compiling with HTTP}
|
||||
CFLAGS += -DWITH_HTTP
|
||||
CFLAGS += -DREST=http_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=1
|
||||
APPS += rest-http-engine
|
||||
APPS += er-http-engine
|
||||
endif
|
||||
|
||||
APPS += erbium
|
||||
|
@ -8,12 +8,16 @@ coap-client-example.c: A CoAP client that polls the /toggle resource every 10 se
|
||||
|
||||
PRELIMINARIES
|
||||
-------------
|
||||
a) For convenience, define the Cooja addresses in /etc/hosts
|
||||
a) Make sure rpl-border-router has the same stack and fits into mote memory, e.g.:
|
||||
Disable RDC in border-router project-conf.h
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
b) For convenience, define the Cooja addresses in /etc/hosts
|
||||
aaaa::0212:7401:0001:0101 cooja1
|
||||
aaaa::0212:7402:0002:0202 cooja2
|
||||
...
|
||||
b) Get the Copper CoAP browser from https://addons.mozilla.org/en-US/firefox/addon/copper-270430/
|
||||
c) Optional: Save Tmotes as default target
|
||||
c) Get the Copper CoAP browser from https://addons.mozilla.org/en-US/firefox/addon/copper-270430/
|
||||
d) Optional: Save Tmotes as default target
|
||||
$ make TARGET=sky savetarget
|
||||
|
||||
COOJA HOWTO
|
||||
@ -26,8 +30,10 @@ Server only:
|
||||
|
||||
With client:
|
||||
1) $ make TARGET=cooja coap-client-server-example.csc
|
||||
2) Wait until red LED toggles on mote 2 (server)
|
||||
3) Choose "Click button on Sky 3" from the context menu of mote 3 (client) and watch serial output
|
||||
2) Open new terminal
|
||||
3) $ make connect-router-cooja
|
||||
4) Wait until red LED toggles on mote 2 (server)
|
||||
5) Choose "Click button on Sky 3" from the context menu of mote 3 (client) and watch serial output
|
||||
|
||||
TMOTES HOWTO
|
||||
------------
|
||||
@ -50,7 +56,7 @@ Add a client:
|
||||
|
||||
DETAILS
|
||||
-------
|
||||
The Erbium CoAP currently implements draft 07.
|
||||
The Erbium CoAP currently implements draft 08.
|
||||
Central features are commented in rest-server-example.c.
|
||||
In general, apps/er-coap-07 supports:
|
||||
* All CoAP-07 header options
|
||||
@ -60,6 +66,15 @@ In general, apps/er-coap-07 supports:
|
||||
* Resource discovery
|
||||
* Observing Resources (see EVENT_ and PRERIODIC_RESOURCE, note COAP_MAX_OBSERVERS)
|
||||
|
||||
REST IMPLEMENTATIONS
|
||||
--------------------
|
||||
The Makefile uses WITH_COAP to configure different implementations for the Erbium REST Engine.
|
||||
* WITH_COAP=7 uses Erbium CoAP 07 apps/er-coap-07/.
|
||||
The default port for coap-07 is 5683.
|
||||
* WITH_COAP=3 uses Erbium CoAP 03 apps/er-coap-03/.
|
||||
The default port for coap-03 is 61616.
|
||||
* WITH_COAP=0 is a stub to link an Erbium HTTP engine that uses the same resource abstraction (REST.x() functions and RESOURCE macros.
|
||||
|
||||
TODOs
|
||||
-----
|
||||
* Blockwise uploads (for POST/PUT payload)
|
||||
|
@ -57,7 +57,7 @@
|
||||
|
||||
/* Must be <= open transaction number. */
|
||||
#ifndef COAP_MAX_OBSERVERS
|
||||
#define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS
|
||||
#define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS-1
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -84,8 +84,6 @@
|
||||
/* For CoAP-specific example: not required for normal RESTful Web service. */
|
||||
#if WITH_COAP == 3
|
||||
#include "er-coap-03.h"
|
||||
#elif WITH_COAP == 6
|
||||
#include "er-coap-06.h"
|
||||
#elif WITH_COAP == 7
|
||||
#include "er-coap-07.h"
|
||||
#else
|
||||
@ -227,7 +225,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||
{
|
||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "Bl %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
||||
}
|
||||
#elif WITH_COAP >= 5
|
||||
#else
|
||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_path(request, &str)))
|
||||
{
|
||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "LP %.*s\n", len, str);
|
||||
@ -240,15 +238,15 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||
{
|
||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "B2 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
||||
}
|
||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL)) /* This getter allows NULL pointers to get only a subset of the block parameters. */
|
||||
/*
|
||||
* Critical Block1 option is currently rejected by engine.
|
||||
*
|
||||
if (strpos<=REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL))
|
||||
{
|
||||
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "B1 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
|
||||
}
|
||||
#if WITH_COAP >= 7
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
*/
|
||||
#endif /* CoAP > 03 */
|
||||
#endif /* CoAP-specific example */
|
||||
|
||||
if (strpos<=REST_MAX_CHUNK_SIZE && (len = REST.get_query(request, &query)))
|
||||
@ -281,16 +279,13 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
|
||||
coap_set_header_observe(response, 10);
|
||||
#if WITH_COAP == 3
|
||||
coap_set_header_block(response, 42, 0, 64); /* The block option might be overwritten by the framework when blockwise transfer is requested. */
|
||||
#elif WITH_COAP >= 5
|
||||
#else
|
||||
coap_set_header_proxy_uri(response, "ftp://x");
|
||||
coap_set_header_block2(response, 42, 0, 64); /* The block option might be overwritten by the framework when blockwise transfer is requested. */
|
||||
coap_set_header_block1(response, 23, 0, 16);
|
||||
#if WITH_COAP >= 7
|
||||
coap_set_header_accept(response, TEXT_PLAIN);
|
||||
coap_set_header_if_none_match(response);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* CoAP > 03 */
|
||||
#endif /* CoAP-specific example */
|
||||
}
|
||||
#endif /* REST_RES_MIRROR */
|
||||
@ -497,7 +492,7 @@ light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
||||
uint16_t light_photosynthetic = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
uint16_t light_solar = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
|
||||
|
||||
uint16_t *accept = NULL;
|
||||
const uint16_t *accept = NULL;
|
||||
int num = REST.get_header_accept(request, &accept);
|
||||
|
||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
||||
@ -537,7 +532,7 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
|
||||
{
|
||||
int battery = battery_sensor.value(0);
|
||||
|
||||
uint16_t *accept = NULL;
|
||||
const uint16_t *accept = NULL;
|
||||
int num = REST.get_header_accept(request, &accept);
|
||||
|
||||
if ((num==0) || (num && accept[0]==REST.type.TEXT_PLAIN))
|
||||
|
Loading…
Reference in New Issue
Block a user