Deleted Added
full compact
1/*
2 * Copyright (c) 1997-2001 Kungliga Tekniska H�gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include "push_locl.h"
35RCSID("$Id: push.c,v 1.45 2001/09/04 09:45:52 assar Exp $");
36
37#ifdef KRB4
38static int use_v4 = -1;
39#endif
40
41#ifdef KRB5
42static int use_v5 = -1;
43static krb5_context context;

--- 88 unchanged lines hidden (view full) ---

132 (void *)&nodelay, sizeof(nodelay)) < 0)
133 err (1, "setsockopt TCP_NODELAY");
134 return s;
135}
136
137typedef enum { INIT = 0, GREET, USER, PASS, STAT, RETR, TOP,
138 DELE, XDELE, QUIT} pop_state;
139
140#define PUSH_BUFSIZ 65536
141
142#define STEP 16
143
144struct write_state {
145 struct iovec *iovecs;
146 size_t niovecs, maxiovecs, allociovecs;
147 int fd;

--- 114 unchanged lines hidden (view full) ---

262 out_len = snprintf (out_buf, sizeof(out_buf),
263 "USER %s\r\nPASS hej\r\nSTAT\r\n",
264 user);
265 if (out_len < 0)
266 errx (1, "snprintf failed");
267 if (net_write (s, out_buf, out_len) != out_len)
268 err (1, "write");
269 if (verbose > 1)
270 write (STDERR_FILENO, out_buf, out_len);
271
272 if (!do_from)
273 write_state_init (&write_state, out_fd);
274
275 while(state != QUIT) {
276 fd_set readset, writeset;
277
278 FD_ZERO(&readset);
279 FD_ZERO(&writeset);
280 if (s >= FD_SETSIZE)
281 errx (1, "fd too large");
282 FD_SET(s,&readset);
283 if (((state == STAT || state == RETR || state == TOP)
284 && asked_for < count)
285 || (state == XDELE && !sent_xdele)
286 || (state == DELE && asked_deleted < count))
287 FD_SET(s,&writeset);
288 ret = select (s + 1, &readset, &writeset, NULL, NULL);
289 if (ret < 0) {
290 if (errno == EAGAIN)

--- 35 unchanged lines hidden (view full) ---

326 if (beg[0] == '.' && beg[1] == '\r' && beg[2] == '\n') {
327 if (numheaders > 1)
328 fprintf (stdout, "\n");
329 state = STAT;
330 if (++retrieved == count) {
331 state = QUIT;
332 net_write (s, "QUIT\r\n", 6);
333 if (verbose > 1)
334 net_write (STDERR_FILENO, "QUIT\r\n", 6);
335 }
336 }
337 rem -= p - beg + 2;
338 beg = p + 2;
339 } else if (state == RETR) {
340 char *copy = beg;
341 if (beg[0] == '.') {
342 if (beg[1] == '\r' && beg[2] == '\n') {

--- 6 unchanged lines hidden (view full) ---

349 write_state_flush (&write_state);
350 if (fsync (out_fd) < 0)
351 err (1, "fsync");
352 close(out_fd);
353 if (leavep) {
354 state = QUIT;
355 net_write (s, "QUIT\r\n", 6);
356 if (verbose > 1)
357 net_write (STDERR_FILENO, "QUIT\r\n", 6);
358 } else {
359 if (forkp) {
360 pid_t pid;
361
362 pid = fork();
363 if (pid < 0)
364 warn ("fork");
365 else if(pid != 0) {

--- 30 unchanged lines hidden (view full) ---

396 if (do_from)
397 state = TOP;
398 else
399 state = RETR;
400 } else if (state == XDELE) {
401 state = QUIT;
402 net_write (s, "QUIT\r\n", 6);
403 if (verbose > 1)
404 net_write (STDERR_FILENO, "QUIT\r\n", 6);
405 break;
406 } else if (state == DELE) {
407 if (++deleted == count) {
408 state = QUIT;
409 net_write (s, "QUIT\r\n", 6);
410 if (verbose > 1)
411 net_write (STDERR_FILENO, "QUIT\r\n", 6);
412 break;
413 }
414 } else if (++state == STAT) {
415 if(sscanf (beg + 4, "%u %u", &count, &bytes) != 2)
416 errx(1, "Bad STAT-line: %.*s", (int)(p - beg), beg);
417 if (verbose) {
418 fprintf (stderr, "%u message(s) (%u bytes). "
419 "fetching... ",
420 count, bytes);
421 if (do_from)
422 fprintf (stderr, "\n");
423 } else if (do_count) {
424 fprintf (stderr, "%u message(s) (%u bytes).\n",
425 count, bytes);
426 }
427 if (count == 0) {
428 state = QUIT;
429 net_write (s, "QUIT\r\n", 6);
430 if (verbose > 1)
431 net_write (STDERR_FILENO, "QUIT\r\n", 6);
432 break;
433 }
434 }
435
436 rem -= p - beg + 2;
437 beg = p + 2;
438 } else {
439 if(state == XDELE) {

--- 26 unchanged lines hidden (view full) ---

466 else if(state == DELE)
467 out_len = snprintf (out_buf, sizeof(out_buf),
468 "DELE %u\r\n", ++asked_deleted);
469 if (out_len < 0)
470 errx (1, "snprintf failed");
471 if (net_write (s, out_buf, out_len) != out_len)
472 err (1, "write");
473 if (verbose > 1)
474 write (STDERR_FILENO, out_buf, out_len);
475 }
476 }
477 if (verbose)
478 fprintf (stderr, "Done\n");
479 if (do_from) {
480 free (tmp);
481 free (headers);
482 } else {

--- 336 unchanged lines hidden ---