1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/lib/webfuse/provider/impl/request.c

52 lines
1.3 KiB
C
Raw Normal View History

2019-03-26 22:04:53 +00:00
#include "webfuse/provider/impl/request.h"
2019-02-24 19:06:16 +00:00
#include <stdlib.h>
2019-03-26 22:04:53 +00:00
#include "webfuse/provider/impl/operation/error.h"
2019-02-24 19:06:16 +00:00
2019-03-26 22:04:53 +00:00
struct wfp_request * wfp_impl_request_create(
struct wfp_request * prototype,
2019-02-24 19:06:16 +00:00
int id)
{
2019-03-26 22:04:53 +00:00
struct wfp_request * request = malloc(sizeof(struct wfp_request));
request->respond = prototype->respond;
request->user_data = prototype->user_data;
request->id = id;
2019-02-24 19:06:16 +00:00
return request;
}
2019-03-26 22:04:53 +00:00
void wfp_impl_request_dispose(
struct wfp_request * request)
2019-02-24 19:06:16 +00:00
{
free(request);
}
2019-03-26 22:04:53 +00:00
extern void wfp_impl_respond(
struct wfp_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->respond(response, request->user_data);
json_decref(response);
2019-03-26 22:04:53 +00:00
wfp_impl_request_dispose(request);
}
2019-03-26 22:04:53 +00:00
void wfp_impl_respond_error(
struct wfp_request * request,
wf_status status)
{
json_t * response = json_object();
json_t * error = json_object();
json_object_set_new(error, "code", json_integer(status));
json_object_set_new(response, "error", error);
json_object_set_new(response, "id", json_integer(request->id));
request->respond(response, request->user_data);
json_decref(response);
2019-03-26 22:04:53 +00:00
wfp_impl_request_dispose(request);
2019-02-24 19:06:16 +00:00
}