From a4f22127be441c4c158c10fe65916872d99253d2 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 19 Jan 2022 02:49:47 +0100 Subject: code cleanup --- ecp/test/basic.c | 12 ++++++------ ecp/test/client.c | 8 ++++---- ecp/test/dir.c | 13 +++++++------ ecp/test/echo.c | 4 ++-- ecp/test/frag.c | 12 ++++++------ ecp/test/init.c | 15 +++++++++++++-- ecp/test/init_vconn.c | 21 ++++++++++++++++++--- ecp/test/server.c | 4 ++-- ecp/test/stress.c | 6 +++--- ecp/test/vc_client.c | 10 +++++----- ecp/test/vc_client_t.c | 20 ++++++++++---------- ecp/test/vc_server.c | 22 +++++++++++----------- ecp/test/vcs.c | 8 ++++---- ecp/test/voip.c | 8 ++++---- 14 files changed, 95 insertions(+), 68 deletions(-) (limited to 'ecp/test') diff --git a/ecp/test/basic.c b/ecp/test/basic.c index eb14b0e..0f4e322 100644 --- a/ecp/test/basic.c +++ b/ecp/test/basic.c @@ -68,8 +68,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_s, &key_perma_s); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_s, "0.0.0.0:3000"); printf("ecp_sock_open RV:%d\n", rv); @@ -88,8 +88,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_c, &key_perma_c); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_c, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) { rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000"); printf("ecp_node_init RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); diff --git a/ecp/test/client.c b/ecp/test/client.c index e6c8208..577a888 100644 --- a/ecp/test/client.c +++ b/ecp/test/client.c @@ -58,8 +58,8 @@ int main(int argc, char *argv[]) { handler.msg[MTYPE_MSG] = handle_msg; ctx.handler[CTYPE_TEST] = &handler; - rv = ecp_sock_create(&sock, &ctx, NULL); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock, &ctx, NULL); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -70,8 +70,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_node_load(&ctx, &node, argv[1]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); diff --git a/ecp/test/dir.c b/ecp/test/dir.c index 413cd03..0c2ac72 100644 --- a/ecp/test/dir.c +++ b/ecp/test/dir.c @@ -5,6 +5,7 @@ #include "core.h" #include "cr.h" #include "dir.h" +#include "dir_srv.h" ECPContext ctx_s; ECPSocket sock_s; @@ -51,8 +52,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_s, &key_perma_s); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_s, "0.0.0.0:3000"); printf("ecp_sock_open RV:%d\n", rv); @@ -70,8 +71,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_c, &key_perma_c); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_c, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -82,8 +83,8 @@ int main(int argc, char *argv[]) { rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000"); printf("ecp_node_init RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_get_dirlist(&conn, &node); printf("ecp_conn_get_dirlist RV:%d\n", rv); diff --git a/ecp/test/echo.c b/ecp/test/echo.c index ff9c01c..f3057df 100644 --- a/ecp/test/echo.c +++ b/ecp/test/echo.c @@ -43,8 +43,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_key_load(&ctx_s, &key_perma_s, argv[2]); printf("ecp_util_key_load RV:%d\n", rv); - rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_s, argv[1]); printf("ecp_sock_open RV:%d\n", rv); diff --git a/ecp/test/frag.c b/ecp/test/frag.c index bf7c1a2..73e45cb 100644 --- a/ecp/test/frag.c +++ b/ecp/test/frag.c @@ -74,8 +74,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_s, &key_perma_s); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_s, "0.0.0.0:3000"); printf("ecp_sock_open RV:%d\n", rv); @@ -94,8 +94,8 @@ int main(int argc, char *argv[]) { rv = ecp_dhkey_gen(&ctx_c, &key_perma_c); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_c, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -106,8 +106,8 @@ int main(int argc, char *argv[]) { rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000"); printf("ecp_node_init RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_rbuf_create(&conn, NULL, NULL, 0, &rbuf_recv, rbuf_r_msg, 128); printf("ecp_rbuf_create RV:%d\n", rv); diff --git a/ecp/test/init.c b/ecp/test/init.c index 4dff693..7b59578 100644 --- a/ecp/test/init.c +++ b/ecp/test/init.c @@ -14,8 +14,19 @@ static int v_rng(void *buf, size_t bufsize) { return 0; } -static ECPConnection *conn_alloc(unsigned char type) { - return malloc(sizeof(ECPConnection)); +static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) { + ECPConnection *conn; + int rv; + + conn = malloc(sizeof(ECPConnection)); + if (conn == NULL) return NULL; + + rv = ecp_conn_init(conn, sock, type); + if (rv) { + free(conn); + return NULL; + } + return conn; } static void conn_free(ECPConnection *conn) { diff --git a/ecp/test/init_vconn.c b/ecp/test/init_vconn.c index b79aa3d..59e9517 100644 --- a/ecp/test/init_vconn.c +++ b/ecp/test/init_vconn.c @@ -15,16 +15,31 @@ static int v_rng(void *buf, size_t bufsize) { return 0; } -static ECPConnection *conn_alloc(unsigned char type) { +static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) { + ECPConnection *conn; + int rv; + switch (type) { case ECP_CTYPE_VCONN: - return malloc(sizeof(ECPVConnIn)); + conn = malloc(sizeof(ECPVConnIn)); + break; default: - return malloc(sizeof(ECPConnection)); + conn = malloc(sizeof(ECPConnection)); + break; + } + if (conn == NULL) return NULL; + + rv = ecp_conn_init(conn, sock, type); + if (rv) { + printf("free1\n"); + free(conn); + return NULL; } + return conn; } static void conn_free(ECPConnection *conn) { + printf("free2\n"); free(conn); } diff --git a/ecp/test/server.c b/ecp/test/server.c index f70cc79..fabaf4e 100644 --- a/ecp/test/server.c +++ b/ecp/test/server.c @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_key_load(&ctx, &key_perma, argv[2]); printf("ecp_util_key_load RV:%d\n", rv); - rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock, &ctx, &key_perma); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock, argv[1]); printf("ecp_sock_open RV:%d\n", rv); diff --git a/ecp/test/stress.c b/ecp/test/stress.c index 4dae990..6eed851 100644 --- a/ecp/test/stress.c +++ b/ecp/test/stress.c @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) { if (!rv) rv = ecp_dhkey_gen(&ctx_s, &key_perma_s); for (i=0; i 22)) usage(argv[0]); - + rv = ecp_init(&ctx); printf("ecp_init RV:%d\n", rv); - + rv = ecp_conn_handler_init(&handler); handler.msg[ECP_MTYPE_OPEN] = handle_open; handler.msg[MTYPE_MSG] = handle_msg; ctx.handler[CTYPE_TEST] = &handler; - - rv = ecp_sock_create(&sock, &ctx, NULL); - printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_init(&sock, &ctx, NULL); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock, NULL); printf("ecp_sock_open RV:%d\n", rv); - + rv = ecp_start_receiver(&sock); printf("ecp_start_receiver RV:%d\n", rv); @@ -108,8 +108,8 @@ int main(int argc, char *argv[]) { printf("ecp_util_node_load RV:%d\n", rv); } - rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2); printf("ecp_vconn_open RV:%d\n", rv); diff --git a/ecp/test/vc_server.c b/ecp/test/vc_server.c index 55f15d1..b86d7b0 100644 --- a/ecp/test/vc_server.c +++ b/ecp/test/vc_server.c @@ -24,7 +24,7 @@ ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned } ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - // printf("MSG S:%s size:%ld\n", p, s); + printf("MSG S:%s size:%ld\n", p, s); char *msg = "VAISTINU JE CAR!"; unsigned char buf[1000]; @@ -42,34 +42,34 @@ static void usage(char *arg) { int main(int argc, char *argv[]) { int rv; - + if (argc != 3) usage(argv[0]); - + rv = ecp_init(&ctx); printf("ecp_init RV:%d\n", rv); - + rv = ecp_conn_handler_init(&handler); handler.msg[ECP_MTYPE_OPEN] = handle_open; handler.msg[MTYPE_MSG] = handle_msg; ctx.handler[CTYPE_TEST] = &handler; - + rv = ecp_util_key_load(&ctx, &key_perma, argv[1]); printf("ecp_util_key_load RV:%d\n", rv); - - rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_init(&sock, &ctx, &key_perma); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock, NULL); printf("ecp_sock_open RV:%d\n", rv); - + rv = ecp_start_receiver(&sock); printf("ecp_start_receiver RV:%d\n", rv); rv = ecp_util_node_load(&ctx, &node, argv[2]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock, ECP_CTYPE_VLINK); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); diff --git a/ecp/test/vcs.c b/ecp/test/vcs.c index 23e2557..f3a0156 100644 --- a/ecp/test/vcs.c +++ b/ecp/test/vcs.c @@ -30,8 +30,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_key_load(&ctx, &key_perma, argv[2]); printf("ecp_util_key_load RV:%d\n", rv); - rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock, &ctx, &key_perma); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock, argv[1]); printf("ecp_sock_open RV:%d\n", rv); @@ -43,8 +43,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_node_load(&ctx, &node, argv[3]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock, ECP_CTYPE_VLINK); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); diff --git a/ecp/test/voip.c b/ecp/test/voip.c index ad5032b..b0a9207 100644 --- a/ecp/test/voip.c +++ b/ecp/test/voip.c @@ -163,8 +163,8 @@ int main(int argc, char *argv[]) { handler_c.msg[MTYPE_MSG] = handle_msg_c; ctx_c.handler[CTYPE_TEST] = &handler_c; - rv = ecp_sock_create(&sock_c, &ctx_c, NULL); - printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_sock_init(&sock_c, &ctx_c, NULL); + printf("ecp_sock_init RV:%d\n", rv); rv = ecp_sock_open(&sock_c, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -175,8 +175,8 @@ int main(int argc, char *argv[]) { rv = ecp_util_node_load(&ctx_c, &node, argv[1]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); - printf("ecp_conn_create RV:%d\n", rv); + rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST); + printf("ecp_conn_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); -- cgit v1.2.3