OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_protocol.h" | 5 #include "net/spdy/spdy_protocol.h" |
6 | 6 |
7 namespace net { | 7 namespace net { |
8 | 8 |
9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( | 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( |
10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} | 10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return 4; | 294 return 4; |
295 default: | 295 default: |
296 LOG(DFATAL) << "Serializing unhandled setting id " << id; | 296 LOG(DFATAL) << "Serializing unhandled setting id " << id; |
297 return -1; | 297 return -1; |
298 } | 298 } |
299 } | 299 } |
300 LOG(DFATAL) << "Unhandled SPDY version " << version; | 300 LOG(DFATAL) << "Unhandled SPDY version " << version; |
301 return -1; | 301 return -1; |
302 } | 302 } |
303 | 303 |
| 304 bool SpdyConstants::IsValidRstStreamStatus(SpdyMajorVersion version, |
| 305 int rst_stream_status_field) { |
| 306 switch (version) { |
| 307 case SPDY2: |
| 308 case SPDY3: |
| 309 // PROTOCOL_ERROR is the valid first status code. |
| 310 if (rst_stream_status_field < |
| 311 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) { |
| 312 return false; |
| 313 } |
| 314 |
| 315 // FRAME_TOO_LARGE is the valid last status code. |
| 316 if (rst_stream_status_field > |
| 317 SerializeRstStreamStatus(version, RST_STREAM_FRAME_TOO_LARGE)) { |
| 318 return false; |
| 319 } |
| 320 |
| 321 return true; |
| 322 case SPDY4: |
| 323 // NO_ERROR is the first valid status code. |
| 324 if (rst_stream_status_field < |
| 325 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) { |
| 326 return false; |
| 327 } |
| 328 |
| 329 // TODO(hkhalil): Omit COMPRESSION_ERROR and SETTINGS_TIMEOUT |
| 330 /* |
| 331 // This works because GOAWAY and RST_STREAM share a namespace. |
| 332 if (rst_stream_status_field == |
| 333 SerializeGoAwayStatus(version, GOAWAY_COMPRESSION_ERROR) || |
| 334 rst_stream_status_field == |
| 335 SerializeGoAwayStatus(version, GOAWAY_SETTINGS_TIMEOUT)) { |
| 336 return false; |
| 337 } |
| 338 */ |
| 339 |
| 340 // ENHANCE_YOUR_CALM is the last valid status code. |
| 341 if (rst_stream_status_field > |
| 342 SerializeRstStreamStatus(version, RST_STREAM_ENHANCE_YOUR_CALM)) { |
| 343 return false; |
| 344 } |
| 345 |
| 346 return true; |
| 347 } |
| 348 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 349 return false; |
| 350 } |
| 351 |
| 352 SpdyRstStreamStatus SpdyConstants::ParseRstStreamStatus( |
| 353 SpdyMajorVersion version, |
| 354 int rst_stream_status_field) { |
| 355 switch (version) { |
| 356 case SPDY2: |
| 357 case SPDY3: |
| 358 switch (rst_stream_status_field) { |
| 359 case 1: |
| 360 return RST_STREAM_PROTOCOL_ERROR; |
| 361 case 2: |
| 362 return RST_STREAM_INVALID_STREAM; |
| 363 case 3: |
| 364 return RST_STREAM_REFUSED_STREAM; |
| 365 case 4: |
| 366 return RST_STREAM_UNSUPPORTED_VERSION; |
| 367 case 5: |
| 368 return RST_STREAM_CANCEL; |
| 369 case 6: |
| 370 return RST_STREAM_INTERNAL_ERROR; |
| 371 case 7: |
| 372 return RST_STREAM_FLOW_CONTROL_ERROR; |
| 373 case 8: |
| 374 return RST_STREAM_STREAM_IN_USE; |
| 375 case 9: |
| 376 return RST_STREAM_STREAM_ALREADY_CLOSED; |
| 377 case 10: |
| 378 return RST_STREAM_INVALID_CREDENTIALS; |
| 379 case 11: |
| 380 return RST_STREAM_FRAME_TOO_LARGE; |
| 381 } |
| 382 break; |
| 383 case SPDY4: |
| 384 switch (rst_stream_status_field) { |
| 385 case 1: |
| 386 return RST_STREAM_PROTOCOL_ERROR; |
| 387 case 2: |
| 388 return RST_STREAM_INTERNAL_ERROR; |
| 389 case 3: |
| 390 return RST_STREAM_FLOW_CONTROL_ERROR; |
| 391 case 5: |
| 392 return RST_STREAM_STREAM_CLOSED; |
| 393 case 6: |
| 394 return RST_STREAM_FRAME_SIZE_ERROR; |
| 395 case 7: |
| 396 return RST_STREAM_REFUSED_STREAM; |
| 397 case 8: |
| 398 return RST_STREAM_CANCEL; |
| 399 case 10: |
| 400 return RST_STREAM_CONNECT_ERROR; |
| 401 case 11: |
| 402 return RST_STREAM_ENHANCE_YOUR_CALM; |
| 403 } |
| 404 break; |
| 405 } |
| 406 |
| 407 LOG(DFATAL) << "Invalid RST_STREAM status " << rst_stream_status_field; |
| 408 return RST_STREAM_PROTOCOL_ERROR; |
| 409 } |
| 410 |
| 411 int SpdyConstants::SerializeRstStreamStatus( |
| 412 SpdyMajorVersion version, |
| 413 SpdyRstStreamStatus rst_stream_status) { |
| 414 switch (version) { |
| 415 case SPDY2: |
| 416 case SPDY3: |
| 417 switch (rst_stream_status) { |
| 418 case RST_STREAM_PROTOCOL_ERROR: |
| 419 return 1; |
| 420 case RST_STREAM_INVALID_STREAM: |
| 421 return 2; |
| 422 case RST_STREAM_REFUSED_STREAM: |
| 423 return 3; |
| 424 case RST_STREAM_UNSUPPORTED_VERSION: |
| 425 return 4; |
| 426 case RST_STREAM_CANCEL: |
| 427 return 5; |
| 428 case RST_STREAM_INTERNAL_ERROR: |
| 429 return 6; |
| 430 case RST_STREAM_FLOW_CONTROL_ERROR: |
| 431 return 7; |
| 432 case RST_STREAM_STREAM_IN_USE: |
| 433 return 8; |
| 434 case RST_STREAM_STREAM_ALREADY_CLOSED: |
| 435 return 9; |
| 436 case RST_STREAM_INVALID_CREDENTIALS: |
| 437 return 10; |
| 438 case RST_STREAM_FRAME_TOO_LARGE: |
| 439 return 11; |
| 440 default: |
| 441 LOG(DFATAL) << "Unhandled RST_STREAM status " |
| 442 << rst_stream_status; |
| 443 return -1; |
| 444 } |
| 445 case SPDY4: |
| 446 switch (rst_stream_status) { |
| 447 case RST_STREAM_PROTOCOL_ERROR: |
| 448 return 1; |
| 449 case RST_STREAM_INTERNAL_ERROR: |
| 450 return 2; |
| 451 case RST_STREAM_FLOW_CONTROL_ERROR: |
| 452 return 3; |
| 453 case RST_STREAM_STREAM_CLOSED: |
| 454 return 5; |
| 455 case RST_STREAM_FRAME_SIZE_ERROR: |
| 456 return 6; |
| 457 case RST_STREAM_REFUSED_STREAM: |
| 458 return 7; |
| 459 case RST_STREAM_CANCEL: |
| 460 return 8; |
| 461 case RST_STREAM_CONNECT_ERROR: |
| 462 return 10; |
| 463 case RST_STREAM_ENHANCE_YOUR_CALM: |
| 464 return 11; |
| 465 default: |
| 466 LOG(DFATAL) << "Unhandled RST_STREAM status " |
| 467 << rst_stream_status; |
| 468 return -1; |
| 469 } |
| 470 } |
| 471 LOG(DFATAL) << "Unhandled SPDY version " << version; |
| 472 return -1; |
| 473 } |
| 474 |
304 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { | 475 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { |
305 return visitor->VisitData(*this); | 476 return visitor->VisitData(*this); |
306 } | 477 } |
307 | 478 |
308 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { | 479 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { |
309 return visitor->VisitSynStream(*this); | 480 return visitor->VisitSynStream(*this); |
310 } | 481 } |
311 | 482 |
312 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { | 483 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { |
313 return visitor->VisitSynReply(*this); | 484 return visitor->VisitSynReply(*this); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 544 |
374 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { | 545 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { |
375 return visitor->VisitPushPromise(*this); | 546 return visitor->VisitPushPromise(*this); |
376 } | 547 } |
377 | 548 |
378 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { | 549 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { |
379 return visitor->VisitContinuation(*this); | 550 return visitor->VisitContinuation(*this); |
380 } | 551 } |
381 | 552 |
382 } // namespace net | 553 } // namespace net |
OLD | NEW |