OLD | NEW |
1 {%- import "interface_macros.tmpl" as interface_macros %} | 1 {%- import "interface_macros.tmpl" as interface_macros %} |
2 {%- import "struct_macros.tmpl" as struct_macros %} | 2 {%- import "struct_macros.tmpl" as struct_macros %} |
3 | 3 |
4 {%- set class_name = interface.name %} | 4 {%- set class_name = interface.name %} |
5 {%- set proxy_name = interface.name ~ "Proxy" %} | 5 {%- set proxy_name = interface.name ~ "Proxy" %} |
6 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} | 6 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} |
7 | 7 |
8 {%- macro alloc_params(struct, params, message, serialization_context, | 8 {%- macro alloc_params(struct, params, message, serialization_context, |
9 description) %} | 9 description) %} |
10 ({{serialization_context}})->handles.Swap(({{message}})->mutable_handles()); | 10 ({{serialization_context}})->handles.Swap(({{message}})->mutable_handles()); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 {%- endif %} | 370 {%- endif %} |
371 } | 371 } |
372 {%- endfor %} | 372 {%- endfor %} |
373 } | 373 } |
374 {%- endif %} | 374 {%- endif %} |
375 return false; | 375 return false; |
376 } | 376 } |
377 | 377 |
378 {#--- Request validator definitions #} | 378 {#--- Request validator definitions #} |
379 | 379 |
380 {{class_name}}RequestValidator::{{class_name}}RequestValidator( | |
381 mojo::MessageReceiver* sink) : MessageFilter(sink) { | |
382 } | |
383 | |
384 bool {{class_name}}RequestValidator::Accept(mojo::Message* message) { | 380 bool {{class_name}}RequestValidator::Accept(mojo::Message* message) { |
385 assert(sink_); | |
386 | |
387 mojo::internal::ValidationContext validation_context( | 381 mojo::internal::ValidationContext validation_context( |
388 message->data(), message->data_num_bytes(), message->handles()->size(), | 382 message->data(), message->data_num_bytes(), message->handles()->size(), |
389 message, "{{class_name}} RequestValidator"); | 383 message, "{{class_name}} RequestValidator"); |
390 | 384 |
391 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { | 385 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { |
392 if (!mojo::internal::ValidateControlRequest(message, &validation_context)) | 386 if (!mojo::internal::ValidateControlRequest(message, &validation_context)) |
393 return false; | 387 return false; |
394 return sink_->Accept(message); | 388 return true; |
395 } | 389 } |
396 | 390 |
397 switch (message->header()->name) { | 391 switch (message->header()->name) { |
398 {%- for method in interface.methods %} | 392 {%- for method in interface.methods %} |
399 case internal::k{{class_name}}_{{method.name}}_Name: { | 393 case internal::k{{class_name}}_{{method.name}}_Name: { |
400 {%- if method.response_parameters != None %} | 394 {%- if method.response_parameters != None %} |
401 if (!mojo::internal::ValidateMessageIsRequestExpectingResponse( | 395 if (!mojo::internal::ValidateMessageIsRequestExpectingResponse( |
402 message, &validation_context)) { | 396 message, &validation_context)) { |
403 return false; | 397 return false; |
404 } | 398 } |
405 {%- else %} | 399 {%- else %} |
406 if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( | 400 if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
407 message, &validation_context)) { | 401 message, &validation_context)) { |
408 return false; | 402 return false; |
409 } | 403 } |
410 {%- endif %} | 404 {%- endif %} |
411 if (!mojo::internal::ValidateMessagePayload< | 405 if (!mojo::internal::ValidateMessagePayload< |
412 internal::{{class_name}}_{{method.name}}_Params_Data>( | 406 internal::{{class_name}}_{{method.name}}_Params_Data>( |
413 message, &validation_context)) { | 407 message, &validation_context)) { |
414 return false; | 408 return false; |
415 } | 409 } |
416 return sink_->Accept(message); | 410 return true; |
417 } | 411 } |
418 {%- endfor %} | 412 {%- endfor %} |
419 default: | 413 default: |
420 break; | 414 break; |
421 } | 415 } |
422 | 416 |
423 // Unrecognized message. | 417 // Unrecognized message. |
424 ReportValidationError( | 418 ReportValidationError( |
425 &validation_context, | 419 &validation_context, |
426 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); | 420 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
427 return false; | 421 return false; |
428 } | 422 } |
429 | 423 |
430 {#--- Response validator definitions #} | 424 {#--- Response validator definitions #} |
431 {% if interface|has_callbacks %} | 425 {% if interface|has_callbacks %} |
432 {{class_name}}ResponseValidator::{{class_name}}ResponseValidator( | |
433 mojo::MessageReceiver* sink) : MessageFilter(sink) { | |
434 } | |
435 | |
436 bool {{class_name}}ResponseValidator::Accept(mojo::Message* message) { | 426 bool {{class_name}}ResponseValidator::Accept(mojo::Message* message) { |
437 assert(sink_); | |
438 | |
439 mojo::internal::ValidationContext validation_context( | 427 mojo::internal::ValidationContext validation_context( |
440 message->data(), message->data_num_bytes(), message->handles()->size(), | 428 message->data(), message->data_num_bytes(), message->handles()->size(), |
441 message, "{{class_name}} ResponseValidator"); | 429 message, "{{class_name}} ResponseValidator"); |
442 | 430 |
443 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { | 431 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { |
444 if (!mojo::internal::ValidateControlResponse(message, &validation_context)) | 432 if (!mojo::internal::ValidateControlResponse(message, &validation_context)) |
445 return false; | 433 return false; |
446 return sink_->Accept(message); | 434 return true; |
447 } | 435 } |
448 | 436 |
449 if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context)) | 437 if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context)) |
450 return false; | 438 return false; |
451 switch (message->header()->name) { | 439 switch (message->header()->name) { |
452 {%- for method in interface.methods if method.response_parameters != None %} | 440 {%- for method in interface.methods if method.response_parameters != None %} |
453 case internal::k{{class_name}}_{{method.name}}_Name: { | 441 case internal::k{{class_name}}_{{method.name}}_Name: { |
454 if (!mojo::internal::ValidateMessagePayload< | 442 if (!mojo::internal::ValidateMessagePayload< |
455 internal::{{class_name}}_{{method.name}}_ResponseParams_Data>( | 443 internal::{{class_name}}_{{method.name}}_ResponseParams_Data>( |
456 message, &validation_context)) { | 444 message, &validation_context)) { |
457 return false; | 445 return false; |
458 } | 446 } |
459 return sink_->Accept(message); | 447 return true; |
460 } | 448 } |
461 {%- endfor %} | 449 {%- endfor %} |
462 default: | 450 default: |
463 break; | 451 break; |
464 } | 452 } |
465 | 453 |
466 // Unrecognized message. | 454 // Unrecognized message. |
467 ReportValidationError( | 455 ReportValidationError( |
468 &validation_context, | 456 &validation_context, |
469 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); | 457 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
470 return false; | 458 return false; |
471 } | 459 } |
472 {%- endif -%} | 460 {%- endif -%} |
OLD | NEW |