summaryrefslogtreecommitdiffstats
path: root/server-client.c
diff options
context:
space:
mode:
authornicm <nicm>2021-02-11 08:28:45 +0000
committernicm <nicm>2021-02-11 08:28:45 +0000
commite40831a0023705885643284b574913e08a59f496 (patch)
treea6246caa2fc119157c346f6cad19d4861633b264 /server-client.c
parent32186950f5ae3e3517f39b2723cc247a9da93d8c (diff)
Move file handling protocol stuff all into file.c so it can be reused
more easily.
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c77
1 files changed, 3 insertions, 74 deletions
diff --git a/server-client.c b/server-client.c
index 52df8110..7d9cc0e6 100644
--- a/server-client.c
+++ b/server-client.c
@@ -51,12 +51,6 @@ static void server_client_dispatch(struct imsg *, void *);
static void server_client_dispatch_command(struct client *, struct imsg *);
static void server_client_dispatch_identify(struct client *, struct imsg *);
static void server_client_dispatch_shell(struct client *);
-static void server_client_dispatch_write_ready(struct client *,
- struct imsg *);
-static void server_client_dispatch_read_data(struct client *,
- struct imsg *);
-static void server_client_dispatch_read_done(struct client *,
- struct imsg *);
/* Compare client windows. */
static int
@@ -2070,13 +2064,13 @@ server_client_dispatch(struct imsg *imsg, void *arg)
server_client_dispatch_shell(c);
break;
case MSG_WRITE_READY:
- server_client_dispatch_write_ready(c, imsg);
+ file_write_ready(&c->files, imsg);
break;
case MSG_READ:
- server_client_dispatch_read_data(c, imsg);
+ file_read_data(&c->files, imsg);
break;
case MSG_READ_DONE:
- server_client_dispatch_read_done(c, imsg);
+ file_read_done(&c->files, imsg);
break;
}
}
@@ -2302,71 +2296,6 @@ server_client_dispatch_shell(struct client *c)
proc_kill_peer(c->peer);
}
-/* Handle write ready message. */
-static void
-server_client_dispatch_write_ready(struct client *c, struct imsg *imsg)
-{
- struct msg_write_ready *msg = imsg->data;
- size_t msglen = imsg->hdr.len - IMSG_HEADER_SIZE;
- struct client_file find, *cf;
-
- if (msglen != sizeof *msg)
- fatalx("bad MSG_WRITE_READY size");
- find.stream = msg->stream;
- if ((cf = RB_FIND(client_files, &c->files, &find)) == NULL)
- return;
- if (msg->error != 0) {
- cf->error = msg->error;
- file_fire_done(cf);
- } else
- file_push(cf);
-}
-
-/* Handle read data message. */
-static void
-server_client_dispatch_read_data(struct client *c, struct imsg *imsg)
-{
- struct msg_read_data *msg = imsg->data;
- size_t msglen = imsg->hdr.len - IMSG_HEADER_SIZE;
- struct client_file find, *cf;
- void *bdata = msg + 1;
- size_t bsize = msglen - sizeof *msg;
-
- if (msglen < sizeof *msg)
- fatalx("bad MSG_READ_DATA size");
- find.stream = msg->stream;
- if ((cf = RB_FIND(client_files, &c->files, &find)) == NULL)
- return;
-
- log_debug("%s: file %d read %zu bytes", c->name, cf->stream, bsize);
- if (cf->error == 0) {
- if (evbuffer_add(cf->buffer, bdata, bsize) != 0) {
- cf->error = ENOMEM;
- file_fire_done(cf);
- } else
- file_fire_read(cf);
- }
-}
-
-/* Handle read done message. */
-static void
-server_client_dispatch_read_done(struct client *c, struct imsg *imsg)
-{
- struct msg_read_done *msg = imsg->data;
- size_t msglen = imsg->hdr.len - IMSG_HEADER_SIZE;
- struct client_file find, *cf;
-
- if (msglen != sizeof *msg)
- fatalx("bad MSG_READ_DONE size");
- find.stream = msg->stream;
- if ((cf = RB_FIND(client_files, &c->files, &find)) == NULL)
- return;
-
- log_debug("%s: file %d read done", c->name, cf->stream);
- cf->error = msg->error;
- file_fire_done(cf);
-}
-
/* Get client working directory. */
const char *
server_client_get_cwd(struct client *c, struct session *s)