1 /* $Id: clientlib.c 6155 2003-01-19 19:58:25Z rra $
3 ** Routines compatible with the NNTP "clientlib" routines.
8 #include "inn/innconf.h"
13 FILE *ser_rd_fp = NULL;
14 FILE *ser_wr_fp = NULL;
15 char ser_line[NNTP_STRLEN + 2];
19 ** Get the name of the NNTP server. Ignore the filename; we use
20 ** our own configuration stuff. Return pointer to static data.
23 getserverbyfile(char *file UNUSED)
25 static char buff[256];
27 strlcpy(buff, innconf->server, sizeof(buff));
33 ** Get a connection to the remote news server. Return server's reply
34 ** code or -1 on error.
37 server_init(char *host, int port)
39 char line2[NNTP_STRLEN];
41 /* This interface may be used by clients that assume C News behavior and
42 won't read inn.conf themselves. */
44 if (!innconf_read(NULL))
47 if (NNTPconnect(host, port, &ser_rd_fp, &ser_wr_fp, ser_line) < 0) {
48 if (ser_line[0] == '\0')
52 /* Server rejected connection; return it's reply code. */
53 return atoi(ser_line);
56 /* Send the INN command; if understood, use that reply. */
57 put_server("mode reader");
58 if (get_server(line2, (int)sizeof line2) < 0)
60 if (atoi(line2) != NNTP_BAD_COMMAND_VAL)
61 strlcpy(ser_line, line2, sizeof(ser_line));
63 /* Connected; return server's reply code. */
64 return atoi(ser_line);
69 "NOTE: This machine does not have permission to post articles"
71 "This machine does not have permission to use the %s news server.\n"
73 ** Print a message based on the the server's initial response.
74 ** Return -1 if server wants us to go away.
77 handle_server_response(int response, char *host)
83 printf("Unknown response code %d from %s.\n", response, host);
85 case NNTP_GOODBYE_VAL:
86 if (atoi(ser_line) == response) {
87 p = &ser_line[strlen(ser_line) - 1];
88 if (*p == '\n' && *--p == '\r')
90 if (p > &ser_line[3]) {
91 printf("News server %s unavailable: %s\n", host,
96 printf("News server %s unavailable, try later.\n", host);
99 printf(CANTUSE, host);
101 case NNTP_NOPOSTOK_VAL:
102 printf("%s.\n", CANTPOST);
104 case NNTP_POSTOK_VAL:
112 ** Send a line of text to the server.
115 put_server(const char *buff)
117 fprintf(ser_wr_fp, "%s\r\n", buff);
123 ** Get a line of text from the server, strip trailing \r\n.
124 ** Return -1 on error.
127 get_server(char *buff, int buffsize)
131 if (fgets(buff, buffsize, ser_rd_fp) == NULL)
133 p = &buff[strlen(buff)];
134 if (p >= &buff[2] && p[-2] == '\r' && p[-1] == '\n')
141 ** Send QUIT and close the server.
146 char buff[NNTP_STRLEN];
148 if (ser_wr_fp != NULL && ser_rd_fp != NULL) {
153 get_server(buff, (int)sizeof buff);