code cleanup (indents, empty lines, CPP defines, etc)

This commit is contained in:
Steffen Vogel 2011-10-01 22:55:34 +02:00
parent 445b3d2da0
commit 26f740f0a0
66 changed files with 499 additions and 484 deletions

View file

@ -62,7 +62,6 @@ int serial_port_open(const char* device) {
}
void transport_receiver(unsigned char *buffer, size_t buffer_len) {
// the buffer contains the whole message, with transport escape sequences.
// these escape sequences are stripped here.
sml_file *file = sml_file_parse(buffer + 8, buffer_len - 16);
@ -91,3 +90,4 @@ int main(int argc, char **argv) {
return 0;
}

View file

@ -17,14 +17,13 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_ATTENTION_RESPONSE_H
#define _SML_ATTENTION_RESPONSE_H
#ifndef _SML_ATTENTION_RESPONSE_H_
#define _SML_ATTENTION_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
#include "sml_tree.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -47,4 +46,5 @@ void sml_attention_response_free(sml_attention_response *msg);
#endif
#endif
#endif /* _SML_ATTENTION_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_BOOLEAN_H
#define _SML_BOOLEAN_H
#ifndef _SML_BOOLEAN_H_
#define _SML_BOOLEAN_H_
#define SML_BOOLEAN_TRUE 0xFF
#define SML_BOOLEAN_FALSE 0x00
@ -40,4 +40,5 @@ void sml_boolean_free(sml_boolean *b);
#endif
#endif
#endif /* _SML_BOOLEAN_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_CLOSE_REQUEST_H
#define _SML_CLOSE_REQUEST_H
#ifndef _SML_CLOSE_REQUEST_H_
#define _SML_CLOSE_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -27,7 +27,7 @@ extern "C" {
#endif
typedef struct {
sml_signature *global_signature; // optional
sml_signature *global_signature; // optional
} sml_close_request;
sml_close_request *sml_close_request_init();
@ -40,4 +40,5 @@ void sml_close_request_free(sml_close_request *msg);
#endif
#endif
#endif /* _SML_CLOSE_REQUEST_H_ */

View file

@ -17,8 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_CLOSE_RESPONSE_H
#define _SML_CLOSE_RESPONSE_H
#ifndef _SML_CLOSE_RESPONSE_H_
#define _SML_CLOSE_RESPONSE_H_
#include "sml_close_request.h"
@ -38,5 +38,5 @@ void sml_close_response_free(sml_close_response *msg);
#endif
#endif
#endif /* _SML_CLOSE_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef SML_CRC16_H_
#define SML_CRC16_H_
#ifndef _SML_CRC16_H_
#define _SML_CRC16_H_
#include "sml_shared.h"
@ -25,7 +25,6 @@
extern "C" {
#endif
// CRC16 FSC implementation based on DIN 62056-46
u16 sml_crc16_calculate(unsigned char *cp, int len) ;
@ -34,7 +33,5 @@ u16 sml_crc16_calculate(unsigned char *cp, int len) ;
#endif
#endif /* SML_CRC16_H_ */
#endif /* _SML_CRC16_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_H
#define _SML_H
#ifndef _SML_FILE_H_
#define _SML_FILE_H_
#include "sml_message.h"
#include "sml_shared.h"
@ -47,4 +47,5 @@ void sml_file_print(sml_file *file);
#endif
#endif
#endif /* _SML_FILE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_LIST_REQUEST_H
#define _SML_GET_LIST_REQUEST_H
#ifndef _SML_GET_LIST_REQUEST_H_
#define _SML_GET_LIST_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,7 +28,6 @@
extern "C" {
#endif
typedef struct {
octet_string *client_id;
octet_string *server_id; // optional
@ -47,4 +46,5 @@ void sml_get_list_request_free(sml_get_list_request *msg);
#endif
#endif
#endif /* _SML_GET_LIST_REQUEST_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_LIST_RESPONSE_H
#define _SML_GET_LIST_RESPONSE_H
#ifndef _SML_GET_LIST_RESPONSE_H_
#define _SML_GET_LIST_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,7 +28,6 @@
extern "C" {
#endif
typedef struct {
octet_string *client_id; // optional
octet_string *server_id;
@ -49,4 +48,5 @@ void sml_get_list_response_free(sml_get_list_response *msg);
#endif
#endif
#endif /* _SML_GET_LIST_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROC_PARAMETER_REQUEST_H
#define _SML_GET_PROC_PARAMETER_REQUEST_H
#ifndef _SML_GET_PROC_PARAMETER_REQUEST_H_
#define _SML_GET_PROC_PARAMETER_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -27,7 +27,6 @@
extern "C" {
#endif
typedef struct {
octet_string *server_id; // optional
octet_string *username; // optional
@ -46,4 +45,5 @@ void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg);
#endif
#endif
#endif /* _SML_GET_PROC_PARAMETER_REQUEST_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROC_PARAMETER_RESPONSE_H
#define _SML_GET_PROC_PARAMETER_RESPONSE_H
#ifndef _SML_GET_PROC_PARAMETER_RESPONSE_H_
#define _SML_GET_PROC_PARAMETER_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -42,4 +42,6 @@ void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg);
}
#endif
#endif
#endif /* _SML_GET_PROC_PARAMETER_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROFILE_LIST_REQUEST_H
#define _SML_GET_PROFILE_LIST_REQUEST_H
#ifndef _SML_GET_PROFILE_LIST_REQUEST_H_
#define _SML_GET_PROFILE_LIST_REQUEST_H_
#include "sml_get_profile_pack_request.h"
@ -37,5 +37,6 @@ typedef sml_get_profile_pack_request sml_get_profile_list_request;
}
#endif
#endif
#endif /* _SML_GET_PROFILE_LIST_REQUEST_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROFILE_LIST_RESPONSE_H
#define _SML_GET_PROFILE_LIST_RESPONSE_H
#ifndef _SML_GET_PROFILE_LIST_RESPONSE_H_
#define _SML_GET_PROFILE_LIST_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -50,4 +50,6 @@ void sml_get_profile_list_response_free(sml_get_profile_list_response *msg);
}
#endif
#endif
#endif /* _SML_GET_PROFILE_LIST_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROFILE_PACK_REQUEST_H
#define _SML_GET_PROFILE_PACK_REQUEST_H
#ifndef _SML_GET_PROFILE_PACK_REQUEST_H_
#define _SML_GET_PROFILE_PACK_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -64,4 +64,5 @@ void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg);
#endif
#endif
#endif /* _SML_GET_PROFILE_PACK_REQUEST_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_GET_PROFILE_PACK_RESPONSE_H
#define _SML_GET_PROFILE_PACK_RESPONSE_H
#ifndef _SML_GET_PROFILE_PACK_RESPONSE_H_
#define _SML_GET_PROFILE_PACK_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -84,4 +84,5 @@ void sml_value_entry_free(sml_value_entry *entry);
#endif
#endif
#endif /* _SML_GET_PROFILE_PACK_RESPONSE_H_ */

View file

@ -17,9 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_LIST_H
#define _SML_LIST_H
#ifndef _SML_LIST_H_
#define _SML_LIST_H_
#include "sml_time.h"
#include "sml_octet_string.h"
@ -34,7 +33,6 @@ extern "C" {
typedef struct {
void **elems;
int elems_len;
void (*elem_free) (void *elem);
} sml_sequence;
@ -68,4 +66,5 @@ void sml_list_free(sml_list *list);
#endif
#endif
#endif /* _SML_LIST_H_ */

View file

@ -17,8 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_MESSAGE_H
#define _SML_MESSAGE_H
#ifndef _SML_MESSAGE_H_
#define _SML_MESSAGE_H_
#include <stdlib.h>
#include "sml_octet_string.h"
@ -41,10 +41,10 @@
#include "sml_get_list_response.h"
#include "sml_attention_response.h"
#define SML_MESSAGE_OPEN_REQUEST 0x00000100
#define SML_MESSAGE_OPEN_RESPONSE 0x00000101
#define SML_MESSAGE_CLOSE_REQUEST 0x00000200
#define SML_MESSAGE_CLOSE_RESPONSE 0x00000201
#define SML_MESSAGE_OPEN_REQUEST 0x00000100
#define SML_MESSAGE_OPEN_RESPONSE 0x00000101
#define SML_MESSAGE_CLOSE_REQUEST 0x00000200
#define SML_MESSAGE_CLOSE_RESPONSE 0x00000201
#define SML_MESSAGE_GET_PROFILE_PACK_REQUEST 0x00000300
#define SML_MESSAGE_GET_PROFILE_PACK_RESPONSE 0x00000301
#define SML_MESSAGE_GET_PROFILE_LIST_REQUEST 0x00000400
@ -53,15 +53,14 @@
#define SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE 0x00000501
#define SML_MESSAGE_SET_PROC_PARAMETER_REQUEST 0x00000600
#define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601 // This doesn't exist in the spec
#define SML_MESSAGE_GET_LIST_REQUEST 0x00000700
#define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701
#define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01
#define SML_MESSAGE_GET_LIST_REQUEST 0x00000700
#define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701
#define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
u16 *tag;
void *data;
@ -93,4 +92,5 @@ void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf);
#endif
#endif
#endif /* _SML_MESSAGE_H_ */

View file

@ -17,8 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_NUMBER_H
#define _SML_NUMBER_H
#ifndef _SML_NUMBER_H_
#define _SML_NUMBER_H_
#include "sml_shared.h"
@ -26,7 +26,6 @@
extern "C" {
#endif
void *sml_number_init(u64 number, unsigned char type, int size);
// Parses a number. Identified by type (SML_TYPE_INTEGER or SML_TYPE_UNSIGNED)
@ -76,4 +75,5 @@ typedef u8 sml_unit;
#endif
#endif
#endif /* _SML_NUMBER_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_OCTET_STRING_H
#define _SML_OCTET_STRING_H
#ifndef _SML_OCTET_STRING_H_
#define _SML_OCTET_STRING_H_
#include <string.h>
#include "sml_shared.h"
@ -26,7 +26,6 @@
extern "C" {
#endif
typedef struct {
unsigned char *str;
int len;
@ -53,5 +52,5 @@ typedef octet_string sml_signature;
#endif
#endif
#endif /* _SML_OCTET_STRING_H_ */

View file

@ -16,18 +16,16 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_OPEN_REQUEST_H
#define _SML_OPEN_REQUEST_H
#ifndef _SML_OPEN_REQUEST_H_
#define _SML_OPEN_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
octet_string *codepage; // optional
octet_string *client_id;
@ -48,4 +46,5 @@ void sml_open_request_free(sml_open_request *msg);
#endif
#endif
#endif /* _SML_OPEN_REQUEST_H_ */

View file

@ -17,8 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_OPEN_RESPONSE_H
#define _SML_OPEN_RESPONSE_H
#ifndef _SML_OPEN_RESPONSE_H_
#define _SML_OPEN_RESPONSE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,7 +28,6 @@
extern "C" {
#endif
typedef struct {
octet_string *codepage; // optional
octet_string *client_id; // optional
@ -48,4 +47,5 @@ void sml_open_response_free(sml_open_response *msg);
#endif
#endif
#endif /* _SML_OPEN_RESPONSE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_SET_PROC_PARAMETER_REQUEST_H
#define _SML_SET_PROC_PARAMETER_REQUEST_H
#ifndef _SML_SET_PROC_PARAMETER_REQUEST_H_
#define _SML_SET_PROC_PARAMETER_REQUEST_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,11 +28,11 @@ extern "C" {
#endif
typedef struct {
octet_string *server_id; // optional
octet_string *username; // optional
octet_string *password; // optional
sml_tree_path *parameter_tree_path;
sml_tree *parameter_tree;
octet_string *server_id; // optional
octet_string *username; // optional
octet_string *password; // optional
sml_tree_path *parameter_tree_path;
sml_tree *parameter_tree;
} sml_set_proc_parameter_request;
sml_set_proc_parameter_request *sml_set_proc_parameter_request_init();
@ -45,4 +45,5 @@ void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg);
#endif
#endif
#endif /* _SML_SET_PROC_PARAMETER_REQUEST_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_SHARED_H
#define _SML_SHARED_H
#ifndef _SML_SHARED_H_
#define _SML_SHARED_H_
#include <stdlib.h>
#include <stdint.h>
@ -56,7 +56,6 @@ typedef int64_t i64;
#define SML_TYPE_NUMBER_32 sizeof(u32)
#define SML_TYPE_NUMBER_64 sizeof(u64)
// This sml_buffer is used in two different use-cases.
//
// Parsing: the raw data is in the buffer field,
@ -114,4 +113,6 @@ void hexdump(unsigned char *buffer, size_t buffer_len);
}
#endif
#endif
#endif /* _SML_SHARED_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_STATUS_H
#define _SML_STATUS_H
#ifndef _SML_STATUS_H_
#define _SML_STATUS_H_
#include "sml_number.h"
#include "sml_shared.h"
@ -26,7 +26,6 @@
extern "C" {
#endif
typedef struct {
u8 type;
union {
@ -46,5 +45,6 @@ void sml_status_free(sml_status *status);
}
#endif
#endif
#endif /* _SML_STATUS_H_ */

View file

@ -17,8 +17,8 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_TIME_H
#define _SML_TIME_H
#ifndef _SML_TIME_H_
#define _SML_TIME_H_
#include "sml_shared.h"
#include "sml_number.h"
@ -47,4 +47,6 @@ void sml_time_free(sml_time *time);
}
#endif
#endif
#endif /* _SML_TIME_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_TRANSPORT_H
#define _SML_TRANSPORT_H
#ifndef _SML_TRANSPORT_H_
#define _SML_TRANSPORT_H_
#include <stdlib.h>
#include <sml/sml_file.h>
@ -48,5 +48,6 @@ int sml_transport_write(int fd, sml_file *file);
}
#endif
#endif
#endif /* _SML_TRANSPORT_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_TREE_H
#define _SML_TREE_H
#ifndef _SML_TREE_H_
#define _SML_TREE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,11 +28,10 @@
extern "C" {
#endif
#define SML_PROC_PAR_VALUE_TAG_VALUE 0x01
#define SML_PROC_PAR_VALUE_TAG_VALUE 0x01
#define SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY 0x02
#define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 0x03
#define SML_PROC_PAR_VALUE_TAG_TIME 0x04
#define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 0x03
#define SML_PROC_PAR_VALUE_TAG_TIME 0x04
// what a messy tupel ...
typedef struct {
@ -78,13 +77,13 @@ typedef struct {
} sml_period_entry;
typedef struct {
u8 *tag;
union {
sml_value *value;
u8 *tag;
union {
sml_value *value;
sml_period_entry *period_entry;
sml_tupel_entry *tupel_entry;
sml_time *time;
} data;
sml_time *time;
} data;
} sml_proc_par_value;
typedef struct s_tree{
@ -100,33 +99,33 @@ typedef struct {
octet_string **path_entries;
} sml_tree_path;
// SML_TREE
// sml_tree;
sml_tree *sml_tree_init();
sml_tree *sml_tree_parse(sml_buffer *buf);
void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree);
void sml_tree_write(sml_tree *tree, sml_buffer *buf);
void sml_tree_free(sml_tree *tree);
// SML_TREE_PATH
// sml_tree_path;
sml_tree_path *sml_tree_path_init();
sml_tree_path *sml_tree_path_parse(sml_buffer *buf);
void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry);
void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf);
void sml_tree_path_free(sml_tree_path *tree_path);
// SML_PROC_PAR_VALUE
// sml_proc_par_value;
sml_proc_par_value *sml_proc_par_value_init();
sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf);
void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf);
void sml_proc_par_value_free(sml_proc_par_value *value);
// SML_TUPEL_ENTRY
// sml_tupel_entry;
sml_tupel_entry *sml_tupel_entry_init();
sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf);
void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf);
void sml_tupel_entry_free(sml_tupel_entry *tupel);
// SML_PERIOD_ENTRY
// sml_period_entry;
sml_period_entry *sml_period_entry_init();
sml_period_entry *sml_period_entry_parse(sml_buffer *buf);
void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf);
@ -136,4 +135,6 @@ void sml_period_entry_free(sml_period_entry *period);
}
#endif
#endif
#endif /* _SML_TREE_H_ */

View file

@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SML_VALUE_H
#define _SML_VALUE_H
#ifndef _SML_VALUE_H_
#define _SML_VALUE_H_
#include "sml_shared.h"
#include "sml_octet_string.h"
@ -28,21 +28,20 @@
extern "C" {
#endif
typedef struct {
u8 type;
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;
} data;
u8 type;
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;
} data;
} sml_value;
sml_value *sml_value_init();
@ -50,16 +49,13 @@ sml_value *sml_value_parse(sml_buffer *buf);
void sml_value_write(sml_value *value, sml_buffer *buf);
void sml_value_free(sml_value *value);
/**
* Cast arbitrary sized sml_value to double
*
* @param value the sml_value which should be casted
* @return double value representation of sml_value, 0 if an error occured
*/
// Cast arbitrary sized sml_value to double
double sml_value_to_double(sml_value *value);
#ifdef __cplusplus
}
#endif
#endif
#endif /* _SML_VALUE_H_ */

