summaryrefslogtreecommitdiffstats
path: root/client-msg.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:50:49 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:50:49 +0000
commit5ef6d077c67b80fdb5e2153172f6d1ec1302050f (patch)
treee43cda0a503957b18d769c25c0c9191faa893b99 /client-msg.c
parent8d019841828d30beee5c78500b07f0c80e69457e (diff)
Join oldest session if non specified. Fix errors.
Diffstat (limited to 'client-msg.c')
-rw-r--r--client-msg.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/client-msg.c b/client-msg.c
index 29b8c7b3..ec0c6c8e 100644
--- a/client-msg.c
+++ b/client-msg.c
@@ -1,4 +1,4 @@
-/* $Id: client-msg.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
+/* $Id: client-msg.c,v 1.3 2007-09-26 18:50:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,24 +24,26 @@
#include "tmux.h"
-int client_msg_fn_output(struct hdr *, struct client_ctx *, const char **);
-int client_msg_fn_pause(struct hdr *, struct client_ctx *, const char **);
-int client_msg_fn_exit(struct hdr *, struct client_ctx *, const char **);
+int client_msg_fn_output(struct hdr *, struct client_ctx *, char **);
+int client_msg_fn_pause(struct hdr *, struct client_ctx *, char **);
+int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **);
+int client_msg_fn_error(struct hdr *, struct client_ctx *, char **);
struct client_msg {
enum hdrtype type;
- int (*fn)(struct hdr *, struct client_ctx *, const char **);
+ int (*fn)(struct hdr *, struct client_ctx *, char **);
};
struct client_msg client_msg_table[] = {
{ MSG_OUTPUT, client_msg_fn_output },
{ MSG_PAUSE, client_msg_fn_pause },
{ MSG_EXIT, client_msg_fn_exit },
+ { MSG_ERROR, client_msg_fn_error },
};
#define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0])
int
-client_msg_dispatch(struct client_ctx *cctx, const char **error)
+client_msg_dispatch(struct client_ctx *cctx, char **error)
{
struct hdr hdr;
struct client_msg *msg;
@@ -72,7 +74,7 @@ client_msg_dispatch(struct client_ctx *cctx, const char **error)
/* Output message from server. */
int
client_msg_fn_output(
- struct hdr *hdr, struct client_ctx *cctx, unused const char **error)
+ struct hdr *hdr, struct client_ctx *cctx, unused char **error)
{
local_output(cctx->srv_in, hdr->size);
return (0);
@@ -81,7 +83,7 @@ client_msg_fn_output(
/* Pause message from server. */
int
client_msg_fn_pause(
- struct hdr *hdr, unused struct client_ctx *cctx, unused const char **error)
+ struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
{
if (hdr->size != 0)
fatalx("bad MSG_PAUSE size");
@@ -91,9 +93,23 @@ client_msg_fn_pause(
/* Exit message from server. */
int
client_msg_fn_exit(
- struct hdr *hdr, unused struct client_ctx *cctx, unused const char **error)
+ struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
{
if (hdr->size != 0)
fatalx("bad MSG_EXIT size");
return (-1);
}
+
+/* Error message from server. */
+int
+client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
+{
+ if (hdr->size > SIZE_MAX - 1)
+ fatalx("bad MSG_ERROR size");
+
+ *error = xmalloc(hdr->size + 1);
+ buffer_read(cctx->srv_in, *error, hdr->size);
+ (*error)[hdr->size] = '\0';
+
+ return (-1);
+}