t_strdup_printf("%c%s\n", chr, line));
} T_END;
- if (status != IPC_CMD_STATUS_REPLY) {
- i_assert(client->io == NULL);
+ if (status != IPC_CMD_STATUS_REPLY && client->io == NULL) {
client->io = io_add(client->fd, IO_READ, client_input, client);
client_input(client);
}
struct ipc_connection *conn;
char *line, *id, *data;
unsigned int id_num;
+ bool ret;
while ((line = i_stream_read_next_line(client->input)) != NULL) {
/* <ipc name> *|<id> <command> */
*data++ = '\0';
group = ipc_group_lookup_name(line);
- if (group == NULL) {
- o_stream_send_str(client->output,
- t_strdup_printf("-Unknown IPC group: %s\n", line));
- continue;
- }
+ ret = FALSE;
if (strcmp(id, "*") == 0) {
/* send to everyone */
- ipc_group_cmd(group, data, client_cmd_input, client);
+ if (group == NULL) {
+ client_cmd_input(IPC_CMD_STATUS_OK,
+ NULL, client);
+ } else {
+ ret = ipc_group_cmd(group, data,
+ client_cmd_input, client);
+ }
} else if (str_to_uint(id, &id_num) < 0) {
o_stream_send_str(client->output,
t_strdup_printf("-Invalid IPC connection id: %s\n", id));
continue;
+ } else if (group == NULL) {
+ o_stream_send_str(client->output,
+ t_strdup_printf("-Unknown IPC group: %s\n", line));
} else if ((conn = ipc_connection_lookup_id(group, id_num)) == NULL) {
o_stream_send_str(client->output,
t_strdup_printf("-Unknown IPC connection id: %u\n", id_num));
continue;
} else {
ipc_connection_cmd(conn, data, client_cmd_input, client);
+ ret = TRUE;
}
- /* we'll handle commands one at a time. stop reading input
- until this command is finished. */
- io_remove(&client->io);
- break;
+ if (ret) {
+ /* we'll handle commands one at a time. stop reading
+ input until this command is finished. */
+ io_remove(&client->io);
+ break;
+ }
}
if (client->input->eof || client->input->stream_errno != 0)
client_destroy(&client);
}
-void ipc_group_cmd(struct ipc_group *group, const char *cmd,
+bool ipc_group_cmd(struct ipc_group *group, const char *cmd,
ipc_cmd_callback_t *callback, void *context)
{
struct ipc_connection *conn, *next;
if (group->connections == NULL) {
callback(IPC_CMD_STATUS_OK, NULL, context);
- return;
+ return FALSE;
}
group_cmd = i_new(struct ipc_group_cmd, 1);
ipc_connection_cmd(conn, cmd,
ipc_group_cmd_callback, group_cmd);
}
+ return TRUE;
}
void ipc_groups_init(void)
int ipc_group_update_name(struct ipc_group *group, const char *name);
/* Send a command to all connections in a group. All connections are expected
- to answer something. All replies are */
-void ipc_group_cmd(struct ipc_group *group, const char *cmd,
+ to answer something. If there are no connections, callback() is called
+ immediately and FALSE is returned. */
+bool ipc_group_cmd(struct ipc_group *group, const char *cmd,
ipc_cmd_callback_t *callback, void *context);
void ipc_groups_init(void);