mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
adds infrastructure to process incoming requests; fixes invalid read of ill formatted responses
This commit is contained in:
parent
b4fac43cd1
commit
0d669fdefb
@ -9,6 +9,18 @@ struct wf_impl_jsonrpc_request
|
|||||||
void * user_data;
|
void * user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool wf_impl_jsonrpc_is_request(
|
||||||
|
json_t * message)
|
||||||
|
{
|
||||||
|
json_t * id = json_object_get(message, "id");
|
||||||
|
json_t * method = json_object_get(message, "method");
|
||||||
|
json_t * params = json_object_get(message, "params");
|
||||||
|
|
||||||
|
return (json_is_integer(id) && json_is_string(method) &&
|
||||||
|
(json_is_array(params) || json_is_object(params)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
||||||
int id,
|
int id,
|
||||||
wf_impl_jsonrpc_send_fn * send,
|
wf_impl_jsonrpc_send_fn * send,
|
||||||
|
@ -22,6 +22,9 @@ extern "C"
|
|||||||
|
|
||||||
struct wf_impl_jsonrpc_request;
|
struct wf_impl_jsonrpc_request;
|
||||||
|
|
||||||
|
extern bool wf_impl_jsonrpc_is_request(
|
||||||
|
json_t * message);
|
||||||
|
|
||||||
extern struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
extern struct wf_impl_jsonrpc_request * wf_impl_jsonrpc_request_create(
|
||||||
int id,
|
int id,
|
||||||
wf_impl_jsonrpc_send_fn * send,
|
wf_impl_jsonrpc_send_fn * send,
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||||
|
|
||||||
|
extern bool wf_impl_jsonrpc_is_response(
|
||||||
|
json_t * message)
|
||||||
|
{
|
||||||
|
json_t * id = json_object_get(message, "id");
|
||||||
|
json_t * err = json_object_get(message, "error");
|
||||||
|
json_t * result = json_object_get(message, "result");
|
||||||
|
|
||||||
|
return (json_is_integer(id) &&
|
||||||
|
(json_is_object(err) || (NULL != result)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void wf_impl_jsonrpc_response_init(
|
void wf_impl_jsonrpc_response_init(
|
||||||
struct wf_impl_jsonrpc_response * result,
|
struct wf_impl_jsonrpc_response * result,
|
||||||
json_t * response)
|
json_t * response)
|
||||||
@ -12,7 +24,6 @@ void wf_impl_jsonrpc_response_init(
|
|||||||
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
if ((NULL == id_holder) || (!json_is_integer(id_holder)))
|
||||||
{
|
{
|
||||||
result->status = WF_BAD_FORMAT;
|
result->status = WF_BAD_FORMAT;
|
||||||
json_decref(response);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
#define WF_ADAPTER_IMPL_JSONRPC_RESPONSE_H
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#else
|
#else
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -22,6 +23,9 @@ struct wf_impl_jsonrpc_response
|
|||||||
json_t * result;
|
json_t * result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern bool wf_impl_jsonrpc_is_response(
|
||||||
|
json_t * message);
|
||||||
|
|
||||||
extern void wf_impl_jsonrpc_response_init(
|
extern void wf_impl_jsonrpc_response_init(
|
||||||
struct wf_impl_jsonrpc_response * response,
|
struct wf_impl_jsonrpc_response * response,
|
||||||
json_t * message);
|
json_t * message);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include "webfuse/core/message_queue.h"
|
#include "webfuse/core/message_queue.h"
|
||||||
#include "webfuse/core/message.h"
|
#include "webfuse/core/message.h"
|
||||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||||
|
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||||
|
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
#include <libwebsockets.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -89,7 +91,15 @@ void wf_impl_session_receive(
|
|||||||
json_t * message = json_loadb(data, length, 0, NULL);
|
json_t * message = json_loadb(data, length, 0, NULL);
|
||||||
if (NULL != message)
|
if (NULL != message)
|
||||||
{
|
{
|
||||||
wf_impl_jsonrpc_proxy_onresult(&session->rpc, message);
|
if (wf_impl_jsonrpc_is_response(message))
|
||||||
|
{
|
||||||
|
wf_impl_jsonrpc_proxy_onresult(&session->rpc, message);
|
||||||
|
}
|
||||||
|
else if (wf_impl_jsonrpc_is_request(message))
|
||||||
|
{
|
||||||
|
wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
|
||||||
|
}
|
||||||
|
|
||||||
json_decref(message);
|
json_decref(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,11 @@ static void response_parse_str(
|
|||||||
struct wf_impl_jsonrpc_response * response)
|
struct wf_impl_jsonrpc_response * response)
|
||||||
{
|
{
|
||||||
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
|
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
|
||||||
wf_impl_jsonrpc_response_init(response, message);
|
if (nullptr != message)
|
||||||
json_decref(message);
|
{
|
||||||
|
wf_impl_jsonrpc_response_init(response, message);
|
||||||
|
json_decref(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(response_parser, test)
|
TEST(response_parser, test)
|
||||||
|
Loading…
Reference in New Issue
Block a user