Used Uncrustify and fixed Travis build errors.

This commit is contained in:
Lars Schmertmann 2014-04-22 10:31:43 +02:00 committed by Matthias Kovatsch
parent 3dd5bd7a37
commit bb737f85ae
50 changed files with 7115 additions and 7071 deletions

0
apps/er-coap/er-coap-conf.h Executable file → Normal file
View file

0
apps/er-coap/er-coap-constants.h Executable file → Normal file
View file

41
apps/er-coap/er-coap-engine.c Executable file → Normal file
View file

@ -41,8 +41,17 @@
#include <string.h> #include <string.h>
#include "er-coap-engine.h" #include "er-coap-engine.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
PROCESS(coap_engine, "CoAP Engine"); PROCESS(coap_engine, "CoAP Engine");
@ -107,14 +116,12 @@ coap_receive(void)
/* unreliable NON requests are answered with a NON as well */ /* unreliable NON requests are answered with a NON as well */
coap_init_message(response, COAP_TYPE_NON, CONTENT_2_05, coap_init_message(response, COAP_TYPE_NON, CONTENT_2_05,
coap_get_mid()); coap_get_mid());
}
/* mirror token */ /* mirror token */
}
if(message->token_len) { if(message->token_len) {
coap_set_token(response, message->token, message->token_len); coap_set_token(response, message->token, message->token_len);
}
/* get offset for blockwise transfers */ /* get offset for blockwise transfers */
}
if(coap_get_header_block2 if(coap_get_header_block2
(message, &block_num, NULL, &block_size, &block_offset)) { (message, &block_num, NULL, &block_size, &block_offset)) {
PRINTF("Blockwise: block request %lu (%u/%u) @ %lu bytes\n", PRINTF("Blockwise: block request %lu (%u/%u) @ %lu bytes\n",
@ -133,7 +140,7 @@ coap_receive(void)
if(erbium_status_code == NO_ERROR) { if(erbium_status_code == NO_ERROR) {
//TODO coap_handle_blockwise(request, response, start_offset, end_offset); /* TODO coap_handle_blockwise(request, response, start_offset, end_offset); */
/* resource is unaware of Block1 */ /* resource is unaware of Block1 */
if(IS_OPTION(message, COAP_OPTION_BLOCK1) if(IS_OPTION(message, COAP_OPTION_BLOCK1)
@ -197,9 +204,9 @@ coap_receive(void)
REST_MAX_CHUNK_SIZE)); REST_MAX_CHUNK_SIZE));
} /* blockwise transfer handling */ } /* blockwise transfer handling */
} /* no errors/hooks */ } /* no errors/hooks */
} /* successful service callback */ /* successful service callback */
/* serialize response */ /* serialize response */
}
if(erbium_status_code == NO_ERROR) { if(erbium_status_code == NO_ERROR) {
if((transaction->packet_len = coap_serialize_message(response, if((transaction->packet_len = coap_serialize_message(response,
transaction-> transaction->
@ -208,12 +215,10 @@ coap_receive(void)
erbium_status_code = PACKET_SERIALIZATION_ERROR; erbium_status_code = PACKET_SERIALIZATION_ERROR;
} }
} }
} else { } else {
erbium_status_code = NOT_IMPLEMENTED_5_01; erbium_status_code = NOT_IMPLEMENTED_5_01;
coap_error_message = "NoServiceCallbck"; /* no 'a' to fit into 16 bytes */ coap_error_message = "NoServiceCallbck"; /* no 'a' to fit into 16 bytes */
} /* if(service callback) */ } /* if(service callback) */
} else { } else {
erbium_status_code = SERVICE_UNAVAILABLE_5_03; erbium_status_code = SERVICE_UNAVAILABLE_5_03;
coap_error_message = "NoFreeTraBuffer"; coap_error_message = "NoFreeTraBuffer";
@ -249,14 +254,14 @@ coap_receive(void)
} }
/* if(ACKed transaction) */ /* if(ACKed transaction) */
transaction = NULL; transaction = NULL;
} /* request or response */ } /* request or response */
} /* parsed correctly */ } /* parsed correctly */
/* if(parsed correctly) */ /* if(parsed correctly) */
if(erbium_status_code == NO_ERROR) { if(erbium_status_code == NO_ERROR) {
if(transaction) if(transaction) {
coap_send_transaction(transaction); coap_send_transaction(transaction);
}
} else if(erbium_status_code == MANUAL_RESPONSE) { } else if(erbium_status_code == MANUAL_RESPONSE) {
PRINTF("Clearing transaction for manual response"); PRINTF("Clearing transaction for manual response");
coap_clear_transaction(transaction); coap_clear_transaction(transaction);
@ -272,9 +277,8 @@ coap_receive(void)
} else if(erbium_status_code >= 192) { } else if(erbium_status_code >= 192) {
/* set to sendable error code */ /* set to sendable error code */
erbium_status_code = INTERNAL_SERVER_ERROR_5_00; erbium_status_code = INTERNAL_SERVER_ERROR_5_00;
}
/* reuse input buffer for error message */ /* reuse input buffer for error message */
}
coap_init_message(message, reply_type, erbium_status_code, coap_init_message(message, reply_type, erbium_status_code,
message->mid); message->mid);
coap_set_payload(message, coap_error_message, coap_set_payload(message, coap_error_message,
@ -381,7 +385,6 @@ PT_THREAD(coap_blocking_request
coap_set_header_block2(request, state->block_num, 0, coap_set_header_block2(request, state->block_num, 0,
REST_MAX_CHUNK_SIZE); REST_MAX_CHUNK_SIZE);
} }
state->transaction->packet_len = coap_serialize_message(request, state->transaction->packet_len = coap_serialize_message(request,
state-> state->
transaction-> transaction->
@ -473,7 +476,8 @@ const struct rest_implementation coap_rest_implementation = {
BAD_GATEWAY_5_02, BAD_GATEWAY_5_02,
SERVICE_UNAVAILABLE_5_03, SERVICE_UNAVAILABLE_5_03,
GATEWAY_TIMEOUT_5_04, GATEWAY_TIMEOUT_5_04,
PROXYING_NOT_SUPPORTED_5_05}, PROXYING_NOT_SUPPORTED_5_05
},
{ {
TEXT_PLAIN, TEXT_PLAIN,
@ -497,6 +501,7 @@ const struct rest_implementation coap_rest_implementation = {
APPLICATION_FASTINFOSET, APPLICATION_FASTINFOSET,
APPLICATION_SOAP_FASTINFOSET, APPLICATION_SOAP_FASTINFOSET,
APPLICATION_JSON, APPLICATION_JSON,
APPLICATION_X_OBIX_BINARY} APPLICATION_X_OBIX_BINARY
}
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

0
apps/er-coap/er-coap-engine.h Executable file → Normal file
View file

19
apps/er-coap/er-coap-observe.c Executable file → Normal file
View file

@ -40,8 +40,17 @@
#include <string.h> #include <string.h>
#include "er-coap-observe.h" #include "er-coap-observe.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
MEMB(observers_memb, coap_observer_t, COAP_MAX_OBSERVERS); MEMB(observers_memb, coap_observer_t, COAP_MAX_OBSERVERS);
@ -199,8 +208,9 @@ coap_notify_observers(resource_t * resource)
transaction->packet + COAP_MAX_HEADER_SIZE, transaction->packet + COAP_MAX_HEADER_SIZE,
REST_MAX_CHUNK_SIZE, NULL); REST_MAX_CHUNK_SIZE, NULL);
if(notification->code < BAD_REQUEST_4_00) if(notification->code < BAD_REQUEST_4_00) {
coap_set_header_observe(notification, (obs->obs_counter)++); coap_set_header_observe(notification, (obs->obs_counter)++);
}
coap_set_token(notification, obs->token, obs->token_len); coap_set_token(notification, obs->token, obs->token_len);
/* TODO use resource-specific COAP_OBSERVE_REFRESH_INTERVAL for CON to check client interest */ /* TODO use resource-specific COAP_OBSERVE_REFRESH_INTERVAL for CON to check client interest */
@ -248,7 +258,8 @@ coap_observe_handler(resource_t * resource, void *request, void *response)
coap_remove_observer_by_token(&UIP_IP_BUF->srcipaddr, coap_remove_observer_by_token(&UIP_IP_BUF->srcipaddr,
UIP_UDP_BUF->srcport, coap_req->token, UIP_UDP_BUF->srcport, coap_req->token,
coap_req->token_len); coap_req->token_len);
} /* if(observe) */ /* if(observe) */
}
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

