home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NNTP-1.000 / NNTP-1 / nntp.1.5.11t / server / ahbs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-17  |  2.8 KB  |  138 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)ahbs.c    1.8    (Berkeley) 1/11/88";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. static char    *verbiage[] = {
  8.     "head and body follow",
  9.     "head follows",
  10.     "body follows",
  11.     "request text separately"
  12. };
  13.  
  14. /*
  15.  * {ARTICLE,HEAD,BODY,STAT} <messageid>|articlenum
  16.  *
  17.  * Retrieve article, head, body, or stat, depending on the
  18.  * command we were invoked with.
  19.  */
  20.  
  21. ahbs(argc, argv)
  22.     int        argc;
  23.     char        *argv[];
  24. {
  25.     char        artbuf[MAXPATHLEN], art_id[MAXBUFLEN];
  26.     register char    c;
  27.     int        method;
  28.     register FILE    *fp;        /* For Message-ID retrieval only */
  29.  
  30.     if (argc > 2) {
  31.         printf("%d Usage: %s <message-id>|article_number.\r\n",
  32.             ERR_CMDSYN,argv[0]);
  33.         (void) fflush(stdout);
  34.         return;
  35.     }
  36.  
  37.     if ((c = *argv[0]) == 'a' || c == 'A')
  38.         method = ARTICLE;
  39.     else if ((c == 's' || c == 'S'))
  40.         method = STAT;
  41.     else
  42.         method = ((c == 'h' || c == 'H') ? HEAD : BODY);
  43.  
  44.     if (argc == 2 && *argv[1] == '<') {    /* Message ID */
  45.         fp = openartbyid(argv[1]);
  46.         if (fp == NULL) {
  47.             printf("%d No article by message-id %s, sorry.\r\n",
  48.                 ERR_NOART, argv[1]);
  49.             (void) fflush(stdout);
  50.             return;
  51.         }
  52. #ifdef PR_HACK
  53.         if (check_ngperm(fp) == 0) {
  54.             printf("%d No such article.\r\n",
  55.                 ERR_NOART, argv[1]);
  56.             (void) fflush(stdout);
  57.             return;
  58.         }
  59. #else
  60.         if (check_ngperm(fp) == 0) {
  61.             printf("%d Can't give that to you, sorry.\r\n",
  62.                 ERR_ACCESS);
  63.             (void) fflush(stdout);
  64.             (void) fclose(fp);
  65.             return;
  66.         }
  67. #endif
  68.         printf("%d 0 %s Article retrieved, %s.\r\n",
  69.             OK_ARTICLE + method, argv[1], verbiage[method]);
  70.         spew(fp, method);
  71.         (void) fclose(fp);
  72. #ifdef LOG
  73.         if (nn_told)
  74.             nn_took++;
  75. #endif
  76.         return;
  77.     }
  78.  
  79.     /* Else we're trying to read */
  80.  
  81.     if (!canread) {
  82.         printf("%d You only have permission to transfer, sorry.\r\n",
  83.             ERR_ACCESS);
  84.         (void) fflush(stdout);
  85.         return;
  86.     }
  87.  
  88.     if (!ingroup) {
  89.         printf("%d You are not currently in a newsgroup.\r\n",
  90.             ERR_NCING);
  91.         (void) fflush(stdout);
  92.         return;
  93.     }
  94.  
  95.     if (argc == 1) {
  96.         if (art_ptr < 0 || art_ptr >= num_arts) {
  97.             printf("%d No article is currently selected.\r\n",
  98.                 ERR_NOCRNT);
  99.             (void) fflush(stdout);
  100.             return;
  101.         }
  102.         (void) sprintf(artbuf, "%d", art_array[art_ptr]);
  103.     } else
  104.         (void) strcpy(artbuf, argv[1]);
  105.  
  106.     if (!valid_art(artbuf)) {
  107.         printf("%d Invalid article number: %s.\r\n",
  108.             ERR_NOARTIG, artbuf);
  109.         (void) fflush(stdout);
  110.         return;
  111.     }
  112.  
  113.     while (open_valid_art(artbuf, art_id) == NULL) {
  114.         if (argc > 1) {
  115.             printf("%d Invalid article number: %s.\r\n",
  116.                 ERR_NOARTIG, artbuf);
  117.             (void) fflush(stdout);
  118.             return;
  119.         } else {
  120.             if (++art_ptr >= num_arts) {
  121.                 printf("%d Invalid article number.\r\n",
  122.                     ERR_NOARTIG);
  123.                 (void) fflush(stdout);
  124.                 return;
  125.             }
  126.             (void) sprintf(artbuf, "%d", art_array[art_ptr]);
  127.         }
  128.     }
  129.  
  130.     printf("%d %s %s Article retrieved; %s.\r\n",
  131.         OK_ARTICLE + method, artbuf, art_id, verbiage[method]);
  132.  
  133.     spew(art_fp, method);
  134.  
  135.     if (argc > 1)
  136.         art_ptr = findart(artbuf);
  137. }
  138.