| OLD | NEW |
| (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 #ifndef MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_MESSAGE_H_ | |
| 6 #define MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_MESSAGE_H_ | |
| 7 | |
| 8 #include <mojo/bindings/struct.h> | |
| 9 #include <mojo/bindings/validation.h> | |
| 10 #include <mojo/macros.h> | |
| 11 #include <stdint.h> | |
| 12 | |
| 13 MOJO_BEGIN_EXTERN_C | |
| 14 | |
| 15 #define MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE ((uint32_t)(1 << 0u)) | |
| 16 #define MOJOM_MESSAGE_FLAGS_IS_RESPONSE ((uint32_t)(1 << 1u)) | |
| 17 | |
| 18 // All mojom messages (over a message pipe) are framed with a MojomMessage as | |
| 19 // its header. | |
| 20 // MojomMessage is actually a mojom struct -- we define it here since it's | |
| 21 // easier to read, and the validation has more to it than simple mojom struct | |
| 22 // validation. | |
| 23 struct MojomMessage { | |
| 24 // header.version = 0 (version 1 has a request_id) | |
| 25 struct MojomStructHeader header; | |
| 26 // The ordinal number associated with this message. This is specified | |
| 27 // (implicitly, if not explicitly) in the mojom IDL for an interface message | |
| 28 // and is used to identify it. | |
| 29 uint32_t ordinal; | |
| 30 // Described by the MOJOM_MESSAGE_* flags defined above. | |
| 31 uint32_t flags; | |
| 32 }; | |
| 33 MOJO_STATIC_ASSERT(sizeof(struct MojomMessage) == 16, | |
| 34 "struct MojomMessage must be 16 bytes"); | |
| 35 | |
| 36 // Using |MojomMessage| as a member of this struct could work, but usability | |
| 37 // would suffer a little while accessing the |header|. MojomMessageWithRequestId | |
| 38 // is a "newer" version than MojomMessage. | |
| 39 struct MojomMessageWithRequestId { | |
| 40 // header.version = 1 | |
| 41 struct MojomStructHeader header; | |
| 42 // Which message is it? | |
| 43 uint32_t ordinal; | |
| 44 // Described by the MOJOM_MESSAGE_* flags defined above. | |
| 45 uint32_t flags; | |
| 46 uint64_t request_id; | |
| 47 }; | |
| 48 MOJO_STATIC_ASSERT(sizeof(struct MojomMessageWithRequestId) == 24, | |
| 49 "MojomMessageWithRequestId must be 24 bytes"); | |
| 50 | |
| 51 // Validates that |in_buf| is a valid mojom message. This does not validate the | |
| 52 // contents of the message's body, only the message header. This function does | |
| 53 // not validate whether a message should be a kind of request. | |
| 54 // |in_buf|: can be a MojomMessage or a MojomMessageWithRequestId. | |
| 55 // |in_buf_size|: number of bytes in |in_buf|. | |
| 56 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf, | |
| 57 uint32_t in_buf_size); | |
| 58 | |
| 59 // Validates that the given message is a request expecting a response. Assumes | |
| 60 // that the message is already validated by MojomMessage_ValidateHeader(). | |
| 61 MojomValidationResult MojomMessage_ValidateRequestExpectingResponse( | |
| 62 const void* in_buf); | |
| 63 | |
| 64 // Validates that the given message is a request which isn't expecting a | |
| 65 // response. Assumes that the message is already validated by | |
| 66 // MojomMessage_ValidateHeader(). | |
| 67 MojomValidationResult MojomMessage_ValidateRequestWithoutResponse( | |
| 68 const void* in_buf); | |
| 69 | |
| 70 // Validates that the given message is a response. Assumes taht the message is | |
| 71 // already validated by MojomMessage_ValidateHeader(). | |
| 72 MojomValidationResult MojomMessage_ValidateResponse(const void* in_buf); | |
| 73 | |
| 74 MOJO_END_EXTERN_C | |
| 75 | |
| 76 #endif // MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_MESSAGE_H_ | |
| OLD | NEW |