1 /* $Id: defdist.c 6135 2003-01-19 01:15:40Z rra $
10 #include "inn/innconf.h"
15 typedef struct _DDENTRY {
26 typedef struct _DDHANDLE DDHANDLE;
29 DDstart(FILE *FromServer, FILE *ToServer)
43 path = concatpath(innconf->pathetc, _PATH_DISTPATS);
47 /* Not available locally; try remotely. */
48 if (FromServer == NULL || ToServer == NULL)
49 /* We're probably nnrpd running on the server and the
50 * file isn't installed. Oh well. */
52 name = concatpath(innconf->pathtmp, _PATH_TEMPACTIVE);
57 if ((F = CA_listopen(name, FromServer, ToServer,
58 "distrib.pats")) == NULL)
63 for (i = 0; fgets(buff, sizeof buff, F) != NULL; i++)
66 /* Allocate space for the handle. */
67 if ((h = xmalloc(sizeof(DDHANDLE))) == NULL) {
79 } else if ((h->Entries = xmalloc(sizeof(DDENTRY) * i)) == NULL) {
89 fseeko(F, 0, SEEK_SET);
90 for (ep = h->Entries; fgets(buff, sizeof buff, F) != NULL; ) {
91 if ((p = strchr(buff, '\n')) != NULL)
93 if (buff[0] == '\0' || buff[0] == '#')
95 if ((p = strchr(buff, ':')) == NULL
96 || (q = strchr(p + 1, ':')) == NULL)
99 ep->Weight = atoi(buff);
100 ep->Pattern = xstrdup(p);
101 q = strchr(ep->Pattern, ':');
106 h->Count = ep - h->Entries;
116 DDcheck(DDHANDLE *h, char *group)
122 if (h == NULL || group == NULL)
125 w = h->Current ? h->Current->Weight : -1;
126 for (ep = h->Entries, i = h->Count; --i >= 0; ep++)
127 if (ep->Weight > w && uwildmat(group, ep->Pattern)) {
137 static char NIL[] = "";
147 if (h->Current == NULL)
150 p = h->Current->Value;
153 for (ep = h->Entries, i = h->Count; --i >= 0; ep++)
162 main(int ac, char *av[])
170 if (NNTPremoteopen(NNTP_PORT, &FromServer, &ToServer, buff) < 0) {
171 if ((p = strchr(buff, '\n')) != NULL)
173 if ((p = strchr(buff, '\r')) != NULL)
176 fprintf(stderr, "%s\n", buff);
178 perror("Can't connect");
182 if ((h = DDstart(FromServer, ToServer)) == NULL)
183 perror("Init failed, proceeding anyway");
184 while ((p = *++av) != NULL)
191 #endif /* defined(TEST) */