Deleted Added
full compact
push.c (90926) push.c (120945)
1/*
1/*
2 * Copyright (c) 1997-2001 Kungliga Tekniska H�gskolan
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"
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 $");
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
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
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)
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)
270 write (STDERR_FILENO, out_buf, out_len);
275 fprintf (stderr, "%s", out_buf);
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);
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
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)
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)
334 net_write (STDERR_FILENO, "QUIT\r\n", 6);
346 fprintf (stderr, "QUIT\r\n");
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)
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)
357 net_write (STDERR_FILENO, "QUIT\r\n", 6);
369 fprintf (stderr, "QUIT\r\n");
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)
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)
404 net_write (STDERR_FILENO, "QUIT\r\n", 6);
416 fprintf (stderr, "QUIT\r\n");
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)
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)
411 net_write (STDERR_FILENO, "QUIT\r\n", 6);
423 fprintf (stderr, "QUIT\r\n");
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)
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)
431 net_write (STDERR_FILENO, "QUIT\r\n", 6);
443 fprintf (stderr, "QUIT\r\n");
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)
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)
474 write (STDERR_FILENO, out_buf, out_len);
486 fprintf (stderr, "%s", out_buf);
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 ---
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 ---