changeset 10151:508f5536a0a7 HEAD

doveadm who -1: Fixed filtering.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Oct 2009 21:18:09 -0400
parents 257bb6f74138
children 383da67215d9
files src/doveadm/doveadm-who.c
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-who.c	Thu Oct 22 21:15:37 2009 -0400
+++ b/src/doveadm/doveadm-who.c	Thu Oct 22 21:18:09 2009 -0400
@@ -156,8 +156,8 @@
 	i_stream_destroy(&input);
 }
 
-static bool who_filter_match(const struct who_user *user,
-			     const struct who_filter *filter)
+static bool who_user_filter_match(const struct who_user *user,
+				  const struct who_filter *filter)
 {
 	if (filter->username != NULL) {
 		if (strstr(user->username, filter->username) == NULL)
@@ -194,7 +194,7 @@
 		const pid_t *pid;
 		bool first = TRUE;
 
-		if (!who_filter_match(user, &ctx->filter))
+		if (!who_user_filter_match(user, &ctx->filter))
 			continue;
 
 		printf("%-30s %2u %-5s ", user->username,
@@ -222,11 +222,29 @@
 	hash_table_iterate_deinit(&iter);
 }
 
-static void who_print_line(struct who_context *ctx ATTR_UNUSED,
+static bool who_line_filter_match(const struct who_line *line,
+				  const struct who_filter *filter)
+{
+	if (filter->username != NULL) {
+		if (strstr(line->username, filter->username) == NULL)
+			return FALSE;
+	}
+	if (filter->net_bits > 0) {
+		if (!net_is_in_network(&line->ip, &filter->net_ip,
+				       filter->net_bits))
+			return FALSE;
+	}
+	return TRUE;
+}
+
+static void who_print_line(struct who_context *ctx,
 			   const struct who_line *line)
 {
 	unsigned int i;
 
+	if (!who_line_filter_match(line, &ctx->filter))
+		return;
+
 	for (i = 0; i < line->refcount; i++) T_BEGIN {
 		printf("%-30s %-15s %-5s %ld\n", line->username,
 		       net_ip2addr(&line->ip), line->service, (long)line->pid);