+ {
+ /*
+ * Re-escape control chars in the command, for logging.
+ */
+ char *reescaped = snewn(4*strlen(formatted_cmd) + 1, char);
+ const char *in;
+ char *out;
+ char *logmsg;
+
+ for (in = formatted_cmd, out = reescaped; *in; in++) {
+ if (*in == '\n') {
+ *out++ = '\\'; *out++ = 'n';
+ } else if (*in == '\r') {
+ *out++ = '\\'; *out++ = 'r';
+ } else if (*in == '\t') {
+ *out++ = '\\'; *out++ = 't';
+ } else if (*in == '\\') {
+ *out++ = '\\'; *out++ = '\\';
+ } else if ((unsigned)(((unsigned char)*in) - 0x20) <
+ (0x7F-0x20)) {
+ *out++ = *in;
+ } else {
+ out += sprintf(out, "\\x%02X", (unsigned)*in & 0xFF);
+ }
+ }
+ *out = '\0';
+
+ logmsg = dupprintf("Sending Telnet proxy command: %s", reescaped);
+ plug_log(p->plug, 2, NULL, 0, logmsg, 0);
+ sfree(logmsg);
+ sfree(reescaped);
+ }
+