10 date 93.08.25.17.27.12; author jromine; state Exp;
15 date 92.02.05.06.05.20; author jromine; state Exp;
20 date 90.04.05.14.56.13; author sources; state Exp;
25 date 90.02.06.13.25.40; author sources; state Exp;
30 date 89.11.17.16.02.24; author sources; state Exp;
35 date 89.09.22.13.50.45; author sources; state Exp;
40 date 89.09.22.13.48.44; author sources; state Exp;
45 date 89.05.05.14.42.00; author sources; state Exp;
51 @new popsbr to use NNTP
57 @off_t fixes for BSD44
60 @/* pshsbr.c - NNTP client subroutines */
62 static char ident[] = "@@(#)$Id: pshsbr.c,v 2.3 1992/02/05 06:05:20 jromine Exp jromine $";
67 #include "../h/strings.h"
68 #include "../h/nntp.h"
78 #define TRMLEN (sizeof TRM - 1)
83 extern char *sys_errlist[];
86 static int poprint = 0;
87 static int pophack = 0;
89 char response[BUFSIZ];
94 #ifdef BPOP /* stupid */
95 static int xtnd_last = -1,
97 static char xtnd_name[512]; /* INCREDIBLE HACK!! */
100 #define command pop_command
101 #define multiline pop_multiline
103 static int traverse(), getline();
108 int pop_init (host, user, pass, snoop)
110 int pop_init (host, user, pass, snoop, rpop)
125 if ((fd1 = client (host, "tcp", "nntp", rpop, response)) == NOTOK)
128 if ((fd2 = dup (fd1)) == NOTOK) {
129 (void) sprintf (response, "unable to dup connection descriptor: %s",
130 errno > 0 && errno < sys_nerr ? sys_errlist[errno]
135 if (pop_set (fd1, fd2, snoop, (char *)0) == NOTOK)
138 (void) signal (SIGPIPE, SIG_IGN);
140 switch (getline (response, sizeof response, input)) {
143 fprintf (stderr, "<--- %s\n", response);
144 if (*response < CHAR_ERR)
147 (void) strcpy (buffer, response);
148 (void) command ("QUIT");
149 (void) strcpy (response, buffer);
155 fprintf (stderr, "%s\n", response);
156 (void) fclose (input);
157 (void) fclose (output);
165 int pop_set (in, out, snoop, myname)
171 if (myname && *myname)
172 strcpy (xtnd_name, myname); /* interface from bbc to msh */
174 if ((input = fdopen (in, "r")) == NULL
175 || (output = fdopen (out, "w")) == NULL) {
176 (void) strcpy (response, "fdopen failed on connection descriptor");
178 (void) fclose (input);
195 (void) sprintf (in, "%d", fileno (input));
196 (void) sprintf (out, "%d", fileno (output));
202 int pop_stat (nmsgs, nbytes)
207 extern char **brkstring();
209 if (xtnd_last < 0) { /* in msh, xtnd_name is set from myname */
210 if (command("GROUP %s", xtnd_name) == NOTOK)
213 ap = brkstring (response, " ", "\n"); /* "211 nart first last ggg" */
214 xtnd_first = atoi (ap[2]);
215 xtnd_last = atoi (ap[3]);
218 /* nmsgs is not the real nart, but an incredible simuation */
220 *nmsgs = xtnd_last - xtnd_first + 1; /* because of holes... */
223 *nbytes = xtnd_first; /* for subtracting offset in msh() */
228 int pop_exists (action)
231 if (traverse (action, "XMSGS %d-%d", xtnd_first, xtnd_last) == OK)
234 return traverse (action, "XHDR NONAME %d-%d", xtnd_first, xtnd_last);
239 int pop_list (msgno, nmsgs, msgs, bytes)
241 int pop_list (msgno, nmsgs, msgs, bytes, ids)
256 if (command ("STAT %d", msgno) == NOTOK)
271 static int traverse (action, fmt, a, b, c, d)
279 char buffer[sizeof response];
281 if (command (fmt, a, b, c, d) == NOTOK)
283 (void) strcpy (buffer, response);
286 switch (multiline ()) {
291 (void) strcpy (response, buffer);
295 (*action) (response);
305 return command ("DELE %d", msgno);
310 return command ("NOOP");
315 return command ("RSET");
320 int pop_top (msgno, lines, action)
322 lines, /* sadly, ignored */
325 return traverse (action, "HEAD %d", msgno);
329 int pop_retr (msgno, action)
333 return traverse (action, "ARTICLE %d", msgno);
339 int pop_xtnd (action, fmt, a, b, c, d)
341 char *fmt, *a, *b, *c, *d;
343 extern char **brkstring();
344 char buffer[BUFSIZ], **ap;
346 sprintf (buffer, fmt, a, b, c, d);
347 ap = brkstring (buffer, " ", "\n"); /* a hack, i know... */
349 if (uleq(ap[0], "x-bboards")) { /* XTND "X-BBOARDS group */
350 /* most of these parameters are meaningless under NNTP.
351 * bbc.c was modified to set AKA and LEADERS as appropriate,
352 * the rest are left blank.
356 if (uleq (ap[0], "archive") && ap[1]) {
357 sprintf (xtnd_name, "%s", ap[1]); /* save the name */
359 xtnd_first = 1; /* setup to fail in pop_stat */
362 if (uleq (ap[0], "bboards")) {
364 if (ap[1]) { /* XTND "BBOARDS group" */
365 sprintf (xtnd_name, "%s", ap[1]); /* save the name */
366 if (command("GROUP %s", xtnd_name) == NOTOK)
369 strcpy (buffer, response); /* action must ignore extra args */
370 ap = brkstring (response, " ", "\n");/* "211 nart first last g" */
371 xtnd_first = atoi (ap[2]);
372 xtnd_last = atoi (ap[3]);
377 } else { /* XTND "BBOARDS" */
378 return traverse (action, "LIST", a, b, c, d);
381 return NOTOK; /* unknown XTND command */
390 i = command ("QUIT");
398 (void) fclose (input);
399 (void) fclose (output);
408 int command (fmt, a, b, c, d)
418 (void) sprintf (buffer, fmt, a, b, c, d);
421 if (cp = index (buffer, ' '))
423 fprintf (stderr, "---> %s ********\n", buffer);
429 fprintf (stderr, "---> %s\n", buffer);
431 if (putline (buffer, output) == NOTOK)
434 switch (getline (response, sizeof response, input)) {
437 fprintf (stderr, "<--- %s\n", response);
438 return (*response < CHAR_ERR ? OK : NOTOK);
443 fprintf (stderr, "%s\n", response);
450 char buffer[BUFSIZ + TRMLEN];
452 if (getline (buffer, sizeof buffer, input) != OK)
456 fprintf (stderr, "<--- %s\n", response);
458 if (strncmp (buffer, TRM, TRMLEN) == 0) {
459 if (buffer[TRMLEN] == NULL)
462 (void) strcpy (response, buffer + TRMLEN);
465 (void) strcpy (response, buffer);
472 static int getline (s, n, iop)
481 while (--n > 0 && (c = fgetc (iop)) != EOF)
482 if ((*p++ = c) == '\n')
484 if (ferror (iop) && c != EOF) {
485 (void) strcpy (response, "error on connection");
488 if (c == EOF && p == s) {
489 (void) strcpy (response, "connection closed by foreign host");
502 static putline (s, iop)
506 (void) fprintf (iop, "%s\r\n", s);
509 (void) strcpy (response, "lost connection");
520 @changes for marshall's popi/mshcmds stuff
525 static char ident[] = "@@(#)$Id: pshsbr.c,v 2.2 1990/04/05 14:56:13 sources Exp jromine $";
538 static char ident[] = "@@(#)$Id:$";
541 static int traverse(), command(), multiline(), getline();
544 static int command (fmt, a, b, c, d)
547 static int multiline () {
562 @changes for SUN40 shared libraries and NNTP under bbc
579 @*** empty log message ***
584 *nmsgs = xtnd_last - xtnd_first + 1; /* because of holes... */
595 /* popsbr.c - POP client subroutines */
600 if ((fd1 = client (host, "tcp", "pop", rpop, response)) == NOTOK)
603 if (pop_set (fd1, fd2, snoop) == NOTOK)
607 && command ("USER %s", user) != NOTOK
608 && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
612 if (*response != '+') {
615 int pop_set (in, out, snoop)
620 if (command ("STAT") == NOTOK)
624 *nmsgs = *nbytes = 0;
625 (void) sscanf (response, "+OK %d %d", nmsgs, nbytes);
630 if (command ("LIST %d", msgno) == NOTOK)
636 (void) sscanf (response, "+OK %d %d %d", msgs, bytes, ids);
639 (void) sscanf (response, "+OK %d %d", msgs, bytes);
643 if (command ("LIST") == NOTOK)
646 for (i = 0; i < *nmsgs; i++)
647 switch (multiline ()) {
657 (void) sscanf (response, "%d %d %d",
658 msgs++, bytes++, ids++);
661 (void) sscanf (response, "%d %d", msgs++, bytes++);
665 switch (multiline ()) {
674 int pop_retr (msgno, action)
678 return traverse (action, "RETR %d", msgno);
687 return traverse (action, "TOP %d %d", msgno, lines);
702 (void) sprintf (buffer, "XTND %s", fmt);
703 return traverse (action, buffer, a, b, c, d);
706 return (*response == '+' ? OK : NOTOK);