| Index: mojo/public/cpp/bindings/lib/validation_util.h
|
| diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h
|
| index 1c6c53cb23eba61f6139a66e712ba6055d5628b9..8c47550070917ce5a4579a4c8355a04d1654ad44 100644
|
| --- a/mojo/public/cpp/bindings/lib/validation_util.h
|
| +++ b/mojo/public/cpp/bindings/lib/validation_util.h
|
| @@ -58,18 +58,42 @@ bool ValidateUnionHeaderAndClaimMemory(const void* data,
|
| ValidationContext* validation_context);
|
|
|
| // Validates that the message is a request which doesn't expect a response.
|
| -bool ValidateMessageIsRequestWithoutResponse(
|
| +inline bool ValidateMessageIsRequestWithoutResponse(
|
| const Message* message,
|
| - ValidationContext* validation_context);
|
| + ValidationContext* validation_context) {
|
| + if (message->has_flag(Message::kFlagIsResponse) ||
|
| + message->has_flag(Message::kFlagExpectsResponse)) {
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
|
|
| // Validates that the message is a request expecting a response.
|
| -bool ValidateMessageIsRequestExpectingResponse(
|
| +inline bool ValidateMessageIsRequestExpectingResponse(
|
| const Message* message,
|
| - ValidationContext* validation_context);
|
| + ValidationContext* validation_context) {
|
| + if (message->has_flag(Message::kFlagIsResponse) ||
|
| + !message->has_flag(Message::kFlagExpectsResponse)) {
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
|
|
| // Validates that the message is a response.
|
| -bool ValidateMessageIsResponse(const Message* message,
|
| - ValidationContext* validation_context);
|
| +inline bool ValidateMessageIsResponse(const Message* message,
|
| + ValidationContext* validation_context) {
|
| + if (message->has_flag(Message::kFlagExpectsResponse) ||
|
| + !message->has_flag(Message::kFlagIsResponse)) {
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS);
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
|
|
| // Validates that the message payload is a valid struct of type ParamsType.
|
| template <typename ParamsType>
|
| @@ -113,27 +137,113 @@ bool ValidateInlinedUnionNonNullable(const T& input,
|
| return false;
|
| }
|
|
|
| -bool IsHandleOrInterfaceValid(const AssociatedInterface_Data& input);
|
| -bool IsHandleOrInterfaceValid(const AssociatedInterfaceRequest_Data& input);
|
| -bool IsHandleOrInterfaceValid(const Interface_Data& input);
|
| -bool IsHandleOrInterfaceValid(const Handle_Data& input);
|
| +inline bool IsHandleOrInterfaceValid(const AssociatedInterface_Data& input) {
|
| + return IsValidInterfaceId(input.interface_id);
|
| +}
|
| +
|
| +inline bool IsHandleOrInterfaceValid(
|
| + const AssociatedInterfaceRequest_Data& input) {
|
| + return IsValidInterfaceId(input.interface_id);
|
| +}
|
| +
|
| +inline bool IsHandleOrInterfaceValid(const Interface_Data& input) {
|
| + return input.handle.is_valid();
|
| +}
|
|
|
| -bool ValidateHandleOrInterfaceNonNullable(
|
| +inline bool IsHandleOrInterfaceValid(const Handle_Data& input) {
|
| + return input.is_valid();
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterfaceNonNullable(
|
| const AssociatedInterface_Data& input,
|
| const char* error_message,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterfaceNonNullable(
|
| + ValidationContext* validation_context) {
|
| + if (IsHandleOrInterfaceValid(input))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_INVALID_INTERFACE_ID,
|
| + error_message);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterfaceNonNullable(
|
| const AssociatedInterfaceRequest_Data& input,
|
| const char* error_message,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterfaceNonNullable(
|
| + ValidationContext* validation_context) {
|
| + if (IsHandleOrInterfaceValid(input))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_INVALID_INTERFACE_ID,
|
| + error_message);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterfaceNonNullable(
|
| const Interface_Data& input,
|
| const char* error_message,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterfaceNonNullable(
|
| + ValidationContext* validation_context) {
|
| + if (IsHandleOrInterfaceValid(input))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
|
| + error_message);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterfaceNonNullable(
|
| const Handle_Data& input,
|
| const char* error_message,
|
| - ValidationContext* validation_context);
|
| + ValidationContext* validation_context) {
|
| + if (IsHandleOrInterfaceValid(input))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
|
| + error_message);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterface(const AssociatedInterface_Data& input,
|
| + ValidationContext* validation_context) {
|
| + if (!IsMasterInterfaceId(input.interface_id))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_ILLEGAL_INTERFACE_ID);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterface(
|
| + const AssociatedInterfaceRequest_Data& input,
|
| + ValidationContext* validation_context) {
|
| + if (!IsMasterInterfaceId(input.interface_id))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context,
|
| + VALIDATION_ERROR_ILLEGAL_INTERFACE_ID);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterface(const Interface_Data& input,
|
| + ValidationContext* validation_context) {
|
| + if (validation_context->ClaimHandle(input.handle))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE);
|
| + return false;
|
| +}
|
| +
|
| +inline bool ValidateHandleOrInterface(const Handle_Data& input,
|
| + ValidationContext* validation_context) {
|
| + if (validation_context->ClaimHandle(input))
|
| + return true;
|
| +
|
| + ReportValidationError(validation_context, VALIDATION_ERROR_ILLEGAL_HANDLE);
|
| + return false;
|
| +}
|
|
|
| template <typename T>
|
| bool ValidateContainer(const Pointer<T>& input,
|
| @@ -163,14 +273,6 @@ bool ValidateNonInlinedUnion(const Pointer<T>& input,
|
| T::Validate(input.Get(), validation_context, false);
|
| }
|
|
|
| -bool ValidateHandleOrInterface(const AssociatedInterface_Data& input,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterface(const AssociatedInterfaceRequest_Data& input,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterface(const Interface_Data& input,
|
| - ValidationContext* validation_context);
|
| -bool ValidateHandleOrInterface(const Handle_Data& input,
|
| - ValidationContext* validation_context);
|
|
|
| } // namespace internal
|
| } // namespace mojo
|
|
|