Changed timers for session setup

This commit is contained in:
Michiel Broek 2003-08-23 18:27:02 +00:00
parent f85535ff11
commit d90c04b69b
2 changed files with 291 additions and 278 deletions

View File

@ -118,7 +118,6 @@ int inbound_close(int success)
sprintf(source, "%s/%s", tempinbound, de->d_name);
sprintf(dest, "%s/%s", inbound, de->d_name);
if ((lstat(source, &stb) == 0) && (S_ISREG(stb.st_mode))) {
Syslog('s', "Regular file");
if (file_exist(dest, F_OK) == 0) {
Syslog('!', "Cannot move %s to %s, file exists", de->d_name, inbound);
} else {
@ -129,8 +128,6 @@ int inbound_close(int success)
gotfiles = TRUE;
}
}
} else {
Syslog('s', "Not a regular file");
}
}
@ -144,7 +141,10 @@ int inbound_close(int success)
*/
if ((rc = rmdir(tempinbound))) {
WriteError("Can't remove %s: %s", tempinbound, strerror(rc));
} else {
Syslog('s', "Removed %s", tempinbound);
}
free(tempinbound);
tempinbound = NULL;

View File

@ -89,11 +89,6 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
type = tp;
nlent = nl;
if (role)
Syslog('+', "Start outbound %s session with %s", typestr(type), ascfnode(a,0x1f));
else
Syslog('+', "Start inbound %s session", typestr(type));
if (getpeername(0,(struct sockaddr*)&peeraddr,&addrlen) == 0) {
Syslog('s', "TCP connection: len=%d, family=%hd, port=%hu, addr=%s",
addrlen,peeraddr.sin_family, peeraddr.sin_port, inet_ntoa(peeraddr.sin_addr));
@ -147,6 +142,7 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
if (role) {
if (type == SESSION_UNKNOWN)
(void)tx_define_type();
Syslog('+', "Start outbound %s session with %s", typestr(type), ascfnode(a,0x1f));
switch(type) {
case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break;
case SESSION_FTSC: rc = tx_ftsc(); break;
@ -159,6 +155,7 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
session_flags |= FTSC_XMODEM_CRC;
if (type == SESSION_UNKNOWN)
(void)rx_define_type();
Syslog('+', "Start inbound %s session", typestr(type));
switch(type) {
case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break;
case SESSION_FTSC: rc = rx_ftsc(); break;
@ -214,28 +211,29 @@ SM_NAMES
(char *)"checkintro",
(char *)"sendinq"
SM_EDECL
int c=0;
int count=0;
char buf[256],*p;
char ebuf[13],*ep;
int standby=0;
int c = 0;
char buf[256], *p;
char ebuf[13], *ep;
int standby = 0;
int maybeftsc=0;
int maybeyoohoo=0;
type=SESSION_UNKNOWN;
ebuf[0]='\0';
ep=ebuf;
buf[0]='\0';
p=buf;
type = SESSION_UNKNOWN;
ebuf[0] = '\0';
ep = ebuf;
buf[0] = '\0';
p = buf;
SM_START(skipjunk)
SM_STATE(skipjunk)
Syslog('S', "tx_define_type SKIPJUNK");
Syslog('s', "tx_define_type SKIPJUNK");
while ((c = GETCHAR(1)) >= 0) /*nothing*/ ;
if (c == TIMEOUT) {
RESETTIMERS();
SETTIMER(0, 60); /* 60 second master timer */
SM_PROCEED(wake);
} else {
SM_ERROR;
@ -243,13 +241,13 @@ SM_STATE(skipjunk)
SM_STATE(wake)
Syslog('S', "tx_define_type WAKE");
if (count++ > 20) {
Syslog('s', "tx_define_type WAKE");
if (EXPIRED(0)) {
Syslog('+', "Remote did not respond");
SM_ERROR;
}
p=buf;
p = buf;
PUTCHAR('\r');
if ((c = GETCHAR(2)) == TIMEOUT) {
SM_PROCEED(wake);
@ -257,19 +255,19 @@ SM_STATE(wake)
WriteError("Error while waking remote");
SM_ERROR;
} else {
count = 0;
SETTIMER(0, 60);
Syslog('S', "Got %c wakeup", c);
SM_PROCEED(nextchar);
}
SM_STATE(waitchar)
Syslog('S', "tx_define_type WAITCHAR");
if ((c = GETCHAR(2)) == TIMEOUT) { /* Was 4 seconds */
Syslog('s', "tx_define_type WAITCHAR");
if ((c = GETCHAR(2)) == TIMEOUT) {
standby = 0;
ep = ebuf;
ebuf[0] = '\0';
if (count++ > 30) { /* Was 8 loops */
if (EXPIRED(0)) {
Syslog('+', "Too many tries waking remote");
SM_ERROR;
}
@ -283,7 +281,6 @@ SM_STATE(waitchar)
SM_STATE(nextchar)
Syslog('S', "tx_define_type NEXTCHAR");
if (c == 'C') {
session_flags |= FTSC_XMODEM_CRC;
maybeftsc++;
@ -329,7 +326,8 @@ SM_STATE(nextchar)
SM_PROCEED(checkintro);
}
}
} else switch (c) {
} else {
switch (c) {
case DC1: break;
case '\r':
case '\n': standby = 0;
@ -346,12 +344,12 @@ SM_STATE(nextchar)
Syslog('i', "Got '%s' reading intro", printablec(c));
break;
}
}
SM_PROCEED(waitchar);
SM_STATE(checkintro)
Syslog('S', "tx_define_type CHECKINTRO");
Syslog('s', "tx_define_type CHECKINTRO");
Syslog('i', "Check \"%s\" for being EMSI request",ebuf);
if (((localoptions & NOEMSI) == 0) && (strncasecmp(ebuf,"EMSI_REQA77E",12) == 0)) {
@ -368,11 +366,11 @@ SM_STATE(checkintro)
SM_STATE(sendinq)
Syslog('S', "tx_define_type SENDINQ");
Syslog('s', "tx_define_type SENDINQ");
PUTCHAR(DC1);
if ((localoptions & NOEMSI) == 0) {
Syslog('S', "send **EMSI_INQC816 (2 times)");
PUTSTR((char *)"\r**EMSI_INQC816**EMSI_INQC816");
PUTSTR((char *)"\r**EMSI_INQC816\r**EMSI_INQC816");
}
if ((localoptions & NOWAZOO) == 0) {
Syslog('S', "send YOOHOO char");
@ -415,14 +413,16 @@ SM_EDECL
session_flags|=FTSC_XMODEM_CRC;
ebuf[0]='\0';
ep=ebuf;
Syslog('S', "rxdefine_type INIT");
RESETTIMERS();
SETTIMER(0, 60);
Syslog('s', "rxdefine_type INIT");
SM_START(sendintro)
SM_STATE(sendintro)
Syslog('S', "rxdefine_type SENDINTRO");
if (count++ > 6) { /* Was 16, is 6 according to the EMSI spec */
Syslog('s', "rxdefine_type SENDINTRO");
if (count++ > 6) {
Syslog('+', "Too many tries to get anything from the caller");
SM_ERROR;
}
@ -455,8 +455,14 @@ SM_STATE(sendintro)
SM_STATE(waitchar)
Syslog('S', "rxdefine_type WAITCHAR");
if ((c=GETCHAR(20)) == TIMEOUT) { /* Timeout was 8, must be 20. */
Syslog('s', "rxdefine_type WAITCHAR");
if (EXPIRED(0)) {
Syslog('+', "Timeout session handshake with the caller");
SM_ERROR;
}
if ((c = GETCHAR(20)) == TIMEOUT) {
SM_PROCEED(sendintro);
} else if (c < 0) {
Syslog('+', "EMSI error while getting from caller");
@ -467,7 +473,7 @@ SM_STATE(waitchar)
SM_STATE(nextchar)
Syslog('S', "rxdefine_type NEXTCHAR");
Syslog('s', "rxdefine_type NEXTCHAR");
if ((c >= ' ') && (c <= 'z')) {
if (c == '*') {
standby = 1;
@ -484,7 +490,8 @@ SM_STATE(nextchar)
}
}
SM_PROCEED(waitchar);
} else switch (c) {
} else {
switch (c) {
case DC1: SM_PROCEED(waitchar);
break;
case TSYNC: standby = 0;
@ -497,7 +504,7 @@ SM_STATE(nextchar)
SM_PROCEED(waitchar);
}
break;
case YOOHOO: standby = 0;
case YOOHOO:standby = 0;
ep = ebuf;
ebuf[0] = '\0';
if (++maybeyoohoo > 1) {
@ -524,10 +531,11 @@ SM_STATE(nextchar)
SM_PROCEED(waitchar);
break;
}
}
SM_STATE(checkemsi)
Syslog('S', "rxdefine_type CHECKEMSI");
Syslog('s', "rxdefine_type CHECKEMSI");
Syslog('i', "check \"%s\" for being EMSI inquery or data",ebuf);
if (localoptions & NOEMSI) {
@ -538,6 +546,11 @@ SM_STATE(checkemsi)
type = SESSION_EMSI;
data = xstrcpy((char *)"**EMSI_INQC816");
SM_SUCCESS;
} else if (strncasecmp(ebuf, "EMSI_HBT", 8) == 0) {
standby = 0;
ep = ebuf;
ebuf[0] = '\0';
SM_PROCEED(waitchar);
} else if (strncasecmp(ebuf, "EMSI_DAT", 8) == 0) {
SM_PROCEED(getdat);
} else {
@ -546,7 +559,7 @@ SM_STATE(checkemsi)
SM_STATE(getdat)
Syslog('S', "rxdefine_type GETDAT");
Syslog('s', "rxdefine_type GETDAT");
Syslog('i', "Try get emsi_dat packet starting with \"%s\"",ebuf);
if (sscanf(ebuf+8, "%04x", &datasize) != 1) {