2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
2019-02-09 02:08:02 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
json_t * wf_impl_jsonrpc_request_create(
|
2019-02-09 02:08:02 +00:00
|
|
|
char const * method,
|
|
|
|
int id,
|
|
|
|
char const * param_info,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
json_t * request = json_object();
|
|
|
|
json_object_set_new(request, "method", json_string(method));
|
|
|
|
json_t * params = json_array();
|
|
|
|
|
|
|
|
for (char const * param_type = param_info; '\0' != *param_type; param_type++)
|
|
|
|
{
|
|
|
|
switch(*param_type)
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
char const * const value = va_arg(args, char const *);
|
|
|
|
json_array_append_new(params, json_string(value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
{
|
|
|
|
int const value = va_arg(args, int);
|
|
|
|
json_array_append_new(params, json_integer(value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "fatal: unknown param_type '%c'\n", *param_type);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
json_object_set_new(request, "params", params);
|
2019-02-09 11:01:58 +00:00
|
|
|
if (0 != id)
|
|
|
|
{
|
|
|
|
json_object_set_new(request, "id", json_integer(id));
|
|
|
|
}
|
|
|
|
|
2019-02-09 02:08:02 +00:00
|
|
|
return request;
|
|
|
|
}
|