Deleted Added
sdiff udiff text old ( 90926 ) new ( 120945 )
full compact
1/*
2 * Copyright (c) 1997-2001, 2003 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.47 2003/04/04 02:10:17 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
140static char *pop_state_string[] = {
141 "INIT", "GREET", "USER", "PASS", "STAT", "RETR", "TOP",
142 "DELE", "XDELE", "QUIT"
143};
144
145#define PUSH_BUFSIZ 65536
146
147#define STEP 16
148
149struct write_state {
150 struct iovec *iovecs;
151 size_t niovecs, maxiovecs, allociovecs;
152 int fd;

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

267 out_len = snprintf (out_buf, sizeof(out_buf),
268 "USER %s\r\nPASS hej\r\nSTAT\r\n",
269 user);
270 if (out_len < 0)
271 errx (1, "snprintf failed");
272 if (net_write (s, out_buf, out_len) != out_len)
273 err (1, "write");
274 if (verbose > 1)
275 fprintf (stderr, "%s", out_buf);
276
277 if (!do_from)
278 write_state_init (&write_state, out_fd);
279
280 while(state != QUIT) {
281 fd_set readset, writeset;
282
283 FD_ZERO(&readset);
284 FD_ZERO(&writeset);
285 if (s >= FD_SETSIZE)
286 errx (1, "fd too large");
287 FD_SET(s,&readset);
288
289 if (verbose > 1)
290 fprintf (stderr, "state: %s count: %d asked_for: %d "
291 "retrieved: %d asked_deleted: %d\n",
292 pop_state_string[state],
293 count, asked_for, retrieved, asked_deleted);
294
295 if (((state == STAT || state == RETR || state == TOP)
296 && asked_for < count)
297 || (state == XDELE && !sent_xdele)
298 || (state == DELE && asked_deleted < count))
299 FD_SET(s,&writeset);
300 ret = select (s + 1, &readset, &writeset, NULL, NULL);
301 if (ret < 0) {
302 if (errno == EAGAIN)

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

338 if (beg[0] == '.' && beg[1] == '\r' && beg[2] == '\n') {
339 if (numheaders > 1)
340 fprintf (stdout, "\n");
341 state = STAT;
342 if (++retrieved == count) {
343 state = QUIT;
344 net_write (s, "QUIT\r\n", 6);
345 if (verbose > 1)
346 fprintf (stderr, "QUIT\r\n");
347 }
348 }
349 rem -= p - beg + 2;
350 beg = p + 2;
351 } else if (state == RETR) {
352 char *copy = beg;
353 if (beg[0] == '.') {
354 if (beg[1] == '\r' && beg[2] == '\n') {

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

361 write_state_flush (&write_state);
362 if (fsync (out_fd) < 0)
363 err (1, "fsync");
364 close(out_fd);
365 if (leavep) {
366 state = QUIT;
367 net_write (s, "QUIT\r\n", 6);
368 if (verbose > 1)
369 fprintf (stderr, "QUIT\r\n");
370 } else {
371 if (forkp) {
372 pid_t pid;
373
374 pid = fork();
375 if (pid < 0)
376 warn ("fork");
377 else if(pid != 0) {

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

408 if (do_from)
409 state = TOP;
410 else
411 state = RETR;
412 } else if (state == XDELE) {
413 state = QUIT;
414 net_write (s, "QUIT\r\n", 6);
415 if (verbose > 1)
416 fprintf (stderr, "QUIT\r\n");
417 break;
418 } else if (state == DELE) {
419 if (++deleted == count) {
420 state = QUIT;
421 net_write (s, "QUIT\r\n", 6);
422 if (verbose > 1)
423 fprintf (stderr, "QUIT\r\n");
424 break;
425 }
426 } else if (++state == STAT) {
427 if(sscanf (beg + 4, "%u %u", &count, &bytes) != 2)
428 errx(1, "Bad STAT-line: %.*s", (int)(p - beg), beg);
429 if (verbose) {
430 fprintf (stderr, "%u message(s) (%u bytes). "
431 "fetching... ",
432 count, bytes);
433 if (do_from)
434 fprintf (stderr, "\n");
435 } else if (do_count) {
436 fprintf (stderr, "%u message(s) (%u bytes).\n",
437 count, bytes);
438 }
439 if (count == 0) {
440 state = QUIT;
441 net_write (s, "QUIT\r\n", 6);
442 if (verbose > 1)
443 fprintf (stderr, "QUIT\r\n");
444 break;
445 }
446 }
447
448 rem -= p - beg + 2;
449 beg = p + 2;
450 } else {
451 if(state == XDELE) {

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

478 else if(state == DELE)
479 out_len = snprintf (out_buf, sizeof(out_buf),
480 "DELE %u\r\n", ++asked_deleted);
481 if (out_len < 0)
482 errx (1, "snprintf failed");
483 if (net_write (s, out_buf, out_len) != out_len)
484 err (1, "write");
485 if (verbose > 1)
486 fprintf (stderr, "%s", out_buf);
487 }
488 }
489 if (verbose)
490 fprintf (stderr, "Done\n");
491 if (do_from) {
492 free (tmp);
493 free (headers);
494 } else {

--- 336 unchanged lines hidden ---