[dovecot-cvs] dovecot/src/pop3 client.c, 1.52, 1.53 client.h, 1.10, 1.11 commands.c, 1.41, 1.42 common.h, 1.8, 1.9 main.c, 1.24, 1.25

cras at dovecot.org cras at dovecot.org
Sat May 14 23:32:11 EEST 2005


Update of /var/lib/cvs/dovecot/src/pop3
In directory talvi:/tmp/cvs-serv17364/src/pop3

Modified Files:
	client.c client.h commands.c common.h main.c 
Log Message:
Added configurable logging for login process. Added configurable pop3 logout
string. Based on a patch by Andrey Panin.



Index: client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/client.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- client.c	13 May 2005 13:11:17 -0000	1.52
+++ client.c	14 May 2005 20:32:08 -0000	1.53
@@ -7,6 +7,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
+#include "var-expand.h"
 #include "mail-storage.h"
 #include "commands.h"
 #include "mail-search.h"
@@ -156,12 +157,12 @@
 		i_error("Couldn't open INBOX: %s",
 			mail_storage_get_last_error(storage, &syntax_error));
 		client_send_line(client, "-ERR No INBOX for user.");
-		client_destroy(client);
+		client_destroy(client, "No INBOX for user.");
 		return NULL;
 	}
 
 	if (!init_mailbox(client)) {
-		client_destroy(client);
+		client_destroy(client, "Mailbox init failed");
 		return NULL;
 	}
 
@@ -173,8 +174,42 @@
 	return client;
 }
 
-void client_destroy(struct client *client)
+static const char *client_stats(struct client *client)
+{
+	static struct var_expand_table static_tab[] = {
+		{ 'T', NULL },
+		{ 't', NULL },
+		{ 'R', NULL },
+		{ 'r', NULL },
+		{ 'd', NULL },
+		{ 'm', NULL },
+		{ 's', NULL },
+		{ '\0', NULL }
+	};
+	struct var_expand_table *tab;
+	string_t *str;
+
+	tab = t_malloc(sizeof(static_tab));
+	memcpy(tab, static_tab, sizeof(static_tab));
+
+	tab[0].value = dec2str(client->top_bytes);
+	tab[1].value = dec2str(client->top_count);
+	tab[2].value = dec2str(client->retr_bytes);
+	tab[3].value = dec2str(client->retr_count);
+	tab[4].value = dec2str(client->deleted_count);
+	tab[5].value = dec2str(client->messages_count);
+	tab[6].value = dec2str(client->total_size);
+
+	str = t_str_new(128);
+	var_expand(str, logout_format, tab);
+	return str_c(str);
+}
+
+void client_destroy(struct client *client, const char *reason)
 {
+	if (reason != NULL)
+		i_info("%s %s", reason, client_stats(client));
+
 	if (client->cmd != NULL) {
 		/* deinitialize command */
 		i_stream_close(client->input);
@@ -204,8 +239,11 @@
 	io_loop_stop(ioloop);
 }
 
-void client_disconnect(struct client *client)
+void client_disconnect(struct client *client, const char *reason)
 {
+	if (reason != NULL)
+		i_info("%s %s", reason, client_stats(client));
+
 	(void)o_stream_flush(client->output);
 
 	i_stream_close(client->input);
@@ -266,7 +304,7 @@
 	if (mailbox_is_inconsistent(client->mailbox)) {
 		client_send_line(client, "-ERR Mailbox is in inconsistent "
 				 "state, please relogin.");
-		client_disconnect(client);
+		client_disconnect(client, "Mailbox is in inconsistent state.");
 		return;
 	}
 
@@ -295,12 +333,12 @@
 	switch (i_stream_read(client->input)) {
 	case -1:
 		/* disconnected */
-		client_destroy(client);
+		client_destroy(client, "Disconnected");
 		return;
 	case -2:
 		/* line too long, kill it */
 		client_send_line(client, "-ERR Input line too long.");
-		client_destroy(client);
+		client_destroy(client, "Input line too long.");
 		return;
 	}
 
@@ -323,13 +361,13 @@
 			}
 		} else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) {
 			client_send_line(client, "-ERR Too many bad commands.");
-			client_disconnect(client);
+			client_disconnect(client, "Too many bad commands.");
 		}
 	}
 	o_stream_uncork(client->output);
 
 	if (client->output->closed)
-		client_destroy(client);
+		client_destroy(client, NULL);
 }
 
 static int client_output(void *context)
@@ -338,7 +376,7 @@
 	int ret;
 
 	if ((ret = o_stream_flush(client->output)) < 0) {
-		client_destroy(client);
+		client_destroy(client, NULL);
 		return 1;
 	}
 
