From 5d2118345b2609c5a378b74a3b97a1b1c5fdae35 Mon Sep 17 00:00:00 2001 From: Juri Glass Date: Mon, 11 Jul 2011 13:46:35 +0200 Subject: [PATCH] no compile time warnings --- .../sml/sml_get_profile_pack_request.h | 2 +- sml/include/sml/sml_list.h | 4 +- sml/include/sml/sml_message.h | 8 ++-- sml/include/sml/sml_number.h | 2 +- sml/include/sml/sml_open_request.h | 2 +- sml/include/sml/sml_open_response.h | 2 +- sml/include/sml/sml_status.h | 8 ++-- sml/include/sml/sml_time.h | 4 +- sml/include/sml/sml_tree.h | 2 +- sml/include/sml/sml_value.h | 16 +++---- sml/src/sml_get_profile_pack_request.c | 46 +++++-------------- sml/src/sml_message.c | 25 +++++----- sml/src/sml_number.c | 2 + sml/src/sml_time.c | 10 ++-- sml/src/sml_tree.c | 8 ++-- 15 files changed, 62 insertions(+), 79 deletions(-) diff --git a/sml/include/sml/sml_get_profile_pack_request.h b/sml/include/sml/sml_get_profile_pack_request.h index 428235f..b3c2b22 100644 --- a/sml/include/sml/sml_get_profile_pack_request.h +++ b/sml/include/sml/sml_get_profile_pack_request.h @@ -38,7 +38,7 @@ typedef struct { sml_time *begin_time; // optional sml_time *end_time; // optional sml_tree_path *parameter_tree_path; - // sml_object_list * object_list; // optional sml_object_list not implemented yet + void *object_list; // sml_object_list * object_list; // optional sml_object_list not implemented yet sml_tree *das_details; // optional } sml_get_profile_pack_request; diff --git a/sml/include/sml/sml_list.h b/sml/include/sml/sml_list.h index b029cbf..923f5dd 100644 --- a/sml/include/sml/sml_list.h +++ b/sml/include/sml/sml_list.h @@ -36,8 +36,8 @@ typedef struct sml_list_entry { octet_string *obj_name; sml_status *status; // optional sml_time *val_time; // optional - sml_unit unit; // optional - i8 scaler; // optional + sml_unit *unit; // optional + i8 *scaler; // optional sml_value *value; sml_signature *value_signature; // optional diff --git a/sml/include/sml/sml_message.h b/sml/include/sml/sml_message.h index 6e6c4ac..0a04551 100644 --- a/sml/include/sml/sml_message.h +++ b/sml/include/sml/sml_message.h @@ -55,16 +55,16 @@ extern "C" { typedef struct { - u16 tag; + u16 *tag; void *data; } sml_message_body; typedef struct { octet_string *transaction_id; - u8 group_id; - u8 abort_on_error; + u8 *group_id; + u8 *abort_on_error; sml_message_body *message_body; - u16 crc; + u16 *crc; /* end of message */ } sml_message; diff --git a/sml/include/sml/sml_number.h b/sml/include/sml/sml_number.h index b7675a4..41b95db 100644 --- a/sml/include/sml/sml_number.h +++ b/sml/include/sml/sml_number.h @@ -34,7 +34,7 @@ void *sml_number_init(u64 number, unsigned char type, int size); // SML_TYPE_NUMBER_32, SML_TYPE_NUMBER_64) void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size); -void sml_number_write(unsigned char type, int size, u64 value, sml_buffer *buf); +//void sml_number_write(unsigned char type, int size, u64 value, sml_buffer *buf); void sml_number_write_new(void *np, unsigned char type, int size, sml_buffer *buf); #define sml_u8_init(n) (u8 *) sml_number_init(n, SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8) diff --git a/sml/include/sml/sml_open_request.h b/sml/include/sml/sml_open_request.h index 8d4ef40..d7f9da3 100644 --- a/sml/include/sml/sml_open_request.h +++ b/sml/include/sml/sml_open_request.h @@ -35,7 +35,7 @@ typedef struct { octet_string *server_id; // optional octet_string *username; // optional octet_string *password; // optional - u8 sml_version; // optional + u8 *sml_version; // optional } sml_open_request; //sml_open_request *sml_open_request_init(); diff --git a/sml/include/sml/sml_open_response.h b/sml/include/sml/sml_open_response.h index 0a33af9..f34b1e8 100644 --- a/sml/include/sml/sml_open_response.h +++ b/sml/include/sml/sml_open_response.h @@ -35,7 +35,7 @@ typedef struct { octet_string *req_file_id; octet_string *server_id; sml_time *ref_time; // optional - u8 sml_version; // optional + u8 *sml_version; // optional } sml_open_response; sml_open_response *sml_open_response_parse(sml_buffer *buf); diff --git a/sml/include/sml/sml_status.h b/sml/include/sml/sml_status.h index 90e8b61..ed5160e 100644 --- a/sml/include/sml/sml_status.h +++ b/sml/include/sml/sml_status.h @@ -27,10 +27,10 @@ extern "C" { typedef union { - u8 status8; - u16 status16; - u32 status32; - u64 status64; + u8 *status8; + u16 *status16; + u32 *status32; + u64 *status64; } sml_status; sml_status *sml_status_parse(sml_buffer *buf); diff --git a/sml/include/sml/sml_time.h b/sml/include/sml/sml_time.h index c1c4afb..3b01a23 100644 --- a/sml/include/sml/sml_time.h +++ b/sml/include/sml/sml_time.h @@ -28,8 +28,8 @@ extern "C" { typedef struct { - u8 tag; - u32 data; + u8 *tag; + u32 *data; } sml_time; // Parses a time, updates the buffer accordingly, memory must be free'd elsewhere. diff --git a/sml/include/sml/sml_tree.h b/sml/include/sml/sml_tree.h index 79b23f2..217d987 100644 --- a/sml/include/sml/sml_tree.h +++ b/sml/include/sml/sml_tree.h @@ -37,7 +37,7 @@ extern "C" { // TODO typedef struct { - u8 tag; + u8 *tag; union { sml_value *value; // sml_period_entry diff --git a/sml/include/sml/sml_value.h b/sml/include/sml/sml_value.h index 407ecba..6916559 100644 --- a/sml/include/sml/sml_value.h +++ b/sml/include/sml/sml_value.h @@ -34,14 +34,14 @@ typedef struct { union { sml_boolean boolean; octet_string *bytes; // can has zero length - i8 int8; - i16 int16; - i32 int32; - i64 int64; - u8 uint8; - u16 uint16; - u32 uint32; - u64 uint64; + i8 *int8; + i16 *int16; + i32 *int32; + i64 *int64; + u8 *uint8; + u16 *uint16; + u32 *uint32; + u64 *uint64; } data; } sml_value; diff --git a/sml/src/sml_get_profile_pack_request.c b/sml/src/sml_get_profile_pack_request.c index 04a8684..2d1a3f4 100644 --- a/sml/src/sml_get_profile_pack_request.c +++ b/sml/src/sml_get_profile_pack_request.c @@ -33,41 +33,19 @@ sml_get_profile_pack_request *sml_get_profile_pack_request_init(){ } void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_buffer *buf) { - sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); - - // server_id - if (msg->server_id != NULL) { - sml_octet_string_write(msg->server_id,buf); - } else sml_buf_optional_write(buf); - - // username - if (msg->username != NULL) { - sml_octet_string_write(msg->username,buf); - } else sml_buf_optional_write(buf); - - // password - if (msg->password != NULL) { - sml_octet_string_write(msg->password,buf); - } else sml_buf_optional_write(buf); - - // with_rawdata - if (msg->with_rawdata != NULL) { - printf("TODO: %s - comparision is not valid", __FUNCTION__); - sml_boolean_write(msg->with_rawdata,buf); - } else sml_buf_optional_write(buf); // with_rawdata - - // begin_time - if (msg->begin_time != NULL){ - sml_time_write(msg->begin_time, buf); - } else sml_buf_optional_write(buf); // begin_time - sml_buf_optional_write(buf); // end_time - - // parameter_tree_path is not optional - sml_tree_path_write(msg->parameter_tree_path, buf); - - sml_buf_optional_write(buf); // object_list + + sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9); + sml_octet_string_write(msg->server_id, buf); + sml_octet_string_write(msg->username, buf); + sml_octet_string_write(msg->password, buf); + sml_boolean_write(msg->with_rawdata, buf); + sml_time_write(msg->begin_time, buf); + sml_time_write(msg->end_time, buf); + sml_tree_path_write(msg->parameter_tree_path, buf); + + printf("TODO: %s - some struct members aren't written", __FUNCTION__); + sml_buf_optional_write(buf); // object_list sml_buf_optional_write(buf); // das_details - printf("request_write"); } diff --git a/sml/src/sml_message.c b/sml/src/sml_message.c index a0f39aa..4119ef6 100644 --- a/sml/src/sml_message.c +++ b/sml/src/sml_message.c @@ -96,13 +96,12 @@ void sml_message_write(sml_message *msg, sml_buffer *buf) { int msg_start = buf->cursor; sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 6); sml_octet_string_write(msg->transaction_id, buf); - sml_number_write(SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, (u64) msg->group_id, buf); - sml_number_write(SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, (u64) msg->abort_on_error, buf); + sml_u8_write(msg->group_id, buf); + sml_u8_write(msg->abort_on_error, buf); sml_message_body_write(msg->message_body, buf); - msg->crc = sml_crc16_calculate(&(buf->buffer[msg_start]), buf->cursor - msg_start); - - sml_number_write(SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16, (u64) msg->crc, buf); + msg->crc = sml_u16_init(sml_crc16_calculate(&(buf->buffer[msg_start]), buf->cursor - msg_start)); + sml_u16_write(msg->crc, buf); // end of message buf->buffer[buf->cursor] = 0x0; @@ -128,7 +127,7 @@ sml_message_body *sml_message_body_parse(sml_buffer *buf) { msg_body->tag = sml_u16_parse(buf); if (sml_buf_has_errors(buf)) goto error; - switch (msg_body->tag) { + switch (*(msg_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: msg_body->data = sml_open_request_parse(buf); break; @@ -151,7 +150,7 @@ sml_message_body *sml_message_body_parse(sml_buffer *buf) { msg_body->data = sml_attention_response_parse(buf); break; default: - printf("error: message type %04X not yet implemented\n", msg_body->tag); + printf("error: message type %04X not yet implemented\n", *(msg_body->tag)); break; } @@ -165,16 +164,16 @@ error: sml_message_body *sml_message_body_init(u16 tag, void *data) { sml_message_body *message_body = (sml_message_body *) malloc(sizeof(sml_message_body)); memset(message_body, 0, sizeof(sml_message_body)); - message_body->tag = tag; + message_body->tag = sml_u16_init(tag); message_body->data = data; return message_body; } void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); - sml_number_write(SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_16, (u64) message_body->tag, buf); + sml_u16_write(message_body->tag, buf); - switch (message_body->tag) { + switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_write((sml_open_request *) message_body->data, buf); break; @@ -194,14 +193,14 @@ void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) { sml_get_profile_pack_request_write((sml_get_profile_pack_request *)message_body->data, buf); break; default: - printf("error: message type %04X not yet implemented\n", message_body->tag); + printf("error: message type %04X not yet implemented\n", *(message_body->tag)); break; } } void sml_message_body_free(sml_message_body *message_body) { if (message_body) { - switch (message_body->tag) { + switch (*(message_body->tag)) { case SML_MESSAGE_OPEN_REQUEST: sml_open_request_free((sml_open_request *) message_body->data); break; @@ -224,7 +223,7 @@ void sml_message_body_free(sml_message_body *message_body) { sml_get_list_response_free((sml_get_list_response *) message_body->data); break; default: - printf("NYI: %s for message type %04X\n", __FUNCTION__, message_body->tag); + printf("NYI: %s for message type %04X\n", __FUNCTION__, *(message_body->tag)); break; } diff --git a/sml/src/sml_number.c b/sml/src/sml_number.c index 14de116..659a40f 100644 --- a/sml/src/sml_number.c +++ b/sml/src/sml_number.c @@ -78,6 +78,7 @@ void *sml_number_parse(sml_buffer *buf, unsigned char type, int max_size) { return np; } +/* void sml_number_write(unsigned char type, int size, u64 value, sml_buffer *buf) { sml_buf_set_type_and_length(buf, type, size); int i; @@ -90,6 +91,7 @@ void sml_number_write(unsigned char type, int size, u64 value, sml_buffer *buf) } buf->cursor += size; } +*/ void sml_number_write_new(void *np, unsigned char type, int size, sml_buffer *buf) { if (np == 0) { diff --git a/sml/src/sml_time.c b/sml/src/sml_time.c index 4b40afb..acf1fdb 100644 --- a/sml/src/sml_time.c +++ b/sml/src/sml_time.c @@ -48,9 +48,13 @@ error: return 0; } -void sml_time_write(sml_time *time, sml_buffer *buf){ - printf("NYI: %s (writing optional flag instead)\n", __FUNCTION__); - sml_buf_optional_write(buf); +void sml_time_write(sml_time *time, sml_buffer *buf) { + if (time == 0) { + sml_buf_optional_write(buf); + return; + } + printf("NYI: %s (writing optional flag instead)\n", __FUNCTION__); + sml_buf_optional_write(buf); } void sml_time_free(sml_time *time) { diff --git a/sml/src/sml_tree.c b/sml/src/sml_tree.c index fd24761..ae4a1af 100644 --- a/sml/src/sml_tree.c +++ b/sml/src/sml_tree.c @@ -77,9 +77,9 @@ sml_proc_par_value *sml_proc_par_value_init(u8 tag, void *data) { sml_proc_par_value *value = (sml_proc_par_value *) malloc(sizeof(sml_proc_par_value)); memset(value, 0, sizeof(sml_proc_par_value)); - value->tag = tag; + value->tag = sml_u8_init(tag); - switch (tag) { + switch (*(value->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: value->data.value = (sml_value*)data; break; @@ -104,9 +104,9 @@ sml_proc_par_value *sml_proc_par_value_init(u8 tag, void *data) { void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf) { sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2); - sml_number_write(SML_TYPE_UNSIGNED, SML_TYPE_NUMBER_8, (u64) value->tag, buf); + sml_u8_write(value->tag, buf); - switch (value->tag) { + switch (*(value->tag)) { case SML_PROC_PAR_VALUE_TAG_VALUE: sml_value_write(value->data.value, buf); break;