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

View File

@ -89,11 +89,6 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
type = tp; type = tp;
nlent = nl; 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) { if (getpeername(0,(struct sockaddr*)&peeraddr,&addrlen) == 0) {
Syslog('s', "TCP connection: len=%d, family=%hd, port=%hu, addr=%s", Syslog('s', "TCP connection: len=%d, family=%hd, port=%hu, addr=%s",
addrlen,peeraddr.sin_family, peeraddr.sin_port, inet_ntoa(peeraddr.sin_addr)); 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 (role) {
if (type == SESSION_UNKNOWN) if (type == SESSION_UNKNOWN)
(void)tx_define_type(); (void)tx_define_type();
Syslog('+', "Start outbound %s session with %s", typestr(type), ascfnode(a,0x1f));
switch(type) { switch(type) {
case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break; case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break;
case SESSION_FTSC: rc = tx_ftsc(); 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; session_flags |= FTSC_XMODEM_CRC;
if (type == SESSION_UNKNOWN) if (type == SESSION_UNKNOWN)
(void)rx_define_type(); (void)rx_define_type();
Syslog('+', "Start inbound %s session", typestr(type));
switch(type) { switch(type) {
case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break; case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break;
case SESSION_FTSC: rc = rx_ftsc(); break; case SESSION_FTSC: rc = rx_ftsc(); break;
@ -200,189 +197,190 @@ int session(faddr *a, node *nl, int role, int tp, char *dt)
SM_DECL(tx_define_type,(char *)"tx_define_type") SM_DECL(tx_define_type,(char *)"tx_define_type")
SM_STATES SM_STATES
skipjunk, skipjunk,
wake, wake,
waitchar, waitchar,
nextchar, nextchar,
checkintro, checkintro,
sendinq sendinq
SM_NAMES SM_NAMES
(char *)"skipjunk", (char *)"skipjunk",
(char *)"wake", (char *)"wake",
(char *)"waitchar", (char *)"waitchar",
(char *)"nextchar", (char *)"nextchar",
(char *)"checkintro", (char *)"checkintro",
(char *)"sendinq" (char *)"sendinq"
SM_EDECL SM_EDECL
int c=0; int c = 0;
int count=0; char buf[256], *p;
char buf[256],*p; char ebuf[13], *ep;
char ebuf[13],*ep; int standby = 0;
int standby=0;
int maybeftsc=0;
int maybeyoohoo=0;
int maybeftsc=0; type = SESSION_UNKNOWN;
int maybeyoohoo=0; ebuf[0] = '\0';
ep = ebuf;
type=SESSION_UNKNOWN; buf[0] = '\0';
ebuf[0]='\0'; p = buf;
ep=ebuf;
buf[0]='\0';
p=buf;
SM_START(skipjunk) SM_START(skipjunk)
SM_STATE(skipjunk) SM_STATE(skipjunk)
Syslog('S', "tx_define_type SKIPJUNK"); Syslog('s', "tx_define_type SKIPJUNK");
while ((c = GETCHAR(1)) >= 0) /*nothing*/ ; while ((c = GETCHAR(1)) >= 0) /*nothing*/ ;
if (c == TIMEOUT) { if (c == TIMEOUT) {
SM_PROCEED(wake); RESETTIMERS();
} else { SETTIMER(0, 60); /* 60 second master timer */
SM_ERROR; SM_PROCEED(wake);
} } else {
SM_ERROR;
}
SM_STATE(wake) SM_STATE(wake)
Syslog('S', "tx_define_type WAKE"); Syslog('s', "tx_define_type WAKE");
if (count++ > 20) { if (EXPIRED(0)) {
Syslog('+', "Remote did not respond"); Syslog('+', "Remote did not respond");
SM_ERROR; SM_ERROR;
} }
p=buf; p = buf;
PUTCHAR('\r'); PUTCHAR('\r');
if ((c = GETCHAR(2)) == TIMEOUT) { if ((c = GETCHAR(2)) == TIMEOUT) {
SM_PROCEED(wake); SM_PROCEED(wake);
} else if (c < 0) { } else if (c < 0) {
WriteError("Error while waking remote"); WriteError("Error while waking remote");
SM_ERROR; SM_ERROR;
} else { } else {
count = 0; SETTIMER(0, 60);
Syslog('S', "Got %c wakeup", c); Syslog('S', "Got %c wakeup", c);
SM_PROCEED(nextchar); SM_PROCEED(nextchar);
} }
SM_STATE(waitchar) SM_STATE(waitchar)
Syslog('S', "tx_define_type WAITCHAR"); Syslog('s', "tx_define_type WAITCHAR");
if ((c = GETCHAR(2)) == TIMEOUT) { /* Was 4 seconds */ if ((c = GETCHAR(2)) == TIMEOUT) {
standby = 0; standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (count++ > 30) { /* Was 8 loops */ if (EXPIRED(0)) {
Syslog('+', "Too many tries waking remote"); Syslog('+', "Too many tries waking remote");
SM_ERROR; SM_ERROR;
}
SM_PROCEED(sendinq);
} else if (c < 0) {
Syslog('+', "Error while getting intro from remote");
SM_ERROR;
} else {
SM_PROCEED(nextchar);
} }
SM_PROCEED(sendinq);
} else if (c < 0) {
Syslog('+', "Error while getting intro from remote");
SM_ERROR;
} else {
SM_PROCEED(nextchar);
}
SM_STATE(nextchar) SM_STATE(nextchar)
Syslog('S', "tx_define_type NEXTCHAR"); if (c == 'C') {
if (c == 'C') { session_flags |= FTSC_XMODEM_CRC;
session_flags |= FTSC_XMODEM_CRC; maybeftsc++;
maybeftsc++; }
} if (c == NAK) {
if (c == NAK) { session_flags &= ~FTSC_XMODEM_CRC;
session_flags &= ~FTSC_XMODEM_CRC; maybeftsc++;
maybeftsc++; }
} if (c == ENQ)
if (c == ENQ) maybeyoohoo++;
maybeyoohoo++;
if (((localoptions & NOWAZOO) == 0) && (maybeyoohoo > 1)) { if (((localoptions & NOWAZOO) == 0) && (maybeyoohoo > 1)) {
type = SESSION_YOOHOO; type = SESSION_YOOHOO;
SM_SUCCESS; SM_SUCCESS;
}
if (maybeftsc > 1) {
type = SESSION_FTSC;
SM_SUCCESS;
}
if ((c >= ' ') && (c <= '~')) {
if (c != 'C')
maybeftsc = 0;
maybeyoohoo = 0;
if ((p-buf) < (sizeof(buf)-1)) {
*p++ = c;
*p = '\0';
} }
if (maybeftsc > 1) { if (c == '*') {
type = SESSION_FTSC; standby = 1;
SM_SUCCESS; ep = ebuf;
buf[0] = '\0';
} else if (standby) {
if ((ep - ebuf) < (sizeof(ebuf) - 1)) {
*ep++ = c;
*ep = '\0';
}
if ((ep - ebuf) >= (sizeof(ebuf) - 1)) {
standby = 0;
SM_PROCEED(checkintro);
}
} }
} else {
if ((c >= ' ') && (c <= '~')) { switch (c) {
if (c != 'C') case DC1: break;
maybeftsc = 0; case '\r':
maybeyoohoo = 0; case '\n': standby = 0;
if ((p-buf) < (sizeof(buf)-1)) {
*p++ = c;
*p = '\0';
}
if (c == '*') {
standby = 1;
ep = ebuf;
buf[0] = '\0';
} else if (standby) {
if ((ep - ebuf) < (sizeof(ebuf) - 1)) {
*ep++ = c;
*ep = '\0';
}
if ((ep - ebuf) >= (sizeof(ebuf) - 1)) {
standby = 0;
SM_PROCEED(checkintro);
}
}
} else switch (c) {
case DC1: break;
case '\r':
case '\n': standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (buf[0]) if (buf[0])
Syslog('+', "Intro: \"%s\"", printable(buf, 0)); Syslog('+', "Intro: \"%s\"", printable(buf, 0));
p = buf; p = buf;
buf[0] = '\0'; buf[0] = '\0';
break; break;
default: standby = 0; default: standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
Syslog('i', "Got '%s' reading intro", printablec(c)); Syslog('i', "Got '%s' reading intro", printablec(c));
break; break;
} }
}
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
SM_STATE(checkintro) SM_STATE(checkintro)
Syslog('S', "tx_define_type CHECKINTRO"); Syslog('s', "tx_define_type CHECKINTRO");
Syslog('i', "Check \"%s\" for being EMSI request",ebuf); Syslog('i', "Check \"%s\" for being EMSI request",ebuf);
if (((localoptions & NOEMSI) == 0) && (strncasecmp(ebuf,"EMSI_REQA77E",12) == 0)) { if (((localoptions & NOEMSI) == 0) && (strncasecmp(ebuf,"EMSI_REQA77E",12) == 0)) {
type = SESSION_EMSI; type = SESSION_EMSI;
data = xstrcpy((char *)"**EMSI_REQA77E"); data = xstrcpy((char *)"**EMSI_REQA77E");
Syslog('i', "Sending **EMSI_INQC816 (2 times)"); Syslog('i', "Sending **EMSI_INQC816 (2 times)");
PUTSTR((char *)"\r**EMSI_INQC816\r**EMSI_INQC816\r\021"); PUTSTR((char *)"\r**EMSI_INQC816\r**EMSI_INQC816\r\021");
SM_SUCCESS; SM_SUCCESS;
} else { } else {
p = buf; p = buf;
buf[0] = '\0'; buf[0] = '\0';
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
} }
SM_STATE(sendinq) SM_STATE(sendinq)
Syslog('S', "tx_define_type SENDINQ"); Syslog('s', "tx_define_type SENDINQ");
PUTCHAR(DC1); PUTCHAR(DC1);
if ((localoptions & NOEMSI) == 0) { if ((localoptions & NOEMSI) == 0) {
Syslog('S', "send **EMSI_INQC816 (2 times)"); 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) { if ((localoptions & NOWAZOO) == 0) {
Syslog('S', "send YOOHOO char"); Syslog('S', "send YOOHOO char");
PUTCHAR(YOOHOO); PUTCHAR(YOOHOO);
} }
Syslog('S', "send TSYNC char"); Syslog('S', "send TSYNC char");
PUTCHAR(TSYNC); PUTCHAR(TSYNC);
if ((localoptions & NOEMSI) == 0) if ((localoptions & NOEMSI) == 0)
PUTSTR((char *)"\r\021"); PUTSTR((char *)"\r\021");
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
SM_END SM_END
SM_RETURN SM_RETURN
@ -391,186 +389,201 @@ SM_RETURN
SM_DECL(rx_define_type,(char *)"rx_define_type") SM_DECL(rx_define_type,(char *)"rx_define_type")
SM_STATES SM_STATES
sendintro, sendintro,
waitchar, waitchar,
nextchar, nextchar,
checkemsi, checkemsi,
getdat getdat
SM_NAMES SM_NAMES
(char *)"sendintro", (char *)"sendintro",
(char *)"waitchar", (char *)"waitchar",
(char *)"nextchar", (char *)"nextchar",
(char *)"checkemsi", (char *)"checkemsi",
(char *)"getdat" (char *)"getdat"
SM_EDECL SM_EDECL
int count=0; int count=0;
int c=0; int c=0;
int maybeftsc=0,maybeyoohoo=0; int maybeftsc=0,maybeyoohoo=0;
char ebuf[13],*ep; char ebuf[13],*ep;
char *p; char *p;
int standby=0; int standby=0;
int datasize; int datasize;
type=SESSION_UNKNOWN; type=SESSION_UNKNOWN;
session_flags|=FTSC_XMODEM_CRC; session_flags|=FTSC_XMODEM_CRC;
ebuf[0]='\0'; ebuf[0]='\0';
ep=ebuf; ep=ebuf;
Syslog('S', "rxdefine_type INIT"); RESETTIMERS();
SETTIMER(0, 60);
Syslog('s', "rxdefine_type INIT");
SM_START(sendintro) SM_START(sendintro)
SM_STATE(sendintro) SM_STATE(sendintro)
Syslog('S', "rxdefine_type SENDINTRO"); Syslog('s', "rxdefine_type SENDINTRO");
if (count++ > 6) { /* Was 16, is 6 according to the EMSI spec */ if (count++ > 6) {
Syslog('+', "Too many tries to get anything from the caller"); Syslog('+', "Too many tries to get anything from the caller");
SM_ERROR; SM_ERROR;
} }
standby = 0; standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if ((localoptions & NOEMSI) == 0) { if ((localoptions & NOEMSI) == 0) {
PUTSTR((char *)"**EMSI_REQA77E\r\021"); PUTSTR((char *)"**EMSI_REQA77E\r\021");
} }
PUTSTR((char *)"\r\rAddress: "); PUTSTR((char *)"\r\rAddress: ");
PUTSTR(aka2str(CFG.aka[0])); PUTSTR(aka2str(CFG.aka[0]));
PUTSTR((char *)" using mbcico "); PUTSTR((char *)" using mbcico ");
PUTSTR((char *)VERSION); PUTSTR((char *)VERSION);
switch (tcp_mode) { switch (tcp_mode) {
case TCPMODE_IFC: PUTSTR((char *)"; IFC"); case TCPMODE_IFC: PUTSTR((char *)"; IFC");
break; break;
case TCPMODE_ITN: PUTSTR((char *)"; ITN"); case TCPMODE_ITN: PUTSTR((char *)"; ITN");
break; break;
case TCPMODE_IBN: PUTSTR((char *)"; IBN"); case TCPMODE_IBN: PUTSTR((char *)"; IBN");
break; break;
} }
PUTCHAR('\r'); PUTCHAR('\r');
if (STATUS) { if (STATUS) {
SM_ERROR; SM_ERROR;
} else { } else {
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
} }
SM_STATE(waitchar) SM_STATE(waitchar)
Syslog('S', "rxdefine_type WAITCHAR"); Syslog('s', "rxdefine_type WAITCHAR");
if ((c=GETCHAR(20)) == TIMEOUT) { /* Timeout was 8, must be 20. */
SM_PROCEED(sendintro); if (EXPIRED(0)) {
} else if (c < 0) { Syslog('+', "Timeout session handshake with the caller");
Syslog('+', "EMSI error while getting from caller"); SM_ERROR;
SM_ERROR; }
} else {
SM_PROCEED(nextchar); if ((c = GETCHAR(20)) == TIMEOUT) {
} SM_PROCEED(sendintro);
} else if (c < 0) {
Syslog('+', "EMSI error while getting from caller");
SM_ERROR;
} else {
SM_PROCEED(nextchar);
}
SM_STATE(nextchar) SM_STATE(nextchar)
Syslog('S', "rxdefine_type NEXTCHAR"); Syslog('s', "rxdefine_type NEXTCHAR");
if ((c >= ' ') && (c <= 'z')) { if ((c >= ' ') && (c <= 'z')) {
if (c == '*') { if (c == '*') {
standby = 1; standby = 1;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
} else if (standby) { } else if (standby) {
if ((ep - ebuf) < (sizeof(ebuf) - 1)) { if ((ep - ebuf) < (sizeof(ebuf) - 1)) {
*ep++ = c; *ep++ = c;
*ep = '\0'; *ep = '\0';
} }
if ((ep - ebuf) >= (sizeof(ebuf) - 1)) { if ((ep - ebuf) >= (sizeof(ebuf) - 1)) {
standby = 0; standby = 0;
SM_PROCEED(checkemsi); SM_PROCEED(checkemsi);
} }
} }
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
} else switch (c) { } else {
case DC1: SM_PROCEED(waitchar); switch (c) {
case DC1: SM_PROCEED(waitchar);
break; break;
case TSYNC: standby = 0; case TSYNC: standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (++maybeftsc > 1) { if (++maybeftsc > 1) {
type = SESSION_FTSC; type = SESSION_FTSC;
SM_SUCCESS; SM_SUCCESS;
} else { } else {
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
} }
break; break;
case YOOHOO: standby = 0; case YOOHOO:standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (++maybeyoohoo > 1) { if (++maybeyoohoo > 1) {
type = SESSION_YOOHOO; type = SESSION_YOOHOO;
SM_SUCCESS; SM_SUCCESS;
} else { } else {
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
} }
break; break;
case '\r': case '\r':
case '\n': standby = 0; case '\n': standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
if (ebuf[0]) { if (ebuf[0]) {
SM_PROCEED(checkemsi); SM_PROCEED(checkemsi);
} else { } else {
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} }
break; break;
default: standby = 0; default: standby = 0;
ep = ebuf; ep = ebuf;
ebuf[0] = '\0'; ebuf[0] = '\0';
Syslog('i', "Got '%s' from remote", printablec(c)); Syslog('i', "Got '%s' from remote", printablec(c));
SM_PROCEED(waitchar); SM_PROCEED(waitchar);
break; break;
} }
}
SM_STATE(checkemsi) SM_STATE(checkemsi)
Syslog('S', "rxdefine_type CHECKEMSI"); Syslog('s', "rxdefine_type CHECKEMSI");
Syslog('i', "check \"%s\" for being EMSI inquery or data",ebuf); Syslog('i', "check \"%s\" for being EMSI inquery or data",ebuf);
if (localoptions & NOEMSI) { if (localoptions & NOEMSI) {
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} }
if (strncasecmp(ebuf, "EMSI_INQC816", 12) == 0) { if (strncasecmp(ebuf, "EMSI_INQC816", 12) == 0) {
type = SESSION_EMSI; type = SESSION_EMSI;
data = xstrcpy((char *)"**EMSI_INQC816"); data = xstrcpy((char *)"**EMSI_INQC816");
SM_SUCCESS; SM_SUCCESS;
} else if (strncasecmp(ebuf, "EMSI_DAT", 8) == 0) { } else if (strncasecmp(ebuf, "EMSI_HBT", 8) == 0) {
SM_PROCEED(getdat); standby = 0;
} else { ep = ebuf;
SM_PROCEED(sendintro); ebuf[0] = '\0';
} SM_PROCEED(waitchar);
} else if (strncasecmp(ebuf, "EMSI_DAT", 8) == 0) {
SM_PROCEED(getdat);
} else {
SM_PROCEED(sendintro);
}
SM_STATE(getdat) SM_STATE(getdat)
Syslog('S', "rxdefine_type GETDAT"); Syslog('s', "rxdefine_type GETDAT");
Syslog('i', "Try get emsi_dat packet starting with \"%s\"",ebuf); Syslog('i', "Try get emsi_dat packet starting with \"%s\"",ebuf);
if (sscanf(ebuf+8, "%04x", &datasize) != 1) { if (sscanf(ebuf+8, "%04x", &datasize) != 1) {
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} }
datasize += 18; /* strlen("**EMSI_DATxxxxyyyy"), include CRC */ datasize += 18; /* strlen("**EMSI_DATxxxxyyyy"), include CRC */
data=malloc(datasize+1); data=malloc(datasize+1);
strcpy(data,"**"); strcpy(data,"**");
strcat(data, ebuf); strcat(data, ebuf);
p = data + strlen(data); p = data + strlen(data);
while (((p - data) < datasize) && ((c = GETCHAR(8)) >= 0)) { while (((p - data) < datasize) && ((c = GETCHAR(8)) >= 0)) {
*p++ = c; *p++ = c;
*p= '\0'; *p= '\0';
} }
if (c == TIMEOUT) { if (c == TIMEOUT) {
SM_PROCEED(sendintro); SM_PROCEED(sendintro);
} else if (c < 0) { } else if (c < 0) {
Syslog('+', "Error while reading EMSI_DAT from the caller"); Syslog('+', "Error while reading EMSI_DAT from the caller");
SM_ERROR; SM_ERROR;
} }
type = SESSION_EMSI; type = SESSION_EMSI;
SM_SUCCESS; SM_SUCCESS;
SM_END SM_END
SM_RETURN SM_RETURN