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

misc.c has been replaced with nopen.c and str_util.c

parent 588fed2a
......@@ -187,7 +187,8 @@ $(SBBSECHO): \
$(EXEODIR)/load_cfg.o \
$(EXEODIR)/scfglib1.o \
$(EXEODIR)/scfglib2.o \
$(EXEODIR)/misc.o \
$(EXEODIR)/nopen.o \
$(EXEODIR)/str_util.o \
$(EXEODIR)/userdat.o \
$(EXEODIR)/rechocfg.o \
$(EXEODIR)/conwrap.o \
......
......@@ -135,7 +135,8 @@ $(SMBUTIL): smbutil.c smbtxt.c crc32.c lzh.c $(SMBLIB) $(XPDEV)dirwrap.c
# SBBSecho (FidoNet Packet Tosser)
$(SBBSECHO): sbbsecho.c rechocfg.c smbtxt.c crc32.c lzh.c $(SMBLIB) \
$(LIBODIR)\ars.obj \
$(LIBODIR)\misc.obj \
$(LIBODIR)\nopen.obj \
$(LIBODIR)\str_util.obj \
$(LIBODIR)\date_str.obj \
userdat.c \
genwrap.c \
......
/* nopen.c */
/* Network open functions (nopen and fnopen) */
/* $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. *
****************************************************************************/
#include "sbbs.h"
#include "crc32.h"
/****************************************************************************/
/* Network open function. Opens all files DENYALL and retries LOOP_NOPEN */
/* number of times if the attempted file is already open or denying access */
/* for some other reason. All files are opened in BINARY mode. */
/****************************************************************************/
int DLLCALL nopen(char *str, int access)
{
int file,share,count=0;
if(access&O_DENYNONE) {
share=SH_DENYNO;
access&=~O_DENYNONE; }
else if(access==O_RDONLY) share=SH_DENYWR;
else share=SH_DENYRW;
if(!(access&O_TEXT))
access|=O_BINARY;
while(((file=sopen(str,access,share))==-1)
&& (errno==EACCES || errno==EAGAIN) && count++<LOOP_NOPEN)
if(count)
mswait(100);
return(file);
}
/****************************************************************************/
/* This function performs an nopen, but returns a file stream with a buffer */
/* allocated. */
/****************************************************************************/
FILE* DLLCALL fnopen(int *fd, char *str, int access)
{
char mode[128];
int file;
FILE * stream;
if((file=nopen(str,access))==-1)
return(NULL);
if(fd!=NULL)
*fd=file;
if(access&O_APPEND) {
if(access&O_RDONLY)
strcpy(mode,"a+");
else
strcpy(mode,"a");
} else if(access&O_CREAT) {
if(access&O_TRUNC)
strcpy(mode,"w");
else
strcpy(mode,"w+");
} else {
if(access&O_WRONLY || (access&O_RDWR)==O_RDWR)
strcpy(mode,"r+");
else
strcpy(mode,"r");
}
stream=fdopen(file,mode);
if(stream==NULL) {
close(file);
return(NULL);
}
setvbuf(stream,NULL,_IOFBF,FNOPEN_BUF_SIZE);
return(stream);
}
......@@ -57,10 +57,10 @@ OBJS = $(LIBODIR)$(SLASH)ansiterm.$(OFILE)\
$(LIBODIR)$(SLASH)lzh.$(OFILE)\
$(LIBODIR)$(SLASH)mail.$(OFILE)\
$(LIBODIR)$(SLASH)main.$(OFILE)\
$(LIBODIR)$(SLASH)misc.$(OFILE)\
$(LIBODIR)$(SLASH)msgtoqwk.$(OFILE)\
$(LIBODIR)$(SLASH)netmail.$(OFILE)\
$(LIBODIR)$(SLASH)newuser.$(OFILE)\
$(LIBODIR)$(SLASH)nopen.$(OFILE)\
$(LIBODIR)$(SLASH)pack_qwk.$(OFILE)\
$(LIBODIR)$(SLASH)pack_rep.$(OFILE)\
$(LIBODIR)$(SLASH)postmsg.$(OFILE)\
......@@ -81,6 +81,7 @@ OBJS = $(LIBODIR)$(SLASH)ansiterm.$(OFILE)\
$(LIBODIR)$(SLASH)smbtxt.$(OFILE)\
$(LIBODIR)$(SLASH)sortdir.$(OFILE)\
$(LIBODIR)$(SLASH)str.$(OFILE)\
$(LIBODIR)$(SLASH)str_util.$(OFILE)\
$(LIBODIR)$(SLASH)telgate.$(OFILE)\
$(LIBODIR)$(SLASH)telnet.$(OFILE)\
$(LIBODIR)$(SLASH)text_sec.$(OFILE)\
......
......@@ -550,8 +550,6 @@ public:
void printstatslog(uint node);
ulong logonstats(void);
void logoffstats(void);
/* misc.cpp */
int nopen(char *str, int access);
int mv(char *src, char *dest, char copy); /* fast file move/copy function */
bool chksyspass(void);
......@@ -767,21 +765,30 @@ extern "C" {
DLLEXPORT ulong DLLCALL getposts(scfg_t* cfg, uint subnum);
DLLEXPORT long DLLCALL getfiles(scfg_t* cfg, uint dirnum);
/* str.cpp */
/* str_util.c */
DLLEXPORT void DLLCALL truncsp(char *str); /* Truncates white spaces off end of str */
DLLEXPORT char * DLLCALL ascii_str(uchar* str);
DLLEXPORT ushort DLLCALL crc16(char *str);
DLLEXPORT BOOL DLLCALL findstr(scfg_t* cfg, char *insearch, char *fname);
DLLEXPORT BOOL DLLCALL trashcan(scfg_t* cfg, char *insearch, char *name);
DLLEXPORT int DLLCALL putsmsg(scfg_t* cfg, int usernumber, char *strin);
DLLEXPORT char * DLLCALL strip_ctrl(char *str);
DLLEXPORT char * DLLCALL strip_exascii(char *str);
DLLEXPORT char * DLLCALL prep_file_desc(char *str);
DLLEXPORT char * DLLCALL strip_ctrl(char *str);
DLLEXPORT char * DLLCALL net_addr(net_t* net);
DLLEXPORT ushort DLLCALL crc16(char *str);
/* misc.c */
/* date_str.c */
DLLEXPORT char * DLLCALL zonestr(short zone);
DLLEXPORT char * DLLCALL net_addr(net_t* net);
DLLEXPORT time_t DLLCALL dstrtounix(scfg_t*, char *str);
DLLEXPORT char * DLLCALL unixtodstr(scfg_t*, time_t, char *str);
DLLEXPORT char * DLLCALL sectostr(uint sec, char *str);
DLLEXPORT char * DLLCALL hhmmtostr(scfg_t* cfg, struct tm* tm, char* str);
DLLEXPORT char * DLLCALL timestr(scfg_t* cfg, time_t *intime, char* str);
DLLEXPORT when_t DLLCALL rfc822date(char* p);
DLLEXPORT char * DLLCALL msgdate(when_t when, char* buf);
/* nopen.c */
DLLEXPORT int DLLCALL nopen(char *str, int access);
DLLEXPORT void DLLCALL truncsp(char *str); /* Truncates white spaces off end of str */
DLLEXPORT FILE * DLLCALL fnopen(int *file, char *str, int access);
/* load_cfg.c */
DLLEXPORT BOOL DLLCALL load_cfg(scfg_t* cfg, char* text[], BOOL prep, char* error);
......@@ -800,22 +807,6 @@ extern "C" {
/* scfglib1.c */
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir);
/* date_str.c */
/* ASCII date (MM/DD/YY) to unix conversion */
DLLEXPORT time_t DLLCALL dstrtounix(scfg_t*, char *str);
/* Unix time to ASCII date */
DLLEXPORT char * DLLCALL unixtodstr(scfg_t*, time_t, char *str);
/* seconds to HH:MM:SS */
DLLEXPORT char * DLLCALL sectostr(uint sec, char *str);
/* struct tm to HH:MMa/p */
DLLEXPORT char * DLLCALL hhmmtostr(scfg_t* cfg, struct tm* tm, char* str);
/* time_t to ctime()-like string */
DLLEXPORT char * DLLCALL timestr(scfg_t* cfg, time_t *intime, char* str);
/* RFC822 date header to when_t */
DLLEXPORT when_t DLLCALL rfc822date(char* p);
/* when_t to RFC822 date header */
DLLEXPORT char * DLLCALL msgdate(when_t when, char* buf);
/* logfile.cpp */
DLLEXPORT BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text
,char* host, SOCKADDR_IN* addr);
......@@ -872,8 +863,10 @@ extern "C" {
#endif
/* misc.c */
FILE * fnopen(int *file, char *str, int access);
/* crc32.c */
ulong crc32(char *buf, ulong len);
/* str_util.c */
int bstrlen(char *str);
void backslashcolon(char *str);
void backslash(char *str);
......@@ -881,10 +874,9 @@ ulong ahtoul(char *str); /* Converts ASCII hex to ulong */
char * ultoac(ulong l,char *str);
char * hexplus(uint num, char *str); /* Hex plus for 3 digits up to 9000 */
uint hptoi(char *str);
ulong crc32(char *buf, ulong len);
void ucrc16(uchar ch, ushort *rcrc);
int pstrcmp(char **str1, char **str2); /* Compares pointers to pointers */
int strsame(char *str1, char *str2); /* Compares number of same chars */
void ucrc16(uchar ch, ushort *rcrc);
/* load_cfg.c */
BOOL md(char *path);
......
......@@ -23,10 +23,11 @@ OBJS = $(ODIR)$(SLASH)scfg.$(OFILE)\
$(ODIR)$(SLASH)scfglib2.$(OFILE)\
$(ODIR)$(SLASH)ars.$(OFILE)\
$(ODIR)$(SLASH)load_cfg.$(OFILE)\
$(ODIR)$(SLASH)misc.$(OFILE)\
$(ODIR)$(SLASH)nopen.$(OFILE)\
$(ODIR)$(SLASH)crc32.$(OFILE)\
$(ODIR)$(SLASH)userdat.$(OFILE)\
$(ODIR)$(SLASH)date_str.$(OFILE)\
$(ODIR)$(SLASH)str_util.$(OFILE)\
$(ODIR)$(SLASH)genwrap.$(OFILE)\
$(ODIR)$(SLASH)dirwrap.$(OFILE)\
$(ODIR)$(SLASH)filewrap.$(OFILE)\
......
/* misc.cpp */
/* str_util.c */
/* Synchronet miscellaneous utility-type routines (exported) */
/* Synchronet string utility routines */
/* $Id$ */
......@@ -36,69 +36,159 @@
****************************************************************************/
#include "sbbs.h"
#include "crc32.h"
/****************************************************************************/
/* Network open function. Opens all files DENYALL and retries LOOP_NOPEN */
/* number of times if the attempted file is already open or denying access */
/* for some other reason. All files are opened in BINARY mode. */
/* Removes ctrl-a codes from the string 'instr' */
/****************************************************************************/
int DLLCALL nopen(char *str, int access)
char* DLLCALL remove_ctrl_a(char *instr, char *outstr)
{
int file,share,count=0;
if(access&O_DENYNONE) {
share=SH_DENYNO;
access&=~O_DENYNONE; }
else if(access==O_RDONLY) share=SH_DENYWR;
else share=SH_DENYRW;
if(!(access&O_TEXT))
access|=O_BINARY;
while(((file=sopen(str,access,share))==-1)
&& (errno==EACCES || errno==EAGAIN) && count++<LOOP_NOPEN)
if(count)
mswait(100);
return(file);
char str[1024],*p;
uint i,j;
for(i=j=0;instr[i] && j<sizeof(str)-1;i++) {
if(instr[i]==CTRL_A && instr[i+1]!=0)
i++;
else str[j++]=instr[i];
}
str[j]=0;
if(outstr!=NULL)
p=outstr;
else
p=instr;
strcpy(p,str);
return(p);
}
char* DLLCALL strip_ctrl(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i] && j<(int)sizeof(tmp)-1;i++)
if(str[i]==CTRL_A && str[i+1]!=0)
i++;
else if((uchar)str[i]>=SP)
tmp[j++]=str[i];
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
char* DLLCALL strip_exascii(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i] && j<(int)sizeof(tmp)-1;i++)
if(!(str[i]&0x80))
tmp[j++]=str[i];
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
char* DLLCALL prep_file_desc(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i];i++)
if(str[i]==CTRL_A && str[i+1]!=0)
i++;
else if(j && str[i]<=SP && tmp[j-1]==SP)
continue;
else if(i && !isalnum(str[i]) && str[i]==str[i-1])
continue;
else if((uchar)str[i]>=SP)
tmp[j++]=str[i];
else if(str[i]==TAB || (str[i]==CR && str[i+1]==LF))
tmp[j++]=SP;
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
/****************************************************************************/
/* This function performs an nopen, but returns a file stream with a buffer */
/* allocated. */
/* Pattern matching string search of 'insearchof' in 'fname'. */
/****************************************************************************/
FILE * fnopen(int *fd, char *str, int access)
BOOL DLLCALL findstr(scfg_t* cfg, char* insearchof, char* fname)
{
char mode[128];
int file;
FILE * stream;
if((file=nopen(str,access))==-1)
return(NULL);
if(fd!=NULL)
*fd=file;
if(access&O_APPEND) {
if(access&O_RDONLY)
strcpy(mode,"a+");
else
strcpy(mode,"a");
} else if(access&O_CREAT) {
if(access&O_TRUNC)
strcpy(mode,"w");
else
strcpy(mode,"w+");
} else {
if(access&O_WRONLY || (access&O_RDWR)==O_RDWR)
strcpy(mode,"r+");
else
strcpy(mode,"r");
}
stream=fdopen(file,mode);
if(stream==NULL) {
close(file);
return(NULL);
char* p;
char str[128];
char search[81];
int c;
int i;
BOOL found;
FILE* stream;
if((stream=fopen(fname,"r"))==NULL)
return(FALSE);
SAFECOPY(search,insearchof);
strupr(search);
found=FALSE;
while(!feof(stream) && !ferror(stream) && !found) {
if(!fgets(str,sizeof(str),stream))
break;
found=FALSE;
p=str;
while(*p && *p<=' ') p++; /* Skip white-space */
if(*p==';') /* comment */
continue;
if(*p=='!') { /* !match */
found=TRUE;
p++;
}
truncsp(p);
c=strlen(p);
if(c) {
c--;
strupr(p);
if(p[c]=='~') {
p[c]=0;
if(strstr(search,p))
found=!found;
}
else if(p[c]=='^' || p[c]=='*') {
p[c]=0;
if(!strncmp(p,search,c))
found=!found;
}
else if(p[0]=='*') {
i=strlen(search);
if(i<c)
continue;
if(!strncmp(p+1,search+(i-c),c))
found=!found;
}
else if(!strcmp(p,search))
found=!found;
}
}
setvbuf(stream,NULL,_IOFBF,FNOPEN_BUF_SIZE);
return(stream);
fclose(stream);
return(found);
}
/****************************************************************************/
/* Searches the file <name>.can in the TEXT directory for matches */
/* Returns TRUE if found in list, FALSE if not. */
/****************************************************************************/
BOOL DLLCALL trashcan(scfg_t* cfg, char* insearchof, char* name)
{
char fname[MAX_PATH+1];
sprintf(fname,"%s%s.can",cfg->text_dir,name);
return(findstr(cfg,insearchof,fname));
}
/****************************************************************************/
......@@ -179,54 +269,6 @@ void backslashcolon(char *str)
}
}
/****************************************************************************/
/* Updates 16-bit "rcrc" with character 'ch' */
/****************************************************************************/
void ucrc16(uchar ch, ushort *rcrc)
{
ushort i, cy;
uchar nch=ch;
for (i=0; i<8; i++) {
cy=*rcrc & 0x8000;
*rcrc<<=1;
if (nch & 0x80) *rcrc |= 1;
nch<<=1;
if (cy) *rcrc ^= 0x1021; }
}
/****************************************************************************/
/* Returns CRC-16 of ASCIIZ string (not including terminating NULL) */
/****************************************************************************/
ushort DLLCALL crc16(char *str)
{
int i=0;
ushort crc=0;
ucrc16(0,&crc);
while(str[i])
ucrc16(str[i++],&crc);
ucrc16(0,&crc);
ucrc16(0,&crc);
return(crc);
}
/****************************************************************************/
/* Returns CRC-32 of sequence of bytes (binary or ASCIIZ) */
/* Pass len of 0 to auto-determine ASCIIZ string length */
/* or non-zero for arbitrary binary data */
/****************************************************************************/
ulong crc32(char *buf, ulong len)
{
ulong l,crc=0xffffffff;
if(len==0)
len=strlen(buf);
for(l=0;l<len;l++)
crc=ucrc32(buf[l],crc);
return(~crc);
}
/****************************************************************************/
/* Compares pointers to pointers to char. Used in conjuction with qsort() */
/****************************************************************************/
......@@ -247,8 +289,6 @@ int strsame(char *str1, char *str2)
return(j);
}
#define MV_BUFLEN 4096
/****************************************************************************/
/* Returns an ASCII string for FidoNet address 'addr' */
/****************************************************************************/
......@@ -301,6 +341,9 @@ ulong ahtoul(char *str)
return(val);
}
/****************************************************************************/
/* Converts hex-plus string to integer */
/****************************************************************************/
uint hptoi(char *str)
{
char tmp[128];
......@@ -315,3 +358,35 @@ uint hptoi(char *str)
}
/****************************************************************************/
/* Updates 16-bit "rcrc" with character 'ch' */
/****************************************************************************/
void ucrc16(uchar ch, ushort *rcrc)
{
ushort i, cy;
uchar nch=ch;
for (i=0; i<8; i++) {
cy=*rcrc & 0x8000;
*rcrc<<=1;
if (nch & 0x80) *rcrc |= 1;
nch<<=1;
if (cy) *rcrc ^= 0x1021; }
}
/****************************************************************************/
/* Returns CRC-16 of ASCIIZ string (not including terminating NULL) */
/****************************************************************************/
ushort DLLCALL crc16(char *str)
{
int i=0;
ushort crc=0;
ucrc16(0,&crc);
while(str[i])
ucrc16(str[i++],&crc);
ucrc16(0,&crc);
ucrc16(0,&crc);
return(crc);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment