From b6dd65e62322507cb7a54e463f58e93755f5e1a5 Mon Sep 17 00:00:00 2001 From: Juri Glass Date: Mon, 22 Aug 2011 16:57:01 +0200 Subject: [PATCH] added missing methods to attention_response --- sml/include/sml/sml_attention_response.h | 3 ++- sml/src/sml_attention_response.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sml/include/sml/sml_attention_response.h b/sml/include/sml/sml_attention_response.h index 3516258..423f7bd 100644 --- a/sml/include/sml/sml_attention_response.h +++ b/sml/include/sml/sml_attention_response.h @@ -37,8 +37,9 @@ typedef struct { sml_tree *attention_details; // optional } sml_attention_response; +sml_attention_response *sml_attention_response_init(); sml_attention_response *sml_attention_response_parse(sml_buffer *buf); - +void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf); void sml_attention_response_free(sml_attention_response *msg); #ifdef __cplusplus diff --git a/sml/src/sml_attention_response.c b/sml/src/sml_attention_response.c index b5facbe..ddb5d82 100644 --- a/sml/src/sml_attention_response.c +++ b/sml/src/sml_attention_response.c @@ -20,9 +20,14 @@ #include #include -sml_attention_response *sml_attention_response_parse(sml_buffer *buf){ +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; +} + +sml_attention_response *sml_attention_response_parse(sml_buffer *buf){ + sml_attention_response *msg = sml_attention_response_init(); if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) { buf->error = 1; @@ -43,15 +48,23 @@ sml_attention_response *sml_attention_response_parse(sml_buffer *buf){ msg->attention_message = sml_octet_string_parse(buf); if (sml_buf_has_errors(buf)) goto error; - msg->attention_details = SML_SKIP_OPTIONAL sml_tree_parse(buf); + msg->attention_details = sml_tree_parse(buf); if (sml_buf_has_errors(buf)) goto error; return msg; error: sml_attention_response_free(msg); - return 0; + return 0; +} + +void sml_attention_response_write(sml_attention_response *msg, sml_buffer *buf) { + sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4); + sml_octet_string_write(msg->server_id, buf); + sml_octet_string_write(msg->attention_number, buf); + sml_octet_string_write(msg->attention_message, buf); + sml_tree_write(msg->attention_details, buf); } void sml_attention_response_free(sml_attention_response *msg){