0
apps/er-coap/er-coap-observe.h Executable file → Normal file
View file

22
apps/er-coap/er-coap-res-well-known-core.c Executable file → Normal file
View file

@ -39,8 +39,17 @@
#include <string.h> #include <string.h>
#include "er-coap-engine.h" #include "er-coap-engine.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/*- Resource Handlers -------------------------------------------------------*/ /*- Resource Handlers -------------------------------------------------------*/
@ -89,15 +98,17 @@ well_known_core_get_handler(void *request, void *response, uint8_t * buffer,
if(len) { if(len) {
if(strcmp(filter, "href") == 0) { if(strcmp(filter, "href") == 0) {
attrib = strstr(resource->url, value); attrib = strstr(resource->url, value);
if(attrib == NULL || (value[-1] == '/' && attrib != resource->url)) if(attrib == NULL || (value[-1] == '/' && attrib != resource->url)) {
continue; continue;
}
end = attrib + strlen(attrib); end = attrib + strlen(attrib);
} else { } else {
attrib = strstr(resource->attributes, filter); attrib = strstr(resource->attributes, filter);
if(attrib == NULL if(attrib == NULL
|| (attrib[strlen(filter)] != '=' || (attrib[strlen(filter)] != '='
&& attrib[strlen(filter)] != '"')) && attrib[strlen(filter)] != '"')) {
continue; continue;
}
attrib += strlen(filter) + 2; attrib += strlen(filter) + 2;
end = strchr(attrib, '"'); end = strchr(attrib, '"');
} }
@ -119,8 +130,9 @@ well_known_core_get_handler(void *request, void *response, uint8_t * buffer,
} }
PRINTF("Filter: res has prefix %s\n", found); PRINTF("Filter: res has prefix %s\n", found);
if(lastchar != '*' if(lastchar != '*'
&& (found[len] != '"' && found[len] != ' ' && found[len] != '\0')) && (found[len] != '"' && found[len] != ' ' && found[len] != '\0')) {
continue; continue;
}
PRINTF("Filter: res has match\n"); PRINTF("Filter: res has match\n");
} }
#endif #endif

16
apps/er-coap/er-coap-separate.c Executable file → Normal file
View file

