head 2.4; access; symbols; locks shettich:2.4; strict; comment @ * @; 2.4 date 93.08.25.17.27.12; author jromine; state Exp; branches; next 2.3; 2.3 date 92.02.05.06.05.20; author jromine; state Exp; branches; next 2.2; 2.2 date 90.04.05.14.56.13; author sources; state Exp; branches; next 2.1; 2.1 date 90.02.06.13.25.40; author sources; state Exp; branches; next 2.0; 2.0 date 89.11.17.16.02.24; author sources; state Exp; branches; next 1.3; 1.3 date 89.09.22.13.50.45; author sources; state Exp; branches; next 1.2; 1.2 date 89.09.22.13.48.44; author sources; state Exp; branches; next 1.1; 1.1 date 89.05.05.14.42.00; author sources; state Exp; branches; next ; desc @new popsbr to use NNTP @ 2.4 log @off_t fixes for BSD44 @ text @/* pshsbr.c - NNTP client subroutines */ #ifndef lint static char ident[] = "@@(#)$Id: pshsbr.c,v 2.3 1992/02/05 06:05:20 jromine Exp jromine $"; #endif lint /* LINTLIBRARY */ #include "../h/strings.h" #include "../h/nntp.h" #include #include #define NOTOK (-1) #define OK 0 #define DONE 1 #define TRM "." #define TRMLEN (sizeof TRM - 1) extern int errno; #ifndef BSD44 extern int sys_nerr; extern char *sys_errlist[]; #endif static int poprint = 0; static int pophack = 0; char response[BUFSIZ]; static FILE *input; static FILE *output; #ifdef BPOP /* stupid */ static int xtnd_last = -1, xtnd_first = 0; static char xtnd_name[512]; /* INCREDIBLE HACK!! */ #endif #define command pop_command #define multiline pop_multiline static int traverse(), getline(); static putline(); /* */ #ifndef RPOP int pop_init (host, user, pass, snoop) #else RPOP int pop_init (host, user, pass, snoop, rpop) int rpop; #endif RPOP char *host, *user, *pass; int snoop; { int fd1, fd2; #ifndef RPOP int rpop = 0; #endif RPOP char buffer[BUFSIZ]; if ((fd1 = client (host, "tcp", "nntp", rpop, response)) == NOTOK) return NOTOK; if ((fd2 = dup (fd1)) == NOTOK) { (void) sprintf (response, "unable to dup connection descriptor: %s", errno > 0 && errno < sys_nerr ? sys_errlist[errno] : "unknown error"); (void) close (fd1); return NOTOK; } if (pop_set (fd1, fd2, snoop, (char *)0) == NOTOK) return NOTOK; (void) signal (SIGPIPE, SIG_IGN); switch (getline (response, sizeof response, input)) { case OK: if (poprint) fprintf (stderr, "<--- %s\n", response); if (*response < CHAR_ERR) return OK; else { (void) strcpy (buffer, response); (void) command ("QUIT"); (void) strcpy (response, buffer); } /* fall */ case NOTOK: case DONE: if (poprint) fprintf (stderr, "%s\n", response); (void) fclose (input); (void) fclose (output); return NOTOK; } /* NOTREACHED */ } /* */ int pop_set (in, out, snoop, myname) int in, out, snoop; char *myname; { if (myname && *myname) strcpy (xtnd_name, myname); /* interface from bbc to msh */ if ((input = fdopen (in, "r")) == NULL || (output = fdopen (out, "w")) == NULL) { (void) strcpy (response, "fdopen failed on connection descriptor"); if (input) (void) fclose (input); else (void) close (in); (void) close (out); return NOTOK; } poprint = snoop; return OK; } int pop_fd (in, out) char *in, *out; { (void) sprintf (in, "%d", fileno (input)); (void) sprintf (out, "%d", fileno (output)); return OK; } /* */ int pop_stat (nmsgs, nbytes) int *nmsgs, *nbytes; { char **ap; extern char **brkstring(); if (xtnd_last < 0) { /* in msh, xtnd_name is set from myname */ if (command("GROUP %s", xtnd_name) == NOTOK) return NOTOK; ap = brkstring (response, " ", "\n"); /* "211 nart first last ggg" */ xtnd_first = atoi (ap[2]); xtnd_last = atoi (ap[3]); } /* nmsgs is not the real nart, but an incredible simuation */ if (xtnd_last > 0) *nmsgs = xtnd_last - xtnd_first + 1; /* because of holes... */ else *nmsgs = 0; *nbytes = xtnd_first; /* for subtracting offset in msh() */ return OK; } int pop_exists (action) int (*action) (); { if (traverse (action, "XMSGS %d-%d", xtnd_first, xtnd_last) == OK) return OK; return traverse (action, "XHDR NONAME %d-%d", xtnd_first, xtnd_last); } #ifndef BPOP int pop_list (msgno, nmsgs, msgs, bytes) #else BPOP int pop_list (msgno, nmsgs, msgs, bytes, ids) int *ids; #endif BPOP int msgno, *nmsgs, *msgs, *bytes; { int i; #ifndef BPOP int *ids = NULL; #endif not BPOP if (msgno) { *msgs = *bytes = 0; if (command ("STAT %d", msgno) == NOTOK) return NOTOK; if (ids) { *ids = msgno; } return OK; } return NOTOK; } /* */ /* VARARGS2 */ static int traverse (action, fmt, a, b, c, d) int (*action) (); char *fmt, *a, *b, *c, *d; { char buffer[sizeof response]; if (command (fmt, a, b, c, d) == NOTOK) return NOTOK; (void) strcpy (buffer, response); for (;;) switch (multiline ()) { case NOTOK: return NOTOK; case DONE: (void) strcpy (response, buffer); return OK; case OK: (*action) (response); break; } } /* */ int pop_dele (msgno) int msgno; { return command ("DELE %d", msgno); } int pop_noop () { return command ("NOOP"); } int pop_rset () { return command ("RSET"); } /* */ int pop_top (msgno, lines, action) int msgno, lines, /* sadly, ignored */ (*action) (); { return traverse (action, "HEAD %d", msgno); } int pop_retr (msgno, action) int msgno, (*action) (); { return traverse (action, "ARTICLE %d", msgno); } #ifdef BPOP int pop_xtnd (action, fmt, a, b, c, d) int (*action) (); char *fmt, *a, *b, *c, *d; { extern char **brkstring(); char buffer[BUFSIZ], **ap; sprintf (buffer, fmt, a, b, c, d); ap = brkstring (buffer, " ", "\n"); /* a hack, i know... */ if (uleq(ap[0], "x-bboards")) { /* XTND "X-BBOARDS group */ /* most of these parameters are meaningless under NNTP. * bbc.c was modified to set AKA and LEADERS as appropriate, * the rest are left blank. */ return OK; } if (uleq (ap[0], "archive") && ap[1]) { sprintf (xtnd_name, "%s", ap[1]); /* save the name */ xtnd_last = 0; xtnd_first = 1; /* setup to fail in pop_stat */ return OK; } if (uleq (ap[0], "bboards")) { if (ap[1]) { /* XTND "BBOARDS group" */ sprintf (xtnd_name, "%s", ap[1]); /* save the name */ if (command("GROUP %s", xtnd_name) == NOTOK) return NOTOK; strcpy (buffer, response); /* action must ignore extra args */ ap = brkstring (response, " ", "\n");/* "211 nart first last g" */ xtnd_first = atoi (ap[2]); xtnd_last = atoi (ap[3]); (*action) (buffer); return OK; } else { /* XTND "BBOARDS" */ return traverse (action, "LIST", a, b, c, d); } } return NOTOK; /* unknown XTND command */ } #endif BPOP /* */ int pop_quit () { int i; i = command ("QUIT"); (void) pop_done (); return i; } int pop_done () { (void) fclose (input); (void) fclose (output); return OK; } /* */ /* VARARGS1 */ int command (fmt, a, b, c, d) char *fmt, *a, *b, *c, *d; { char *cp, buffer[BUFSIZ]; (void) sprintf (buffer, fmt, a, b, c, d); if (poprint) if (pophack) { if (cp = index (buffer, ' ')) *cp = NULL; fprintf (stderr, "---> %s ********\n", buffer); if (cp) *cp = ' '; pophack = 0; } else fprintf (stderr, "---> %s\n", buffer); if (putline (buffer, output) == NOTOK) return NOTOK; switch (getline (response, sizeof response, input)) { case OK: if (poprint) fprintf (stderr, "<--- %s\n", response); return (*response < CHAR_ERR ? OK : NOTOK); case NOTOK: case DONE: if (poprint) fprintf (stderr, "%s\n", response); return NOTOK; } /* NOTREACHED */ } int multiline () { char buffer[BUFSIZ + TRMLEN]; if (getline (buffer, sizeof buffer, input) != OK) return NOTOK; #ifdef DEBUG if (poprint) fprintf (stderr, "<--- %s\n", response); #endif DEBUG if (strncmp (buffer, TRM, TRMLEN) == 0) { if (buffer[TRMLEN] == NULL) return DONE; else (void) strcpy (response, buffer + TRMLEN); } else (void) strcpy (response, buffer); return OK; } /* */ static int getline (s, n, iop) char *s; int n; FILE * iop; { int c; char *p; p = s; while (--n > 0 && (c = fgetc (iop)) != EOF) if ((*p++ = c) == '\n') break; if (ferror (iop) && c != EOF) { (void) strcpy (response, "error on connection"); return NOTOK; } if (c == EOF && p == s) { (void) strcpy (response, "connection closed by foreign host"); return DONE; } *p = NULL; if (*--p == '\n') *p = NULL; if (*--p == '\r') *p = NULL; return OK; } static putline (s, iop) char *s; FILE * iop; { (void) fprintf (iop, "%s\r\n", s); (void) fflush (iop); if (ferror (iop)) { (void) strcpy (response, "lost connection"); return NOTOK; } return OK; } @ 2.3 log @changes for marshall's popi/mshcmds stuff @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: pshsbr.c,v 2.2 1990/04/05 14:56:13 sources Exp jromine $"; d22 1 d25 1 @ 2.2 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d39 4 a42 1 static int traverse(), command(), multiline(), getline(); d347 1 a347 1 static int command (fmt, a, b, c, d) d388 1 a388 1 static int multiline () { @ 2.1 log @ANSI Compilance @ text @d2 3 @ 2.0 log @changes for SUN40 shared libraries and NNTP under bbc @ text @d36 2 @ 1.3 log @fix minor nntp bug @ text @@ 1.2 log @*** empty log message *** @ text @d150 4 a153 1 *nmsgs = xtnd_last - xtnd_first + 1; /* because of holes... */ @ 1.1 log @Initial revision @ text @d1 1 a1 1 /* popsbr.c - POP client subroutines */ d6 1 d30 6 d56 1 a56 1 if ((fd1 = client (host, "tcp", "pop", rpop, response)) == NOTOK) d66 1 a66 1 if (pop_set (fd1, fd2, snoop) == NOTOK) d75 1 a75 4 if (*response == '+' && command ("USER %s", user) != NOTOK && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"), pass) != NOTOK) d77 1 a77 1 if (*response != '+') { d96 1 a96 1 int pop_set (in, out, snoop) d100 1 d102 3 d137 2 a138 2 if (command ("STAT") == NOTOK) return NOTOK; d140 13 a152 2 *nmsgs = *nbytes = 0; (void) sscanf (response, "+OK %d %d", nmsgs, nbytes); d156 5 d162 4 d183 2 a184 1 if (command ("LIST %d", msgno) == NOTOK) a186 1 *msgs = *bytes = 0; d188 1 a188 2 *ids = 0; (void) sscanf (response, "+OK %d %d %d", msgs, bytes, ids); a189 2 else (void) sscanf (response, "+OK %d %d", msgs, bytes); d192 1 a192 31 if (command ("LIST") == NOTOK) return NOTOK; for (i = 0; i < *nmsgs; i++) switch (multiline ()) { case NOTOK: return NOTOK; case DONE: *nmsgs = ++i; return OK; case OK: *msgs = *bytes = 0; if (ids) { *ids = 0; (void) sscanf (response, "%d %d %d", msgs++, bytes++, ids++); } else (void) sscanf (response, "%d %d", msgs++, bytes++); break; } for (;;) switch (multiline ()) { case NOTOK: return NOTOK; case DONE: return OK; case OK: break; } a196 8 int pop_retr (msgno, action) int msgno, (*action) (); { return traverse (action, "RETR %d", msgno); } d250 1 a250 1 lines, d253 1 a253 1 return traverse (action, "TOP %d %d", msgno, lines); d257 8 d266 1 d269 1 a269 5 char *fmt, *a, *b, *c, *d; d271 2 a272 1 char buffer[BUFSIZ]; d274 36 a309 2 (void) sprintf (buffer, "XTND %s", fmt); return traverse (action, buffer, a, b, c, d); d366 1 a366 1 return (*response == '+' ? OK : NOTOK); d382 4 @