AmendHub

Download:

jcs

/

subtext

/

amendments

/

12

telnet: Don't listen or do idle loop if config telnet port is 0


jcs made amendment 12 over 2 years ago
--- main.c Fri Dec 3 17:34:34 2021 +++ main.c Mon Dec 6 09:45:14 2021 @@ -29,6 +29,7 @@ MenuHandle file_menu; short quitting = 0; struct console *cur_console = NULL; struct db *db; +short mainResFile; void handle_menu(long menu_id); void update_menu(void); @@ -43,10 +44,13 @@ main(void) GrafPtr old_port; AppFile finder_file; short event_in, n, finder_action, finder_count; + char *dbpath; char key; uthread_init(); + mainResFile = CurMap; + InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent, 0); @@ -74,7 +78,9 @@ main(void) GetAppFiles(1, &finder_file); ClrAppFiles(1); finder_count = 0; - db = db_open(&finder_file); + getpath(finder_file.vRefNum, finder_file.fName, &dbpath, 1); + db = db_open(dbpath); + free(dbpath); } else db = db_open(NULL); @@ -82,11 +88,15 @@ main(void) ExitToShell(); cur_console = console_init(); - telnet_init(); + if (db->config.telnet_port) + telnet_init(); while (!quitting) { - telnet_idle(); + if (db->config.telnet_port) + telnet_idle(); + uthread_coordinate(); + WaitNextEvent(everyEvent, &event, 1, 0); switch (event.what) { --- telnet.c Tue Nov 30 20:49:46 2021 +++ telnet.c Mon Dec 6 09:44:44 2021 @@ -18,6 +18,7 @@ #include <string.h> #include "session.h" +#include "subtext.h" #include "telnet.h" #include "tcp.h" #include "util.h" @@ -59,14 +60,15 @@ telnet_init(void) { struct telnet_node *node; short error, i; + ip_port port = db->config.telnet_port; + if (!port) + return; + if (_TCPInit() != 0) err(1, "Failed initializing MacTCP"); _atexit(telnet_atexit); - - /* TODO: get from resource */ - telnet_local_port = 23; for (i = 0; i < TELNET_SLOTS; i++) { node = &telnet_nodes[i]; @@ -84,9 +86,10 @@ telnet_init(void) err(1, "TCPCreate[%d] failed: %d", i, error); error = _TCPPassiveOpen(&node->listen_pb, node->stream, nil, nil, - nil, (ip_port *)&telnet_local_port, nil, nil, true); + nil, &port, nil, nil, true); if (error) - err(1, "TCPPassiveOpen[%d] failed: %d", i, error); + err(1, "TCPPassiveOpen[%d] on port %d failed: %d", i, port, + error); node->state = TELNET_PB_STATE_LISTENING; } }