+
+int term_ldisc(int option) {
+ if (option == LD_ECHO) return term_echoing;
+ if (option == LD_EDIT) return term_editing;
+ return FALSE;
+}
+
+/*
+ * from_backend(), to get data from the backend for the terminal.
+ */
+void from_backend(int is_stderr, char *data, int len) {
+ while (len--) {
+ if (inbuf_head >= INBUF_SIZE)
+ term_out();
+ inbuf[inbuf_head++] = *data++;
+ }
+}
+
+/*
+ * Log session traffic.
+ */
+void logtraffic(unsigned char c, int logmode) {
+ if (cfg.logtype > 0) {
+ if (cfg.logtype == logmode) {
+ /* deferred open file from pgm start? */
+ if (!lgfp) logfopen();
+ if (lgfp) fputc (c, lgfp);
+ }
+ }
+}
+
+/* open log file append/overwrite mode */
+void logfopen(void) {
+ char buf[256];
+ time_t t;
+ struct tm *tm;
+ char writemod[4];
+
+ if (!cfg.logtype)
+ return;
+ sprintf (writemod, "wb"); /* default to rewrite */
+ lgfp = fopen(cfg.logfilename, "r"); /* file already present? */
+ if (lgfp) {
+ int i;
+ fclose(lgfp);
+ i = askappend(cfg.logfilename);
+ if (i == 1)
+ writemod[0] = 'a'; /* set append mode */
+ else if (i == 0) { /* cancelled */
+ lgfp = NULL;
+ cfg.logtype = 0; /* disable logging */
+ return;
+ }
+ }
+
+ lgfp = fopen(cfg.logfilename, writemod);
+ if (lgfp) { /* enter into event log */
+ sprintf(buf, "%s session log (%s mode) to file : ",
+ (writemod[0] == 'a') ? "Appending" : "Writing new",
+ (cfg.logtype == LGTYP_ASCII ? "ASCII" :
+ cfg.logtype == LGTYP_DEBUG ? "raw" : "<ukwn>") );
+ /* Make sure we do not exceed the output buffer size */
+ strncat (buf, cfg.logfilename, 128);
+ buf[strlen(buf)] = '\0';
+ logevent(buf);
+
+ /* --- write header line iinto log file */
+ fputs ("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", lgfp);
+ time(&t);
+ tm = localtime(&t);
+ strftime(buf, 24, "%Y.%m.%d %H:%M:%S", tm);
+ fputs (buf, lgfp);
+ fputs (" =~=~=~=~=~=~=~=~=~=~=~=\r\n", lgfp);
+ }
+}
+
+void logfclose (void) {
+ if (lgfp) { fclose(lgfp); lgfp = NULL; }
+}