1772
|
1 /* openarts.c - Open a number of articles, if possible.
|
|
2 Copyright (C) 1994 Brad Spencer
|
|
3
|
|
4 This file is part of the OS-9 UUCP package, UUCPbb.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 The author of UUCPbb, Bob Billson, can be contacted at:
|
|
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
|
|
22 21 Bates Way, Westfield, NJ 07090
|
|
23 */
|
|
24
|
|
25 #include "uucp.h"
|
|
26 #include "rnews.h"
|
|
27 #include "mbuf.h"
|
|
28
|
|
29 EXTERN int debuglvl;
|
|
30 char *fixgroupname();
|
|
31
|
|
32
|
|
33 int openarts (g, gname)
|
|
34 struct mbuf *g;
|
|
35 char *gname;
|
|
36 {
|
|
37 char lbuf[512], gpath[200];
|
|
38 char *p, *ngroups, *np, *ncp;
|
|
39 struct mbuf *gp;
|
|
40 int havegroup = FALSE;
|
|
41
|
|
42 /* Allocate some space for the group name stuff */
|
|
43 ngroups = (char *)malloc (strlen (gname) + 2);
|
|
44
|
|
45 if (ngroups == NULL)
|
|
46 fatal ("openarts(): can't malloc copy of newsgroup name");
|
|
47
|
|
48 sprintf (ngroups, "%s\n", gname);
|
|
49 np = ngroups;
|
|
50
|
|
51 /* Loop until we run out of given articles */
|
|
52 while (*np != '\0' && *np != '\l' && *np != '\n')
|
|
53 {
|
|
54 /* Search for the terminator or separator character */
|
|
55 for (ncp = np;
|
|
56 *ncp != ',' && *ncp != '\0' && *ncp != '\l' && *ncp != '\n';
|
|
57 ncp++);
|
|
58 {
|
|
59 *ncp = '\0';
|
|
60 }
|
|
61
|
|
62 /* Loop through the groups that are at this particular site, see if
|
|
63 there is a match */
|
|
64
|
|
65 for (gp = g; gp != NULL; gp = gp->mbuf_next)
|
|
66 {
|
|
67 if (debuglvl > 4)
|
|
68 {
|
|
69 sprintf (lbuf, "Checking group '%s' and '%s'", np,
|
|
70 ((struct groups *)gp->cbuf)->name);
|
|
71 log (lbuf);
|
|
72 }
|
|
73
|
|
74 /* Ok, this group matched */
|
|
75 if (strcmp(((struct groups *)gp->cbuf)->name, np) == 0)
|
|
76 {
|
|
77 char *gname;
|
|
78
|
|
79 gname = NULL;
|
|
80 havegroup = TRUE;
|
|
81
|
|
82 if (chdir (newsdir) == ERROR)
|
|
83 {
|
|
84 sprintf (lbuf, "Can't chdir to '%s'", newsdir);
|
|
85 log (lbuf);
|
|
86 return (ABORT);
|
|
87 }
|
|
88
|
|
89 /* Make the directory path for this news group, if it
|
|
90 doesn't exist */
|
|
91
|
|
92 gname = fixgroupname (np);
|
|
93 makepath (gname);
|
|
94
|
|
95 if (gname != NULL)
|
|
96 {
|
|
97 free (gname);
|
|
98 gname = NULL;
|
|
99 }
|
|
100
|
|
101 /* Form this particular article. We should already be in
|
|
102 the correct newsgroup's directory. */
|
|
103
|
|
104 ((struct groups *)gp->cbuf)->max++;
|
|
105 sprintf (gpath, "a%d", ((struct groups *)gp->cbuf)->max);
|
|
106
|
|
107 if (debuglvl > 3)
|
|
108 {
|
|
109 sprintf (lbuf, "Trying: '%s' in '%s'", gpath,
|
|
110 ((struct groups *)gp->cbuf)->name);
|
|
111 log (lbuf);
|
|
112 }
|
|
113
|
|
114 /* Try to open the article, this should truncate any files
|
|
115 that are the same name */
|
|
116
|
|
117 if ((((struct groups *)gp->cbuf)->artfd
|
|
118 = fopen (gpath, "w")) == NULL)
|
|
119 {
|
|
120 sprintf (lbuf, "Couldn't open '%s', because %d",
|
|
121 gpath, errno);
|
|
122 log (lbuf);
|
|
123 }
|
|
124 else
|
|
125 {
|
|
126 np = ncp + 1;
|
|
127 break;
|
|
128 }
|
|
129 }
|
|
130 }
|
|
131 np = ncp + 1;
|
|
132 }
|
|
133
|
|
134 /* Ok, this article doesn't go to any of the groups at this site */
|
|
135 if (!havegroup)
|
|
136 {
|
|
137 if (debuglvl > 1)
|
|
138 {
|
|
139 log ("Article doesn't go to any news groups in active file.");
|
|
140 log ("Junking it.");
|
|
141 }
|
|
142
|
|
143 for (gp = g; gp != NULL; gp = gp->mbuf_next)
|
|
144 {
|
|
145 if (strncmp (((struct groups *)gp->cbuf)->name, "junk" ,4) == 0)
|
|
146 {
|
|
147 np = ((struct groups *)gp->cbuf)->name;
|
|
148 if (chdir (newsdir) == ERROR)
|
|
149 {
|
|
150 sprintf (lbuf, "Can't chdir to '%s'", newsdir);
|
|
151 log (lbuf);
|
|
152 return (ABORT);
|
|
153 }
|
|
154 makepath (np);
|
|
155 ((struct groups *)gp->cbuf)->max++;
|
|
156 sprintf (gpath, "Z%d", ((struct groups *)gp->cbuf)->max);
|
|
157
|
|
158 for (p = gpath; *p != '\0'; p++)
|
|
159 if (*p == '.')
|
|
160 *p='/';
|
|
161
|
|
162 if (debuglvl > 3)
|
|
163 {
|
|
164 sprintf (lbuf, "Trying: '%s' in '%s'",
|
|
165 gpath, ((struct groups *)gp->cbuf)->name);
|
|
166 log(lbuf);
|
|
167 }
|
|
168
|
|
169 if ((((struct groups *)gp->cbuf)->artfd
|
|
170 = fopen (gpath, "w")) == NULL)
|
|
171 {
|
|
172 sprintf (lbuf, "Couldn't open '%s', because %d",
|
|
173 gpath, errno);
|
|
174 log (lbuf);
|
|
175 }
|
|
176 break;
|
|
177 }
|
|
178 }
|
|
179
|
|
180 /* This really indicates that there is a problem in the universe.
|
|
181 Every site should have a 'junk' group */
|
|
182
|
|
183 if (gp == NULL)
|
|
184 if (debuglvl > 1)
|
|
185 log ("No junk group.....");
|
|
186 }
|
|
187 free (ngroups);
|
|
188 }
|