removed jansson from implementation code

pull/87/head
Falk Werner 4 years ago
parent 2a0ac6d2dd
commit 6c522b3072

@ -9,6 +9,8 @@
#include "webfuse/impl/timer/manager.h"
#include "webfuse/impl/jsonrpc/response.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_queue.h"
@ -30,26 +32,26 @@ struct wf_impl_client_protocol_add_filesystem_context
static void
wf_impl_client_protocol_process(
struct wf_client_protocol * protocol,
char const * data,
char * data,
size_t length)
{
json_t * message = json_loadb(data, length, 0, NULL);
if (NULL != message)
struct wf_json_doc * doc = wf_impl_json_doc_loadb(data, length);
if (NULL != doc)
{
struct wf_json const * message = wf_impl_json_doc_root(doc);
if (wf_impl_jsonrpc_is_response(message))
{
wf_impl_jsonrpc_proxy_onresult(protocol->proxy, message);
}
json_decref(message);
wf_impl_json_doc_dispose(doc);
}
}
static void
wf_impl_client_protocol_receive(
struct wf_client_protocol * protocol,
char const * data,
char * data,
size_t length,
bool is_final_fragment)
{
@ -101,7 +103,7 @@ wf_impl_client_protocol_send(
static void
wf_impl_client_protocol_on_authenticate_finished(
void * user_data,
json_t const * result,
struct wf_json const * result,
struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error))
{
struct wf_client_protocol * protocol = user_data;
@ -113,7 +115,7 @@ wf_impl_client_protocol_on_authenticate_finished(
static void
wf_impl_client_protocol_on_add_filesystem_finished(
void * user_data,
json_t const * result,
struct wf_json const * result,
struct wf_jsonrpc_error const * WF_UNUSED_PARAM(error))
{
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;
if (NULL == protocol->filesystem)
{
json_t * id = json_object_get(result, "id");
if (json_is_string(id))
struct wf_json const * id = wf_impl_json_object_get(result, "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);
protocol->filesystem = wf_impl_filesystem_create(protocol->wsi,protocol->proxy, name, mountpoint);
if (NULL != protocol->filesystem)

@ -1,29 +1,51 @@
#include "webfuse/impl/credentials.h"
#include "webfuse/impl/json/writer.h"
#include "webfuse/impl/json/node.h"
#include <stdlib.h>
#include <string.h>
#define WF_CREDENTIALS_INITIAL_CAPACITY 2
void wf_impl_credentials_init_default(
struct wf_credentials * credentials)
{
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(
struct wf_credentials * credentials,
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->data = data;
json_incref(credentials->data);
credentials->capacity = (count > 0) ? count : WF_CREDENTIALS_INITIAL_CAPACITY;
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(
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);
json_decref(credentials->data);
}
char const * wf_impl_credentials_type(
@ -36,15 +58,15 @@ char const * wf_impl_credentials_get(
struct wf_credentials const * credentials,
char const * key)
{
char const * result = NULL;
json_t * value_holder = json_object_get(credentials->data, key);
if (json_is_string(value_holder))
for (size_t i = 0; i < credentials->size; i++)
{
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(
@ -60,7 +82,15 @@ void wf_impl_credentials_add(
char const * key,
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
@ -69,13 +99,14 @@ wf_impl_credentials_write(
void * data)
{
struct wf_credentials * credentials = data;
char const * key;
json_t * value;
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);
}

@ -1,7 +1,11 @@
#ifndef 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
extern "C"
@ -9,17 +13,26 @@ extern "C"
#endif
struct wf_json_writer;
struct wf_json;
struct wf_credentials_entry
{
char * key;
char * value;
};
struct wf_credentials
{
char * type;
json_t * data;
struct wf_credentials_entry * entries;
size_t capacity;
size_t size;
};
extern void wf_impl_credentials_init(
struct wf_credentials * credentials,
char const * type,
json_t * data);
struct wf_json const * data);
extern void wf_impl_credentials_init_default(
struct wf_credentials * credentials);

@ -34,9 +34,17 @@ char const *
wf_impl_json_string_get(
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 *
wf_impl_json_array_get(
struct wf_json const * json,

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

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

@ -161,11 +161,13 @@ wf_impl_json_parse_string(
struct wf_json * json)
{
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)
{
json->type = WF_JSON_TYPE_STRING;
json->value.s = value;
json->value.s.data = value;
json->value.s.size = size;
}
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]);
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)
{
wf_impl_json_reader_skip_whitespace(reader);

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,6 +1,7 @@
#include "webfuse/impl/jsonrpc/server.h"
#include "webfuse/impl/jsonrpc/method.h"
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/status.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(
struct wf_jsonrpc_request * request,
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))
{
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(
struct wf_jsonrpc_server * server,
json_t * request_data,
struct wf_json const * request_data,
wf_jsonrpc_send_fn * send,
void * user_data)
{
json_t * method_holder = json_object_get(request_data, "method");
json_t * params = json_object_get(request_data, "params");
json_t * id_holder = json_object_get(request_data, "id");
struct wf_json const * method_holder = wf_impl_json_object_get(request_data, "method");
struct wf_json const * params = wf_impl_json_object_get(request_data, "params");
struct wf_json const * id_holder = wf_impl_json_object_get(request_data, "id");
if (json_is_string(method_holder) &&
(json_is_array(params) || (json_is_object(params))) &&
json_is_integer(id_holder))
if ((WF_JSON_TYPE_STRING == wf_impl_json_type(method_holder)) &&
((WF_JSON_TYPE_ARRAY == wf_impl_json_type(params)) || (WF_JSON_TYPE_OBJECT == wf_impl_json_type(params))) &&
(WF_JSON_TYPE_INT == wf_impl_json_type(id_holder)))
{
char const * method_name = json_string_value(method_holder);
int id = json_integer_value(id_holder);
char const * method_name = wf_impl_json_string_get(method_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_method const * method = wf_impl_jsonrpc_server_get_method(server, method_name);

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

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

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

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

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

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

@ -2,6 +2,7 @@
#include "webfuse/impl/operation/context.h"
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/util.h"
#include "webfuse/status.h"
#include "webfuse/impl/util/json_util.h"
@ -11,7 +12,7 @@
void wf_impl_operation_open_finished(
void * user_data,
json_t const * result,
struct wf_json const * result,
struct wf_jsonrpc_error const * error)
{
wf_status status = wf_impl_jsonrpc_get_status(error);
@ -21,10 +22,10 @@ void wf_impl_operation_open_finished(
if (NULL != result)
{
json_t * handle_holder = json_object_get(result, "handle");
if (json_is_integer(handle_holder))
struct wf_json const * handle_holder = wf_impl_json_object_get(result, "handle");
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
{

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

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

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

@ -10,6 +10,7 @@
#include <unistd.h>
#include "webfuse/impl/jsonrpc/proxy.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/util/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 * user_data,
json_t const * result,
struct wf_json const * result,
struct wf_jsonrpc_error const * 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;
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++)
{
json_t * entry =json_array_get(result, i);
if (json_is_object(entry))
struct wf_json const * entry = wf_impl_json_array_get(result, i);
if (WF_JSON_TYPE_OBJECT == wf_impl_json_type(entry))
{
json_t * name_holder = json_object_get(entry, "name");
json_t * inode_holder = json_object_get(entry, "inode");
struct wf_json const * name_holder = wf_impl_json_object_get(entry, "name");
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);
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
char const * name = wf_impl_json_string_get(name_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);
}
else

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

@ -13,6 +13,7 @@
#include "webfuse/impl/jsonrpc/request.h"
#include "webfuse/impl/jsonrpc/response_writer.h"
#include "webfuse/impl/json/node.h"
#include "webfuse/impl/timer/manager.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(
struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name),
json_t * params,
struct wf_json const * params,
void * WF_UNUSED_PARAM(user_data))
{
bool result = false;
json_t * type_holder = json_array_get(params, 0);
json_t * creds_holder = json_array_get(params, 1);
struct wf_json const * type_holder = wf_impl_json_array_get(params, 0);
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;
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(
struct wf_jsonrpc_request * request,
char const * WF_UNUSED_PARAM(method_name),
json_t * params,
struct wf_json const * params,
void * WF_UNUSED_PARAM(user_data))
{
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;
if (WF_GOOD == status)
{
json_t * name_holder = json_array_get(params, 0);
if (json_is_string(name_holder))
struct wf_json const * name_holder = wf_impl_json_array_get(params, 0);
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))
{
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));
}
}
void wf_impl_server_protocol_init(

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

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

@ -1,14 +1,19 @@
#include "webfuse/impl/util/json_util.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;
json_t * holder = json_object_get(object, key);
if (json_is_integer(holder))
struct wf_json const * holder = wf_impl_json_object_get(object, key);
if (WF_JSON_TYPE_INT == wf_impl_json_type(holder))
{
result = json_integer_value(holder);
result = wf_impl_json_int_get(holder);
}
return result;

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

@ -161,8 +161,10 @@ TEST(json_reader, read_string)
wf_impl_json_reader_init(&reader, const_cast<char*>(text.data()), text.size());
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_EQ(7, size);
}
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());
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_EQ(17, size);
}
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());
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)
@ -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());
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)
@ -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());
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));
}

Loading…
Cancel
Save