aboutsummaryrefslogtreecommitdiffstats
path: root/fs/tabfs.c
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2019-02-27 22:06:37 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2019-02-27 22:06:37 -0800
commit73f8bc754e200c041e17e613a61dfc35db414b66 (patch)
tree0b2aadcc2fc1edf75e35c5af12dacb921036d94f /fs/tabfs.c
parent74c794d75c7205123c4dc37e7a997507b61be98b (diff)
base64 hack to handle binary files.
add memory fences because why not.
Diffstat (limited to 'fs/tabfs.c')
-rw-r--r--fs/tabfs.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fs/tabfs.c b/fs/tabfs.c
index 1fa5476..0447387 100644
--- a/fs/tabfs.c
+++ b/fs/tabfs.c
@@ -8,6 +8,9 @@
#include "cJSON/cJSON.h"
#include "cJSON/cJSON.c"
+#include "base64/base64.h"
+#include "base64/base64.c"
+
#include "common.h"
#include "ws.h"
@@ -119,12 +122,15 @@ tabfs_read(const char *path, char *buf, size_t size, off_t offset,
char *resp_buf = cJSON_GetStringValue(resp_buf_item);
if (!resp_buf) return -EIO;
-
size_t resp_buf_len = strlen(resp_buf);
- size = resp_buf_len < size ? resp_buf_len : size;
-
- memcpy(buf, resp_buf, size);
+ cJSON *base64_encoded_item = cJSON_GetObjectItemCaseSensitive(resp, "base64Encoded");
+ if (base64_encoded_item && cJSON_IsTrue(base64_encoded_item)) {
+ size = base64_decode(resp_buf, resp_buf_len, (unsigned char *) buf);
+ } else {
+ size = resp_buf_len < size ? resp_buf_len : size;
+ memcpy(buf, resp_buf, size);
+ }
ret = size;
});
}