You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/12 00:33:47 UTC
[1/3] incubator-mynewt-core git commit: base64;
add base64_decode_len() to query the amount of data to be decoded.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 0f0173365 -> 6b24447dc
base64; add base64_decode_len() to query the amount of data to be decoded.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/16265b64
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/16265b64
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/16265b64
Branch: refs/heads/develop
Commit: 16265b6448ebe55bdd46e6e28c369746853d53f3
Parents: 0f01733
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 11 15:28:43 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 11 15:28:43 2016 -0700
----------------------------------------------------------------------
libs/util/include/util/base64.h | 8 +++++---
libs/util/src/base64.c | 13 +++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/16265b64/libs/util/include/util/base64.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/base64.h b/libs/util/include/util/base64.h
index 4428fa9..c6b63a7 100644
--- a/libs/util/include/util/base64.h
+++ b/libs/util/include/util/base64.h
@@ -6,7 +6,7 @@
* 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,
@@ -16,14 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifndef __UTIL_BASE64_H
-#define __UTIL_BASE64_H
+#ifndef __UTIL_BASE64_H
+#define __UTIL_BASE64_H
#include <stdint.h>
+#include <string.h>
int base64_encode(const void *, int, char *, uint8_t);
int base64_decode(const char *, void *buf);
int base64_pad(char *, int);
+int base64_decode_len(const char *str);
#define BASE64_ENCODE_SIZE(__size) (((__size) * (4 / 3)) + 4)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/16265b64/libs/util/src/base64.c
----------------------------------------------------------------------
diff --git a/libs/util/src/base64.c b/libs/util/src/base64.c
index d7a79c0..685135e 100644
--- a/libs/util/src/base64.c
+++ b/libs/util/src/base64.c
@@ -166,3 +166,16 @@ base64_decode(const char *str, void *data)
}
return q - (unsigned char *) data;
}
+
+
+int
+base64_decode_len(const char *str)
+{
+ int len;
+
+ len = strlen(str);
+ while (len && str[len - 1] == '=') {
+ len--;
+ }
+ return len * 3 / 4;
+}
[3/3] incubator-mynewt-core git commit: boot/bootutil;
also move call to fs_mkdir() to boot/main.c:main().
Posted by ma...@apache.org.
boot/bootutil; also move call to fs_mkdir() to boot/main.c:main().
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6b24447d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6b24447d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6b24447d
Branch: refs/heads/develop
Commit: 6b24447dcb4c176cff995c331d2d10191283a4dc
Parents: 88045b4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 11 15:32:29 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 11 15:32:29 2016 -0700
----------------------------------------------------------------------
apps/boot/src/boot.c | 4 ++++
libs/bootutil/src/loader.c | 3 ---
2 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6b24447d/apps/boot/src/boot.c
----------------------------------------------------------------------
diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
index 3059f7d..5157364 100755
--- a/apps/boot/src/boot.c
+++ b/apps/boot/src/boot.c
@@ -109,6 +109,10 @@ main(void)
*/
nffs_detect(nffs_descs);
}
+
+ /* Create the boot directory if it doesn't already exist. */
+ fs_mkdir("/boot");
+
log_init();
rc = boot_go(&req, &rsp);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6b24447d/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 6949d39..32a7189 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -610,9 +610,6 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
*/
boot_req = req;
- /* Create the boot directory if it doesn't already exist. */
- fs_mkdir("/boot");
-
/* Read the boot status to determine if an image copy operation was
* interrupted (i.e., the system was reset before the boot loader could
* finish its task last time).
[2/3] incubator-mynewt-core git commit: sys/config;
store/restore binary data.
Posted by ma...@apache.org.
sys/config; store/restore binary data.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/88045b45
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/88045b45
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/88045b45
Branch: refs/heads/develop
Commit: 88045b453ff49f8186848806c15141f9ed6fc512
Parents: 16265b6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 11 15:31:14 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 11 15:31:14 2016 -0700
----------------------------------------------------------------------
sys/config/include/config/config.h | 3 +++
sys/config/src/config.c | 27 +++++++++++++++++++++++++++
sys/config/src/test/conf_test.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/88045b45/sys/config/include/config/config.h
----------------------------------------------------------------------
diff --git a/sys/config/include/config/config.h b/sys/config/include/config/config.h
index 729d13b..a7956da 100644
--- a/sys/config/include/config/config.h
+++ b/sys/config/include/config/config.h
@@ -71,8 +71,11 @@ int conf_commit(char *name);
int conf_value_from_str(char *val_str, enum conf_type type, void *vp,
int maxlen);
+int conf_bytes_from_str(char *val_str, void *vp, int *len);
char *conf_str_from_value(enum conf_type type, void *vp, char *buf,
int buf_len);
+char *conf_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len);
+
#define CONF_VALUE_SET(str, type, val) \
conf_value_from_str((str), (type), &(val), sizeof(val))
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/88045b45/sys/config/src/config.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config.c b/sys/config/src/config.c
index 217466e..ceea6fa 100644
--- a/sys/config/src/config.c
+++ b/sys/config/src/config.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <os/os.h>
+#include <util/base64.h>
#include "config/config.h"
#include "config_priv.h"
@@ -142,6 +143,22 @@ err:
return OS_INVALID_PARM;
}
+int
+conf_bytes_from_str(char *val_str, void *vp, int *len)
+{
+ int tmp;
+
+ if (base64_decode_len(val_str) > *len) {
+ return OS_INVALID_PARM;
+ }
+ tmp = base64_decode(val_str, vp);
+ if (tmp < 0) {
+ return OS_INVALID_PARM;
+ }
+ *len = tmp;
+ return 0;
+}
+
char *
conf_str_from_value(enum conf_type type, void *vp, char *buf, int buf_len)
{
@@ -168,6 +185,16 @@ conf_str_from_value(enum conf_type type, void *vp, char *buf, int buf_len)
}
}
+char *
+conf_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len)
+{
+ if (BASE64_ENCODE_SIZE(vp_len) > buf_len) {
+ return NULL;
+ }
+ base64_encode(vp, vp_len, buf, 1);
+ return buf;
+}
+
int
conf_set_value(char *name, char *val_str)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/88045b45/sys/config/src/test/conf_test.c
----------------------------------------------------------------------
diff --git a/sys/config/src/test/conf_test.c b/sys/config/src/test/conf_test.c
index 6fa263c..6e80b9e 100644
--- a/sys/config/src/test/conf_test.c
+++ b/sys/config/src/test/conf_test.c
@@ -330,6 +330,36 @@ TEST_CASE(config_test_getset_int)
ctest_clear_call_state();
}
+TEST_CASE(config_test_getset_bytes)
+{
+ char orig[32];
+ char bytes[32];
+ char str[48];
+ char *ret;
+ int j, i;
+ int tmp;
+ int rc;
+
+ for (j = 1; j < sizeof(orig); j++) {
+ for (i = 0; i < j; i++) {
+ orig[i] = i + j + 1;
+ }
+ ret = conf_str_from_bytes(orig, j, str, sizeof(str));
+ TEST_ASSERT(ret);
+ tmp = strlen(str);
+ TEST_ASSERT(tmp < sizeof(str));
+
+ memset(bytes, 0, sizeof(bytes));
+ tmp = sizeof(bytes);
+
+ tmp = sizeof(bytes);
+ rc = conf_bytes_from_str(str, bytes, &tmp);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(tmp == j);
+ TEST_ASSERT(!memcmp(orig, bytes, j));
+ }
+}
+
TEST_CASE(config_test_commit)
{
char name[80];
@@ -884,6 +914,8 @@ TEST_SUITE(config_test_all)
config_test_insert();
config_test_getset_unknown();
config_test_getset_int();
+ config_test_getset_bytes();
+
config_test_commit();
/*