home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XT.ZIP / RNEWS / ACTIVE.C next >
Encoding:
C/C++ Source or Header  |  1992-11-22  |  8.3 KB  |  287 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    a c t i v e . c                                                 */
  3. /*                                                                    */
  4. /*    Load and write UUPC/extended news active file                   */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*
  8.  *    $Id: ACTIVE.C 1.2 1992/11/23 03:56:06 ahd Exp $
  9.  *
  10.  *    $Log: ACTIVE.C $
  11.  * Revision 1.2  1992/11/23  03:56:06  ahd
  12.  * Use strpool for news group names
  13.  *
  14.  */
  15.  
  16. /*
  17.    This file contains routines that muck with the "active" file.
  18.  
  19.    The file is named "active" and is in the configuration directory
  20.    defined in UUPC.RC.
  21.  
  22.    The file is a direct copy of the UNIX active file which is
  23.    defined and described in the Nutshell book "Managing UUCP
  24.    and Usenet".
  25.  
  26.    IMPORTANT:
  27.    ----------
  28.       Almost no checking is performed on the contents of the file.
  29.       It is critically important that the system administrator
  30.       maintain the file carefully.
  31.  
  32.    The file consists of one line for each newsgroup to be received.
  33.    Articles destined for newsgroups which do not have a line in the
  34.    active file are lost.
  35.  
  36.    Each line consists of four fields separated by spaces.
  37.  
  38.    The fields are:
  39.  
  40.       group high low post
  41.  
  42.    where:
  43.       group the newsgroup name.  Case is important.  E.g., ba.food
  44.             This field is maintained by the administrator.
  45.             This field must be less than 50 characters long.
  46.  
  47.       high  highest article number in the group.  (Zero for a
  48.             new group.)  This field is maintained by rnews.
  49.  
  50.       low   lowest article number in the group.  (Zero for a
  51.             new group.)  This field is maintained by expire.
  52.  
  53.       post  can the user post to this newsgroup.  A single
  54.             character. 'y' for yes; 'n' for no; 'm'
  55.             for moderated.  This field is maintained
  56.             by the administrator.
  57.  
  58. */
  59.  
  60. #include <stdio.h>
  61.  
  62. #ifndef __GNUC__
  63. #include <io.h>
  64. #include <conio.h>
  65. #endif
  66.  
  67. #include <stdlib.h>
  68. #include <string.h>
  69. #include <ctype.h>
  70. #include <time.h>
  71. #include <sys/types.h>
  72. #include <sys\stat.h>
  73. #include <errno.h>
  74.  
  75. #ifdef __TURBOC__
  76. #include <dir.h>
  77. #endif
  78.  
  79. #include "lib.h"
  80. #include "hlib.h"
  81. #include "timestmp.h"
  82. #include "rnews.h"
  83. #include "active.h"
  84. #include "importng.h"
  85.  
  86. #include "getopt.h"
  87.  
  88. currentfile();
  89.  
  90. static boolean fallback = FALSE;
  91.  
  92. struct grp *group_list = NULL;      /* List of all groups */
  93.  
  94. /*--------------------------------------------------------------------*/
  95. /*    g e t _ a c t i v e                                             */
  96. /*                                                                    */
  97. /*    This function opens <newsdir>/active and extracts all the       */
  98. /*    information about the newsgroup we currently maintain           */
  99. /*--------------------------------------------------------------------*/
  100.  
  101. void get_active( void )
  102. {
  103.    char active_filename[FILENAME_MAX];
  104.    char grp_name_tmp[51];     /* Space to hold the group field being read in */
  105.    FILE *g;
  106.    struct grp *cur_grp;
  107.    struct grp *prev_grp;
  108.    int i;
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*    Open the active file and extract all the newsgroups and         */
  112. /*    their next number.                                              */
  113. /*--------------------------------------------------------------------*/
  114.  
  115. /*--------------------------------------------------------------------*/
  116. /*     Try configuration directory first, then try news directory     */
  117. /*--------------------------------------------------------------------*/
  118.  
  119.    mkfilename(active_filename, E_confdir, ACTIVE);
  120.    g = FOPEN(active_filename,"r",TEXT);
  121.  
  122.    if (g == NULL)
  123.    {
  124.       printerr(active_filename);
  125.  
  126.       mkfilename(active_filename, E_newsdir, ACTIVE);
  127.       fallback= TRUE;
  128.       g = FOPEN(active_filename,"r",TEXT);
  129.    } /* if */
  130.  
  131.    if (g == NULL) {
  132.       printerr(active_filename);
  133.       panic();
  134.    }
  135.  
  136.    prev_grp = NULL;
  137.  
  138.    group_list = (struct grp *) malloc(sizeof(struct grp));
  139.    cur_grp = group_list;
  140.  
  141.    cur_grp->grp_next = NULL;
  142.    cur_grp->grp_name = NULL;
  143.    cur_grp->grp_low  = 0;
  144.    cur_grp->grp_high = 0;
  145.    cur_grp->grp_can_post = ' ';
  146.  
  147.    while ((i = fscanf(g, "%s %ld %ld %1s\n", &grp_name_tmp[0],
  148.             &cur_grp->grp_high,
  149.             &cur_grp->grp_low,
  150.             &cur_grp->grp_can_post)) != EOF)
  151.    {
  152.       if (i != 4)
  153.       {
  154.          printmsg(0,"rnews: incomplete line in %s, %d tokens found",
  155.                      active_filename, i);
  156.          panic();
  157.       }
  158.  
  159.       cur_grp->grp_name = newstr(grp_name_tmp);
  160.  
  161.       cur_grp->grp_high++;    /* It is stored as one less than we want it */
  162.  
  163.       prev_grp = cur_grp;
  164.       cur_grp = (struct grp *) malloc(sizeof(struct grp));
  165.       checkref(cur_grp);
  166.       prev_grp->grp_next = cur_grp;
  167.  
  168.       cur_grp->grp_next = NULL;
  169.       cur_grp->grp_name = NULL;
  170.       cur_grp->grp_low  = 0;
  171.       cur_grp->grp_high = 0;
  172.       cur_grp->grp_can_post = ' ';
  173.  
  174.    } /* while */
  175.  
  176.    if (fclose(g))
  177.       printerr( active_filename );
  178.  
  179.    if (prev_grp != NULL) {
  180.       prev_grp->grp_next = NULL;
  181.       free(cur_grp);
  182.    }
  183.  
  184.    return;
  185. } /* get_active */
  186.  
  187. /*--------------------------------------------------------------------*/
  188. /*    p u t _ a c t i v e                                             */
  189. /*                                                                    */
  190. /*    Update current active file                                      */
  191. /*--------------------------------------------------------------------*/
  192.  
  193. void put_active()
  194. {
  195.    char active_filename[FILENAME_MAX];
  196.    FILE *g;
  197.    struct grp *cur_grp;
  198.  
  199.    mkfilename(active_filename, E_confdir, ACTIVE);
  200.  
  201.    filebkup( active_filename );
  202.  
  203.    g = FOPEN(active_filename,"w",TEXT);
  204.  
  205.    if (g == NULL) {
  206.       printmsg(0, "rnews: Cannot update active %s", active_filename );
  207.       printerr(active_filename);
  208.       panic();
  209.    }
  210.  
  211.    cur_grp = group_list;
  212.  
  213. /*--------------------------------------------------------------------*/
  214. /*           Loop to actually write out the updated groups            */
  215. /*--------------------------------------------------------------------*/
  216.  
  217.    while ((cur_grp != NULL) && (cur_grp->grp_name != NULL))
  218.    {
  219.       fprintf(g, "%s %ld %ld %c\n", cur_grp->grp_name,
  220.                               cur_grp->grp_high-1,
  221.                               cur_grp->grp_low,
  222.                               cur_grp->grp_can_post);
  223.       cur_grp = cur_grp->grp_next;
  224.    }
  225.  
  226.    fclose(g);
  227.  
  228. /*--------------------------------------------------------------------*/
  229. /*    Delete old (now obsolete) active file in the news directory     */
  230. /*--------------------------------------------------------------------*/
  231.  
  232.    if ( fallback )
  233.    {
  234.       mkfilename(active_filename, E_newsdir, ACTIVE);
  235.       filebkup( active_filename );
  236.    }
  237.  
  238. } /* put_active */
  239.  
  240. /*--------------------------------------------------------------------*/
  241. /*    v a l i d a t e _ n e w s g r o u p s                           */
  242. /*                                                                    */
  243. /*    Verify all the directories for news groups exist                */
  244. /*--------------------------------------------------------------------*/
  245.  
  246. void validate_newsgroups( void )
  247. {
  248.    char full_dirname[FILENAME_MAX];
  249.  
  250.    struct stat buff;
  251.  
  252.    struct grp *cur_grp;
  253.    int i;
  254.  
  255.    cur_grp = group_list;
  256.    while (cur_grp != NULL) {
  257.       ImportNewsGroup( full_dirname , cur_grp->grp_name, 0 );
  258.  
  259.       i = stat(full_dirname, &buff);
  260.       if (i != 0) {
  261.          /* Directory does not exist, create it */
  262.          printmsg(4,"Directory %s does not exist for group %s",
  263.                      full_dirname, cur_grp->grp_name );
  264.  
  265. #ifdef WASTE_SPACE
  266.          i = MKDIR(full_dirname);
  267.          if (i != 0) {
  268.             printf("Unable to create %s\n", full_dirname);
  269.             panic();
  270.          }
  271. #endif
  272.  
  273.       } else {
  274.          /* It exists.  Ensure that it is a directory */
  275.          if (!(buff.st_mode & S_IFDIR)) {
  276.             /* Yukk! */
  277.             printmsg(0,"validate_newsgroups: %s is a file not a directory",
  278.                    full_dirname);
  279.             panic();
  280.          }
  281.        }
  282.       cur_grp = cur_grp->grp_next;
  283.    }
  284.  
  285.    return;
  286. } /* validate_newsgroups */
  287.