From d3e15dd815573b4d543d41d9fb8a3e05813a57fe Mon Sep 17 00:00:00 2001
From: Dmitry Simonenko <pmwkaa@gmail.com>
Date: Mon, 2 Dec 2013 18:31:55 +0400
Subject: [PATCH] client-update: refactor, add include new connector as
 submodule use new connector as client driver

---
 .gitmodules                                   |   3 +
 CMakeLists.txt                                |   4 +-
 client/tarantool/CMakeLists.txt               |  16 +-
 client/tarantool/{tc_buf.c => buf.c}          |   2 +-
 client/tarantool/{tc_buf.h => buf.h}          |   0
 client/tarantool/{tc_cli.c => cli.c}          | 203 +++----------
 client/tarantool/{tc_cli.h => cli.h}          |   1 -
 client/tarantool/main.c                       | 190 +++++++++++++
 client/tarantool/{tc.h => main.h}             |  24 +-
 client/tarantool/{tc_opt.c => opt.c}          |  23 +-
 client/tarantool/{tc_opt.h => opt.h}          |   3 -
 client/tarantool/{tc_admin.h => pager.c}      |  68 ++++-
 client/tarantool/{tc_pager.h => pager.h}      |   0
 client/tarantool/{tc_print.c => print.c}      |  29 +-
 client/tarantool/{tc_print.h => print.h}      |   0
 .../{tc_print_snap.c => print_snap.c}         |   0
 .../{tc_print_snap.h => print_snap.h}         |   0
 .../{tc_print_xlog.c => print_xlog.c}         |   0
 .../{tc_print_xlog.h => print_xlog.h}         |   0
 client/tarantool/{tc_query.c => query.c}      |  82 +++---
 client/tarantool/{tc_query.h => query.h}      |  16 +-
 client/tarantool/{tc_store.c => store.c}      |   0
 client/tarantool/{tc_store.h => store.h}      |   0
 client/tarantool/tc.c                         | 266 ------------------
 client/tarantool/tc_admin.c                   | 159 -----------
 client/tarantool/tc_pager.c                   |  60 ----
 connector/c/CMakeLists.txt                    |  22 +-
 connector/c/tb                                |   1 +
 28 files changed, 397 insertions(+), 775 deletions(-)
 rename client/tarantool/{tc_buf.c => buf.c} (99%)
 rename client/tarantool/{tc_buf.h => buf.h} (100%)
 rename client/tarantool/{tc_cli.c => cli.c} (71%)
 rename client/tarantool/{tc_cli.h => cli.h} (98%)
 create mode 100644 client/tarantool/main.c
 rename client/tarantool/{tc.h => main.h} (75%)
 rename client/tarantool/{tc_opt.c => opt.c} (94%)
 rename client/tarantool/{tc_opt.h => opt.h} (97%)
 rename client/tarantool/{tc_admin.h => pager.c} (51%)
 rename client/tarantool/{tc_pager.h => pager.h} (100%)
 rename client/tarantool/{tc_print.c => print.c} (89%)
 rename client/tarantool/{tc_print.h => print.h} (100%)
 rename client/tarantool/{tc_print_snap.c => print_snap.c} (100%)
 rename client/tarantool/{tc_print_snap.h => print_snap.h} (100%)
 rename client/tarantool/{tc_print_xlog.c => print_xlog.c} (100%)
 rename client/tarantool/{tc_print_xlog.h => print_xlog.h} (100%)
 rename client/tarantool/{tc_query.c => query.c} (74%)
 rename client/tarantool/{tc_query.h => query.h} (87%)
 rename client/tarantool/{tc_store.c => store.c} (100%)
 rename client/tarantool/{tc_store.h => store.h} (100%)
 delete mode 100644 client/tarantool/tc.c
 delete mode 100644 client/tarantool/tc_admin.c
 delete mode 100644 client/tarantool/tc_pager.c
 create mode 160000 connector/c/tb

diff --git a/.gitmodules b/.gitmodules
index 56afac8cb1..992d2a7fcb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -13,3 +13,6 @@
 [submodule "src/lib/msgpuck"]
 	path = src/lib/msgpuck
 	url = https://github.com/tarantool/msgpuck.git
+[submodule "connector/c/tb"]
+	path = connector/c/tb
+	url = https://github.com/tarantool/tarantool-c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c891ec6ab4..e8303b32c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -152,6 +152,8 @@ include_directories("${PROJECT_SOURCE_DIR}/src") # for lib/
 include_directories("${PROJECT_SOURCE_DIR}/include")
 include_directories("${PROJECT_BINARY_DIR}/include")
 include_directories("${PROJECT_SOURCE_DIR}/third_party")
+
+include_directories("${PROJECT_SOURCE_DIR}/connector/c/tb")
 #
 # Specify prefixes
 #
@@ -349,7 +351,7 @@ include (cmake/rpm.cmake)
 
 add_subdirectory(cfg)
 # Disable connector_c for 1.6
-# add_subdirectory(connector)
+add_subdirectory(connector)
 add_subdirectory(src)
 add_subdirectory(extra)
 add_subdirectory(client)
diff --git a/client/tarantool/CMakeLists.txt b/client/tarantool/CMakeLists.txt
index 12b71cf7de..fe9b1b98a0 100644
--- a/client/tarantool/CMakeLists.txt
+++ b/client/tarantool/CMakeLists.txt
@@ -1,24 +1,24 @@
-project(tnt_cli)
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
 
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
 include(FindReadline)
 
 if (NOT READLINE_FOUND)
     message(FATAL_ERROR "readline library not found.")
 endif()
 
-set (cli "tarantool")
-set (cli_sources tc.c tc_opt.c tc_admin.c tc_query.c tc_print.c tc_buf.c
-                 tc_cli.c tc_pager.c)
-
-set (cli_libs gopt ${READLINE_LIBRARIES})
+set(cli "tarantool")
+set(cli_sources main.c opt.c query.c print.c buf.c cli.c pager.c)
+set(cli_libs gopt ${READLINE_LIBRARIES} tb)
 
 include_directories(${READLINE_INCLUDE_DIR})
 
+add_definitions("-DTB_LOCAL=${PROJECT_SOURCE_DIR}/connector/c/tb/lib")
+
 list(APPEND cli_sources ${CMAKE_SOURCE_DIR}/src/errcode.c)
 
 add_executable(${cli} ${cli_sources})
 set_source_files_compile_flags("TARANTOOL" ${cli_sources})
 target_link_libraries (${cli} ${cli_libs})
 