@ -41,8 +41,17 @@
#include "er-coap-separate.h" #include "er-coap-separate.h"
#include "er-coap-transactions.h" #include "er-coap-transactions.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/*- Separate Response API ---------------------------------------------------*/ /*- Separate Response API ---------------------------------------------------*/
@ -58,7 +67,7 @@
void void
coap_separate_reject() coap_separate_reject()
{ {
// TODO: Accept string pointer for custom error message /* TODO: Accept string pointer for custom error message */
erbium_status_code = SERVICE_UNAVAILABLE_5_03; erbium_status_code = SERVICE_UNAVAILABLE_5_03;
coap_error_message = "AlreadyInUse"; coap_error_message = "AlreadyInUse";
} }
@ -112,7 +121,6 @@ coap_separate_accept(void *request, coap_separate_t * separate_store)
/* signal the engine to skip automatic response and clear transaction by engine */ /* signal the engine to skip automatic response and clear transaction by engine */
erbium_status_code = MANUAL_RESPONSE; erbium_status_code = MANUAL_RESPONSE;
} else { } else {
PRINTF("ERROR: Response transaction for separate request not found!\n"); PRINTF("ERROR: Response transaction for separate request not found!\n");
erbium_status_code = INTERNAL_SERVER_ERROR_5_00; erbium_status_code = INTERNAL_SERVER_ERROR_5_00;

1
apps/er-coap/er-coap-separate.h Executable file → Normal file
View file

@ -55,7 +55,6 @@ typedef struct coap_separate {
/* separate + blockwise is untested! */ /* separate + blockwise is untested! */
uint32_t block2_num; uint32_t block2_num;
uint16_t block2_size; uint16_t block2_size;
} coap_separate_t; } coap_separate_t;
int coap_separate_handler(resource_t *resource, void *request, int coap_separate_handler(resource_t *resource, void *request,

15
apps/er-coap/er-coap-transactions.c Executable file → Normal file
View file

@ -41,8 +41,17 @@
#include "er-coap-transactions.h" #include "er-coap-transactions.h"
#include "er-coap-observe.h" #include "er-coap-observe.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS); MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
@ -58,7 +67,6 @@ coap_register_as_transaction_handler()
{ {
transaction_handler_process = PROCESS_CURRENT(); transaction_handler_process = PROCESS_CURRENT();
} }
coap_transaction_t * coap_transaction_t *
coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr, uint16_t port) coap_new_transaction(uint16_t mid, uip_ipaddr_t *addr, uint16_t port)
{ {
@ -147,7 +155,6 @@ coap_clear_transaction(coap_transaction_t * t)
memb_free(&transactions_memb, t); memb_free(&transactions_memb, t);
} }
} }
coap_transaction_t * coap_transaction_t *
coap_get_transaction_by_mid(uint16_t mid) coap_get_transaction_by_mid(uint16_t mid)
{ {

0
apps/er-coap/er-coap-transactions.h Executable file → Normal file
View file

182
apps/er-coap/er-coap.c Executable file → Normal file
View file

@ -40,11 +40,21 @@
#include <stdio.h> #include <stdio.h>
#include "contiki.h" #include "contiki.h"
#include "contiki-net.h" #include "contiki-net.h"
#include "er-coap.h" #include "er-coap.h"
#include "er-coap-transactions.h" #include "er-coap-transactions.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/*- Variables ---------------------------------------------------------------*/ /*- Variables ---------------------------------------------------------------*/
@ -125,29 +135,35 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number,
{ {
size_t i = 0; size_t i = 0;
if(0xFF000000 & value) if(0xFF000000 & value) {
++i; ++i;
if(0xFFFF0000 & value) }
if(0xFFFF0000 & value) {
++i; ++i;
if(0xFFFFFF00 & value) }
if(0xFFFFFF00 & value) {
++i; ++i;
if(0xFFFFFFFF & value) }
if(0xFFFFFFFF & value) {
++i; ++i;
}
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number, PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number,
i); i);
i = coap_set_option_header(number - current_number, i, buffer); i = coap_set_option_header(number - current_number, i, buffer);
if(0xFF000000 & value) if(0xFF000000 & value) {
buffer[i++] = (uint8_t)(value >> 24); buffer[i++] = (uint8_t)(value >> 24);
if(0xFFFF0000 & value) }
if(0xFFFF0000 & value) {
buffer[i++] = (uint8_t)(value >> 16); buffer[i++] = (uint8_t)(value >> 16);
if(0xFFFFFF00 & value) }
if(0xFFFFFF00 & value) {
buffer[i++] = (uint8_t)(value >> 8); buffer[i++] = (uint8_t)(value >> 8);
if(0xFFFFFFFF & value) }
if(0xFFFFFFFF & value) {
buffer[i++] = (uint8_t)(value); buffer[i++] = (uint8_t)(value);
}
return i; return i;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -246,13 +262,11 @@ coap_get_variable(const char *buffer, size_t length, const char *name,
if(value_end == NULL) { if(value_end == NULL) {
value_end = end; value_end = end;
} }
*output = start; *output = start;
return (value_end - start); return value_end - start;
} }
} }
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -467,9 +481,8 @@ coap_parse_message(void *packet, uint8_t * data, uint16_t data_len)
/* also for receiving, the Erbium upper bound is REST_MAX_CHUNK_SIZE */ /* also for receiving, the Erbium upper bound is REST_MAX_CHUNK_SIZE */
if(coap_pkt->payload_len > REST_MAX_CHUNK_SIZE) { if(coap_pkt->payload_len > REST_MAX_CHUNK_SIZE) {
coap_pkt->payload_len = REST_MAX_CHUNK_SIZE; coap_pkt->payload_len = REST_MAX_CHUNK_SIZE;
}
/* null-terminate payload */ /* null-terminate payload */
}
coap_pkt->payload[coap_pkt->payload_len] = '\0'; coap_pkt->payload[coap_pkt->payload_len] = '\0';
break; break;
@ -671,7 +684,6 @@ coap_get_query_variable(void *packet, const char *name, const char **output)
} }
return 0; return 0;
} }
int int
coap_get_post_variable(void *packet, const char *name, const char **output) coap_get_post_variable(void *packet, const char *name, const char **output)
{ {
@ -713,13 +725,12 @@ coap_get_header_content_format(void *packet, unsigned int *format)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) if(!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) {
return 0; return 0;
}
*format = coap_pkt->content_format; *format = coap_pkt->content_format;
return 1; return 1;
} }
int int
coap_set_header_content_format(void *packet, unsigned int format) coap_set_header_content_format(void *packet, unsigned int format)
{ {
@ -735,13 +746,12 @@ coap_get_header_accept(void *packet, unsigned int *accept)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) if(!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) {
return 0; return 0;
}
*accept = coap_pkt->accept; *accept = coap_pkt->accept;
return 1; return 1;
} }
int int
coap_set_header_accept(void *packet, unsigned int accept) coap_set_header_accept(void *packet, unsigned int accept)
{ {
@ -761,10 +771,8 @@ coap_get_header_max_age(void *packet, uint32_t * age)
*age = COAP_DEFAULT_MAX_AGE; *age = COAP_DEFAULT_MAX_AGE;
} else { } else {
*age = coap_pkt->max_age; *age = coap_pkt->max_age;
} return 1;
} }
return 1;
}
int int
coap_set_header_max_age(void *packet, uint32_t age) coap_set_header_max_age(void *packet, uint32_t age)
{ {
@ -780,13 +788,12 @@ coap_get_header_etag(void *packet, const uint8_t ** etag)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) if(!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) {
return 0; return 0;
}
*etag = coap_pkt->etag; *etag = coap_pkt->etag;
return coap_pkt->etag_len; return coap_pkt->etag_len;
} }
int int
coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len) coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len)
{ {
@ -805,13 +812,12 @@ coap_get_header_if_match(void *packet, const uint8_t ** etag)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) if(!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) {
return 0; return 0;
}
*etag = coap_pkt->if_match; *etag = coap_pkt->if_match;
return coap_pkt->if_match_len; return coap_pkt->if_match_len;
} }
int int
coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len) coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len)
{ {
@ -830,7 +836,6 @@ coap_get_header_if_none_match(void *packet)
return IS_OPTION((coap_packet_t *)packet, return IS_OPTION((coap_packet_t *)packet,
COAP_OPTION_IF_NONE_MATCH) ? 1 : 0; COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
} }
int int
coap_set_header_if_none_match(void *packet) coap_set_header_if_none_match(void *packet)
{ {
@ -843,13 +848,12 @@ coap_get_header_proxy_uri(void *packet, const char **uri)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) if(!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) {
return 0; return 0;
}
*uri = coap_pkt->proxy_uri; *uri = coap_pkt->proxy_uri;
return coap_pkt->proxy_uri_len; return coap_pkt->proxy_uri_len;
} }
int int
coap_set_header_proxy_uri(void *packet, const char *uri) coap_set_header_proxy_uri(void *packet, const char *uri)
{ {
@ -869,13 +873,12 @@ coap_get_header_uri_host(void *packet, const char **host)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) {
return 0; return 0;
}
*host = coap_pkt->uri_host; *host = coap_pkt->uri_host;
return coap_pkt->uri_host_len; return coap_pkt->uri_host_len;
} }
int int
coap_set_header_uri_host(void *packet, const char *host) coap_set_header_uri_host(void *packet, const char *host)
{ {
@ -893,13 +896,12 @@ coap_get_header_uri_path(void *packet, const char **path)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) {
return 0; return 0;
}
*path = coap_pkt->uri_path; *path = coap_pkt->uri_path;
return coap_pkt->uri_path_len; return coap_pkt->uri_path_len;
} }
int int
coap_set_header_uri_path(void *packet, const char *path) coap_set_header_uri_path(void *packet, const char *path)
{ {
@ -920,13 +922,12 @@ coap_get_header_uri_query(void *packet, const char **query)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
return 0; return 0;
}
*query = coap_pkt->uri_query; *query = coap_pkt->uri_query;
return coap_pkt->uri_query_len; return coap_pkt->uri_query_len;
} }
int int
coap_set_header_uri_query(void *packet, const char *query) coap_set_header_uri_query(void *packet, const char *query)
{ {
@ -947,13 +948,12 @@ coap_get_header_location_path(void *packet, const char **path)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) {
return 0; return 0;
}
*path = coap_pkt->location_path; *path = coap_pkt->location_path;
return coap_pkt->location_path_len; return coap_pkt->location_path_len;
} }
int int
coap_set_header_location_path(void *packet, const char *path) coap_set_header_location_path(void *packet, const char *path)
{ {
@ -969,12 +969,11 @@ coap_set_header_location_path(void *packet, const char *path)
coap_pkt->location_path_len = query - path; coap_pkt->location_path_len = query - path;
} else { } else {
coap_pkt->location_path_len = strlen(path); coap_pkt->location_path_len = strlen(path);
} } coap_pkt->location_path = path;
coap_pkt->location_path = path; if(coap_pkt->location_path_len > 0) {
if(coap_pkt->location_path_len > 0)
SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH); SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH);
}
return coap_pkt->location_path_len; return coap_pkt->location_path_len;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -983,13 +982,12 @@ coap_get_header_location_query(void *packet, const char **query)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) {
return 0; return 0;
}
*query = coap_pkt->location_query; *query = coap_pkt->location_query;
return coap_pkt->location_query_len; return coap_pkt->location_query_len;
} }
int int
coap_set_header_location_query(void *packet, const char *query) coap_set_header_location_query(void *packet, const char *query)
{ {
@ -1010,13 +1008,12 @@ coap_get_header_observe(void *packet, uint32_t * observe)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) if(!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) {
return 0; return 0;
}
*observe = coap_pkt->observe; *observe = coap_pkt->observe;
return 1; return 1;
} }
int int
coap_set_header_observe(void *packet, uint32_t observe) coap_set_header_observe(void *packet, uint32_t observe)
{ {
@ -1033,35 +1030,39 @@ coap_get_header_block2(void *packet, uint32_t * num, uint8_t * more,
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) {
return 0; return 0;
}
/* pointers may be NULL to get only specific block parameters */ /* pointers may be NULL to get only specific block parameters */
if(num != NULL) if(num != NULL) {
*num = coap_pkt->block2_num; *num = coap_pkt->block2_num;
if(more != NULL) }
if(more != NULL) {
*more = coap_pkt->block2_more; *more = coap_pkt->block2_more;
if(size != NULL) }
if(size != NULL) {
*size = coap_pkt->block2_size; *size = coap_pkt->block2_size;
if(offset != NULL) }
if(offset != NULL) {
*offset = coap_pkt->block2_offset; *offset = coap_pkt->block2_offset;
}
return 1; return 1;
} }
int int
coap_set_header_block2(void *packet, uint32_t num, uint8_t more, coap_set_header_block2(void *packet, uint32_t num, uint8_t more,
uint16_t size) uint16_t size)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(size < 16) if(size < 16) {
return 0; return 0;
if(size > 2048) }
if(size > 2048) {
return 0; return 0;
if(num > 0x0FFFFF) }
if(num > 0x0FFFFF) {
return 0; return 0;
}
coap_pkt->block2_num = num; coap_pkt->block2_num = num;
coap_pkt->block2_more = more ? 1 : 0; coap_pkt->block2_more = more ? 1 : 0;
coap_pkt->block2_size = size; coap_pkt->block2_size = size;
@ -1076,35 +1077,39 @@ coap_get_header_block1(void *packet, uint32_t * num, uint8_t * more,
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) if(!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) {
return 0; return 0;
}
/* pointers may be NULL to get only specific block parameters */ /* pointers may be NULL to get only specific block parameters */
if(num != NULL) if(num != NULL) {
*num = coap_pkt->block1_num; *num = coap_pkt->block1_num;
if(more != NULL) }
if(more != NULL) {
*more = coap_pkt->block1_more; *more = coap_pkt->block1_more;
if(size != NULL) }
if(size != NULL) {
*size = coap_pkt->block1_size; *size = coap_pkt->block1_size;
if(offset != NULL) }
if(offset != NULL) {
*offset = coap_pkt->block1_offset; *offset = coap_pkt->block1_offset;
}
return 1; return 1;
} }
int int
coap_set_header_block1(void *packet, uint32_t num, uint8_t more, coap_set_header_block1(void *packet, uint32_t num, uint8_t more,
uint16_t size) uint16_t size)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(size < 16) if(size < 16) {
return 0; return 0;
if(size > 2048) }
if(size > 2048) {
return 0; return 0;
if(num > 0x0FFFFF) }
if(num > 0x0FFFFF) {
return 0; return 0;
}
coap_pkt->block1_num = num; coap_pkt->block1_num = num;
coap_pkt->block1_more = more; coap_pkt->block1_more = more;
coap_pkt->block1_size = size; coap_pkt->block1_size = size;
@ -1118,13 +1123,12 @@ coap_get_header_size2(void *packet, uint32_t * size)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) {
return 0; return 0;
}
*size = coap_pkt->size2; *size = coap_pkt->size2;
return 1; return 1;
} }
int int
coap_set_header_size2(void *packet, uint32_t size) coap_set_header_size2(void *packet, uint32_t size)
{ {
@ -1140,13 +1144,12 @@ coap_get_header_size1(void *packet, uint32_t * size)
{ {
coap_packet_t *const coap_pkt = (coap_packet_t *)packet; coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) {
return 0; return 0;
}
*size = coap_pkt->size1; *size = coap_pkt->size1;
return 1; return 1;
} }
int int
coap_set_header_size1(void *packet, uint32_t size) coap_set_header_size1(void *packet, uint32_t size)
{ {
@ -1170,7 +1173,6 @@ coap_get_payload(void *packet, const uint8_t ** payload)
return 0; return 0;
} }
} }
int int
coap_set_payload(void *packet, const void *payload, size_t length) coap_set_payload(void *packet, const void *payload, size_t length)
{ {

5
apps/er-coap/er-coap.h Executable file → Normal file
View file

@ -40,7 +40,7 @@
#define ER_COAP_H_ #define ER_COAP_H_
#include <stddef.h> /* for size_t */ #include <stddef.h> /* for size_t */
#include "net/uip.h" #include "contiki-net.h"
#include "er-coap-constants.h" #include "er-coap-constants.h"
#include "er-coap-conf.h" #include "er-coap-conf.h"
@ -123,7 +123,6 @@ typedef struct {
uint16_t payload_len; uint16_t payload_len;
uint8_t *payload; uint8_t *payload;
} coap_packet_t; } coap_packet_t;
/* option format serialization */ /* option format serialization */
@ -159,7 +158,7 @@ typedef struct {
{ \ { \
PRINTF(text " [%lu%s (%u B/blk)]\n", coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \ PRINTF(text " [%lu%s (%u B/blk)]\n", coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \
uint32_t block = coap_pkt->field##_num << 4; \ uint32_t block = coap_pkt->field##_num << 4; \
if (coap_pkt->field##_more) block |= 0x8; \ if(coap_pkt->field##_more) { block |= 0x8; } \
block |= 0xF & coap_log_2(coap_pkt->field##_size / 16); \ block |= 0xF & coap_log_2(coap_pkt->field##_size / 16); \
PRINTF(text " encoded: 0x%lX\n", block); \ PRINTF(text " encoded: 0x%lX\n", block); \
option += coap_serialize_int_option(number, current_number, option, block); \ option += coap_serialize_int_option(number, current_number, option, block); \

0
apps/rest-engine/rest-constants.h Executable file → Normal file
View file

16
apps/rest-engine/rest-engine.c Executable file → Normal file
View file

@ -42,8 +42,17 @@
#include "contiki.h" #include "contiki.h"
#include "rest-engine.h" #include "rest-engine.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
PROCESS(rest_engine_process, "REST Engine"); PROCESS(rest_engine_process, "REST Engine");
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -151,7 +160,6 @@ rest_invoke_restful_service(void *request, void *response, uint8_t * buffer,
break; break;
} }
} }
if(!found) { if(!found) {
REST.set_response_status(response, REST.status.NOT_FOUND); REST.set_response_status(response, REST.status.NOT_FOUND);
} else if(allowed) { } else if(allowed) {
@ -160,7 +168,6 @@ rest_invoke_restful_service(void *request, void *response, uint8_t * buffer,
REST.subscription_handler(resource, request, response); REST.subscription_handler(resource, request, response);
} }
} }
return found & allowed; return found & allowed;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -184,7 +191,6 @@ PROCESS_THREAD(rest_engine_process, ev, data)
periodic_resource->period); periodic_resource->period);
} }
} }
while(1) { while(1) {
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();

1
apps/rest-engine/rest-engine.h Executable file → Normal file
View file

@ -66,7 +66,6 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* MIN */ #endif /* MIN */
struct resource_s; struct resource_s;
struct periodic_resource_s; struct periodic_resource_s;

View file

@ -13,7 +13,15 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
# automatically build RESTful resources # automatically build RESTful resources
REST_RESOURCES_DIR = ./resources REST_RESOURCES_DIR = ./resources
ifndef TARGET
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c')) REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
else
ifeq ($(TARGET), native)
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c'))
else
REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c' ! -name 'res-plugtest*'))
endif
endif
PROJECTDIRS += $(REST_RESOURCES_DIR) PROJECTDIRS += $(REST_RESOURCES_DIR)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)

21
examples/er-rest-example/er-example-client.c Executable file → Normal file
View file

@ -44,13 +44,21 @@
#include "er-coap-engine.h" #include "er-coap-engine.h"
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */ /* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */
#define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) /* cooja2 */ #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) /* cooja2 */
//#define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) /* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) */
#define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1) #define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1)
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT) #define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
@ -60,7 +68,6 @@
PROCESS(er_example_client, "Erbium Example Client"); PROCESS(er_example_client, "Erbium Example Client");
AUTOSTART_PROCESSES(&er_example_client); AUTOSTART_PROCESSES(&er_example_client);
uip_ipaddr_t server_ipaddr; uip_ipaddr_t server_ipaddr;
static struct etimer et; static struct etimer et;
@ -83,8 +90,6 @@ client_chunk_handler(void *response)
printf("|%.*s", len, (char *)chunk); printf("|%.*s", len, (char *)chunk);
} }
PROCESS_THREAD(er_example_client, ev, data) PROCESS_THREAD(er_example_client, ev, data)
{ {
PROCESS_BEGIN(); PROCESS_BEGIN();
@ -117,7 +122,6 @@ PROCESS_THREAD(er_example_client, ev, data)
coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1); coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1);
PRINT6ADDR(&server_ipaddr); PRINT6ADDR(&server_ipaddr);
PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT)); PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT));
@ -148,7 +152,6 @@ PROCESS_THREAD(er_example_client, ev, data)
uri_switch = (uri_switch + 1) % NUMBER_OF_URLS; uri_switch = (uri_switch + 1) % NUMBER_OF_URLS;
#endif #endif
} }
} }

