Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp208589pxb; Wed, 22 Sep 2021 20:29:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3YCCV9ddUWvdo92S59LdQwAsF3P+ICqCxrhI/pJi/bIa66ejvDCfDNGpo3uxiRsXZO1CM X-Received: by 2002:a17:906:2691:: with SMTP id t17mr2612026ejc.522.1632367759809; Wed, 22 Sep 2021 20:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632367759; cv=none; d=google.com; s=arc-20160816; b=poOXfMgC6dERGsTwJ4v8Y4QuF5eLWddRvzIAdDm+flEwBeLznmwKsOWwa7oHeMXjvu A2YawrbhiUMVP+acODEM5UHKWGxG2DQ+fG+4uOa9eMGhveElN6DkJrkA1kyfctNhKezu VkiPcxuyz6huzTwUGr3dTzJXWUkn5JWsTX3aBhBRxScq4PzGm43ldJp+K6uzspj8S0FH yAHKsr+0vWNY0vMD4iL86HV5MXLriPleiz93jAqbCVKYaaDwQqC1rRnAdiVXBKOqY6L6 btkQ1py3IuFNFvdZpNfNWx26sYetXaPG2KetUWt6tKj4yOj51o+do1FwYfrShysfNu2u E6lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=swP0uvlS87aLK+OLnXr7Y+6hW6GZx/Mp3i1jB7A16OY=; b=rQB4YFdtTEf+mO+xiaF7TcOkxmmQFEc6c3e+u6wxb8sPcMElkretLTn0c97XbfPedq 14LzoMlwpF/3j2a2HFW18JBL+63nrHLfnD3CgILMTIDtJI06ba/HxxQdcJWFq5qu5XBN nJ2xlJ8MHWVjoHSw1jOgOtPCRxz9ew4aFHbF3AbXh1EQr1Kg41LAsS9uhA4zolEnhLxd QQtyy/nSefpQiH3oaCf1GtJRpJ+qZdu7IBv6hcZpD+2NFqYHMuOSrWqiV01aT5w/7QYH TvykeGgxih2IhI0wissv/LPqA3cC2wczEr0en98mDZZw9pAJJvvcZNc75zV6JEzRxNnT 0uwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id 9si4311390ejy.65.2021.09.22.20.28.40; Wed, 22 Sep 2021 20:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 S239051AbhIWD2o (ORCPT + 99 others); Wed, 22 Sep 2021 23:28:44 -0400 Received: from mga11.intel.com ([192.55.52.93]:16373 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239045AbhIWD2l (ORCPT ); Wed, 22 Sep 2021 23:28:41 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10115"; a="220555895" X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="220555895" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 20:26:52 -0700 X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="534072328" Received: from jdudwadk-mobl.amr.corp.intel.com (HELO istotlan-desk.intel.com) ([10.212.205.211]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 20:26:51 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 02/20] tools/mesh-cfgclient: Add timestamp to config database Date: Wed, 22 Sep 2021 20:25:45 -0700 Message-Id: <20210923032603.50536-3-inga.stotland@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210923032603.50536-1-inga.stotland@intel.com> References: <20210923032603.50536-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds timestamp property to the configuration database. The UTC timestamp format: YYYY-MM-DDThh:mm:ssZ --- tools/mesh/mesh-db.c | 56 +++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c index 50fbc18cb..d42587da8 100644 --- a/tools/mesh/mesh-db.c +++ b/tools/mesh/mesh-db.c @@ -3,7 +3,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2019 Intel Corporation. All rights reserved. + * Copyright (C) 2019-2020 Intel Corporation. All rights reserved. * * */ @@ -20,10 +20,9 @@ #include #include #include +#include #include -#include - #include #include @@ -42,13 +41,39 @@ struct mesh_db { json_object *jcfg; char *cfg_fname; uint8_t token[8]; - struct timeval write_time; }; static struct mesh_db *cfg; static const char *bak_ext = ".bak"; static const char *tmp_ext = ".tmp"; +static bool add_string(json_object *jobj, const char *desc, const char *str) +{ + json_object *jstring = json_object_new_string(str); + + if (!jstring) + return false; + + json_object_object_add(jobj, desc, jstring); + return true; +} + +static bool set_timestamp(json_object *jobj) +{ + time_t time_raw; + struct tm *tp; + char buf[80]; + + time(&time_raw); + tp = gmtime(&time_raw); + + strftime(buf, 80, "%FT%TZ", tp); + + json_object_object_del(jobj, "timestamp"); + + return add_string(jobj, "timestamp", buf); +} + static bool save_config_file(const char *fname) { FILE *outfile; @@ -61,6 +86,8 @@ static bool save_config_file(const char *fname) return false; } + set_timestamp(cfg->jcfg); + str = json_object_to_json_string_ext(cfg->jcfg, JSON_C_TO_STRING_PRETTY); @@ -97,8 +124,6 @@ static bool save_config(void) l_free(fname_tmp); l_free(fname_bak); - gettimeofday(&cfg->write_time, NULL); - return result; } @@ -289,17 +314,6 @@ static bool add_u8_16(json_object *jobj, const char *desc, return true; } -static bool add_string(json_object *jobj, const char *desc, const char *str) -{ - json_object *jstring = json_object_new_string(str); - - if (!jstring) - return false; - - json_object_object_add(jobj, desc, jstring); - return true; -} - static bool get_token(json_object *jobj, uint8_t token[8]) { json_object *jval; @@ -726,6 +740,9 @@ bool mesh_db_net_key_add(uint16_t net_idx) if (!write_int(jkey, "phase", KEY_REFRESH_PHASE_NONE)) goto fail; + if (!set_timestamp(jkey)) + goto fail; + json_object_array_add(jarray, jkey); return save_config(); @@ -960,10 +977,7 @@ bool mesh_db_add_node(uint8_t uuid[16], uint8_t num_els, uint16_t unicast, json_object_array_add(jnodes, jnode); - if (!save_config()) - goto fail; - - return true; + return save_config(); fail: json_object_put(jnode); -- 2.31.1