View file

@ -23,6 +23,7 @@
sml_attention_response *sml_attention_response_init() {
sml_attention_response *msg = (sml_attention_response *) malloc(sizeof(sml_attention_response));
memset(msg, 0, sizeof(sml_attention_response));
return msg;
}
@ -69,10 +70,12 @@ void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf)
void sml_attention_response_free(sml_attention_response *msg){
if (msg) {
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->attention_number);
sml_octet_string_free(msg->attention_message);
sml_tree_free(msg->attention_details);
free(msg);
}
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->attention_number);
sml_octet_string_free(msg->attention_message);
sml_tree_free(msg->attention_details);
free(msg);
}
}

View file

@ -23,6 +23,7 @@
sml_boolean *sml_boolean_init(u8 b) {
sml_boolean *boolean = malloc(sizeof(u8));
*boolean = b;
return boolean;
}
@ -31,13 +32,12 @@ sml_boolean *sml_boolean_parse(sml_buffer *buf) {
return 0;
}
int l;
if (sml_buf_get_next_type(buf) != SML_TYPE_BOOLEAN) {
buf->error = 1;
return 0;
}
l = sml_buf_get_next_length(buf);
int l = sml_buf_get_next_length(buf);
if (l != 1) {
buf->error = 1;
return 0;
@ -51,7 +51,6 @@ sml_boolean *sml_boolean_parse(sml_buffer *buf) {
sml_buf_update_bytes_read(buf, 1);
return sml_boolean_init(SML_BOOLEAN_FALSE);
}
}
void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf) {
@ -60,14 +59,14 @@ void sml_boolean_write(sml_boolean *boolean, sml_buffer *buf) {
return;
}
sml_buf_set_type_and_length(buf, SML_TYPE_BOOLEAN, 1);
if (*boolean == SML_BOOLEAN_FALSE) {
buf->buffer[buf->cursor] = SML_BOOLEAN_FALSE;
}
else {
buf->buffer[buf->cursor] = SML_BOOLEAN_TRUE;
}
buf->cursor++;
sml_buf_set_type_and_length(buf, SML_TYPE_BOOLEAN, 1);
if (*boolean == SML_BOOLEAN_FALSE) {
buf->buffer[buf->cursor] = SML_BOOLEAN_FALSE;
}
else {
buf->buffer[buf->cursor] = SML_BOOLEAN_TRUE;
}
buf->cursor++;
}
void sml_boolean_free(sml_boolean *b) {
@ -76,5 +75,3 @@ void sml_boolean_free(sml_boolean *b) {
}
}