-install (TARGETS ${cli} DESTINATION bin)
+install(TARGETS ${cli} DESTINATION bin)
+
diff --git a/client/tarantool/tc_buf.c b/client/tarantool/buf.c
similarity index 99%
rename from client/tarantool/tc_buf.c
rename to client/tarantool/buf.c
index 4826ed1361..d8aad7eb2c 100644
--- a/client/tarantool/tc_buf.c
+++ b/client/tarantool/buf.c
@@ -32,7 +32,7 @@
 #include <stddef.h>
 #include <ctype.h>
 
-#include "client/tarantool/tc_buf.h"
+#include "client/tarantool/buf.h"
 
 /* Strip trailing ws from (char*) */
 size_t strip_end_ws(char *str) {
diff --git a/client/tarantool/tc_buf.h b/client/tarantool/buf.h
similarity index 100%
rename from client/tarantool/tc_buf.h
rename to client/tarantool/buf.h
diff --git a/client/tarantool/tc_cli.c b/client/tarantool/cli.c
similarity index 71%
rename from client/tarantool/tc_cli.c
rename to client/tarantool/cli.c
index cd287634fb..fe72b2fa60 100644
--- a/client/tarantool/tc_cli.c
+++ b/client/tarantool/cli.c
@@ -26,57 +26,32 @@
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdint.h>
-#include <ctype.h>
 
+#include <lib/tarantool.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <signal.h>
-#include <errno.h>
 #include <wchar.h>
 
 #include <readline/readline.h>
 #include <readline/history.h>
 
-#if 0
-#include <connector/c/include/tarantool/tnt.h>
-#include <connector/c/include/tarantool/tnt_net.h>
-#include <connector/c/include/tarantool/tnt_queue.h>
-#include <connector/c/include/tarantool/tnt_utf8.h>
-#include <connector/c/include/tarantool/tnt_lex.h>
-#include <connector/c/include/tarantool/tnt_sql.h>
-#include <connector/c/include/tarantool/tnt_xlog.h>
-#include <connector/c/include/tarantool/tnt_rpl.h>
-#endif
-
-#include "client/tarantool/tc_opt.h"
-#include "client/tarantool/tc_admin.h"
-#include "client/tarantool/tc.h"
-#include "client/tarantool/tc_pager.h"
-#include "client/tarantool/tc_query.h"
-#include "client/tarantool/tc_cli.h"
-#include "client/tarantool/tc_print.h"
-#include "client/tarantool/tc_buf.h"
-
-#define TC_DEFAULT_HISTORY_FILE ".tarantool_history"
-
-#define TC_ALLOCATION_ERROR "error: memory allocation failed for %zu bytes\n"
-#define TC_REALLOCATION_ERROR "error: memory reallocation failed for %zu bytes\n"
+#include <client/tarantool/opt.h>
+#include <client/tarantool/main.h>
+#include <client/tarantool/pager.h>
+#include <client/tarantool/query.h>
+#include <client/tarantool/cli.h>
+#include <client/tarantool/print.h>
+#include <client/tarantool/buf.h>
 
-extern struct tc tc;
+extern struct tarantool_client tc;
 
 static inline int tc_cli_error(char *e) {
-	if (e) {
+	if (e)
 		tc_printf("%s\n", e);
-		free(e);
-	}
 	return 1;
 }
 
@@ -87,10 +62,12 @@ static int tc_cli_reconnect(void) {
 		return 1;
 	}
 #endif
+#if 0
 	if (tc_admin_reconnect(&tc.admin) == -1) {
 		tc_printf("reconnect: admin console connection failed\n");
 		return 1;
 	}
+#endif
 	tc_printf("reconnected\n");
 	return 0;
 }
@@ -147,12 +124,14 @@ tc_cmd_usage(void)
 }
 #endif
 
-static int tc_cli_admin(char *cmd, int exit) {
-	char *e = NULL;
-	tc_query_admin_t cb = (exit) ? NULL : tc_query_admin_printer;
-	if (!exit) tc_pager_start();
-	if (tc_query_admin(cmd, cb, &e) == -1)
-		return tc_cli_error(e);
+static int
+tc_cli_admin(char *cmd, int exit)
+{
+	tc_query_t cb = (exit) ? NULL : tc_printer;
+	if (!exit)
+		tc_pager_start();
+	if (tc_query(cmd, cb) == -1)
+		return tc_cli_error("failed to send admin query");
 	return 0;
 }
 
@@ -384,7 +363,8 @@ int tc_cli_cmdv(void)
 	return rc;
 }
 
