fully implemented open_request, open_response

This commit is contained in:
Juri Glass 2011-07-26 14:43:29 +02:00
parent 352d6997f5
commit d96e7dd1d8
7 changed files with 78 additions and 26 deletions

View file

@ -38,16 +38,9 @@ typedef struct {
u8 *sml_version; // optional
} sml_open_request;
//sml_open_request *sml_open_request_init();
//sml_open_request *sml_open_request_init(char* client_id,char* req_file_id, char* server_id);
sml_open_request *sml_open_request_init();
void sml_open_request_write(sml_open_request *msg, sml_buffer *buf);
sml_open_request *sml_open_request_parse(sml_buffer *buf);
void sml_open_request_write(sml_open_request *msg, sml_buffer *buf);
void sml_open_request_free(sml_open_request *msg);
#ifdef __cplusplus

View file

@ -38,8 +38,9 @@ typedef struct {
u8 *sml_version; // optional
} sml_open_response;
sml_open_response *sml_open_response_init();
sml_open_response *sml_open_response_parse(sml_buffer *buf);
void sml_open_response_write(sml_open_response *msg, sml_buffer *buf);
void sml_open_response_free(sml_open_response *msg);
#ifdef __cplusplus

View file

@ -29,21 +29,8 @@ sml_open_request *sml_open_request_init(){
return open_request;
}
void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) {
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_open_request *sml_open_request_parse(sml_buffer *buf) {
sml_open_request *msg = (sml_open_request *) malloc(sizeof(sml_open_request));
memset(msg, 0, sizeof(sml_open_request));
sml_open_request *msg = sml_open_request_init();
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
@ -83,6 +70,18 @@ error:
return 0;
}
void sml_open_request_write(sml_open_request *msg, sml_buffer *buf) {
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);
}
void sml_open_request_free(sml_open_request *msg) {
if (msg) {
sml_octet_string_free(msg->codepage);

View file

@ -18,12 +18,16 @@
#include <sml/sml_open_response.h>
#include <sml/sml_number.h>
sml_open_response *sml_open_response_parse(sml_buffer *buf) {
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;
}
sml_open_response *sml_open_response_parse(sml_buffer *buf) {
sml_open_response *msg = sml_open_response_init();
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
buf->error = 1;
@ -47,7 +51,7 @@ sml_open_response *sml_open_response_parse(sml_buffer *buf) {
msg->server_id = sml_octet_string_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->ref_time = SML_SKIP_OPTIONAL sml_time_parse(buf);
msg->ref_time = sml_time_parse(buf);
if (sml_buf_has_errors(buf)) goto error;
msg->sml_version = sml_u8_parse(buf);
@ -59,6 +63,17 @@ error:
return 0;
}
void sml_open_response_write(sml_open_response *msg, sml_buffer *buf) {
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_time_write(msg->ref_time, buf);
sml_u8_write(msg->sml_version, buf);
}
void sml_open_response_free(sml_open_response *msg) {
if (msg) {
sml_octet_string_free(msg->codepage);

View file

@ -16,6 +16,7 @@ OBJS = \
src/sml_list_test.o \
src/sml_time_test.o \
src/sml_file_test.o \
src/sml_open_request_test.o \
src/sml_message_test.o
test_run: libsml test

View file

@ -0,0 +1,42 @@
// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed
// DAI-Labor, TU-Berlin
//
// This file is part of libSML.
//
// libSML is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libSML is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libSML. If not, see <http://www.gnu.org/licenses/>.
#include "../unity/unity_fixture.h"
#include "test_helper.h"
#include <sml/sml_open_request.h>
TEST_GROUP(sml_open_request);
sml_buffer *buf;
TEST_SETUP(sml_open_request) {
buf = sml_buffer_init(512);
}
TEST_TEAR_DOWN(sml_open_request) {
sml_buffer_free(buf);
}
TEST(sml_open_request, init) {
sml_open_request *m = sml_open_request_init();
TEST_ASSERT_NOT_NULL(m);
}
TEST_GROUP_RUNNER(sml_open_request) {
RUN_TEST_CASE(sml_open_request, init);
}

View file

@ -27,6 +27,7 @@ static void runAllTests() {
RUN_TEST_GROUP(sml_status);
RUN_TEST_GROUP(sml_list);
RUN_TEST_GROUP(sml_time);
RUN_TEST_GROUP(sml_open_request);
RUN_TEST_GROUP(sml_message);
RUN_TEST_GROUP(sml_file);
}