@@ -374,13 +412,13 @@
 	if (my_client->cmd != NULL) {
 		if (ioloop_time - my_client->last_output >=
 		    CLIENT_OUTPUT_TIMEOUT)
-			client_destroy(my_client);
+			client_destroy(my_client, "Disconnected for inactivity.");
 	} else {
 		if (ioloop_time - my_client->last_input >=
 		    CLIENT_IDLE_TIMEOUT) {
 			client_send_line(my_client,
 					 "-ERR Disconnected for inactivity.");
-			client_destroy(my_client);
+			client_destroy(my_client, "Disconnected for inactivity.");
 		}
 	}
 }
@@ -395,7 +433,7 @@
 {
 	if (my_client != NULL) {
 		client_send_line(my_client, "-ERR Server shutting down.");
-		client_destroy(my_client);
+		client_destroy(my_client, "Server shutting down.");
 	}
 
 	timeout_remove(to_idle);

Index: client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/client.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- client.h	15 Dec 2004 20:05:19 -0000	1.10
+++ client.h	14 May 2005 20:32:08 -0000	1.11
@@ -30,6 +30,14 @@
 	uoff_t deleted_size;
 	uint32_t last_seen;
 
+	uoff_t top_bytes;
+	uoff_t retr_bytes;
+	unsigned int top_count;
+	unsigned int retr_count;
+
+	uoff_t *byte_counter;
+	uoff_t byte_counter_offset;
+
 	unsigned char *deleted_bitmask;
 
 	unsigned int deleted:1;
@@ -39,10 +47,10 @@
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
 struct client *client_create(int hin, int hout, struct mail_storage *storage);
-void client_destroy(struct client *client);
+void client_destroy(struct client *client, const char *reason);
 
 /* Disconnect client connection */
-void client_disconnect(struct client *client);
+void client_disconnect(struct client *client, const char *reason);
 
 /* Send a line of data to client */
 int client_send_line(struct client *client, const char *fmt, ...)

Index: commands.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/commands.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- commands.c	8 May 2005 09:38:36 -0000	1.41
+++ commands.c	14 May 2005 20:32:08 -0000	1.42
@@ -217,7 +217,7 @@
 	if (client->deleted) {
 		if (!expunge_mails(client)) {
 			client_send_storage_error(client);
-			client_disconnect(client);
+			client_disconnect(client, "Storage error during logout.");
 			return TRUE;
 		}
 	}
@@ -230,7 +230,7 @@
 	else
 		client_send_line(client, "+OK Logging out, messages deleted.");
 
-	client_disconnect(client);
+	client_disconnect(client, "Logout.");
 	return TRUE;
 }
 
@@ -342,6 +342,10 @@
 		(void)o_stream_send(client->output, "\r\n", 2);
 	}
 
+	*client->byte_counter +=
+		client->output->offset - client->byte_counter_offset;
+        client->byte_counter = NULL;
+
 	client_send_line(client, ".");
 	fetch_deinit(ctx);
 	client->cmd = NULL;
@@ -405,6 +409,10 @@
 	if (client->last_seen <= msgnum)
 		client->last_seen = msgnum+1;
 
+	client->retr_count++;
+	client->byte_counter = &client->retr_bytes;
+	client->byte_counter_offset = client->output->offset;
+
 	fetch(client, msgnum, (uoff_t)-1);
 	return TRUE;
 }
@@ -468,6 +476,10 @@
 	if (get_size(client, args, &max_lines) == NULL)
 		return FALSE;
 
+	client->top_count++;
+	client->byte_counter = &client->top_bytes;
+	client->byte_counter_offset = client->output->offset;
+
 	fetch(client, msgnum, max_lines);
 	return TRUE;
 }

Index: common.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/common.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- common.h	19 Dec 2004 06:36:13 -0000	1.8
+++ common.h	14 May 2005 20:32:08 -0000	1.9
@@ -19,7 +19,7 @@
 extern struct ioloop *ioloop;
 extern enum client_workarounds client_workarounds;
 extern int enable_last_command, no_flag_updates;
-extern const char *uidl_format;
+extern const char *uidl_format, *logout_format;
 extern enum uidl_keys uidl_keymask;
 
 extern void (*hook_mail_storage_created)(struct mail_storage **storage);

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/main.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- main.c	11 Apr 2005 19:17:19 -0000	1.24
+++ main.c	14 May 2005 20:32:08 -0000	1.25
@@ -41,7 +41,7 @@
 enum client_workarounds client_workarounds = 0;
 int enable_last_command = FALSE;
 int no_flag_updates = FALSE;
-const char *uidl_format;
+const char *uidl_format, *logout_format;
 enum uidl_keys uidl_keymask;
 
 static void sig_quit(int signo __attr_unused__)
@@ -178,6 +178,9 @@
 	uidl_format = getenv("POP3_UIDL_FORMAT");
 	if (uidl_format == NULL)
 		uidl_format = "%v.%u";
+	logout_format = getenv("POP3_LOGOUT_FORMAT");
+	if (logout_format == NULL)
+		logout_format = "top=%t/%T, retr=%r/%R, del=%d/%m, size=%s";
 	uidl_keymask = parse_uidl_keymask(uidl_format);
 
 	flags = 0;



More information about the dovecot-cvs mailing list