0
examples/er-rest-example/er-example-server.c Executable file → Normal file
View file

1
examples/er-rest-example/er-plugtest-server.c Executable file → Normal file
View file

@ -122,7 +122,6 @@ PROCESS_THREAD(plugtest_server, ev, data)
/* Define application-specific events here. */ /* Define application-specific events here. */
while(1) { while(1) {
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
} /* while (1) */ } /* while (1) */
PROCESS_END(); PROCESS_END();

13
examples/er-rest-example/er-plugtest.h Executable file → Normal file
View file

@ -43,8 +43,17 @@
#warning "Should only be compiled for native!" #warning "Should only be compiled for native!"
#endif #endif
#define DEBUG DEBUG_PRINT #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
/* double expansion */ /* double expansion */
#define TO_STRING2(x) # x #define TO_STRING2(x) # x

0
examples/er-rest-example/project-conf.h Executable file → Normal file
View file

1
examples/er-rest-example/resources/res-battery.c Executable file → Normal file
View file

@ -78,5 +78,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_payload(response, msg, strlen(msg)); REST.set_response_payload(response, msg, strlen(msg));
} }
} }
#endif /* PLATFORM_HAS_BATTERY */ #endif /* PLATFORM_HAS_BATTERY */

4
examples/er-rest-example/resources/res-chunks.c Executable file → Normal file
View file

