11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * nghttp3
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Copyright (c) 2019 nghttp3 contributors
51cb0ef41Sopenharmony_ci *
61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the
81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
121cb0ef41Sopenharmony_ci * the following conditions:
131cb0ef41Sopenharmony_ci *
141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be
151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software.
161cb0ef41Sopenharmony_ci *
171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
241cb0ef41Sopenharmony_ci */
251cb0ef41Sopenharmony_ci#include "nghttp3_err.h"
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciconst char *nghttp3_strerror(int liberr) {
281cb0ef41Sopenharmony_ci  switch (liberr) {
291cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_INVALID_ARGUMENT:
301cb0ef41Sopenharmony_ci    return "ERR_INVALID_ARGUMENT";
311cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_NOBUF:
321cb0ef41Sopenharmony_ci    return "ERR_NOBUF";
331cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_INVALID_STATE:
341cb0ef41Sopenharmony_ci    return "ERR_INVALID_STATE";
351cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_WOULDBLOCK:
361cb0ef41Sopenharmony_ci    return "ERR_WOULDBLOCK";
371cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_STREAM_IN_USE:
381cb0ef41Sopenharmony_ci    return "ERR_STREAM_IN_USE";
391cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
401cb0ef41Sopenharmony_ci    return "ERR_MALFORMED_HTTP_HEADER";
411cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_REMOVE_HTTP_HEADER:
421cb0ef41Sopenharmony_ci    return "ERR_REMOVE_HTTP_HEADER";
431cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
441cb0ef41Sopenharmony_ci    return "ERR_MALFORMED_HTTP_MESSAGING";
451cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_FATAL:
461cb0ef41Sopenharmony_ci    return "ERR_QPACK_FATAL";
471cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
481cb0ef41Sopenharmony_ci    return "ERR_QPACK_HEADER_TOO_LARGE";
491cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_STREAM_NOT_FOUND:
501cb0ef41Sopenharmony_ci    return "ERR_STREAM_NOT_FOUND";
511cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_CONN_CLOSING:
521cb0ef41Sopenharmony_ci    return "ERR_CONN_CLOSING";
531cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
541cb0ef41Sopenharmony_ci    return "ERR_STREAM_DATA_OVERFLOW";
551cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
561cb0ef41Sopenharmony_ci    return "ERR_QPACK_DECOMPRESSION_FAILED";
571cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
581cb0ef41Sopenharmony_ci    return "ERR_QPACK_ENCODER_STREAM_ERROR";
591cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
601cb0ef41Sopenharmony_ci    return "ERR_QPACK_DECODER_STREAM_ERROR";
611cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
621cb0ef41Sopenharmony_ci    return "ERR_H3_FRAME_UNEXPECTED";
631cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_FRAME_ERROR:
641cb0ef41Sopenharmony_ci    return "ERR_H3_FRAME_ERROR";
651cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_MISSING_SETTINGS:
661cb0ef41Sopenharmony_ci    return "ERR_H3_MISSING_SETTINGS";
671cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_INTERNAL_ERROR:
681cb0ef41Sopenharmony_ci    return "ERR_H3_INTERNAL_ERROR";
691cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
701cb0ef41Sopenharmony_ci    return "ERR_CLOSED_CRITICAL_STREAM";
711cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
721cb0ef41Sopenharmony_ci    return "ERR_H3_GENERAL_PROTOCOL_ERROR";
731cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_ID_ERROR:
741cb0ef41Sopenharmony_ci    return "ERR_H3_ID_ERROR";
751cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_SETTINGS_ERROR:
761cb0ef41Sopenharmony_ci    return "ERR_H3_SETTINGS_ERROR";
771cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
781cb0ef41Sopenharmony_ci    return "ERR_H3_STREAM_CREATION_ERROR";
791cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_NOMEM:
801cb0ef41Sopenharmony_ci    return "ERR_NOMEM";
811cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_CALLBACK_FAILURE:
821cb0ef41Sopenharmony_ci    return "ERR_CALLBACK_FAILURE";
831cb0ef41Sopenharmony_ci  default:
841cb0ef41Sopenharmony_ci    return "(unknown)";
851cb0ef41Sopenharmony_ci  }
861cb0ef41Sopenharmony_ci}
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ciuint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
891cb0ef41Sopenharmony_ci  switch (liberr) {
901cb0ef41Sopenharmony_ci  case 0:
911cb0ef41Sopenharmony_ci    return NGHTTP3_H3_NO_ERROR;
921cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
931cb0ef41Sopenharmony_ci    return NGHTTP3_QPACK_DECOMPRESSION_FAILED;
941cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
951cb0ef41Sopenharmony_ci    return NGHTTP3_QPACK_ENCODER_STREAM_ERROR;
961cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
971cb0ef41Sopenharmony_ci    return NGHTTP3_QPACK_DECODER_STREAM_ERROR;
981cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
991cb0ef41Sopenharmony_ci    return NGHTTP3_H3_FRAME_UNEXPECTED;
1001cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_FRAME_ERROR:
1011cb0ef41Sopenharmony_ci    return NGHTTP3_H3_FRAME_ERROR;
1021cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_MISSING_SETTINGS:
1031cb0ef41Sopenharmony_ci    return NGHTTP3_H3_MISSING_SETTINGS;
1041cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_INTERNAL_ERROR:
1051cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_NOMEM:
1061cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_CALLBACK_FAILURE:
1071cb0ef41Sopenharmony_ci    return NGHTTP3_H3_INTERNAL_ERROR;
1081cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
1091cb0ef41Sopenharmony_ci    return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;
1101cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
1111cb0ef41Sopenharmony_ci    return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
1121cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_ID_ERROR:
1131cb0ef41Sopenharmony_ci    return NGHTTP3_H3_ID_ERROR;
1141cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_SETTINGS_ERROR:
1151cb0ef41Sopenharmony_ci    return NGHTTP3_H3_SETTINGS_ERROR;
1161cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
1171cb0ef41Sopenharmony_ci    return NGHTTP3_H3_STREAM_CREATION_ERROR;
1181cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
1191cb0ef41Sopenharmony_ci  case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
1201cb0ef41Sopenharmony_ci    return NGHTTP3_H3_MESSAGE_ERROR;
1211cb0ef41Sopenharmony_ci  default:
1221cb0ef41Sopenharmony_ci    return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
1231cb0ef41Sopenharmony_ci  }
1241cb0ef41Sopenharmony_ci}
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ciint nghttp3_err_is_fatal(int liberr) { return liberr < NGHTTP3_ERR_FATAL; }
127