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

Side by Side Diff: mojo/public/c/lib/bindings/message.c

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « mojo/public/c/lib/bindings/map.c ('k') | mojo/public/c/lib/bindings/struct.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <mojo/bindings/message.h>
6
7 #include <mojo/bindings/struct.h>
8 #include <stdint.h>
9
10 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf,
11 uint32_t in_buf_size) {
12 const struct MojomStructHeader* header =
13 (const struct MojomStructHeader*)in_buf;
14
15 if (in_buf_size < sizeof(struct MojomStructHeader) ||
16 in_buf_size < header->num_bytes)
17 return MOJOM_VALIDATION_ILLEGAL_MEMORY_RANGE;
18
19 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
20 if (header->version == 0u) {
21 if (header->num_bytes != sizeof(struct MojomMessage)) {
22 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER;
23 }
24
25 // Version 0 has no request id and should not have either of these flags.
26 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) ||
27 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) {
28 return MOJOM_VALIDATION_MESSAGE_HEADER_MISSING_REQUEST_ID;
29 }
30 } else if (header->version == 1u) {
31 if (header->num_bytes != sizeof(struct MojomMessageWithRequestId)) {
32 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER;
33 }
34 } else if (header->version > 1u) {
35 if (header->num_bytes < sizeof(struct MojomMessageWithRequestId)) {
36 return MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER;
37 }
38 }
39
40 // Mutually exclusive flags.
41 if ((msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) &&
42 (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)) {
43 return MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
44 }
45
46 // Accept unknown versions of the message header to be future-proof.
47 return MOJOM_VALIDATION_ERROR_NONE;
48 }
49
50 MojomValidationResult MojomMessage_ValidateRequestExpectingResponse(
51 const void* in_buf) {
52 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
53 return (msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE)
54 ? MOJOM_VALIDATION_ERROR_NONE
55 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
56 }
57
58 MojomValidationResult MojomMessage_ValidateRequestWithoutResponse(
59 const void* in_buf) {
60 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
61 return (!(msg->flags & MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE) &&
62 !(msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE))
63 ? MOJOM_VALIDATION_ERROR_NONE
64 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
65 }
66
67 MojomValidationResult MojomMessage_ValidateResponse(
68 const void* in_buf) {
69 const struct MojomMessage* msg = (const struct MojomMessage*)in_buf;
70 return (msg->flags & MOJOM_MESSAGE_FLAGS_IS_RESPONSE)
71 ? MOJOM_VALIDATION_ERROR_NONE
72 : MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS;
73 }
OLDNEW
« no previous file with comments | « mojo/public/c/lib/bindings/map.c ('k') | mojo/public/c/lib/bindings/struct.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698