bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainenstatic void client_input(struct client *client);
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainenclient_cmd_input(enum ipc_cmd_status status, const char *line, void *context)
eef20a55e19a239244b14963d716cf0d070fe1bbTimo Sirainen if (status != IPC_CMD_STATUS_REPLY && client->io == NULL) {
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen client->io = io_add(client->fd, IO_READ, client_input, client);
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainenstatic void client_input(struct client *client)
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen while ((line = i_stream_read_next_line(client->input)) != NULL) {
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen /* <ipc name> *|<id> <command> */
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(client->output, "-Invalid input\n");
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen /* send to everyone */
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen client_cmd_input(IPC_CMD_STATUS_OK, "", client);
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen t_strdup_printf("-Invalid IPC connection id: %s\n", id));
eef20a55e19a239244b14963d716cf0d070fe1bbTimo Sirainen t_strdup_printf("-Unknown IPC group: %s\n", line));
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen } else if ((conn = ipc_connection_lookup_id(group, id_num)) == NULL) {
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen t_strdup_printf("-Unknown IPC connection id: %u\n", id_num));
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen ipc_connection_cmd(conn, data, client_cmd_input, client);
eef20a55e19a239244b14963d716cf0d070fe1bbTimo Sirainen /* we'll handle commands one at a time. stop reading
eef20a55e19a239244b14963d716cf0d070fe1bbTimo Sirainen input until this command is finished. */
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen if (client->input->eof || client->input->stream_errno != 0)
83942ac160cdfb922c3a2f29ddfae2a13ebf8b5dTimo Sirainen client->io = io_add(fd, IO_READ, client_input, client);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi client->input = i_stream_create_fd(fd, (size_t)-1);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi client->output = o_stream_create_fd(fd, (size_t)-1);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_set_no_error_handling(client->output, TRUE);