aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/msgpack_rpc/helpers.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-04-12 02:06:49 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-04-12 02:30:31 +0200
commitfd00806f01673891a4970851612dea1838a39fb9 (patch)
tree47dc0642aaa9b7b25d0f226f29862660ef208205 /src/nvim/msgpack_rpc/helpers.c
parentb4ca56d96dcf0fe14150115a8826206710d0567a (diff)
downloadrneovim-fd00806f01673891a4970851612dea1838a39fb9.tar.gz
rneovim-fd00806f01673891a4970851612dea1838a39fb9.tar.bz2
rneovim-fd00806f01673891a4970851612dea1838a39fb9.zip
RPC: eliminate NO_RESPONSE
Using a sentinel value in the response-id is ambiguous because the msgpack-rpc spec allows all values (including zero/max). And clients control the id, so we can't be sure they won't use the sentinel value. Instead of a sentinel value, check the message type explicitly. ref #8850
Diffstat (limited to 'src/nvim/msgpack_rpc/helpers.c')
-rw-r--r--src/nvim/msgpack_rpc/helpers.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c
index 19cc31f6a6..d7834fc047 100644
--- a/src/nvim/msgpack_rpc/helpers.c
+++ b/src/nvim/msgpack_rpc/helpers.c
@@ -561,58 +561,57 @@ static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req)
return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL;
}
-void msgpack_rpc_validate(uint64_t *response_id,
- msgpack_object *req,
- Error *err)
+MessageType msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req,
+ Error *err)
{
- // response id not known yet
-
- *response_id = NO_RESPONSE;
+ *response_id = 0;
// Validate the basic structure of the msgpack-rpc payload
if (req->type != MSGPACK_OBJECT_ARRAY) {
api_set_error(err, kErrorTypeValidation, "Message is not an array");
- return;
+ return kMessageTypeUnknown;
}
if (req->via.array.size == 0) {
api_set_error(err, kErrorTypeValidation, "Message is empty");
- return;
+ return kMessageTypeUnknown;
}
if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
api_set_error(err, kErrorTypeValidation, "Message type must be an integer");
- return;
+ return kMessageTypeUnknown;
}
- uint64_t type = req->via.array.ptr[0].via.u64;
+ MessageType type = (MessageType)req->via.array.ptr[0].via.u64;
if (type != kMessageTypeRequest && type != kMessageTypeNotification) {
api_set_error(err, kErrorTypeValidation, "Unknown message type");
- return;
+ return kMessageTypeUnknown;
}
if ((type == kMessageTypeRequest && req->via.array.size != 4)
|| (type == kMessageTypeNotification && req->via.array.size != 3)) {
api_set_error(err, kErrorTypeValidation,
"Request array size must be 4 (request) or 3 (notification)");
- return;
+ return type;
}
if (type == kMessageTypeRequest) {
msgpack_object *id_obj = msgpack_rpc_msg_id(req);
if (!id_obj) {
api_set_error(err, kErrorTypeValidation, "ID must be a positive integer");
- return;
+ return type;
}
*response_id = id_obj->via.u64;
}
if (!msgpack_rpc_method(req)) {
api_set_error(err, kErrorTypeValidation, "Method must be a string");
- return;
+ return type;
}
if (!msgpack_rpc_args(req)) {
api_set_error(err, kErrorTypeValidation, "Parameters must be an array");
- return;
+ return type;
}
+
+ return type;
}