version 1.3, 2009/07/21 18:52:03 |
version 1.4, 2009/07/23 20:24:27 |
|
|
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
int client_msg_fn_detach(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_detach(struct hdr *, struct client_ctx *); |
int client_msg_fn_error(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_error(struct hdr *, struct client_ctx *); |
int client_msg_fn_shutdown(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_shutdown(struct hdr *, struct client_ctx *); |
int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_exit(struct hdr *, struct client_ctx *); |
int client_msg_fn_exited(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_exited(struct hdr *, struct client_ctx *); |
int client_msg_fn_suspend(struct hdr *, struct client_ctx *, char **); |
int client_msg_fn_suspend(struct hdr *, struct client_ctx *); |
|
|
struct client_msg { |
struct client_msg { |
enum hdrtype type; |
enum hdrtype type; |
int (*fn)(struct hdr *, struct client_ctx *, char **); |
int (*fn)(struct hdr *, struct client_ctx *); |
}; |
}; |
struct client_msg client_msg_table[] = { |
struct client_msg client_msg_table[] = { |
{ MSG_DETACH, client_msg_fn_detach }, |
{ MSG_DETACH, client_msg_fn_detach }, |
|
|
}; |
}; |
|
|
int |
int |
client_msg_dispatch(struct client_ctx *cctx, char **error) |
client_msg_dispatch(struct client_ctx *cctx) |
{ |
{ |
struct hdr hdr; |
struct hdr hdr; |
struct client_msg *msg; |
struct client_msg *msg; |
|
|
|
|
for (i = 0; i < nitems(client_msg_table); i++) { |
for (i = 0; i < nitems(client_msg_table); i++) { |
msg = client_msg_table + i; |
msg = client_msg_table + i; |
if (msg->type == hdr.type) { |
if (msg->type == hdr.type) |
if (msg->fn(&hdr, cctx, error) != 0) |
return (msg->fn(&hdr, cctx)); |
return (-1); |
|
return (0); |
|
} |
|
} |
} |
fatalx("unexpected message"); |
fatalx("unexpected message"); |
} |
} |
|
|
int |
int |
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error) |
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx) |
{ |
{ |
|
char *errstr; |
|
|
if (hdr->size == SIZE_MAX) |
if (hdr->size == SIZE_MAX) |
fatalx("bad MSG_ERROR size"); |
fatalx("bad MSG_ERROR size"); |
|
|
*error = xmalloc(hdr->size + 1); |
errstr = xmalloc(hdr->size + 1); |
buffer_read(cctx->srv_in, *error, hdr->size); |
buffer_read(cctx->srv_in, errstr, hdr->size); |
(*error)[hdr->size] = '\0'; |
errstr[hdr->size] = '\0'; |
|
|
|
cctx->errstr = errstr; |
return (-1); |
return (-1); |
} |
} |
|
|
int |
int |
client_msg_fn_detach( |
client_msg_fn_detach(struct hdr *hdr, struct client_ctx *cctx) |
struct hdr *hdr, struct client_ctx *cctx, unused char **error) |
|
{ |
{ |
if (hdr->size != 0) |
if (hdr->size != 0) |
fatalx("bad MSG_DETACH size"); |
fatalx("bad MSG_DETACH size"); |
|
|
client_write_server(cctx, MSG_EXITING, NULL, 0); |
client_write_server(cctx, MSG_EXITING, NULL, 0); |
cctx->flags |= CCTX_DETACH; |
cctx->exittype = CCTX_DETACH; |
|
|
return (0); |
return (0); |
} |
} |
|
|
int |
int |
client_msg_fn_shutdown( |
client_msg_fn_shutdown( |
struct hdr *hdr, struct client_ctx *cctx, unused char **error) |
struct hdr *hdr, struct client_ctx *cctx) |
{ |
{ |
if (hdr->size != 0) |
if (hdr->size != 0) |
fatalx("bad MSG_SHUTDOWN size"); |
fatalx("bad MSG_SHUTDOWN size"); |
|
|
client_write_server(cctx, MSG_EXITING, NULL, 0); |
client_write_server(cctx, MSG_EXITING, NULL, 0); |
cctx->flags |= CCTX_SHUTDOWN; |
cctx->exittype = CCTX_SHUTDOWN; |
|
|
return (0); |
return (0); |
} |
} |
|
|
int |
int |
client_msg_fn_exit( |
client_msg_fn_exit(struct hdr *hdr, struct client_ctx *cctx) |
struct hdr *hdr, struct client_ctx *cctx, unused char **error) |
|
{ |
{ |
if (hdr->size != 0) |
if (hdr->size != 0) |
fatalx("bad MSG_EXIT size"); |
fatalx("bad MSG_EXIT size"); |
|
|
client_write_server(cctx, MSG_EXITING, NULL, 0); |
client_write_server(cctx, MSG_EXITING, NULL, 0); |
cctx->flags |= CCTX_EXIT; |
cctx->exittype = CCTX_EXIT; |
|
|
return (0); |
return (0); |
} |
} |
|
|
int |
int |
client_msg_fn_exited( |
client_msg_fn_exited(struct hdr *hdr, unused struct client_ctx *cctx) |
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error) |
|
{ |
{ |
if (hdr->size != 0) |
if (hdr->size != 0) |
fatalx("bad MSG_EXITED size"); |
fatalx("bad MSG_EXITED size"); |
|
|
} |
} |
|
|
int |
int |
client_msg_fn_suspend( |
client_msg_fn_suspend(struct hdr *hdr, unused struct client_ctx *cctx) |
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error) |
|
{ |
{ |
struct sigaction act; |
struct sigaction act; |
|
|