summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-02 17:25:29 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-06 13:06:22 +0000
commit52f6e4e7c59ab3fddac779278dd90796569a857f (patch)
treec1661cb0555cf9050e32223753d56247b6d5901b /testing
parenta3a0e553f3f06cf97d58347901fd478db81d571b (diff)
Move tox_shell program to the toxins repository.
https://github.com/TokTok/toxins/tree/master/tox_shell
Diffstat (limited to 'testing')
-rw-r--r--testing/BUILD.bazel10
-rw-r--r--testing/Makefile.inc21
-rw-r--r--testing/tox_shell.c161
3 files changed, 0 insertions, 192 deletions
diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel
index 1413acc9..ca354998 100644
--- a/testing/BUILD.bazel
+++ b/testing/BUILD.bazel
@@ -42,13 +42,3 @@ cc_binary(
42 "@sndfile", 42 "@sndfile",
43 ], 43 ],
44) 44)
45
46cc_binary(
47 name = "tox_shell",
48 srcs = ["tox_shell.c"],
49 linkopts = ["-lutil"],
50 deps = [
51 ":misc_tools",
52 "//c-toxcore/toxcore",
53 ],
54)
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index 7d5b41e7..f4ed568c 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -32,27 +32,6 @@ Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \
32 $(WINSOCK2_LIBS) 32 $(WINSOCK2_LIBS)
33 33
34 34
35
36if !WIN32
37
38noinst_PROGRAMS += tox_shell
39
40tox_shell_SOURCES = ../testing/tox_shell.c
41
42tox_shell_CFLAGS = $(LIBSODIUM_CFLAGS) \
43 $(NACL_CFLAGS)
44
45tox_shell_LDADD = $(LIBSODIUM_LDFLAGS) \
46 $(NACL_LDFLAGS) \
47 libtoxcore.la \
48 $(LIBSODIUM_LIBS) \
49 $(NACL_OBJECTS) \
50 $(NACL_LIBS) \
51 -lutil
52
53
54endif
55
56EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c 35EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c
57 36
58endif 37endif
diff --git a/testing/tox_shell.c b/testing/tox_shell.c
deleted file mode 100644
index d0f38e24..00000000
--- a/testing/tox_shell.c
+++ /dev/null
@@ -1,161 +0,0 @@
1/* Tox Shell
2 *
3 * Proof of concept ssh like server software using tox.
4 *
5 * Command line arguments are the ip, port and public_key of a node (for bootstrapping).
6 *
7 * EX: ./test 127.0.0.1 33445 CDCFD319CE3460824B33BE58FD86B8941C9585181D8FBD7C79C5721D7C2E9F7C
8 */
9
10/*
11 * Copyright © 2016-2017 The TokTok team.
12 * Copyright © 2014 Tox project.
13 *
14 * This file is part of Tox, the free peer to peer instant messenger.
15 *
16 * Tox is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * Tox is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
28 */
29#define _XOPEN_SOURCE 600
30
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include "../toxcore/tox.h"
36#include "misc_tools.c"
37
38#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
39#include <util.h>
40#elif defined(__FreeBSD__) || defined(__DragonFly__)
41#include <libutil.h>
42#else
43#include <pty.h>
44#endif
45#include <fcntl.h>
46
47static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata)
48{
49 if (status) {
50 printf("\nOther went online.\n");
51 } else {
52 printf("\nOther went offline.\n");
53 }
54}
55
56static void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length,
57 void *userdata)
58{
59 int master = *((int *)userdata);
60 write(master, string, length);
61 write(master, "\n", 1);
62}
63
64int main(int argc, char *argv[])
65{
66 uint8_t ipv6enabled = 1; /* x */
67 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
68
69 if (argvoffset < 0) {
70 exit(1);
71 }
72
73 /* with optional --ipvx, now it can be 1-4 arguments... */
74 if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) {
75 printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]);
76 exit(0);
77 }
78
79 int *master = (int *)malloc(sizeof(int));
80 int ret = forkpty(master, nullptr, nullptr, nullptr);
81
82 if (ret == -1) {
83 printf("fork failed\n");
84 free(master);
85 return 1;
86 }
87
88 if (ret == 0) {
89 execl("/bin/sh", "sh", nullptr);
90 return 0;
91 }
92
93 int flags = fcntl(*master, F_GETFL, 0);
94 int r = fcntl(*master, F_SETFL, flags | O_NONBLOCK);
95
96 if (r < 0) {
97 printf("error setting flags\n");
98 }
99
100 Tox *tox = tox_new(0, 0);
101 tox_callback_friend_connection_status(tox, print_online);
102 tox_callback_friend_message(tox, print_message);
103
104
105 uint16_t port = atoi(argv[argvoffset + 2]);
106 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
107 int res = tox_bootstrap(tox, argv[argvoffset + 1], port, binary_string, 0);
108 free(binary_string);
109
110 if (!res) {
111 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
112 exit(1);
113 }
114
115 uint8_t address[TOX_ADDRESS_SIZE];
116 tox_self_get_address(tox, address);
117 uint32_t i;
118
119 for (i = 0; i < TOX_ADDRESS_SIZE; i++) {
120 printf("%02X", address[i]);
121 }
122
123 char temp_id[128];
124 printf("\nEnter the address of the other id you want to sync with (38 bytes HEX format):\n");
125
126 if (scanf("%s", temp_id) != 1) {
127 return 1;
128 }
129
130 uint8_t *bin_id = hex_string_to_bin(temp_id);
131 uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0);
132 free(bin_id);
133
134 if (num == UINT32_MAX) {
135 printf("\nSomething went wrong when adding friend.\n");
136 return 1;
137 }
138
139 uint8_t notconnected = 1;
140
141 while (1) {
142 if (tox_self_get_connection_status(tox) && notconnected) {
143 printf("\nDHT connected.\n");
144 notconnected = 0;
145 }
146
147 while (tox_friend_get_connection_status(tox, num, 0)) {
148 uint8_t buf[TOX_MAX_MESSAGE_LENGTH];
149 ret = read(*master, buf, sizeof(buf));
150
151 if (ret <= 0) {
152 break;
153 }
154
155 tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0);
156 }
157
158 tox_iterate(tox, master);
159 c_sleep(1);
160 }
161}