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 7333609f authored by rswindell's avatar rswindell

Eliminated in favor of xpdev versions of these wrappers.

parent c2ff0e0b
/*
conwrap.c -- To give DOS's getch() function to Linux for use in Synchronet
Casey Martin 2000
*/
/* $Id$ */
/* @format.tab-size 4, @format.use-tabs true */
#ifdef __unix__
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
/* Do the correct thing under BSD */
#ifndef __FreeBSD__
#include <sys/kd.h>
#endif
#ifdef __FreeBSD__
#include <sys/kbio.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include "conwrap.h" // Verify prototypes
struct termios current; // our current term settings
struct termios original; // old termios settings
struct timeval timeout = {0, 0}; // passed in select() call
fd_set inp; // ditto
int beensetup = 0; // has _termios_setup() been called?
/*
I'm using a variable function here simply for the sake of speed. The
termios functions must be called before a kbhit() can be successful, so
on the first call, we just set up the terminal, point to variable function
to kbhit_norm(), and then call the new function. Otherwise, testing would
be required on every call to determine if termios has already been setup.
Maybe I'm being way too anal, though.
*/
/* Resets the termios to its previous state */
void _termios_reset(void)
{
tcsetattr(0, TCSANOW, &original);
}
/************************************************
This pair of functions handles Ctrl-Z presses
************************************************/
void _sighandler_stop(int sig)
{
// clean up the terminal
_termios_reset();
// ... and stop
kill(getpid(), SIGSTOP);
}
void _sighandler_cont(int sig)
{
// restore terminal
tcsetattr(0, TCSANOW, &current);
}
/* Prepares termios for non-blocking action */
void _termios_setup(void)
{
beensetup = 1;
tcgetattr(0, &original);
memcpy(&current, &original, sizeof(struct termios));
current.c_cc[VMIN] = 1; // read() will return with one char
current.c_cc[VTIME] = 0; // read() blocks forever
current.c_lflag &= ~ICANON; // character mode
current.c_lflag &= ~ECHO; // turn off echoing
tcsetattr(0, TCSANOW, &current);
// Let's install an exit function, also. This way, we can reset
// the termios silently
atexit(_termios_reset);
// install the Ctrl-Z handler
signal(SIGSTOP, _sighandler_stop);
signal(SIGCONT, _sighandler_cont);
}
int kbhit(void)
{
// set up select() args
FD_ZERO(&inp);
FD_SET(0, &inp);
return select(1, &inp, NULL, NULL, &timeout);
}
int getch(void)
{
char c;
if (!beensetup)
// I hate to test for this every time, but this shouldn't be
// called that often anyway...
_termios_setup();
// get a char out of stdin
read(0, &c, 1);
return c;
}
#endif // __unix__
/* conwrap.h */
/* Synchronet local console I/O wrapppers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program 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 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _CONWRAP_H
#define _CONWRAP_H
#ifdef __unix__
int kbhit(void);
int getch(void);
#else /* DOS-Based */
#include <conio.h>
#endif
#endif /* _CONWRAP_H */
/* sbbsinet.h */
/* Synchronet platform-specific Internet stuff */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program 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 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _SBBSINET_H
#define _SBBSINET_H
/***************/
/* OS-specific */
/***************/
#if defined _WIN32 || defined __OS2__ /* Use WinSock */
#include <winsock.h> /* socket/bind/etc. */
/* Let's agree on a standard WinSock symbol here, people */
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif
#elif defined __unix__ /* Unix-variant */
#include <netdb.h> /* gethostbyname */
#ifdef __FreeBSD__
#include <sys/types.h> /* For u_int32_t on FreeBSD */
#endif
#include <netinet/in.h> /* IPPROTO_IP */
#include <sys/socket.h> /* socket/bind/etc. */
#include <sys/ioctl.h> /* FIONBIO */
#include <sys/time.h> /* struct timeval */
#include <arpa/inet.h> /* inet_ntoa */
#include <unistd.h> /* close */
#endif
#include <errno.h> /* errno */
/**********************************/
/* Socket Implementation-specific */
/**********************************/
#ifdef _WINSOCKAPI_
#undef EINTR
#define EINTR (WSAEINTR-WSABASEERR)
#undef ENOTSOCK
#define ENOTSOCK (WSAENOTSOCK-WSABASEERR)
#undef EWOULDBLOCK
#define EWOULDBLOCK (WSAEWOULDBLOCK-WSABASEERR)
#undef ECONNRESET
#define ECONNRESET (WSAECONNRESET-WSABASEERR)
#undef ESHUTDOWN
#define ESHUTDOWN (WSAESHUTDOWN-WSABASEERR)
#undef ECONNABORTED
#define ECONNABORTED (WSAECONNABORTED-WSABASEERR)
#define s_addr S_un.S_addr
#define socklen_t int
static wsa_error;
#define ERROR_VALUE ((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error)
#define sendsocket(s,b,l) send(s,b,l,0)
#else /* BSD sockets */
/* WinSock-isms */
#define HOSTENT struct hostent
#define SOCKADDR_IN struct sockaddr_in
#define LINGER struct linger
#define SOCKET int
#define SOCKET_ERROR -1
#define INVALID_SOCKET (SOCKET)(~0)
#define closesocket close
#define ioctlsocket ioctl
#define ERROR_VALUE errno
#define sendsocket write // FreeBSD send() is broken
#endif /* __unix__ */
#ifndef SHUT_RDWR
#define SHUT_RDWR 2 /* for shutdown() */
#endif
#ifndef IPPORT_FTP
#define IPPORT_FTP 21
#endif
#ifndef IPPORT_TELNET
#define IPPORT_TELNET 23
#endif
#ifndef IPPORT_SMTP
#define IPPORT_SMTP 25
#endif
#ifndef IPPORT_POP3
#define IPPORT_POP3 110
#endif
#endif /* Don't add anything after this line */
/* sbbswrap.h */
/* Synchronet system-call wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program 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 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef _SBBSWRAP_H
#define _SBBSWRAP_H
#include "gen_defs.h" /* ulong */
#ifdef DLLEXPORT
#undef DLLEXPORT
#endif
#ifdef DLLCALL
#undef DLLCALL
#endif
#ifdef _WIN32
#ifdef WRAPPER_DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#ifdef __BORLANDC__
#define DLLCALL __stdcall
#else
#define DLLCALL
#endif
#else /* !_WIN32 */
#define DLLEXPORT
#define DLLCALL
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#include "msdirent.h"
#else
#include <dirent.h> /* POSIX directory functions */
#endif
/***************/
/* OS-specific */
/***************/
#ifdef __unix__
#include <glob.h> /* POSIX.2 directory pattern matching function */
#define ALLFILES "*" /* matches all files in a directory */
#else /* glob-compatible findfirst/findnext wrapper */
typedef struct
{
size_t gl_pathc; /* Count of paths matched so far */
char **gl_pathv; /* List of matched pathnames. */
size_t gl_offs; /* Slots to reserve in 'gl_pathv'. */
} glob_t;
/* Bits set in the FLAGS argument to `glob'. */
#define GLOB_ERR (1 << 0) /* Return on read errors. */
#define GLOB_MARK (1 << 1) /* Append a slash to each name. */
#define GLOB_NOSORT (1 << 2) /* Don't sort the names. */
#define GLOB_DOOFFS (1 << 3) /* Insert PGLOB->gl_offs NULLs. */
#define GLOB_NOCHECK (1 << 4) /* If nothing matches, return the pattern. */
#define GLOB_APPEND (1 << 5) /* Append to results of a previous call. */
#define GLOB_NOESCAPE (1 << 6) /* Backslashes don't quote metacharacters. */
#define GLOB_PERIOD (1 << 7) /* Leading `.' can be matched by metachars. */
#define GLOB_MAGCHAR (1 << 8) /* Set in gl_flags if any metachars seen. */
#define GLOB_ALTDIRFUNC (1 << 9) /* Use gl_opendir et al functions. */
#define GLOB_BRACE (1 << 10) /* Expand "{a,b}" to "a" "b". */
#define GLOB_NOMAGIC (1 << 11) /* If no magic chars, return the pattern. */
#define GLOB_TILDE (1 << 12) /* Expand ~user and ~ to home directories. */
#define GLOB_ONLYDIR (1 << 13) /* Match only directories. */
#define GLOB_TILDE_CHECK (1 << 14) /* Like GLOB_TILDE but return an error
if the user name is not available. */
/* Error returns from `glob'. */
#define GLOB_NOSPACE 1 /* Ran out of memory. */
#define GLOB_ABORTED 2 /* Read error. */
#define GLOB_NOMATCH 3 /* No matches found. */
#define GLOB_NOSYS 4 /* Not implemented. */
DLLEXPORT int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t*);
DLLEXPORT void DLLCALL globfree(glob_t*);
#define ALLFILES "*.*" /* matches all files in a directory */
#endif
#ifdef __unix__
#include <pthread.h> /* POSIX threads and mutexes */
#include <semaphore.h> /* POSIX semaphores */
ulong _beginthread(void( *start_address )( void * )
,unsigned stack_size, void *arglist);
#elif defined(_WIN32)
/* POSIX semaphores */
typedef HANDLE sem_t;
#define sem_init(psem,ps,v) ResetEvent(*(psem))
#define sem_wait(psem) WaitForSingleObject(*(psem),INFINITE)
#define sem_post(psem) SetEvent(*(psem))
#define sem_destroy(psem) CloseHandle(*(psem))
DLLEXPORT int DLLCALL sem_getvalue(sem_t*, int* val);
/* POSIX mutexes */
typedef HANDLE pthread_mutex_t;
#define PTHREAD_MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL)
#define pthread_mutex_init(pmtx,v) *(pmtx)=CreateMutex(NULL,FALSE,NULL)
#define pthread_mutex_lock(pmtx) WaitForSingleObject(*(pmtx),INFINITE)
#define pthread_mutex_unlock(pmtx) ReleaseMutex(*(pmtx))
#define pthread_mutex_destroy(pmtx) CloseHandle(*(pmtx))
#else
#warning "Need semaphore wrappers."
#endif
#if defined(_WIN32)
#define sbbs_beep(freq,dur) Beep(freq,dur)
#elif defined(__OS2__)
#define sbbs_beep(freq,dur) DosBeep(freq,dur)
#elif defined(__unix__)
DLLEXPORT void DLLCALL sbbs_beep(int freq, int dur);
DLLEXPORT char* DLLCALL strrev(char* str);
#else /* Unsupported OS */
#warning "Unsupported Target: Need some macros or function prototypes here."
#endif
/*********************/
/* Compiler-specific */
/*********************/
/* Compiler Description */
#if defined(__BORLANDC__)
#define COMPILER_DESC(str) sprintf(str,"BCC %X.%02X" \
,__BORLANDC__>>8,__BORLANDC__&0xff);
#elif defined(_MSC_VER)
#define COMPILER_DESC(str) sprintf(str,"MSC %u", _MSC_VER);
/***
#elif defined(__GNUC__) && defined(__GLIBC__)
#define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u (GLIBC %u.%u)" \
,__GNUC__,__GNUC_MINOR__,__GLIBC__,__GLIBC_MINOR__);
***/
#elif defined(__GNUC__)
#define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u" \
,__GNUC__,__GNUC_MINOR__);
#else /* Unknown compiler */
#define COMPILER_DESC(str) strcpy(str,"UNKNOWN COMPILER");
#endif
/**********/
/* Macros */
/**********/
/* POSIX readdir convenience macro */
#ifndef DIRENT
#define DIRENT struct dirent
#endif
#if defined(__unix__)
#define BACKSLASH '/'
#else /* MS-DOS based OS */
#define BACKSLASH '\\'
#endif
/* Target Platform Description */
#if defined(_WIN64)
#define PLATFORM_DESC "Win64"
#elif defined(_WIN32)
#define PLATFORM_DESC "Win32"
#elif defined(__OS2__)
#define PLATFORM_DESC "OS/2"
#elif defined(__MSDOS__)
#define PLATFORM_DESC "DOS"
#elif defined(__linux__)
#define PLATFORM_DESC "Linux"
#elif defined(__FreeBSD__)
#define PLATFORM_DESC "FreeBSD"
#elif defined(BSD)
#define PLATFORM_DESC "BSD"
#elif defined(__unix__)
#define PLATFORM_DESC "Unix"
#else
#warning "Need to describe target platform"
#define PLATFORM_DESC "UNKNOWN"
#endif
#if defined(_MSC_VER) || defined(__MINGW32__)
#define CHMOD(s,m) _chmod(s,m)
#define PUTENV _putenv
#define GETCWD _getcwd
#define snprintf _snprintf
#elif defined(__BORLANDC__)
#define CHMOD(p,a) _rtl_chmod(p,1,a) /* _chmod obsolete in 4.x */
#define PUTENV putenv
#define GETCWD getcwd
#else /* ??? */
#define CHMOD(s,m) chmod(s,m)
#define PUTENV putenv
#define GETCWD getcwd
#endif
#if defined(__BORLANDC__)
#define sbbs_random(x) random(x)
#else
DLLEXPORT int DLLCALL sbbs_random(int n);
#endif
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
DLLEXPORT char* DLLCALL ultoa(ulong, char*, int radix);
#endif
/* General file system wrappers for all platforms and compilers */
DLLEXPORT time_t DLLCALL fdate(char *filename);
DLLEXPORT time_t DLLCALL filetime(int fd);
DLLEXPORT BOOL DLLCALL isdir(char *filename);
DLLEXPORT int DLLCALL getfattr(char* filename);
DLLEXPORT ulong DLLCALL getfreediskspace(char* path);
#ifdef __cplusplus
}
#endif
#endif /* Don't add anything after this line */
/* smbwrap.c */
/* Synchronet SMBLIB system-call wrappers */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program 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 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
/* OS-specific */
#if defined(__unix__)
#include <glob.h> /* glob() wildcard matching */
#include <string.h> /* strlen() */
#include <unistd.h> /* getpid() */
#include <fcntl.h> /* fcntl() file/record locking */
#endif
/* ANSI */
#include <sys/types.h> /* _dev_t */
#include <sys/stat.h> /* struct stat */
/* SMB-specific */
#include "smblib.h" /* SMBCALL */
#include "smbwrap.h" /* Verify prototypes */