Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Unified Diff: mojo/public/c/bindings/lib/message.c

Issue 2163793002: C bindings: Implement _Validate(), and some pre-requisites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/c/bindings/lib/map.c ('k') | mojo/public/c/bindings/lib/struct.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/c/bindings/lib/message.c
diff --git a/mojo/public/c/bindings/lib/message.c b/mojo/public/c/bindings/lib/message.c
index 9b2d27dce004f9b4f9e8c5fad1d8d3e04c960e17..6c766e3009fe7b192483c4d6a116e3bfcd0cb8b3 100644
--- a/mojo/public/c/bindings/lib/message.c
+++ b/mojo/public/c/bindings/lib/message.c
@@ -12,10 +12,10 @@ MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf,
uint32_t in_buf_size) {
const struct MojomStructHeader* header =
(const struct MojomStructHeader*)in_buf;
+
if (in_buf_size < sizeof(struct MojomStructHeader) ||
- in_buf_size < header->num_bytes) {
- return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER;
- }
+ in_buf_size < header->num_bytes)
+ return MOJOM_VALIDATION_ILLEGAL_MEMORY_RANGE;
const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
if (header->version == 0u) {
@@ -47,3 +47,28 @@ MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf,
// Accept unknown versions of the message header to be future-proof.
return MOJOM_VALIDATION_ERROR_NONE;
}
+
+MojomValidationResult MojomMessage_ValidateRequestExpectingResponse(
+ const void* in_buf) {
+ const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
+ return (msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE)
+ ? MOJOM_VALIDATION_ERROR_NONE
+ : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
+}
+
+MojomValidationResult MojomMessage_ValidateRequestWithoutResponse(
+ const void* in_buf) {
+ const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
+ return (!(msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) &&
+ !(msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE))
+ ? MOJOM_VALIDATION_ERROR_NONE
+ : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
+}
+
+MojomValidationResult MojomMessage_ValidateResponse(
+ const void* in_buf) {
+ const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
+ return (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)
+ ? MOJOM_VALIDATION_ERROR_NONE
+ : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
+}
« no previous file with comments | « mojo/public/c/bindings/lib/map.c ('k') | mojo/public/c/bindings/lib/struct.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698