2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/request.h"
|
2020-07-08 19:29:18 +00:00
|
|
|
#include "webfuse_provider/impl/operation/error.h"
|
|
|
|
#include "webfuse_provider/impl/message_writer.h"
|
2019-02-24 19:06:16 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
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));
|
2020-03-21 20:22:22 +00:00
|
|
|
request->respond = prototype->respond;
|
|
|
|
request->user_data = prototype->user_data;
|
2020-07-08 19:29:18 +00:00
|
|
|
request->writer = wfp_impl_message_writer_create(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
|
|
|
{
|
2020-07-08 19:29:18 +00:00
|
|
|
wfp_impl_message_writer_dispose(request->writer);
|
2019-02-24 19:06:16 +00:00
|
|
|
free(request);
|
2019-03-03 11:48:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 19:29:18 +00:00
|
|
|
struct wfp_message_writer *
|
|
|
|
wfp_impl_request_get_writer(
|
|
|
|
struct wfp_request * request)
|
2019-03-03 11:48:58 +00:00
|
|
|
{
|
2020-07-08 19:29:18 +00:00
|
|
|
return request->writer;
|
|
|
|
}
|
|
|
|
|
2019-03-03 11:48:58 +00:00
|
|
|
|
2020-07-08 19:29:18 +00:00
|
|
|
extern void wfp_impl_respond(
|
|
|
|
struct wfp_request * request)
|
|
|
|
{
|
|
|
|
struct wfp_message * response = wfp_impl_message_writer_take_message(request->writer);
|
2019-03-03 11:48:58 +00:00
|
|
|
request->respond(response, request->user_data);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
wfp_impl_request_dispose(request);
|
2019-03-03 11:48:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wfp_impl_respond_error(
|
|
|
|
struct wfp_request * request,
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_status status)
|
2019-03-03 11:48:58 +00:00
|
|
|
{
|
2020-07-08 19:29:18 +00:00
|
|
|
wfp_impl_message_writer_set_error(request->writer, status);
|
|
|
|
wfp_impl_respond(request);
|
2019-02-24 19:06:16 +00:00
|
|
|
}
|