From: Marcel Poul Date: Fri, 25 Nov 2011 11:36:28 +0000 (+0000) Subject: canl_io_ssl_write over ssl X-Git-Tag: merge_30_head_take2_dst~11 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=28d38714dc3e172238b4215192d999c3f54d686a;p=jra1mw.git canl_io_ssl_write over ssl --- diff --git a/emi.canl.canl-c/Makefile b/emi.canl.canl-c/Makefile index aa74a6d..50024cd 100644 --- a/emi.canl.canl-c/Makefile +++ b/emi.canl.canl-c/Makefile @@ -63,7 +63,7 @@ canl_dns.lo: canl_dns.c ${HEAD_CANL} canl_err.lo: canl_err.c ${HEAD_CANL} ${COMPILE} -c ${top_srcdir}/src/canl_err.c ${CFLAGS_LIB} -o $@ -canl_ssl.lo: canl_err.c ${HEAD_CANL} +canl_ssl.lo: canl_ssl.c ${HEAD_CANL} ${COMPILE} -c ${top_srcdir}/src/canl_ssl.c ${CFLAGS_LIB} -o $@ client: ${OBJ_CLI} diff --git a/emi.canl.canl-c/src/canl.c b/emi.canl.canl-c/src/canl.c index c465920..de1fd44 100644 --- a/emi.canl.canl-c/src/canl.c +++ b/emi.canl.canl-c/src/canl.c @@ -460,6 +460,7 @@ size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, glb_ctx *glb_cc = (glb_ctx*) cc; int b_written = 0; int err = 0; + errno = 0; if (!cc) { return -1; @@ -470,8 +471,8 @@ size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, goto end; } - //TODO testing: read something without using openssl - b_written = send(io_cc->sock, "Hello, world!", 13, 0); + //read something using openssl + b_written = ssl_write(glb_cc, io_cc, buffer, size, timeout); if (b_written == -1) { err = errno; //TODO check again goto end; diff --git a/emi.canl.canl-c/src/canl_sample_client.c b/emi.canl.canl-c/src/canl_sample_client.c index ea344e2..2bd1cdf 100644 --- a/emi.canl.canl-c/src/canl_sample_client.c +++ b/emi.canl.canl-c/src/canl_sample_client.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "canl.h" #define BUF_LEN 1000 @@ -12,6 +13,7 @@ int main(int argc, char *argv[]) int err = 0; char *err_msg = NULL; char buf[BUF_LEN]; + int buf_len = 0; char *p_server = NULL; char *def_server = "www.linuxfoundation.org"; int opt, port = 80; @@ -59,10 +61,22 @@ int main(int argc, char *argv[]) printf("connection cannot be established\n"); goto end; } + else { + printf("connection established\n"); + } - err = canl_io_write (my_ctx, my_io_h, NULL, 0, NULL); - if (err) { - //set_error ("cannot write"); + strcpy(buf, "This is the testing message to send"); + buf_len = strlen(buf) + 1; + + printf("Trying to send sth to the server\n"); + err = canl_io_write (my_ctx, my_io_h, buf, buf_len, NULL); + if (err <= 0) { + printf("can't write using ssl\n"); + goto end; + } + else { + buf[err] = '\0'; + printf("message \"%s\" sent successfully\n", buf); } err = canl_io_read (my_ctx, my_io_h, buf, sizeof(buf)-1, NULL);