Example #1
0
static struct fw3_address *
parse_subnet(enum fw3_family family, struct blob_attr *dict, int rem)
{
	struct blob_attr *cur;
	struct fw3_address *addr;

	addr = calloc(1, sizeof(*addr));
	if (!addr)
		return NULL;

	addr->set = true;
	addr->family = family;

	__blob_for_each_attr(cur, dict, rem)
	{
		if (!strcmp(blobmsg_name(cur), "address"))
			inet_pton(family == FW3_FAMILY_V4 ? AF_INET : AF_INET6,
			          blobmsg_get_string(cur), &addr->address.v6);

		else if (!strcmp(blobmsg_name(cur), "mask"))
			fw3_bitlen2netmask(family, blobmsg_get_u32(cur), &addr->mask.v6);
	}

	return addr;
}
Example #2
0
void blobmsg_format_std_indent(const struct blob_attr *data, int indent)
{
	struct blob_attr *attr;
	const struct blob_attr *head = blobmsg_data(data);
	int len = blobmsg_data_len(data);

	__blob_for_each_attr(attr, head, len) {
		int type = blobmsg_type(attr);

		if (blobmsg_type(data) != BLOBMSG_TYPE_ARRAY
			 && blobmsg_name(attr)[0])
			indent_printf(indent, "%s: ", blobmsg_name(attr));
		else
			indent_printf(indent, "%s", "");

		if (type == BLOBMSG_TYPE_TABLE)
			printf("{\n");
		else if (type == BLOBMSG_TYPE_ARRAY)
			printf("[\n");

		blobmsg_format_element(attr, indent + 1);

		if (type == BLOBMSG_TYPE_TABLE)
			indent_printf(indent, "}\n");
		else if (type == BLOBMSG_TYPE_ARRAY)
			indent_printf(indent, "]\n");
	}
Example #3
0
static bool
rpc_plugin_parse_signature(struct blob_attr *sig, struct ubus_method *method)
{
	int rem, n_attr;
	enum blobmsg_type type;
	struct blob_attr *attr;
	struct blobmsg_policy *policy = NULL;

	if (!sig || blobmsg_type(sig) != BLOBMSG_TYPE_TABLE)
		return false;

	n_attr = 0;

	blobmsg_for_each_attr(attr, sig, rem)
		n_attr++;

	if (n_attr)
	{
		policy = calloc(n_attr, sizeof(*policy));

		if (!policy)
			return false;

		n_attr = 0;

		blobmsg_for_each_attr(attr, sig, rem)
		{
			type = blobmsg_type(attr);

			if (type == BLOBMSG_TYPE_INT32)
			{
				switch (blobmsg_get_u32(attr))
				{
				case 8:
					type = BLOBMSG_TYPE_INT8;
					break;

				case 16:
					type = BLOBMSG_TYPE_INT16;
					break;

				case 64:
					type = BLOBMSG_TYPE_INT64;
					break;

				default:
					type = BLOBMSG_TYPE_INT32;
					break;
				}
			}

			policy[n_attr].name = strdup(blobmsg_name(attr));
			policy[n_attr].type = type;

			n_attr++;
		}
	}
Example #4
0
static void uqmi_print_result(struct blob_attr *data)
{
	struct blob_attr *cur;
	int rem;

	blob_for_each_attr(cur, data, rem) {
		switch (blobmsg_type(cur)) {
		case BLOBMSG_TYPE_STRING:
			printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
			break;
		case BLOBMSG_TYPE_INT32:
			printf("%s=%d\n", blobmsg_name(cur), (int32_t) blobmsg_get_u32(cur));
			break;
		case BLOBMSG_TYPE_INT8:
			printf("%s=%s\n", blobmsg_name(cur), blobmsg_get_u8(cur) ? "true" : "false");
			break;
		}
	}
}
Example #5
0
static void proc_handle_header_end(struct relay *r)
{
	struct client *cl = r->cl;
	struct dispatch_proc *p = &cl->dispatch.proc;
	struct blob_attr *cur;
	int rem;

	uloop_timeout_cancel(&p->timeout);
	uh_http_header(cl, cl->dispatch.proc.status_code, cl->dispatch.proc.status_msg);
	blob_for_each_attr(cur, cl->dispatch.proc.hdr.head, rem)
		ustream_printf(cl->us, "%s: %s\r\n", blobmsg_name(cur), blobmsg_data(cur));

	ustream_printf(cl->us, "\r\n");

	if (cl->request.method == UH_HTTP_MSG_HEAD)
		r->skip_data = true;
}
Example #6
0
					break;

				default:
					type = BLOBMSG_TYPE_INT32;
					break;
				}
			}

			policy[n_attr].name = strdup(blobmsg_name(attr));
			policy[n_attr].type = type;

			n_attr++;
		}
	}

	method->name = strdup(blobmsg_name(sig));
	method->handler = rpc_plugin_call;
	method->policy = policy;
	method->n_policy = n_attr;

	return true;
}

static struct ubus_object *
rpc_plugin_parse_exec(const char *name, int fd)
{
	int len, rem, n_method;
	struct blob_attr *cur;
	struct ubus_method *methods;
	struct ubus_object_type *obj_type;
	struct ubus_object *obj;