Skip to content

Commit

Permalink
Wasn't parsing preamble correctly - was using int not uint8_t
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlaszcz committed Dec 31, 2021
1 parent 04ba9ca commit 29d758f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 30 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Several variations are available but the following is recommended:
<https://galax.xyz/TELETEXT/MODE7GX3.TTF>

## Installation
wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-1.0.0.tar.gz"
tar xvf vidtex-1.0.0.tar.gz
cd vidtex-1.0.0
wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-1.1.0.tar.gz"
tar xvf vidtex-1.1.0.tar.gz
cd vidtex-1.1.0
./configure
sudo make install

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([vidtex], [1.0.0])
AC_INIT([vidtex], [1.1.0])
AX_WITH_CURSES
AC_ARG_WITH([ncursesw], AC_MSG_ERROR([ncursesw not installed]))
AC_CONFIG_SRCDIR([src/main.c])
Expand Down
Binary file added releases/vidtex-1.1.0.tar.gz
Binary file not shown.
1 change: 0 additions & 1 deletion src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ vt_trace(struct vt_decoder_state *state, char *format, ...)
}
}


static void
vt_cursor(struct vt_decoder_state *state)
{
Expand Down
58 changes: 46 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <inttypes.h>
#include <locale.h>
#include <ncursesw/curses.h>
#include <netdb.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
Expand All @@ -25,6 +27,12 @@ const char *sys_conf_dir = SYSCONFDIR;
const char *sys_conf_dir = NULL;
#endif

#ifdef VERSION
const char *version = VERSION;
#else
const char *version = "0.0.0";
#endif

#define vt_perror() fprintf(stderr, \
"Error: %s (%d)\n\tat %s line %d\n", strerror(errno), errno, __FILE__, __LINE__)
#define vt_is_ctrl(x) ((x) & 0x1F)
Expand All @@ -33,16 +41,15 @@ const char *sys_conf_dir = NULL;
#define BUFFER_LEN 1024
#define MAX_AMBLE_LEN 10
#define POLL_PERIOD_MS -1
#define VERSION "1.0.0"

struct vt_rc_entry
{
char *name;
char *host;
char *port;
int preamble[MAX_AMBLE_LEN];
uint8_t preamble[MAX_AMBLE_LEN];
int preamble_length;
int postamble[MAX_AMBLE_LEN];
uint8_t postamble[MAX_AMBLE_LEN];
int postamble_length;
};

Expand All @@ -66,14 +73,15 @@ static void vt_terminate(int signal);
static void vt_cleanup(struct vt_session_state *session);
static int vt_get_rc(const char *dir, struct vt_rc_entry ***rc_data, int *rc_data_count);
static char *vt_duplicate_token(char *token);
static int vt_scan_array(char *token, int buffer[]);
static int vt_scan_array(char *token, uint8_t buffer[]);
static void vt_free_rc(struct vt_rc_entry *rc_data[], int rc_data_count);
static int vt_parse_options(int argc, char *argv[], struct vt_session_state *session);
static struct vt_rc_entry *vt_show_rc_menu(struct vt_rc_entry **rc_data, int rc_data_count);
static int vt_connect(struct vt_session_state *session);
static bool vt_is_valid_fd(int fd);
static int vt_transform_input(int ch);
static void vt_usage();
static void vt_trace(struct vt_session_state *session, char *format, ...);

volatile sig_atomic_t terminate_received = false;
volatile sig_atomic_t socket_closed = false;
Expand Down Expand Up @@ -295,8 +303,8 @@ vt_cleanup(struct vt_session_state *session)
endwin();

