annotate src/pop3/client.c @ 3879:928229f8b3e6 HEAD

deinit, unref, destroy, close, free, etc. functions now take a pointer to their data pointer, and set it to NULL. This makes double-frees less likely to cause security holes.
author Timo Sirainen <tss@iki.fi>
date Sat, 14 Jan 2006 20:47:20 +0200
parents 55df57c028d4
children aeb424e64f24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
4 #include "buffer.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ioloop.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "network.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "istream.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "ostream.h"
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
9 #include "str.h"
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
10 #include "var-expand.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "mail-storage.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "commands.h"
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
13 #include "mail-search.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <stdlib.h>
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
1053
28f606ada24a Reduce input buffer size
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
17 /* max. length of input command line (spec says 512) */
28f606ada24a Reduce input buffer size
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
18 #define MAX_INBUF_SIZE 2048
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
20 /* Stop reading input when output buffer has this many bytes. Once the buffer
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
21 size has dropped to half of it, start reading input again. */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
22 #define OUTBUF_THROTTLE_SIZE 4096
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
23
2927
6e2129a4a595 Timeout changes. Default idle timeout is now 10 minutes instead of 30
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
24 /* If we can't send anything for 10 minutes, disconnect the client */
6e2129a4a595 Timeout changes. Default idle timeout is now 10 minutes instead of 30
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
25 #define CLIENT_OUTPUT_TIMEOUT (10*60)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 /* Disconnect client when it sends too many bad commands in a row */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 #define CLIENT_MAX_BAD_COMMANDS 20
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 /* Disconnect client after idling this many seconds */
2927
6e2129a4a595 Timeout changes. Default idle timeout is now 10 minutes instead of 30
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
31 #define CLIENT_IDLE_TIMEOUT (10*60)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 extern struct mail_storage_callbacks mail_storage_callbacks;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 static struct client *my_client; /* we don't need more than one currently */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 static struct timeout *to_idle;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 static void client_input(void *context);
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2735
diff changeset
39 static int client_output(void *context);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2927
diff changeset
41 static int sync_mailbox(struct mailbox *box, struct mailbox_status *status)
2322
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
42 {
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
43 struct mailbox_sync_context *ctx;
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
44 struct mailbox_sync_rec sync_rec;
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
45
2665
ccf563859be5 Split sync_flag_full into sync_flag_full_read and _write. Closing mailbox
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
46 ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
2322
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
47 while (mailbox_sync_next(ctx, &sync_rec) > 0)
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
48 ;
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
49 return mailbox_sync_deinit(&ctx, status);
2322
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
50 }
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
51
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
52 static int init_mailbox(struct client *client)
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
53 {
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
54 struct mail_search_arg search_arg;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
55 struct mailbox_transaction_context *t;
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
56 struct mail_search_context *ctx;
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2927
diff changeset
57 struct mailbox_status status;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
58 struct mail *mail;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
59 buffer_t *message_sizes_buf;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3517
diff changeset
60 int i;
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3517
diff changeset
61 bool failed;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
62
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
63 message_sizes_buf = buffer_create_dynamic(default_pool, 512);
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
64
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
65 memset(&search_arg, 0, sizeof(search_arg));
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
66 search_arg.type = SEARCH_ALL;
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
67
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
68 for (i = 0; i < 2; i++) {
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2927
diff changeset
69 if (sync_mailbox(client->mailbox, &status) < 0) {
2322
aae574ed7f4c Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
70 client_send_storage_error(client);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
71 break;
2092
952a4106d3b8 assert fix
Timo Sirainen <tss@iki.fi>
parents: 2039
diff changeset
72 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2927
diff changeset
73 client->uid_validity = status.uidvalidity;
2092
952a4106d3b8 assert fix
Timo Sirainen <tss@iki.fi>
parents: 2039
diff changeset
74
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
75 t = mailbox_transaction_begin(client->mailbox, 0);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
76 ctx = mailbox_search_init(t, NULL, &search_arg, NULL);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
77 if (ctx == NULL) {
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
78 client_send_storage_error(client);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
79 mailbox_transaction_rollback(&t);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
80 break;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
81 }
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
82
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
83 client->last_seen = 0;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
84 client->total_size = 0;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
85 buffer_set_used_size(message_sizes_buf, 0);
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
86
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
87 failed = FALSE;
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
88 mail = mail_alloc(t, MAIL_FETCH_VIRTUAL_SIZE, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
89 while (mailbox_search_next(ctx, mail) > 0) {
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
90 uoff_t size = mail_get_virtual_size(mail);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
91
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
92 if (size == (uoff_t)-1) {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
93 failed = TRUE;
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
94 break;
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
95 }
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2525
diff changeset
96
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
97 if ((mail_get_flags(mail) & MAIL_SEEN) != 0)
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2525
diff changeset
98 client->last_seen = mail->seq;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
99 client->total_size += size;
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
100
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
101 buffer_append(message_sizes_buf, &size, sizeof(size));
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
102 }
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
103 client->messages_count =
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
104 message_sizes_buf->used / sizeof(uoff_t);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
105
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
106 mail_free(&mail);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
107 if (mailbox_search_deinit(&ctx) < 0) {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
108 client_send_storage_error(client);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
109 mailbox_transaction_rollback(&t);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
110 break;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
111 }
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
112
2010
01d2eb10a1c9 index wasn't unlocked initially
Timo Sirainen <tss@iki.fi>
parents: 1994
diff changeset
113 if (!failed) {
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
114 client->trans = t;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
115 client->message_sizes =
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
116 buffer_free_without_data(message_sizes_buf);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
117 return TRUE;
2010
01d2eb10a1c9 index wasn't unlocked initially
Timo Sirainen <tss@iki.fi>
parents: 1994
diff changeset
118 }
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
119
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
120 /* well, sync and try again */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
121 mailbox_transaction_rollback(&t);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
122 }
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
123
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
124 if (i == 2)
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
125 client_send_line(client, "-ERR [IN-USE] Couldn't sync mailbox.");
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
126 buffer_free(message_sizes_buf);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
127 return FALSE;
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
128 }
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
129
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
130 struct client *client_create(int hin, int hout, struct mail_storage *storage)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 struct client *client;
2039
f0925b2271e1 Added pop3_mails_keep_recent option. Fixed recent assert crash.
Timo Sirainen <tss@iki.fi>
parents: 2020
diff changeset
133 enum mailbox_open_flags flags;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3517
diff changeset
134 bool syntax_error, temporary_error;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
136 /* always use nonblocking I/O */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
137 net_set_nonblock(hin, TRUE);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
138 net_set_nonblock(hout, TRUE);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
139
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 client = i_new(struct client, 1);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 client->input = i_stream_create_file(hin, default_pool,
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 MAX_INBUF_SIZE, FALSE);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
143 client->output = o_stream_create_file(hout, default_pool,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
144 (size_t)-1, FALSE);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
145 o_stream_set_flush_callback(client->output, client_output, client);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 client->io = io_add(hin, IO_READ, client_input, client);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 client->last_input = ioloop_time;
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
149 client->storage = storage;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
151 mail_storage_set_callbacks(storage, &mail_storage_callbacks, client);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152
2039
f0925b2271e1 Added pop3_mails_keep_recent option. Fixed recent assert crash.
Timo Sirainen <tss@iki.fi>
parents: 2020
diff changeset
153 flags = 0;
2719
f8adc5cb2508 Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents: 2712
diff changeset
154 if (no_flag_updates)
2039
f0925b2271e1 Added pop3_mails_keep_recent option. Fixed recent assert crash.
Timo Sirainen <tss@iki.fi>
parents: 2020
diff changeset
155 flags |= MAILBOX_OPEN_KEEP_RECENT;
3245
6491dab63e54 Added input stream parameter to mailbox_open(). With mbox it now allows
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
156 client->mailbox = mailbox_open(storage, "INBOX", NULL, flags);
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
157 if (client->mailbox == NULL) {
2525
633683d78bcb Log error message if we can't open INBOX.
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
158 i_error("Couldn't open INBOX: %s",
3517
46bfbbcc3c54 Added separate "temporary error" flag for mail_storage_get_last_error().
Timo Sirainen <tss@iki.fi>
parents: 3469
diff changeset
159 mail_storage_get_last_error(storage, &syntax_error,
46bfbbcc3c54 Added separate "temporary error" flag for mail_storage_get_last_error().
Timo Sirainen <tss@iki.fi>
parents: 3469
diff changeset
160 &temporary_error));
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
161 client_send_line(client, "-ERR No INBOX for user.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
162 client_destroy(client, "No INBOX for user.");
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
163 return NULL;
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
164 }
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
165
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
166 if (!init_mailbox(client)) {
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
167 client_destroy(client, "Mailbox init failed");
1363
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
168 return NULL;
383e4b9e347c Crashfix if there was some errors while opening mailbox
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
169 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 i_assert(my_client == NULL);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 my_client = client;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173
1646
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1640
diff changeset
174 if (hook_client_created != NULL)
a7c742b940e5 Added pop3 hooks
Timo Sirainen <tss@iki.fi>
parents: 1640
diff changeset
175 hook_client_created(&client);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 return client;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
179 static const char *client_stats(struct client *client)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 {
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
181 static struct var_expand_table static_tab[] = {
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
182 { 'T', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
183 { 't', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
184 { 'R', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
185 { 'r', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
186 { 'd', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
187 { 'm', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
188 { 's', NULL },
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
189 { '\0', NULL }
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
190 };
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
191 struct var_expand_table *tab;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
192 string_t *str;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
193
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
194 tab = t_malloc(sizeof(static_tab));
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
195 memcpy(tab, static_tab, sizeof(static_tab));
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
196
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
197 tab[0].value = dec2str(client->top_bytes);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
198 tab[1].value = dec2str(client->top_count);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
199 tab[2].value = dec2str(client->retr_bytes);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
200 tab[3].value = dec2str(client->retr_count);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
201 tab[4].value = dec2str(client->deleted_count);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
202 tab[5].value = dec2str(client->messages_count);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
203 tab[6].value = dec2str(client->total_size);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
204
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
205 str = t_str_new(128);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
206 var_expand(str, logout_format, tab);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
207 return str_c(str);
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
208 }
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
209
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
210 void client_destroy(struct client *client, const char *reason)
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
211 {
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
212 if (reason != NULL)
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
213 i_info("%s %s", reason, client_stats(client));
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
214
2502
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
215 if (client->cmd != NULL) {
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
216 /* deinitialize command */
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
217 i_stream_close(client->input);
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
218 o_stream_close(client->output);
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
219 client->cmd(client);
2695
Timo Sirainen <tss@iki.fi>
parents: 2665
diff changeset
220 i_assert(client->cmd == NULL);
2502
e628e0ab8924 Deinitialize pop3 commands if connection is closed unexpectedly.
Timo Sirainen <tss@iki.fi>
parents: 2494
diff changeset
221 }
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
222 if (client->trans != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
223 mailbox_transaction_rollback(&client->trans);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
224 if (client->mailbox != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
225 mailbox_close(&client->mailbox);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
226 mail_storage_destroy(&client->storage);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
228 i_free(client->message_sizes);
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
229 i_free(client->deleted_bitmask);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
231 if (client->io != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
232 io_remove(&client->io);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
234 i_stream_unref(&client->input);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
235 o_stream_unref(&client->output);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 i_free(client);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 /* quit the program */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 my_client = NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 io_loop_stop(ioloop);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
244 void client_disconnect(struct client *client, const char *reason)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 {
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
246 if (reason != NULL)
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
247 i_info("%s %s", reason, client_stats(client));
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
248
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
249 (void)o_stream_flush(client->output);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 i_stream_close(client->input);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 o_stream_close(client->output);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
255 int client_send_line(struct client *client, const char *fmt, ...)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 va_list va;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
258 string_t *str;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
259 ssize_t ret;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 if (client->output->closed)
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
262 return -1;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263
2015
0fae715679bc t_push/t_pop
Timo Sirainen <tss@iki.fi>
parents: 2012
diff changeset
264 t_push();
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 va_start(va, fmt);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
266
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
267 str = t_str_new(256);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
268 str_vprintfa(str, fmt, va);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
269 str_append(str, "\r\n");
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
270
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
271 ret = o_stream_send(client->output, str_data(str), str_len(str));
2735
25113dcc9705 Crashfix
Timo Sirainen <tss@iki.fi>
parents: 2722
diff changeset
272 if (ret >= 0) {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
273 i_assert((size_t)ret == str_len(str));
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
274
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
275 if (o_stream_get_buffer_used_size(client->output) <
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
276 OUTBUF_THROTTLE_SIZE) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
277 ret = 1;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
278 client->last_output = ioloop_time;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
279 } else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
280 ret = 0;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
281 if (client->io != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
282 /* no more input until client has read
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
283 our output */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
284 io_remove(&client->io);
3352
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
285
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
286 /* If someone happens to flush output,
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
287 we want to get our IO handler back in
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
288 flush callback */
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
289 o_stream_set_flush_pending(client->output,
75cfcf7736a7 Connection could have gotten stuck sometimes, doing nothing until idle
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
290 TRUE);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
291 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
292 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
293 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
294
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 va_end(va);
2015
0fae715679bc t_push/t_pop
Timo Sirainen <tss@iki.fi>
parents: 2012
diff changeset
296 t_pop();
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
297 return (int)ret;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
300 void client_send_storage_error(struct client *client)
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
301 {
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
302 const char *error;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3517
diff changeset
303 bool syntax, temporary_error;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
304
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
305 if (mailbox_is_inconsistent(client->mailbox)) {
1415
c1a7da406bbd Handle inconsistency error separately.
Timo Sirainen <tss@iki.fi>
parents: 1412
diff changeset
306 client_send_line(client, "-ERR Mailbox is in inconsistent "
c1a7da406bbd Handle inconsistency error separately.
Timo Sirainen <tss@iki.fi>
parents: 1412
diff changeset
307 "state, please relogin.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
308 client_disconnect(client, "Mailbox is in inconsistent state.");
1415
c1a7da406bbd Handle inconsistency error separately.
Timo Sirainen <tss@iki.fi>
parents: 1412
diff changeset
309 return;
c1a7da406bbd Handle inconsistency error separately.
Timo Sirainen <tss@iki.fi>
parents: 1412
diff changeset
310 }
c1a7da406bbd Handle inconsistency error separately.
Timo Sirainen <tss@iki.fi>
parents: 1412
diff changeset
311
3517
46bfbbcc3c54 Added separate "temporary error" flag for mail_storage_get_last_error().
Timo Sirainen <tss@iki.fi>
parents: 3469
diff changeset
312 error = mail_storage_get_last_error(client->storage, &syntax,
46bfbbcc3c54 Added separate "temporary error" flag for mail_storage_get_last_error().
Timo Sirainen <tss@iki.fi>
parents: 3469
diff changeset
313 &temporary_error);
1412
ac714d7d0b67 If no error is set, give "BUG: Unknown error" rather than try to print NULL
Timo Sirainen <tss@iki.fi>
parents: 1363
diff changeset
314 client_send_line(client, "-ERR %s", error != NULL ? error :
ac714d7d0b67 If no error is set, give "BUG: Unknown error" rather than try to print NULL
Timo Sirainen <tss@iki.fi>
parents: 1363
diff changeset
315 "BUG: Unknown error");
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
316 }
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
317
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 static void client_input(void *context)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 struct client *client = context;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 char *line, *args;
3469
7e39590da48a Call t_push/t_pop around client command execution function, so if client
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
322 int ret;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
324 if (client->cmd != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
325 /* we're still processing a command. wait until it's
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
326 finished. */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
327 io_remove(&client->io);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
328 client->waiting_input = TRUE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
329 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
330 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
331
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
332 client->waiting_input = FALSE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 client->last_input = ioloop_time;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 switch (i_stream_read(client->input)) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 case -1:
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 /* disconnected */
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
338 client_destroy(client, "Disconnected");
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 case -2:
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 /* line too long, kill it */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 client_send_line(client, "-ERR Input line too long.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
343 client_destroy(client, "Input line too long.");
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 o_stream_cork(client->output);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 while (!client->output->closed &&
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 (line = i_stream_next_line(client->input)) != NULL) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 args = strchr(line, ' ');
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 if (args == NULL)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 args = "";
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 else
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 *args++ = '\0';
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355
3469
7e39590da48a Call t_push/t_pop around client command execution function, so if client
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
356 t_push();
7e39590da48a Call t_push/t_pop around client command execution function, so if client
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
357 ret = client_command_execute(client, line, args);
7e39590da48a Call t_push/t_pop around client command execution function, so if client
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
358 t_pop();
7e39590da48a Call t_push/t_pop around client command execution function, so if client
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
359 if (ret >= 0) {
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1053
diff changeset
360 client->bad_counter = 0;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
361 if (client->cmd != NULL) {
3336
a3a72d5bdfce o_stream_uncork() was previously always setting IO_WRITE handler even if
Timo Sirainen <tss@iki.fi>
parents: 3260
diff changeset
362 o_stream_set_flush_pending(client->output,
a3a72d5bdfce o_stream_uncork() was previously always setting IO_WRITE handler even if
Timo Sirainen <tss@iki.fi>
parents: 3260
diff changeset
363 TRUE);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
364 client->waiting_input = TRUE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
365 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
366 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
367 } else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) {
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1053
diff changeset
368 client_send_line(client, "-ERR Too many bad commands.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
369 client_disconnect(client, "Too many bad commands.");
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1053
diff changeset
370 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
372 o_stream_uncork(client->output);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 if (client->output->closed)
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
375 client_destroy(client, NULL);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2735
diff changeset
378 static int client_output(void *context)
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
379 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
380 struct client *client = context;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
381 int ret;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
382
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
383 if ((ret = o_stream_flush(client->output)) < 0) {
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
384 client_destroy(client, NULL);
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2735
diff changeset
385 return 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
386 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
387
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
388 client->last_output = ioloop_time;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
389
3394
30099e1ccf97 Small optimization
Timo Sirainen <tss@iki.fi>
parents: 3391
diff changeset
390 if (client->cmd != NULL) {
30099e1ccf97 Small optimization
Timo Sirainen <tss@iki.fi>
parents: 3391
diff changeset
391 o_stream_cork(client->output);
2494
a2e2c76021b9 Fixes for nonblocking changes.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
392 client->cmd(client);
3394
30099e1ccf97 Small optimization
Timo Sirainen <tss@iki.fi>
parents: 3391
diff changeset
393 o_stream_uncork(client->output);
30099e1ccf97 Small optimization
Timo Sirainen <tss@iki.fi>
parents: 3391
diff changeset
394 }
2494
a2e2c76021b9 Fixes for nonblocking changes.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
395
3391
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
396 if (client->cmd == NULL) {
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
397 if (o_stream_get_buffer_used_size(client->output) <
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
398 OUTBUF_THROTTLE_SIZE/2 && client->io == NULL) {
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
399 /* enable input again */
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
400 client->io = io_add(i_stream_get_fd(client->input),
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
401 IO_READ, client_input, client);
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
402 }
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
403 if (client->io != NULL && client->waiting_input)
d01de9d362c1 Code cleanup. Removed useless previous "fix".
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
404 client_input(client);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
405 }
2494
a2e2c76021b9 Fixes for nonblocking changes.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
406
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2735
diff changeset
407 return client->cmd == NULL;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
408 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
409
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 static void idle_timeout(void *context __attr_unused__)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 if (my_client == NULL)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
415 if (my_client->cmd != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
416 if (ioloop_time - my_client->last_output >=
2927
6e2129a4a595 Timeout changes. Default idle timeout is now 10 minutes instead of 30
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
417 CLIENT_OUTPUT_TIMEOUT)
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
418 client_destroy(my_client, "Disconnected for inactivity.");
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
419 } else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
420 if (ioloop_time - my_client->last_input >=
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
421 CLIENT_IDLE_TIMEOUT) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
422 client_send_line(my_client,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
423 "-ERR Disconnected for inactivity.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
424 client_destroy(my_client, "Disconnected for inactivity.");
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2322
diff changeset
425 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 void clients_init(void)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 my_client = NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 to_idle = timeout_add(10000, idle_timeout, NULL);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 void clients_deinit(void)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 if (my_client != NULL) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 client_send_line(my_client, "-ERR Server shutting down.");
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3372
diff changeset
439 client_destroy(my_client, "Server shutting down.");
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
442 timeout_remove(&to_idle);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 }