Skip to content

Commit

Permalink
Merge branch 'warning_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
David Navarro committed Apr 27, 2015
2 parents bf2a80c + 7e3baf8 commit 6b0508b
Show file tree
Hide file tree
Showing 26 changed files with 229 additions and 203 deletions.
40 changes: 20 additions & 20 deletions core/er-coap-13/er-coap-13.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ uint32_t
coap_parse_int_option(uint8_t *bytes, size_t length)
{
uint32_t var = 0;
int i = 0;
size_t i = 0;
while (i<length)
{
var <<= 8;
Expand Down Expand Up @@ -175,7 +175,7 @@ coap_serialize_array_option(unsigned int number, unsigned int current_number, ui

if (split_char!='\0')
{
int j;
size_t j;
uint8_t *part_start = array;
uint8_t *part_end = NULL;
size_t temp_length;
Expand Down Expand Up @@ -231,7 +231,7 @@ coap_serialize_multi_option(unsigned int number, unsigned int current_number, ui
/*-----------------------------------------------------------------------------------*/
static
void
coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option, size_t option_len, char separator)
coap_merge_multi_option(uint8_t **dst, size_t *dst_len, uint8_t *option, size_t option_len, char separator)
{
/* Merge multiple options. */
if (*dst_len > 0)
Expand All @@ -248,7 +248,7 @@ coap_merge_multi_option(char **dst, size_t *dst_len, uint8_t *option, size_t opt
else
{
/* dst is empty: set to option */
*dst = (char *) option;
*dst = option;
*dst_len = option_len;
}
}
Expand All @@ -265,13 +265,13 @@ coap_add_multi_option(multi_option_t **dst, uint8_t *option, size_t option_len,
opt->len = option_len;
if (is_static)
{
opt->data = (char*)option;
opt->data = option;
opt->is_static = 1;
}
else
{
opt->is_static = 0;
opt->data = (char *)lwm2m_malloc(option_len);
opt->data = (uint8_t *)lwm2m_malloc(option_len);
if (opt->data == NULL)
{
lwm2m_free(opt);
Expand Down Expand Up @@ -345,11 +345,11 @@ char * coap_get_multi_option_as_string(multi_option_t * option)
/*-----------------------------------------------------------------------------------*/
static
int
coap_get_variable(const char *buffer, size_t length, const char *name, const char **output)
coap_get_variable(const uint8_t *buffer, size_t length, const char *name, const char **output)
{
const char *start = NULL;
const char *end = NULL;
const char *value_end = NULL;
const uint8_t *start = NULL;
const uint8_t *end = NULL;
const uint8_t *value_end = NULL;
size_t name_len = 0;

/*initialize the output buffer first*/
Expand All @@ -360,18 +360,18 @@ coap_get_variable(const char *buffer, size_t length, const char *name, const cha

for (start = buffer; start + name_len < end; ++start){
if ((start == buffer || start[-1] == '&') && start[name_len] == '=' &&
strncmp(name, start, name_len)==0) {
strncmp(name, (char *)start, name_len)==0) {

/* Point start to variable value */
start += name_len + 1;

/* Point end to the end of the value */
value_end = (const char *) memchr(start, '&', end - start);
value_end = (const uint8_t *) memchr(start, '&', end - start);
if (value_end == NULL) {
value_end = end;
}

*output = start;
*output = (char *)start;

return (value_end - start);
}
Expand Down Expand Up @@ -661,7 +661,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
break;

case COAP_OPTION_URI_HOST:
coap_pkt->uri_host = (char *) current_option;
coap_pkt->uri_host = current_option;
coap_pkt->uri_host_len = option_length;
PRINTF("Uri-Host [%.*s]\n", coap_pkt->uri_host_len, coap_pkt->uri_host);
break;
Expand All @@ -687,13 +687,13 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
break;
case COAP_OPTION_LOCATION_QUERY:
/* 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_pkt->location_query), &(coap_pkt->location_query_len), current_option, option_length, '&');
coap_merge_multi_option( &(coap_pkt->location_query), &(coap_pkt->location_query_len), current_option, option_length, '&');
PRINTF("Location-Query [%.*s]\n", coap_pkt->location_query_len, coap_pkt->location_query);
break;

case COAP_OPTION_PROXY_URI:
/*FIXME check for own end-point */
coap_pkt->proxy_uri = (char *) current_option;
coap_pkt->proxy_uri = current_option;
coap_pkt->proxy_uri_len = option_length;
/*TODO length > 270 not implemented (actually not required) */
PRINTF("Proxy-Uri NOT IMPLEMENTED [%.*s]\n", coap_pkt->proxy_uri_len, coap_pkt->proxy_uri);
Expand Down Expand Up @@ -765,7 +765,7 @@ coap_get_post_variable(void *packet, const char *name, const char **output)
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;

if (coap_pkt->payload_len) {
return coap_get_variable((const char *)coap_pkt->payload, coap_pkt->payload_len, name, output);
return coap_get_variable(coap_pkt->payload, coap_pkt->payload_len, name, output);
}
return 0;
}
Expand Down Expand Up @@ -968,7 +968,7 @@ coap_get_header_uri_host(void *packet, const char **host)

if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) return 0;

*host = coap_pkt->uri_host;
*host = (char *)coap_pkt->uri_host;
return coap_pkt->uri_host_len;
}

Expand All @@ -977,7 +977,7 @@ coap_set_header_uri_host(void *packet, const char *host)
{
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;

coap_pkt->uri_host = host;
coap_pkt->uri_host = (uint8_t *)host;
coap_pkt->uri_host_len = strlen(host);

SET_OPTION(coap_pkt, COAP_OPTION_URI_HOST);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ coap_get_header_location_query(void *packet, const char **query)
}

int
coap_set_header_location_query(void *packet, const char *query)
coap_set_header_location_query(void *packet, char *query)
{
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;

Expand Down
11 changes: 5 additions & 6 deletions core/er-coap-13/er-coap-13.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ typedef struct _multi_option_t {
struct _multi_option_t *next;
uint8_t is_static;
uint8_t len;
char *data;
uint8_t *data;
} multi_option_t;

/* Parsed message struct */
Expand All @@ -221,15 +221,15 @@ 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;
const char *proxy_uri;
const uint8_t *proxy_uri;
uint8_t etag_len;
uint8_t etag[COAP_ETAG_LEN];
size_t uri_host_len;
const char *uri_host;
const uint8_t *uri_host;
multi_option_t *location_path;
uint16_t uri_port;
size_t location_query_len;
const char *location_query;
uint8_t *location_query;
multi_option_t *uri_path;
uint32_t observe;
uint8_t token_len;
Expand Down Expand Up @@ -312,7 +312,6 @@ typedef struct {
}

/* To store error code and human-readable payload */
extern coap_status_t coap_error_code;
extern char *coap_error_message;

uint16_t coap_get_mid(void);
Expand Down Expand Up @@ -369,7 +368,7 @@ int coap_get_header_location_path(void *packet, const char **path); /* In-place
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, const char *query);
int coap_set_header_location_query(void *packet, char *query);

int coap_get_header_observe(void *packet, uint32_t *observe);
int coap_set_header_observe(void *packet, uint32_t observe);
Expand Down
17 changes: 10 additions & 7 deletions core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ typedef struct _obs_list_
} obs_list_t;

// defined in uri.c
int lwm2m_get_number(const char * uriString, size_t uriLength);
int lwm2m_get_number(char * uriString, size_t uriLength);
lwm2m_uri_t * lwm2m_decode_uri(char * altPath, multi_option_t *uriPath);
int prv_get_number(uint8_t * uriString, size_t uriLength);

// defined in objects.c
coap_status_t object_read(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char ** bufferP, int * lengthP);
coap_status_t object_write(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_create(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_execute(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_read(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, uint8_t ** bufferP, size_t * lengthP);
coap_status_t object_write(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, uint8_t * buffer, size_t length);
coap_status_t object_create(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, uint8_t * buffer, size_t length);
coap_status_t object_execute(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, uint8_t * buffer, size_t length);
coap_status_t object_delete(lwm2m_context_t * contextP, lwm2m_uri_t * uriP);
bool object_isInstanceNew(lwm2m_context_t * contextP, uint16_t objectId, uint16_t instanceId);
int prv_getRegisterPayload(lwm2m_context_t * contextP, char * buffer, size_t length);
int prv_getRegisterPayload(lwm2m_context_t * contextP, uint8_t * buffer, size_t length);
int object_getServers(lwm2m_context_t * contextP);

// defined in transaction.c
Expand Down Expand Up @@ -160,8 +161,10 @@ void delete_observed_list(lwm2m_context_t * contextP);

// defined in utils.c
lwm2m_binding_t lwm2m_stringToBinding(uint8_t *buffer, size_t length);
int prv_isAltPathValid(char * altPath);
#ifdef LWM2M_CLIENT_MODE
lwm2m_server_t * prv_findServer(lwm2m_context_t * contextP, void * fromSessionH);
lwm2m_server_t * utils_findBootstrapServer(lwm2m_context_t * contextP, void * fromSessionH);
int prv_isAltPathValid(char * altPath);
#endif

#endif
36 changes: 18 additions & 18 deletions core/liblwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int lwm2m_strncmp(const char * s1, const char * s2, size_t n);
// In case of error, this must return a negative value.
// Per POSIX specifications, time_t is a signed integer.
// An implementation for POSIX systems is provided in utils.c
time_t lwm2m_gettime();
time_t lwm2m_gettime(void);

/*
* Error code
Expand Down Expand Up @@ -183,18 +183,18 @@ void lwm2m_list_free(lwm2m_list_t * head);
*/

// defined in utils.c
int lwm2m_PlainTextToInt64(char * buffer, int length, int64_t * dataP);
int lwm2m_PlainTextToFloat64(char * buffer, int length, double * dataP);
int lwm2m_PlainTextToInt64(uint8_t * buffer, int length, int64_t * dataP);
int lwm2m_PlainTextToFloat64(uint8_t * buffer, int length, double * dataP);

/*
* These utility functions allocate a new buffer storing the plain text
* representation of data. They return the size in bytes of the buffer
* or 0 in case of error.
* There is no trailing '\0' character in the buffer.
*/
size_t lwm2m_int64ToPlainText(int64_t data, char ** bufferP);
size_t lwm2m_float64ToPlainText(double data, char ** bufferP);
size_t lwm2m_boolToPlainText(bool data, char ** bufferP);
size_t lwm2m_int64ToPlainText(int64_t data, uint8_t ** bufferP);
size_t lwm2m_float64ToPlainText(double data, uint8_t ** bufferP);
size_t lwm2m_boolToPlainText(bool data, uint8_t ** bufferP);


/*
Expand Down Expand Up @@ -255,8 +255,8 @@ typedef struct
} lwm2m_tlv_t;

lwm2m_tlv_t * lwm2m_tlv_new(int size);
int lwm2m_tlv_parse(char * buffer, size_t bufferLen, lwm2m_tlv_t ** dataP);
int lwm2m_tlv_serialize(int size, lwm2m_tlv_t * tlvP, char ** bufferP);
int lwm2m_tlv_parse(uint8_t * buffer, size_t bufferLen, lwm2m_tlv_t ** dataP);
int lwm2m_tlv_serialize(int size, lwm2m_tlv_t * tlvP, uint8_t ** bufferP);
void lwm2m_tlv_free(int size, lwm2m_tlv_t * tlvP);

void lwm2m_tlv_encode_int(int64_t data, lwm2m_tlv_t * tlvP);
Expand All @@ -273,12 +273,12 @@ void lwm2m_tlv_include(lwm2m_tlv_t * subTlvP, size_t count, lwm2m_tlv_t * tlvP);
* the data. They return the size in bytes of the TLV record, 0 in case
* of error.
*/
int lwm2m_intToTLV(lwm2m_tlv_type_t type, int64_t data, uint16_t id, char * buffer, size_t buffer_len);
int lwm2m_boolToTLV(lwm2m_tlv_type_t type, bool value, uint16_t id, char * buffer, size_t buffer_len);
int lwm2m_opaqueToTLV(lwm2m_tlv_type_t type, uint8_t * dataP, size_t data_len, uint16_t id, char * buffer, size_t buffer_len);
int lwm2m_intToTLV(lwm2m_tlv_type_t type, int64_t data, uint16_t id, uint8_t * buffer, size_t buffer_len);
int lwm2m_boolToTLV(lwm2m_tlv_type_t type, bool value, uint16_t id, uint8_t * buffer, size_t buffer_len);
int lwm2m_opaqueToTLV(lwm2m_tlv_type_t type, uint8_t * dataP, size_t data_len, uint16_t id, uint8_t * buffer, size_t buffer_len);
int lwm2m_decodeTLV(uint8_t * buffer, size_t buffer_len, lwm2m_tlv_type_t * oType, uint16_t * oID, size_t * oDataIndex, size_t * oDataLen);
int lwm2m_opaqueToInt(char * buffer, size_t buffer_len, int64_t * dataP);
int lwm2m_opaqueToFloat(char * buffer, size_t buffer_len, double * dataP);
int lwm2m_opaqueToInt(uint8_t * buffer, size_t buffer_len, int64_t * dataP);
int lwm2m_opaqueToFloat(uint8_t * buffer, size_t buffer_len, double * dataP);

/*
* URI
Expand Down Expand Up @@ -312,7 +312,7 @@ typedef struct
// Return the number of characters read from buffer or 0 in case of error.
// Valid URIs: /1, /1/, /1/2, /1/2/, /1/2/3
// Invalid URIs: /, //, //2, /1//, /1//3, /1/2/3/, /1/2/3/4
int lwm2m_stringToUri(const char * buffer, size_t buffer_len, lwm2m_uri_t * uriP);
int lwm2m_stringToUri(char * buffer, size_t buffer_len, lwm2m_uri_t * uriP);


/*
Expand All @@ -327,7 +327,7 @@ typedef struct _lwm2m_object_t lwm2m_object_t;

typedef uint8_t (*lwm2m_read_callback_t) (uint16_t instanceId, int * numDataP, lwm2m_tlv_t ** dataArrayP, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_write_callback_t) (uint16_t instanceId, int numData, lwm2m_tlv_t * dataArray, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_execute_callback_t) (uint16_t instanceId, uint16_t resourceId, char * buffer, int length, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_execute_callback_t) (uint16_t instanceId, uint16_t resourceId, uint8_t * buffer, int length, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_create_callback_t) (uint16_t instanceId, int numData, lwm2m_tlv_t * dataArray, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_delete_callback_t) (uint16_t instanceId, lwm2m_object_t * objectP);
typedef void (*lwm2m_close_callback_t) (lwm2m_object_t * objectP);
Expand Down Expand Up @@ -593,9 +593,9 @@ void lwm2m_set_monitoring_callback(lwm2m_context_t * contextP, lwm2m_result_call

// Device Management APIs
int lwm2m_dm_read(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_write(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, char * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_execute(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, char * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_create(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, char * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_write(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_execute(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_create(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, uint8_t * buffer, int length, lwm2m_result_callback_t callback, void * userData);
int lwm2m_dm_delete(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData);

// Information Reporting APIs
Expand Down
12 changes: 6 additions & 6 deletions core/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ coap_status_t handle_dm_request(lwm2m_context_t * contextP,
{
case COAP_GET:
{
char * buffer = NULL;
int length = 0;
uint8_t * buffer = NULL;
size_t length = 0;

result = object_read(contextP, uriP, &buffer, &length);
if (COAP_205_CONTENT == result)
Expand Down Expand Up @@ -324,7 +324,7 @@ static int prv_make_operation(lwm2m_context_t * contextP,
uint16_t clientID,
lwm2m_uri_t * uriP,
coap_method_t method,
char * buffer,
uint8_t * buffer,
int length,
lwm2m_result_callback_t callback,
void * userData)
Expand Down Expand Up @@ -380,7 +380,7 @@ int lwm2m_dm_read(lwm2m_context_t * contextP,
int lwm2m_dm_write(lwm2m_context_t * contextP,
uint16_t clientID,
lwm2m_uri_t * uriP,
char * buffer,
uint8_t * buffer,
int length,
lwm2m_result_callback_t callback,
void * userData)
Expand Down Expand Up @@ -408,7 +408,7 @@ int lwm2m_dm_write(lwm2m_context_t * contextP,
int lwm2m_dm_execute(lwm2m_context_t * contextP,
uint16_t clientID,
lwm2m_uri_t * uriP,
char * buffer,
uint8_t * buffer,
int length,
lwm2m_result_callback_t callback,
void * userData)
Expand All @@ -426,7 +426,7 @@ int lwm2m_dm_execute(lwm2m_context_t * contextP,
int lwm2m_dm_create(lwm2m_context_t * contextP,
uint16_t clientID,
lwm2m_uri_t * uriP,
char * buffer,
uint8_t * buffer,
int length,
lwm2m_result_callback_t callback,
void * userData)
Expand Down
Loading

0 comments on commit 6b0508b

Please sign in to comment.