if (session->socket_fd > -1) {
int default_buffer[4] = {'*', '9', '0', '_'};
int *buffer = default_buffer;
uint8_t default_buffer[4] = {'*', '9', '0', '_'};
uint8_t *buffer = default_buffer;
int len = 4;

if (session->selected_rc != NULL && session->selected_rc->postamble_length > 0) {
Expand All @@ -306,6 +314,12 @@ vt_cleanup(struct vt_session_state *session)

// If write fails it was closed by the host first
if (write(session->socket_fd, buffer, len) == len) {
vt_trace(session, "postamble: ");
for (int i = 0; i < len; ++i) {
vt_trace(session, "%d '%c' ", buffer[i], buffer[i]);
}
vt_trace(session, "\n");

if (shutdown(session->socket_fd, SHUT_RDWR) == -1) {
vt_perror();
}
Expand Down Expand Up @@ -498,9 +512,10 @@ vt_duplicate_token(char *token)
}

static int
vt_scan_array(char *token, int buffer[])
vt_scan_array(char *token, uint8_t buffer[])
{
int count = sscanf(token, "%d %d %d %d %d %d %d %d %d %d",
int count = sscanf(token,
"%"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8,
&buffer[0], &buffer[1], &buffer[2], &buffer[3], &buffer[4],
&buffer[5], &buffer[6], &buffer[7], &buffer[8], &buffer[9]);

Expand Down Expand Up @@ -691,14 +706,16 @@ vt_connect(struct vt_session_state *session)
goto abend;
}

int preamble[MAX_AMBLE_LEN + 1] = {0};
uint8_t preamble[MAX_AMBLE_LEN + 1] = {0};
preamble[0] = 22;
int preamble_len = 1;

if (session->selected_rc != NULL && session->selected_rc->preamble_length > 0) {
int n = sizeof(int) * session->selected_rc->preamble_length;
memcpy(&preamble[1], session->selected_rc->preamble, n);
preamble_len += session->selected_rc->preamble_length;

for (int i = 0; i < session->selected_rc->preamble_length; ++i) {
preamble[i + 1] = session->selected_rc->preamble[i];
}
}

int sz = write(session->socket_fd, preamble, preamble_len);
Expand All @@ -713,6 +730,12 @@ vt_connect(struct vt_session_state *session)
goto abend;
}

vt_trace(session, "preamble: ");
for (int i = 0; i < preamble_len; ++i) {
vt_trace(session, "%d '%c' ", preamble[i], preamble[i]);
}
vt_trace(session, "\n");

return EXIT_SUCCESS;

abend:
Expand Down Expand Up @@ -743,7 +766,7 @@ vt_transform_input(int ch)
static void
vt_usage()
{
fprintf(stderr, "Version: %s\n", VERSION);
fprintf(stderr, "Version: %s\n", version);
fprintf(stderr, "SYSCONFDIR=%s\n", sys_conf_dir);
fprintf(stderr, "Usage: vidtex [options]\nOptions:\n");
fprintf(stderr, "%-16s\tOutput bold brighter colours\n", "--bold");
Expand All @@ -756,3 +779,14 @@ vt_usage()
fprintf(stderr, "%-16s\tViewdata service host port\n", "--port number");
fprintf(stderr, "%-16s\tWrite trace to file\n", "--trace filename");
}

static void
vt_trace(struct vt_session_state *session, char *format, ...)
{
if (session->decoder_state.trace_file != NULL) {
va_list args;
va_start(args, format);
vfprintf(session->decoder_state.trace_file, format, args);
va_end(args);
}
}
4 changes: 2 additions & 2 deletions src/vidtex.1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Use 'whereis vidtex' to locate vidtexrc. Typically it will exist at /usr/local/e
.PP
The program will also look in the user's HOME directory and the current working directory (in that order) for vidtexrc files. All will be read and when displaying the menu, all entries will be listed.
.PP
Service hosts are listed one per line in the file. Lines may be commented by placing a '#' at the start of the line. Fields are tab delimited and are as follows:
Service hosts are listed one per line in the file. Lines may be commented by placing a '#' at the start of the line. Fields are delimited by either tab, ',' or '|' and are as follows:
.TP
\fBDisplay name
.TP
Expand All @@ -109,7 +109,7 @@ Service hosts are listed one per line in the file. Lines may be commented by pla
\fBPort number
.TP
\fBPreamble (optional)
Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on connection.
Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on connection. If there is no preamble but there is postamble, use a space for preamble.
.TP
\fBPostamble (optional)
Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on termination. Typically this might be the standard Viewdata logoff sequence of '*90#', although note that '#' should be translated to '_' so in effect this would be '*90_'.
Expand Down
22 changes: 11 additions & 11 deletions src/vidtexrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#name host port preamble postamble
ccl4 fish.ccl4.org 23 42 81 81
nxtel nx.nxtel.org 23280
teefax pegasus.matrixnetwork.co.uk 6502 70 70 70
telstar-fast-1 glasstty.com 6502 255 253 3 42 57 48 95 95
telstar-fast-2 glasstty.com 6503 255 253 3 42 57 48 95 95
telstar-slow-1 glasstty.com 6502 42 57 48 95 95
telstar-slow-2 glasstty.com 6503 42 57 48 95 95
prestel demo viewdata.org.uk 6522
linkline demo viewdata.org.uk 6854
#name,host,port,preamble,postamble
ccl4,fish.ccl4.org,23, ,42 81 81
nxtel,nx.nxtel.org,23280
teefax,pegasus.matrixnetwork.co.uk,6502, ,70 70 70
telstar-fast-1,glasstty.com,6502,255 253 3,42 57 48 95 95
telstar-fast-2,glasstty.com,6503,255 253 3,42 57 48 95 95
telstar-slow-1,glasstty.com,6502, ,42 57 48 95 95
telstar-slow-2,glasstty.com,6503, ,42 57 48 95 95
prestel demo,viewdata.org.uk,6522
linkline demo,viewdata.org.uk,6854
#offline for a long time
ringworld rw1.m63.co.uk 23
ringworld,rw1.m63.co.uk,23

0 comments on commit 29d758f

Please sign in to comment.