mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
fix: handle incoming websocket requests; fix: removed double free; introduced jsonrpc notifications (to handle close)
This commit is contained in:
parent
b698119079
commit
aec60d194e
@ -53,7 +53,7 @@ class FileSystemHandler {
|
||||
const inode = request.params[0];
|
||||
const handle = request.params[1];
|
||||
const mode = request.params[2];
|
||||
result = this._fs.open(inode, handle, mode);
|
||||
this._fs.close(inode, handle, mode);
|
||||
}
|
||||
break;
|
||||
case "read":
|
||||
@ -69,6 +69,8 @@ class FileSystemHandler {
|
||||
break;
|
||||
}
|
||||
|
||||
if ("number" == typeof(request.id))
|
||||
{
|
||||
if ("number" !== typeof(result)) {
|
||||
response = {result: result, id: request.id};
|
||||
}
|
||||
@ -79,6 +81,7 @@ class FileSystemHandler {
|
||||
this._connection.send(JSON.stringify(response));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ex) { console.log(ex, message); }
|
||||
};
|
||||
}
|
||||
|
@ -35,7 +35,10 @@ json_t * wsfs_jsonrpc_request_create(
|
||||
|
||||
|
||||
json_object_set_new(request, "params", params);
|
||||
if (0 != id)
|
||||
{
|
||||
json_object_set_new(request, "id", json_integer(id));
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
@ -83,6 +83,11 @@ void wsfs_jsonrpc_server_invoke(
|
||||
{
|
||||
if (!method->invoke(method->user_data, request))
|
||||
{
|
||||
server->request.is_pending = false;
|
||||
server->request.finished = NULL;
|
||||
server->request.user_data = NULL;
|
||||
server->request.id = 0;
|
||||
|
||||
finished(user_data, WSFS_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
@ -97,9 +102,33 @@ void wsfs_jsonrpc_server_invoke(
|
||||
{
|
||||
finished(user_data, WSFS_BAD_BUSY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
extern void wsfs_jsonrpc_server_notify(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
)
|
||||
{
|
||||
struct wsfs_jsonrpc_method const * method = wsfs_jsonrpc_server_getmethod(server, method_name);
|
||||
if (NULL != method)
|
||||
{
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wsfs_jsonrpc_request_create(method_name, 0, param_info, args);
|
||||
va_end(args);
|
||||
if (NULL != request)
|
||||
{
|
||||
method->invoke(method->user_data, request);
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void wsfs_jsonrpc_server_onresult(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * message,
|
||||
@ -108,8 +137,6 @@ void wsfs_jsonrpc_server_onresult(
|
||||
struct wsfs_jsonrpc_response response;
|
||||
wsfs_jsonrpc_response_init(&response, message, length);
|
||||
|
||||
if (-1 != response.id)
|
||||
{
|
||||
if ((server->request.is_pending) && (response.id == server->request.id))
|
||||
{
|
||||
wsfs_jsonrpc_method_finished_fn * finished = server->request.finished;
|
||||
@ -122,7 +149,6 @@ void wsfs_jsonrpc_server_onresult(
|
||||
|
||||
finished(user_data, response.status, response.result);
|
||||
}
|
||||
}
|
||||
|
||||
wsfs_jsonrpc_response_cleanup(&response);
|
||||
}
|
||||
|
@ -50,7 +50,14 @@ extern void wsfs_jsonrpc_server_invoke(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
wsfs_jsonrpc_method_finished_fn * finished,
|
||||
void * user_data,
|
||||
char const * method,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
||||
extern void wsfs_jsonrpc_server_notify(
|
||||
struct wsfs_jsonrpc_server * server,
|
||||
char const * method_name,
|
||||
char const * param_info,
|
||||
...
|
||||
);
|
||||
|
@ -7,16 +7,6 @@
|
||||
#include "wsfs/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
|
||||
static void wsfs_operation_close_finished(
|
||||
void * user_data,
|
||||
wsfs_status status,
|
||||
json_t const * WSFS_UNUSED_PARAM(result))
|
||||
{
|
||||
fuse_req_t request = (fuse_req_t) user_data;
|
||||
fuse_reply_err(request, (WSFS_GOOD == status) ? 0 : ENOENT);
|
||||
}
|
||||
|
||||
void wsfs_operation_close(
|
||||
fuse_req_t request,
|
||||
fuse_ino_t inode,
|
||||
@ -26,7 +16,6 @@ void wsfs_operation_close(
|
||||
struct wsfs_jsonrpc_server * rpc = user_data->rpc;
|
||||
|
||||
int handle = (int) (file_info->fh & INT_MAX);
|
||||
wsfs_jsonrpc_server_invoke(
|
||||
rpc, &wsfs_operation_close_finished, request,
|
||||
"close", "iii", inode, handle, file_info->flags);
|
||||
wsfs_jsonrpc_server_notify(rpc, "close", "iii", inode, handle, file_info->flags);
|
||||
fuse_reply_err(request, 0);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "wsfs/jsonrpc/server.h"
|
||||
#include "wsfs/util.h"
|
||||
#include "wsfs/status.h"
|
||||
|
||||
static void wsfs_operation_open_finished(
|
||||
void * user_data,
|
||||
|
@ -11,8 +11,8 @@ static int wsfs_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
void * WSFS_UNUSED_PARAM(user),
|
||||
void * WSFS_UNUSED_PARAM(in),
|
||||
size_t WSFS_UNUSED_PARAM(len))
|
||||
void * in,
|
||||
size_t len)
|
||||
{
|
||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||
struct wsfs_server_protocol * protocol = ws_protocol->user;
|
||||
@ -56,6 +56,11 @@ static int wsfs_server_protocol_callback(
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE:
|
||||
{
|
||||
wsfs_jsonrpc_server_onresult(&protocol->rpc, in, len);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
{
|
||||
wsfs_filesystem_process_request(&protocol->filesystem);
|
||||
|
@ -10,8 +10,25 @@
|
||||
case WSFS_BAD_NOTIMPLEMENTED: return -ENOSYS;
|
||||
case WSFS_BAD_TIMEOUT: return -ETIMEDOUT;
|
||||
case WSFS_BAD_BUSY: return -ENOENT;
|
||||
case WSFS_BAD_FORMAT: return -ENOENT;
|
||||
case WSFS_BAD_NOENTRY: return -ENOENT;
|
||||
case WSFS_BAD_NOACCESS: return -EACCES;
|
||||
default: return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
char const * wsfs_status_tostring(wsfs_status status)
|
||||
{
|
||||
switch(status)
|
||||
{
|
||||
case WSFS_GOOD: return "Good";
|
||||
case WSFS_BAD: return "Bad";
|
||||
case WSFS_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)";
|
||||
case WSFS_BAD_TIMEOUT: return "Bad (timeout)";
|
||||
case WSFS_BAD_BUSY: return "Bad (busy)";
|
||||
case WSFS_BAD_FORMAT: return "Bad (format)";
|
||||
case WSFS_BAD_NOENTRY: return "Bad (no entry)";
|
||||
case WSFS_BAD_NOACCESS: return "Bad (no access)";
|
||||
default: return "Bad (unknown)";
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ extern "C" {
|
||||
|
||||
extern int wsfs_status_to_rc(wsfs_status status);
|
||||
|
||||
extern char const * wsfs_status_tostring(wsfs_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user