mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-01 13:32:28 +02:00
fs: Fix formatting.
This commit is contained in:
parent
784ec83696
commit
a8ce61d9a1
40
fs/tabfs.c
40
fs/tabfs.c
|
@ -27,15 +27,15 @@ static cJSON *send_request_then_await_response(cJSON *req) {
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAKE_REQ(op, req_body, resp_handler) \
|
#define MAKE_REQ(OP, REQ_BUILDER_BODY, RESP_HANDLER_BODY) \
|
||||||
do { \
|
do { \
|
||||||
int ret = -1; \
|
int ret = -1; \
|
||||||
cJSON *req = NULL; \
|
cJSON *req = NULL; \
|
||||||
cJSON *resp = NULL; \
|
cJSON *resp = NULL; \
|
||||||
\
|
\
|
||||||
req = cJSON_CreateObject(); \
|
req = cJSON_CreateObject(); \
|
||||||
cJSON_AddStringToObject(req, "op", op); \
|
cJSON_AddStringToObject(req, "op", OP); \
|
||||||
req_body \
|
REQ_BUILDER_BODY \
|
||||||
\
|
\
|
||||||
resp = send_request_then_await_response(req); \
|
resp = send_request_then_await_response(req); \
|
||||||
\
|
\
|
||||||
|
@ -46,22 +46,20 @@ static cJSON *send_request_then_await_response(cJSON *req) {
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
resp_handler \
|
RESP_HANDLER_BODY \
|
||||||
\
|
\
|
||||||
done: \
|
done: \
|
||||||
if (req != NULL) cJSON_Delete(req); \
|
if (req != NULL) cJSON_Delete(req); \
|
||||||
if (resp != NULL) cJSON_Delete(resp); \
|
if (resp != NULL) cJSON_Delete(resp); \
|
||||||
return ret; \
|
return ret; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define JSON_GET_PROP_INT(lvalue, key) \
|
#define JSON_GET_PROP_INT(LVALUE, KEY) \
|
||||||
do { \
|
do { \
|
||||||
lvalue = cJSON_GetObjectItemCaseSensitive(resp, key)->valueint; \
|
LVALUE = cJSON_GetObjectItemCaseSensitive(resp, KEY)->valueint; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static int
|
static int tabfs_getattr(const char *path, struct stat *stbuf) {
|
||||||
tabfs_getattr(const char *path, struct stat *stbuf)
|
|
||||||
{
|
|
||||||
memset(stbuf, 0, sizeof(struct stat));
|
memset(stbuf, 0, sizeof(struct stat));
|
||||||
|
|
||||||
MAKE_REQ("getattr", {
|
MAKE_REQ("getattr", {
|
||||||
|
@ -75,9 +73,7 @@ tabfs_getattr(const char *path, struct stat *stbuf)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int tabfs_readlink(const char *path, char *buf, size_t size) {
|
||||||
tabfs_readlink(const char *path, char *buf, size_t size)
|
|
||||||
{
|
|
||||||
MAKE_REQ("readlink", {
|
MAKE_REQ("readlink", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
}, {
|
}, {
|
||||||
|
@ -93,9 +89,7 @@ tabfs_readlink(const char *path, char *buf, size_t size)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int tabfs_open(const char *path, struct fuse_file_info *fi) {
|
||||||
tabfs_open(const char *path, struct fuse_file_info *fi)
|
|
||||||
{
|
|
||||||
MAKE_REQ("open", {
|
MAKE_REQ("open", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
cJSON_AddNumberToObject(req, "flags", fi->flags);
|
cJSON_AddNumberToObject(req, "flags", fi->flags);
|
||||||
|
@ -109,8 +103,7 @@ tabfs_open(const char *path, struct fuse_file_info *fi)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tabfs_read(const char *path, char *buf, size_t size, off_t offset,
|
tabfs_read(const char *path, char *buf, size_t size, off_t offset,
|
||||||
struct fuse_file_info *fi)
|
struct fuse_file_info *fi) {
|
||||||
{
|
|
||||||
MAKE_REQ("read", {
|
MAKE_REQ("read", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
cJSON_AddNumberToObject(req, "size", size);
|
cJSON_AddNumberToObject(req, "size", size);
|
||||||
|
@ -143,9 +136,7 @@ static int tabfs_release(const char *path, struct fuse_file_info *fi) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int tabfs_opendir(const char *path, struct fuse_file_info *fi) {
|
||||||
tabfs_opendir(const char *path, struct fuse_file_info *fi)
|
|
||||||
{
|
|
||||||
MAKE_REQ("opendir", {
|
MAKE_REQ("opendir", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
cJSON_AddNumberToObject(req, "flags", fi->flags);
|
cJSON_AddNumberToObject(req, "flags", fi->flags);
|
||||||
|
@ -159,9 +150,7 @@ tabfs_opendir(const char *path, struct fuse_file_info *fi)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tabfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
tabfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||||
off_t offset, struct fuse_file_info *fi)
|
off_t offset, struct fuse_file_info *fi) {
|
||||||
{
|
|
||||||
// send {op: "readdir", path} to the websocket handler
|
|
||||||
MAKE_REQ("readdir", {
|
MAKE_REQ("readdir", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
}, {
|
}, {
|
||||||
|
@ -176,8 +165,7 @@ tabfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tabfs_releasedir(const char *path, struct fuse_file_info *fi)
|
tabfs_releasedir(const char *path, struct fuse_file_info *fi) {
|
||||||
{
|
|
||||||
MAKE_REQ("releasedir", {
|
MAKE_REQ("releasedir", {
|
||||||
cJSON_AddStringToObject(req, "path", path);
|
cJSON_AddStringToObject(req, "path", path);
|
||||||
cJSON_AddNumberToObject(req, "fh", fi->fh);
|
cJSON_AddNumberToObject(req, "fh", fi->fh);
|
||||||
|
|
89
fs/ws.c
89
fs/ws.c
|
@ -49,37 +49,17 @@ static void receive_tabfs_request_then_send_to_browser() {
|
||||||
wby_write(con, request_data, strlen(request_data));
|
wby_write(con, request_data, strlen(request_data));
|
||||||
wby_frame_end(con);
|
wby_frame_end(con);
|
||||||
|
|
||||||
/* pthread_mutex_lock(&queue_mutex); */
|
// Was allocated by sender (tabfs.c, send_request_then_await_response).
|
||||||
|
free(request_data);
|
||||||
/* if (con == NULL) goto done; */
|
|
||||||
|
|
||||||
/* for (request_id id = 0; id < REQUEST_RESPONSE_QUEUE_SIZE; id++) { */
|
|
||||||
/* if (queue[id].state == SEND_REQUEST) { */
|
|
||||||
/* char *request = queue[id].request; */
|
|
||||||
|
|
||||||
/* wby_frame_begin(con, WBY_WSOP_TEXT_FRAME); */
|
|
||||||
/* wby_write(con, request, strlen(request)); */
|
|
||||||
/* wby_frame_end(con); */
|
|
||||||
|
|
||||||
/* queue[id].state = RECEIVE_RESPONSE; */
|
|
||||||
/* free(request); */
|
|
||||||
/* queue[id].request = NULL; */
|
|
||||||
/* } */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* done: */
|
|
||||||
/* pthread_mutex_unlock(&queue_mutex); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dispatch(struct wby_con *connection, void *userdata)
|
dispatch(struct wby_con *connection, void *userdata) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
websocket_connect(struct wby_con *connection, void *userdata)
|
websocket_connect(struct wby_con *connection, void *userdata) {
|
||||||
{
|
|
||||||
/* connection bound userdata */
|
/* connection bound userdata */
|
||||||
connection->user_data = NULL;
|
connection->user_data = NULL;
|
||||||
if (0 == strcmp(connection->request.uri, "/"))
|
if (0 == strcmp(connection->request.uri, "/"))
|
||||||
|
@ -88,8 +68,7 @@ websocket_connect(struct wby_con *connection, void *userdata)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
websocket_connected(struct wby_con *connection, void *userdata)
|
websocket_connected(struct wby_con *connection, void *userdata) {
|
||||||
{
|
|
||||||
printf("WebSocket connected\n");
|
printf("WebSocket connected\n");
|
||||||
con = connection;
|
con = connection;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +78,8 @@ websocket_connected(struct wby_con *connection, void *userdata)
|
||||||
static int
|
static int
|
||||||
websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void *userdata)
|
websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void *userdata)
|
||||||
{
|
{
|
||||||
unsigned char *data = calloc(1, MAX_DATA_LENGTH); // Will be freed at receiver (tabfs).
|
// Will be freed at receiver (tabfs.c, send_request_then_await_response).
|
||||||
|
unsigned char *data = calloc(1, MAX_DATA_LENGTH);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
DEBUG("WebSocket frame incoming\n");
|
DEBUG("WebSocket frame incoming\n");
|
||||||
|
@ -141,63 +121,20 @@ websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void
|
||||||
|
|
||||||
common_send_ws_to_tabfs((char *) data);
|
common_send_ws_to_tabfs((char *) data);
|
||||||
|
|
||||||
// Will be freed at the receiver end.
|
|
||||||
/* cJSON *resp = cJSON_Parse((const char *) data); */
|
|
||||||
|
|
||||||
/* cJSON *id_item = cJSON_GetObjectItemCaseSensitive(resp, "id"); */
|
|
||||||
/* if (id_item == NULL) { */
|
|
||||||
/* printf("No id in response!\n"); */
|
|
||||||
/* exit(1); */
|
|
||||||
/* } */
|
|
||||||
/* request_id id = id_item->valueint; */
|
|
||||||
|
|
||||||
/* pthread_mutex_lock(&queue_mutex); */
|
|
||||||
|
|
||||||
/* if (queue[id].state != RECEIVE_RESPONSE) { */
|
|
||||||
/* printf("Got response to request in wrong state!\n"); */
|
|
||||||
/* exit(1); */
|
|
||||||
/* } */
|
|
||||||
/* queue[id].state = HANDLE_RESPONSE; */
|
|
||||||
/* queue[id].response = resp; */
|
|
||||||
|
|
||||||
/* pthread_cond_signal(&queue_cv); */
|
|
||||||
/* pthread_mutex_unlock(&queue_mutex); */
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void websocket_closed(struct wby_con *connection, void *userdata) {
|
||||||
websocket_closed(struct wby_con *connection, void *userdata)
|
|
||||||
{
|
|
||||||
printf("WebSocket closed\n");
|
printf("WebSocket closed\n");
|
||||||
|
|
||||||
if (con == connection) con = NULL;
|
if (con == connection) con = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void test_log(const char* text) {
|
||||||
test_log(const char* text)
|
|
||||||
{
|
|
||||||
DEBUG("[debug] %s\n", text);
|
DEBUG("[debug] %s\n", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void await_io_demand_or_timeout() {
|
void *websocket_main(void *threadid) {
|
||||||
/* pthread_mutex_lock(&queue_mutex); */
|
|
||||||
|
|
||||||
/* struct timeval now; */
|
|
||||||
/* gettimeofday(&now, NULL); */
|
|
||||||
|
|
||||||
/* struct timespec tsp; */
|
|
||||||
/* tsp.tv_sec = now.tv_sec; */
|
|
||||||
/* tsp.tv_nsec = now.tv_usec * 1000; */
|
|
||||||
|
|
||||||
/* tsp.tv_nsec += 200 * 1000000; // wait for 200ms max */
|
|
||||||
/* pthread_cond_timedwait(&queue_cv, &queue_mutex, &tsp); */
|
|
||||||
|
|
||||||
/* pthread_mutex_unlock(&queue_mutex); */
|
|
||||||
}
|
|
||||||
|
|
||||||
void *websocket_main(void *threadid)
|
|
||||||
{
|
|
||||||
void *memory = NULL;
|
void *memory = NULL;
|
||||||
wby_size needed_memory = 0;
|
wby_size needed_memory = 0;
|
||||||
|
|
||||||
|
@ -222,12 +159,8 @@ void *websocket_main(void *threadid)
|
||||||
|
|
||||||
printf("Awaiting WebSocket connection from Chrome extension.\n");
|
printf("Awaiting WebSocket connection from Chrome extension.\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// FIXME: makes reconnect impossible. :<
|
|
||||||
/* await_io_demand_or_timeout(); */
|
|
||||||
|
|
||||||
receive_tabfs_request_then_send_to_browser();
|
receive_tabfs_request_then_send_to_browser();
|
||||||
|
wby_update(&server); // We receive stuff from the browser here.
|
||||||
wby_update(&server); // We receive stuff during this phase.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wby_stop(&server);
|
wby_stop(&server);
|
||||||
|
|
Loading…
Reference in a new issue