aboutsummaryrefslogtreecommitdiffhomepage
path: root/input
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2014-09-09 22:11:45 +0200
committerGravatar wm4 <wm4@nowhere>2014-09-10 00:48:12 +0200
commit256fea7655435ed5d94c4c8899fd191c40cfcee3 (patch)
tree105b19d0759a0a70628dfbfc0be00a424d92404f /input
parent49a0b61880692a07da1c6a370e6cc2eb39373d28 (diff)
input: make some fields internal
Diffstat (limited to 'input')
-rw-r--r--input/input.c28
-rw-r--r--input/input.h4
2 files changed, 19 insertions, 13 deletions
diff --git a/input/input.c b/input/input.c
index 31ce41ff57..431b76bb95 100644
--- a/input/input.c
+++ b/input/input.c
@@ -1688,6 +1688,12 @@ void mp_input_run_cmd(struct input_ctx *ictx, int def_flags, const char **cmd,
mp_input_queue_cmd(ictx, cmdt);
}
+struct mp_input_src_internal {
+ char *cmd_buffer;
+ size_t cmd_buffer_size;
+ bool drop;
+};
+
struct mp_input_src *mp_input_add_src(struct input_ctx *ictx)
{
input_lock(ictx);
@@ -1703,6 +1709,7 @@ struct mp_input_src *mp_input_add_src(struct input_ctx *ictx)
.global = ictx->global,
.log = mp_log_new(src, ictx->log, name),
.input_ctx = ictx,
+ .in = talloc_zero(src, struct mp_input_src_internal),
};
ictx->sources[ictx->num_sources++] = src;
@@ -1748,30 +1755,31 @@ void mp_input_src_kill(struct mp_input_src *src)
void mp_input_src_feed_cmd_text(struct mp_input_src *src, char *buf, size_t len)
{
- if (!src->cmd_buffer)
- src->cmd_buffer = talloc_size(src, CMD_BUFFER);
+ struct mp_input_src_internal *in = src->in;
+ if (!in->cmd_buffer)
+ in->cmd_buffer = talloc_size(in, CMD_BUFFER);
while (len) {
char *next = memchr(buf, '\n', len);
bool term = !!next;
next = next ? next + 1 : buf + len;
size_t copy = next - buf;
- bool overflow = copy > CMD_BUFFER - src->cmd_buffer_size;
- if (overflow || src->drop) {
- src->cmd_buffer_size = 0;
- src->drop = overflow || !term;
+ bool overflow = copy > CMD_BUFFER - in->cmd_buffer_size;
+ if (overflow || in->drop) {
+ in->cmd_buffer_size = 0;
+ in->drop = overflow || !term;
MP_WARN(src, "Dropping overlong line.\n");
} else {
- memcpy(src->cmd_buffer + src->cmd_buffer_size, buf, copy);
- src->cmd_buffer_size += copy;
+ memcpy(in->cmd_buffer + in->cmd_buffer_size, buf, copy);
+ in->cmd_buffer_size += copy;
buf += copy;
len -= copy;
if (term) {
- bstr s = {src->cmd_buffer, src->cmd_buffer_size};
+ bstr s = {in->cmd_buffer, in->cmd_buffer_size};
s = bstr_strip(s);
struct mp_cmd *cmd= mp_input_parse_cmd_(src->log, s, "<>");
if (cmd)
mp_input_queue_cmd(src->input_ctx, cmd);
- src->cmd_buffer_size = 0;
+ in->cmd_buffer_size = 0;
}
}
}
diff --git a/input/input.h b/input/input.h
index 1bd1410f66..10ad5d3621 100644
--- a/input/input.h
+++ b/input/input.h
@@ -99,9 +99,7 @@ struct mp_input_src {
struct mp_log *log;
struct input_ctx *input_ctx;
- char *cmd_buffer;
- size_t cmd_buffer_size;
- bool drop;
+ struct mp_input_src_internal *in;
// If not-NULL: called before destroying the input_src. Should close the
// underlying device, and free all memory.