home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / cp2s_223.zip / SYSOP.ZIP / CPHOST.C next >
C/C++ Source or Header  |  1994-07-13  |  4KB  |  162 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <io.h>
  6.  
  7. #define TRUE  1
  8. #define FALSE 0
  9.  
  10. void main(int ac,char **av)
  11. {
  12.    FILE  *fd,
  13.          *wfd;
  14.    char  tbuf[512],
  15.          name[36],
  16.          *p;
  17.    int   n=0,
  18.          point=0,
  19.          files=0,
  20.          count=0,
  21.          found=FALSE;
  22.    long  pos;
  23.    char  *rmlead(char *);
  24.    char  *rmtrail(char *);
  25.  
  26.    /* these just prevent an annoying compiler warning with tc++ */
  27.  
  28.    ac--;
  29.    point--;
  30.  
  31.  
  32.    printf("\ncPHost v1.00 - (c)1994 Simon Ewins - All Rights Reserved\n");
  33.    printf("\nCompiled: "__DATE__" @ "__TIME__"\n");
  34.    printf("\nUsage: cPHost <session_log_path> <user_notes_file> <func_req_file>\n\n");
  35.  
  36.    /* D'Bridge creates a file called Caller.Inf when it gets a function */
  37.    /* request file. This file contains three or four lines that give    */
  38.    /* you some info on the current caller. All I use is the name which  */
  39.    /* the caller's name. The Users.Txt file that I use contains each    */
  40.    /* point's name and then a comment that is written to the log file   */
  41.    /* that is sent to the user. There doesn't seem to be a standard way */
  42.    /* of handling function requests so you are really on your own here! */
  43.  
  44.    fd=fopen("Caller.Inf","rt");
  45.    if(!fd)
  46.       exit(0);
  47.  
  48.    /* create the session log file. D'Bridge has its function requests */
  49.    /* set up such that I tell it which file to send the caller. I use */
  50.    /* Session.Log but this will, once again, depend on the mailer you */
  51.    /* are using.                                                      */
  52.  
  53.    wfd=fopen(av[1],"w+t");
  54.    if(!wfd) {
  55.       fclose(fd);
  56.       exit(0);
  57.    }
  58.    fprintf(wfd,"Session log:\n\n");
  59.    fgets(tbuf,81,fd);   /* skip address */
  60.    p=strchr(tbuf,'.');
  61.    if(p) point=atoi(p+1);
  62.    fprintf(wfd,tbuf);
  63.    fgets(tbuf,81,fd);   /* skip system name */
  64.    fprintf(wfd,tbuf);
  65.    fgets(tbuf,81,fd);   /* read caller's name */
  66.    fprintf(wfd,tbuf);
  67.    fclose(fd);
  68.    fprintf(wfd,"\n");
  69.    strncpy(name,tbuf,35);
  70.    rmlead(rmtrail(name));
  71.  
  72.    /* now we read the Users.Txt file and if we find the current caller's */
  73.    /* name we attach the comment part of the line to the log file.       */
  74.  
  75.    fd=fopen(av[2],"r+t");
  76.    fgets(tbuf,81,fd);
  77.    while(!feof(fd)) {
  78.       rmlead(rmtrail(tbuf));
  79.       if(!strnicmp(name,tbuf,strlen(name))) {
  80.          p=strchr(tbuf,':');
  81.          p++;
  82.          fprintf(wfd,"%s\n\n",p);
  83.  
  84.          // check first character after user's name:
  85.          //
  86.          // if == - then errorlevel is 1 and .Req file is deleted
  87.          // if == + then errorlevel is 0 and .Req file is approved
  88.          // if == ! then errorlevel is 0 but the number is limited to the
  89.          //         number immediately after the ! character
  90.  
  91.          if(tbuf[strlen(name)]=='!') {
  92.             found=TRUE;
  93.             files=atoi(&tbuf[strlen(name)+1]);
  94.          }
  95.          if(tbuf[strlen(name)]=='+') {
  96.             found=TRUE;
  97.             files=99;
  98.          }
  99.          if(tbuf[strlen(name)]=='-') {
  100.             found=TRUE;
  101.             n=1;
  102.          }
  103.          break;
  104.       }
  105.       fgets(tbuf,81,fd);
  106.    }
  107.    fclose(fd);
  108.    if(!found) {
  109.       fprintf(wfd,"Above not recognized as a valid user ID.\n");
  110.       n=1;
  111.    }
  112.    if(found && !n) {
  113.       fd=fopen(av[3],"r+t");
  114.       if(fd) {
  115.          fprintf(wfd,"The following files will be sent if they are found\nand any required passwords are correct:\n\n");
  116.          pos=ftell(fd);
  117.          count++;
  118.          fgets(tbuf,81,fd);
  119.          while(!feof(fd) && count<=files) {
  120.             rmlead(rmtrail(tbuf));
  121.             fprintf(wfd,"%s\n",tbuf);
  122.             pos=ftell(fd);
  123.             count++;
  124.             fgets(tbuf,81,fd);
  125.          }
  126.          chsize(fileno(fd),pos);
  127.          fclose(fd);
  128.       }
  129.    }
  130.    fclose(wfd);
  131.    printf("Done.\n\n");
  132.  
  133.    /* if n==1 then we had a problem with this caller's downloading anything */
  134.  
  135.    exit(n);
  136. }
  137.  
  138.  
  139. char *rmlead(char *str)
  140. {
  141.    char *obuf;
  142.  
  143.    for (obuf=str;obuf && *obuf && isspace(*obuf);++obuf)
  144.             ;
  145.    if(str!=obuf) strcpy(str,obuf);
  146.    return(str);
  147. }
  148.  
  149.  
  150. char *rmtrail(char *str)
  151. {
  152.    int i;
  153.  
  154.    if(0!=(i=strlen(str))) {
  155.       while(--i>=0) {
  156.          if(!isspace(str[i])) break;
  157.       }
  158.       str[++i]=NULL;
  159.    }
  160.    return(str);
  161. }
  162.