simplify, fix garbage read
This commit is contained in:
parent
0270a9c565
commit
29f551626e
|
@ -266,16 +266,10 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
|||
/* A YAJL JSON generator used for formatting replies. */
|
||||
command_output.json_gen = gen;
|
||||
|
||||
// FIXME: Add results (as string, remove this json dependency)
|
||||
y(map_open);
|
||||
// BOOL + false -> failed
|
||||
// else success
|
||||
ystr("success");
|
||||
bool success = (scm_is_bool(status) == 0) || scm_is_true(status);
|
||||
y(bool, success);
|
||||
ystr("results");
|
||||
ystr(scm_is_string(status) ? scm_to_locale_string(status) : "#undefined");
|
||||
y(map_close);
|
||||
SCM _str = scm_simple_format (SCM_BOOL_F,
|
||||
scm_from_locale_string("{\"status\": ~S}\n"),
|
||||
scm_list_1(status));
|
||||
ystr(scm_to_locale_string(_str));
|
||||
command_output.needs_tree_render = false;
|
||||
|
||||
result->needs_tree_render = command_output.needs_tree_render;
|
||||
|
|
60
src/ipc.c
60
src/ipc.c
|
@ -112,11 +112,10 @@ static void ipc_push_pending(ipc_client *client) {
|
|||
* send the message if the client's buffer was empty.
|
||||
*
|
||||
*/
|
||||
static void ipc_send_client_message(ipc_client *client, size_t size, const uint32_t message_type, const uint8_t *payload) {
|
||||
static void ipc_send_client_message(ipc_client *client, size_t size, const uint8_t *payload) {
|
||||
const i3_ipc_header_t header = {
|
||||
.magic = {'i', '3', '-', 'i', 'p', 'c'},
|
||||
.size = size,
|
||||
.type = message_type};
|
||||
.size = size};
|
||||
const size_t header_size = sizeof(i3_ipc_header_t);
|
||||
const size_t message_size = header_size + size;
|
||||
|
||||
|
@ -166,7 +165,7 @@ void ipc_send_event(const char *event, uint32_t message_type, const char *payloa
|
|||
TAILQ_FOREACH (current, &all_clients, clients) {
|
||||
for (int i = 0; i < current->num_events; i++) {
|
||||
if (strcasecmp(current->events[i], event) == 0) {
|
||||
ipc_send_client_message(current, strlen(payload), message_type, (uint8_t *)payload);
|
||||
ipc_send_client_message(current, strlen(payload), (uint8_t *)payload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -242,8 +241,7 @@ IPC_HANDLER(run_command) {
|
|||
ylength length;
|
||||
yajl_gen_get_buf(gen, &reply, &length);
|
||||
|
||||
ipc_send_client_message(client, length, I3_IPC_REPLY_TYPE_COMMAND,
|
||||
(const uint8_t *)reply);
|
||||
ipc_send_client_message(client, length, (const uint8_t *)reply);
|
||||
|
||||
yajl_gen_free(gen);
|
||||
}
|
||||
|
@ -870,58 +868,12 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) {
|
|||
#undef YSTR_IF_SET
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for the YAJL parser (will be called when a string is parsed).
|
||||
*
|
||||
*/
|
||||
static int add_subscription(void *extra, const unsigned char *s,
|
||||
ylength len) {
|
||||
ipc_client *client = extra;
|
||||
|
||||
DLOG("should add subscription to extra %p, sub %.*s\n", client, (int)len, s);
|
||||
int event = client->num_events;
|
||||
|
||||
client->num_events++;
|
||||
client->events = srealloc(client->events, client->num_events * sizeof(char *));
|
||||
/* We copy the string because it is not null-terminated and strndup()
|
||||
* is missing on some BSD systems */
|
||||
client->events[event] = scalloc(len + 1, 1);
|
||||
memcpy(client->events[event], s, len);
|
||||
|
||||
DLOG("client is now subscribed to:\n");
|
||||
for (int i = 0; i < client->num_events; i++) {
|
||||
DLOG("event %s\n", client->events[i]);
|
||||
}
|
||||
DLOG("(done)\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct sync_state {
|
||||
char *last_key;
|
||||
uint32_t rnd;
|
||||
xcb_window_t window;
|
||||
};
|
||||
|
||||
static int _sync_json_key(void *extra, const unsigned char *val, size_t len) {
|
||||
struct sync_state *state = extra;
|
||||
FREE(state->last_key);
|
||||
state->last_key = scalloc(len + 1, 1);
|
||||
memcpy(state->last_key, val, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _sync_json_int(void *extra, long long val) {
|
||||
struct sync_state *state = extra;
|
||||
if (strcasecmp(state->last_key, "rnd") == 0) {
|
||||
state->rnd = val;
|
||||
} else if (strcasecmp(state->last_key, "window") == 0) {
|
||||
state->window = (xcb_window_t)val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler for activity on a client connection, receives a message from a
|
||||
* client.
|
||||
|
@ -1252,8 +1204,6 @@ void ipc_send_binding_event(const char *event_type, Binding *bind) {
|
|||
void ipc_confirm_restart(ipc_client *client) {
|
||||
DLOG("ipc_confirm_restart(fd %d)\n", client->fd);
|
||||
static const char *reply = "[{\"success\":true}]";
|
||||
ipc_send_client_message(
|
||||
client, strlen(reply), I3_IPC_REPLY_TYPE_COMMAND,
|
||||
(const uint8_t *)reply);
|
||||
ipc_send_client_message(client, strlen(reply), (const uint8_t *)reply);
|
||||
ipc_push_pending(client);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue