home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
cp2s_223.zip
/
SYSOP.ZIP
/
CPHOST.C
next >
Wrap
C/C++ Source or Header
|
1994-07-13
|
4KB
|
162 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#define TRUE 1
#define FALSE 0
void main(int ac,char **av)
{
FILE *fd,
*wfd;
char tbuf[512],
name[36],
*p;
int n=0,
point=0,
files=0,
count=0,
found=FALSE;
long pos;
char *rmlead(char *);
char *rmtrail(char *);
/* these just prevent an annoying compiler warning with tc++ */
ac--;
point--;
printf("\ncPHost v1.00 - (c)1994 Simon Ewins - All Rights Reserved\n");
printf("\nCompiled: "__DATE__" @ "__TIME__"\n");
printf("\nUsage: cPHost <session_log_path> <user_notes_file> <func_req_file>\n\n");
/* D'Bridge creates a file called Caller.Inf when it gets a function */
/* request file. This file contains three or four lines that give */
/* you some info on the current caller. All I use is the name which */
/* the caller's name. The Users.Txt file that I use contains each */
/* point's name and then a comment that is written to the log file */
/* that is sent to the user. There doesn't seem to be a standard way */
/* of handling function requests so you are really on your own here! */
fd=fopen("Caller.Inf","rt");
if(!fd)
exit(0);
/* create the session log file. D'Bridge has its function requests */
/* set up such that I tell it which file to send the caller. I use */
/* Session.Log but this will, once again, depend on the mailer you */
/* are using. */
wfd=fopen(av[1],"w+t");
if(!wfd) {
fclose(fd);
exit(0);
}
fprintf(wfd,"Session log:\n\n");
fgets(tbuf,81,fd); /* skip address */
p=strchr(tbuf,'.');
if(p) point=atoi(p+1);
fprintf(wfd,tbuf);
fgets(tbuf,81,fd); /* skip system name */
fprintf(wfd,tbuf);
fgets(tbuf,81,fd); /* read caller's name */
fprintf(wfd,tbuf);
fclose(fd);
fprintf(wfd,"\n");
strncpy(name,tbuf,35);
rmlead(rmtrail(name));
/* now we read the Users.Txt file and if we find the current caller's */
/* name we attach the comment part of the line to the log file. */
fd=fopen(av[2],"r+t");
fgets(tbuf,81,fd);
while(!feof(fd)) {
rmlead(rmtrail(tbuf));
if(!strnicmp(name,tbuf,strlen(name))) {
p=strchr(tbuf,':');
p++;
fprintf(wfd,"%s\n\n",p);
// check first character after user's name:
//
// if == - then errorlevel is 1 and .Req file is deleted
// if == + then errorlevel is 0 and .Req file is approved
// if == ! then errorlevel is 0 but the number is limited to the
// number immediately after the ! character
if(tbuf[strlen(name)]=='!') {
found=TRUE;
files=atoi(&tbuf[strlen(name)+1]);
}
if(tbuf[strlen(name)]=='+') {
found=TRUE;
files=99;
}
if(tbuf[strlen(name)]=='-') {
found=TRUE;
n=1;
}
break;
}
fgets(tbuf,81,fd);
}
fclose(fd);
if(!found) {
fprintf(wfd,"Above not recognized as a valid user ID.\n");
n=1;
}
if(found && !n) {
fd=fopen(av[3],"r+t");
if(fd) {
fprintf(wfd,"The following files will be sent if they are found\nand any required passwords are correct:\n\n");
pos=ftell(fd);
count++;
fgets(tbuf,81,fd);
while(!feof(fd) && count<=files) {
rmlead(rmtrail(tbuf));
fprintf(wfd,"%s\n",tbuf);
pos=ftell(fd);
count++;
fgets(tbuf,81,fd);
}
chsize(fileno(fd),pos);
fclose(fd);
}
}
fclose(wfd);
printf("Done.\n\n");
/* if n==1 then we had a problem with this caller's downloading anything */
exit(n);
}
char *rmlead(char *str)
{
char *obuf;
for (obuf=str;obuf && *obuf && isspace(*obuf);++obuf)
;
if(str!=obuf) strcpy(str,obuf);
return(str);
}
char *rmtrail(char *str)
{
int i;
if(0!=(i=strlen(str))) {
while(--i>=0) {
if(!isspace(str[i])) break;
}
str[++i]=NULL;
}
return(str);
}