OLD | NEW |
| (Empty) |
1 // Copyright 2015 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_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ | |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | |
11 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | |
12 #include "mojo/public/cpp/bindings/message.h" | |
13 | |
14 namespace mojo { | |
15 namespace internal { | |
16 | |
17 // Validates that the message is a request which doesn't expect a response. | |
18 ValidationError ValidateMessageIsRequestWithoutResponse(const Message* message, | |
19 std::string* err); | |
20 // Validates that the message is a request expecting a response. | |
21 ValidationError ValidateMessageIsRequestExpectingResponse( | |
22 const Message* message, | |
23 std::string* err); | |
24 // Validates that the message is a response. | |
25 ValidationError ValidateMessageIsResponse(const Message* message, | |
26 std::string* err); | |
27 | |
28 // Validates that the message payload is a valid struct of type ParamsType. | |
29 template <typename ParamsType> | |
30 ValidationError ValidateMessagePayload(const Message* message, | |
31 std::string* err) { | |
32 BoundsChecker bounds_checker(message->payload(), message->payload_num_bytes(), | |
33 message->handles()->size()); | |
34 return ParamsType::Validate(message->payload(), &bounds_checker, err); | |
35 } | |
36 | |
37 } // namespace internal | |
38 } // namespace mojo | |
39 | |
40 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_VALIDATION_H_ | |
OLD | NEW |