dovecot-2.2: Added "doveadm replicator remove" command to remove...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Apr 7 18:02:06 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/872b06768835
changeset: 16225:872b06768835
user: Timo Sirainen <tss at iki.fi>
date: Sun Apr 07 18:01:52 2013 +0300
description:
Added "doveadm replicator remove" command to remove users from replicator queue.
diffstat:
src/doveadm/doveadm-replicator.c | 30 +++++++++++++++++++++++++
src/replication/replicator/doveadm-connection.c | 22 ++++++++++++++++++
src/replication/replicator/replicator-queue.c | 8 +++++-
src/replication/replicator/replicator-queue.h | 3 ++
4 files changed, 62 insertions(+), 1 deletions(-)
diffs (121 lines):
diff -r 8b13ef2e9569 -r 872b06768835 src/doveadm/doveadm-replicator.c
--- a/src/doveadm/doveadm-replicator.c Sun Apr 07 17:47:16 2013 +0300
+++ b/src/doveadm/doveadm-replicator.c Sun Apr 07 18:01:52 2013 +0300
@@ -215,11 +215,41 @@
replicator_disconnect(ctx);
}
+static void cmd_replicator_remove(int argc, char *argv[])
+{
+ struct replicator_context *ctx;
+ string_t *str;
+ const char *line;
+
+ if (argv[1] == NULL)
+ replicator_cmd_help(cmd_replicator_remove);
+
+ ctx = cmd_replicator_init(argc, argv, "a:", cmd_replicator_remove);
+
+ str = t_str_new(128);
+ str_append(str, "REMOVE\t");
+ str_append_tabescaped(str, argv[1]);
+ str_append_c(str, '\n');
+ replicator_send(ctx, str_c(str));
+
+ line = i_stream_read_next_line(ctx->input);
+ if (line == NULL) {
+ i_error("Replicator disconnected unexpectedly");
+ doveadm_exit_code = EX_TEMPFAIL;
+ } else if (line[0] != '+') {
+ i_error("Replicator failed: %s", line+1);
+ doveadm_exit_code = EX_USAGE;
+ }
+ replicator_disconnect(ctx);
+}
+
struct doveadm_cmd doveadm_cmd_replicator[] = {
{ cmd_replicator_status, "replicator status",
"[-a <replicator socket path>] [<user mask>]" },
{ cmd_replicator_replicate, "replicator replicate",
"[-a <replicator socket path>] [-p <priority>] <user mask>" },
+ { cmd_replicator_remove, "replicator remove",
+ "[-a <replicator socket path>] <username>" },
};
static void replicator_cmd_help(doveadm_command_t *cmd)
diff -r 8b13ef2e9569 -r 872b06768835 src/replication/replicator/doveadm-connection.c
--- a/src/replication/replicator/doveadm-connection.c Sun Apr 07 17:47:16 2013 +0300
+++ b/src/replication/replicator/doveadm-connection.c Sun Apr 07 18:01:52 2013 +0300
@@ -138,6 +138,26 @@
}
static int
+client_input_remove(struct doveadm_connection *client, const char *const *args)
+{
+ struct replicator_user *user;
+
+ /* <username> */
+ if (str_array_length(args) != 1) {
+ i_error("%s: REMOVE: Invalid parameters", client->conn.name);
+ return -1;
+ }
+ user = replicator_queue_lookup(client->queue, args[0]);
+ if (user == NULL)
+ o_stream_send_str(client->conn.output, "-User not found\n");
+ else {
+ replicator_queue_remove(client->queue, &user);
+ o_stream_send_str(client->conn.output, "+\n");
+ }
+ return 0;
+}
+
+static int
client_input_notify(struct doveadm_connection *client, const char *const *args)
{
struct replicator_user *user;
@@ -178,6 +198,8 @@
return client_input_status(client, args);
else if (strcmp(cmd, "REPLICATE") == 0)
return client_input_replicate(client, args);
+ else if (strcmp(cmd, "REMOVE") == 0)
+ return client_input_remove(client, args);
else if (strcmp(cmd, "NOTIFY") == 0)
return client_input_notify(client, args);
i_error("%s: Unknown command: %s", conn->name, cmd);
diff -r 8b13ef2e9569 -r 872b06768835 src/replication/replicator/replicator-queue.c
--- a/src/replication/replicator/replicator-queue.c Sun Apr 07 17:47:16 2013 +0300
+++ b/src/replication/replicator/replicator-queue.c Sun Apr 07 18:01:52 2013 +0300
@@ -120,13 +120,19 @@
queue->change_context = context;
}
+struct replicator_user *
+replicator_queue_lookup(struct replicator_queue *queue, const char *username)
+{
+ return hash_table_lookup(queue->user_hash, username);
+}
+
static struct replicator_user *
replicator_queue_add_int(struct replicator_queue *queue, const char *username,
enum replication_priority priority)
{
struct replicator_user *user;
- user = hash_table_lookup(queue->user_hash, username);
+ user = replicator_queue_lookup(queue, username);
if (user == NULL) {
user = i_new(struct replicator_user, 1);
user->username = i_strdup(username);
diff -r 8b13ef2e9569 -r 872b06768835 src/replication/replicator/replicator-queue.h
--- a/src/replication/replicator/replicator-queue.h Sun Apr 07 17:47:16 2013 +0300
+++ b/src/replication/replicator/replicator-queue.h Sun Apr 07 18:01:52 2013 +0300
@@ -35,6 +35,9 @@
void (*callback)(void *context),
void *context);
+/* Lookup an existing user */
+struct replicator_user *
+replicator_queue_lookup(struct replicator_queue *queue, const char *username);
/* Add a user to queue and return it. If the user already exists, it's updated
only if the new priority is higher. */
struct replicator_user *
More information about the dovecot-cvs
mailing list