View file

@ -18,19 +18,19 @@
#include <sml/sml_close_request.h>
#include <stdio.h>
sml_close_request *sml_close_request_init() {
sml_close_request *close_request = (sml_close_request *) malloc(sizeof(sml_close_request));
memset(close_request, 0, sizeof(sml_close_request));
return close_request;
sml_close_request *close_request = (sml_close_request *) malloc(sizeof(sml_close_request));
memset(close_request, 0, sizeof(sml_close_request));
return close_request;
}
sml_close_request * sml_close_request_parse(sml_buffer *buf) {
sml_close_request *msg = sml_close_request_init();
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
goto error;
}
@ -40,10 +40,10 @@ sml_close_request * sml_close_request_parse(sml_buffer *buf) {
goto error;
}
msg->global_signature = sml_octet_string_parse(buf);
msg->global_signature = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
return msg;
return msg;
error:
sml_close_request_free(msg);
@ -62,4 +62,3 @@ void sml_close_request_free(sml_close_request *msg) {
}
}

View file

@ -23,6 +23,7 @@
sml_close_response *sml_close_response_init() {
sml_close_response *msg = (sml_close_response *) malloc(sizeof(sml_close_response));
memset(msg, 0, sizeof(sml_close_response));
return msg;
}
@ -50,13 +51,15 @@ error:
}
void sml_close_response_write(sml_close_response *msg, sml_buffer *buf) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1);
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 1);
sml_octet_string_write(msg->global_signature,buf);
}
void sml_close_response_free(sml_close_response *msg) {
if (msg) {
sml_octet_string_free(msg->global_signature);
free(msg);
}
}

View file

@ -45,13 +45,15 @@ static u16 fcstab [256] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x65
};
u16 sml_crc16_calculate(unsigned char *cp, int len) {
u16 fcs = PPPINITFCS16;
u16 fcs = PPPINITFCS16;
while (len--) {
fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
}
fcs ^= 0xffff;
fcs = ((fcs & 0xff) << 8) | ((fcs & 0xff00) >> 8);
fcs ^= 0xffff;
fcs = ((fcs & 0xff) << 8) | ((fcs & 0xff00) >> 8);
return fcs;
}

View file