@ -80,13 +80,11 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
/* snprintf() does not adjust return value if truncated by size. */ /* snprintf() does not adjust return value if truncated by size. */
if(strpos > preferred_size) { if(strpos > preferred_size) {
strpos = preferred_size; strpos = preferred_size;
}
/* Truncate if above CHUNKS_TOTAL bytes. */ /* Truncate if above CHUNKS_TOTAL bytes. */
}
if(*offset + (int32_t)strpos > CHUNKS_TOTAL) { if(*offset + (int32_t)strpos > CHUNKS_TOTAL) {
strpos = CHUNKS_TOTAL - *offset; strpos = CHUNKS_TOTAL - *offset;
} }
REST.set_response_payload(response, buffer, strpos); REST.set_response_payload(response, buffer, strpos);
/* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */ /* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */

14
examples/er-rest-example/resources/res-event.c Executable file → Normal file
View file

@ -40,8 +40,17 @@
#include "rest-engine.h" #include "rest-engine.h"
#include "er-coap.h" #include "er-coap.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
static void res_event_handler(); static void res_event_handler();
@ -72,7 +81,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
/* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */ /* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */
} }
/* /*
* Additionally, res_event_handler must be implemented for each EVENT_RESOURCE. * Additionally, res_event_handler must be implemented for each EVENT_RESOURCE.
* It is called through <res_name>.trigger(), usually from the server process. * It is called through <res_name>.trigger(), usually from the server process.

12
examples/er-rest-example/resources/res-hello.c Executable file → Normal file
View file

@ -66,14 +66,16 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
/* The query string can be retrieved by rest_get_query() or parsed for its key-value pairs. */ /* The query string can be retrieved by rest_get_query() or parsed for its key-value pairs. */
if(REST.get_query_variable(request, "len", &len)) { if(REST.get_query_variable(request, "len", &len)) {
length = atoi(len); length = atoi(len);
if(length<0) length = 0; if(length < 0) {
if(length>REST_MAX_CHUNK_SIZE) length = REST_MAX_CHUNK_SIZE; length = 0;
}
if(length > REST_MAX_CHUNK_SIZE) {
length = REST_MAX_CHUNK_SIZE;
}
memcpy(buffer, message, length); memcpy(buffer, message, length);
} else { } else {
memcpy(buffer, message, length); memcpy(buffer, message, length);
} } REST.set_header_content_type(response, REST.type.TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); /* text/plain is the default, hence this option could be omitted. */
REST.set_header_etag(response, (uint8_t *)&length, 1); REST.set_header_etag(response, (uint8_t *)&length, 1);
REST.set_response_payload(response, buffer, length); REST.set_response_payload(response, buffer, length);
} }

