home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / uqwk / part01 / reply.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  5.0 KB  |  217 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "uqwk.h"
  4. /*
  5.  *  Process a reply packet
  6.  */
  7.  
  8. DoReply ()
  9. {
  10.     int n, rep_cnt;
  11.     char bbs[PATH_LEN];
  12.  
  13.     rep_cnt = 0;
  14.  
  15.     /* Open the packet */
  16.     if (NULL == (rep_fd = fopen (rep_file, "r")))
  17.     {
  18.         fprintf (stderr, "%s: can't open %s\n", progname, rep_file);
  19.         return (0);
  20.     }
  21.  
  22.     /* Get the first block, the BBS ID */
  23.     if (1 != fread (buf, 128, 1, rep_fd))
  24.     {
  25.         fprintf (stderr, "%s: reply packet read error\n", progname);
  26.         fclose (rep_fd);
  27.         return (0);
  28.     }
  29.  
  30.     /* Extract bbs id and check */
  31.     sscanf (bbs_id, "%*d,%s", bbs);
  32.     n = strlen (bbs);
  33.     buf[n] = 0;
  34.     if (strcmp (bbs, buf))
  35.     {
  36.         fprintf (stderr, "%s: reply BBS ID mismatch: %s != %s\n",
  37.             progname, buf, bbs);
  38.         fclose (rep_fd);
  39.         return (0);
  40.     }
  41.  
  42.     /* Read the .newsrc file; we will need the list of conferences */
  43.     ReadNewsrc();
  44.  
  45.     /* Read the next message header and process it */
  46.     while (1 == fread (&rep_hdr, 128, 1, rep_fd))
  47.     {
  48.         SendReply ();
  49.         rep_cnt++;
  50.     }
  51.  
  52.     fclose (rep_fd);
  53.     printf ("%s: sent %d replies\n", progname, rep_cnt);
  54. }
  55.  
  56. SendReply ()
  57. /*
  58.  *  Pipe a reply to the mailer or inews
  59.  */
  60. {
  61.     FILE *pfd;
  62.     unsigned char c, to[PATH_LEN], subject[PATH_LEN], group[PATH_LEN];
  63.     int i, n, blocks, bytes, conf;
  64.     struct nrc_ent *np;
  65.  
  66.     /* Extract recipient */
  67.     strncpy (buf, rep_hdr.to, 25);
  68.     buf[25] = 0;
  69.     sscanf (buf, "%s", to);
  70.  
  71.     /* Extract conference number */
  72.     strncpy (buf, rep_hdr.number, 7);
  73.     buf[7] = 0;
  74.     sscanf (buf, "%d", &conf);
  75.  
  76.     /* Extract subject */
  77.     strncpy (buf, rep_hdr.subject, 25);
  78.     buf[25] = 0;
  79.     strcpy (subject, buf);
  80.  
  81.     /* Get rid of single quotes in subject */
  82.     n = strlen (subject);
  83.     for (i=0; i<n; i++) if (subject[i] == '\'') subject[i] = '`';
  84.  
  85.     /* Find newsgroup with this conference number */
  86.     np = nrc_list;
  87.     while (np != NULL)
  88.     {
  89.         if (np->conf == conf) break;
  90.         np = np->next;
  91.     }
  92.  
  93.     /* Get newsgroup name */
  94.     if (np == NULL)
  95.     {
  96.         /* Bet this generates lots of email for "ALL" */
  97.         rep_hdr.status = QWK_PRIVATE;
  98.     }
  99.     else
  100.     {
  101.         strcpy (group, np->name);
  102.     }
  103.  
  104.     /* Extract block count */
  105.     strncpy (buf, rep_hdr.blocks, 6);
  106.     buf[6] = 0;
  107.     sscanf (buf, "%d", &blocks);
  108.     blocks -= 1;
  109.     bytes = 128 * blocks;
  110.  
  111.     /* Check for off-line command message */
  112.     if ( (!strcmp (to, "uqwk")) || (!strcmp (to, "UQWK")) )
  113.     {
  114.         OffLine (bytes);
  115.         return (0);
  116.     }
  117.  
  118.     /* Check for a configuration message intended for some
  119.        other QWK "door" */
  120.     if ( (!strcmp (to, "MARKMAIL")) || (!strcmp (to, "QMAIL"))   ||
  121.          (!strcmp (to, "markmail")) || (!strcmp (to, "qmail"))   ||
  122.          (!strcmp (to, "ROSEMAIL")) || (!strcmp (to, "KMAIL"))   ||
  123.          (!strcmp (to, "rosemail")) || (!strcmp (to, "kmail"))   ||
  124.          (!strcmp (to, "MAINMAIL")) || (!strcmp (to, "CMPMAIL")) ||
  125.          (!strcmp (to, "mainmail")) || (!strcmp (to, "cmpmail")) ||
  126.          (!strcmp (to, "ULTRABBS")) || (!strcmp (to, "BGQWK"))   ||
  127.          (!strcmp (to, "ultrabbs")) || (!strcmp (to, "bgqwk"))   ||
  128.          (!strcmp (to, "CAM-MAIL")) || (!strcmp (to, "TRIMAIL")) ||
  129.          (!strcmp (to, "cam-mail")) || (!strcmp (to, "trimail")) ||
  130.          (!strcmp (to, "QSO")) || (!strcmp (to, "qso")) )
  131.     {
  132.         /* Send warning to user */
  133.         SendWarning (to);
  134.  
  135.         /* Skip the rest of the message */
  136.         while (bytes--) fread (&c, 1, 1, rep_fd);
  137.  
  138.         return (0);
  139.     }
  140.  
  141.     /* Open pipe to proper program */
  142.     pfd = NULL;
  143.  
  144.     if ( (rep_hdr.status == QWK_PUBLIC) ||
  145.          (rep_hdr.status == QWK_PUBLIC2) )
  146.     {
  147.         /* Public message, open pipe to inews */
  148.         sprintf (buf, "%s -t '%s' -n %s", INEWS_PATH, subject, group);
  149.         printf ("%s\n", buf);
  150.         if (NULL == (pfd = popen (buf, "w")))
  151.         {
  152.             fprintf (stderr, "%s: can't popen() inews\n",
  153.                     progname);
  154.         }
  155.     }
  156.     else if ( (rep_hdr.status == QWK_PRIVATE) ||
  157.               (rep_hdr.status == QWK_PRIVATE2) )
  158.     {
  159.         /* Open pipe to mail */
  160.         sprintf (buf, "%s -s '%s' %s", MAILER_PATH, subject, to);
  161.         printf ("%s\n", buf);
  162.         if (NULL == (pfd = popen (buf, "w")))
  163.         {
  164.             fprintf (stderr, "%s: can't popen() mail\n", progname);
  165.         }
  166.     }
  167.  
  168.     /* Read and send all bytes of message */
  169.     for (i=0; i<bytes; i++)
  170.     {
  171.         fread (&c, 1, 1, rep_fd);
  172.         if (c == QWK_EOL) c = 012;
  173.         if (pfd != NULL) fwrite (&c, 1, 1, pfd);
  174.     }
  175.  
  176.     if (pfd != NULL) pclose (pfd);
  177. }
  178.  
  179. SendWarning (to)
  180. char *to;
  181. /*
  182.  *  Mail a warning to the user if the reply packet
  183.  *  contains a message apparently for some other QWK
  184.  *  "door" program.
  185.  */
  186. {
  187.     FILE *pfd;
  188.  
  189.     /* Open pipe to mailer */
  190.     sprintf (buf, "%s -s 'UQWK Error Message' %s",
  191.             MAILER_PATH, user_name);
  192.     if (NULL == (pfd = popen (buf, "w")))
  193.     {
  194.         fprintf (stderr, "%s: can't popen() mail\n", progname);
  195.         return (0);
  196.     }
  197.  
  198.     /* Send the message */
  199.  
  200.     fprintf (pfd,
  201. "Hello. You sent a message to the username %s, presumably to\n", to);
  202.     fprintf (pfd,
  203. "perform some sort of offline configuration. This QWK processor,\n");
  204.     fprintf (pfd,
  205. "called UQWK, cannot process this message. To perform offline\n");
  206.     fprintf (pfd,
  207. "configuration using UQWK, you must send a message to the username\n");
  208.     fprintf (pfd,
  209. "UQWK. Commands are to be included in the body of the message.\n");
  210.     fprintf (pfd,
  211. "For a list of commands, send a message to UQWK with the word\n");
  212.     fprintf (pfd,
  213. "HELP in the body of the message (not the subject). Thanks!\n");
  214.  
  215.     pclose (pfd);
  216. }
  217.