int ret;
ctx->conn = conn;
+ o_stream_cork(conn->output);
if (ctx->v.preinit != NULL)
ctx->v.preinit(ctx);
} else {
o_stream_nsend(conn->output, "\n+\n", 3);
}
+ o_stream_uncork(conn->output);
pool_unref(&ctx->pool);
}
}
}
client_connection_send_auth_handshake(conn, listen_fd);
+
+ doveadm_print_ostream = conn->output;
return conn;
}
i_error("close(client) failed: %m");
pool_unref(&conn->pool);
+ doveadm_print_ostream = NULL;
doveadm_client = NULL;
master_service_client_connection_destroyed(master_service);
}
-
-struct ostream *client_connection_get_output(struct client_connection *conn)
-{
- return conn->output;
-}
client_connection_create(int fd, int listen_fd, bool ssl);
void client_connection_destroy(struct client_connection **conn);
-struct ostream *client_connection_get_output(struct client_connection *conn);
-
#endif
#include "lib.h"
#include "array.h"
+#include "ostream.h"
#include "doveadm-print-private.h"
-#include <stdio.h>
-
struct doveadm_print_flow_header {
const char *title;
enum doveadm_print_header_flags flags;
static void flow_next_hdr(void)
{
if (++ctx->header_idx < array_count(&ctx->headers))
- printf(" ");
+ o_stream_nsend(doveadm_print_ostream, " ", 1);
else {
ctx->header_idx = 0;
- printf("\n");
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
+ }
+}
+
+static void doveadm_print_flow_print_heder(const struct doveadm_print_flow_header *hdr)
+{
+ if ((hdr->flags & DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE) == 0) {
+ o_stream_nsend_str(doveadm_print_ostream, hdr->title);
+ o_stream_nsend(doveadm_print_ostream, "=", 1);
}
}
const struct doveadm_print_flow_header *hdr =
array_idx(&ctx->headers, ctx->header_idx);
- if ((hdr->flags & DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE) == 0)
- printf("%s=", hdr->title);
- printf("%s", value);
+ doveadm_print_flow_print_heder(hdr);
+ o_stream_nsend_str(doveadm_print_ostream, value);
flow_next_hdr();
}
if (!ctx->streaming) {
ctx->streaming = TRUE;
- if ((hdr->flags & DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE) == 0)
- printf("%s=", hdr->title);
+ doveadm_print_flow_print_heder(hdr);
}
- fwrite(value, 1, size, stdout);
+ o_stream_nsend(doveadm_print_ostream, value, size);
if (size == 0) {
flow_next_hdr();
ctx->streaming = FALSE;
static void doveadm_print_flow_flush(void)
{
if (ctx->header_idx != 0) {
- printf("\n");
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
ctx->header_idx = 0;
}
}
#include "lib.h"
#include "array.h"
+#include "ostream.h"
#include "doveadm-print-private.h"
-#include <stdio.h>
-
struct doveadm_print_pager_header {
const char *title;
};
{
if (++ctx->header_idx == array_count(&ctx->headers)) {
ctx->header_idx = 0;
- printf("\f\n");
+ o_stream_nsend(doveadm_print_ostream, "\f\n", 2);
}
}
const struct doveadm_print_pager_header *hdr =
array_idx(&ctx->headers, ctx->header_idx);
- printf("%s: %s\n", hdr->title, value);
+ o_stream_nsend_str(doveadm_print_ostream, hdr->title);
+ o_stream_nsend(doveadm_print_ostream, ": ", 2);
+ o_stream_nsend_str(doveadm_print_ostream, value);
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
pager_next_hdr();
}
if (!ctx->streaming) {
ctx->streaming = TRUE;
- printf("%s:\n", hdr->title);
+ o_stream_nsend_str(doveadm_print_ostream, hdr->title);
+ o_stream_nsend(doveadm_print_ostream, ":\n", 2);
}
- fwrite(value, 1, size, stdout);
+ o_stream_nsend(doveadm_print_ostream, value, size);
if (size == 0) {
pager_next_hdr();
ctx->streaming = FALSE;
static void doveadm_print_pager_flush(void)
{
if (ctx->header_idx != 0) {
- printf("\n");
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
ctx->header_idx = 0;
}
}
#include "strescape.h"
#include "ostream.h"
#include "client-connection.h"
-#include "doveadm-server.h"
#include "doveadm-print-private.h"
struct doveadm_print_server_context {
static void doveadm_print_server_flush(void)
{
- if (doveadm_client == NULL)
- return;
-
- o_stream_nsend(client_connection_get_output(doveadm_client),
+ o_stream_nsend(doveadm_print_ostream,
str_data(ctx.str), str_len(ctx.str));
str_truncate(ctx.str, 0);
}
#include "lib.h"
#include "array.h"
+#include "ostream.h"
#include "doveadm-print-private.h"
-#include <stdio.h>
-
struct doveadm_print_tab_context {
unsigned int header_idx, header_count;
{
if (!ctx.header_written) {
if (!doveadm_print_hide_titles)
- printf("\n");
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
ctx.header_written = TRUE;
}
}
ctx.header_count++;
if (!doveadm_print_hide_titles) {
if (ctx.header_count > 1)
- printf("\t");
- printf("%s", hdr->title);
+ o_stream_nsend(doveadm_print_ostream, "\t", 1);
+ o_stream_nsend_str(doveadm_print_ostream, hdr->title);
}
}
{
doveadm_print_tab_flush_header();
if (ctx.header_idx > 0)
- printf("\t");
- printf("%s", value);
+ o_stream_nsend(doveadm_print_ostream, "\t", 1);
+ o_stream_nsend_str(doveadm_print_ostream, value);
if (++ctx.header_idx == ctx.header_count) {
ctx.header_idx = 0;
- printf("\n");
+ o_stream_nsend(doveadm_print_ostream, "\n", 1);
}
}
}
doveadm_print_tab_flush_header();
if (ctx.header_idx > 0)
- printf("\t");
- fwrite(value, 1, size, stdout);
+ o_stream_nsend(doveadm_print_ostream, "\t", 1);
+ o_stream_nsend(doveadm_print_ostream, value, size);
}
static void doveadm_print_tab_flush(void)
#include "lib.h"
#include "array.h"
#include "istream.h"
+#include "ostream.h"
#include "doveadm-print-private.h"
-#include <stdio.h>
-
struct doveadm_print_header_context {
const char *key;
char *sticky_value;
};
bool doveadm_print_hide_titles = FALSE;
+struct ostream *doveadm_print_ostream = NULL;
static struct doveadm_print_context *ctx;
{
if (ctx != NULL && ctx->v->flush != NULL)
ctx->v->flush();
- fflush(stdout);
+ o_stream_uncork(doveadm_print_ostream);
+ o_stream_cork(doveadm_print_ostream);
}
void doveadm_print_unstick_headers(void)
if (ctx == NULL)
return;
- if (ctx->v->flush != NULL)
+ if (ctx->v->flush != NULL && doveadm_print_ostream != NULL) {
ctx->v->flush();
+ o_stream_uncork(doveadm_print_ostream);
+ }
if (ctx->v->deinit != NULL)
ctx->v->deinit();
array_foreach_modifiable(&ctx->headers, hdr)
#define DOVEADM_PRINT_TYPE_TAB "tab"
#define DOVEADM_PRINT_TYPE_FLOW "flow"
#define DOVEADM_PRINT_TYPE_TABLE "table"
+#define DOVEADM_PRINT_TYPE_SERVER "server"
enum doveadm_print_header_flags {
DOVEADM_PRINT_HEADER_FLAG_RIGHT_JUSTIFY = 0x01,
extern const struct doveadm_print_vfuncs *doveadm_print_vfuncs_all[];
extern bool doveadm_print_hide_titles;
+/* points to either stdout or to doveadm-server's TCP connection */
+extern struct ostream *doveadm_print_ostream;
bool doveadm_print_is_initialized(void);
#ifndef DOVEADM_SERVER_H
#define DOVEADM_SERVER_H
-#define DOVEADM_PRINT_TYPE_SERVER "server"
-
extern struct client_connection *doveadm_client;
extern struct doveadm_print_vfuncs doveadm_print_server_vfuncs;
#include "lib.h"
#include "array.h"
#include "str.h"
+#include "ostream.h"
#include "env-util.h"
#include "execv-const.h"
#include "dict.h"
quick_init = TRUE;
} else {
quick_init = FALSE;
+ doveadm_print_ostream = o_stream_create_fd(STDOUT_FILENO, 0, FALSE);
+ o_stream_set_no_error_handling(doveadm_print_ostream, TRUE);
doveadm_dump_init();
doveadm_mail_init();
dict_drivers_register_builtin();
doveadm_unload_modules();
dict_drivers_unregister_builtin();
doveadm_print_deinit();
+ o_stream_unref(&doveadm_print_ostream);
}
doveadm_cmds_deinit();
master_service_deinit(&master_service);