|
|
1.1 root 1: /* $Header: addng.c,v 4.3.1.2 85/05/29 09:06:24 lwall Exp $
2: *
3: * $Log: addng.c,v $
4: * Revision 4.3.1.2 85/05/29 09:06:24 lwall
5: * New newsgroups without spool directories incorrectly classified as "ancient".
6: *
7: * Revision 4.3.1.1 85/05/10 11:30:50 lwall
8: * Branch for patches.
9: *
10: * Revision 4.3 85/05/01 11:34:41 lwall
11: * Baseline for release with 4.3bsd.
12: *
13: */
14:
15: #include "EXTERN.h"
16: #include "common.h"
17: #include "rn.h"
18: #include "ngdata.h"
19: #include "last.h"
20: #include "util.h"
21: #include "intrp.h"
22: #include "only.h"
23: #include "rcstuff.h"
24: #include "server.h"
25: #include "INTERN.h"
26: #include "addng.h"
27: #include <sys/time.h>
28:
29: void
30: addng_init()
31: {
32: ;
33: }
34:
35: #ifdef FINDNEWNG
36: /* generate a list of new newsgroups from active file */
37:
38: bool
39: newlist(munged,checkinlist)
40: bool munged; /* are we scanning the whole file? */
41: bool checkinlist;
42: {
43: char *tmpname;
44: register char *s;
45: long birthof();
46: #ifdef SERVER
47: char ser_line[256];
48: struct tm *tmptr;
49: #endif
50:
51: tmpname = savestr(filexp("/tmp/rnew.%$"));
52: tmpfp = fopen(tmpname,"w");
53: if (tmpfp == Nullfp) {
54: printf(cantcreate,tmpname) FLUSH;
55: return FALSE;
56: }
57: #ifdef SERVER
58: tmptr = localtime(&lasttime);
59: sprintf(ser_line, "NEWGROUPS %02d%02d%02d %02d%02d%02d", tmptr->tm_year,
60: tmptr->tm_mon+1, tmptr->tm_mday, tmptr->tm_hour,
61: tmptr->tm_min, tmptr->tm_sec);
62: put_server(ser_line);
63: if (get_server(ser_line, sizeof(ser_line)) < 0) {
64: fprintf(stderr, "rrn: Unexpected close of server socket.\n");
65: finalize(1);
66: }
67: if (*ser_line != CHAR_OK) {
68: fclose(tmpfp);
69: UNLINK(tmpname);
70: free(tmpname);
71: return TRUE;
72: }
73:
74: while (get_server(ser_line, sizeof(ser_line)) >= 0) {
75: if (ser_line[0] == '.')
76: break;
77: if (strnEQ(ser_line, "to.", 3))
78: continue;
79: if (find_ng(ser_line) == nextrcline &&
80: (checkinlist ? (inlist(ser_line)) : (1))) { /* if not in .newsrc */
81: fprintf(tmpfp,"%s\n", ser_line); /* and younger than */
82: /* the last time we checked */
83: /* then remember said newsgroup */
84: }
85: #else /* not SERVER */
86: while (fgets(buf,LBUFLEN,actfp) != Nullch) {
87: if (s = index(buf,' ')) {
88: *s++ = '\0';
89: if (strnEQ(buf,"to.",3))
90: continue;
91: if (find_ng(buf) == nextrcline &&
92: (checkinlist ?
93: (inlist(buf)) :
94: (birthof(buf,(ART_NUM)atol(s)) > lasttime)
95: )
96: ) {
97: /* if not in .newsrc and younger */
98: /* than the last time we checked */
99: fprintf(tmpfp,"%s\n",buf);
100: /* then remember said newsgroup */
101: }
102: #ifdef FASTNEW
103: else { /* not really a new group */
104: if (!munged) { /* did we assume not munged? */
105: fclose(tmpfp); /* then go back, knowing that */
106: UNLINK(tmpname);
107: free(tmpname);
108: return TRUE; /* active file was indeed munged */
109: }
110: }
111: #endif
112: }
113: #ifdef DEBUGGING
114: else
115: printf("Bad active record: %s\n",buf) FLUSH;
116: #endif
117: #endif /* SERVER */
118: }
119:
120: /* we have successfully generated the list */
121:
122: fclose(tmpfp);
123: tmpfp = fopen(tmpname,"r");
124: UNLINK(tmpname); /* be nice to the world */
125: if (tmpfp == Nullfp) {
126: printf(cantopen,tmpname) FLUSH;
127: return FALSE;
128: }
129: while (fgets(buf,LBUFLEN,tmpfp) != Nullch) {
130: buf[strlen(buf)-1] = '\0';
131: get_ng(buf,TRUE); /* add newsgroup, maybe */
132: }
133: fclose(tmpfp); /* be nice to ourselves */
134: free(tmpname);
135: return FALSE; /* do not call us again */
136: }
137:
138: /* return creation time of newsgroup */
139:
140: long
141: birthof(ngnam,ngsize)
142: char *ngnam;
143: ART_NUM ngsize;
144: {
145: char tst[128];
146: long time();
147:
148: sprintf(tst, ngsize ? "%s/%s/1" : "%s/%s" ,spool,getngdir(ngnam));
149: if (stat(tst,&filestat) < 0)
150: return (ngsize ? 0L : time(0)); /* not there, assume something good */
151: else
152: return filestat.st_mtime;
153: }
154:
155: bool
156: scanactive()
157: {
158: NG_NUM oldnext = nextrcline; /* remember # lines in newsrc */
159:
160: fseek(actfp,0L,0);
161: newlist(TRUE,TRUE);
162: if (nextrcline != oldnext) { /* did we add any new groups? */
163: return TRUE;
164: }
165: return FALSE;
166: }
167:
168: #endif
169:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.