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 #include "mojo/public/cpp/bindings/lib/message_validation.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | |
10 #include "mojo/public/cpp/bindings/message.h" | |
11 | |
12 namespace mojo { | |
13 namespace internal { | |
14 | |
15 ValidationError ValidateMessageIsRequestWithoutResponse(const Message* message, | |
16 std::string* err) { | |
17 if (message->has_flag(kMessageIsResponse)) { | |
18 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
19 << "message should be a request, not a response"; | |
20 return ValidationError::MESSAGE_HEADER_INVALID_FLAGS; | |
21 } | |
22 if (message->has_flag(kMessageExpectsResponse)) { | |
23 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
24 << "message should not expect a response"; | |
25 return ValidationError::MESSAGE_HEADER_INVALID_FLAGS; | |
26 } | |
27 return ValidationError::NONE; | |
28 } | |
29 | |
30 ValidationError ValidateMessageIsRequestExpectingResponse( | |
31 const Message* message, | |
32 std::string* err) { | |
33 if (message->has_flag(kMessageIsResponse)) { | |
34 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
35 << "message should be a request, not a response"; | |
36 return ValidationError::MESSAGE_HEADER_INVALID_FLAGS; | |
37 } | |
38 if (!message->has_flag(kMessageExpectsResponse)) { | |
39 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
40 << "message should expect a response"; | |
41 return ValidationError::MESSAGE_HEADER_INVALID_FLAGS; | |
42 } | |
43 return ValidationError::NONE; | |
44 } | |
45 | |
46 ValidationError ValidateMessageIsResponse(const Message* message, | |
47 std::string* err) { | |
48 if (message->has_flag(kMessageExpectsResponse) || | |
49 !message->has_flag(kMessageIsResponse)) { | |
50 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "message should be a response"; | |
51 return ValidationError::MESSAGE_HEADER_INVALID_FLAGS; | |
52 } | |
53 return ValidationError::NONE; | |
54 } | |
55 | |
56 } // namespace internal | |
57 } // namespace mojo | |
OLD | NEW |