1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

removed jansson from implementation code

This commit is contained in:
Falk Werner 2020-07-16 22:36:12 +02:00
parent 2a0ac6d2dd
commit 6c522b3072
38 changed files with 262 additions and 183 deletions

View File

@ -9,6 +9,8 @@
#include "webfuse/impl/timer/manager.h" #include "webfuse/impl/timer/manager.h"
#include "webfuse/impl/jsonrpc/response.h" #include "webfuse/impl/jsonrpc/response.h"
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/doc.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/message.h" #include "webfuse/impl/message.h"
#include "webfuse/impl/message_queue.h" #include "webfuse/impl/message_queue.h"
@ -30,26 +32,26 @@ struct wf_impl_client_protocol_add_filesystem_context
static void static void
wf_impl_client_protocol_process( wf_impl_client_protocol_process(
struct wf_client_protocol * protocol, struct wf_client_protocol * protocol,
char const * data, char * data,
size_t length) size_t length)
{ {
struct wf_json_doc * doc = wf_impl_json_doc_loadb(data, length);
json_t * message = json_loadb(data, length, 0, NULL); if (NULL != doc)
if (NULL != message)
{ {
struct wf_json const * message = wf_impl_json_doc_root(doc);
if (wf_impl_jsonrpc_is_response(message)) if (wf_impl_jsonrpc_is_response(message))
{ {
wf_impl_jsonrpc_proxy_onresult(protocol->proxy, message); wf_impl_jsonrpc_proxy_onresult(protocol->proxy, message);
} }
json_decref(message); wf_impl_json_doc_dispose(doc);
} }
} }
static void static void
wf_impl_client_protocol_receive( wf_impl_client_protocol_receive(
struct wf_client_protocol * protocol, struct wf_client_protocol * protocol,
char const * data, char * data,
size_t length, size_t length,
bool is_final_fragment) bool is_final_fragment)
{ {
@ -101,7 +103,7 @@ wf_impl_client_protocol_send(
static void static void
wf_impl_client_protocol_on_authenticate_finished( wf_impl_client_protocol_on_authenticate_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error)) struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error))
{ {
struct wf_client_protocol * protocol = user_data; struct wf_client_protocol * protocol = user_data;
@ -113,7 +115,7 @@ wf_impl_client_protocol_on_authenticate_finished(
static void static void
wf_impl_client_protocol_on_add_filesystem_finished( wf_impl_client_protocol_on_add_filesystem_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error)) struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error))
{ {
struct wf_impl_client_protocol_add_filesystem_context * context = user_data; struct wf_impl_client_protocol_add_filesystem_context * context = user_data;
@ -122,10 +124,10 @@ wf_impl_client_protocol_on_add_filesystem_finished(
int reason = WF_CLIENT_FILESYSTEM_ADD_FAILED; int reason = WF_CLIENT_FILESYSTEM_ADD_FAILED;
if (NULL == protocol->filesystem) if (NULL == protocol->filesystem)
{ {
json_t * id = json_object_get(result, "id"); struct wf_json const * id = wf_impl_json_object_get(result, "id");
if (json_is_string(id)) if (WF_JSON_TYPE_STRING == wf_impl_json_type(id))
{ {
char const * name = json_string_value(id); char const * name = wf_impl_json_string_get(id);
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(context->local_path); struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(context->local_path);
protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint); protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint);
if (NULL != protocol->filesystem) if (NULL != protocol->filesystem)

View File

@ -1,29 +1,51 @@
#include "webfuse/impl/credentials.h" #include "webfuse/impl/credentials.h"
#include "webfuse/impl/json/writer.h" #include "webfuse/impl/json/writer.h"
#include "webfuse/impl/json/node.h"
#include <stdlib.h>
#include <string.h> #include <string.h>
#define WF_CREDENTIALS_INITIAL_CAPACITY 2
void wf_impl_credentials_init_default( void wf_impl_credentials_init_default(
struct wf_credentials * credentials) struct wf_credentials * credentials)
{ {
credentials->type = NULL; credentials->type = NULL;
credentials->data = json_object(); credentials->capacity = WF_CREDENTIALS_INITIAL_CAPACITY;
credentials->entries = malloc(sizeof(struct wf_credentials_entry) * credentials->capacity);
credentials->size = 0;
} }
void wf_impl_credentials_init( void wf_impl_credentials_init(
struct wf_credentials * credentials, struct wf_credentials * credentials,
char const * type, char const * type,
json_t * data) struct wf_json const * data)
{ {
size_t count = wf_impl_json_object_size(data);
credentials->type = strdup(type); credentials->type = strdup(type);
credentials->data = data; credentials->capacity = (count > 0) ? count : WF_CREDENTIALS_INITIAL_CAPACITY;
json_incref(credentials->data); credentials->entries = malloc(sizeof(struct wf_credentials_entry) * credentials->capacity);
credentials->size = 0;
for (size_t i; i < count; i++)
{
char const * key = wf_impl_json_object_key(data, i);
struct wf_json const * value = wf_impl_json_object_value(data, i);
wf_impl_credentials_add(credentials, key, wf_impl_json_string_get(value));
}
} }
void wf_impl_credentials_cleanup( void wf_impl_credentials_cleanup(
struct wf_credentials * credentials) struct wf_credentials * credentials)
{ {
for (size_t i = 0; i < credentials->size; i++)
{
free(credentials->entries[i].key);
free(credentials->entries[i].value);
}
free(credentials->entries);
free(credentials->type); free(credentials->type);
json_decref(credentials->data);
} }
char const * wf_impl_credentials_type( char const * wf_impl_credentials_type(
@ -36,15 +58,15 @@ char const * wf_impl_credentials_get(
struct wf_credentials const * credentials, struct wf_credentials const * credentials,
char const * key) char const * key)
{ {
char const * result = NULL; for (size_t i = 0; i < credentials->size; i++)
json_t * value_holder = json_object_get(credentials->data, key);
if (json_is_string(value_holder))
{ {
result = json_string_value(value_holder); if (0 == strcmp(key, credentials->entries[i].key))
{
return credentials->entries[i].value;
}
} }
return result; return NULL;
} }
void wf_impl_credentials_set_type( void wf_impl_credentials_set_type(
@ -60,7 +82,15 @@ void wf_impl_credentials_add(
char const * key, char const * key,
char const * value) char const * value)
{ {
json_object_set_new(credentials->data, key, json_string(value)); if (credentials->size >= credentials->capacity)
{
credentials->capacity *= 2;
credentials->entries = realloc(credentials->entries, credentials->capacity);
}
credentials->entries[credentials->size].key = strdup(key);
credentials->entries[credentials->size].value = strdup(value);
credentials->size++;
} }
void void
@ -69,13 +99,14 @@ wf_impl_credentials_write(
void * data) void * data)
{ {
struct wf_credentials * credentials = data; struct wf_credentials * credentials = data;
char const * key;
json_t * value;
wf_impl_json_write_object_begin(writer); wf_impl_json_write_object_begin(writer);
json_object_foreach(credentials->data, key, value) for (size_t i = 0; i < credentials->size; i++)
{ {
wf_impl_json_write_object_string(writer, key, json_string_value(value)); char const * key = credentials->entries[i].key;
char const * value = credentials->entries[i].value;
wf_impl_json_write_object_string(writer, key, value);
} }
wf_impl_json_write_object_end(writer); wf_impl_json_write_object_end(writer);
} }

View File

@ -1,7 +1,11 @@
#ifndef WF_ADAPTER_IMPL_CREDENTIALS_H #ifndef WF_ADAPTER_IMPL_CREDENTIALS_H
#define WF_ADAPTER_IMPL_CREDENTIALS_H #define WF_ADAPTER_IMPL_CREDENTIALS_H
#include <jansson.h> #ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -9,17 +13,26 @@ extern "C"
#endif #endif
struct wf_json_writer; struct wf_json_writer;
struct wf_json;
struct wf_credentials_entry
{
char * key;
char * value;
};
struct wf_credentials struct wf_credentials
{ {
char * type; char * type;
json_t * data; struct wf_credentials_entry * entries;
size_t capacity;
size_t size;
}; };
extern void wf_impl_credentials_init( extern void wf_impl_credentials_init(
struct wf_credentials * credentials, struct wf_credentials * credentials,
char const * type, char const * type,
json_t * data); struct wf_json const * data);
extern void wf_impl_credentials_init_default( extern void wf_impl_credentials_init_default(
struct wf_credentials * credentials); struct wf_credentials * credentials);

View File

@ -34,9 +34,17 @@ char const *
wf_impl_json_string_get( wf_impl_json_string_get(
struct wf_json const * json) struct wf_json const * json)
{ {
return (WF_JSON_TYPE_STRING == json->type) ? json->value.s : ""; return (WF_JSON_TYPE_STRING == json->type) ? json->value.s.data : "";
} }
size_t
wf_impl_json_string_size(
struct wf_json const * json)
{
return (WF_JSON_TYPE_STRING == json->type) ? json->value.s.size : 0;
}
struct wf_json const * struct wf_json const *
wf_impl_json_array_get( wf_impl_json_array_get(
struct wf_json const * json, struct wf_json const * json,

View File

@ -42,6 +42,10 @@ extern char const *
wf_impl_json_string_get( wf_impl_json_string_get(
struct wf_json const * json); struct wf_json const * json);
extern size_t
wf_impl_json_string_size(
struct wf_json const * json);
extern struct wf_json const * extern struct wf_json const *
wf_impl_json_array_get( wf_impl_json_array_get(
struct wf_json const * json, struct wf_json const * json,

View File

@ -8,6 +8,12 @@ extern "C"
{ {
#endif #endif
struct wf_json_string
{
char * data;
size_t size;
};
struct wf_json_array struct wf_json_array
{ {
struct wf_json * items; struct wf_json * items;
@ -26,7 +32,7 @@ union wf_json_value
{ {
bool b; bool b;
int i; int i;
char * s; struct wf_json_string s;
struct wf_json_array a; struct wf_json_array a;
struct wf_json_object o; struct wf_json_object o;
}; };

View File

@ -161,11 +161,13 @@ wf_impl_json_parse_string(
struct wf_json * json) struct wf_json * json)
{ {
char * value; char * value;
bool const result = wf_impl_json_reader_read_string(reader, &value); size_t size;
bool const result = wf_impl_json_reader_read_string(reader, &value, &size);
if (result) if (result)
{ {
json->type = WF_JSON_TYPE_STRING; json->type = WF_JSON_TYPE_STRING;
json->value.s = value; json->value.s.data = value;
json->value.s.size = size;
} }
return result; return result;
@ -254,7 +256,8 @@ wf_impl_json_parse_object(
} }
struct wf_json_object_item * item = &(json->value.o.items[json->value.o.size]); struct wf_json_object_item * item = &(json->value.o.items[json->value.o.size]);
result = wf_impl_json_reader_read_string(reader, &(item->key)); size_t key_size;
result = wf_impl_json_reader_read_string(reader, &(item->key), &key_size);
if (result) if (result)
{ {
wf_impl_json_reader_skip_whitespace(reader); wf_impl_json_reader_skip_whitespace(reader);

View File

@ -117,14 +117,15 @@ wf_impl_json_reader_read_int(
bool bool
wf_impl_json_reader_read_string( wf_impl_json_reader_read_string(
struct wf_json_reader * reader, struct wf_json_reader * reader,
char * * value) char * * value,
size_t * size)
{ {
wf_impl_json_reader_skip_whitespace(reader); wf_impl_json_reader_skip_whitespace(reader);
char c = wf_impl_json_reader_get_char(reader); char c = wf_impl_json_reader_get_char(reader);
if ('\"' != c) { return false; } if ('\"' != c) { return false; }
size_t start = reader->pos;
size_t p = reader->pos; size_t p = reader->pos;
*value = &(reader->contents[p]);
c = wf_impl_json_reader_get_char(reader); c = wf_impl_json_reader_get_char(reader);
while (('\"' != c) && ('\0' != c)) while (('\"' != c) && ('\0' != c))
{ {
@ -142,7 +143,6 @@ wf_impl_json_reader_read_string(
} }
else else
{ {
*value = NULL;
return false; return false;
} }
} }
@ -154,6 +154,8 @@ wf_impl_json_reader_read_string(
if (result) if (result)
{ {
reader->contents[p] = '\0'; reader->contents[p] = '\0';
*value = &(reader->contents[start]);
*size = p - start;
} }
return result; return result;

View File

@ -56,7 +56,8 @@ wf_impl_json_reader_read_int(
extern bool extern bool
wf_impl_json_reader_read_string( wf_impl_json_reader_read_string(
struct wf_json_reader * reader, struct wf_json_reader * reader,
char * * value); char * * value,
size_t * size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,7 +1,6 @@
#ifndef WF_IMPL_JSONRPC_ERROR_H #ifndef WF_IMPL_JSONRPC_ERROR_H
#define WF_IMPL_JSONRPC_ERROR_H #define WF_IMPL_JSONRPC_ERROR_H
#include <jansson.h>
#include "webfuse/impl/jsonrpc/proxy_finished_fn.h" #include "webfuse/impl/jsonrpc/proxy_finished_fn.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,19 +1,18 @@
#ifndef WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H #ifndef WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H
#define WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H #define WF_IMPL_JSONRPC_METHOD_INVOKE_FN_H
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wf_jsonrpc_request; struct wf_jsonrpc_request;
struct wf_json;
typedef void wf_jsonrpc_method_invoke_fn( typedef void wf_jsonrpc_method_invoke_fn(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
char const * method_name, char const * method_name,
json_t * params, struct wf_json const * params,
void * user_data); void * user_data);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -143,7 +143,7 @@ extern void wf_impl_jsonrpc_proxy_vnotify(
void wf_impl_jsonrpc_proxy_onresult( void wf_impl_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
json_t * message) struct wf_json const * message)
{ {
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_impl_jsonrpc_response_init(&response, message); wf_impl_jsonrpc_response_init(&response, message);

View File

@ -11,7 +11,6 @@
using std::size_t; using std::size_t;
#endif #endif
#include <jansson.h>
#include "webfuse/impl/jsonrpc/send_fn.h" #include "webfuse/impl/jsonrpc/send_fn.h"
#include "webfuse/impl/jsonrpc/proxy_finished_fn.h" #include "webfuse/impl/jsonrpc/proxy_finished_fn.h"
@ -22,6 +21,7 @@ extern "C" {
struct wf_jsonrpc_proxy; struct wf_jsonrpc_proxy;
struct wf_timer_manager; struct wf_timer_manager;
struct wf_json_writer; struct wf_json_writer;
struct wf_json;
typedef void typedef void
wf_jsonrpc_custom_write_fn( wf_jsonrpc_custom_write_fn(
@ -70,7 +70,7 @@ extern void wf_impl_jsonrpc_proxy_notify(
extern void wf_impl_jsonrpc_proxy_onresult( extern void wf_impl_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
json_t * message); struct wf_json const * message);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,18 +1,17 @@
#ifndef WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H #ifndef WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H
#define WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H #define WF_IMPL_JSONRPC_PROXY_FINISHED_FN_H
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
typedef void wf_jsonrpc_proxy_finished_fn( typedef void wf_jsonrpc_proxy_finished_fn(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,6 +1,7 @@
#include "webfuse/impl/jsonrpc/request.h" #include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/error.h" #include "webfuse/impl/jsonrpc/error.h"
#include "webfuse/impl/json/writer.h" #include "webfuse/impl/json/writer.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/jsonrpc/response_writer.h" #include "webfuse/impl/jsonrpc/response_writer.h"
#include "webfuse/impl/message.h" #include "webfuse/impl/message.h"
@ -17,14 +18,14 @@ struct wf_jsonrpc_request
bool bool
wf_impl_jsonrpc_is_request( wf_impl_jsonrpc_is_request(
json_t * message) struct wf_json const * message)
{ {
json_t * id = json_object_get(message, "id"); struct wf_json const * id = wf_impl_json_object_get(message, "id");
json_t * method = json_object_get(message, "method"); struct wf_json const * method = wf_impl_json_object_get(message, "method");
json_t * params = json_object_get(message, "params"); struct wf_json const * params = wf_impl_json_object_get(message, "params");
return (json_is_integer(id) && json_is_string(method) && return ( (WF_JSON_TYPE_INT == wf_impl_json_type(id)) && (WF_JSON_TYPE_STRING == wf_impl_json_type(method)) &&
(json_is_array(params) || json_is_object(params))); ( (WF_JSON_TYPE_ARRAY == wf_impl_json_type(params)) || (WF_JSON_TYPE_OBJECT == wf_impl_json_type(params)) ));
} }

View File

@ -11,7 +11,6 @@
using std::size_t; using std::size_t;
#endif #endif
#include <jansson.h>
#include "webfuse/impl/jsonrpc/send_fn.h" #include "webfuse/impl/jsonrpc/send_fn.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -21,9 +20,10 @@ extern "C"
struct wf_jsonrpc_request; struct wf_jsonrpc_request;
struct wf_jsonrpc_response_writer; struct wf_jsonrpc_response_writer;
struct wf_json;
extern bool wf_impl_jsonrpc_is_request( extern bool wf_impl_jsonrpc_is_request(
json_t * message); struct wf_json const * message);
extern struct wf_jsonrpc_request * extern struct wf_jsonrpc_request *
wf_impl_jsonrpc_request_create( wf_impl_jsonrpc_request_create(

View File

@ -1,54 +1,51 @@
#include "webfuse/impl/jsonrpc/response_intern.h" #include "webfuse/impl/jsonrpc/response_intern.h"
#include "webfuse/impl/jsonrpc/error.h" #include "webfuse/impl/jsonrpc/error.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/status.h" #include "webfuse/status.h"
bool bool
wf_impl_jsonrpc_is_response( wf_impl_jsonrpc_is_response(
json_t * message) struct wf_json const * message)
{ {
json_t * id = json_object_get(message, "id"); struct wf_json const * id = wf_impl_json_object_get(message, "id");
json_t * err = json_object_get(message, "error"); struct wf_json const * err = wf_impl_json_object_get(message, "error");
json_t * result = json_object_get(message, "result"); struct wf_json const * result = wf_impl_json_object_get(message, "result");
return (json_is_integer(id) && return ((WF_JSON_TYPE_INT == wf_impl_json_type(id)) &&
(json_is_object(err) || (NULL != result))); ((WF_JSON_TYPE_OBJECT == wf_impl_json_type(err)) || (WF_JSON_TYPE_UNDEFINED != wf_impl_json_type(result))));
} }
void void
wf_impl_jsonrpc_response_init( wf_impl_jsonrpc_response_init(
struct wf_jsonrpc_response * result, struct wf_jsonrpc_response * result,
json_t * response) struct wf_json const * response)
{ {
result->id = -1; result->id = -1;
result->result = NULL; result->result = NULL;
result->error = NULL; result->error = NULL;
json_t * id_holder = json_object_get(response, "id"); struct wf_json const * id_holder = wf_impl_json_object_get(response, "id");
if (!json_is_integer(id_holder)) if (WF_JSON_TYPE_INT != wf_impl_json_type(id_holder))
{ {
result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id"); result->error = wf_impl_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
return; return;
} }
result->id = json_integer_value(id_holder); result->id = wf_impl_json_int_get(id_holder);
result->result = json_object_get(response, "result"); result->result = wf_impl_json_object_get(response, "result");
if (NULL != result->result) if (WF_JSON_TYPE_UNDEFINED == wf_impl_json_type(result->result))
{
json_incref(result->result);
}
else
{ {
int code = WF_BAD_FORMAT; int code = WF_BAD_FORMAT;
char const * message = "invalid format: invalid error object"; char const * message = "invalid format: invalid error object";
json_t * error = json_object_get(response, "error"); struct wf_json const * error = wf_impl_json_object_get(response, "error");
json_t * code_holder = json_object_get(error, "code"); struct wf_json const * code_holder = wf_impl_json_object_get(error, "code");
if (json_is_integer(code_holder)) if (WF_JSON_TYPE_INT == wf_impl_json_type(code_holder))
{ {
code = json_integer_value(json_object_get(error, "code")); code = wf_impl_json_int_get(code_holder);
json_t * message_holder = json_object_get(error, "message"); struct wf_json const * message_holder = wf_impl_json_object_get(error, "message");
message = json_is_string(message_holder) ? json_string_value(message_holder) : ""; message = wf_impl_json_string_get(message_holder);
} }
result->error = wf_impl_jsonrpc_error(code, message); result->error = wf_impl_jsonrpc_error(code, message);
@ -59,10 +56,5 @@ void
wf_impl_jsonrpc_response_cleanup( wf_impl_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response) struct wf_jsonrpc_response * response)
{ {
if (NULL != response->result)
{
json_decref(response->result);
}
wf_impl_jsonrpc_error_dispose(response->error); wf_impl_jsonrpc_error_dispose(response->error);
} }

View File

@ -5,15 +5,15 @@
#include <stdbool.h> #include <stdbool.h>
#endif #endif
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wf_json;
extern bool wf_impl_jsonrpc_is_response( extern bool wf_impl_jsonrpc_is_response(
json_t * message); struct wf_json const * message);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -15,17 +15,18 @@ extern "C" {
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
struct wf_jsonrpc_response struct wf_jsonrpc_response
{ {
json_t * result; struct wf_json const * result;
struct wf_jsonrpc_error * error; struct wf_jsonrpc_error * error;
int id; int id;
}; };
extern void wf_impl_jsonrpc_response_init( extern void wf_impl_jsonrpc_response_init(
struct wf_jsonrpc_response * response, struct wf_jsonrpc_response * response,
json_t * message); struct wf_json const * message);
extern void wf_impl_jsonrpc_response_cleanup( extern void wf_impl_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response); struct wf_jsonrpc_response * response);

View File

@ -1,6 +1,7 @@
#include "webfuse/impl/jsonrpc/server.h" #include "webfuse/impl/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/method.h" #include "webfuse/impl/jsonrpc/method.h"
#include "webfuse/impl/jsonrpc/request.h" #include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/status.h" #include "webfuse/status.h"
#include "webfuse/impl/util/util.h" #include "webfuse/impl/util/util.h"
@ -70,7 +71,7 @@ void wf_impl_jsonrpc_server_add(
static void wf_impl_jsonrpc_server_invalid_method_invoke( static void wf_impl_jsonrpc_server_invalid_method_invoke(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name), char const * WF_UNUSED_PARAM(method_name),
json_t * WF_UNUSED_PARAM(params), struct wf_json const * WF_UNUSED_PARAM(params),
void * WF_UNUSED_PARAM(user_data)) void * WF_UNUSED_PARAM(user_data))
{ {
wf_impl_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented"); wf_impl_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented");
@ -105,20 +106,20 @@ wf_impl_jsonrpc_server_get_method(
void wf_impl_jsonrpc_server_process( void wf_impl_jsonrpc_server_process(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
json_t * request_data, struct wf_json const * request_data,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data) void * user_data)
{ {
json_t * method_holder = json_object_get(request_data, "method"); struct wf_json const * method_holder = wf_impl_json_object_get(request_data, "method");
json_t * params = json_object_get(request_data, "params"); struct wf_json const * params = wf_impl_json_object_get(request_data, "params");
json_t * id_holder = json_object_get(request_data, "id"); struct wf_json const * id_holder = wf_impl_json_object_get(request_data, "id");
if (json_is_string(method_holder) && if ((WF_JSON_TYPE_STRING == wf_impl_json_type(method_holder)) &&
(json_is_array(params) || (json_is_object(params))) && ((WF_JSON_TYPE_ARRAY == wf_impl_json_type(params)) || (WF_JSON_TYPE_OBJECT == wf_impl_json_type(params))) &&
json_is_integer(id_holder)) (WF_JSON_TYPE_INT == wf_impl_json_type(id_holder)))
{ {
char const * method_name = json_string_value(method_holder); char const * method_name = wf_impl_json_string_get(method_holder);
int id = json_integer_value(id_holder); int id = wf_impl_json_int_get(id_holder);
struct wf_jsonrpc_request * request = wf_impl_jsonrpc_request_create(id, send, user_data); struct wf_jsonrpc_request * request = wf_impl_jsonrpc_request_create(id, send, user_data);
struct wf_jsonrpc_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name); struct wf_jsonrpc_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name);

View File

@ -8,7 +8,6 @@
#include <cstdarg> #include <cstdarg>
#endif #endif
#include <jansson.h>
#include "webfuse/impl/jsonrpc/method_invoke_fn.h" #include "webfuse/impl/jsonrpc/method_invoke_fn.h"
#include "webfuse/impl/jsonrpc/send_fn.h" #include "webfuse/impl/jsonrpc/send_fn.h"
@ -18,6 +17,7 @@ extern "C"
#endif #endif
struct wf_jsonrpc_server; struct wf_jsonrpc_server;
struct wf_json;
extern struct wf_jsonrpc_server * extern struct wf_jsonrpc_server *
wf_impl_jsonrpc_server_create(void); wf_impl_jsonrpc_server_create(void);
@ -34,7 +34,7 @@ extern void wf_impl_jsonrpc_server_add(
extern void wf_impl_jsonrpc_server_process( extern void wf_impl_jsonrpc_server_process(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
json_t * request, struct wf_json const * request,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data); void * user_data);

View File

@ -3,7 +3,6 @@
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include <jansson.h>
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"

View File

@ -3,6 +3,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -11,10 +12,11 @@
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
#include "webfuse/impl/util/util.h" #include "webfuse/impl/util/util.h"
#include "webfuse/impl/json/node.h"
void wf_impl_operation_getattr_finished( void wf_impl_operation_getattr_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error) struct wf_jsonrpc_error const * error)
{ {
wf_status status = wf_impl_jsonrpc_get_status(error); wf_status status = wf_impl_jsonrpc_get_status(error);
@ -23,15 +25,15 @@ void wf_impl_operation_getattr_finished(
struct stat buffer; struct stat buffer;
if (NULL != result) if (NULL != result)
{ {
json_t * mode_holder = json_object_get(result, "mode"); struct wf_json const * mode_holder = wf_impl_json_object_get(result, "mode");
json_t * type_holder = json_object_get(result, "type"); struct wf_json const * type_holder = wf_impl_json_object_get(result, "type");
if ((json_is_integer(mode_holder)) && (json_is_string(type_holder))) if ((WF_JSON_TYPE_INT == wf_impl_json_type(mode_holder)) && (WF_JSON_TYPE_STRING == wf_impl_json_type(type_holder)))
{ {
memset(&buffer, 0, sizeof(struct stat)); memset(&buffer, 0, sizeof(struct stat));
buffer.st_ino = context->inode; buffer.st_ino = context->inode;
buffer.st_mode = json_integer_value(mode_holder) & 0555; buffer.st_mode = wf_impl_json_int_get(mode_holder) & 0555;
char const * type = json_string_value(type_holder); char const * type = wf_impl_json_string_get(type_holder);
if (0 == strcmp("file", type)) if (0 == strcmp("file", type))
{ {
buffer.st_mode |= S_IFREG; buffer.st_mode |= S_IFREG;

View File

@ -3,7 +3,6 @@
#include "webfuse/impl/fuse_wrapper.h" #include "webfuse/impl/fuse_wrapper.h"
#include <jansson.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -12,6 +11,7 @@ extern "C"
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
struct wf_impl_operation_getattr_context struct wf_impl_operation_getattr_context
{ {
@ -24,7 +24,7 @@ struct wf_impl_operation_getattr_context
extern void wf_impl_operation_getattr_finished( extern void wf_impl_operation_getattr_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);
extern void wf_impl_operation_getattr ( extern void wf_impl_operation_getattr (

View File

@ -12,12 +12,13 @@
#include <stdlib.h> #include <stdlib.h>
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
#include "webfuse/impl/util/util.h" #include "webfuse/impl/util/util.h"
void wf_impl_operation_lookup_finished( void wf_impl_operation_lookup_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error struct wf_jsonrpc_error const * error
) )
{ {
@ -27,19 +28,19 @@ void wf_impl_operation_lookup_finished(
if (NULL != result) if (NULL != result)
{ {
json_t * inode_holder = json_object_get(result, "inode"); struct wf_json const * inode_holder = wf_impl_json_object_get(result, "inode");
json_t * mode_holder = json_object_get(result, "mode"); struct wf_json const * mode_holder = wf_impl_json_object_get(result, "mode");
json_t * type_holder = json_object_get(result, "type"); struct wf_json const * type_holder = wf_impl_json_object_get(result, "type");
if ((json_is_integer(inode_holder)) && if ((WF_JSON_TYPE_INT == wf_impl_json_type(inode_holder)) &&
(json_is_integer(mode_holder)) && (WF_JSON_TYPE_INT == wf_impl_json_type(mode_holder)) &&
(json_is_string(type_holder))) (WF_JSON_TYPE_INT == wf_impl_json_type(type_holder)))
{ {
memset(&buffer, 0, sizeof(struct stat)); memset(&buffer, 0, sizeof(struct stat));
buffer.ino = json_integer_value(inode_holder); buffer.ino = wf_impl_json_int_get(inode_holder);
buffer.attr.st_ino = buffer.ino; buffer.attr.st_ino = buffer.ino;
buffer.attr.st_mode = json_integer_value(mode_holder) & 0555; buffer.attr.st_mode = wf_impl_json_int_get(mode_holder) & 0555;
char const * type = json_string_value(type_holder); char const * type = wf_impl_json_string_get(type_holder);
if (0 == strcmp("file", type)) if (0 == strcmp("file", type))
{ {
buffer.attr.st_mode |= S_IFREG; buffer.attr.st_mode |= S_IFREG;

View File

@ -3,7 +3,6 @@
#include "webfuse/impl/fuse_wrapper.h" #include "webfuse/impl/fuse_wrapper.h"
#include <jansson.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -12,6 +11,7 @@ extern "C"
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
struct wf_impl_operation_lookup_context struct wf_impl_operation_lookup_context
{ {
@ -23,7 +23,7 @@ struct wf_impl_operation_lookup_context
extern void wf_impl_operation_lookup_finished( extern void wf_impl_operation_lookup_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);
extern void wf_impl_operation_lookup ( extern void wf_impl_operation_lookup (

View File

@ -2,6 +2,7 @@
#include "webfuse/impl/operation/context.h" #include "webfuse/impl/operation/context.h"
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/util.h" #include "webfuse/impl/util/util.h"
#include "webfuse/status.h" #include "webfuse/status.h"
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
@ -11,7 +12,7 @@
void wf_impl_operation_open_finished( void wf_impl_operation_open_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error) struct wf_jsonrpc_error const * error)
{ {
wf_status status = wf_impl_jsonrpc_get_status(error); wf_status status = wf_impl_jsonrpc_get_status(error);
@ -21,10 +22,10 @@ void wf_impl_operation_open_finished(
if (NULL != result) if (NULL != result)
{ {
json_t * handle_holder = json_object_get(result, "handle"); struct wf_json const * handle_holder = wf_impl_json_object_get(result, "handle");
if (json_is_integer(handle_holder)) if (WF_JSON_TYPE_INT == wf_impl_json_type(handle_holder))
{ {
file_info.fh = json_integer_value(handle_holder); file_info.fh = wf_impl_json_int_get(handle_holder);
} }
else else
{ {

View File

@ -2,7 +2,6 @@
#define WF_ADAPTER_IMPL_OPERATION_OPEN_H #define WF_ADAPTER_IMPL_OPERATION_OPEN_H
#include "webfuse/impl/fuse_wrapper.h" #include "webfuse/impl/fuse_wrapper.h"
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -10,6 +9,7 @@ extern "C"
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
extern void wf_impl_operation_open( extern void wf_impl_operation_open(
fuse_req_t request, fuse_req_t request,
@ -18,7 +18,7 @@ extern void wf_impl_operation_open(
extern void wf_impl_operation_open_finished( extern void wf_impl_operation_open_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -2,11 +2,12 @@
#include "webfuse/impl/operation/context.h" #include "webfuse/impl/operation/context.h"
#include <errno.h> #include <errno.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <jansson.h>
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/base64.h" #include "webfuse/impl/util/base64.h"
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
@ -61,7 +62,7 @@ char * wf_impl_fill_buffer(
void wf_impl_operation_read_finished( void wf_impl_operation_read_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error) struct wf_jsonrpc_error const * error)
{ {
wf_status status = wf_impl_jsonrpc_get_status(error); wf_status status = wf_impl_jsonrpc_get_status(error);
@ -71,18 +72,18 @@ void wf_impl_operation_read_finished(
size_t length = 0; size_t length = 0;
if (NULL != result) if (NULL != result)
{ {
json_t * data_holder = json_object_get(result, "data"); struct wf_json const * data_holder = wf_impl_json_object_get(result, "data");
json_t * format_holder = json_object_get(result, "format"); struct wf_json const * format_holder = wf_impl_json_object_get(result, "format");
json_t * count_holder = json_object_get(result, "count"); struct wf_json const * count_holder = wf_impl_json_object_get(result, "count");
if (json_is_string(data_holder) && if ((WF_JSON_TYPE_STRING == wf_impl_json_type(data_holder)) &&
json_is_string(format_holder) && (WF_JSON_TYPE_STRING == wf_impl_json_type(format_holder)) &&
json_is_integer(count_holder)) (WF_JSON_TYPE_INT == wf_impl_json_type(count_holder)))
{ {
char const * const data = json_string_value(data_holder); char const * const data = wf_impl_json_string_get(data_holder);
size_t const data_size = json_string_length(data_holder); size_t const data_size = wf_impl_json_string_size(data_holder);
char const * const format = json_string_value(format_holder); char const * const format = wf_impl_json_string_get(format_holder);
length = (size_t) json_integer_value(count_holder); length = (size_t) wf_impl_json_int_get(count_holder);
buffer = wf_impl_fill_buffer(data, data_size, format, length, &status); buffer = wf_impl_fill_buffer(data, data_size, format, length, &status);
} }

View File

@ -4,14 +4,13 @@
#include "webfuse/impl/fuse_wrapper.h" #include "webfuse/impl/fuse_wrapper.h"
#include "webfuse/status.h" #include "webfuse/status.h"
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
extern void wf_impl_operation_read( extern void wf_impl_operation_read(
fuse_req_t request, fuse_req_t request,
@ -27,7 +26,7 @@ extern char * wf_impl_fill_buffer(
extern void wf_impl_operation_read_finished( extern void wf_impl_operation_read_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);

View File

@ -10,6 +10,7 @@
#include <unistd.h> #include <unistd.h>
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/util.h" #include "webfuse/impl/util/util.h"
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
@ -68,7 +69,7 @@ static size_t wf_impl_min(size_t a, size_t b)
void wf_impl_operation_readdir_finished( void wf_impl_operation_readdir_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error) struct wf_jsonrpc_error const * error)
{ {
wf_status status = wf_impl_jsonrpc_get_status(error); wf_status status = wf_impl_jsonrpc_get_status(error);
@ -77,21 +78,21 @@ void wf_impl_operation_readdir_finished(
struct wf_impl_dirbuffer buffer; struct wf_impl_dirbuffer buffer;
wf_impl_dirbuffer_init(&buffer); wf_impl_dirbuffer_init(&buffer);
if (json_is_array(result)) if (WF_JSON_TYPE_ARRAY == wf_impl_json_type(result))
{ {
size_t const count = json_array_size(result); size_t const count = wf_impl_json_array_size(result);
for(size_t i = 0; i < count; i++) for(size_t i = 0; i < count; i++)
{ {
json_t * entry =json_array_get(result, i); struct wf_json const * entry = wf_impl_json_array_get(result, i);
if (json_is_object(entry)) if (WF_JSON_TYPE_OBJECT == wf_impl_json_type(entry))
{ {
json_t * name_holder = json_object_get(entry, "name"); struct wf_json const * name_holder = wf_impl_json_object_get(entry, "name");
json_t * inode_holder = json_object_get(entry, "inode"); struct wf_json const * inode_holder = wf_impl_json_object_get(entry, "inode");
if ((json_is_string(name_holder)) && (json_is_integer(inode_holder))) if ((WF_JSON_TYPE_STRING == wf_impl_json_type(name_holder)) && (WF_JSON_TYPE_INT == wf_impl_json_type(inode_holder)))
{ {
char const * name = json_string_value(name_holder); char const * name = wf_impl_json_string_get(name_holder);
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); fuse_ino_t entry_inode = (fuse_ino_t) wf_impl_json_int_get(inode_holder);
wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode);
} }
else else

View File

@ -2,7 +2,6 @@
#define WF_ADAPTER_IMPL_OPERATION_READDIR_H #define WF_ADAPTER_IMPL_OPERATION_READDIR_H
#include "webfuse/impl/fuse_wrapper.h" #include "webfuse/impl/fuse_wrapper.h"
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -10,6 +9,7 @@ extern "C"
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
struct wf_impl_operation_readdir_context struct wf_impl_operation_readdir_context
{ {
@ -27,7 +27,7 @@ extern void wf_impl_operation_readdir (
extern void wf_impl_operation_readdir_finished( extern void wf_impl_operation_readdir_finished(
void * user_data, void * user_data,
json_t const * result, struct wf_json const * result,
struct wf_jsonrpc_error const * error); struct wf_jsonrpc_error const * error);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -13,6 +13,7 @@
#include "webfuse/impl/jsonrpc/request.h" #include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/response_writer.h" #include "webfuse/impl/jsonrpc/response_writer.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/timer/manager.h" #include "webfuse/impl/timer/manager.h"
#include "webfuse/impl/timer/timer.h" #include "webfuse/impl/timer/timer.h"
@ -114,17 +115,17 @@ void wf_impl_server_protocol_init_lws(
static void wf_impl_server_protocol_authenticate( static void wf_impl_server_protocol_authenticate(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name), char const * WF_UNUSED_PARAM(method_name),
json_t * params, struct wf_json const * params,
void * WF_UNUSED_PARAM(user_data)) void * WF_UNUSED_PARAM(user_data))
{ {
bool result = false; bool result = false;
json_t * type_holder = json_array_get(params, 0); struct wf_json const * type_holder = wf_impl_json_array_get(params, 0);
json_t * creds_holder = json_array_get(params, 1); struct wf_json const * creds_holder = wf_impl_json_array_get(params, 1);
if (json_is_string(type_holder) && json_is_object(creds_holder)) if ((WF_JSON_TYPE_STRING == wf_impl_json_type(type_holder)) && (WF_JSON_TYPE_OBJECT == wf_impl_json_type(creds_holder)))
{ {
char const * type = json_string_value(type_holder); char const * type = wf_impl_json_string_get(type_holder);
struct wf_credentials creds; struct wf_credentials creds;
wf_impl_credentials_init(&creds, type, creds_holder); wf_impl_credentials_init(&creds, type, creds_holder);
@ -163,7 +164,7 @@ static bool wf_impl_server_protocol_check_name(char const * value)
static void wf_impl_server_protocol_add_filesystem( static void wf_impl_server_protocol_add_filesystem(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name), char const * WF_UNUSED_PARAM(method_name),
json_t * params, struct wf_json const * params,
void * WF_UNUSED_PARAM(user_data)) void * WF_UNUSED_PARAM(user_data))
{ {
struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request); struct wf_impl_session * session = wf_impl_jsonrpc_request_get_userdata(request);
@ -172,10 +173,10 @@ static void wf_impl_server_protocol_add_filesystem(
char const * name = NULL; char const * name = NULL;
if (WF_GOOD == status) if (WF_GOOD == status)
{ {
json_t * name_holder = json_array_get(params, 0); struct wf_json const * name_holder = wf_impl_json_array_get(params, 0);
if (json_is_string(name_holder)) if (WF_JSON_TYPE_STRING == wf_impl_json_type(name_holder))
{ {
name = json_string_value(name_holder); name = wf_impl_json_string_get(name_holder);
if (wf_impl_server_protocol_check_name(name)) if (wf_impl_server_protocol_check_name(name))
{ {
bool const success = wf_impl_session_add_filesystem(session, name); bool const success = wf_impl_session_add_filesystem(session, name);
@ -206,8 +207,6 @@ static void wf_impl_server_protocol_add_filesystem(
{ {
wf_impl_jsonrpc_respond_error(request, status, wf_impl_status_tostring(status)); wf_impl_jsonrpc_respond_error(request, status, wf_impl_status_tostring(status));
} }
} }
void wf_impl_server_protocol_init( void wf_impl_server_protocol_init(

View File

@ -11,6 +11,7 @@
#include "webfuse/impl/jsonrpc/proxy.h" #include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/jsonrpc/request.h" #include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/response.h" #include "webfuse/impl/jsonrpc/response.h"
#include "webfuse/impl/json/doc.h"
#include <libwebsockets.h> #include <libwebsockets.h>
#include <stddef.h> #include <stddef.h>
@ -149,12 +150,13 @@ void wf_impl_session_onwritable(
static void wf_impl_session_process( static void wf_impl_session_process(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * data, char * data,
size_t length) size_t length)
{ {
json_t * message = json_loadb(data, length, 0, NULL); struct wf_json_doc * doc = wf_impl_json_doc_loadb(data, length);
if (NULL != message) if (NULL != doc)
{ {
struct wf_json const * message = wf_impl_json_doc_root(doc);
if (wf_impl_jsonrpc_is_response(message)) if (wf_impl_jsonrpc_is_response(message))
{ {
wf_impl_jsonrpc_proxy_onresult(session->rpc, message); wf_impl_jsonrpc_proxy_onresult(session->rpc, message);
@ -164,13 +166,13 @@ static void wf_impl_session_process(
wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session); wf_impl_jsonrpc_server_process(session->server, message, &wf_impl_session_send, session);
} }
json_decref(message); wf_impl_json_doc_dispose(doc);
} }
} }
void wf_impl_session_receive( void wf_impl_session_receive(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * data, char * data,
size_t length, size_t length,
bool is_final_fragment) bool is_final_fragment)
{ {

View File

@ -62,7 +62,7 @@ extern bool wf_impl_session_add_filesystem(
extern void wf_impl_session_receive( extern void wf_impl_session_receive(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * data, char * data,
size_t length, size_t length,
bool is_final_fragment); bool is_final_fragment);

View File

@ -1,14 +1,19 @@
#include "webfuse/impl/util/json_util.h" #include "webfuse/impl/util/json_util.h"
#include "webfuse/impl/jsonrpc/error.h" #include "webfuse/impl/jsonrpc/error.h"
#include "webfuse/impl/json/node.h"
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) int
wf_impl_json_get_int(
struct wf_json const * object,
char const * key,
int default_value)
{ {
int result = default_value; int result = default_value;
json_t * holder = json_object_get(object, key); struct wf_json const * holder = wf_impl_json_object_get(object, key);
if (json_is_integer(holder)) if (WF_JSON_TYPE_INT == wf_impl_json_type(holder))
{ {
result = json_integer_value(holder); result = wf_impl_json_int_get(holder);
} }
return result; return result;

View File

@ -1,7 +1,6 @@
#ifndef WF_IMPL_UTIL_JSON_UTIL_H #ifndef WF_IMPL_UTIL_JSON_UTIL_H
#define WF_IMPL_UTIL_JSON_UTIL_H #define WF_IMPL_UTIL_JSON_UTIL_H
#include <jansson.h>
#include "webfuse/status.h" #include "webfuse/status.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -10,10 +9,11 @@ extern "C"
#endif #endif
struct wf_jsonrpc_error; struct wf_jsonrpc_error;
struct wf_json;
extern int extern int
wf_impl_json_get_int( wf_impl_json_get_int(
json_t const * object, struct wf_json const * object,
char const * key, char const * key,
int default_value); int default_value);

View File

@ -161,8 +161,10 @@ TEST(json_reader, read_string)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size()); wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
char * value; char * value;
ASSERT_TRUE(wf_impl_json_reader_read_string(&reader, &value)); size_t size;
ASSERT_TRUE(wf_impl_json_reader_read_string(&reader, &value, &size));
ASSERT_STREQ("brummni", value); ASSERT_STREQ("brummni", value);
ASSERT_EQ(7, size);
} }
TEST(json_reader, read_string_escaped) TEST(json_reader, read_string_escaped)
@ -172,8 +174,10 @@ TEST(json_reader, read_string_escaped)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size()); wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
char * value; char * value;
ASSERT_TRUE(wf_impl_json_reader_read_string(&reader, &value)); size_t size;
ASSERT_TRUE(wf_impl_json_reader_read_string(&reader, &value, &size));
ASSERT_STREQ("_\"_\\_/_\b_\f_\n_\r_\t_", value); ASSERT_STREQ("_\"_\\_/_\b_\f_\n_\r_\t_", value);
ASSERT_EQ(17, size);
} }
TEST(json_reader, read_string_fail_missig_start_quot) TEST(json_reader, read_string_fail_missig_start_quot)
@ -183,7 +187,8 @@ TEST(json_reader, read_string_fail_missig_start_quot)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size()); wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
char * value; char * value;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value)); size_t size;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value, &size));
} }
TEST(json_reader, read_string_fail_missig_end_quot) TEST(json_reader, read_string_fail_missig_end_quot)
@ -193,7 +198,8 @@ TEST(json_reader, read_string_fail_missig_end_quot)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size()); wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
char * value; char * value;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value)); size_t size;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value, &size));
} }
TEST(json_reader, read_string_fail_invalid_escape_seq) TEST(json_reader, read_string_fail_invalid_escape_seq)
@ -203,5 +209,6 @@ TEST(json_reader, read_string_fail_invalid_escape_seq)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size()); wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
char * value; char * value;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value)); size_t size;
ASSERT_FALSE(wf_impl_json_reader_read_string(&reader, &value, &size));
} }