home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / addng.c < prev    next >
C/C++ Source or Header  |  1993-12-04  |  10KB  |  372 lines

  1. /* $Id: addng.c,v 4.4.3.1 1992/02/01 03:09:32 sob PATCH_3 sob $
  2.  *
  3.  * $Log: addng.c,v $
  4.  * Revision 4.4.3.1  1992/02/01  03:09:32  sob
  5.  * Release 4.4 Patchlevel 3
  6.  *
  7.  * Revision 4.4.2.1  1991/12/01  18:05:42  sob
  8.  * Patchlevel 2 changes
  9.  *
  10.  * Revision 4.4  1991/09/09  20:18:23  sob
  11.  * release 4.4
  12.  *
  13.  *
  14.  * 
  15.  */
  16. /* This software is Copyright 1991 by Stan Barber. 
  17.  *
  18.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  19.  * use this software as long as: there is no monetary profit gained
  20.  * specifically from the use or reproduction of this software, it is not
  21.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  22.  * included prominently in any copy made. 
  23.  *
  24.  * The author make no claims as to the fitness or correctness of this software
  25.  * for any use whatsoever, and it is provided as is. Any use of this software
  26.  * is at the user's own risk. 
  27.  */
  28.  
  29. #include "EXTERN.h"
  30. #include "common.h"
  31. #include "rn.h"
  32. #include "ngdata.h"
  33. #include "last.h"
  34. #include "util.h"
  35. #include "intrp.h"
  36. #include "only.h"
  37. #include "rcstuff.h"
  38. #ifdef SERVER
  39. #include "server.h"
  40. #endif
  41. #include "final.h"
  42. #include "INTERN.h"
  43. #include "addng.h"
  44.  
  45. void
  46. addng_init()
  47. {
  48.     ;
  49. }
  50.  
  51. #ifdef FINDNEWNG
  52. /* generate a list of new newsgroups from active file */
  53.  
  54. bool
  55. newlist(munged,checkinlist)
  56. bool_int munged;            /* are we scanning the whole file? */
  57. bool_int checkinlist;
  58. {
  59.     char *tmpname;
  60.     char *anothername;  /* OS2-patch */
  61.     register char *s, *status;
  62.     register NG_NUM ngnum;
  63. #ifndef ACTIVE_TIMES
  64.     long birthof();
  65. #endif
  66.  
  67. /*** OS2: RNEWNAME is #defined in common.h as a name
  68.           which is located in /tmp. Now we use the temp-name
  69.           which is defined in UUPCSYSRC. ***/
  70. /*    tmpname = filexp(RNEWNAME);  */
  71.  
  72.     anothername = (char *)malloc(strlen(uupc_rc_settings.temp_name) + 20);
  73.     if (anothername == NULL)
  74.     {   fprintf(stderr, "\n\n\nWAAHH, malloc failed in line %s, file %s\n",
  75.                      __LINE__, __FILE__);
  76.         fprintf(stderr, "Please send email to haen@veces.stgt.sub.org!!\n");
  77.     }
  78.     sprintf(anothername,"%s/rnew.%$",uupc_rc_settings.temp_name);
  79.     tmpname = filexp(anothername);
  80.     free(anothername);
  81. /*** OS2: end of patch ***/
  82.  
  83.     tmpfp = fos2open(tmpname,"w+");
  84.     if (tmpfp == Nullfp) {
  85.     printf(cantcreate,tmpname) ; ; FLUSH;
  86.     return FALSE;
  87.     }
  88.     UNLINK(tmpname);            /* be nice to the world */
  89.  
  90.     while (fgets(buf,LBUFLEN,actfp) != Nullch) {
  91.     /* Check if they want to break out of the new newsgroups search */
  92.     if (int_count) {
  93.         int_count = 0;
  94.         fclose(tmpfp);
  95.         return FALSE;
  96.     }
  97.     if (s = index(buf,' ')) {
  98.         status=s;
  99.         while (isdigit(*status) || isspace(*status)) status++;
  100.         *s++ = '\0';
  101.         if (strnEQ(buf,"to.",3) || *status == 'x' || *status == '=')
  102.             /* since = groups are refiling to another group, just
  103.            ignore their existence */
  104.         continue;
  105. #ifdef ACTIVE_TIMES
  106.         if (inlist(buf) && ((ngnum = find_ng(buf)) == nextrcline
  107.                 || toread[ngnum] == TR_UNSUB)
  108. #else
  109.         if (checkinlist ?
  110.         (inlist(buf) && ((ngnum = find_ng(buf)) == nextrcline
  111.                  || toread[ngnum] == TR_UNSUB))
  112.           : (find_ng(buf) == nextrcline
  113.          && birthof(buf,(ART_NUM)atol(s)) > lasttime)
  114. #endif
  115.         ) {
  116.                     /* if not in .newsrc and younger */
  117.                     /* than the last time we checked */
  118.         fprintf(tmpfp,"%s\n",buf);
  119.                     /* then remember said newsgroup */
  120.         }
  121. #ifdef FASTNEW
  122.         else {            /* not really a new group */
  123.         if (!munged) {        /* did we assume not munged? */
  124.             fclose(tmpfp);    /* then go back, knowing that */
  125.             return TRUE;    /* active file was indeed munged */
  126.         }
  127.         }
  128. #endif
  129.     }
  130. #ifdef DEBUGGING
  131.     else
  132.         printf("Bad active record: %s\n",buf) ; ; FLUSH;
  133. #endif
  134.     }
  135.  
  136.     /* we have successfully generated the list */
  137.  
  138.     fseek(tmpfp,0L,0);            /* rewind back to the beginning */
  139.     while (fgets(buf,LBUFLEN,tmpfp) != Nullch) {
  140.     buf[strlen(buf)-1] = '\0';
  141.     get_ng(buf,TRUE);        /* add newsgroup, maybe */
  142.     }
  143.     fclose(tmpfp);            /* be nice to ourselves */
  144.     return FALSE;            /* do not call us again */
  145. }
  146.  
  147. #ifdef ACTIVE_TIMES
  148. #ifdef SERVER
  149.  
  150. bool
  151. find_new_groups()
  152. {
  153.     char *tmpname;
  154.     char *anothername; /* OS2-patch */
  155.     register char *s;
  156.     struct tm *ts;
  157.     long now;
  158.     NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
  159.  
  160. /*** OS2: RNEWNAME is #defined in common.h as a name
  161.           which is located in /tmp. Now we use the temp-name
  162.           which is defined in UUPCSYSRC. ***/
  163. /*    tmpname = filexp(RNEWNAME);  */
  164.  
  165.     anothername = (char *)malloc(strlen(uupc_rc_settings.temp_name) + 20);
  166.     if (anothername == NULL)
  167.     {   fprintf(stderr, "\n\n\nWAAHH, malloc failed in line %s, file %s\n",
  168.                      __LINE__, __FILE__);
  169.         fprintf(stderr, "Please send email to haen@veces.stgt.sub.org!!\n");
  170.     }
  171.     sprintf(anothername,"%s/rnew.%$",uupc_rc_settings.temp_name);
  172.     tmpname = filexp(tmpname);
  173.     free(tmpname);
  174. /*end of patch*/
  175.  
  176.     tmpname = filexp(RNEWNAME);
  177.     tmpfp = fos2open(tmpname,"w+");
  178.     if (tmpfp == Nullfp) {
  179.     printf(cantcreate,tmpname) ; ; FLUSH;
  180.     return FALSE;
  181.     }
  182.     UNLINK(tmpname);            /* be nice to the world */
  183.  
  184.     time(&now);
  185.     ts = gmtime(&lastnewtime);
  186.     sprintf(ser_line, "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT",
  187.     ts->tm_year % 100, ts->tm_mon+1, ts->tm_mday,
  188.     ts->tm_hour, ts->tm_min, ts->tm_sec);
  189. #ifdef DEBUGGING
  190.     if (debug & DEB_NNTP)
  191.     printf(">%s\n", ser_line) ; ; FLUSH;
  192. #endif
  193.     put_server(ser_line);
  194.     nntp_get(ser_line, sizeof(ser_line));
  195. #ifdef DEBUGGING
  196.     if (debug & DEB_NNTP)
  197.     printf("<%s\n", ser_line) ; ; FLUSH;
  198. #endif
  199.     if (*ser_line != CHAR_OK) {        /* and then see if that's ok */
  200.   error_exit:
  201.     fclose(tmpfp);
  202.     printf("Can't get new groups from server:\n%s\n", ser_line);
  203.     return FALSE;
  204.     }
  205.  
  206.     while (1) {
  207.     if (nntp_get(ser_line, sizeof(ser_line)) < 0)
  208.         goto error_exit;
  209. #ifdef DEBUGGING
  210.     if (debug & DEB_NNTP)
  211.         printf("<%s\n", ser_line) ; ; FLUSH;
  212. #endif
  213.     if (ser_line[0] == '.')
  214.         break;
  215.     if ((s = index(ser_line, ' ')) != Nullch)
  216.         *s = '\0';
  217.     fprintf(tmpfp,"%s\n",ser_line);
  218.     }
  219.  
  220.     /* we have successfully generated the list */
  221.  
  222.     if (ftell(tmpfp)) {
  223.     fputs("\nFinding new newsgroups:\n",stdout) ; ; FLUSH;
  224.  
  225.     fseek(tmpfp,0L,0);        /* rewind back to the beginning */
  226.     while (fgets(buf,LBUFLEN,tmpfp) != Nullch) {
  227.         buf[strlen(buf)-1] = '\0';
  228.         get_ng(buf,FALSE);        /* add newsgroup, maybe */
  229.     }
  230.     lastnewtime = now;        /* remember when we found new groups */
  231.     }                    /* (ends up back in .rnlast) */
  232.     fclose(tmpfp);            /* be nice to ourselves */
  233.  
  234.     return oldnext != nextrcline;
  235. }
  236. #else /* not SERVER */
  237.  
  238. bool
  239. find_new_groups()
  240. {
  241.     register char *s;
  242.     long lastone;
  243.     NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
  244.  
  245.     fstat(fileno(actfp),&filestat);    /* find active file size */
  246.     lastactsiz = filestat.st_size;    /* just to save it in .rnlast */
  247.  
  248.     stat(ACTIVE_TIMES,&filestat);    /* did active.times file grow? */
  249.     if (filestat.st_size == lastnewsize)
  250.     return FALSE;
  251.     lastnewsize = filestat.st_size;
  252.  
  253.     fputs("\nChecking for new newsgroups...\n",stdout) ; ; FLUSH;
  254.  
  255. /*** OS2: because we get settings out of uupc-rc-files,
  256.           we don't use the filexp-function to expand the name ***/
  257. /*    s = filexp(ACTIVE_TIMES);*/
  258.     s = ACTIVE_TIMES;
  259.     tmpfp = fos2open(s,"r");
  260.     if (tmpfp == Nullfp) {
  261.     printf(cantopen,s) ; ; FLUSH;
  262.     return FALSE;
  263.     }
  264.     lastone = time(Null(time_t*)) - 24L * 60 * 60 - 1;
  265.     while (fgets(buf,LBUFLEN,tmpfp) != Nullch) {
  266.     if ((s = index(buf, ' ')) != Nullch)
  267.         if ((lastone = atol(s+1)) >= lastnewtime) {
  268.         char tmpbuf[80];
  269.         *s = '\0';
  270.         if (findact(tmpbuf, buf, s - buf, 0L) >= 0)
  271.             get_ng(buf,FALSE);    /* add newsgroup, maybe */
  272.         }
  273.     }
  274.     fclose(tmpfp);
  275.     lastnewtime = lastone+1;        /* remember time of last new group */
  276.                     /* (ends up back in .rnlast) */
  277.     return oldnext != nextrcline;
  278. }
  279. #endif /* SERVER */
  280. #else /* not ACTIVE_TIMES */
  281.  
  282. bool
  283. find_new_groups()
  284. {
  285.     long oldactsiz = lastactsiz;
  286.     NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
  287.  
  288.     fstat(fileno(actfp),&filestat);    /* did active file grow? */
  289.  
  290.     if (filestat.st_size == lastactsiz)
  291.     return FALSE;
  292.     lastactsiz = filestat.st_size;    /* remember new size */
  293.  
  294. #ifdef VERBOSE
  295.     IF(verbose)
  296.     fputs("\nChecking active file for new newsgroups...\n",stdout) ; ; FLUSH;
  297.     ELSE
  298. #endif
  299. #ifdef TERSE
  300.     fputs("\nNew newsgroups:\n",stdout) ; ; FLUSH;
  301. #endif
  302.  
  303. #ifdef FASTNEW                /* bad soft ptrs -> edited active */
  304.     if (!writesoft && oldactsiz) {    /* maybe just do tail of file? */
  305.     fseek(actfp,oldactsiz-NL_SIZE,0);
  306.     fgets(buf,LBUFLEN,actfp);
  307.     if (*buf == '\n' && !newlist(FALSE,FALSE))
  308.         goto bugout;
  309.     }
  310. #endif
  311.     fseek(actfp,0L,0);        /* rewind active file */
  312.     newlist(TRUE,FALSE);        /* sure hope they use hashing... */
  313. bugout:
  314.     return oldnext != nextrcline;
  315. }
  316.  
  317. /* return creation time of newsgroup */
  318.  
  319. long
  320. birthof(ngnam,ngsize)
  321. char *ngnam;
  322. ART_NUM ngsize;
  323. {
  324.     char tst[128];
  325.     long time();
  326.  
  327. #ifdef SERVER        /* ngsize not used */
  328.     long tot;
  329.     sprintf(tst,"GROUP %s",ngnam);
  330. #ifdef DEBUGGING
  331.     if (debug & DEB_NNTP)
  332.     printf(">%s\n", tst) ; ; FLUSH;
  333. #endif
  334.     put_server(tst);
  335.     (void) nntp_get(tst, sizeof(tst));
  336. #ifdef DEBUGGING
  337.     if (debug & DEB_NNTP)
  338.     printf("<%s\n", tst) ; ; FLUSH;
  339. #endif
  340.     if (*tst != CHAR_OK) return(0); /* not a real group */
  341.     (void) sscanf(tst,"%*d%ld",&tot);
  342.     if (tot > 0) return(time(Null(long *)));
  343.     else return(0);
  344. #else /* not SERVER */
  345.  
  346.     sprintf(tst, ngsize ? "%s/%s/1" : "%s/%s" ,spool,getngdir(ngnam));
  347.     if (stat(tst,&filestat) < 0)
  348.     return (ngsize ? 0L : time(Null(long *)));
  349.     /* not there, assume something good */
  350.     else
  351.     return filestat.st_mtime;
  352.  
  353. #endif
  354. }
  355. #endif /* ACTIVE_TIMES */
  356.  
  357. bool
  358. scanactive()
  359. {
  360.     NG_NUM oldnext = nextrcline;    /* remember # lines in newsrc */
  361.  
  362.     fseek(actfp,0L,0);
  363.     newlist(TRUE,TRUE);
  364.     if (nextrcline != oldnext) {    /* did we add any new groups? */
  365.     return TRUE;
  366.     }
  367.     return FALSE;
  368. }
  369.  
  370. #endif
  371.  
  372.