- if (!*cfg.host) {
- char *q = p;
- /*
- * If the hostname starts with "telnet:", set the
- * protocol to Telnet and process the string as a
- * Telnet URL.
- */
- if (!strncmp(q, "telnet:", 7)) {
- char c;
-
- q += 7;
- if (q[0] == '/' && q[1] == '/')
- q += 2;
- cfg.protocol = PROT_TELNET;
- p = q;
- while (*p && *p != ':' && *p != '/') p++;
- c = *p;
- if (*p)
- *p++ = '\0';
- if (c == ':')
- cfg.port = atoi(p);
- else
- cfg.port = -1;
- strncpy (cfg.host, q, sizeof(cfg.host)-1);
- cfg.host[sizeof(cfg.host)-1] = '\0';
- } else {
- char *r;
- /*
- * Before we process the [user@]host string, we
- * first check for the presence of a protocol
- * prefix (a protocol name followed by ",").
- */
- r = strchr(p, ',');
- if (r) {
- int i, j;
- for (i = 0; backends[i].backend != NULL; i++) {
- j = strlen(backends[i].name);
- if (j == r-p &&
- !memcmp(backends[i].name, p, j)) {
- default_protocol = cfg.protocol = backends[i].protocol;
- portnumber = backends[i].backend->default_port;
- p = r+1;
- break;
- }
- }
- }
-
- /*
- * Three cases. Either (a) there's a nonzero
- * length string followed by an @, in which
- * case that's user and the remainder is host.
- * Or (b) there's only one string, not counting
- * a potential initial @, and it exists in the
- * saved-sessions database. Or (c) only one
- * string and it _doesn't_ exist in the
- * database.
- */
- r = strrchr(p, '@');
- if (r == p) p++, r = NULL; /* discount initial @ */
- if (r == NULL) {
- /*
- * One string.
- */
- Config cfg2;
- do_defaults (p, &cfg2);
- if (cfg2.host[0] == '\0') {
- /* No settings for this host; use defaults */
- strncpy(cfg.host, p, sizeof(cfg.host)-1);
- cfg.host[sizeof(cfg.host)-1] = '\0';
- cfg.port = default_port;
- } else {
- cfg = cfg2;
- cfg.remote_cmd_ptr = cfg.remote_cmd;
- }
- } else {
- *r++ = '\0';
- strncpy(cfg.username, p, sizeof(cfg.username)-1);
- cfg.username[sizeof(cfg.username)-1] = '\0';
- strncpy(cfg.host, r, sizeof(cfg.host)-1);
- cfg.host[sizeof(cfg.host)-1] = '\0';
- cfg.port = default_port;
- }
- }
- } else {
- int len = sizeof(cfg.remote_cmd) - 1;
- char *cp = cfg.remote_cmd;
- int len2;
-
- strncpy(cp, p, len); cp[len] = '\0';
- len2 = strlen(cp); len -= len2; cp += len2;
- while (--argc) {
- if (len > 0)
- len--, *cp++ = ' ';
- strncpy(cp, *++argv, len); cp[len] = '\0';
- len2 = strlen(cp); len -= len2; cp += len2;
- }
- cfg.nopty = TRUE; /* command => no terminal */
- break; /* done with cmdline */
- }
+ if (!*cfg.host) {
+ char *q = p;
+ /*
+ * If the hostname starts with "telnet:", set the
+ * protocol to Telnet and process the string as a
+ * Telnet URL.
+ */
+ if (!strncmp(q, "telnet:", 7)) {
+ char c;
+
+ q += 7;
+ if (q[0] == '/' && q[1] == '/')
+ q += 2;
+ cfg.protocol = PROT_TELNET;
+ p = q;
+ while (*p && *p != ':' && *p != '/')
+ p++;
+ c = *p;
+ if (*p)
+ *p++ = '\0';
+ if (c == ':')
+ cfg.port = atoi(p);
+ else
+ cfg.port = -1;
+ strncpy(cfg.host, q, sizeof(cfg.host) - 1);
+ cfg.host[sizeof(cfg.host) - 1] = '\0';
+ } else {
+ char *r;
+ /*
+ * Before we process the [user@]host string, we
+ * first check for the presence of a protocol
+ * prefix (a protocol name followed by ",").
+ */
+ r = strchr(p, ',');
+ if (r) {
+ int i, j;
+ for (i = 0; backends[i].backend != NULL; i++) {
+ j = strlen(backends[i].name);
+ if (j == r - p &&
+ !memcmp(backends[i].name, p, j)) {
+ default_protocol = cfg.protocol =
+ backends[i].protocol;
+ portnumber =
+ backends[i].backend->default_port;
+ p = r + 1;
+ break;
+ }
+ }
+ }
+
+ /*
+ * Three cases. Either (a) there's a nonzero
+ * length string followed by an @, in which
+ * case that's user and the remainder is host.
+ * Or (b) there's only one string, not counting
+ * a potential initial @, and it exists in the
+ * saved-sessions database. Or (c) only one
+ * string and it _doesn't_ exist in the
+ * database.
+ */
+ r = strrchr(p, '@');
+ if (r == p)
+ p++, r = NULL; /* discount initial @ */
+ if (r == NULL) {
+ /*
+ * One string.
+ */
+ Config cfg2;
+ do_defaults(p, &cfg2);
+ if (cfg2.host[0] == '\0') {
+ /* No settings for this host; use defaults */
+ strncpy(cfg.host, p, sizeof(cfg.host) - 1);
+ cfg.host[sizeof(cfg.host) - 1] = '\0';
+ cfg.port = default_port;
+ } else {
+ cfg = cfg2;
+ cfg.remote_cmd_ptr = cfg.remote_cmd;
+ }
+ } else {
+ *r++ = '\0';
+ strncpy(cfg.username, p, sizeof(cfg.username) - 1);
+ cfg.username[sizeof(cfg.username) - 1] = '\0';
+ strncpy(cfg.host, r, sizeof(cfg.host) - 1);
+ cfg.host[sizeof(cfg.host) - 1] = '\0';
+ cfg.port = default_port;
+ }
+ }
+ } else {
+ int len = sizeof(cfg.remote_cmd) - 1;
+ char *cp = cfg.remote_cmd;
+ int len2;
+
+ strncpy(cp, p, len);
+ cp[len] = '\0';
+ len2 = strlen(cp);
+ len -= len2;
+ cp += len2;
+ while (--argc) {
+ if (len > 0)
+ len--, *cp++ = ' ';
+ strncpy(cp, *++argv, len);
+ cp[len] = '\0';
+ len2 = strlen(cp);
+ len -= len2;
+ cp += len2;
+ }
+ cfg.nopty = TRUE; /* command => no terminal */
+ break; /* done with cmdline */
+ }