X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.c;h=12bdb37a2318ac365ea51673f17148548c15bd0c;hp=97cdfc81528165d1ae271338c1476af55d59ab57;hb=659a98c8107d194f3ef6822dacc97e02e7c53e31;hpb=83a6386edea4c246b7514f90118cd31dac573eba diff --git a/libubus.c b/libubus.c index 97cdfc8..12bdb37 100644 --- a/libubus.c +++ b/libubus.c @@ -55,7 +55,7 @@ static int ubus_cmp_id(const void *k1, const void *k2, void *ptr) return *id1 > *id2; } -struct blob_attr **ubus_parse_msg(struct blob_attr *msg) +static struct blob_attr **ubus_parse_msg(struct blob_attr *msg) { blob_parse(msg, attrbuf, ubus_policy, UBUS_ATTR_MAX); return attrbuf; @@ -102,8 +102,8 @@ static int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, return writev(ctx->sock.fd, iov, 2); } -int ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, - struct blob_attr *msg, int cmd, uint32_t peer) +static int ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, + struct blob_attr *msg, int cmd, uint32_t peer) { memset(req, 0, sizeof(*req)); @@ -657,36 +657,27 @@ struct ubus_context *ubus_connect(const char *path) goto error; ctx->sock.fd = usock(USOCK_UNIX, path, NULL); - if (ctx->sock.fd < 0) { - DPRINTF("Failed to connect to server\n"); + if (ctx->sock.fd < 0) goto error_free; - } + ctx->sock.cb = ubus_handle_data; - if (read(ctx->sock.fd, &hdr, sizeof(hdr)) != sizeof(hdr)) { - DPRINTF("Failed to read initial message data\n"); + if (read(ctx->sock.fd, &hdr, sizeof(hdr)) != sizeof(hdr)) goto error_close; - } - if (!ubus_validate_hdr(&hdr.hdr)) { - DPRINTF("Failed to validate initial message header\n"); + if (!ubus_validate_hdr(&hdr.hdr)) goto error_close; - } - if (hdr.hdr.type != UBUS_MSG_HELLO) { - DPRINTF("Unexpected initial message\n"); + if (hdr.hdr.type != UBUS_MSG_HELLO) goto error_close; - } buf = calloc(1, blob_raw_len(&hdr.data)); if (!buf) goto error_close; memcpy(buf, &hdr.data, sizeof(hdr.data)); - if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != blob_len(buf)) { - DPRINTF("Failed to retrieve initial message data\n"); + if (read(ctx->sock.fd, blob_data(buf), blob_len(buf)) != blob_len(buf)) goto error_free_buf; - } ctx->local_id = hdr.hdr.peer; free(buf); @@ -696,10 +687,8 @@ struct ubus_context *ubus_connect(const char *path) INIT_LIST_HEAD(&ctx->requests); avl_init(&ctx->objects, ubus_cmp_id, false, NULL); - if (!ctx->local_id) { - DPRINTF("Failed to get local peer id\n"); + if (!ctx->local_id) goto error_close; - } return ctx;