@ -22,7 +22,6 @@
#include <sml/sml_message.h>
#include <sml/sml_number.h>
#include <sml/sml_time.h>
#include <stdio.h>
#include <string.h>
@ -30,91 +29,88 @@
#define SML_FILE_BUFFER_LENGTH 512
sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) {
sml_file *file = (sml_file*) malloc(sizeof(sml_file));
memset(file, 0, sizeof(sml_file));
sml_file *file = (sml_file*) malloc(sizeof(sml_file));
memset(file, 0, sizeof(sml_file));
sml_buffer *buf = sml_buffer_init(buffer_len);
memcpy(buf->buffer, buffer, buffer_len);
file->buf = buf;
sml_buffer *buf = sml_buffer_init(buffer_len);
memcpy(buf->buffer, buffer, buffer_len);
file->buf = buf;
sml_message *msg;
sml_message *msg;
// parsing all messages
for (; buf->cursor < buf->buffer_len;) {
// parsing all messages
for (; buf->cursor < buf->buffer_len;) {
if(sml_buf_get_current_byte(buf) == SML_MESSAGE_END) {
// reading trailing zeroed bytes
sml_buf_update_bytes_read(buf, 1);
continue;
}
if(sml_buf_get_current_byte(buf) == SML_MESSAGE_END) {
// reading trailing zeroed bytes
sml_buf_update_bytes_read(buf, 1);
continue;
}
msg = sml_message_parse(buf);
msg = sml_message_parse(buf);
if (sml_buf_has_errors(buf)) {
printf("warning: could not read the whole file\n");
break;
}
if (sml_buf_has_errors(buf)) {
printf("warning: could not read the whole file\n");
break;
}
sml_file_add_message(file, msg);
sml_file_add_message(file, msg);
}
}
return file;
return file;
}
sml_file *sml_file_init() {
sml_file *file = (sml_file*) malloc(sizeof(sml_file));
memset(file, 0, sizeof(sml_file));
sml_file *file = (sml_file*) malloc(sizeof(sml_file));
memset(file, 0, sizeof(sml_file));
sml_buffer *buf = sml_buffer_init(SML_FILE_BUFFER_LENGTH);
file->buf = buf;
return file;
sml_buffer *buf = sml_buffer_init(SML_FILE_BUFFER_LENGTH);
file->buf = buf;
return file;
}
void sml_file_add_message(sml_file *file, sml_message *message) {
file->messages_len++;
file->messages = (sml_message **) realloc(file->messages, sizeof(sml_message *) * file->messages_len);
file->messages[file->messages_len - 1] = message;
file->messages_len++;
file->messages = (sml_message **) realloc(file->messages, sizeof(sml_message *) * file->messages_len);
file->messages[file->messages_len - 1] = message;
}
void sml_file_write(sml_file *file) {
int i;
if (file->messages && file->messages_len > 0) {
for (i = 0; i < file->messages_len; i++) {
sml_message_write(file->messages[i], file->buf);
}
}
int i;
if (file->messages && file->messages_len > 0) {
for (i = 0; i < file->messages_len; i++) {
sml_message_write(file->messages[i], file->buf);
}
}
}
void sml_file_free(sml_file *file) {
if (file) {
if (file) {
if (file->messages) {
int i;
for (i = 0; i < file->messages_len; i++) {
sml_message_free(file->messages[i]);
}
free(file->messages);
}
if (file->messages) {
int i;
for (i = 0; i < file->messages_len; i++) {
sml_message_free(file->messages[i]);
}
free(file->messages);
}
if (file->buf) {
sml_buffer_free(file->buf);
}
if (file->buf) {
sml_buffer_free(file->buf);
}
free(file);
}
free(file);
}
}
void sml_file_print(sml_file *file) {
int i;
printf("SML file (%d SML messages, %d bytes)\n", file->messages_len, file->buf->cursor);
for (i = 0; i < file->messages_len; i++) {
printf("SML message %4.X\n", *(file->messages[i]->message_body->tag));
}
int i;
printf("SML file (%d SML messages, %d bytes)\n", file->messages_len, file->buf->cursor);
for (i = 0; i < file->messages_len; i++) {
printf("SML message %4.X\n", *(file->messages[i]->message_body->tag));
}
}

View file

@ -20,7 +20,7 @@
#include <sml/sml_get_list_request.h>
#include <stdio.h>
sml_get_list_request* sml_get_list_request_init(){
sml_get_list_request* sml_get_list_request_init() {
sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request));
memset(msg, 0, sizeof(sml_get_list_request));
@ -28,9 +28,9 @@ sml_get_list_request* sml_get_list_request_init(){
}
void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_octet_string_write(msg->client_id, buf);
sml_octet_string_write(msg->client_id, buf);
sml_octet_string_write(msg->server_id, buf);
sml_octet_string_write(msg->username, buf);
sml_octet_string_write(msg->password, buf);
@ -39,7 +39,6 @@ void sml_get_list_request_write(sml_get_list_request *msg, sml_buffer *buf) {
sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) {
sml_get_list_request *msg = (sml_get_list_request *) malloc(sizeof(sml_get_list_request));
memset(msg, 0, sizeof(sml_get_list_request));
@ -73,17 +72,17 @@ sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) {
error:
sml_get_list_request_free(msg);
return 0;
}
void sml_get_list_request_free(sml_get_list_request *msg) {
if (msg) {
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->list_name);
sml_octet_string_free(msg->username);
sml_octet_string_free(msg->password);
free(msg);
}
if (msg) {
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->list_name);
sml_octet_string_free(msg->username);
sml_octet_string_free(msg->password);
free(msg);
}
}

View file

@ -19,10 +19,10 @@
#include <sml/sml_get_list_response.h>
sml_get_list_response *sml_get_list_response_init() {
sml_get_list_response *msg = (sml_get_list_response *) malloc(sizeof(sml_get_list_response));
memset(msg, 0, sizeof(sml_get_list_response));
return msg;
}
@ -65,7 +65,6 @@ sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf) {
error:
sml_get_list_response_free(msg);
return 0;
}
void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf) {
@ -81,14 +80,16 @@ void sml_get_list_response_write(sml_get_list_response *msg, sml_buffer *buf) {
}
void sml_get_list_response_free(sml_get_list_response *msg) {
if (msg) {
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->list_name);
sml_time_free(msg->act_sensor_time);
sml_list_free(msg->val_list);
sml_octet_string_free(msg->list_signature);
sml_time_free(msg->act_gateway_time);
free(msg);
}
if (msg) {
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->list_name);
sml_time_free(msg->act_sensor_time);
sml_list_free(msg->val_list);
sml_octet_string_free(msg->list_signature);
sml_time_free(msg->act_gateway_time);
free(msg);
}
}

View file

@ -17,15 +17,15 @@
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#include <sml/sml_get_proc_parameter_request.h>
#include <sml/sml_tree.h>
#include <stdio.h>
sml_get_proc_parameter_request *sml_get_proc_parameter_request_init() {
sml_get_proc_parameter_request *msg = (sml_get_proc_parameter_request *) malloc(sizeof (sml_get_proc_parameter_request));
memset(msg, 0, sizeof(sml_get_proc_parameter_request));
return msg;
sml_get_proc_parameter_request *msg = (sml_get_proc_parameter_request *) malloc(sizeof (sml_get_proc_parameter_request));
memset(msg, 0, sizeof(sml_get_proc_parameter_request));
return msg;
}
sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer *buf) {
@ -57,13 +57,14 @@ sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer
if (sml_buf_has_errors(buf)) goto error;
return msg;
error:
sml_get_proc_parameter_request_free(msg);
return 0;
}
void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, sml_buffer *buf) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_octet_string_write(msg->server_id, buf);
sml_octet_string_write(msg->username, buf);
@ -73,12 +74,14 @@ void sml_get_proc_parameter_request_write(sml_get_proc_parameter_request *msg, s
}
void sml_get_proc_parameter_request_free(sml_get_proc_parameter_request *msg) {
if (msg){
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->username);
sml_octet_string_free(msg->password);
sml_tree_path_free(msg->parameter_tree_path);
sml_octet_string_free(msg->attribute);
free(msg);
}
if (msg) {
sml_octet_string_free(msg->server_id);
sml_octet_string_free(msg->username);
sml_octet_string_free(msg->password);
sml_tree_path_free(msg->parameter_tree_path);
sml_octet_string_free(msg->attribute);
free(msg);
}
}

