From patchwork Sun Jun 14 04:14:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 483922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 278891400A0 for ; Sun, 14 Jun 2015 14:30:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ehrdqo4h; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 202A328C119; Sun, 14 Jun 2015 06:27:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 06D8328BD88 for ; Sun, 14 Jun 2015 06:27:03 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-pd0-f181.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com [209.85.192.181]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 14 Jun 2015 06:27:01 +0200 (CEST) Received: by pdbki1 with SMTP id ki1so49203808pdb.1 for ; Sat, 13 Jun 2015 21:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9D9W9Qe+Y4AGS3QPJj1AUIbOlkllIpcNLRmauSVK3Tg=; b=ehrdqo4hx9GIrJJg71IgKC0IjClePOWoT32YvbaxWMet/Hv41SxvjIbL8CUxfgmGWe NhEiFYyVNg878y1/sZ46RaObb553LPURvKucsyUia3RmtCEVGGChcg2wqWGVpTL49N3T w47Xk0694+oy8RakBfRk9F3LFKg677lTYYyZSXrDQ36IdBaEXLPZ7f0sAKdetiXhcLcx SZLOrFurSYQ8YUDw6OMJWt5/xPL9QqOjSSe7VYSrKoE3myrRu3kRko3zopIoefw8mb79 uUwappOD9wg4t0GZHfniijWspJF8Y6yCg18NKvXAieV2uO4M0YYU7VnzXDAkN7q2gbjP GiVQ== X-Received: by 10.66.100.162 with SMTP id ez2mr36856619pab.89.1434256021563; Sat, 13 Jun 2015 21:27:01 -0700 (PDT) Received: from debian.corp.sankuai.com ([103.29.140.57]) by mx.google.com with ESMTPSA id w4sm8120056pdl.7.2015.06.13.21.26.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Jun 2015 21:27:01 -0700 (PDT) From: Yousong Zhou To: blogic@openwrt.org Date: Sun, 14 Jun 2015 12:14:46 +0800 Message-Id: <1434255287-18591-5-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1434255287-18591-1-git-send-email-yszhou4tech@gmail.com> References: <1434255287-18591-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH 4/5] service: allow get_data of specifc instance. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Yousong Zhou --- service/service.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/service/service.c b/service/service.c index c2a242b..2702dc3 100644 --- a/service/service.c +++ b/service/service.c @@ -213,8 +213,17 @@ static const struct blobmsg_policy validate_policy[__VALIDATE_MAX] = { [VALIDATE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING }, }; +enum { + DATA_NAME, + DATA_INSTANCE, + DATA_TYPE, + __DATA_MAX +}; + static const struct blobmsg_policy get_data_policy[] = { - { "type", BLOBMSG_TYPE_STRING } + [DATA_NAME] = { "name", BLOBMSG_TYPE_STRING }, + [DATA_INSTANCE] = { "instance", BLOBMSG_TYPE_STRING }, + [DATA_TYPE] = { "type", BLOBMSG_TYPE_STRING }, }; static int @@ -424,24 +433,36 @@ service_get_data(struct ubus_context *ctx, struct ubus_object *obj, { struct service_instance *in; struct service *s; - struct blob_attr *tb; + struct blob_attr *tb[__DATA_MAX]; + const char *name = NULL; + const char *instance = NULL; const char *type = NULL; - blobmsg_parse(get_data_policy, 1, &tb, blob_data(msg), blob_len(msg)); - if (tb) - type = blobmsg_data(tb); + blobmsg_parse(get_data_policy, __DATA_MAX, tb, blob_data(msg), blob_len(msg)); + if (tb[DATA_NAME]) + name = blobmsg_data(tb[DATA_NAME]); + if (tb[DATA_INSTANCE]) + instance = blobmsg_data(tb[DATA_INSTANCE]); + if (tb[DATA_TYPE]) + type = blobmsg_data(tb[DATA_TYPE]); blob_buf_init(&b, 0); avl_for_each_element(&services, s, avl) { void *cs = NULL; + if (name && strcmp(name, s->name)) + continue; + vlist_for_each_element(&s->instances, in, node) { struct blobmsg_list_node *var; void *ci = NULL; + if (instance && strcmp(instance, in->name)) + continue; + blobmsg_list_for_each(&in->data, var) { if (type && - strcmp(blobmsg_name(var->data), type) != 0) + strcmp(blobmsg_name(var->data), type)) continue; if (!cs)