git ssb

8+

cel / sbotc



Commit bb26631cfb2893ba5b7e37a305b6fa550cad6444

Add -r raw input mode

cel committed on 12/16/2018, 9:27:37 PM
Parent: d8bc88f9016da527bf5ba572320ad7c9556d053d

Files changed

README.mdchanged
sbotc.1changed
sbotc.cchanged
README.mdView
@@ -15,9 +15,9 @@
1515
1616 ## Usage
1717
1818 ```sh
19-sbotc [-j] [-T] [-l]
19 +sbotc [-j] [-T] [-l] [-r]
2020 [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]
2121 [ [-s <host>] [-p <port>] [ -4 | -6 ] | [-u <socket_path>] ]
2222 [ -a | [-t <type>] <method> [<argument>...] ]
2323 ```
sbotc.1View
@@ -47,8 +47,10 @@
4747 .It Fl j
4848 Send stdin data as JSON.
4949 .It Fl l
5050 Don't output newlines after string or JSON packets.
51 +.It Fl r
52 +Raw mode. Disables stdin line buffering/editing and echoing.
5153 .It Fl T
5254 Test using shs1-testsuite protocol. Instead of connecting to a server and running
5355 a command, connect to stdio. On successful handshake, output concatenation of
5456 the encryption key, encryption nonce, decryption key and decryption nonce.
sbotc.cView
@@ -24,8 +24,9 @@
2424 #include <sys/select.h>
2525 #include <sys/socket.h>
2626 #include <sys/stat.h>
2727 #include <sys/un.h>
28 +#include <termios.h>
2829 #include <unistd.h>
2930
3031 #include <sodium.h>
3132
@@ -103,9 +104,9 @@
103104 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
104105 };
105106
106107 static void usage() {
107- fputs("usage: sbotc [-j] [-T] [-l]\n"
108 + fputs("usage: sbotc [-j] [-T] [-l] [-r]\n"
108109 " [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]\n"
109110 " [ [-s <host>] [-p <port>] [ -4 | -6 ] | [-u <socket_path>] ]\n"
110111 " [ -a | [-t <type>] <method> [<argument>...] ]\n", stderr);
111112 exit(EXIT_FAILURE);
@@ -856,18 +857,18 @@
856857 return in == stream_state_ended_ok && out == stream_state_ended_ok ? 0 :
857858 in == stream_state_ended_error || out == stream_state_ended_error ? 2 : 1;
858859 }
859860
860-static int muxrpc_duplex(struct boxs *bs, int infd, int outfd, enum pkt_type in_ptype, int req_id, bool no_newline) {
861 +static int muxrpc_duplex(struct boxs *bs, int infd, int outfd, enum pkt_type in_ptype, int req_id, bool no_newline, bool raw) {
861862 int rc;
862863 fd_set rd;
863864 int sfd = bs->s;
864865 int maxfd = infd > sfd ? infd : sfd;
865866 enum stream_state in = stream_state_open;
866867 enum stream_state out = stream_state_open;
867868
868869 while (out == stream_state_open
869- || (in == stream_state_open && out != stream_state_ended_error)) {
870 + || (!raw && in == stream_state_open && out != stream_state_ended_error)) {
870871 FD_ZERO(&rd);
871872 if (in == stream_state_open) FD_SET(infd, &rd);
872873 if (out == stream_state_open) FD_SET(sfd, &rd);
873874 rc = select(maxfd + 1, &rd, 0, 0, NULL);
@@ -956,8 +957,9 @@
956957 ssize_t len;
957958 bool test = false;
958959 bool noauth = false;
959960 bool no_newline = false;
961 + bool raw = false;
960962 bool host_arg = false;
961963 bool port_arg = false;
962964 bool key_arg = false;
963965 bool shs_cap_key_str_arg = false;
@@ -998,8 +1000,9 @@
9981000 case '4': ipv4_arg = true; break;
9991001 case '6': ipv6_arg = true; break;
10001002 case 'a': passthrough = true; break;
10011003 case 'l': no_newline = true; break;
1004 + case 'r': raw = true; break;
10021005 default: usage();
10031006 }
10041007 }
10051008 if (i < argc) methodstr = argv[i++];
@@ -1133,8 +1136,19 @@
11331136 }
11341137
11351138 muxrpc_call(&bs, method, argument, type, typestr, 1);
11361139
1140 + struct termios orig_tc;
1141 + if (raw) {
1142 + struct termios raw_tc;
1143 + rc = tcgetattr(STDIN_FILENO, &orig_tc);
1144 + if (rc < 0) warnx("tcgetattr");
1145 + raw_tc = orig_tc;
1146 + raw_tc.c_lflag &= ~(ICANON | ECHO);
1147 + rc = tcsetattr(STDIN_FILENO, TCSANOW, &raw_tc);
1148 + if (rc < 0) warnx("tcgetattr");
1149 + }
1150 +
11371151 switch (type) {
11381152 case muxrpc_type_async:
11391153 rc = muxrpc_read_async(&bs, STDOUT_FILENO, 1, no_newline);
11401154 break;
@@ -1148,12 +1162,17 @@
11481162 rc = muxrpc_write_sink(&bs, STDIN_FILENO, ptype, 1, no_newline);
11491163 }
11501164 break;
11511165 case muxrpc_type_duplex:
1152- rc = muxrpc_duplex(&bs, STDIN_FILENO, STDOUT_FILENO, ptype, 1, no_newline);
1166 + rc = muxrpc_duplex(&bs, STDIN_FILENO, STDOUT_FILENO, ptype, 1, no_newline, raw);
11531167 break;
11541168 }
11551169
1170 + if (raw) {
1171 + rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc);
1172 + if (rc < 0) warnx("tcsetattr");
1173 + }
1174 +
11561175 bs_end(&bs);
11571176 close(s);
11581177 return rc;
11591178 }

Built with git-ssb-web