View file

@ -22,6 +22,7 @@
sml_get_proc_parameter_response *sml_get_proc_parameter_response_init() {
sml_get_proc_parameter_response *msg = (sml_get_proc_parameter_response *)malloc(sizeof(sml_get_proc_parameter_response));
memset(msg, 0, sizeof(sml_get_proc_parameter_response));
return msg;
}
@ -48,6 +49,7 @@ sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffe
if (sml_buf_has_errors(buf)) goto error;
return msg;
error:
sml_get_proc_parameter_response_free(msg);
return 0;
@ -70,4 +72,3 @@ void sml_get_proc_parameter_response_free(sml_get_proc_parameter_response *msg)
}
}

View file

@ -20,8 +20,5 @@
// this file is just there for symmetry
void sml_get_profile_list_request_noop() {}

View file

@ -104,3 +104,4 @@ void sml_get_profile_list_response_free(sml_get_profile_list_response *msg) {
free(msg);
}
}

View file

@ -24,13 +24,14 @@
#include <stdio.h>
sml_get_profile_pack_request *sml_get_profile_pack_request_init(){
sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request));
memset(msg, 0, sizeof(sml_get_profile_pack_request));
return msg;
sml_get_profile_pack_request *msg = (sml_get_profile_pack_request *) malloc(sizeof(sml_get_profile_pack_request));
memset(msg, 0, sizeof(sml_get_profile_pack_request));
return msg;
}
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);
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);
@ -55,12 +56,10 @@ void sml_get_profile_pack_request_write(sml_get_profile_pack_request *msg, sml_b
sml_buf_optional_write(buf);
}
sml_tree_write(msg->das_details, buf);
sml_tree_write(msg->das_details, buf);
}
sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf) {
sml_get_profile_pack_request *msg = sml_get_profile_pack_request_init();
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
@ -122,6 +121,7 @@ sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf
if (sml_buf_has_errors(buf)) goto error;
return msg;
error:
sml_get_profile_pack_request_free(msg);
return 0;
@ -146,9 +146,9 @@ void sml_get_profile_pack_request_free(sml_get_profile_pack_request *msg){
d = n;
} while (d);
}
sml_tree_free(msg->das_details);
free(msg);
}
}

View file

@ -20,11 +20,12 @@
#include <sml/sml_get_profile_pack_response.h>
#include <stdio.h>
// sml_get_profile_pack_response
// sml_get_profile_pack_response;
sml_get_profile_pack_response *sml_get_profile_pack_response_init() {
sml_get_profile_pack_response *msg = (sml_get_profile_pack_response *) malloc(sizeof(sml_get_profile_pack_response));
memset(msg, 0, sizeof(sml_get_profile_pack_response));
return msg;
}
@ -102,7 +103,6 @@ void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg){
}
// sml_prof_obj_header_entry;
sml_prof_obj_header_entry *sml_prof_obj_header_entry_init() {
@ -157,10 +157,8 @@ void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry) {
}
// sml_prof_obj_period_entry;
sml_prof_obj_period_entry *sml_prof_obj_period_entry_init() {
sml_prof_obj_period_entry *entry = (sml_prof_obj_period_entry *) malloc(sizeof(sml_prof_obj_period_entry));
memset(entry, 0, sizeof(sml_prof_obj_period_entry));
@ -218,12 +216,12 @@ void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry) {
}
// sml_value_entry;
sml_value_entry *sml_value_entry_init() {
sml_value_entry *entry = (sml_value_entry *) malloc(sizeof(sml_value_entry));
memset(entry, 0, sizeof(sml_value_entry));
return entry;
}
@ -246,6 +244,7 @@ sml_value_entry *sml_value_entry_parse(sml_buffer *buf) {
if (sml_buf_has_errors(buf)) goto error;
return entry;
error:
buf->error = 1;
sml_value_entry_free(entry);
@ -267,4 +266,3 @@ void sml_value_entry_free(sml_value_entry *entry) {
}
}

View file

