1 /* $Id: getlist.c 6135 2003-01-19 01:15:40Z rra $
3 ** Get a file list from an NNTP server.
10 #include "inn/innconf.h"
11 #include "inn/messages.h"
18 ** Print usage message and exit.
23 fprintf(stderr, "Usage: getlist [-p port] [-h host] [-A] [type [pat [groups]]\n");
29 main(int ac, char *av[])
47 /* First thing, set up our identity. */
48 message_program_name = "getlist";
50 if (!innconf_read(NULL))
61 while ((i = getopt(ac, av, "Ah:p:")) != EOF)
75 die("illegal value for -p option");
81 /* Parse parameters. */
101 if (strcmp(list, "active") != 0 && types != NULL)
103 if (strcmp(list, "active") != 0 && strcmp(list, "newsgroups") != 0
108 /* Open a connection to the server. */
109 if (host == NULL && (host = innconf->server) == NULL)
110 sysdie("cannot get server name");
112 if (NNTPconnect(host, port, &FromServer, &ToServer, buff) < 0)
113 die("cannot connect to server: %s", buff[0] ? buff : strerror(errno));
114 if (authinfo && NNTPsendpassword(host, FromServer, ToServer) < 0)
115 die("cannot authenticate to server");
117 /* Get the data from the server. */
118 active = CAlistopen(FromServer, ToServer,
119 (strcmp(list, "active") == 0) ? NULL : list);
121 sysdie("cannot retrieve data");
123 /* Set up to read it quickly. */
124 if ((qp = QIOfdopen((int)fileno(active))) == NULL)
125 sysdie("cannot read temporary file");
127 /* Scan server's output, displaying appropriate lines. */
129 while ((line = QIOread(qp)) != NULL) {
132 /* No pattern means print all. */
133 if (pattern == NULL) {
134 printf("%s\n", line);
138 /* Get the group name, see if it's one we want. */
139 if ((p = strchr(line, ' ')) == NULL) {
140 warn("line %d is malformed", i);
144 if (!uwildmat(line, pattern))
148 /* If no group types, we want them all. */
150 printf("%s\n", line);
154 /* Find the fourth field. */
155 if ((p = strchr(p + 1, ' ')) == NULL) {
156 warn("line %d (field 2) is malformed", i);
159 if ((p = strchr(p + 1, ' ')) == NULL) {
160 warn("line %d (field 3) is malformed", i);
164 if ((p = strchr(field4, ' ')) != NULL) {
165 warn("line %d has more than 4 fields", i);
169 /* Is this the type of line we want? */
170 if (strchr(types, field4[0]) != NULL)
171 printf("%s\n", line);
174 /* Determine why we stopped */
176 syswarn("cannot read temporary file at line %d", i);
179 else if (QIOtoolong(qp)) {
180 warn("line %d is too long", i);
188 fprintf(ToServer, "quit\r\n");
190 fgets(buff, sizeof buff, FromServer);