Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 6341827f authored by rswindell's avatar rswindell

Created system call wrappers.c (and sbbswrap.h) and moved target...

Created system call wrappers.c (and sbbswrap.h) and moved target platform-specific macros and code there.
parent af1676c4
......@@ -8,7 +8,6 @@
DEBUG = 1 # Comment out for release (non-debug) version
CC = gcc
LD = ld
OS = Win32
CFLAGS = -Id:/cygwin/usr/include/mingw32
LFLAGS = -L$(LIB)
......@@ -26,9 +25,6 @@ FTPSRVR = ftpsrvr.dll
MAILSRVR= mailsrvr.dll
vpath .c .
VPATH = .
OBJS = ansiterm.o\
answer.o\
ars.o\
......@@ -98,14 +94,16 @@ OBJS = ansiterm.o\
userdat.o\
useredit.o\
viewfile.o\
wrappers.o\
writemsg.o\
xtrn.o\
xtrn_sec.o
HEADERS = sbbs.h sbbsdefs.h scfgdefs.h gen_defs.h nodedefs.h text.h \
smblib.h smbdefs.h
HEADERS = sbbs.h sbbsdefs.h sbbswrap.h scfgdefs.h gen_defs.h nodedefs.h \
smblib.h smbdefs.h text.h
SBBSDEFS= -DSBBS -DSBBS_EXPORTS -DSMB_GETMSGTXT -DSMBDLL -DLZHDLL
SBBSDEFS= -DSBBS -DSBBS_EXPORTS -DSMB_GETMSGTXT -DSMBDLL -DLZHDLL \
-DWRAPPER_DLL
# Implicit C Compile Rule for SBBS.DLL
.c.o:
......@@ -146,7 +144,7 @@ data.o: $(HEADERS)
data_ovl.o: $(HEADERS)
date_str.o: $(HEADERS)
download.o: $(HEADERS)
email.o: $(HEADERS) cmdshell.h
email.o: $(HEADERS) cmdshell.h
exec.o: $(HEADERS) cmdshell.h
execfile.o: $(HEADERS) cmdshell.h
execfunc.o: $(HEADERS) cmdshell.h
......@@ -159,12 +157,12 @@ getkey.o: $(HEADERS)
getmsg.o: $(HEADERS)
getnode.o: $(HEADERS)
getstr.o: $(HEADERS)
inkey.o: $(HEADERS)
inkey.o: $(HEADERS)
listfile.o: $(HEADERS)
load_cfg.o: $(HEADERS)
logfile.o: $(HEADERS)
login.o: $(HEADERS)
logon.o: $(HEADERS) cmdshell.h
login.o: $(HEADERS)
logon.o: $(HEADERS) cmdshell.h
logout.o: $(HEADERS)
lzh.o: $(HEADERS)
mail.o: $(HEADERS)
......@@ -176,12 +174,12 @@ newuser.o: $(HEADERS)
pack_qwk.o: $(HEADERS) qwk.h post.h
pack_rep.o: $(HEADERS) qwk.h post.h
postmsg.o: $(HEADERS)
prntfile.o: $(HEADERS)
prntfile.o: $(HEADERS)
putmsg.o: $(HEADERS)
putnode.o: $(HEADERS)
qwk.o: $(HEADERS) qwk.h post.h
qwktomsg.o: $(HEADERS) qwk.h
readmail.o: $(HEADERS)
readmail.o: $(HEADERS)
readmsgs.o: $(HEADERS) post.h
ringbuf.o: $(HEADERS)
scandirs.o: $(HEADERS)
......@@ -203,6 +201,7 @@ useredit.o: $(HEADERS)
getuser.o: $(HEADERS)
ver.o: $(HEADERS) $(OBJS)
viewfile.o: $(HEADERS)
writemsg.o: $(HEADERS)
wrappers.o: $(HEADERS)
writemsg.o: $(HEADERS)
xtrn.o: $(HEADERS) cmdshell.h
xtrn_sec.o: $(HEADERS)
......@@ -620,7 +620,7 @@ void sbbs_t::sysop_page(void)
else if(cfg.sys_misc&SM_SHRTPAGE) {
bprintf(text[PagingGuru],cfg.sys_op);
for(i=0;i<10 && !lkbrd(1);i++) {
beep(1000,200);
sbbs_beep(1000,200);
mswait(200);
outchar('.'); }
CRLF; }
......@@ -1368,7 +1368,7 @@ void sbbs_t::guruchat(char *line, char *gurubuf, int gurunum)
if(answers==100)
while(*ptr && *ptr!='(' && ptr<gurubuf+len)
ptr++;
i=random(answers);
i=sbbs_random(answers);
for(j=0,k=0;answer[i][j];j++) {
if(answer[i][j]=='`') {
j++;
......@@ -1493,32 +1493,32 @@ void sbbs_t::guruchat(char *line, char *gurubuf, int gurunum)
else
theanswer[k++]=answer[i][j]; }
theanswer[k]=0;
mswait(500+random(1000)); /* thinking time */
mswait(500+sbbs_random(1000)); /* thinking time */
if(action!=NODE_MCHT) {
for(i=0;i<k;i++) {
if(mistakes && theanswer[i]!=theanswer[i-1] &&
((!isalnum(theanswer[i]) && !random(100))
|| (isalnum(theanswer[i]) && !random(30)))) {
c=j=((uint)random(3)+1); /* 1 to 3 chars */
((!isalnum(theanswer[i]) && !sbbs_random(100))
|| (isalnum(theanswer[i]) && !sbbs_random(30)))) {
c=j=((uint)sbbs_random(3)+1); /* 1 to 3 chars */
if(c<strcspn(theanswer+(i+1),"\0., "))
c=j=1;
while(j) {
outchar(97+random(26));
mswait(25+random(150));
outchar(97+sbbs_random(26));
mswait(25+sbbs_random(150));
j--; }
if(random(100)) {
mswait(100+random(300));
if(sbbs_random(100)) {
mswait(100+sbbs_random(300));
while(c) {
bputs("\b \b");
mswait(50+random(50));
mswait(50+sbbs_random(50));
c--; } } }
outchar(theanswer[i]);
if(theanswer[i]==theanswer[i+1])
mswait(25+random(50));
mswait(25+sbbs_random(50));
else
mswait(25+random(150));
mswait(25+sbbs_random(150));
if(theanswer[i]==SP)
mswait(random(50));
mswait(sbbs_random(50));
} }
else {
mswait(strlen(theanswer)*100);
......@@ -1677,7 +1677,7 @@ void sbbs_t::localguru(char *gurubuf, int gurunum)
console|=(CON_L_ECHO|CON_R_ECHO); /* make sure echo is on */
if(action==NODE_CHAT) { /* only page if from chat section */
bprintf(text[PagingGuru],cfg.guru[gurunum]->name);
ch=random(25)+25;
ch=sbbs_random(25)+25;
while(ch--) {
mswait(200);
outchar('.'); } }
......
......@@ -302,7 +302,7 @@ bool sbbs_t::ar_exp(uchar **ptrptr, user_t* user)
noaccess_val=i; }
break;
case AR_RANDOM:
n=random(i+1);
n=sbbs_random(i+1);
if((equal && n!=i) || (!equal && n<i))
result=not;
else
......
......@@ -166,7 +166,7 @@ void sbbs_t::outchar(char ch)
putch('X');
else if(cfg.node_misc&NM_NOBEEP && ch==7); /* Do nothing if beep */
else if(ch==7) {
beep(2000,110);
sbbs_beep(2000,110);
nosound(); }
else putch(ch); }
#endif
......@@ -184,7 +184,7 @@ void sbbs_t::outchar(char ch)
break;
i++;
if(sys_status&SS_SYSPAGE)
beep(i,80);
sbbs_beep(i,80);
else
mswait(80); }
if(i==1440) { /* timeout - beep flush outbuf */
......@@ -535,7 +535,7 @@ void sbbs_t::attr(int atr)
bool sbbs_t::msgabort()
{
if(sys_status&SS_SYSPAGE) {
beep(random(800),1);
sbbs_beep(sbbs_random(800),1);
}
checkline();
......
......@@ -686,7 +686,7 @@ int sbbs_t::exec_misc(csi_t *csi, char *path)
l=*(long *)csi->ip;
csi->ip+=4;
if(lp)
*lp=random(l);
*lp=sbbs_random(l);
return(0);
case TIME_INT_VAR:
lp=getintvar(csi,*(long *)csi->ip);
......
......@@ -54,19 +54,12 @@
/* Synchronet-specific headers */
#include "sbbsinet.h"
#include "sbbswrap.h"
#include "scfgdefs.h"
#include "ftpsrvr.h"
#include "userdat.h"
#include "telnet.h"
#if defined(__GNUC__) /* GNU CC */
#warning "ultoa needs to be defined or replaced"
#define ultoa ltoa
#endif /* __GNUC__ */
/* Constants */
#define FTP_VERSION "1.02"
......@@ -97,16 +90,13 @@ static const char *mon[]={"Jan","Feb","Mar","Apr","May","Jun"
#endif
IMPORT BOOL load_cfg(scfg_t* cfg, char* text[]);
IMPORT BOOL fexist(char *filespec);
IMPORT long flength(char *filespec);
IMPORT long fdate(char *filespec);
IMPORT BOOL getfileixb(scfg_t* cfg, file_t* f);
IMPORT BOOL getfiledat(scfg_t* cfg, file_t* f);
IMPORT BOOL putfiledat(scfg_t* cfg, file_t* f);
IMPORT BOOL removefiledat(scfg_t* cfg, file_t* f);
IMPORT BOOL addfiledat(scfg_t* cfg, file_t* f);
IMPORT BOOL addfiledat(scfg_t* cfg, file_t* f);
IMPORT BOOL findfile(scfg_t* cfg, uint dirnum, char *filename);
IMPORT char* padfname(char *filename, char *str);
......@@ -114,8 +104,6 @@ IMPORT char* unpadfname(char *filename, char *str);
IMPORT BOOL trashcan(scfg_t* cfg, char *insearch, char *name);
IMPORT ulong getfreediskspace(char* path);
BOOL direxist(char *dir)
{
if(access(dir,0)==0)
......@@ -175,19 +163,12 @@ static BOOL winsock_startup(void)
return (FALSE);
}
#else /* No WINSOCK */
#define winsock_startup() (TRUE)
#endif
#ifdef _WIN32 /* Windows */
#define ERROR_VALUE WSAGetLastError()
#else /* Non-Windows */
#else /* No WINSOCK */
#define ERROR_VALUE errno
#define winsock_startup() (TRUE)
#define ERROR_VALUE errno
#endif
......@@ -2923,8 +2904,11 @@ static void cleanup(int code)
server_socket=INVALID_SOCKET;
update_clients();
#ifdef _WINSOCKAPI_
if(WSACleanup()!=0)
lprintf("!WSACleanup ERROR %d",ERROR_VALUE);
#endif
lprintf("FTP Server thread terminated");
status("Down");
......@@ -2978,15 +2962,15 @@ void ftp_server(void* arg)
startup=(ftp_startup_t*)arg;
if(startup==NULL) {
Beep(100,500);
sbbs_beep(100,500);
fprintf(stderr, "No startup structure passed!\n");
return;
}
if(startup->size!=sizeof(ftp_startup_t)) { /* verify size */
Beep(100,500);
Beep(300,500);
Beep(100,500);
sbbs_beep(100,500);
sbbs_beep(300,500);
sbbs_beep(100,500);
fprintf(stderr, "Invalid startup structure!\n");
return;
}
......@@ -3034,11 +3018,13 @@ void ftp_server(void* arg)
return;
}
#ifdef _WIN32
if((socket_mutex=CreateMutex(NULL,FALSE,NULL))==NULL) {
lprintf("!ERROR %d creating socket_mutex", GetLastError());
cleanup(1);
return;
}
#endif
/* Initial configuration and load from CNF files */
memset(&scfg, 0, sizeof(scfg));
......
......@@ -45,7 +45,7 @@
/****************************************************************************/
char sbbs_t::getkey(long mode)
{
char ch,coldkey,c=0,spin=random(5);
char ch,coldkey,c=0,spin=sbbs_random(5);
if(!online)
return(0);
......@@ -64,7 +64,7 @@ char sbbs_t::getkey(long mode)
return(0); }
if(sys_status&SS_SYSPAGE) {
beep(random(800),100);
sbbs_beep(sbbs_random(800),100);
}
if(mode&K_SPIN)
......
......@@ -235,7 +235,7 @@ bool sbbs_t::logon()
c=0;
while(c<LEN_PASS) { /* Create random password */
str[c]=random(43)+'0';
str[c]=sbbs_random(43)+'0';
if(isalnum(str[c]))
c++; }
str[c]=0;
......
......@@ -117,7 +117,7 @@ void sbbs_t::logout()
CLS;
lputs("\r\n\r\nAlerting Sysop...");
while(!lkbrd(1)) {
beep(1000,200);
sbbs_beep(1000,200);
nosound();
mswait(200); }
lkbrd(0); }
......
......@@ -58,13 +58,7 @@
#include "smblib.h"
#include "crc32.h"
#include "sbbsinet.h"
#if defined(__GNUC__) /* GNU CC */
#warning "ultoa needs to be defined or replaced"
#define ultoa ltoa
#endif /* __GNUC__ */
#include "sbbswrap.h"
/* Constants */
#define MAIL_VERSION "1.10"
......@@ -141,20 +135,12 @@ static BOOL winsock_startup(void)
lprintf("!WinSock startup ERROR %d", status);
return (FALSE);
}
#define ERROR_VALUE WSAGetLastError()
#else /* No WINSOCK */
#define winsock_startup() (TRUE)
#endif
#ifdef _WIN32 /* Windows */
#define ERROR_VALUE GetLastError()
#else /* Non-Windows */
#define ERROR_VALUE errno
#define ERROR_VALUE errno
#endif
......@@ -2241,8 +2227,10 @@ static void cleanup(int code)
update_clients();
#ifdef _WINSOCKAPI_
if(WSACleanup()!=0)
lprintf("!WSACleanup ERROR %d",ERROR_VALUE);
#endif
lprintf("Mail Server thread terminated");
status("Down");
......@@ -2301,15 +2289,15 @@ void mail_server(void* arg)
startup=(mail_startup_t*)arg;
if(startup==NULL) {
Beep(100,500);
sbbs_beep(100,500);
fprintf(stderr, "No startup structure passed!\n");
return;
}
if(startup->size!=sizeof(mail_startup_t)) { /* verify size */
Beep(100,500);
Beep(300,500);
Beep(100,500);
sbbs_beep(100,500);
sbbs_beep(300,500);
sbbs_beep(100,500);
fprintf(stderr, "Invalid startup structure!\n");
return;
}
......
......@@ -292,50 +292,6 @@ char *zonestr(short zone)
return(str);
}
/****************************************************************************/
/* Checks the disk drive for the existence of a file. Returns 1 if it */
/* exists, 0 if it doesn't. */
/****************************************************************************/
BOOL fexist(char *filespec)
{
long handle;
struct _finddata_t f;
if((handle=_findfirst(filespec,&f))==-1)
return(FALSE);
_findclose(handle);
if(f.attrib&_A_SUBDIR)
return(FALSE);
return(TRUE);
}
/****************************************************************************/
/* Returns the length of the file in 'filespec' */
/****************************************************************************/
long flength(char *filespec)
{
long handle;
struct _finddata_t f;
if((handle=_findfirst(filespec,&f))==-1)
return(-1L);
_findclose(handle);
return(f.size);
}
/****************************************************************************/
/* Returns the time/date of the file in 'filespec' in time_t (unix) format */
/****************************************************************************/
long fdate(char *filespec)
{
long handle;
struct _finddata_t f;
if((handle=_findfirst(filespec,&f))==-1)
return(-1L);
_findclose(handle);
return(f.time_write);
}
/****************************************************************************/
/* Returns an ASCII string for FidoNet address 'addr' */
......@@ -389,67 +345,3 @@ ulong ahtoul(char *str)
return(val);
}
#ifndef __BORLANDC__
int sbbs_random(int n)
{
float f;
if(n<2)
return(0);
f=(float)rand()/(float)RAND_MAX;
return((int)(n*f));
}
#endif
typedef BOOL(WINAPI * GetDiskFreeSpaceEx_t)(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
ulong getfreediskspace(char* path)
{
#ifdef _WIN32
HINSTANCE hK32;
char root[16];
DWORD TotalNumberOfClusters;
DWORD NumberOfFreeClusters;
DWORD BytesPerSector;
DWORD SectorsPerCluster;
ULARGE_INTEGER avail;
ULARGE_INTEGER size;
GetDiskFreeSpaceEx_t GetDiskFreeSpaceEx;
if ((hK32 = LoadLibrary("KERNEL32")) == NULL)
return(0);
GetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)GetProcAddress(hK32,"GetDiskFreeSpaceExA");
if (GetDiskFreeSpaceEx!=NULL) { /* Windows 95-OSR2 or later */
if(!GetDiskFreeSpaceEx(
path, // pointer to the directory name
&avail, // receives the number of bytes on disk available to the caller
&size, // receives the number of bytes on disk
NULL)) // receives the free bytes on disk
return(0);
if(avail.HighPart)
return(0xffffffff);
return(avail.LowPart);
}
/* Windows 95 (old way), limited to 2GB */
sprintf(root,"%.3s",path);
if(!GetDiskFreeSpace(
root, // pointer to root path
&SectorsPerCluster, // pointer to sectors per cluster
&BytesPerSector, // pointer to bytes per sector
&NumberOfFreeClusters, // pointer to number of free clusters
&TotalNumberOfClusters // pointer to total number of clusters
))
return(0);
return(NumberOfFreeClusters*SectorsPerCluster*BytesPerSector);
#else
#warning OS-specific code needed here
return(0);
#endif
}
......@@ -300,7 +300,7 @@ void sbbs_t::newuser()
c=0;
while(c<LEN_PASS) { /* Create random password */
useron.pass[c]=random(43)+'0';
useron.pass[c]=sbbs_random(43)+'0';
if(isalnum(useron.pass[c]))
c++; }
useron.pass[c]=0;
......
......@@ -69,7 +69,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SBBS_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SBBS" /D "SBBS_EXPORTS" /D "SMB_GETMSGTXT" /D "SMBDLL" /D "LZHDLL" /FR /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SBBS" /D "SBBS_EXPORTS" /D "WRAPPER_DLL" /D "SMB_GETMSGTXT" /D "SMBDLL" /D "LZHDLL" /FR /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
......@@ -373,6 +373,10 @@ SOURCE=.\viewfile.cpp
# End Source File
# Begin Source File
SOURCE=.\wrappers.c
# End Source File
# Begin Source File
SOURCE=.\writemsg.cpp
# End Source File
# Begin Source File
......
......@@ -77,6 +77,7 @@
/* Synchronet-specific */
/***********************/
#include "sbbsinet.h"
#include "sbbswrap.h"
#include "smblib.h"
#include "ars_defs.h"
#include "scfgdefs.h"
......@@ -104,13 +105,6 @@ int unlock(int file, long offset, int size);
#endif
#endif /* !__BORLANDC__ */
#if defined(__GNUC__) /* GNU CC */
#warning "ultoa needs to be defined or replaced"
#define ultoa ltoa
#endif /* __GNUC__ */
#ifdef __cplusplus
class sbbs_t
......@@ -660,11 +654,6 @@ public:
void scanalldirs(long mode);
void scandirs(long mode);
#ifdef _WIN32
#define beep(freq, dur) Beep(freq, dur)
#else
#define beep(freq, dur)
#endif
#define nosound()
#define checkline()
......@@ -676,6 +665,9 @@ public:
};
#endif
#ifdef DLLEXPORT
#undef DLLEXPORT
#endif
#ifdef _WIN32
#ifdef SBBS_EXPORTS
#define DLLEXPORT __declspec(dllexport)
......@@ -730,22 +722,10 @@ extern "C" {
ulong ahtoul(char *str); /* Converts ASCII hex to ulong */
char * hexplus(uint num, char *str); /* Hex plus for 3 digits up to 9000 */
uint hptoi(char *str);
#ifndef __BORLANDC__
int sbbs_random(int n); /* return random number between 0 and n-1 */
#define random(x) sbbs_random(x)
#endif
#ifndef _WIN32
long filelength(int fd);
#endif
DLLEXPORT ushort crc16(char *str);
DLLEXPORT char * zonestr(short zone);
DLLEXPORT int putsmsg(scfg_t* cfg, int usernumber, char *strin);
DLLEXPORT BOOL fexist(char *filespec);