anvil-connection.c revision c6260b961ca7b469a75ab842eeb53d3f904090e3
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi/* Copyright (C) 2009 Dovecot authors, see the included COPYING file */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi unsigned char *fifo_inbuf;
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistatic const char *
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomianvil_connection_fifo_read_line(struct anvil_connection *conn)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi ret = read(conn->fd, conn->fifo_inbuf, conn->fifo_inbuf_size);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (ret == 0) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi /* disconnected */
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomistatic const char *const *
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomianvil_connection_next_line(struct anvil_connection *conn)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi const char *line;
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi return line == NULL ? NULL : t_strsplit(line, "\t");
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomianvil_connection_request(struct anvil_connection *conn,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi unsigned int count;
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi connect_limit_connect(connect_limit, pid, args[1]);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi connect_limit_disconnect(connect_limit, pid, args[1]);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi *error_r = "KILL sent by a non-master connection";
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi count = connect_limit_lookup(connect_limit, args[0]);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi *error_r = t_strconcat("Unknown command: ", cmd, NULL);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi "much data");
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if ((args = anvil_connection_next_line(conn)) == NULL)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi atoi(args[2]) != ANVIL_CLIENT_PROTOCOL_MAJOR_VERSION) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi i_error("Anvil client not compatible with this server "
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi "(mixed old and new binaries?)");
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi while ((args = anvil_connection_next_line(conn)) != NULL) {
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi if (anvil_connection_request(conn, args, &error) < 0)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomianvil_connection_create(int fd, bool master, bool fifo)
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi conn->fifo_inbuf = i_malloc(conn->fifo_inbuf_size);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi conn->io = io_add(fd, IO_READ, anvil_connection_input, conn);
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomivoid anvil_connection_destroy(struct anvil_connection *conn)