aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2018-11-11 11:44:36 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2018-11-11 11:44:36 -0800
commit5c2b15068ea11795ebd60de0f4bbb8240c70135f (patch)
tree4d668c99115e7951ec42829dbb477e37b1d2fb87
parent4ca75894c16ea3be1e4c19a7469f1595c18b2f63 (diff)
Groundwork for response parsing.
-rw-r--r--extension/background.js10
-rw-r--r--fs/hello.c41
2 files changed, 41 insertions, 10 deletions
diff --git a/extension/background.js b/extension/background.js
index 3fa39c1..aa10b37 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -3,9 +3,13 @@ const ws = new WebSocket("ws://localhost:8888");
ws.onmessage = function(event) {
const req = JSON.parse(event.data);
- const response = {
- names: [".", "..", "hi.txt"]
- };
+ let response;
+ if (req.op === "readdir") {
+ response = {
+ op: "readdir",
+ names: [".", "..", "hi.txt"]
+ };
+ }
ws.send(JSON.stringify(response));
};
diff --git a/fs/hello.c b/fs/hello.c
index 2d5db9c..d84fe37 100644
--- a/fs/hello.c
+++ b/fs/hello.c
@@ -25,8 +25,8 @@ struct wby_server server;
struct wby_con *con;
typedef struct response_readdir_t {
- char **names;
- size_t num_names;
+ char **entries;
+ size_t num_entries;
} response_readdir_t;
response_readdir_t *response;
@@ -74,30 +74,33 @@ hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
// send [READDIR, path] to the websocket handler
{
- char *msg;
+ char *data;
{
cJSON *req = cJSON_CreateObject();
cJSON_AddStringToObject(req, "op", "readdir");
cJSON_AddStringToObject(req, "path", path);
- msg = cJSON_Print(req);
- printf("%s\n", msg);
+ data = cJSON_Print(req);
+ printf("%s\n", data);
cJSON_Delete(req);
}
wby_frame_begin(con, WBY_WSOP_TEXT_FRAME);
- wby_write(con, msg, strlen(msg));
+ wby_write(con, data, strlen(data));
wby_frame_end(con);
- free(msg);
+ free(data);
}
+ if (response) free(response);
response = NULL;
do {
wby_update(&server);
} while (response == NULL);
+ printf("response: %d files\n", response->num_entries);
+
filler(buf, ".", NULL, 0); /* Current directory (.) */
filler(buf, "..", NULL, 0); /* Parent directory (..) */
filler(buf, file_path + 1, NULL, 0); /* The only file we have. */
@@ -159,12 +162,19 @@ websocket_connected(struct wby_con *connection, void *userdata)
static int
websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void *userdata)
{
+ unsigned char data[1024] = {0};
+
int i = 0;
printf("WebSocket frame incoming\n");
printf(" Frame OpCode: %d\n", frame->opcode);
printf(" Final frame?: %s\n", (frame->flags & WBY_WSF_FIN) ? "yes" : "no");
printf(" Masked? : %s\n", (frame->flags & WBY_WSF_MASKED) ? "yes" : "no");
printf(" Data Length : %d\n", (int) frame->payload_length);
+
+ if ((unsigned long) frame->payload_length > sizeof(data)) {
+ printf("Data too long!\n");
+ }
+
while (i < frame->payload_length) {
unsigned char buffer[16];
int remain = frame->payload_length - i;
@@ -182,8 +192,25 @@ websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void
for (k = 0; k < read_size; ++k)
printf("%c", isprint(buffer[k]) ? buffer[k] : '?');
printf("\n");
+ for (k = 0; k < read_size; ++k)
+ data[i + k] = buffer[k];
i += (int)read_size;
}
+
+ if ((int) strlen((const char *) data) != frame->payload_length) {
+ printf("Null in data! [%s]\n", data);
+ }
+
+ cJSON *ret = cJSON_Parse((const char *) data);
+ cJSON *op = cJSON_GetObjectItemCaseSensitive(ret, "op");
+ if (strcmp(op->valuestring, "readdir") == 0) {
+ response = malloc(sizeof(response));
+ response->entries = malloc(sizeof(char *) * 10);
+ response->entries[0] = "a";
+ response->entries[1] = "b";
+ response->num_entries = 2;
+ }
+
return 0;
}