home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / ngdata.c < prev    next >
Text File  |  1990-08-22  |  8KB  |  351 lines

  1. /* $Header: ngdata.c,v 4.3.2.10 90/04/14 22:05:15 sob Exp $
  2.  *
  3.  * $Log:    ngdata.c,v $
  4.  * Revision 4.3.2.10  90/04/14  22:05:15  sob
  5.  * Removed redundant declaration of active_name
  6.  * 
  7.  * Revision 4.3.2.9  90/03/22  23:04:55  sob
  8.  * Fixes provided by Wayne Davison <drivax!davison>
  9.  * 
  10.  * Revision 4.3.2.8  90/03/17  20:50:51  sob
  11.  * Fixes provided by stewart@netxcom.iad-nxe.global-mis.dhl.com to handle
  12.  * flaky transfers of the active file from the server.
  13.  * 
  14.  * Revision 4.3.2.7  90/03/17  17:11:08  sob
  15.  * Added support for CNEWS active file flags.
  16.  *
  17.  * Revision 4.3.2.6  89/12/08  22:42:04  sob
  18.  * Corrected typo in an #ifdef statement pointed out by
  19.  * jik@pit-manager.mit.edu
  20.  * 
  21.  * Revision 4.3.2.5  89/11/28  01:51:14  sob
  22.  * Removed redundant #include directive.
  23.  * 
  24.  * Revision 4.3.2.4  89/11/27  01:31:07  sob
  25.  * Altered NNTP code per ideas suggested by Bela Lubkin
  26.  * <filbo@gorn.santa-cruz.ca.us>
  27.  * 
  28.  * Revision 4.3.2.3  89/11/08  02:41:40  sob
  29.  * Removed unneeded subroutine.
  30.  * 
  31.  * Revision 4.3.2.2  89/11/08  02:24:31  sob
  32.  * Integrated modifications from other RRN patches colleceted from USENET
  33.  * 
  34.  * Revision 4.3.2.1  89/11/06  00:42:43  sob
  35.  * Added RRN support from NNTP 1.5
  36.  * 
  37.  * Revision 4.3  85/05/01  11:44:38  lwall
  38.  * Baseline for release with 4.3bsd.
  39.  * 
  40.  */
  41.  
  42. #include "EXTERN.h"
  43. #include "common.h"
  44. #include "ndir.h"
  45. #include "rcstuff.h"
  46. #include "rn.h"
  47. #include "intrp.h"
  48. #include "final.h"
  49. #include "rcln.h"
  50. #include "util.h"
  51. #ifdef SERVER
  52. #include "server.h"
  53. #endif
  54. #include "INTERN.h"
  55. #include "ngdata.h"
  56.  
  57. void
  58. ngdata_init()
  59. {
  60. #ifdef SERVER
  61.     char ser_line[256];
  62.     char *cp;
  63.     int entries;
  64. #endif
  65. /* The following is only for systems that do not zero globals properly */
  66. #ifdef ZEROGLOB
  67. # ifdef CACHEFIRST
  68.     for (i=0; i<MAXRCLINE; i++)
  69.     abs1st[i] = 0;
  70. # endif
  71. #endif    /* ZEROGLOB */
  72.  
  73.     /* open the active file */
  74.  
  75. #ifdef SERVER
  76.  
  77.     put_server("LIST");        /* tell server we want the active file */
  78.     get_server(ser_line, sizeof(ser_line));
  79.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  80.     fprintf(stdout, "Can't get active file from server: \n%s\n", ser_line);
  81.     finalize(1);
  82.     }
  83.  
  84.     cp = filexp("/tmp/rrnact.%$");    /* make a temporary name */
  85.     strcpy(active_name, cp);
  86.     actfp = fopen(active_name, "w+");    /* and get ready */
  87.     if (actfp == Nullfp) {
  88.     printf(cantopen,active_name) FLUSH;
  89.     finalize(1);
  90.     }
  91.  
  92.     entries = 0;
  93.     while (1) {
  94.     if (get_server(ser_line, sizeof(ser_line)) < 0) {
  95.         printf("Can't get active file from server:\ntransfer failed after %d entries\n", entries);
  96.         finalize(1);
  97.     }
  98.     if (ser_line[0] == '.')        /* while there's another line */
  99.         break;            /* get it and write it to */
  100.     entries++;
  101.     fputs(ser_line, actfp);
  102.     putc('\n', actfp);
  103.     }
  104.  
  105.     fseek(actfp,0L,0);        /* just get to the beginning */
  106.  
  107. #else not SERVER
  108.  
  109.     actfp = fopen(filexp(ACTIVE),"r");
  110.     if (actfp == Nullfp) {
  111.     printf(cantopen,filexp(ACTIVE)) FLUSH;
  112.     finalize(1);
  113.     }
  114. #endif SERVER
  115. }
  116.  
  117. /* find the maximum article number of a newsgroup */
  118.  
  119. ART_NUM
  120. getngsize(num)
  121. register NG_NUM num;
  122. {
  123.     register int len;
  124.     register char *nam;
  125.     char tmpbuf[80];
  126.     ART_POS oldsoft;
  127.  
  128.     nam = rcline[num];
  129.     len = rcnums[num] - 1;
  130.     softtries++;
  131. #ifdef DEBUGGING
  132.     if (debug & DEB_SOFT_POINTERS)
  133.     printf("Softptr = %ld\n",(long)softptr[num]) FLUSH;
  134. #endif
  135.     oldsoft = softptr[num];
  136.     if ((softptr[num] = findact(tmpbuf, nam, len, (long)oldsoft)) >= 0) {
  137.     if (softptr[num] != oldsoft) {
  138.         softmisses++;
  139.         writesoft = TRUE;
  140.     }
  141.     }
  142.     else {
  143.     softptr[num] = 0;
  144.     if (rcchar[num] == ':')        /* unsubscribe quietly */
  145.         rcchar[num] = NEGCHAR;
  146.     return TR_BOGUS;        /* well, not so quietly, actually */
  147.     }
  148.     
  149. #ifdef DEBUGGING
  150.     if (debug & DEB_SOFT_POINTERS) {
  151.     printf("Should be %ld\n",(long)softptr[num]) FLUSH;
  152.     }
  153. #endif
  154. #ifdef MININACT
  155.     {
  156.     register char *s;
  157.     ART_NUM tmp;
  158.  
  159.     for (s=tmpbuf+len+1; isdigit(*s); s++) ;
  160.     if (tmp = atol(s))
  161. #ifdef CACHEFIRST
  162.         abs1st[num] = tmp;
  163. #else
  164.         abs1st = tmp;
  165. #endif
  166.     if (!in_ng) {
  167.         for (s++; isdigit(*s); s++) ;
  168.         while (isspace(*s)) s++;
  169.         switch (*s) {
  170.         case 'n': moderated = getval("NOPOSTRING"," (no posting)"); break;
  171.         case 'm': moderated = getval("MODSTRING", " (moderated)"); break;
  172.         /* This shouldn't even occur.  What are we doing in a non-existent
  173.            group?  Disallow it. */
  174.         case 'x': return TR_BOGUS;
  175.         /* what should be done about refiled groups?  rn shouldn't even
  176.            be in them (ie, if sci.aquaria is refiled to rec.aquaria, then
  177.            get the news there) */
  178.         case '=': return TR_BOGUS;
  179.         default: moderated = nullstr;
  180.         }
  181.     }
  182.     }
  183. #endif
  184.     return atol(tmpbuf+len+1);
  185. }
  186.  
  187. ACT_POS
  188. findact(outbuf,nam,len,suggestion)
  189. char *outbuf;
  190. char *nam;
  191. int len;
  192. long suggestion;
  193. {
  194.     ACT_POS retval;
  195.  
  196.     fseek(actfp,100000L,1);    /* hopefully this forces a reread */
  197.     if (suggestion == 0L || fseek(actfp,suggestion,0) < 0 ||
  198.       fgets(outbuf,80,actfp) == Nullch ||
  199.       outbuf[len] != ' ' ||
  200.       strnNE(outbuf,nam,len)) {
  201. #ifdef DEBUGGING
  202.     if (debug & DEB_SOFT_POINTERS)
  203.         printf("Missed, looking for %s in %sLen = %d\n",nam,outbuf,len)
  204.           FLUSH;
  205. #endif
  206.     fseek(actfp,0L,0);
  207. #ifndef lint
  208.     retval = (ACT_POS)ftell(actfp);
  209. #else
  210.     retval = Null(ACT_POS);
  211. #endif lint
  212.     while (fgets(outbuf,80,actfp) != Nullch) {
  213.         if (outbuf[len] == ' ' && strnEQ(outbuf,nam,len))
  214.         return retval;
  215. #ifndef lint
  216.         retval = (ACT_POS) ftell(actfp);
  217. #endif lint
  218.     }
  219.     return (ACT_POS) -1;        /* well, not so quietly, actually */
  220.     }
  221.     else
  222. #ifndef lint
  223.     return (ACT_POS) suggestion;
  224. #else
  225.     return retval;
  226. #endif lint
  227.     /*NOTREACHED*/
  228. }
  229.  
  230. /* determine the absolutely first existing article number */
  231. #ifdef SERVER
  232. ART_NUM
  233. getabsfirst(ngnum,ngsize)
  234. register NG_NUM ngnum;
  235. ART_NUM ngsize;
  236. {
  237.     register ART_NUM a1st;
  238. #ifndef MININACT
  239.     char ser_line[256];
  240.     ART_NUM x,y;
  241. #endif
  242.  
  243. #ifdef CACHEFIRST
  244.     if (a1st = abs1st[ngnum])
  245.     return a1st;
  246. #endif
  247. #ifdef MININACT
  248.     getngsize(ngnum);
  249. # ifdef CACHEFIRST
  250.     return abs1st[ngnum];
  251. # else
  252.     return abs1st;
  253. # endif
  254. #else
  255.     sprintf(cp,"GROUP %s",rcline[ngnum]);
  256.     put_server(cp);
  257.     if (get_server(ser_line, sizeof(ser_line)) < 0) {
  258.     fprintf(stderr, "rrn: Unexpected close of server socket.\n");
  259.     finalize(1);
  260.     }
  261.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  262.     a1st = ngsize+1;        /* nothing there */
  263.     }
  264.     (void) sscanf(ser_line,"%d%d%d",&x,&y,&a1st);
  265. # ifdef CACHEFIRST
  266.     abs1st[ngnum] = a1st;
  267. # endif
  268.     return a1st;
  269. #endif
  270. }
  271. /* we already know the lowest article number with NNTP */
  272. ART_NUM
  273. getngmin(dirname,floor)
  274. char *dirname;
  275. ART_NUM floor;
  276. {
  277.     return(floor);
  278. }
  279. #else
  280. ART_NUM
  281. getabsfirst(ngnum,ngsize)
  282. register NG_NUM ngnum;
  283. ART_NUM ngsize;
  284. {
  285.     register ART_NUM a1st;
  286. #ifndef MININACT
  287.     char dirname[MAXFILENAME];
  288. #endif
  289.  
  290. #ifdef CACHEFIRST
  291.     if (a1st = abs1st[ngnum])
  292.     return a1st;
  293. #endif
  294. #ifdef MININACT
  295.     getngsize(ngnum);
  296. # ifdef CACHEFIRST
  297.     return abs1st[ngnum];
  298. # else
  299.     return abs1st;
  300. # endif
  301. #else not MININACT
  302.     sprintf(dirname,"%s/%s",spool,getngdir(rcline[ngnum]));
  303.     a1st = getngmin(dirname,0L);
  304.     if (!a1st)                /* nothing there at all? */
  305.     a1st = ngsize+1;        /* aim them at end of newsgroup */
  306. # ifdef CACHEFIRST
  307.     abs1st[ngnum] = a1st;
  308. # endif
  309.     return a1st;
  310. #endif MININACT
  311. }
  312.  
  313. /* scan a directory for minimum article number greater than floor */
  314.  
  315. ART_NUM
  316. getngmin(dirname,floor)
  317. char *dirname;
  318. ART_NUM floor;
  319. {
  320.     register DIR *dirp;
  321.     register struct DIRTYPE *dp;
  322.     register ART_NUM min = 1000000;
  323.     register ART_NUM maybe;
  324.     register char *p;
  325.     char tmpbuf[128];
  326.     
  327.     dirp = opendir(dirname);
  328.     if (!dirp)
  329.     return 0;
  330.     while ((dp = readdir(dirp)) != Null(struct DIRTYPE *)) {
  331.     if ((maybe = atol(dp->d_name)) < min && maybe > floor) {
  332.         for (p = dp->d_name; *p; p++)
  333.         if (!isdigit(*p))
  334.             goto nope;
  335.         if (*dirname == '.' && !dirname[1])
  336.         stat(dp->d_name, &filestat);
  337.         else {
  338.         sprintf(tmpbuf,"%s/%s",dirname,dp->d_name);
  339.         stat(tmpbuf, &filestat);
  340.         }
  341.         if (! (filestat.st_mode & S_IFDIR))
  342.         min = maybe;
  343.     }
  344.       nope:
  345.     ;
  346.     }
  347.     closedir(dirp);
  348.     return min==1000000 ? 0 : min;
  349. }
  350. #endif
  351.