/** * @copyright * Copyright (c) 1993-2024 Paul Mattes. * Copyright (c) 1990, Jeff Sparkes. * Copyright (c) 1989, Georgia Tech Research Corporation (GTRC), Atlanta, GA * 30332. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 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. * * Neither the names of Paul Mattes, Jeff Sparkes, GTRC nor the names of * their contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY PAUL MATTES, JEFF SPARKES AND GTRC "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 PAUL MATTES, JEFF SPARKES OR GTRC 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. */ /** * @file x3270.c * @par A 3270 Terminal Emulator for X11 * Main procedure. */ #include "globals.h" #include #include #include #include #include #include #include #include "appres.h" #include "3270ds.h" #include "resources.h" #include "actions.h" #include "bind-opt.h" #include "boolstr.h" #include "codepage.h" #include "ctlrc.h" #include "ft.h" #include "host.h" #include "httpd-core.h" #include "httpd-nodes.h" #include "httpd-io.h" #include "idle.h" #include "keymap.h" #include "kybd.h" #include "lazya.h" #include "login_macro.h" #include "min_version.h" #include "model.h" #include "nvt.h" #include "opts.h" #include "popups.h" #include "pr3287_session.h" #include "prefer.h" #include "print_screen.h" #include "print_window.h" #include "product.h" #include "proxy_toggle.h" #include "query.h" #include "resolver.h" #include "resourcesc.h" #include "save_restore.h" #include "screen.h" #include "selectc.h" #include "sio.h" #include "sio_glue.h" #include "status.h" #include "task.h" #include "telnet.h" #include "toggles.h" #include "trace.h" #include "screentrace.h" #include "utils.h" #include "vstatus.h" #include "xactions.h" #include "xappres.h" #include "xglobals.h" #include "xio.h" #include "xkybd.h" #include "xmenubar.h" #include "xpopups.h" #include "xsave.h" #include "xscreen.h" #include "xscroll.h" #include "xselectc.h" #include "xstatus.h" /* Globals */ const char *programname; Display *display; int default_screen; Window root_window; int screen_depth; Widget toplevel; XtAppContext appcontext; Atom a_delete_me, a_save_yourself, a_3270, a_registry, a_encoding, a_state, a_net_wm_state, a_net_wm_state_maximized_horz, a_net_wm_state_maximized_vert, a_net_wm_name, a_atom, a_spacing, a_pixel_size, a_font; char full_model_name[13] = "IBM-"; char *model_name = &full_model_name[4]; Pixmap gray; XrmDatabase rdb; AppRes appres; xappres_t xappres; bool exiting = false; char *user_title = NULL; /* Statics */ static void peek_at_xevent(XEvent *); static XtErrorMsgHandler old_emh; static void trap_colormaps(String, String, String, String, String *, Cardinal *); static bool colormap_failure = false; #if defined(LOCAL_PROCESS) /*[*/ static void parse_local_process(int *argcp, char **argv, char **cmds); #endif /*]*/ static int parse_model_number(char *m); #if defined(DEBUG_SET_CLEAR) /*[*/ static void dump_argv(const char *, int, char **); #endif /*]*/ static void parse_set_clear(int *, char **); static void label_init(void); static void sigchld_handler(int); static char *user_icon_name = NULL; static void copy_xres_to_res_bool(void); XrmOptionDescRec base_options[]= { { OptActiveIcon, DotActiveIcon, XrmoptionNoArg, ResTrue }, { OptAplMode, DotAplMode, XrmoptionNoArg, ResTrue }, { OptAcceptHostname,DotAcceptHostname,XrmoptionSepArg, NULL }, { OptCaDir, DotCaDir, XrmoptionSepArg, NULL }, { OptCaFile, DotCaFile, XrmoptionSepArg, NULL }, { OptCertFile, DotCertFile, XrmoptionSepArg, NULL }, { OptCertFileType, DotCertFileType,XrmoptionSepArg, NULL }, { OptChainFile, DotChainFile, XrmoptionSepArg, NULL }, { OptCharClass, DotCharClass, XrmoptionSepArg, NULL }, { OptCharset, DotCodePage, XrmoptionSepArg, NULL }, { OptClear, ".xxx", XrmoptionSkipArg, NULL }, { OptClientCert, DotClientCert, XrmoptionSepArg, NULL }, { OptCodePage, DotCodePage, XrmoptionSepArg, NULL }, { OptColorScheme, DotColorScheme, XrmoptionSepArg, NULL }, { OptConnectTimeout,DotConnectTimeout,XrmoptionSepArg, NULL }, { OptDevName, DotDevName, XrmoptionSepArg, NULL }, { OptTrace, DotTrace, XrmoptionNoArg, ResTrue }, #if defined(LOCAL_PROCESS) /*[*/ { OptLocalProcess, NULL, XrmoptionSkipLine, NULL }, #endif /*]*/ { OptEmulatorFont, DotEmulatorFont,XrmoptionSepArg, NULL }, { OptHostsFile, DotHostsFile, XrmoptionSepArg, NULL }, { OptHttpd, DotHttpd, XrmoptionSepArg, NULL }, { OptIconName, ".iconName", XrmoptionSepArg, NULL }, { OptIconX, ".iconX", XrmoptionSepArg, NULL }, { OptIconY, ".iconY", XrmoptionSepArg, NULL }, { OptKeyFile, DotKeyFile, XrmoptionSepArg, NULL }, { OptKeyFileType, DotKeyFileType, XrmoptionSepArg, NULL }, { OptKeymap, DotKeymap, XrmoptionSepArg, NULL }, { OptKeypadOn, DotKeypadOn, XrmoptionNoArg, ResTrue }, { OptKeyPasswd, DotKeyPasswd, XrmoptionSepArg, NULL }, { OptLoginMacro, DotLoginMacro, XrmoptionSepArg, NULL }, { OptTlsMaxProtocol,DotTlsMaxProtocol,XrmoptionSepArg, NULL }, { OptTlsMinProtocol,DotTlsMinProtocol,XrmoptionSepArg, NULL }, { OptMinVersion, DotMinVersion, XrmoptionSepArg, NULL }, { OptModel, DotModel, XrmoptionSepArg, NULL }, { OptMono, DotMono, XrmoptionNoArg, ResTrue }, { OptNoScrollBar, DotScrollBar, XrmoptionNoArg, ResFalse }, { OptNoVerifyHostCert,DotVerifyHostCert,XrmoptionNoArg, ResFalse }, { OptNvtMode, DotNvtMode, XrmoptionNoArg, ResTrue }, { OptOnce, DotOnce, XrmoptionNoArg, ResTrue }, { OptOversize, DotOversize, XrmoptionSepArg, NULL }, { OptPort, DotPort, XrmoptionSepArg, NULL }, { OptPreferIpv4, DotPreferIpv4, XrmoptionNoArg, ResTrue }, { OptPreferIpv6, DotPreferIpv6, XrmoptionNoArg, ResTrue }, { OptPrinterLu, DotPrinterLu, XrmoptionSepArg, NULL }, { OptProxy, DotProxy, XrmoptionSepArg, NULL }, { OptReconnect, DotReconnect, XrmoptionNoArg, ResTrue }, { OptSaveLines, DotSaveLines, XrmoptionSepArg, NULL }, { OptScripted, DotScripted, XrmoptionNoArg, ResTrue }, { OptScrollBar, DotScrollBar, XrmoptionNoArg, ResTrue }, { OptSecure, DotSecure, XrmoptionNoArg, ResTrue }, { OptSet, ".xxx", XrmoptionSkipArg, NULL }, { OptSocket, DotSocket, XrmoptionNoArg, ResTrue }, { OptScriptPort, DotScriptPort, XrmoptionSepArg, NULL }, { OptScriptPortOnce,DotScriptPortOnce,XrmoptionNoArg, ResTrue }, { OptTermName, DotTermName, XrmoptionSepArg, NULL }, { OptTraceFile, DotTraceFile, XrmoptionSepArg, NULL }, { OptTraceFileSize, DotTraceFileSize,XrmoptionSepArg, NULL }, { OptInputMethod, DotInputMethod, XrmoptionSepArg, NULL }, { OptPreeditType, DotPreeditType, XrmoptionSepArg, NULL }, { OptUser, DotUser, XrmoptionSepArg, NULL }, { OptUtf8, DotUtf8, XrmoptionNoArg, ResTrue }, { OptVerifyHostCert,DotVerifyHostCert,XrmoptionNoArg, ResTrue }, { OptXrm, NULL, XrmoptionResArg, NULL } }; int num_base_options = XtNumber(base_options); XrmOptionDescRec *options; int num_options; /**< number of options */ /** Option help. */ static struct option_help { char *opt; /**< option name */ char *args; /**< arguments or NULL */ char *help; /**< help text */ unsigned tls_flag; /**< flags for conditional TLS options */ } option_help[] = { { OptAcceptHostname, "[DNS:]", "Host name to accept from server certificate", TLS_OPT_ACCEPT_HOSTNAME }, { OptActiveIcon, NULL, "Make icon a miniature of the display" }, { OptAplMode, NULL, "Turn on APL mode" }, { OptCaDir, "", "TLS CA certificate database directory", TLS_OPT_CA_DIR }, { OptCaFile, "", "TLS CA certificate file", TLS_OPT_CA_FILE }, { OptCertFile, "", "TLS certificate file", TLS_OPT_CERT_FILE }, { OptCertFileType, "pem|asn1", "TLS certificate file type", TLS_OPT_CERT_FILE_TYPE }, { OptChainFile, "", "TLS certificate chain file", TLS_OPT_CHAIN_FILE }, { OptCharClass, "", "Define characters for word boundaries" }, { OptCharset, "", "Alias for " OptCodePage }, { OptClear, "", "Turn on " }, { OptClientCert, "", "TLS client certificate name", TLS_OPT_CLIENT_CERT }, { OptCodePage, "", "Use host EBCDIC code page " }, { OptColorScheme, "", "Use color scheme " }, { OptConnectTimeout, "", "Timeout for host connect requests" }, { OptDevName, "", "Device name (workstation ID)" }, #if defined(LOCAL_PROCESS) /*[*/ { OptLocalProcess, " [arg...]", "Run process instead of connecting to host" }, #endif /*]*/ { OptEmulatorFont, "", "Font for emulator window" }, { OptHttpd, "[:]", "TCP port to listen on for http requests" }, { OptHostsFile, "", "Pathname of ibm_hosts file" }, { OptIconName, "", "Title for icon" }, { OptIconX, "", "X position for icon" }, { OptIconY, "", "Y position for icon" }, { OptKeyFile, "", "Get TLS private key from ", TLS_OPT_KEY_FILE }, { OptKeyFileType, "pem|asn1", "TLS private key file type", TLS_OPT_KEY_FILE_TYPE }, { OptKeymap, "[,...]", "Keyboard map name(s)" }, { OptKeypadOn, NULL, "Turn on pop-up keypad at start-up" }, { OptKeyPasswd, "file:|string:", "TLS private key password", TLS_OPT_KEY_PASSWD }, { OptLoginMacro, "Action([arg[,...]]) [...]", "Macro to run at login" }, { OptMinVersion, "", "Fail unless at this version or greater" }, { OptModel, "[327{8,9}-]", "Emulate a 3278 or 3279 model " }, { OptMono, NULL, "Do not use color" }, { OptNoScrollBar, NULL, "Disable scroll bar" }, { OptNoVerifyHostCert, NULL, "Do not verify TLS host certificate", TLS_OPT_VERIFY_HOST_CERT }, { OptNvtMode, NULL, "Begin in NVT mode" }, { OptOnce, NULL, "Exit as soon as the host disconnects" }, { OptOversize, "x", "Larger screen dimensions" }, { OptPort, "", "Default TELNET port" }, { OptPreferIpv4, NULL, "Prefer IPv4 host addresses" }, { OptPreferIpv6, NULL, "Prefer IPv6 host addresses" }, { OptPrinterLu, "", "Automatically start a pr3287 printer session to " }, { OptProxy, ":[:]", "Secify proxy type and server" }, { OptReconnect, NULL, "Reconnect to host as soon as it disconnects" }, { OptSaveLines, "", "Number of lines to save for scroll bar" }, { OptScripted, NULL, "Accept commands on standard input" }, { OptScrollBar, NULL, "Turn on scroll bar" }, { OptSet, "", "Turn on " }, { OptSocket, NULL, "Create socket for script control" }, { OptScriptPort, "", "Listen on TCP port for script connections" }, { OptScriptPortOnce, NULL, "Accept one script connection, then exit" }, { OptSecure, NULL, "Set secure mode" }, { OptTermName, "", "Send as TELNET terminal name" }, { OptTlsMaxProtocol, "", "TLS maximum protocol version" }, { OptTlsMinProtocol, "", "TLS minimum protocol version" }, { OptTrace, NULL, "Enable tracing" }, { OptTraceFile, "", "Write traces to " }, { OptTraceFileSize, "[KM]", "Limit trace file to bytes" }, { OptInputMethod, "", "Multi-byte input method" }, { OptPreeditType, "