-static void tc_cli_init(void) {
+static void tc_cli_init(void)
+{
 	/* ignoring SIGPIPE for reconnection handling */
 	struct sigaction sa;
 	memset(&sa, 0, sizeof(sa));
@@ -399,14 +379,14 @@ static char* tc_cli_readline_pipe() {
 	const size_t wcsize = sizeof(wchar_t);
 	char *str = (char *)malloc(size);
 	if (str == NULL)
-		tc_error(TC_ALLOCATION_ERROR, size);
+		tc_oom();
 	wchar_t c;
 	while ((c = getwchar())) {
 		if (size < (pos + wcsize)) {
 			size *= 2;
 			char *nd = (char *)realloc(str, size);
 			if (nd == NULL)
-				tc_error(TC_REALLOCATION_ERROR, size);
+				tc_oom();
 			str = nd;
 		}
 		if (c == '\r' || c == '\n' || c == WEOF) {
@@ -441,27 +421,28 @@ static int check_delim(char* str, size_t len, size_t sep_len) {
 
 int tc_cli(void)
 {
-	/* initializing cli */
+	/* initialize cli */
 	tc_cli_init();
 
-	/* loading history file */
+	/* load history file */
 	char *home = getenv("HOME");
 	char history[1024];
 	snprintf(history, sizeof(history), "%s/%s", home,
 		 TC_DEFAULT_HISTORY_FILE);
 	read_history(history);
 
-	/* setting prompt */
+	/* set prompt */
 	char prompt[128];
-	int prompt_len = snprintf(prompt, sizeof(prompt),
-				  "%s> ", tc.opt.host) - 2;
+	int prompt_len =
+		snprintf(prompt, sizeof(prompt), "%s> ", tc.opt.host) - 2;
 	char prompt_delim[128];
+
 	/* interactive mode */
 	char *part_cmd;
 	struct tc_buf cmd;
 	if (tc_buf_str(&cmd))
-		tc_error(TC_REALLOCATION_ERROR,
-			 cmd.size);
+		tc_oom();
+
 	while (1) {
 		if (isatty(STDIN_FILENO)) {
 			snprintf(prompt_delim, sizeof(prompt_delim),
@@ -475,26 +456,26 @@ int tc_cli(void)
 		}
 		if (!part_cmd)
 			break;
+
 		if (tc_buf_str_append(&cmd, part_cmd, strlen(part_cmd)))
-			tc_error(TC_REALLOCATION_ERROR,
-				 cmd.size);
-		int delim_exists = check_delim( cmd.data,
+			tc_oom();
+		int delim_exists =
+			check_delim(cmd.data,
 						cmd.used - 1,
 						tc.opt.delim_len);
-		if (tc_buf_str_append(&cmd, "\n", 1)) /* Append '\n' to the STR */
-			tc_error(TC_REALLOCATION_ERROR,
-				 cmd.size);
+		if (tc_buf_str_append(&cmd, "\n", 1))
+			tc_oom();
 		free(part_cmd);
-		if (!delim_exists && !feof(stdin)) /* If still without delimiter and not EOF */
+		if (!delim_exists && !feof(stdin))
 			continue;
-		tc_buf_str_delete(&cmd, 1); /* Delete last appended '\n' */
-		if (isatty(STDIN_FILENO)) /* Enable history on readline use only */
+		tc_buf_str_delete(&cmd, 1);
+		if (isatty(STDIN_FILENO))
 			add_history(cmd.data);
-		tc_buf_cmdfy(&cmd, tc.opt.delim_len); /* Create admin cmd from STR */
+		tc_buf_cmdfy(&cmd, tc.opt.delim_len);
 		if (delim_exists && tc_buf_str_isempty(&cmd))
 			goto next;
-		enum tc_cli_cmd_ret ret = tc_cli_cmd(cmd.data,
-						     cmd.used - 1);
+
+		enum tc_cli_cmd_ret ret = tc_cli_cmd(cmd.data, cmd.used - 1);
 next:
 		tc_buf_clear(&cmd);
 		if (ret == TC_CLI_EXIT || feof(stdin)) {
@@ -503,100 +484,8 @@ int tc_cli(void)
 		}
 	}
 
-	/* updating history file */
+	/* update history file */
 	write_history(history);
 	clear_history();
 	return 0;
 }
-
-#undef TC_ALLOCATION_ERROR
-#undef TC_REALLOCATION_ERROR
-
-#if 0
-struct tc_version {
-	int a, b, c;
-	int commit;
-};
-
-static int
-tc_versionof(struct tc_version *v, char *str)
-{
-	int rc = sscanf(str, "%d.%d.%d-%d", &v->a, &v->b, &v->c, &v->commit);
-	return rc == 4;
-}
-
-static int
-tc_versioncmp(struct tc_version *v, int a, int b, int c, int commit)
-{
-	int rc;
-	rc = v->a - a;
-	if (rc != 0)
-		return rc;
-	rc = v->b - b;
-	if (rc != 0)
-		return rc;
-	rc = v->c - c;
-	if (rc != 0)
-		return rc;
-	rc = v->commit - commit;
-	if (rc != 0)
-		return rc;
-	return 0;
-}
-#endif
-
-#if 0
-	if (tc_admin_query(&tc.admin, "box.info.version") == -1)
-		return -1;
-	char *message = NULL;
-	size_t size = 0;
-	int rc = tc_admin_reply(&tc.admin, &message, &size);
-	if (rc == -1 || size < 8) {
-		free(message);
-		return -1;
-	}
-	char *version = message + 7;
-	char *eol = strchr(version, '\n');
-	*eol = 0;
-	struct tc_version v;
-	rc = tc_versionof(&v, version);
-	if (rc == 0) {
-		free(message);
-		return -1;
-	}
-	free(message);
-
-	/* call motd for version >= 1.5.3-93 */
-	if (tc_versioncmp(&v, 1, 5, 3, 93) < 0)
-		return 0;
-	if (tc_admin_query(&tc.admin, "motd()") == -1)
-		return -1;
-	rc = tc_admin_reply(&tc.admin, &message, &size);
-	if (rc == -1 || size < 8) {
-		free(message);
-		return -1;
-	}
-	tc_printf("%s", message);
-	free(message);
-#endif
-
-int tc_cli_motd(void)
-{
-	/* call motd for version >= 1.5.3-93 */
-	if (tc_admin_query(&tc.admin, "motd()") == -1)
-		return -1;
-	char *message = NULL;
-	size_t size = 0;
-	int rc = tc_admin_reply(&tc.admin, &message, &size);
-	if (rc == -1 || size < 8) {
-		free(message);
-		return -1;
-	}
-	if (strcmp(message, "---\nunknown command. try typing help.\n...\n") == 0) {
-		free(message);
-		return 0;
-	}
-	tc_printf("%s", message);
-	free(message);
-	return 0;
-}
diff --git a/client/tarantool/tc_cli.h b/client/tarantool/cli.h
similarity index 98%
rename from client/tarantool/tc_cli.h
rename to client/tarantool/cli.h
index 9650457cb2..fb516501ca 100644
--- a/client/tarantool/tc_cli.h
+++ b/client/tarantool/cli.h
@@ -30,6 +30,5 @@
  */
 int tc_cli_cmdv(void);
 int tc_cli(void);
-int tc_cli_motd(void);
 
 #endif /* TC_CLI_H_INCLUDED */
diff --git a/client/tarantool/main.c b/client/tarantool/main.c
new file mode 100644
index 0000000000..965ee414d5
--- /dev/null
+++ b/client/tarantool/main.c
@@ -0,0 +1,190 @@
+
+/*
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <lib/tarantool.h>
+#include <locale.h>
+#include <unistd.h>
+
+#include <client/tarantool/opt.h>
+#include <client/tarantool/main.h>
+#include <client/tarantool/pager.h>
+#include <client/tarantool/cli.h>
+#include <client/tarantool/print.h>
+/*#include <client/tarantool/store.h>*/
+#include <client/tarantool/query.h>
+/*#include <client/tarantool/print_snap.h>*/
+/*#include <client/tarantool/print_xlog.h>*/
+
+struct tarantool_client tc;
+
+static void
+tc_init(void)
+{
+	memset(&tc, 0, sizeof(tc));
+	setlocale(LC_ALL, "");
+	tc.pager_fd = fileno(stdout);
+	tc.pager_pid = 0;
+	tb_sesinit(&tc.admin);
+}
+
+static void
+tc_shutdown(void)
+{
+	tb_sesclose(&tc.admin);
+	tc_pager_kill();
+}
+
+void tc_error(char *fmt, ...)
+{
+	char msg[256];
+	va_list args;
+	tc_shutdown();
+	va_start(args, fmt);
+	vsnprintf(msg, sizeof(msg), fmt, args);
+	va_end(args);
+	tc_printf("error: %s\n", msg);
+	exit(1);
+}
+
+static int
+tc_motdof(char *r)
+{
+	if (strcmp(r, TC_ERRCMD) != 0)
+		tc_printf("%s", r);
+	return 0;
+}
+
+static void
+tc_motd(void)
+{
+	int rc = tc_query("motd()", tc_motdof);
+	if (rc == -1)
+		tc_error("%s\n", "failed to send admin query");
+}
+
+static int
+tc_primaryportof(char *r)
+{
+	if (strcmp(r, TC_ERRCMD) != 0)
+		return 0;
+	int port = 0;
+	sscanf(r, "---\n - %d\n...", &port);
+	return port;
+}
+
+static int
+tc_primaryport()
+{
+	int rc = tc_query("box.cfg.primary_port", tc_primaryportof);
+	if (rc == -1)
+		tc_error("%s\n", "failed to send admin query");
+	if (rc > 0)
+		return rc;
+	rc = tc_query("lua box.cfg.primary_port", tc_primaryportof);
+	if (rc == -1)
+		tc_error("%s\n", "failed to send admin query");
+	return rc;
+}
+
+static void
+tc_connect(void)
+{
+	tb_sesset(&tc.admin, TB_HOST, tc.opt.host);
+	tb_sesset(&tc.admin, TB_PORT, tc.opt.port_admin);
+	tb_sesset(&tc.admin, TB_SENDBUF, 0);
+	tb_sesset(&tc.admin, TB_READBUF, 0);
+
+	int rc = tb_sesconnect(&tc.admin);
+	if (rc == -1)
+		tc_error("admin console connection failed");
+
+	if (tc.opt.port == 0)
+		tc.opt.port = tc_primaryport();
+}
+
+#if 0
+static void tc_validate(void)
+{
+	tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format);
+	tc.opt.snap_printer = tc_print_getsnapcb(tc.opt.format);
+	if (tc.opt.xlog_printer == NULL)
+		tc_error("unsupported output xlog format '%s'",
+				tc.opt.format);
+	if (tc.opt.snap_printer == NULL)
+		tc_error("unsupported output snap format '%s'",
+				tc.opt.format);
+	if (tc.opt.format && strcmp(tc.opt.format, "raw") == 0)
+		tc.opt.raw = 1;
+}
+#endif
+
+int main(int argc, char *argv[], char *envp[])
+{
+	tc_init();
+	enum tc_opt_mode mode =
+		tc_opt_init(&tc.opt, argc, argv, envp);
+
+	/*tc_validate();*/
+
+	int rc = 0;
+	switch (mode) {
+	case TC_OPT_USAGE:
+		tc_opt_usage();
+		break;
+	case TC_OPT_VERSION:
+		tc_opt_version();
+		break;
+#if 0
+	case TC_OPT_RPL:
+		tc_connect();
+		rc = tc_store_remote();
+		break;
+	case TC_OPT_WAL_CAT:
+		rc = tc_store_cat();
+		break;
+	case TC_OPT_WAL_PLAY:
+		tc_connect();
+		rc = tc_store_play();
+		break;
+#endif
+	case TC_OPT_CMD:
+		tc_connect();
+		rc = tc_cli_cmdv();
+		break;
+	case TC_OPT_INTERACTIVE:
+		tc_connect();
+		tc_motd();
+		rc = tc_cli();
+		break;
+	}
+
+	tc_shutdown();
+	return rc;
+}
diff --git a/client/tarantool/tc.h b/client/tarantool/main.h
similarity index 75%
rename from client/tarantool/tc.h
rename to client/tarantool/main.h
index f001346125..7b6b592f16 100644
--- a/client/tarantool/tc.h
+++ b/client/tarantool/main.h
@@ -1,5 +1,5 @@
-#ifndef TC_H_INCLUDED
-#define TC_H_INCLUDED
+#ifndef TC_MAIN_H_INCLUDED
+#define TC_MAIN_H_INCLUDED
 /*
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -29,14 +29,28 @@
  * SUCH DAMAGE.
  */
 
-struct tc {
+#define TC_VERSION_MAJOR "0"
+#define TC_VERSION_MINOR "3"
+
+#define TC_DEFAULT_HOST "localhost"
+#define TC_DEFAULT_PORT 33013
+#define TC_DEFAULT_ADMIN_PORT 33015
+#define TC_DEFAULT_HISTORY_FILE ".tarantool_history"
+
+struct tarantool_client {
+	struct tbses admin;
 	struct tc_opt opt;
-	struct tc_admin admin;
-	struct tnt_stream *net;
 	int pager_fd;
 	pid_t pager_pid;
 };
 
 void tc_error(char *fmt, ...);
 
+static inline void
+tc_oom(void) {
+	tc_error("memory allocation failed");
+}
+
+#define TC_ERRCMD "---\nunknown command. try typing help.\n...\n"
+
 #endif /* TC_H_INCLUDED */
diff --git a/client/tarantool/tc_opt.c b/client/tarantool/opt.c
similarity index 94%
rename from client/tarantool/tc_opt.c
rename to client/tarantool/opt.c
index 544af0ccab..fc4ff9445e 100644
--- a/client/tarantool/tc_opt.c
+++ b/client/tarantool/opt.c
@@ -26,17 +26,12 @@
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
+#include <lib/tarantool.h>
 
 #include <third_party/gopt/gopt.h>
 
-#include "client/tarantool/tc_opt.h"
-
-
-#define TC_DEFAULT_HOST "localhost"
+#include <client/tarantool/opt.h>
+#include <client/tarantool/main.h>
 
 /* supported cli options */
 static const void *tc_options_def = gopt_start(
@@ -96,7 +91,8 @@ void tc_opt_version(void)
 	exit(0);
 }
 
-enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp)
+enum tc_opt_mode
+tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp)
 {
 	/* usage */
 	void *tc_options = gopt_sort(&argc, (const char**)argv, tc_options_def);
@@ -116,17 +112,14 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **e
 	if (opt->host == NULL)
 		opt->host = TC_DEFAULT_HOST;
 
-#if 0
 	/* server port */
 	const char *arg = NULL;
-	opt->port = 0;
+	opt->port = TC_DEFAULT_PORT;
 	if (gopt_arg(tc_options, 'p', &arg))
 		opt->port = atoi(arg);
-#endif
 
-	const char *arg = NULL;
 	/* server admin port */
-	opt->port_admin = 0;
+	opt->port_admin = TC_DEFAULT_ADMIN_PORT;
 	if (gopt_arg(tc_options, 'a', &arg))
 		opt->port_admin = atoi(arg);
 
@@ -169,13 +162,13 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **e
 		opt->str_instead_int = 1;
 #endif
 
-#if 0
 	/* set delimiter on start */
 	opt->delim = "";
 	opt->delim_len = 0;
 	if (gopt_arg(tc_options, 'D', &opt->delim))
 		opt->delim_len = strlen(opt->delim);
 
+#if 0
 	/* replica mode */
 	if (gopt_arg(tc_options, 'R', &arg)) {
 		opt->mode = TC_OPT_RPL;
diff --git a/client/tarantool/tc_opt.h b/client/tarantool/opt.h
similarity index 97%
rename from client/tarantool/tc_opt.h
rename to client/tarantool/opt.h
index 311e0eb428..48eb0dd850 100644
--- a/client/tarantool/tc_opt.h
+++ b/client/tarantool/opt.h
@@ -29,9 +29,6 @@
  * SUCH DAMAGE.
  */
 
-#define TC_VERSION_MAJOR "0"
-#define TC_VERSION_MINOR "2"
-
 enum tc_opt_mode {
 	TC_OPT_USAGE,
 	TC_OPT_VERSION,
diff --git a/client/tarantool/tc_admin.h b/client/tarantool/pager.c
similarity index 51%
rename from client/tarantool/tc_admin.h
rename to client/tarantool/pager.c
index 56e109a98d..032e79706d 100644
--- a/client/tarantool/tc_admin.h
+++ b/client/tarantool/pager.c
@@ -1,5 +1,4 @@
-#ifndef TC_ADMIN_H_INCLUDED
-#define TC_ADMIN_H_INCLUDED
+
 /*
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -27,20 +26,61 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- */
+*/
+
+#include <lib/tarantool.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "client/tarantool/opt.h"
+#include "client/tarantool/main.h"
+#include "client/tarantool/pager.h"
 
-struct tc_admin {
-	const char *host;
-	int port;
-	int fd;
-};
+extern struct tarantool_client tc;
 
-int tc_admin_connect(struct tc_admin *a, const char *host, int port);
-int tc_admin_reconnect(struct tc_admin *a);
+void tc_pager_start() {
+	if (tc.pager_pid != 0)
+		tc_pager_kill();
+	if (tc.opt.pager == NULL) {
+		tc.pager_fd = fileno(stdout);
+		return;
+	}
+	int pipefd[2];
+	const char *const argv[] = {"/bin/sh", "-c", tc.opt.pager, NULL};
 
-void tc_admin_close(struct tc_admin *a);
+	if (pipe(pipefd) < 0)
+		tc_error("Failed to open pipe. Errno: %s", strerror(errno));
+	pid_t pid = fork();
+	if (pid < 0) {
+		tc_error("Failed to fork. Errno: %s", strerror(errno));
+	} else if (pid == 0) {
+		close(pipefd[1]);
+		dup2(pipefd[0], STDIN_FILENO);
+		execve(argv[0], (char * const*)argv, (char * const*)tc.opt.envp);
+		tc_error("Can't start pager! Errno: %s", strerror(errno));
+	} else {
+		close(pipefd[0]);
+		tc.pager_fd = pipefd[1];
+		tc.pager_pid = pid;
+	}
+	return;
+}
 
-int tc_admin_query(struct tc_admin *a, char *q);
-int tc_admin_reply(struct tc_admin *a, char **r, size_t *size);
+void tc_pager_stop () {
+	if (tc.pager_pid != 0) {
+		close(tc.pager_fd);
+		tc.pager_fd = fileno(stdout);
+		waitpid(tc.pager_pid, NULL, 0);
+		tc.pager_pid = 0;
+	}
+	return;
+}
 
-#endif /* TC_ADMIN_H_INCLUDED */
+void tc_pager_kill () {
+	if (tc.pager_pid != 0) {
+		kill(tc.pager_pid, SIGTERM);
+		tc_pager_stop();
+	}
+}
diff --git a/client/tarantool/tc_pager.h b/client/tarantool/pager.h
similarity index 100%
rename from client/tarantool/tc_pager.h
rename to client/tarantool/pager.h
diff --git a/client/tarantool/tc_print.c b/client/tarantool/print.c
similarity index 89%
rename from client/tarantool/tc_print.c
rename to client/tarantool/print.c
index ed8985f928..e6ace8a2a9 100644
--- a/client/tarantool/tc_print.c
+++ b/client/tarantool/print.c
@@ -25,34 +25,21 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- */
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <string.h>
+*/
+
+#include <lib/tarantool.h>
 #include <ctype.h>
 #include <wctype.h>
-
 #include <unistd.h>
 #include <errno.h>
 
-#if 0
-#include <connector/c/include/tarantool/tnt.h>
-#include <connector/c/include/tarantool/tnt_xlog.h>
-#include <connector/c/include/tarantool/tnt_rpl.h>
-#endif
-
-#include "client/tarantool/tc_opt.h"
-#include "client/tarantool/tc_admin.h"
-#include "client/tarantool/tc.h"
-#include "client/tarantool/tc_print.h"
-#include "client/tarantool/tc_query.h"
+#include <client/tarantool/opt.h>
+#include <client/tarantool/main.h>
+#include <client/tarantool/print.h>
+#include <client/tarantool/query.h>
 
-extern struct tc tc;
+extern struct tarantool_client tc;
 
-/*##################### Base printing functions #####################*/
 void tc_print_buf(char *buf, size_t size) {
 	printf("%-.*s", (int)size, buf);
 	fflush(stdout);
diff --git a/client/tarantool/tc_print.h b/client/tarantool/print.h
similarity index 100%
rename from client/tarantool/tc_print.h
rename to client/tarantool/print.h
diff --git a/client/tarantool/tc_print_snap.c b/client/tarantool/print_snap.c
similarity index 100%
rename from client/tarantool/tc_print_snap.c
rename to client/tarantool/print_snap.c
diff --git a/client/tarantool/tc_print_snap.h b/client/tarantool/print_snap.h
similarity index 100%
rename from client/tarantool/tc_print_snap.h
rename to client/tarantool/print_snap.h
diff --git a/client/tarantool/tc_print_xlog.c b/client/tarantool/print_xlog.c
similarity index 100%
rename from client/tarantool/tc_print_xlog.c
rename to client/tarantool/print_xlog.c
diff --git a/client/tarantool/tc_print_xlog.h b/client/tarantool/print_xlog.h
similarity index 100%
rename from client/tarantool/tc_print_xlog.h
rename to client/tarantool/print_xlog.h
diff --git a/client/tarantool/tc_query.c b/client/tarantool/query.c
similarity index 74%
rename from client/tarantool/tc_query.c
rename to client/tarantool/query.c
index 2da1ee9b4e..610c2fdf27 100644
--- a/client/tarantool/tc_query.c
+++ b/client/tarantool/query.c
@@ -1,3 +1,4 @@
+
 /*
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -25,31 +26,44 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdint.h>
+*/
+
+#include <lib/tarantool.h>
 
 #include <include/errcode.h>
+#include <client/tarantool/opt.h>
+#include <client/tarantool/main.h>
+#include <client/tarantool/print.h>
+#include <client/tarantool/query.h>
 
-#if 0
-#include <connector/c/include/tarantool/tnt.h>
-#include <connector/c/include/tarantool/tnt_net.h>
-#include <connector/c/include/tarantool/tnt_sql.h>
-#include <connector/c/include/tarantool/tnt_xlog.h>
-#include <connector/c/include/tarantool/tnt_rpl.h>
-#endif
+extern struct tarantool_client tc;
 
-#include "client/tarantool/tc_opt.h"
-#include "client/tarantool/tc_admin.h"
-#include "client/tarantool/tc.h"
-#include "client/tarantool/tc_print.h"
-#include "client/tarantool/tc_query.h"
+int tc_printer(char *reply, size_t size, void *ctx)
+{
+	(void)ctx;
+	(void)size;
+	tc_printf("%s", reply);
+	return 0;
+}
 
-extern struct tc tc;
+int tc_exec(char *q, tc_query_t cb, void *ctx)
+{
+	int rc = tb_conwrite(&tc.admin, q, strlen(q));
+	if (rc == -1)
+		return -1;
+	size_t size;
+	char *reply;
+	rc = tb_conread(&tc.admin, &reply, &size);
+	if (rc == -1)
+		return -1;
+	rc = 0;
+	if (cb && reply)
+		rc = cb(reply, size, ctx);
+	free(reply);
+	return rc;
+}
 
+#if 0
 char *tc_query_error(char *fmt, ...) {
 	char msg[256];
 	va_list args;
@@ -62,7 +76,6 @@ char *tc_query_error(char *fmt, ...) {
 	return ptr;
 }
 
-#if 0
 char *tc_query_type(uint32_t type) {
 	switch (type) {
 	case TNT_OP_PING:   return "Ping";
@@ -134,32 +147,3 @@ int tc_query(char *q, char **e) {
 }
 #endif
 
-int tc_query_admin_printer(char *r, char **e) {
-	(void)e;
-	tc_printf("%s", r);
-	return 0;
-}
-
-int tc_query_admin(char *q, tc_query_admin_t cb, char **e)
-{
-	if (tc_admin_query(&tc.admin, q) == -1) {
-		*e = tc_query_error("failed to send admin query");
-		return -1;
-	}
-	if (cb == NULL)
-		return 0;
-	char *reply = NULL;
-	size_t reply_size = 0;
-	if (tc_admin_reply(&tc.admin, &reply, &reply_size) == -1) {
-		*e = tc_query_error("failed to recv admin reply");
-		return -1;
-	}
-	if (cb && reply) {
-		if (cb(reply, e) == -1) {
-			free(reply);
-			return -1;
-		}
-	}
-	free(reply);
-	return 0;
-}
diff --git a/client/tarantool/tc_query.h b/client/tarantool/query.h
similarity index 87%
rename from client/tarantool/tc_query.h
rename to client/tarantool/query.h
index 36dc74ac7a..bafd5792d0 100644
--- a/client/tarantool/tc_query.h
+++ b/client/tarantool/query.h
@@ -29,7 +29,16 @@
  * SUCH DAMAGE.
  */
 
-typedef int (*tc_query_admin_t)(char *r, char **e);
+typedef int (*tc_query_t)(char *reply, size_t size, void *ctx);
+
+int tc_printer(char *r, size_t size, void *ctx);
+int tc_exec(char *q, tc_query_t cb, void *ctx);
+
+static inline int
+tc_query(char *q, void *cb) {
+	return tc_exec(q, (tc_query_t)cb, NULL);
+}
+
 
 #if 0
 typedef int (*tc_query_t)(struct tnt_reply *r, void *ptr, char **e);
@@ -39,14 +48,11 @@ char *tc_query_type(uint32_t type);
 int tc_query_printer(struct tnt_reply *r, void *ptr, char **e);
 int tc_query_foreach(tc_query_t cb, void *cba, char **e);
 int tc_query(char *q, char **e);
-#endif
-
-int tc_query_admin_printer(char *r, char **e);
-int tc_query_admin(char *q, tc_query_admin_t cb, char **e);
 
 struct tnt_reply;
 
 char *tc_query_error(char *fmt, ...);
 char *tc_query_op(struct tnt_reply *r);
+#endif
 
 #endif /* TC_QUERY_H_INCLUDED */
diff --git a/client/tarantool/tc_store.c b/client/tarantool/store.c
similarity index 100%
rename from client/tarantool/tc_store.c
rename to client/tarantool/store.c
diff --git a/client/tarantool/tc_store.h b/client/tarantool/store.h
similarity index 100%
rename from client/tarantool/tc_store.h
rename to client/tarantool/store.h
diff --git a/client/tarantool/tc.c b/client/tarantool/tc.c
deleted file mode 100644
index 779c042682..0000000000
--- a/client/tarantool/tc.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdint.h>
-#include <locale.h>
-
-#include <unistd.h>
-
-#if 0
-#include <connector/c/include/tarantool/tnt.h>
-#include <connector/c/include/tarantool/tnt_net.h>
-#include <connector/c/include/tarantool/tnt_sql.h>
-#include <connector/c/include/tarantool/tnt_iter.h>
-#include <connector/c/include/tarantool/tnt_xlog.h>
-#endif
-
-#include "client/tarantool/tc_opt.h"
-#include "client/tarantool/tc_admin.h"
-#include "client/tarantool/tc.h"
-#include "client/tarantool/tc_pager.h"
-#include "client/tarantool/tc_cli.h"
-#include "client/tarantool/tc_print.h"
-/*#include "client/tarantool/tc_store.h"*/
-#include "client/tarantool/tc_query.h"
-/*#include "client/tarantool/tc_print_snap.h"*/
-/*#include "client/tarantool/tc_print_xlog.h"*/
-
-#define TC_DEFAULT_PORT 33013
-#define TC_DEFAULT_PORT 33013
-#define TC_ERR_CMD "---\nunknown command. try typing help.\n...\n"
-
-struct tc tc;
-
-static void tc_init(void) {
-	memset(&tc, 0, sizeof(tc));
-	setlocale(LC_ALL, "");
-	tc.pager_fd = fileno(stdout);
-	tc.pager_pid = 0;
-}
-
-static void tc_free(void) {
-	/*
-	if (tc.net) {
-		tnt_stream_free(tc.net);
-	}
-	*/
-	tc_admin_close(&tc.admin);
-	/*
-	tc_cmd_tee_close();
-	*/
-	tc_pager_kill();
-}
-
-void tc_error(char *fmt, ...) {
-	char msg[256];
-	va_list args;
-	tc_free();
-	/* - - - - */
-	va_start(args, fmt);
-	vsnprintf(msg, sizeof(msg), fmt, args);
-	va_end(args);
-	tc_printf("error: %s\n", msg);
-	exit(1);
-}
-
-#if 0
-static int get_admin_port(void)
-{
-	char *e = NULL;
-	tc_query("call box.dostring('return box.cfg.admin_port')", &e);
-	struct tnt_iter i, it, ifl;
-	tnt_iter_reply(&i, tc.net);
-	struct tnt_reply *r = TNT_IREPLY_PTR(&i);
-	if (!tnt_next(&i)) {
-		tnt_iter_free(&i);
-	}
-	if (tnt_error(tc.net) != TNT_EOK) {
-		tc_error(tc_query_error("%s ERROR, %s",
-				tc_query_op(r),
-				tnt_strerror(tc.net)));
-	} else if (r->code != 0) {
-		tc_error(tc_query_error("%s ERROR, %s (%s)",
-				tc_query_op(r), ((r->error) ? r->error : ""),
-				tnt_strerror(tc.net)));
-	}
-	tnt_iter_list(&it, TNT_REPLY_LIST(r));
-	if (!tnt_next(&it)) {
-		tnt_iter_free(&it);
-		tnt_iter_free(&i);
-	}
-	struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it);
-	tnt_iter(&ifl, tu);
-	if (!tnt_next(&ifl)) { goto end; }
-	int port = *((uint32_t* )TNT_IFIELD_DATA(&ifl));
-end:
-	tnt_iter_free(&ifl);
-	tnt_iter_free(&it);
-	tnt_iter_free(&i);
-	if (e != NULL)
-		free(e);
-	return port;
-}
-
-static void tc_connect(void)
-{
-	if (tc.opt.port == 0)
-		tc.opt.port = TC_DEFAULT_PORT;
-	/* allocating stream */
-	tc.net = tnt_net(NULL);
-	if (tc.net == NULL)
-		tc_error("stream allocation error");
-	/* initializing network stream */
-	tnt_set(tc.net, TNT_OPT_HOSTNAME, tc.opt.host);
-	tnt_set(tc.net, TNT_OPT_PORT, tc.opt.port);
-	tnt_set(tc.net, TNT_OPT_SEND_BUF, 0);
-	tnt_set(tc.net, TNT_OPT_RECV_BUF, 0);
-	if (tnt_init(tc.net) == -1)
-		tc_error("%s", tnt_strerror(tc.net));
-	/* connecting to server */
-	if (tnt_connect(tc.net) == -1)
-		tc_error("%s", tnt_strerror(tc.net));
-	if (tc.opt.port_admin == 0)
-		tc.opt.port_admin = get_admin_port();
-}
-#endif
-
-#if 0
-static char *send_cmd(char *cmd)
-{
-	size_t size = 0;
-	char *reply = NULL;
-	if (tc_admin_query(&tc.admin, cmd) == -1)
-		tc_error("cannot send query");
-	if (tc_admin_reply(&tc.admin, &reply, &size) == -1)
-		tc_error("cannot recv query");
-	if (strncmp(reply, TC_ERR_CMD, size) == 0) {
-		free(reply);
-		return NULL;
-	}
-	return reply;
-}
-
-static int get_primary_port()
-{
-	int port = 0;
-	char *reply = send_cmd("box.cfg.primary_port");
-	if (reply == NULL)
-		reply = send_cmd("lua box.cfg.primary_port");
-	if (reply != NULL) {
-		sscanf(reply, "---\n - %d\n...", &port);
-		free(reply);
-	}
-	return port;
-}
-#endif
-
-static void tc_connect_admin(void)
-{
-	tc.opt.port_admin = 33015;
-	if (tc_admin_connect(&tc.admin,
-			     tc.opt.host,
-			     tc.opt.port_admin) == -1)
-		tc_error("admin console connection failed");
-#if 0
-	if (tc.opt.port == 0)
-		tc.opt.port = get_primary_port();
-#endif
-}
-
-#if 0
-static void tc_connect_both(void)
-{
-	if (!tc.opt.port && tc.opt.port_admin) {
-		tc_connect_admin();
-		tc_connect();
-	} else {
-		tc_connect();
-		tc_connect_admin();
-	}
-}
-
-static void tc_validate(void)
-{
-	tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format);
-	tc.opt.snap_printer = tc_print_getsnapcb(tc.opt.format);
-	if (tc.opt.xlog_printer == NULL)
-		tc_error("unsupported output xlog format '%s'",
-				tc.opt.format);
-	if (tc.opt.snap_printer == NULL)
-		tc_error("unsupported output snap format '%s'",
-				tc.opt.format);
-	if (tc.opt.format && strcmp(tc.opt.format, "raw") == 0)
-		tc.opt.raw = 1;
-}
-#endif
-
-int main(int argc, char *argv[], char *envp[])
-{
-	tc_init();
-
-	int rc = 0;
-	enum tc_opt_mode mode = tc_opt_init(&tc.opt, argc, argv, envp);
-	/*tc_validate();*/
-	switch (mode) {
-	case TC_OPT_USAGE:
-		tc_opt_usage();
-		break;
-	case TC_OPT_VERSION:
-		tc_opt_version();
-		break;
-#if 0
-	case TC_OPT_RPL:
-		tc_connect();
-		rc = tc_store_remote();
-		break;
-	case TC_OPT_WAL_CAT:
-		rc = tc_store_cat();
-		break;
-	case TC_OPT_WAL_PLAY:
-		tc_connect();
-		rc = tc_store_play();
-		break;
-#endif
-	case TC_OPT_CMD:
-		tc_connect_admin();
-		rc = tc_cli_cmdv();
-		break;
-	case TC_OPT_INTERACTIVE:
-		tc_connect_admin();
-		tc_cli_motd();
-		rc = tc_cli();
-		break;
-	}
-
-	tc_free();
-	return rc;
-}
diff --git a/client/tarantool/tc_admin.c b/client/tarantool/tc_admin.c
deleted file mode 100644
index 8d57564e3a..0000000000
--- a/client/tarantool/tc_admin.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "client/tarantool/tc_admin.h"
-
-int tc_admin_connect(struct tc_admin *a, const char *host, int port)
-{
-	a->host = host;
-	a->port = port;
-	a->fd = socket(AF_INET, SOCK_STREAM, 0);
-	if (a->fd < 0)
-		return -1;
-	int opt = 1;
-	if (setsockopt(a->fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)) == -1)
-		goto error;
-	struct sockaddr_in addr;
-	memset(&addr, 0, sizeof(addr));
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(a->port);
-	struct hostent *he = gethostbyname(a->host);
-	if (he)
-		memcpy(&addr.sin_addr, (void*)(he->h_addr), he->h_length);
-	else 
-		goto error;
-	if (connect(a->fd, (struct sockaddr*)&addr, sizeof(addr)) == -1)
-		goto error;
-	return 0;
-error:
-	close(a->fd);
-	return -1;
-}
-
-int tc_admin_reconnect(struct tc_admin *a)
-{
-	tc_admin_close(a);
-	return tc_admin_connect(a, a->host, a->port);
-}
-
-void tc_admin_close(struct tc_admin *a)
-{
-	if (a->fd > 0)
-		close(a->fd);
-	a->fd = 0;
-}
-
-int tc_admin_query(struct tc_admin *a, char *q)
-{
-	size_t total = 0;
-	int count = 2;
-	struct iovec v[2];
-	struct iovec *vp = v;
-	v[0].iov_base = q;
-	v[0].iov_len = strlen(q);
-	v[1].iov_base = "\n";
-	v[1].iov_len = 1;
-	while (count > 0)
-	{
-		ssize_t r;
-		do {
-			r = writev(a->fd, vp, count);
-		} while (r == -1 && (errno == EINTR));
-		if (r <= 0)
-			return -1;
-		total += r;
-		while (count > 0) {
-			if (vp->iov_len > (size_t)r) {
-				vp->iov_base += r;
-				vp->iov_len -= r;
-				break;
-			} else {
-				r -= vp->iov_len;
-				vp++;
-				count--;
-			}
-		}
-	}
-	return 0;
-}
-
-int tc_admin_reply(struct tc_admin *a, char **r, size_t *size)
-{
-	char *buf = NULL;
-	size_t off = 0;
-	while (1) {
-		char rx[8096];
-		ssize_t rxi = recv(a->fd, rx, sizeof(rx), 0);
-		if (rxi <= 0)
-			break;
-		char *bufn = (char *)realloc(buf, off + rxi + 1);
-		if (bufn == NULL) {
-			free(buf);
-			break;
-		}
-		buf = bufn;
-		memcpy(buf + off, rx, rxi);
-		off += rxi;
-		buf[off] = 0;
-
-		int is_complete =
-		 (off >= 6 && !memcmp(buf, "---", 3)) &&
-		 ((!memcmp(buf + off - 3, "...", 3)) ||
-		  (off >= 7 && !memcmp(buf + off - 4, "...\n", 4))   ||
-		  (off >= 7 && !memcmp(buf + off - 4, "...\r", 4))   ||
-		  (off >= 8 && !memcmp(buf + off - 5, "...\r\n", 5)) ||
-		  (off >= 8 && !memcmp(buf + off - 5, "...\n\n", 5)));
-
-		if (is_complete) {
-			*r = buf;
-			*size = off;
-			return 0;
-		}
-	}
-	if (buf)
-		free(buf);
-	return -1;
-}
diff --git a/client/tarantool/tc_pager.c b/client/tarantool/tc_pager.c
deleted file mode 100644
index a97b50dc00..0000000000
--- a/client/tarantool/tc_pager.c
+++ /dev/null
@@ -1,60 +0,0 @@
-#include <errno.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "client/tarantool/tc_opt.h"
-#include "client/tarantool/tc_admin.h"
-#include "client/tarantool/tc.h"
-#include "client/tarantool/tc_pager.h"
-
-extern struct tc tc;
-
-void tc_pager_start() {
-	if (tc.pager_pid != 0)
-		tc_pager_kill();
-	if (tc.opt.pager == NULL) {
-		tc.pager_fd = fileno(stdout);
-		return;
-	}
-	int pipefd[2];
-	const char *const argv[] = {"/bin/sh", "-c", tc.opt.pager, NULL};
-
-	if (pipe(pipefd) < 0)
-		tc_error("Failed to open pipe. Errno: %s", strerror(errno));
-	pid_t pid = fork();
-	if (pid < 0) {
-		tc_error("Failed to fork. Errno: %s", strerror(errno));
-	} else if (pid == 0) {
-		close(pipefd[1]);
-		dup2(pipefd[0], STDIN_FILENO);
-		execve(argv[0], (char * const*)argv, (char * const*)tc.opt.envp);
-		tc_error("Can't start pager! Errno: %s", strerror(errno));
-	} else {
-		close(pipefd[0]);
-		tc.pager_fd = pipefd[1];
-		tc.pager_pid = pid;
-	}
-	return;
-}
-
-void tc_pager_stop () {
-	if (tc.pager_pid != 0) {
-		close(tc.pager_fd);
-		tc.pager_fd = fileno(stdout);
-		waitpid(tc.pager_pid, NULL, 0);
-		tc.pager_pid = 0;
-	}
-	return;
-}
-
-void tc_pager_kill () {
-	if (tc.pager_pid != 0) {
-		kill(tc.pager_pid, SIGTERM);
-		tc_pager_stop();
-	}
-}
diff --git a/connector/c/CMakeLists.txt b/connector/c/CMakeLists.txt
index d2e18d8dbd..c1e75e90e5 100644
--- a/connector/c/CMakeLists.txt
+++ b/connector/c/CMakeLists.txt
@@ -2,16 +2,18 @@
 #
 # library soname version
 #
-set(LIBTNT_VERSION_MAJOR "1")
-set(LIBTNT_VERSION_MINOR "1")
+#set(LIBTNT_VERSION_MAJOR "1")
+#set(LIBTNT_VERSION_MINOR "1")
 
-set(LIBTNT_VERSION   "${LIBTNT_VERSION_MAJOR}.${LIBTNT_VERSION_MINOR}")
-set(LIBTNT_SOVERSION "${LIBTNT_VERSION_MAJOR}")
+#set(LIBTNT_VERSION   "${LIBTNT_VERSION_MAJOR}.${LIBTNT_VERSION_MINOR}")
+#set(LIBTNT_SOVERSION "${LIBTNT_VERSION_MAJOR}")
 
-include_directories("${PROJECT_SOURCE_DIR}/connector/c/include")
+#include_directories("${PROJECT_SOURCE_DIR}/connector/c/include")
 
-add_subdirectory(tnt)
-add_subdirectory(tntsql)
-add_subdirectory(tntnet)
-add_subdirectory(tntrpl)
-add_subdirectory(include)
+#add_subdirectory(tnt)
+#add_subdirectory(tntsql)
+#add_subdirectory(tntnet)
+#add_subdirectory(tntrpl)
+#add_subdirectory(include)
+
+add_subdirectory(tb)
diff --git a/connector/c/tb b/connector/c/tb
new file mode 160000
index 0000000000..a7744d2835
--- /dev/null
+++ b/connector/c/tb
@@ -0,0 +1 @@
+Subproject commit a7744d2835fec707f40ade45ff807b47627aaf35
-- 
GitLab