Commit d7b1f25e authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Send a "banner" when accepting incoming connections.

Fix a corner case where an invalid command-mode escape sequence (e.g. "+.+.+") could've been interpreted as valid.
parent 198ef67f
...@@ -75,6 +75,7 @@ struct { ...@@ -75,6 +75,7 @@ struct {
ulong data_rate; ulong data_rate;
bool server_echo; bool server_echo;
char busy_notice[INI_MAX_VALUE_LEN]; char busy_notice[INI_MAX_VALUE_LEN];
char answer_banner[INI_MAX_VALUE_LEN];
enum { enum {
ADDRESS_FAMILY_UNSPEC ADDRESS_FAMILY_UNSPEC
,ADDRESS_FAMILY_INET ,ADDRESS_FAMILY_INET
...@@ -168,6 +169,8 @@ ulong count_esc(struct modem* modem, uint8_t* buf, size_t rd) ...@@ -168,6 +169,8 @@ ulong count_esc(struct modem* modem, uint8_t* buf, size_t rd)
for(size_t i = 0; i < rd; i++) { for(size_t i = 0; i < rd; i++) {
if(buf[i] == modem->esc) if(buf[i] == modem->esc)
count++; count++;
else
return 0;
} }
return count; return count;
} }
...@@ -699,6 +702,7 @@ char* answer(struct modem* modem) ...@@ -699,6 +702,7 @@ char* answer(struct modem* modem)
/* Will suppress Go Ahead */ /* Will suppress Go Ahead */
request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); request_telnet_opt(TELNET_WILL,TELNET_SUP_GA);
} }
putcom(cfg.answer_banner, strlen(cfg.answer_banner));
return connected(modem); return connected(modem);
} }
...@@ -1000,6 +1004,9 @@ bool read_ini(const char* ini_fname) ...@@ -1000,6 +1004,9 @@ bool read_ini(const char* ini_fname)
const char* p = iniGetString(ini, ROOT_SECTION, "BusyNotice", NULL, value); const char* p = iniGetString(ini, ROOT_SECTION, "BusyNotice", NULL, value);
if(p != NULL) if(p != NULL)
SAFECOPY(cfg.busy_notice, p); SAFECOPY(cfg.busy_notice, p);
p = iniGetString(ini, ROOT_SECTION, "AnswerBanner", NULL, value);
if(p != NULL)
SAFECOPY(cfg.answer_banner, p);
return true; return true;
} }
...@@ -1030,6 +1037,7 @@ int main(int argc, char** argv) ...@@ -1030,6 +1037,7 @@ int main(int argc, char** argv)
cfg.port = IPPORT_TELNET; cfg.port = IPPORT_TELNET;
cfg.address_family = ADDRESS_FAMILY_UNSPEC; cfg.address_family = ADDRESS_FAMILY_UNSPEC;
SAFECOPY(cfg.busy_notice, "\r\nSorry, not available right now\r\n"); SAFECOPY(cfg.busy_notice, "\r\nSorry, not available right now\r\n");
SAFEPRINTF(cfg.answer_banner, "\r\n" TITLE " v" VERSION " Copyright %s Rob Swindell\r\n", &__DATE__[7]);
ini = strListInit(); ini = strListInit();
GetModuleFileName(NULL, ini_fname, sizeof(ini_fname) - 1); GetModuleFileName(NULL, ini_fname, sizeof(ini_fname) - 1);
...@@ -1323,6 +1331,7 @@ int main(int argc, char** argv) ...@@ -1323,6 +1331,7 @@ int main(int argc, char** argv)
if(rd) { if(rd) {
if(modem.online) { if(modem.online) {
if(modem.esc_count) { if(modem.esc_count) {
dprintf("Esc count = %d", modem.esc_count);
if(modem.esc_count >= 3) if(modem.esc_count >= 3)
modem.esc_count = 0; modem.esc_count = 0;
else { else {
...@@ -1333,8 +1342,10 @@ int main(int argc, char** argv) ...@@ -1333,8 +1342,10 @@ int main(int argc, char** argv)
modem.esc_count = 0; modem.esc_count = 0;
} }
} else { } else {
if(now - lasttx > guard_time(&modem)) if(now - lasttx > guard_time(&modem)) {
modem.esc_count = count_esc(&modem, buf, rd); modem.esc_count = count_esc(&modem, buf, rd);
dprintf("New esc count = %d", modem.esc_count);
}
} }
size_t len = rd; size_t len = rd;
uint8_t* p = buf; uint8_t* p = buf;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment