Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #include "src/core/transport/chttp2/status_conversion.h"
35 :
36 280531 : int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) {
37 280531 : switch (status) {
38 : case GRPC_STATUS_OK:
39 1773 : return GRPC_CHTTP2_NO_ERROR;
40 : case GRPC_STATUS_CANCELLED:
41 278335 : return GRPC_CHTTP2_CANCEL;
42 : case GRPC_STATUS_RESOURCE_EXHAUSTED:
43 1 : return GRPC_CHTTP2_ENHANCE_YOUR_CALM;
44 : case GRPC_STATUS_PERMISSION_DENIED:
45 1 : return GRPC_CHTTP2_INADEQUATE_SECURITY;
46 : case GRPC_STATUS_UNAVAILABLE:
47 61 : return GRPC_CHTTP2_REFUSED_STREAM;
48 : default:
49 360 : return GRPC_CHTTP2_INTERNAL_ERROR;
50 : }
51 : }
52 :
53 5741 : grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
54 : grpc_chttp2_error_code error) {
55 5741 : switch (error) {
56 : case GRPC_CHTTP2_NO_ERROR:
57 : /* should never be received */
58 241 : return GRPC_STATUS_INTERNAL;
59 : case GRPC_CHTTP2_CANCEL:
60 5433 : return GRPC_STATUS_CANCELLED;
61 : case GRPC_CHTTP2_ENHANCE_YOUR_CALM:
62 1 : return GRPC_STATUS_RESOURCE_EXHAUSTED;
63 : case GRPC_CHTTP2_INADEQUATE_SECURITY:
64 1 : return GRPC_STATUS_PERMISSION_DENIED;
65 : case GRPC_CHTTP2_REFUSED_STREAM:
66 1 : return GRPC_STATUS_UNAVAILABLE;
67 : default:
68 64 : return GRPC_STATUS_INTERNAL;
69 : }
70 : }
71 :
72 1012 : grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
73 1012 : switch (status) {
74 : /* these HTTP2 status codes are called out explicitly in status.proto */
75 : case 200:
76 2 : return GRPC_STATUS_OK;
77 : case 400:
78 2 : return GRPC_STATUS_INVALID_ARGUMENT;
79 : case 401:
80 2 : return GRPC_STATUS_UNAUTHENTICATED;
81 : case 403:
82 2 : return GRPC_STATUS_PERMISSION_DENIED;
83 : case 404:
84 2 : return GRPC_STATUS_NOT_FOUND;
85 : case 409:
86 2 : return GRPC_STATUS_ABORTED;
87 : case 412:
88 2 : return GRPC_STATUS_FAILED_PRECONDITION;
89 : case 429:
90 2 : return GRPC_STATUS_RESOURCE_EXHAUSTED;
91 : case 499:
92 2 : return GRPC_STATUS_CANCELLED;
93 : case 500:
94 2 : return GRPC_STATUS_UNKNOWN;
95 : case 501:
96 1 : return GRPC_STATUS_UNIMPLEMENTED;
97 : case 503:
98 2 : return GRPC_STATUS_UNAVAILABLE;
99 : case 504:
100 2 : return GRPC_STATUS_DEADLINE_EXCEEDED;
101 : /* everything else is unknown */
102 : default:
103 987 : return GRPC_STATUS_UNKNOWN;
104 : }
105 : }
106 :
107 17 : int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) {
108 17 : return 200;
109 : }
|