bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenstatic void notify_connection_destroy(struct notify_connection *conn);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenstatic void notify_sync_callback(bool success, void *context)
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen struct notify_sync_request *request = context;
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(request->conn->output, t_strdup_printf(
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen "%c\t%u\n", success ? '+' : '-', request->id));
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainennotify_connection_input_line(struct notify_connection *conn, const char *line)
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen /* U \t <username> \t <priority> [\t <sync id>] */
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("notify client sent invalid input: %s", line);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("notify client sent unknown command: %s", args[0]);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen if (replication_priority_parse(args[2], &priority) < 0) {
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("notify client sent invalid priority: %s", args[2]);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (void)replicator_queue_add(conn->queue, args[1], priority);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen else if (args[3] == NULL || str_to_uint(args[3], &id) < 0) {
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("notify client sent invalid sync id: %s", line);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen request = i_new(struct notify_sync_request, 1);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen replicator_queue_add_sync(conn->queue, args[1],
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenstatic void notify_connection_input(struct notify_connection *conn)
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("BUG: Client connection sent too much data");
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen if ((line = i_stream_next_line(conn->input)) == NULL)
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen if (!version_string_verify(line, "replicator-notify",
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("Notify client not compatible with this server "
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen "(mixed old and new binaries?)");
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen while ((line = i_stream_next_line(conn->input)) != NULL) {
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen ret = notify_connection_input_line(conn, line);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainennotify_connection_create(int fd, struct replicator_queue *queue)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->output = o_stream_create_fd(fd, (size_t)-1);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_set_no_error_handling(conn->output, TRUE);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen conn->io = io_add(fd, IO_READ, notify_connection_input, conn);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenstatic void notify_connection_destroy(struct notify_connection *conn)
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen i_error("close(notify connection) failed: %m");
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen master_service_client_connection_destroyed(master_service);
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenvoid notify_connection_ref(struct notify_connection *conn)