]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-auth-server: Fix cmd_list output to use JSON
authorAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 19 Sep 2018 09:34:57 +0000 (12:34 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Nov 2018 12:00:11 +0000 (14:00 +0200)
Fixes output for HTTP client

src/doveadm/doveadm-auth-server.c

index e874ea8ad010b5ceca967696f607010696da2880..fa7acb9aa32dcdb8ec02a2cebab15c966141cb7d 100644 (file)
@@ -168,24 +168,39 @@ cmd_user_list(struct auth_master_connection *conn,
 {
        struct auth_master_user_list_ctx *ctx;
        const char *username, *user_mask = "*";
+       string_t *escaped = t_str_new(256);
+       bool first = TRUE;
        unsigned int i;
 
        if (users[0] != NULL && users[1] == NULL)
                user_mask = users[0];
 
+       o_stream_nsend_str(doveadm_print_ostream, "{\"userList\":[");
+
        ctx = auth_master_user_list_init(conn, user_mask, &input->info);
        while ((username = auth_master_user_list_next(ctx)) != NULL) {
                for (i = 0; users[i] != NULL; i++) {
                        if (wildcard_match_icase(username, users[i]))
                                break;
                }
-               if (users[i] != NULL)
-                       printf("%s\n", username);
+               if (users[i] != NULL) {
+                       if (first)
+                               first = FALSE;
+                       else
+                               o_stream_nsend_str(doveadm_print_ostream, ",");
+                       str_truncate(escaped, 0);
+                       str_append_c(escaped, '"');
+                       json_append_escaped(escaped, username);
+                       str_append_c(escaped, '"');
+                       o_stream_nsend(doveadm_print_ostream, escaped->data, escaped->used);
+               }
        }
        if (auth_master_user_list_deinit(&ctx) < 0) {
                i_error("user listing failed");
                doveadm_exit_code = EX_DATAERR;
        }
+
+       o_stream_nsend_str(doveadm_print_ostream, "]}");
 }
 
 static void cmd_auth_cache_flush(int argc, char *argv[])