From 437cd481214b73c9dd33f86966f1edf244ffa4c4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 22 Jan 2010 22:30:22 +0100 Subject: [PATCH] One COMSTACK test program --- test/Makefile.am | 3 +- test/tst_comstack.c | 62 ++++++++++++++++++++++++++++++++++++ test/tstcomstack.c | 87 --------------------------------------------------- 3 files changed, 63 insertions(+), 89 deletions(-) delete mode 100644 test/tstcomstack.c diff --git a/test/Makefile.am b/test/Makefile.am index a381d77..459177c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,7 +2,7 @@ ## Copyright (C) 1995-2010 Index Data check_PROGRAMS = tstxmalloc tsticonv tstnmem tstmatchstr tstwrbuf tstodr \ - tstccl tstlog tstcomstack \ + tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \ tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \ tst_timing tst_query_charset tst_oid tst_icu_I18N tst_match_glob \ @@ -62,7 +62,6 @@ tstodr_SOURCES = tstodrcodec.c tstodrcodec.h tstodr.c tstodrstack_SOURCES = tstodrstack.c tstccl_SOURCES = tstccl.c tstlog_SOURCES = tstlog.c -tstcomstack_SOURCES = tstcomstack.c tstsoap1_SOURCES = tstsoap1.c tstsoap2_SOURCES = tstsoap2.c tstlogthread_SOURCES = tstlogthread.c diff --git a/test/tst_comstack.c b/test/tst_comstack.c index e75653f..eee72f8 100644 --- a/test/tst_comstack.c +++ b/test/tst_comstack.c @@ -4,10 +4,12 @@ */ #include +#include #include #include #include +#include static void tst_http_request(void) { @@ -185,11 +187,71 @@ static void tst_http_response(void) } } +/** \brief COMSTACK synopsis from manual, doc/comstack.xml */ +static int comstack_example(const char *server_address_str) +{ + COMSTACK stack; + char *buf = 0; + int size = 0, length_incoming; + void *server_address_ip; + int status; + + char *protocol_package = "GET / HTTP/1.0\r\n\r\n"; + int protocol_package_length = strlen(protocol_package); + + stack = cs_create(tcpip_type, 1, PROTO_HTTP); + if (!stack) { + perror("cs_create"); /* use perror() here since we have no stack yet */ + return -1; + } + + server_address_ip = cs_straddr(stack, server_address_str); + if (!server_address_ip) + { + fprintf(stderr, "cs_straddr: address could not be resolved\n"); + return -1; + } + + status = cs_connect(stack, server_address_ip); + if (status != 0) { + fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack)); + return -1; + } + + status = cs_put(stack, protocol_package, protocol_package_length); + if (status) { + fprintf(stderr, "cs_put: %s\n", cs_strerror(stack)); + return -1; + } + + /* Now get a response */ + + length_incoming = cs_get(stack, &buf, &size); + if (!length_incoming) { + fprintf(stderr, "Connection closed\n"); + return -1; + } else if (length_incoming < 0) { + fprintf(stderr, "cs_get: %s\n", cs_strerror(stack)); + return -1; + } + + /* Print result */ + fwrite(buf, length_incoming, 1, stdout); + + /* clean up */ + cs_close(stack); + if (buf) + free(buf); + return 0; +} + int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); + if (argc == 2) + comstack_example(argv[1]); tst_http_request(); tst_http_response(); YAZ_CHECK_TERM; diff --git a/test/tstcomstack.c b/test/tstcomstack.c deleted file mode 100644 index 9ced280..0000000 --- a/test/tstcomstack.c +++ /dev/null @@ -1,87 +0,0 @@ -/* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data - * See the file LICENSE for details. - */ -#include -#include -#include - -#include -#include -#include - -static int comstack_example(const char *server_address_str) -{ - COMSTACK stack; - char *buf = 0; - int size = 0, length_incoming; - void *server_address_ip; - int status; - - char *protocol_package = "GET / HTTP/1.0\r\n\r\n"; - int protocol_package_length = strlen(protocol_package); - - stack = cs_create(tcpip_type, 1, PROTO_HTTP); - if (!stack) { - perror("cs_create"); /* use perror() here since we have no stack yet */ - return -1; - } - - server_address_ip = cs_straddr(stack, server_address_str); - if (!server_address_ip) - { - fprintf(stderr, "cs_straddr: address could not be resolved\n"); - return -1; - } - - status = cs_connect(stack, server_address_ip); - if (status != 0) { - fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack)); - return -1; - } - - status = cs_put(stack, protocol_package, protocol_package_length); - if (status) { - fprintf(stderr, "cs_put: %s\n", cs_strerror(stack)); - return -1; - } - - /* Now get a response */ - - length_incoming = cs_get(stack, &buf, &size); - if (!length_incoming) { - fprintf(stderr, "Connection closed\n"); - return -1; - } else if (length_incoming < 0) { - fprintf(stderr, "cs_get: %s\n", cs_strerror(stack)); - return -1; - } - - /* Print result */ - fwrite(buf, length_incoming, 1, stdout); - - /* clean up */ - cs_close(stack); - if (buf) - free(buf); - return 0; -} - - -int main(int argc, char **argv) -{ - YAZ_CHECK_INIT(argc, argv); - if (argc == 2) - comstack_example(argv[1]); - YAZ_CHECK_TERM; -} - -/* - * Local variables: - * c-basic-offset: 4 - * c-file-style: "Stroustrup" - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - -- 1.7.10.4