22
examples/er-rest-example/resources/res-leds.c Executable file → Normal file
View file

@ -44,8 +44,17 @@
#include "rest-engine.h" #include "rest-engine.h"
#include "dev/leds.h" #include "dev/leds.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -80,9 +89,7 @@ res_post_put_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
} }
} else { } else {
success = 0; success = 0;
} } if(success && (len = REST.get_post_variable(request, "mode", &mode))) {
if(success && (len=REST.get_post_variable(request, "mode", &mode))) {
PRINTF("mode %s\n", mode); PRINTF("mode %s\n", mode);
if(strncmp(mode, "on", len) == 0) { if(strncmp(mode, "on", len) == 0) {
@ -94,11 +101,8 @@ res_post_put_handler(void* request, void* response, uint8_t *buffer, uint16_t pr
} }
} else { } else {
success = 0; success = 0;
} } if(!success) {
if(!success) {
REST.set_response_status(response, REST.status.BAD_REQUEST); REST.set_response_status(response, REST.status.BAD_REQUEST);
} }
} }
#endif /* PLATFORM_HAS_LEDS */ #endif /* PLATFORM_HAS_LEDS */

1
examples/er-rest-example/resources/res-light.c Executable file → Normal file
View file

@ -84,5 +84,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_payload(response, msg, strlen(msg)); REST.set_response_payload(response, msg, strlen(msg));
} }
} }
#endif /* PLATFORM_HAS_LIGHT */ #endif /* PLATFORM_HAS_LIGHT */

30
examples/er-rest-example/resources/res-mirror.c Executable file → Normal file
View file

