1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/webfuse/adapter/impl/jsonrpc/request.c
Falk Werner 87f34fa768 feat(authentication): provide an authentication mechanism (#19)
* moves server into session

* renames jsonrpc server to jsonrpc proxy

* moves server into session

* renames jsonrpc server to jsonrpc proxy

* adds json rpc server

* removes obsolete proxy from protocol

* changes interface of jsonrpc_proxy_onresult to accept previously parsed messages

* adds infrastructure to process incoming requests; fixes invalid read of ill formatted responses

* adds description of authentication request

* adds authentication request

* adds userdb for authentication purposes

* removes debug code: console.log()

* fixes cmake build error (missing openssl symbols)

* fixes typo

* replaces ASCII art by UML diagram

* renames BAD_NOACCESS to BAD_ACCESS_DENIED

* fixes style

* adds docu of authentication

* ignored false positives of flawfinder

* fixes style issues

* fixes javascript style issues
2019-04-01 22:15:12 +02:00

83 lines
2.1 KiB
C

#include "webfuse/adapter/impl/jsonrpc/request.h"
#include "webfuse/core/status_intern.h"
#include <stdlib.h>
struct wf_impl_jsonrpc_request
{
int id;
wf_impl_jsonrpc_send_fn * send;
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(
int id,
wf_impl_jsonrpc_send_fn * send,
void * user_data)
{
struct wf_impl_jsonrpc_request * request = malloc(sizeof(struct wf_impl_jsonrpc_request));
if (NULL != request)
{
request->id = id;
request->send = send;
request->user_data = user_data;
}
return request;
}
void wf_impl_jsonrpc_request_dispose(
struct wf_impl_jsonrpc_request * request)
{
free(request);
}
void * wf_impl_jsonrpc_request_get_userdata(
struct wf_impl_jsonrpc_request * request)
{
return request->user_data;
}
void wf_impl_jsonrpc_respond(
struct wf_impl_jsonrpc_request * request,
json_t * result)
{
json_t * response = json_object();
json_object_set_new(response, "result", result);
json_object_set_new(response, "id", json_integer(request->id));
request->send(response, request->user_data);
json_decref(response);
wf_impl_jsonrpc_request_dispose(request);
}
void wf_impl_jsonrpc_respond_error(
struct wf_impl_jsonrpc_request * request,
wf_status status)
{
json_t * err = json_object();
json_object_set_new(err, "code", json_integer(status));
json_object_set_new(err, "message", json_string(wf_status_tostring(status)));
json_t * response = json_object();
json_object_set_new(response, "error", err);
json_object_set_new(response, "id", json_integer(request->id));
request->send(response, request->user_data);
json_decref(response);
wf_impl_jsonrpc_request_dispose(request);
}