@ -25,17 +25,17 @@
#include <sml/sml_value.h>
#include <stdio.h>
// sml_sequence;
sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)) {
sml_sequence *seq = (sml_sequence *) malloc(sizeof(sml_sequence));
memset(seq, 0, sizeof(sml_sequence));
seq->elem_free = elem_free;
return seq;
}
sml_sequence *sml_sequence_parse(sml_buffer *buf,
void *(*elem_parse) (sml_buffer *buf),
void (*elem_free) (void *elem)) {
sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem)) {
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
goto error;
@ -49,6 +49,7 @@ sml_sequence *sml_sequence_parse(sml_buffer *buf,
if (sml_buf_has_errors(buf)) goto error;
sml_sequence_add(seq, p);
}
return seq;
error:
@ -56,6 +57,7 @@ error:
sml_sequence_free(seq);
return 0;
}
void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)) {
if (seq == 0) {
sml_buf_optional_write(buf);
@ -72,14 +74,15 @@ void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (
void sml_sequence_free(sml_sequence *seq) {
if (seq) {
int i;
for (i = 0; i < seq->elems_len; i++) {
seq->elem_free((seq->elems)[i]);
}
if (seq->elems != 0) {
free(seq->elems);
}
free(seq);
}
}
@ -91,6 +94,8 @@ void sml_sequence_add(sml_sequence *seq, void *new_entry) {
}
// sml_list;
sml_list *sml_list_init(){
sml_list *s = (sml_list *)malloc(sizeof(sml_list));
memset(s, 0, sizeof(sml_list));
@ -136,9 +141,9 @@ sml_list *sml_list_entry_parse(sml_buffer *buf) {
return l;
error:
// This function doesn't free the allocated memory in error cases,
// this is done in sml_list_parse.
error:
buf->error = 1;
return 0;
}
@ -213,33 +218,34 @@ void sml_list_write(sml_list *list, sml_buffer *buf){
sml_list_entry_write(i, buf);
i = i->next;
}
}
void sml_list_entry_free(sml_list *list) {
if (list) {
sml_octet_string_free(list->obj_name);
sml_status_free(list->status);
sml_time_free(list->val_time);
if (list) {
sml_octet_string_free(list->obj_name);
sml_status_free(list->status);
sml_time_free(list->val_time);
sml_number_free(list->unit);
sml_number_free(list->scaler);
sml_value_free(list->value);
sml_octet_string_free(list->value_signature);
free(list);
}
sml_value_free(list->value);
sml_octet_string_free(list->value_signature);
free(list);
}
}
void sml_list_free(sml_list *list) {
if (list) {
sml_list *f = list;
sml_list *n = list->next;
if (list) {
sml_list *f = list;
sml_list *n = list->next;
while(f) {
sml_list_entry_free(f);
f = n;
if (f) {
n = f->next;
}
}
}
while(f) {
sml_list_entry_free(f);
f = n;
if (f) {
n = f->next;
}
}
}
}

View file

@ -28,7 +28,7 @@
#include <stdlib.h>
#include <unistd.h>
// SML MESSAGE
// sml_message;
sml_message *sml_message_parse(sml_buffer *buf) {
sml_message *msg = (sml_message *) malloc(sizeof(sml_message));
@ -62,6 +62,7 @@ sml_message *sml_message_parse(sml_buffer *buf) {
if (sml_buf_get_current_byte(buf) == SML_MESSAGE_END) {
sml_buf_update_bytes_read(buf, 1);
}
return msg;
error:
@ -70,40 +71,41 @@ error:
}
sml_message *sml_message_init() {
sml_message *msg = (sml_message *) malloc(sizeof(sml_message));
memset(msg, 0, sizeof(sml_message));
sml_message *msg = (sml_message *) malloc(sizeof(sml_message));
memset(msg, 0, sizeof(sml_message));
msg->transaction_id = sml_octet_string_generate_uuid();
return msg;
return msg;
}
void sml_message_free(sml_message *msg) {
if (msg) {
if (msg) {
sml_octet_string_free(msg->transaction_id);
sml_number_free(msg->group_id);
sml_number_free(msg->abort_on_error);
sml_message_body_free(msg->message_body);
sml_number_free(msg->crc);
free(msg);
}
free(msg);
}
}
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);
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_u8_write(msg->group_id, buf);
sml_u8_write(msg->abort_on_error, buf);
sml_message_body_write(msg->message_body, buf);
sml_message_body_write(msg->message_body, 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;
buf->cursor++;
// end of message
buf->buffer[buf->cursor] = 0x0;
buf->cursor++;
}
// SML MESSAGE BODY
// sml_message_body;
sml_message_body *sml_message_body_parse(sml_buffer *buf) {
sml_message_body *msg_body = (sml_message_body *) malloc(sizeof(sml_message_body));
@ -178,11 +180,11 @@ 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 = sml_u16_init(tag);
message_body->data = data;
return message_body;
sml_message_body *message_body = (sml_message_body *) malloc(sizeof(sml_message_body));
memset(message_body, 0, sizeof(sml_message_body));
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) {
@ -235,7 +237,7 @@ void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) {
default:
printf("error: message type %04X not yet implemented\n", *(message_body->tag));
break;
}
}
}
void sml_message_body_free(sml_message_body *message_body) {

View file

@ -99,6 +99,7 @@ void sml_number_byte_swap(unsigned char *bytes, int bytes_len) {
int i;
unsigned char ob[bytes_len];
memcpy(&ob, bytes, bytes_len);
for (i = 0; i < bytes_len; i++) {
bytes[i] = ob[bytes_len - (i + 1)];
}

View file

@ -18,11 +18,9 @@
#include <sml/sml_open_request.h>
#include <sml/sml_number.h>
#include <stdio.h>
sml_open_request *sml_open_request_init(){
sml_open_request *open_request = (sml_open_request *) malloc(sizeof(sml_open_request));
memset(open_request, 0, sizeof(sml_open_request));
@ -32,7 +30,7 @@ sml_open_request *sml_open_request_init(){
sml_open_request *sml_open_request_parse(sml_buffer *buf) {
sml_open_request *msg = sml_open_request_init();
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
goto error;
}
@ -42,28 +40,28 @@ sml_open_request *sml_open_request_parse(sml_buffer *buf) {
goto error;
}
msg->codepage = sml_octet_string_parse(buf);
msg->codepage = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->client_id = sml_octet_string_parse(buf);
msg->client_id = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->req_file_id = sml_octet_string_parse(buf);
msg->req_file_id = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->server_id = sml_octet_string_parse(buf);
msg->server_id = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->username = sml_octet_string_parse(buf);
msg->username = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->password = sml_octet_string_parse(buf);
msg->password = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->sml_version = sml_u8_parse(buf);
msg->sml_version = sml_u8_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
return msg;
return msg;
error:
sml_open_request_free(msg);
@ -71,15 +69,15 @@ error:
}
void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7);
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7);
sml_octet_string_write(msg->codepage, buf);
sml_octet_string_write(msg->client_id, buf);
sml_octet_string_write(msg->req_file_id, buf);
sml_octet_string_write(msg->server_id, buf);
sml_octet_string_write(msg->username,buf);
sml_octet_string_write(msg->password,buf);
sml_u8_write(msg->sml_version, buf);
sml_octet_string_write(msg->codepage, buf);
sml_octet_string_write(msg->client_id, buf);
sml_octet_string_write(msg->req_file_id, buf);
sml_octet_string_write(msg->server_id, buf);
sml_octet_string_write(msg->username,buf);
sml_octet_string_write(msg->password,buf);
sml_u8_write(msg->sml_version, buf);
}
void sml_open_request_free(sml_open_request *msg) {
@ -91,8 +89,8 @@ void sml_open_request_free(sml_open_request *msg) {
sml_octet_string_free(msg->username);
sml_octet_string_free(msg->password);
sml_number_free(msg->sml_version);
free(msg);
}
}

View file

@ -23,6 +23,7 @@
sml_open_response *sml_open_response_init() {
sml_open_response *msg = (sml_open_response *) malloc(sizeof(sml_open_response));
memset(msg, 0, sizeof(sml_open_response));
return msg;
}
@ -75,13 +76,15 @@ void sml_open_response_write(sml_open_response *msg, sml_buffer *buf) {
}
void sml_open_response_free(sml_open_response *msg) {
if (msg) {
sml_octet_string_free(msg->codepage);
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->req_file_id);
sml_octet_string_free(msg->server_id);
sml_time_free(msg->ref_time);
if (msg) {
sml_octet_string_free(msg->codepage);
sml_octet_string_free(msg->client_id);
sml_octet_string_free(msg->req_file_id);
sml_octet_string_free(msg->server_id);
sml_time_free(msg->ref_time);
sml_number_free(msg->sml_version);
free(msg);
}
free(msg);
}
}

View file

@ -20,9 +20,10 @@
#include <sml/sml_set_proc_parameter_request.h>
sml_set_proc_parameter_request *sml_set_proc_parameter_request_init() {
sml_set_proc_parameter_request *msg = (sml_set_proc_parameter_request *) malloc(sizeof (sml_set_proc_parameter_request));
memset(msg, 0, sizeof(sml_set_proc_parameter_request));
return msg;
sml_set_proc_parameter_request *msg = (sml_set_proc_parameter_request *) malloc(sizeof (sml_set_proc_parameter_request));
memset(msg, 0, sizeof(sml_set_proc_parameter_request));
return msg;
}
sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer *buf) {
@ -54,18 +55,19 @@ sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer
if (sml_buf_has_errors(buf)) goto error;
return msg;
error:
sml_set_proc_parameter_request_free(msg);
return 0;
}
void sml_set_proc_parameter_request_write(sml_set_proc_parameter_request *msg, sml_buffer *buf) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_octet_string_write(msg->server_id, buf);
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 5);
sml_octet_string_write(msg->server_id, buf);
sml_octet_string_write(msg->username, buf);
sml_octet_string_write(msg->password, buf);
sml_tree_path_write(msg->parameter_tree_path, buf);
sml_tree_write(msg->parameter_tree, buf);
sml_octet_string_write(msg->password, buf);
sml_tree_path_write(msg->parameter_tree_path, buf);
sml_tree_write(msg->parameter_tree, buf);
}
void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg) {
@ -75,9 +77,8 @@ void sml_set_proc_parameter_request_free(sml_set_proc_parameter_request *msg) {
sml_octet_string_free(msg->password);
sml_tree_path_free(msg->parameter_tree_path);
sml_tree_free(msg->parameter_tree);
free(msg);
}
}

