• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * nghttp3
3  *
4  * Copyright (c) 2019 nghttp3 contributors
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #include "nghttp3_err.h"
26 
nghttp3_strerror(int liberr)27 const char *nghttp3_strerror(int liberr) {
28   switch (liberr) {
29   case NGHTTP3_ERR_INVALID_ARGUMENT:
30     return "ERR_INVALID_ARGUMENT";
31   case NGHTTP3_ERR_NOBUF:
32     return "ERR_NOBUF";
33   case NGHTTP3_ERR_INVALID_STATE:
34     return "ERR_INVALID_STATE";
35   case NGHTTP3_ERR_WOULDBLOCK:
36     return "ERR_WOULDBLOCK";
37   case NGHTTP3_ERR_STREAM_IN_USE:
38     return "ERR_STREAM_IN_USE";
39   case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
40     return "ERR_MALFORMED_HTTP_HEADER";
41   case NGHTTP3_ERR_REMOVE_HTTP_HEADER:
42     return "ERR_REMOVE_HTTP_HEADER";
43   case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
44     return "ERR_MALFORMED_HTTP_MESSAGING";
45   case NGHTTP3_ERR_QPACK_FATAL:
46     return "ERR_QPACK_FATAL";
47   case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
48     return "ERR_QPACK_HEADER_TOO_LARGE";
49   case NGHTTP3_ERR_STREAM_NOT_FOUND:
50     return "ERR_STREAM_NOT_FOUND";
51   case NGHTTP3_ERR_CONN_CLOSING:
52     return "ERR_CONN_CLOSING";
53   case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
54     return "ERR_STREAM_DATA_OVERFLOW";
55   case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
56     return "ERR_QPACK_DECOMPRESSION_FAILED";
57   case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
58     return "ERR_QPACK_ENCODER_STREAM_ERROR";
59   case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
60     return "ERR_QPACK_DECODER_STREAM_ERROR";
61   case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
62     return "ERR_H3_FRAME_UNEXPECTED";
63   case NGHTTP3_ERR_H3_FRAME_ERROR:
64     return "ERR_H3_FRAME_ERROR";
65   case NGHTTP3_ERR_H3_MISSING_SETTINGS:
66     return "ERR_H3_MISSING_SETTINGS";
67   case NGHTTP3_ERR_H3_INTERNAL_ERROR:
68     return "ERR_H3_INTERNAL_ERROR";
69   case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
70     return "ERR_CLOSED_CRITICAL_STREAM";
71   case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
72     return "ERR_H3_GENERAL_PROTOCOL_ERROR";
73   case NGHTTP3_ERR_H3_ID_ERROR:
74     return "ERR_H3_ID_ERROR";
75   case NGHTTP3_ERR_H3_SETTINGS_ERROR:
76     return "ERR_H3_SETTINGS_ERROR";
77   case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
78     return "ERR_H3_STREAM_CREATION_ERROR";
79   case NGHTTP3_ERR_NOMEM:
80     return "ERR_NOMEM";
81   case NGHTTP3_ERR_CALLBACK_FAILURE:
82     return "ERR_CALLBACK_FAILURE";
83   default:
84     return "(unknown)";
85   }
86 }
87 
nghttp3_err_infer_quic_app_error_code(int liberr)88 uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
89   switch (liberr) {
90   case 0:
91     return NGHTTP3_H3_NO_ERROR;
92   case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
93     return NGHTTP3_QPACK_DECOMPRESSION_FAILED;
94   case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
95     return NGHTTP3_QPACK_ENCODER_STREAM_ERROR;
96   case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
97     return NGHTTP3_QPACK_DECODER_STREAM_ERROR;
98   case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
99     return NGHTTP3_H3_FRAME_UNEXPECTED;
100   case NGHTTP3_ERR_H3_FRAME_ERROR:
101     return NGHTTP3_H3_FRAME_ERROR;
102   case NGHTTP3_ERR_H3_MISSING_SETTINGS:
103     return NGHTTP3_H3_MISSING_SETTINGS;
104   case NGHTTP3_ERR_H3_INTERNAL_ERROR:
105   case NGHTTP3_ERR_NOMEM:
106   case NGHTTP3_ERR_CALLBACK_FAILURE:
107     return NGHTTP3_H3_INTERNAL_ERROR;
108   case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
109     return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;
110   case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
111     return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
112   case NGHTTP3_ERR_H3_ID_ERROR:
113     return NGHTTP3_H3_ID_ERROR;
114   case NGHTTP3_ERR_H3_SETTINGS_ERROR:
115     return NGHTTP3_H3_SETTINGS_ERROR;
116   case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
117     return NGHTTP3_H3_STREAM_CREATION_ERROR;
118   case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
119   case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
120     return NGHTTP3_H3_MESSAGE_ERROR;
121   default:
122     return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
123   }
124 }
125 
nghttp3_err_is_fatal(int liberr)126 int nghttp3_err_is_fatal(int liberr) { return liberr < NGHTTP3_ERR_FATAL; }
127