client.c revision e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4
183bea41fa640dc8117f3eb45ff935cd81377a84Timo Sirainen/* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainenstatic void client_input(struct client *client);
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainenclient_cmd_input(enum ipc_cmd_status status, const char *line, void *context)
9f10cc61ec303351b43e54155c86699ef53cb8beTimo Sirainen if (status != IPC_CMD_STATUS_REPLY && client->io == NULL) {
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen client->io = io_add(client->fd, IO_READ, client_input, client);
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainenstatic void client_input(struct client *client)
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainen unsigned int id_num;
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainen while ((line = i_stream_read_next_line(client->input)) != NULL) {
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainen /* <ipc name> *|<id> <command> */
64bfe7b4a42512971db154937905dfa2bdb9cf2cTimo Sirainen o_stream_nsend_str(client->output, "-Invalid input\n");
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde /* send to everyone */
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde client_cmd_input(IPC_CMD_STATUS_OK, "", client);
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainen t_strdup_printf("-Invalid IPC connection id: %s\n", id));
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde t_strdup_printf("-Unknown IPC group: %s\n", line));
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde } else if ((conn = ipc_connection_lookup_id(group, id_num)) == NULL) {
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde t_strdup_printf("-Unknown IPC connection id: %u\n", id_num));
1c6dd898551d7d4d61970b24a8372438f6b72f97Timo Sirainen ipc_connection_cmd(conn, data, client_cmd_input, client);
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde /* we'll handle commands one at a time. stop reading
64bfe7b4a42512971db154937905dfa2bdb9cf2cTimo Sirainen input until this command is finished. */
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainen if (client->input->eof || client->input->stream_errno != 0)
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainen client->io = io_add(fd, IO_READ, client_input, client);
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainen client->input = i_stream_create_fd(fd, (size_t)-1, FALSE);
4b1359bde7d32667197548652a4b4f540062e2acTimo Sirainen client->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainen o_stream_set_no_error_handling(client->output, TRUE);