@ -40,8 +40,17 @@
#include "rest-engine.h" #include "rest-engine.h"
#include "er-coap.h" #include "er-coap.h"
#define DEBUG DEBUG_NONE #define DEBUG 0
#include "net/uip-debug.h" #if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
static void res_any_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); static void res_any_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
@ -85,18 +94,16 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} }
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_accept(request, &content_format))) { if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_accept(request, &content_format))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ac %u\n", content_format); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "Ac %u\n", content_format);
}
/* Some getters such as for ETag or Location are omitted, as these options should not appear in a request. /* Some getters such as for ETag or Location are omitted, as these options should not appear in a request.
* Max-Age might appear in HTTP requests or used for special purposes in CoAP. */ * Max-Age might appear in HTTP requests or used for special purposes in CoAP. */
}
if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_max_age(request, &longint)) { if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_max_age(request, &longint)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "MA %lu\n", longint); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "MA %lu\n", longint);
}
/* For HTTP this is the Length option, for CoAP it is the Size option. */ /* For HTTP this is the Length option, for CoAP it is the Size option. */
}
if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_length(request, &longint)) { if(strpos <= REST_MAX_CHUNK_SIZE && REST.get_header_length(request, &longint)) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "SZ %lu\n", longint); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "SZ %lu\n", longint);
} }
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_host(request, &str))) { if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_header_host(request, &str))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UH %.*s\n", len, str); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UH %.*s\n", len, str);
} }
@ -105,17 +112,15 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} }
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_query(request, &str))) { if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_query(request, &str))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UQ %.*s\n", len, str); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "UQ %.*s\n", len, str);
}
/* Undefined request options for debugging: actions not required for normal RESTful Web service. */ /* Undefined request options for debugging: actions not required for normal RESTful Web service. */
}
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_path(request, &str))) { 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); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LP %.*s\n", len, str);
} }
if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_query(request, &str))) { if(strpos <= REST_MAX_CHUNK_SIZE && (len = coap_get_header_location_query(request, &str))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LQ %.*s\n", len, str); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "LQ %.*s\n", len, str);
}
/* CoAP-specific example: actions not required for normal RESTful Web service. */ /* CoAP-specific example: actions not required for normal RESTful Web service. */
}
coap_packet_t *const coap_pkt = (coap_packet_t *)request; coap_packet_t *const coap_pkt = (coap_packet_t *)request;
if(strpos <= REST_MAX_CHUNK_SIZE && coap_pkt->token_len > 0) { if(strpos <= REST_MAX_CHUNK_SIZE && coap_pkt->token_len > 0) {
@ -144,17 +149,12 @@ res_any_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if(strpos <= REST_MAX_CHUNK_SIZE && coap_get_header_block1(request, &block_num, &block_more, &block_size, NULL)) { 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); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "B1 %lu%s (%u)\n", block_num, block_more ? "+" : "", block_size);
} }
if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_request_payload(request, &bytes))) { if(strpos <= REST_MAX_CHUNK_SIZE && (len = REST.get_request_payload(request, &bytes))) {
strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%.*s", len, bytes); strpos += snprintf((char *)buffer + strpos, REST_MAX_CHUNK_SIZE - strpos + 1, "%.*s", len, bytes);
} }
if(strpos >= REST_MAX_CHUNK_SIZE) { if(strpos >= REST_MAX_CHUNK_SIZE) {
buffer[REST_MAX_CHUNK_SIZE - 1] = 0xBB; /* '»' to indicate truncation */ buffer[REST_MAX_CHUNK_SIZE - 1] = 0xBB; /* '»' to indicate truncation */
} }
REST.set_response_payload(response, buffer, strpos); REST.set_response_payload(response, buffer, strpos);
PRINTF("/mirror options received: %s\n", buffer); PRINTF("/mirror options received: %s\n", buffer);

View file

@ -70,7 +70,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_status(response, REST.status.CHANGED); REST.set_response_status(response, REST.status.CHANGED);
} }
} }
static void static void
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {

View file

View file

@ -70,7 +70,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_status(response, REST.status.CHANGED); REST.set_response_status(response, REST.status.CHANGED);
} }
} }
static void static void
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {

View file

View file

@ -81,7 +81,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
*offset = -1; *offset = -1;
} }
} }
static void static void
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {

View file

@ -74,13 +74,11 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
/* snprintf() does not adjust return value if truncated by size. */ /* snprintf() does not adjust return value if truncated by size. */
if(strpos > preferred_size) { if(strpos > preferred_size) {
strpos = preferred_size; strpos = preferred_size;
}
/* Truncate if above CHUNKS_TOTAL bytes. */ /* Truncate if above CHUNKS_TOTAL bytes. */
}
if(*offset + (int32_t)strpos > CHUNKS_TOTAL) { if(*offset + (int32_t)strpos > CHUNKS_TOTAL) {
strpos = CHUNKS_TOTAL - *offset; strpos = CHUNKS_TOTAL - *offset;
} }
REST.set_response_payload(response, buffer, strpos); REST.set_response_payload(response, buffer, strpos);
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); REST.set_header_content_type(response, REST.type.TEXT_PLAIN);

View file

View file

View file

View file

10
examples/er-rest-example/resources/res-plugtest-obs.c Executable file → Normal file
View file

@ -69,7 +69,6 @@ obs_purge_list()
PRINTF("### SERVER ACTION ### Purging obs list"); PRINTF("### SERVER ACTION ### Purging obs list");
coap_remove_observer_by_uri(NULL, 0, res_plugtest_obs.url); coap_remove_observer_by_uri(NULL, 0, res_plugtest_obs.url);
} }
static void static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -77,7 +76,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if(request != NULL) { if(request != NULL) {
PRINTF("/obs GET\n"); PRINTF("/obs GET\n");
} }
REST.set_header_content_type(response, obs_format); REST.set_header_content_type(response, obs_format);
REST.set_header_max_age(response, 5); REST.set_header_max_age(response, 5);
@ -91,7 +89,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} }
/* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */ /* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */
} }
static void static void
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -114,7 +111,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_status(response, REST.status.CHANGED); REST.set_response_status(response, REST.status.CHANGED);
} }
static void static void
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -124,7 +120,6 @@ res_delete_handler(void* request, void* response, uint8_t *buffer, uint16_t pref
REST.set_response_status(response, REST.status.DELETED); REST.set_response_status(response, REST.status.DELETED);
} }
/* /*
* Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE. * Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE.
* It will be called by the REST manager process with the defined period. * It will be called by the REST manager process with the defined period.
@ -134,7 +129,7 @@ res_periodic_handler()
{ {
++obs_counter; ++obs_counter;
//PRINTF("TICK %u for /%s\n", obs_counter, r->url); /* PRINTF("TICK %u for /%s\n", obs_counter, r->url); */
if(obs_status == 1) { if(obs_status == 1) {
@ -156,6 +151,5 @@ res_periodic_handler()
} else { } else {
/* Notify the registered observers with the given message type, observe option, and payload. */ /* Notify the registered observers with the given message type, observe option, and payload. */
REST.notify_subscribers(&res_plugtest_obs); REST.notify_subscribers(&res_plugtest_obs);
} } obs_status = 0;
obs_status = 0;
} }

0
examples/er-rest-example/resources/res-plugtest-path.c Executable file → Normal file
View file

View file