View file

@ -34,47 +34,48 @@ int sml_buf_get_next_length(sml_buffer *buf) {
if ((byte & SML_ANOTHER_TL) != SML_ANOTHER_TL) {
break;
}
sml_buf_update_bytes_read(buf, 1);
if(list) {
list += -1;
}
sml_buf_update_bytes_read(buf, 1);
if(list) {
list += -1;
}
}
sml_buf_update_bytes_read(buf, 1);
return length + list;
}
void sml_buf_set_type_and_length(sml_buffer *buf, unsigned int type, unsigned int l) {
// set the type
buf->buffer[buf->cursor] |= type;
// set the type
buf->buffer[buf->cursor] |= type;
if (type != SML_TYPE_LIST) {
l++;
}
if (type != SML_TYPE_LIST) {
l++;
}
if (l > SML_LENGTH_FIELD) {
// how much shifts are necessary
int mask_pos = (sizeof(unsigned int) * 2) - 1;
if (l > SML_LENGTH_FIELD) {
// how much shifts are necessary
int mask_pos = (sizeof(unsigned int) * 2) - 1;
// the 4 most significant bits of l
unsigned int mask = 0xF0 << (8 * (sizeof(unsigned int) - 1));
// the 4 most significant bits of l
unsigned int mask = 0xF0 << (8 * (sizeof(unsigned int) - 1));
// select the 4 most significant bits with a bit set
while (!(mask & l)) {
mask >>= 4;
mask_pos--;
}
// select the 4 most significant bits with a bit set
while (!(mask & l)) {
mask >>= 4;
mask_pos--;
}
// copy the bits to the buffer
while (mask > SML_LENGTH_FIELD) {
buf->buffer[buf->cursor] |= SML_ANOTHER_TL;
buf->buffer[buf->cursor] |= ((mask & l) >> (4 * mask_pos));
mask >>= 4;
mask_pos--;
buf->cursor++;
}
}
buf->buffer[buf->cursor] |= (l & SML_LENGTH_FIELD);
buf->cursor++;
// copy the bits to the buffer
while (mask > SML_LENGTH_FIELD) {
buf->buffer[buf->cursor] |= SML_ANOTHER_TL;
buf->buffer[buf->cursor] |= ((mask & l) >> (4 * mask_pos));
mask >>= 4;
mask_pos--;
buf->cursor++;
}
}
buf->buffer[buf->cursor] |= (l & SML_LENGTH_FIELD);
buf->cursor++;
}
int sml_buf_has_errors(sml_buffer *buf) {
@ -98,34 +99,37 @@ void sml_buf_update_bytes_read(sml_buffer *buf, int bytes) {
}
sml_buffer *sml_buffer_init(size_t length) {
sml_buffer *buf = (sml_buffer *) malloc(sizeof(sml_buffer));
memset(buf, 0, sizeof(sml_buffer));
buf->buffer = (unsigned char *) malloc(length);
buf->buffer_len = length;
memset(buf->buffer, 0, buf->buffer_len);
return buf;
sml_buffer *buf = (sml_buffer *) malloc(sizeof(sml_buffer));
memset(buf, 0, sizeof(sml_buffer));
buf->buffer = (unsigned char *) malloc(length);
buf->buffer_len = length;
memset(buf->buffer, 0, buf->buffer_len);
return buf;
}
void sml_buf_optional_write(sml_buffer *buf) {
buf->buffer[buf->cursor] = SML_OPTIONAL_SKIPPED;
buf->cursor++;
buf->buffer[buf->cursor] = SML_OPTIONAL_SKIPPED;
buf->cursor++;
}
void sml_buffer_free(sml_buffer *buf) {
if (buf) {
if (buf->buffer)
free(buf->buffer);
if (buf->error_msg)
free(buf->error_msg);
free(buf);
}
if (buf) {
if (buf->buffer)
free(buf->buffer);
if (buf->error_msg)
free(buf->error_msg);
free(buf);
}
}
int sml_buf_optional_is_skipped(sml_buffer *buf) {
if (sml_buf_get_current_byte(buf) == SML_OPTIONAL_SKIPPED) {
sml_buf_update_bytes_read(buf, 1);
return 1;
}
return 0;
}
@ -139,3 +143,4 @@ void hexdump(unsigned char *buffer, size_t buffer_len) {
}
printf("\n");
}

View file

@ -22,6 +22,7 @@
sml_status *sml_status_init() {
sml_status *status = (sml_status *) malloc(sizeof(sml_status));
memset(status, 0, sizeof(sml_status));
return status;
}
@ -58,14 +59,14 @@ sml_status *sml_status_parse(sml_buffer *buf) {
return status;
}
void sml_status_write(sml_status *status, sml_buffer *buf){
void sml_status_write(sml_status *status, sml_buffer *buf) {
if (status == 0) {
sml_buf_optional_write(buf);
return;
}
sml_number_write(status->data.status8, (status->type & SML_TYPE_FIELD),
(status->type & SML_LENGTH_FIELD), buf);
};
}
void sml_status_free(sml_status *status) {
if (status) {
@ -73,3 +74,4 @@ void sml_status_free(sml_status *status) {
free(status);
}
}

View file

@ -76,3 +76,4 @@ void sml_time_free(sml_time *tme) {
free(tme);
}
}

View file

@ -18,19 +18,17 @@
#include <sml/sml_transport.h>
#include <sml/sml_shared.h>
#include <sml/sml_crc16.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <sml/sml_shared.h>
#include <sml/sml_crc16.h>
#define MC_SML_BUFFER_LEN 8096
size_t sml_transport_read(int fd, unsigned char *buffer, size_t max_len) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
@ -124,7 +122,6 @@ void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *
}
int sml_transport_write(int fd, sml_file *file) {
unsigned char start_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01};
unsigned char end_seq[] = {0x1b, 0x1b, 0x1b, 0x1b, 0x1a};
sml_buffer *buf = file->buf;
@ -161,6 +158,7 @@ int sml_transport_write(int fd, sml_file *file) {
if (wr == buf->cursor) {
return wr;
}
return 0;
}

View file

