mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-05 22:08:23 +00:00
Ditch JSON-RPC from mongoose
PUBLISHED_FROM=89b978c02be2f10eb930ff13673d45249fd67763
This commit is contained in:
1 parent
421b420a0c
commit
b7a0748312
30 files changed
+14
-2323
No files matched your search
-206
@@ -1067,74 +1067,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
|
||||
#endif
|
||||
|
||||
#endif /* CS_COMMON_STR_UTIL_H_ */
|
||||
/*
|
||||
* Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
|
||||
* Copyright (c) 2013 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* This library is dual-licensed: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. For the terms of this
|
||||
* license, see <http: *www.gnu.org/licenses/>.
|
||||
*
|
||||
* You are free to use this library under the terms of the GNU General
|
||||
* Public License, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* Alternatively, you can license this library under a commercial
|
||||
* license, as set out in <http://cesanta.com/products.html>.
|
||||
*/
|
||||
|
||||
#ifndef CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_
|
||||
#define CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
enum json_type {
|
||||
JSON_TYPE_EOF = 0, /* End of parsed tokens marker */
|
||||
JSON_TYPE_STRING = 1,
|
||||
JSON_TYPE_NUMBER = 2,
|
||||
JSON_TYPE_OBJECT = 3,
|
||||
JSON_TYPE_TRUE = 4,
|
||||
JSON_TYPE_FALSE = 5,
|
||||
JSON_TYPE_NULL = 6,
|
||||
JSON_TYPE_ARRAY = 7
|
||||
};
|
||||
|
||||
struct json_token {
|
||||
const char *ptr; /* Points to the beginning of the token */
|
||||
int len; /* Token length */
|
||||
int num_desc; /* For arrays and object, total number of descendants */
|
||||
enum json_type type; /* Type of the token, possible values above */
|
||||
};
|
||||
|
||||
/* Error codes */
|
||||
#define JSON_STRING_INVALID -1
|
||||
#define JSON_STRING_INCOMPLETE -2
|
||||
#define JSON_TOKEN_ARRAY_TOO_SMALL -3
|
||||
|
||||
int parse_json(const char *json_string, int json_string_length,
|
||||
struct json_token *tokens_array, int size_of_tokens_array);
|
||||
struct json_token *parse_json2(const char *json_string, int string_length);
|
||||
struct json_token *find_json_token(struct json_token *toks, const char *path);
|
||||
|
||||
int json_emit_long(char *buf, int buf_len, long value);
|
||||
int json_emit_double(char *buf, int buf_len, double value);
|
||||
int json_emit_quoted_str(char *buf, int buf_len, const char *str, int len);
|
||||
int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len);
|
||||
int json_emit(char *buf, int buf_len, const char *fmt, ...);
|
||||
int json_emit_va(char *buf, int buf_len, const char *fmt, va_list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_ */
|
||||
/*
|
||||
* Copyright (c) 2014 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
@@ -2754,144 +2686,6 @@ int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain,
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* CS_MONGOOSE_SRC_HTTP_H_ */
|
||||
/*
|
||||
* Copyright (c) 2014 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
/*
|
||||
* === JSON-RPC
|
||||
*/
|
||||
|
||||
#ifndef CS_MONGOOSE_SRC_JSON_RPC_H_
|
||||
#define CS_MONGOOSE_SRC_JSON_RPC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* JSON-RPC request */
|
||||
struct mg_rpc_request {
|
||||
struct json_token *message; /* Whole RPC message */
|
||||
struct json_token *id; /* Message ID */
|
||||
struct json_token *method; /* Method name */
|
||||
struct json_token *params; /* Method params */
|
||||
};
|
||||
|
||||
/* JSON-RPC response */
|
||||
struct mg_rpc_reply {
|
||||
struct json_token *message; /* Whole RPC message */
|
||||
struct json_token *id; /* Message ID */
|
||||
struct json_token *result; /* Remote call result */
|
||||
};
|
||||
|
||||
/* JSON-RPC error */
|
||||
struct mg_rpc_error {
|
||||
struct json_token *message; /* Whole RPC message */
|
||||
struct json_token *id; /* Message ID */
|
||||
struct json_token *error_code; /* error.code */
|
||||
struct json_token *error_message; /* error.message */
|
||||
struct json_token *error_data; /* error.data, can be NULL */
|
||||
};
|
||||
|
||||
/*
|
||||
* Parse JSON-RPC reply contained in `buf`, `len` into JSON tokens array
|
||||
* `toks`, `max_toks`. If buffer contains valid reply, `reply` structure is
|
||||
* populated. The result of RPC call is located in `reply.result`. On error,
|
||||
* `error` structure is populated. Returns: the result of calling
|
||||
* `parse_json(buf, len, toks, max_toks)`:
|
||||
*
|
||||
* On success, an offset inside `json_string` is returned
|
||||
* where parsing has finished. On failure, a negative number is
|
||||
* returned, one of:
|
||||
*
|
||||
* - `#define JSON_STRING_INVALID -1`
|
||||
* - `#define JSON_STRING_INCOMPLETE -2`
|
||||
* - `#define JSON_TOKEN_ARRAY_TOO_SMALL -3`
|
||||
*/
|
||||
int mg_rpc_parse_reply(const char *buf, int len, struct json_token *toks,
|
||||
int max_toks, struct mg_rpc_reply *,
|
||||
struct mg_rpc_error *);
|
||||
|
||||
/*
|
||||
* Create JSON-RPC request in a given buffer.
|
||||
*
|
||||
* Return length of the request, which
|
||||
* can be larger then `len` that indicates an overflow.
|
||||
* `params_fmt` format string should conform to `json_emit()` API,
|
||||
* see https://github.com/cesanta/frozen
|
||||
*/
|
||||
int mg_rpc_create_request(char *buf, int len, const char *method,
|
||||
const char *id, const char *params_fmt, ...);
|
||||
|
||||
/*
|
||||
* Create JSON-RPC reply in a given buffer.
|
||||
*
|
||||
* Return length of the reply, which
|
||||
* can be larger then `len` that indicates an overflow.
|
||||
* `result_fmt` format string should conform to `json_emit()` API,
|
||||
* see https://github.com/cesanta/frozen
|
||||
*/
|
||||
int mg_rpc_create_reply(char *buf, int len, const struct mg_rpc_request *req,
|
||||
const char *result_fmt, ...);
|
||||
|
||||
/*
|
||||
* Create JSON-RPC error reply in a given buffer.
|
||||
*
|
||||
* Return length of the error, which
|
||||
* can be larger then `len` that indicates an overflow.
|
||||
* `fmt` format string should conform to `json_emit()` API,
|
||||
* see https://github.com/cesanta/frozen
|
||||
*/
|
||||
int mg_rpc_create_error(char *buf, int len, struct mg_rpc_request *req,
|
||||
int code, const char *message, const char *fmt, ...);
|
||||
|
||||
/* JSON-RPC standard error codes */
|
||||
#define JSON_RPC_PARSE_ERROR (-32700)
|
||||
#define JSON_RPC_INVALID_REQUEST_ERROR (-32600)
|
||||
#define JSON_RPC_METHOD_NOT_FOUND_ERROR (-32601)
|
||||
#define JSON_RPC_INVALID_PARAMS_ERROR (-32602)
|
||||
#define JSON_RPC_INTERNAL_ERROR (-32603)
|
||||
#define JSON_RPC_SERVER_ERROR (-32000)
|
||||
|
||||
/*
|
||||
* Create JSON-RPC error in a given buffer.
|
||||
*
|
||||
* Return length of the error, which
|
||||
* can be larger then `len` that indicates an overflow. See
|
||||
* JSON_RPC_*_ERROR definitions for standard error values:
|
||||
*
|
||||
* - `#define JSON_RPC_PARSE_ERROR (-32700)`
|
||||
* - `#define JSON_RPC_INVALID_REQUEST_ERROR (-32600)`
|
||||
* - `#define JSON_RPC_METHOD_NOT_FOUND_ERROR (-32601)`
|
||||
* - `#define JSON_RPC_INVALID_PARAMS_ERROR (-32602)`
|
||||
* - `#define JSON_RPC_INTERNAL_ERROR (-32603)`
|
||||
* - `#define JSON_RPC_SERVER_ERROR (-32000)`
|
||||
*/
|
||||
int mg_rpc_create_std_error(char *buf, int len, struct mg_rpc_request *req,
|
||||
int code);
|
||||
|
||||
typedef int (*mg_rpc_handler_t)(char *buf, int len, struct mg_rpc_request *req);
|
||||
|
||||
/*
|
||||
* Dispatches a JSON-RPC request.
|
||||
*
|
||||
* Parses JSON-RPC request contained in `buf`, `len`.
|
||||
* Then, dispatches the request to the correct handler method.
|
||||
* Valid method names should be specified in NULL
|
||||
* terminated array `methods`, and corresponding handlers in `handlers`.
|
||||
* Result is put in `dst`, `dst_len`. Return: length of the result, which
|
||||
* can be larger then `dst_len` that indicates an overflow.
|
||||
* Overflown bytes are not written to the buffer.
|
||||
* If method is not found, an error is automatically generated.
|
||||
*/
|
||||
int mg_rpc_dispatch(const char *buf, int, char *dst, int dst_len,
|
||||
const char **methods, mg_rpc_handler_t *handlers);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* CS_MONGOOSE_SRC_JSON_RPC_H_ */
|
||||
/*
|
||||
* Copyright (c) 2014 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
|
||||
Reference in new issue
Block a user