1 /* $Id: clientactive.c 6135 2003-01-19 01:15:40Z rra $
9 #include "inn/innconf.h"
15 static char *CApathname;
20 ** Get a copy of the active file for a client host to use, locally or
24 CAopen(FILE *FromServer, FILE *ToServer)
28 /* Use a local (or NFS-mounted) copy if available. Make sure we don't
29 * try to delete it when we close it. */
30 path = concatpath(innconf->pathdb, _PATH_CLIENTACTIVE);
31 CAfp = fopen(path, "r");
38 /* Use the active file from the server */
39 return CAlistopen(FromServer, ToServer, (char *)NULL);
44 ** Internal library routine.
47 CA_listopen(char *pathname, FILE *FromServer, FILE *ToServer,
55 F = fopen(pathname, "w");
59 /* Send a LIST command to and capture the output. */
61 fprintf(ToServer, "list\r\n");
63 fprintf(ToServer, "list %s\r\n", request);
66 /* Get the server's reply to our command. */
67 if (fgets(buff, sizeof buff, FromServer) == NULL
68 || strncmp(buff, NNTP_LIST_FOLLOWS, strlen(NNTP_LIST_FOLLOWS)) != 0) {
70 /* Only call CAclose() if opened through CAopen() */
71 if (strcmp(CApathname, pathname) == 0)
77 /* Slurp up the rest of the response. */
78 while (fgets(buff, sizeof buff, FromServer) != NULL) {
79 if ((p = strchr(buff, '\r')) != NULL)
81 if ((p = strchr(buff, '\n')) != NULL)
83 if (buff[0] == '.' && buff[1] == '\0') {
84 if (ferror(F) || fflush(F) == EOF || fclose(F) == EOF)
86 return fopen(pathname, "r");
88 fprintf(F, "%s\n", buff);
91 /* Ran out of input before finding the terminator; quit. */
101 ** Use the NNTP list command to get a file from a server. Default is
102 ** the active file, otherwise ask for whatever is in the request param.
105 CAlistopen(FILE *FromServer, FILE *ToServer, const char *request)
109 /* Gotta talk to the server -- see if we can. */
110 if (FromServer == NULL || ToServer == NULL) {
115 CApathname = concatpath(innconf->pathtmp, _PATH_TEMPACTIVE);
116 fd = mkstemp(CApathname);
125 return CAfp = CA_listopen(CApathname, FromServer, ToServer, request);
131 ** Close the file opened by CAopen or CAlistopen.
140 if (CApathname != NULL) {