@ -21,13 +21,13 @@
#include <sml/sml_value.h>
#include <stdio.h>
// SML_TREE_PATH
// sml_tree_path;
sml_tree_path *sml_tree_path_init() {
sml_tree_path *tree_path = (sml_tree_path *) malloc(sizeof(sml_tree_path));
memset(tree_path, 0, sizeof(sml_tree_path));
return tree_path;
sml_tree_path *tree_path = (sml_tree_path *) malloc(sizeof(sml_tree_path));
memset(tree_path, 0, sizeof(sml_tree_path));
return tree_path;
}
sml_tree_path *sml_tree_path_parse(sml_buffer *buf) {
@ -61,11 +61,11 @@ error:
}
void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry) {
tree_path->path_entries_len++;
tree_path->path_entries = (octet_string **) realloc(tree_path->path_entries,
tree_path->path_entries_len++;
tree_path->path_entries = (octet_string **) realloc(tree_path->path_entries,
sizeof(octet_string *) * tree_path->path_entries_len);
tree_path->path_entries[tree_path->path_entries_len - 1] = entry;
tree_path->path_entries[tree_path->path_entries_len - 1] = entry;
}
void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) {
@ -74,38 +74,42 @@ void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) {
return;
}
int i;
if (tree_path->path_entries && tree_path->path_entries_len > 0) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree_path->path_entries_len);
for (i = 0; i < tree_path->path_entries_len; i++) {
sml_octet_string_write(tree_path->path_entries[i], buf);
}
}
if (tree_path->path_entries && tree_path->path_entries_len > 0) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree_path->path_entries_len);
int i;
for (i = 0; i < tree_path->path_entries_len; i++) {
sml_octet_string_write(tree_path->path_entries[i], buf);
}
}
}
void sml_tree_path_free(sml_tree_path *tree_path){
int i;
void sml_tree_path_free(sml_tree_path *tree_path) {
if (tree_path) {
if (tree_path->path_entries && tree_path->path_entries_len > 0) {
int i;
for (i = 0; i < tree_path->path_entries_len; i++) {
sml_octet_string_free(tree_path->path_entries[i]);
}
free(tree_path->path_entries);
}
free(tree_path);
}
}
// SML_TREE
// sml_tree;
sml_tree *sml_tree_init() {
sml_tree *tree = (sml_tree *) malloc(sizeof(sml_tree));
memset(tree, 0, sizeof(sml_tree));
return tree;
sml_tree *tree = (sml_tree *) malloc(sizeof(sml_tree));
memset(tree, 0, sizeof(sml_tree));
return tree;
}
sml_tree *sml_tree_parse(sml_buffer *buf){
sml_tree *sml_tree_parse(sml_buffer *buf) {
if (sml_buf_optional_is_skipped(buf)) {
return 0;
}
@ -146,6 +150,7 @@ sml_tree *sml_tree_parse(sml_buffer *buf){
}
return tree;
error:
sml_tree_free(tree);
return 0;
@ -158,7 +163,7 @@ void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree) {
base_tree->child_list[base_tree->child_list_len - 1] = tree;
}
void sml_tree_free(sml_tree *tree){
void sml_tree_free(sml_tree *tree) {
if (tree) {
sml_octet_string_free(tree->parameter_name);
sml_proc_par_value_free(tree->parameter_value);
@ -177,7 +182,6 @@ void sml_tree_write(sml_tree *tree, sml_buffer *buf) {
return;
}
int i;
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3);
sml_octet_string_write(tree->parameter_name, buf);
@ -186,6 +190,7 @@ void sml_tree_write(sml_tree *tree, sml_buffer *buf) {
if (tree->child_list && tree->child_list_len > 0) {
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, tree->child_list_len);
int i;
for (i = 0; i < tree->child_list_len; i++) {
sml_tree_write(tree->child_list[i], buf);
}
@ -196,7 +201,7 @@ void sml_tree_write(sml_tree *tree, sml_buffer *buf) {
}
// SML_PROC_PAR_VALUE
// sml_proc_par_value;
sml_proc_par_value *sml_proc_par_value_init() {
sml_proc_par_value *value = (sml_proc_par_value *) malloc(sizeof(sml_proc_par_value));
@ -276,9 +281,8 @@ void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf) {
}
}
void sml_proc_par_value_free(sml_proc_par_value *ppv){
void sml_proc_par_value_free(sml_proc_par_value *ppv) {
if (ppv) {
if (ppv->tag) {
switch (*(ppv->tag)) {
case SML_PROC_PAR_VALUE_TAG_VALUE:
@ -306,16 +310,18 @@ void sml_proc_par_value_free(sml_proc_par_value *ppv){
free(ppv->data.value);
}
}
free(ppv);
}
}
// SML_TUPEL_ENTRY
// sml_tuple_entry;
sml_tupel_entry *sml_tupel_entry_init() {
sml_tupel_entry *tupel = (sml_tupel_entry *) malloc(sizeof(sml_tupel_entry));
memset(tupel, 0, sizeof(sml_tupel_entry));
return tupel;
}
@ -437,7 +443,6 @@ void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf) {
sml_i64_write(tupel->value_R3, buf);
sml_octet_string_write(tupel->signature_mA_R2_R3, buf);
}
void sml_tupel_entry_free(sml_tupel_entry *tupel) {
@ -480,11 +485,12 @@ void sml_tupel_entry_free(sml_tupel_entry *tupel) {
// SML_PERIOD_ENTRY
// sml_period_entry;
sml_period_entry *sml_period_entry_init() {
sml_period_entry *period = (sml_period_entry *) malloc(sizeof(sml_period_entry));
memset(period, 0, sizeof(sml_period_entry));
return period;
}
@ -554,5 +560,3 @@ void sml_period_entry_free(sml_period_entry *period) {
}
}

View file

@ -18,7 +18,6 @@
#include <sml/sml_value.h>
#include <stdio.h>
sml_value *sml_value_parse(sml_buffer *buf) {
@ -86,6 +85,7 @@ void sml_value_write(sml_value *value, sml_buffer *buf) {
sml_value *sml_value_init() {
sml_value *value = (sml_value *) malloc(sizeof(sml_value));
memset(value, 0, sizeof(value));
return value;
}
@ -122,3 +122,4 @@ double sml_value_to_double(sml_value *value) {
return 0;
}
}

View file

@ -87,3 +87,4 @@ TEST_GROUP_RUNNER(sml_boolean) {
RUN_TEST_CASE(sml_boolean, write_false);
RUN_TEST_CASE(sml_boolean, write_optional);
}

View file

@ -46,6 +46,3 @@ TEST_GROUP_RUNNER(sml_buffer) {
RUN_TEST_CASE(sml_buffer, init_defaults);
}

View file

@ -45,6 +45,3 @@ TEST_GROUP_RUNNER(sml_file) {
RUN_TEST_CASE(sml_file, init);
}

View file

@ -50,4 +50,5 @@ TEST(sml_get_profile_pack_request, parse) {
TEST_GROUP_RUNNER(sml_get_profile_pack_request) {
RUN_TEST_CASE(sml_get_profile_pack_request, init);
RUN_TEST_CASE(sml_get_profile_pack_request, parse);
}
}

View file

@ -138,7 +138,3 @@ TEST_GROUP_RUNNER(sml_sequence) {
RUN_TEST_CASE(sml_sequence, free_octet_string);
}

View file

@ -56,6 +56,3 @@ TEST_GROUP_RUNNER(sml_message) {
RUN_TEST_CASE(sml_message, parse);
}

View file

@ -158,6 +158,3 @@ TEST_GROUP_RUNNER(sml_number) {
RUN_TEST_CASE(sml_number, write_integer8_optional);
}

View file

@ -97,6 +97,3 @@ TEST_GROUP_RUNNER(sml_octet_string) {
RUN_TEST_CASE(sml_octet_string, cmp_with_hex);
}

View file

@ -40,3 +40,4 @@ TEST(sml_open_request, init) {
TEST_GROUP_RUNNER(sml_open_request) {
RUN_TEST_CASE(sml_open_request, init);
}

View file

@ -77,3 +77,4 @@ TEST_GROUP_RUNNER(sml_status) {
RUN_TEST_CASE(sml_status, write_status32);
RUN_TEST_CASE(sml_status, write_optional);
}

View file

@ -85,3 +85,4 @@ TEST_GROUP_RUNNER(sml_time) {
RUN_TEST_CASE(sml_time, write_sec_index);
RUN_TEST_CASE(sml_time, write_optional);
}

View file

@ -136,3 +136,4 @@ TEST_GROUP_RUNNER(sml_value) {
RUN_TEST_CASE(sml_value, write_integer16);
RUN_TEST_CASE(sml_value, write_optional);
}