2 * rpcd - UBUS RPC server
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 #include <libubox/blobmsg.h>
33 #include <libubox/ustream.h>
35 /* limit of sys & proc files */
36 #define RPC_FILE_MIN_SIZE (128)
38 /* limit of regular files and command output data */
39 #define RPC_FILE_MAX_SIZE (4096 * 64)
40 #define RPC_FILE_MAX_RUNTIME (3 * 1000)
42 #define ustream_for_each_read_buffer(stream, ptr, len) \
43 for (ptr = ustream_get_read_buf(stream, &len); \
44 ptr != NULL && len > 0; \
45 ustream_consume(stream, len), ptr = ustream_get_read_buf(stream, &len))
47 #define ustream_declare(us, fd, name) \
48 us.stream.string_data = true; \
49 us.stream.r.buffer_len = 4096; \
50 us.stream.r.max_buffers = RPC_FILE_MAX_SIZE / 4096; \
51 us.stream.notify_read = rpc_file_##name##_read_cb; \
52 us.stream.notify_state = rpc_file_##name##_state_cb; \
53 ustream_fd_init(&us, fd);
55 struct rpc_file_exec_context {
56 struct ubus_context *context;
57 struct ubus_request_data request;
58 struct uloop_timeout timeout;
59 struct uloop_process process;
60 struct ustream_fd opipe;
61 struct ustream_fd epipe;