From 4d8975e12813433b4d3227b731b312b790b91956 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Thu, 29 Jun 2017 00:45:54 +0900 Subject: [PATCH] Add ngtcp2_strerror --- lib/Makefile.am | 4 ++- lib/includes/ngtcp2/ngtcp2.h | 7 +++++ lib/ngtcp2_err.c | 50 ++++++++++++++++++++++++++++++++++++ lib/ngtcp2_err.h | 34 ++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 lib/ngtcp2_err.c create mode 100644 lib/ngtcp2_err.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 7da50fba..a42823bd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -42,7 +42,8 @@ OBJECTS = \ ngtcp2_pq.c \ ngtcp2_rob.c \ ngtcp2_ppe.c \ - ngtcp2_crypto.c + ngtcp2_crypto.c \ + ngtcp2_err.c HFILES = \ ngtcp2_pkt.h \ @@ -56,6 +57,7 @@ HFILES = \ ngtcp2_rob.h \ ngtcp2_ppe.h \ ngtcp2_crypto.h \ + ngtcp2_err.h \ ngtcp2_macro.h libngtcp2_la_SOURCES = $(HFILES) $(OBJECTS) diff --git a/lib/includes/ngtcp2/ngtcp2.h b/lib/includes/ngtcp2/ngtcp2.h index e3082f38..4683061d 100644 --- a/lib/includes/ngtcp2/ngtcp2.h +++ b/lib/includes/ngtcp2/ngtcp2.h @@ -594,6 +594,13 @@ NGTCP2_EXTERN int ngtcp2_conn_update_rx_keys(ngtcp2_conn *conn, const uint8_t *key, size_t keylen, const uint8_t *iv, size_t ivlen); +/** + * @function + * + * `ngtcp2_strerror` returns the text representation of |liberr|. + */ +NGTCP2_EXTERN const char *ngtcp2_strerror(int liberr); + #ifdef __cplusplus } #endif diff --git a/lib/ngtcp2_err.c b/lib/ngtcp2_err.c new file mode 100644 index 00000000..5490213f --- /dev/null +++ b/lib/ngtcp2_err.c @@ -0,0 +1,50 @@ +/* + * ngtcp2 + * + * Copyright (c) 2017 ngtcp2 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include "ngtcp2_err.h" + +const char *ngtcp2_strerror(int liberr) { + switch (liberr) { + case NGTCP2_ERR_INVALID_ARGUMENT: + return "ERR_INVALID_ARGUMENT"; + case NGTCP2_ERR_UNKNOWN_PKT_TYPE: + return "ERR_UNKNOWN_PKT_TYPE"; + case NGTCP2_ERR_NOBUF: + return "ERR_NOBUF"; + case NGTCP2_ERR_BAD_PKT_HASH: + return "ERR_BAD_PKT_HASH"; + case NGTCP2_ERR_PROTO: + return "ERR_PROTO"; + case NGTCP2_ERR_INVALID_STATE: + return "ERR_INVALID_STATE"; + case NGTCP2_ERR_NOMEM: + return "ERR_NOMEM"; + case NGTCP2_ERR_CALLBACK_FAILURE: + return "ERR_CALLBACK_FAILURE"; + case NGTCP2_ERR_INTERNAL: + return "ERR_INTERNAL"; + default: + return "UNKNOWN"; + } +} diff --git a/lib/ngtcp2_err.h b/lib/ngtcp2_err.h new file mode 100644 index 00000000..e9509151 --- /dev/null +++ b/lib/ngtcp2_err.h @@ -0,0 +1,34 @@ +/* + * ngtcp2 + * + * Copyright (c) 2017 ngtcp2 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef NGTCP2_ERR_H +#define NGTCP2_ERR_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#include <ngtcp2/ngtcp2.h> + +#endif /* NGTCP2_ERR_H */ -- GitLab