2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2004-01-28 21:10:56 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Fidonet mailer
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-28 11:34:24 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "ttyio.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "statetbl.h"
|
|
|
|
#include "sendbark.h"
|
|
|
|
#include "xmrecv.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int send_bark(void);
|
|
|
|
static char *nm,*pw,*dt;
|
|
|
|
|
|
|
|
|
|
|
|
int sendbark(void)
|
|
|
|
{
|
|
|
|
char *fn;
|
|
|
|
FILE *fp;
|
|
|
|
char buf[256], *p;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
fn = reqname(remote->addr);
|
|
|
|
if ((fp = fopen(fn,"r")) == NULL) {
|
|
|
|
Syslog('s', "no request file for this node");
|
|
|
|
PUTCHAR(ETB);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf,sizeof(buf)-1,fp)) {
|
|
|
|
nm = buf;
|
|
|
|
pw = strchr(buf, '!');
|
|
|
|
dt = strchr(buf, '+');
|
|
|
|
|
|
|
|
if (pw)
|
|
|
|
*pw++= '\0';
|
|
|
|
if (dt)
|
|
|
|
*dt++= '\0';
|
|
|
|
|
|
|
|
if (nm) {
|
|
|
|
while (isspace(*nm))
|
|
|
|
nm++;
|
|
|
|
for (p = nm; (*p != '!') && (*p != '+') && (!isspace(*p)); p++);
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pw) {
|
|
|
|
while (isspace(*pw))
|
|
|
|
pw++;
|
|
|
|
for (p = pw; (*p != '!') && (*p != '+') && (!isspace(*p)); p++);
|
|
|
|
*p = '\0';
|
|
|
|
} else
|
|
|
|
pw = (char *)"";
|
|
|
|
|
|
|
|
if (dt) {
|
|
|
|
while (isspace(*nm))
|
|
|
|
nm++;
|
|
|
|
for (p = nm; (*p != '!') && (*p != '+') && (*p != '-') && (!isspace(*p)); p++);
|
|
|
|
*p = '\0';
|
|
|
|
} else
|
|
|
|
dt = (char *)"0";
|
|
|
|
|
|
|
|
if (*nm == ';')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Syslog('+', "Sending bark request for \"%s\", password \"%s\", update \"%s\"",MBSE_SS(nm),MBSE_SS(pw),MBSE_SS(dt));
|
|
|
|
if ((rc = send_bark()))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc == 0)
|
|
|
|
PUTCHAR(ETB);
|
|
|
|
fclose(fp);
|
|
|
|
if (rc == 0)
|
|
|
|
unlink(fn);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SM_DECL(send_bark,(char *)"sendbark")
|
|
|
|
SM_STATES
|
2004-01-28 21:10:56 +00:00
|
|
|
Send,
|
|
|
|
waitack,
|
|
|
|
getfile
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_NAMES
|
2004-01-28 21:10:56 +00:00
|
|
|
(char *)"send",
|
|
|
|
(char *)"waitack",
|
|
|
|
(char *)"getfile"
|
2001-08-17 05:46:24 +00:00
|
|
|
SM_EDECL
|
|
|
|
|
2004-01-28 21:10:56 +00:00
|
|
|
char buf[256];
|
|
|
|
unsigned short crc;
|
|
|
|
int c, count = 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-08-28 11:34:24 +00:00
|
|
|
snprintf(buf,255,"%s %s %s",nm,dt,pw);
|
2004-01-28 21:10:56 +00:00
|
|
|
crc = crc16xmodem(buf, strlen(buf));
|
|
|
|
Syslog('s', "sending bark packet \"%s\", crc = 0x%04x", buf, crc);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_START(Send)
|
|
|
|
|
|
|
|
SM_STATE(Send)
|
|
|
|
|
2004-01-28 21:10:56 +00:00
|
|
|
if (count++ > 5) {
|
|
|
|
Syslog('+', "Bark request failed");
|
|
|
|
SM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTCHAR(ACK);
|
|
|
|
PUT(buf, strlen(buf));
|
|
|
|
PUTCHAR(ETX);
|
|
|
|
PUTCHAR(crc & 0xff);
|
|
|
|
PUTCHAR((crc >> 8) & 0xff);
|
|
|
|
if (STATUS) {
|
|
|
|
SM_ERROR;
|
|
|
|
} else {
|
|
|
|
SM_PROCEED(waitack);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(waitack)
|
|
|
|
|
2004-01-28 21:10:56 +00:00
|
|
|
c = GETCHAR(10);
|
|
|
|
if (c == TIMEOUT) {
|
|
|
|
Syslog('s', "sendbark got timeout waiting for ACK");
|
|
|
|
SM_PROCEED(Send);
|
|
|
|
} else if (c < 0) {
|
|
|
|
SM_PROCEED(Send);
|
|
|
|
} else if (c == ACK) {
|
|
|
|
SM_PROCEED(getfile);
|
|
|
|
} else {
|
|
|
|
Syslog('s', "sendbark got %s waiting for ACK", printablec(c));
|
|
|
|
SM_PROCEED(Send);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_STATE(getfile)
|
|
|
|
|
2004-01-28 21:10:56 +00:00
|
|
|
switch (xmrecv(NULL)) {
|
|
|
|
case 0: SM_PROCEED(getfile);
|
|
|
|
break;
|
|
|
|
case 1: SM_SUCCESS;
|
|
|
|
break;
|
|
|
|
default: SM_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
SM_END
|
|
|
|
SM_RETURN
|
|
|
|
|
|
|
|
|