Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5265031ybi; Tue, 30 Jul 2019 17:23:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcnDexk1V3kFXCjei9yiFikB8/eXGOKhnJPvKSHU8i/ELfegbsAGq+ipGR7POhMPdwqjsb X-Received: by 2002:aa7:9531:: with SMTP id c17mr46082169pfp.130.1564532618986; Tue, 30 Jul 2019 17:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564532618; cv=none; d=google.com; s=arc-20160816; b=rcj38bqekEK9Be9BpZaN6WT/JtIvNsf5C06izZwBYMXI1rx/6la/ndK0U+MfHU54KE fzD15eb56g5ulA5/beatijAJkMzSv/z6ye1jWQnlJhVXgEA9LKZ6fIaDOc+QejxFsnj9 d4zvG2Uey6fwNuzGWBxbjWYJeduetVeRQ/bwJ17Oj33EzRddT4ISu6E2RtRr3r3TBINf xxMMm0Jj0Oj8PoW+3Gf3WtLqXcVICT1V0mW3l1jA/jWvK5XoaTWDJ2bvcAGoJae+zQob Ebq/RTFqY/s2cFIuxk5OSl8J24uoSej1z+HKhfumaozLFbfoNqV14CHhNObVg/+XMruY hhEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=dNDheRZrZZz8vG69Ha1urG6LqZqtmAu2OiONPHdUBSk=; b=S54pluu2TNjo4TIskOw2mwHD+3NREJ6gM3AWFc8MiJN4nSe/INWehLckrCYJ3/vfo/ Qm+z0sy23GWP/87L3JSbqxSvjq35TYq/rsPpqafCzZBiYlIKK2GgyLBGyUDG5xmSZ1N/ LoKF4VkkqvuYj/9Cs8YL06vxf6bZfBF67C9neuiwAcX6f6HL2fsYD+yfEbjQojVVij4p r65YJ6q1ZYwMEM25mtrshShCEHaGbMEDRXDUoZA7d+SFYRlIS0ADXTO87Ci+mGoolBxL Tyutw746a8+v5e1/r3eO36SILDM3QLJJWT0/ezyol/fsKlnKv9QkuEM8w4aDV1vWz5vu YOEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cf16si27832177plb.346.2019.07.30.17.23.07; Tue, 30 Jul 2019 17:23:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfG3XSJ (ORCPT + 99 others); Tue, 30 Jul 2019 19:18:09 -0400 Received: from mga05.intel.com ([192.55.52.43]:59875 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbfG3XSJ (ORCPT ); Tue, 30 Jul 2019 19:18:09 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jul 2019 16:18:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,327,1559545200"; d="p7s'?scan'208";a="191069011" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by fmsmga001.fm.intel.com with ESMTP; 30 Jul 2019 16:18:08 -0700 Received: from orsmsx103.amr.corp.intel.com ([169.254.5.29]) by ORSMSX109.amr.corp.intel.com ([169.254.11.170]) with mapi id 14.03.0439.000; Tue, 30 Jul 2019 16:18:07 -0700 From: "Stotland, Inga" To: "jakub.witowski@silvair.com" , "linux-bluetooth@vger.kernel.org" CC: "michal.lowas-rzechonek@silvair.com" Subject: Re: [PATCH BlueZ v6 1/3] mesh: Extract read_* functions in mesh-config-json Thread-Topic: [PATCH BlueZ v6 1/3] mesh: Extract read_* functions in mesh-config-json Thread-Index: AQHVRhNIYJrBBkPOhESzHIm3oi0086bkQ0mA Date: Tue, 30 Jul 2019 23:18:07 +0000 Message-ID: <5805488b1228a044dd5c9261b7fafd53acdd467b.camel@intel.com> References: <20190729134047.21033-1-michal.lowas-rzechonek@silvair.com> <20190729134047.21033-2-michal.lowas-rzechonek@silvair.com> In-Reply-To: <20190729134047.21033-2-michal.lowas-rzechonek@silvair.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [10.255.229.74] Content-Type: multipart/signed; micalg=sha-1; protocol="application/x-pkcs7-signature"; boundary="=-6OsKnQ+fCQROjZ9UBo/H" MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --=-6OsKnQ+fCQROjZ9UBo/H Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jakub, On Mon, 2019-07-29 at 15:40 +0200, Micha=C5=82 Lowas-Rzechonek wrote: > From: Jakub Witowski >=20 > This is a small improvement of read_node function readability. > --- > mesh/mesh-config-json.c | 68 +++++++++++++++++++++++++++++-------- > ---- > 1 file changed, 49 insertions(+), 19 deletions(-) >=20 > diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c > index e3baf5dc6..c63883a3d 100644 > --- a/mesh/mesh-config-json.c > +++ b/mesh/mesh-config-json.c > @@ -297,6 +297,51 @@ static json_object *jarray_key_del(json_object > *jarray, int16_t idx) > return jarray_new; > } > =20 > +static bool read_unicast_address(json_object *jobj, > + uint16_t > *unicast) > +{ > + json_object *jvalue; > + char *str; > + > + if (!json_object_object_get_ex(jobj, "unicastAddress", > &jvalue)) > + return false; > + > + str =3D (char *)json_object_get_string(jvalue); > + if (sscanf(str, "%04hx", unicast) !=3D 1) > + return false; > + > + return true; > +} > + > +static bool read_default_ttl(json_object *jobj, > + uint8_t > *ttl) > +{ > + json_object *jvalue; > + int val; > + > + if (!json_object_object_get_ex(jobj, "defaultTTL", &jvalue)) > + return false; > + > + val =3D json_object_get_int(jvalue); > + > + if (val < 0 || val =3D=3D 1 || val > DEFAULT_TTL) > + return false; New line here to separate from "if" statement > + *ttl =3D (uint8_t) val; > + > + return true; > +} > + > +static bool read_seq_number(json_object *jobj, uint32_t *seq_number) > +{ > + json_object *jvalue; > + > + if (!json_object_object_get_ex(jobj, "sequenceNumber", > &jvalue)) > + return false; > + > + *seq_number =3D json_object_get_int(jvalue); > + return true; > +} > + > static bool read_iv_index(json_object *jobj, uint32_t *idx, bool > *update) > { > int tmp; > @@ -424,7 +469,7 @@ fail: > return false; > } > =20 > -static bool read_net_keys(json_object *jobj, struct > mesh_config_node *node) > +static bool read_net_keys(json_object *jobj, struct mesh_config_node > *node) > { > json_object *jarray; > int len; > @@ -1294,7 +1339,6 @@ static bool read_net_transmit(json_object > *jobj, struct mesh_config_node *node) > static bool read_node(json_object *jnode, struct mesh_config_node > *node) > { > json_object *jvalue; > - char *str; > =20 > if (!read_iv_index(jnode, &node->iv_index, &node->iv_update)) { > l_info("Failed to read IV index"); > @@ -1318,25 +1362,11 @@ static bool read_node(json_object *jnode, > struct mesh_config_node *node) > =20 > parse_features(jnode, node); > =20 > - if (!json_object_object_get_ex(jnode, "unicastAddress", > &jvalue)) { > - l_info("Bad config: Unicast address must be present"); > - return false; > - } > - > - str =3D (char *)json_object_get_string(jvalue); > - if (sscanf(str, "%04hx", &node->unicast) !=3D 1) > - return false; > - > - if (json_object_object_get_ex(jnode, "defaultTTL", &jvalue)) { > - int ttl =3D json_object_get_int(jvalue); > + read_unicast_address(jnode, &node->unicast); > =20 The return status needs to be checked: unicast must be present > - if (ttl < 0 || ttl =3D=3D 1 || ttl > DEFAULT_TTL) > - return false; > - node->ttl =3D (uint8_t) ttl; > - } > + read_default_ttl(jnode, &node->ttl); > =20 I would prefer to keep ttl and sequesnce number parsing as they are now: they are not mandatory, but we don't want to allow for bad format, i.e., we dont want to fail if the fields are absent, but we do want to fail if the format is wrong. > - if (json_object_object_get_ex(jnode, "sequenceNumber", > &jvalue)) > - node->seq_number =3D json_object_get_int(jvalue); > + read_seq_number(jnode, &node->seq_number); > =20 > /* Check for required "elements" property */ > if (!json_object_object_get_ex(jnode, "elements", &jvalue)) Regards, Inga --=-6OsKnQ+fCQROjZ9UBo/H Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Disposition: attachment; filename="smime.p7s" Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIKbDCCBOsw ggPToAMCAQICEDabxALowUBS+21KC0JI8fcwDQYJKoZIhvcNAQEFBQAwbzELMAkGA1UEBhMCU0Ux FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5hbCBUVFAgTmV0 d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9vdDAeFw0xMzEyMTEwMDAwMDBa Fw0yMDA1MzAxMDQ4MzhaMHkxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEUMBIGA1UEBxMLU2Fu dGEgQ2xhcmExGjAYBgNVBAoTEUludGVsIENvcnBvcmF0aW9uMSswKQYDVQQDEyJJbnRlbCBFeHRl cm5hbCBCYXNpYyBJc3N1aW5nIENBIDRCMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA yzuW/y/g0bznz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