@ -62,9 +62,8 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if((len = REST.get_query(request, &query))) { if((len = REST.get_query(request, &query))) {
PRINTF("Query: %.*s\n", len, query); PRINTF("Query: %.*s\n", len, query);
} } /* Code 2.05 CONTENT is default. */
REST.set_header_content_type(response,
/* Code 2.05 CONTENT is default. */REST.set_header_content_type(response,
REST.type.TEXT_PLAIN); REST.type.TEXT_PLAIN);
REST.set_response_payload( REST.set_response_payload(
response, response,

View file

@ -56,8 +56,7 @@ PERIODIC_RESOURCE(res_plugtest_separate,
res_resume_handler); res_resume_handler);
/* A structure to store the required information */ /* A structure to store the required information */
typedef struct application_separate_store typedef struct application_separate_store {
{
/* Provided by Erbium to store generic request information such as remote address and token. */ /* Provided by Erbium to store generic request information such as remote address and token. */
coap_separate_t request_metadata; coap_separate_t request_metadata;
/* Add fields for addition information to be stored for finalizing, e.g.: */ /* Add fields for addition information to be stored for finalizing, e.g.: */
@ -91,7 +90,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
} }
static void static void
res_resume_handler() res_resume_handler()
{ {

5
examples/er-rest-example/resources/res-plugtest-test.c Executable file → Normal file
View file

@ -68,7 +68,6 @@ test_update_etag()
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]); PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", test_etag_len, test_etag[0], test_etag[1], test_etag[2], test_etag[3], test_etag[4], test_etag[5], test_etag[6], test_etag[7]);
} }
static void static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -77,7 +76,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if(test_change) { if(test_change) {
test_update_etag(); test_update_etag();
} }
PRINTF("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); PRINTF("/test GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
if((len = coap_get_header_etag(request, &bytes)) > 0 if((len = coap_get_header_etag(request, &bytes)) > 0
@ -100,7 +98,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid)); snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid));
} }
} }
static void static void
res_post_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_post_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -110,7 +107,6 @@ res_post_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
REST.set_response_status(response, REST.status.CREATED); REST.set_response_status(response, REST.status.CREATED);
REST.set_header_location(response, "/location1/location2/location3"); REST.set_header_location(response, "/location1/location2/location3");
} }
static void static void
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -153,7 +149,6 @@ res_put_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_status(response, PRECONDITION_FAILED_4_12); REST.set_response_status(response, PRECONDITION_FAILED_4_12);
} }
} }
static void static void
res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_delete_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {

View file

@ -55,7 +55,6 @@ static uint8_t validate_etag[8] = { 0 };
static uint8_t validate_etag_len = 1; static uint8_t validate_etag_len = 1;
static uint8_t validate_change = 1; static uint8_t validate_change = 1;
static const uint8_t *bytes = NULL; static const uint8_t *bytes = NULL;
static size_t len = 0; static size_t len = 0;
@ -72,7 +71,6 @@ validate_update_etag()
PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", PRINTF("### SERVER ACTION ### Changed ETag %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
validate_etag_len, validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]); validate_etag_len, validate_etag[0], validate_etag[1], validate_etag[2], validate_etag[3], validate_etag[4], validate_etag[5], validate_etag[6], validate_etag[7]);
} }
static void static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
@ -81,7 +79,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
if(validate_change) { if(validate_change) {
validate_update_etag(); validate_update_etag();
} }
PRINTF("/validate GET"); PRINTF("/validate GET");
PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); PRINTF("(%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid);
@ -106,7 +103,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
coap_req->mid)); coap_req->mid));
} }
} }
static void static void
res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) res_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {

1
examples/er-rest-example/resources/res-push.c Executable file → Normal file
View file

@ -71,7 +71,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
/* The REST.subscription_handler() will be called for observable resources by the REST framework. */ /* The REST.subscription_handler() will be called for observable resources by the REST framework. */
} }
/* /*
* Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE. * Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE.
* It will be called by the REST manager process with the defined period. * It will be called by the REST manager process with the defined period.

6
examples/er-rest-example/resources/res-radio.c Executable file → Normal file
View file

@ -75,9 +75,7 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} }
} else { } else {
success = 0; success = 0;
} } if(success) {
if(success) {
if(accept == -1 || accept == REST.type.TEXT_PLAIN) { if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", radio_sensor.value(param)); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", radio_sensor.value(param));
@ -91,7 +89,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
} else if(param == RADIO_SENSOR_LAST_PACKET) { } else if(param == RADIO_SENSOR_LAST_PACKET) {
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", radio_sensor.value(param)); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'rssi':%d}", radio_sensor.value(param));
} }
REST.set_response_payload(response, buffer, strlen((char *)buffer)); REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else { } else {
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
@ -102,5 +99,4 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
REST.set_response_status(response, REST.status.BAD_REQUEST); REST.set_response_status(response, REST.status.BAD_REQUEST);
} }
} }
#endif /* PLATFORM_HAS_RADIO */ #endif /* PLATFORM_HAS_RADIO */

4
examples/er-rest-example/resources/res-separate.c Executable file → Normal file
View file

@ -60,7 +60,6 @@ typedef struct application_separate_store {
/* Add fields for addition information to be stored for finalizing, e.g.: */ /* Add fields for addition information to be stored for finalizing, e.g.: */
char buffer[16]; char buffer[16];
} application_separate_store_t; } application_separate_store_t;
#define COAP_MAX_OPEN_SEPARATE 2 #define COAP_MAX_OPEN_SEPARATE 2
@ -92,7 +91,6 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
snprintf(separate_store->buffer, sizeof(separate_store->buffer), "StoredInfo"); snprintf(separate_store->buffer, sizeof(separate_store->buffer), "StoredInfo");
} }
} }
static void static void
res_resume_handler() res_resume_handler()
{ {
@ -117,7 +115,7 @@ res_resume_handler()
coap_send_transaction(transaction); coap_send_transaction(transaction);
/* The engine will clear the transaction (right after send for NON, after acked for CON). */ /* The engine will clear the transaction (right after send for NON, after acked for CON). */
//FIXME there could me more! /* FIXME there could me more! */
separate_active = 0; separate_active = 0;
} else { } else {
/* /*

4
examples/er-rest-example/resources/res-sub.c Executable file → Normal file
View file

@ -65,7 +65,5 @@ res_get_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "Request any sub-resource of /%s", res_sub.url); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "Request any sub-resource of /%s", res_sub.url);
} else { } else {
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, ".%.*s", len - base_len, uri_path + base_len); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, ".%.*s", len - base_len, uri_path + base_len);
} } REST.set_response_payload(response, buffer, strlen((char *)buffer));
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} }

1
examples/er-rest-example/resources/res-toggle.c Executable file → Normal file
View file

@ -60,5 +60,4 @@ res_post_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
{ {
leds_invert(LEDS_RED); leds_invert(LEDS_RED);
} }
#endif /* PLATFORM_HAS_LEDS */ #endif /* PLATFORM_HAS_LEDS */