You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/16 06:50:17 UTC

[GitHub] mkiiskila closed pull request #1084: sys/config; option to save all config as part of newtmgr write.

mkiiskila closed pull request #1084: sys/config; option to save all config as part of newtmgr write.
URL: https://github.com/apache/mynewt-core/pull/1084
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/config/src/config_json_line.c b/sys/config/src/config_json_line.c
deleted file mode 100644
index fe6e12d83d..0000000000
--- a/sys/config/src/config_json_line.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "os/mynewt.h"
-
-#if MYNEWT_VAL(CONFIG_NEWTMGR)
-
-#include "config/config.h"
-#include "config_priv.h"
-#include "cborattr/cborattr.h"
-#include "mgmt/mgmt.h"
-
-int
-conf_cbor_line(struct mgmt_cbuf *cb, char *name, int nlen, char *value, int vlen)
-{
-    const struct cbor_attr_t val_attr[3] = {
-        [0] = {
-            .attribute = "name",
-            .type = CborAttrTextStringType,
-            .addr.string = name,
-            .len = nlen
-        },
-        [1] = {
-            .attribute = "val",
-            .type = CborAttrTextStringType,
-            .addr.string = value,
-            .len = vlen
-        },
-        [2] = {
-            .attribute = NULL
-        }
-    };
-    int rc;
-
-    rc = cbor_read_object(&cb->it, val_attr);
-    if (rc) {
-        return rc;
-    }
-    return 0;
-}
-
-#endif
diff --git a/sys/config/src/config_nmgr.c b/sys/config/src/config_nmgr.c
index 464132c9ca..ba94a97d65 100644
--- a/sys/config/src/config_nmgr.c
+++ b/sys/config/src/config_nmgr.c
@@ -87,22 +87,58 @@ conf_nmgr_write(struct mgmt_cbuf *cb)
     int rc;
     char name_str[CONF_MAX_NAME_LEN];
     char val_str[CONF_MAX_VAL_LEN];
+    bool do_save = false;
+    const struct cbor_attr_t val_attr[] = {
+        [0] = {
+            .attribute = "name",
+            .type = CborAttrTextStringType,
+            .addr.string = name_str,
+            .len = sizeof(name_str)
+        },
+        [1] = {
+            .attribute = "val",
+            .type = CborAttrTextStringType,
+            .addr.string = val_str,
+            .len = sizeof(val_str)
+        },
+        [2] = {
+            .attribute = "save",
+            .type = CborAttrBooleanType,
+            .addr.boolean = &do_save
+        },
+        [3] = {
+            .attribute = NULL
+        }
+    };
 
-    rc = conf_cbor_line(cb, name_str, sizeof(name_str), val_str,
-      sizeof(val_str));
-    if (rc) {
-        return MGMT_ERR_EINVAL;
-    }
+    name_str[0] = '\0';
+    val_str[0] = '\0';
 
-    rc = conf_set_value(name_str, val_str);
+    rc = cbor_read_object(&cb->it, val_attr);
     if (rc) {
         return MGMT_ERR_EINVAL;
     }
 
+    if (name_str[0] != '\0') {
+        if (val_str[0] != '\0') {
+            rc = conf_set_value(name_str, val_str);
+        } else {
+            rc = conf_set_value(name_str, NULL);
+        }
+        if (rc) {
+            return MGMT_ERR_EINVAL;
+        }
+    }
     rc = conf_commit(NULL);
     if (rc) {
         return MGMT_ERR_EINVAL;
     }
+    if (do_save) {
+        rc = conf_save();
+        if (rc) {
+            return MGMT_ERR_EINVAL;
+        }
+    }
     return 0;
 }
 
diff --git a/sys/config/src/config_priv.h b/sys/config/src/config_priv.h
index 0e17b92e9c..6e70b15485 100644
--- a/sys/config/src/config_priv.h
+++ b/sys/config/src/config_priv.h
@@ -28,8 +28,6 @@ int conf_cli_register(void);
 int conf_nmgr_register(void);
 
 struct mgmt_cbuf;
-int conf_cbor_line(struct mgmt_cbuf *cb, char *name, int nlen, char *value,
-                   int vlen);
 int conf_line_parse(char *buf, char **namep, char **valp);
 int conf_line_make(char *dst, int dlen, const char *name, const char *val);
 int conf_line_make2(char *dst, int dlen, const char *name, const char *value);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services