gana

GNUnet Assigned Numbers Authority
Log | Files | Refs | README | LICENSE

commit 0a783e357d2f252cae9e7596319eced422537cb6
parent 9657bf77de05c0ac17ff39629306a604066b21de
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sun, 23 Oct 2022 14:57:53 +0900

add gnunet error codes

Diffstat:
Agnunet-error-codes/Makefile | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/c-length.template | 9+++++++++
Agnunet-error-codes/c.footer | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/c.header | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/c.template | 6++++++
Agnunet-error-codes/go.footer | 1+
Agnunet-error-codes/go.header | 23+++++++++++++++++++++++
Agnunet-error-codes/go.template | 7+++++++
Agnunet-error-codes/h.footer | 45+++++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/h.header | 43+++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/h.template | 7+++++++
Agnunet-error-codes/registry.rec | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agnunet-error-codes/rst.footer | 0
Agnunet-error-codes/rst.header | 4++++
Agnunet-error-codes/rst.template | 10++++++++++
Agnunet-error-codes/ts.footer | 3+++
Agnunet-error-codes/ts.header | 21+++++++++++++++++++++
Agnunet-error-codes/ts.template | 7+++++++
18 files changed, 485 insertions(+), 0 deletions(-)

diff --git a/gnunet-error-codes/Makefile b/gnunet-error-codes/Makefile @@ -0,0 +1,68 @@ +FILES=gnunet_error_codes.h \ + gnunet_error_codes.c \ + gnunet_error_codes.ts \ + gnunet_error_codes.go \ + gnunet_error_codes.rst + +all: check $(FILES) + +check: registry.rec + recfix --check registry.rec + +distclean: + rm -f *.tmp + +clean: + rm -f $(FILES) *.tmp + +prep: + cd ../http-status-codes; make ; cd - + +# Because prep is phony, this rule always triggers. To avoid +# combined.tmp cascading into triggering the other rules even +# if nothing changed, we use 'diff' to make sure that 'recsel' +# actually changed the result. +combined.tmp: registry.rec prep + recsel -t GnunetErrorCode -j HttpStatus -p Description,Name,Value,HttpStatus,HttpStatus.Value,HttpStatus.Identifier ../http-status-codes/registry.rec registry.rec > combined.xtmp + if ! diff $@ combined.xtmp > /dev/null; then mv combined.xtmp $@; else rm combined.xtmp; fi + +combined-escaped.tmp: combined.tmp + sed 's/"/\\"/g' $^ > $@ + +length.tmp: combined.tmp + recsel -p "Count(Description):ECS_LENGTH" combined.tmp > $@ + +gnunet_error_codes.h.tmp: combined.tmp h.template + ../format.sh h.template < combined.tmp > $@ + +gnunet_error_codes.h: h.header gnunet_error_codes.h.tmp h.footer + cat $^ > $@ + +gnunet_error_codes.c.tmp: combined-escaped.tmp c.template + ../format.sh c.template < combined-escaped.tmp > $@ + +gnunet_error_codes-length.c.tmp: length.tmp c-length.template + ../format.sh c-length.template < length.tmp > $@ + +gnunet_error_codes.c: c.header gnunet_error_codes.c.tmp gnunet_error_codes-length.c.tmp c.footer + cat $^ > $@ + +gnunet_error_codes.ts.tmp: combined.tmp ts.template + ../format.sh ts.template < combined.tmp > $@ + +gnunet_error_codes.ts: ts.header gnunet_error_codes.ts.tmp ts.footer + cat $^ > $@ + +gnunet_error_codes.go.tmp: combined.tmp go.template + ../format.sh go.template < combined.tmp > $@ + +gnunet_error_codes.go: go.header gnunet_error_codes.go.tmp go.footer + cat $^ > $@ + +gnunet_error_codes.rst.tmp: combined.tmp rst.template + ../format.sh rst.template < combined.tmp > $@ + +gnunet_error_codes.rst: rst.header gnunet_error_codes.rst.tmp rst.footer + cat $^ > $@ + +.PHONY: check clean distclean prep diff --git a/gnunet-error-codes/c-length.template b/gnunet-error-codes/c-length.template @@ -0,0 +1,9 @@ + + +}; + + +/** + * The length of @e code_hint_pairs. + */ +static const unsigned int code_hint_pairs_length = {{ECS_LENGTH}}; diff --git a/gnunet-error-codes/c.footer b/gnunet-error-codes/c.footer @@ -0,0 +1,66 @@ + + + +const char * +GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec) +{ + unsigned int lower = 0; + unsigned int upper = code_hint_pairs_length - 1; + unsigned int mid = upper / 2; + while (lower <= upper) + { + mid = (upper + lower) / 2; + if (code_hint_pairs[mid].ec < ec) + { + lower = mid + 1; + } + else if (code_hint_pairs[mid].ec > ec) + { + upper = mid - 1; + } + else + { + return code_hint_pairs[mid].hint; + } + } + return "<no hint found>"; +} + + +unsigned int +GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec) +{ + unsigned int lower = 0; + unsigned int upper = code_hint_pairs_length - 1; + unsigned int mid = upper / 2; + while (lower <= upper) + { + mid = (upper + lower) / 2; + if (code_hint_pairs[mid].ec < ec) + { + lower = mid + 1; + } + else if (code_hint_pairs[mid].ec > ec) + { + upper = mid - 1; + } + else + { + return code_hint_pairs[mid].http_code; + } + } + return UINT_MAX; +} + + +unsigned int +GNUNET_ErrorCode_get_http_status_safe (enum GNUNET_ErrorCode ec) +{ + unsigned int hc; + + hc = GNUNET_ErrorCode_get_http_status (ec); + if ( (0 == hc) || + (UINT_MAX == hc) ) + return MHD_HTTP_INTERNAL_SERVER_ERROR; + return hc; +} diff --git a/gnunet-error-codes/c.header b/gnunet-error-codes/c.header @@ -0,0 +1,55 @@ +/* + This file is part of GNUnet + Copyright (C) 2012-2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +#include "gnunet_error_codes.h" +#include <stddef.h> +#include <microhttpd.h> +#include <gettext.h> + +/** + * MHD does not define our value for 0 (client-side generated code). + */ +#define MHD_HTTP_UNINITIALIZED 0 + +/** + * A pair containing an error code and its hint. + */ +struct ErrorCodeAndHint +{ + /** + * The error code. + */ + enum GNUNET_ErrorCode ec; + + /** + * The hint. + */ + const char *hint; + + /** + * The HTTP status code. + */ + unsigned int http_code; +}; + + +/** + * The list of all error codes with their hints. + */ +static const struct ErrorCodeAndHint code_hint_pairs[] = { diff --git a/gnunet-error-codes/c.template b/gnunet-error-codes/c.template @@ -0,0 +1,6 @@ + + { + .ec = GNUNET_EC_{{Name}}, + .hint = gettext_noop ("{{Description}}"), + .http_code = MHD_HTTP_{{HttpStatus_Identifier}} + }, diff --git a/gnunet-error-codes/go.footer b/gnunet-error-codes/go.footer @@ -0,0 +1 @@ +) diff --git a/gnunet-error-codes/go.header b/gnunet-error-codes/go.header @@ -0,0 +1,23 @@ +/* + This file is part of GNUnet + Copyright (C) 2012-2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +package gana + +const ( diff --git a/gnunet-error-codes/go.template b/gnunet-error-codes/go.template @@ -0,0 +1,7 @@ + + + /** + * {{Description}} + * Returned with an HTTP status code of #MHD_HTTP_{{HttpStatus_Identifier}} ({{HttpStatus_Value}}). + */ + {{Name}} = {{Value}} diff --git a/gnunet-error-codes/h.footer b/gnunet-error-codes/h.footer @@ -0,0 +1,45 @@ + + +}; + + +/** + * Returns a hint for a given error code. + * + * @param ec the error code. + * @return the hint if it could be found, otherwise "<no hint found>" + */ +const char * +GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec); + + +/** + * Return HTTP status for a given error code. + * + * @param ec the error code. + * @return the HTTP status code for the given @a ec, UINT_MAX if not found + */ +unsigned int +GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec); + + +/** + * Return HTTP status for a given error code that is guaranteed + * to work (no corner cases). + * + * @param ec the error code. + * @return the HTTP status code for the given @a ec, 500 if + * the @a ec is not found or is a client-side code + */ +unsigned int +GNUNET_ErrorCode_get_http_status_safe (enum GNUNET_ErrorCode ec); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/gnunet-error-codes/h.header b/gnunet-error-codes/h.header @@ -0,0 +1,43 @@ +/* + This file is part of GNUnet + Copyright (C) 2012-2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ + /** + * @file include/taler_error_codes.h + * @brief GNUnet error codes, generated via https://gana.gnunet.org/ + * + * Do NOT edit this file, it is generated! + */ +#ifndef GNUNET_ERROR_CODES_H +#define GNUNET_ERROR_CODES_H + +#ifdef __cplusplus +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include <limits.h> + + +/** + * Taler error codes. + */ +enum GNUNET_ErrorCode +{ diff --git a/gnunet-error-codes/h.template b/gnunet-error-codes/h.template @@ -0,0 +1,7 @@ + + + /** + * {{Description}} + * Returned with an HTTP status code of #MHD_HTTP_{{HttpStatus_Identifier}} ({{HttpStatus_Value}}). + */ + GNUNET_EC_{{Name}} = {{Value}}, diff --git a/gnunet-error-codes/registry.rec b/gnunet-error-codes/registry.rec @@ -0,0 +1,110 @@ +# -*- mode: rec -*- +# +# Registry for GNUnet errors. +# +%rec: GnunetErrorCode +%key: Value +%typedef: ValueRange_t range 0 9999 +%constraint: ( Value < 100 ) || ( Value > 999 ) +%type: Value ValueRange_t +%mandatory: Value +%typedef: Description_t regexp |^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\(\)\.,;!"':#\/ -]*$| +%type: Description Description_t +%mandatory: Description +%typedef: Name_t regexp /^[ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*$/ +%type: Name Name_t +%unique: Name +%mandatory: Name +# A status of 0 means no HTTP status is associated +%type: HttpStatus rec HttpStatusCode +%mandatory: HttpStatus +%sort: Value + +Value: 0 +Name: NONE +Description: No error (success). +HttpStatus: 0 + +# NAMESTORE Error Codes + +Value: 5000 +Name: NAMESTORE_UNKNOWN +Description: Unknown namestore error. +HttpStatus: 500 + +Value: 5001 +Name: NAMESTORE_ITERATION_FAILED +Description: Zone iteration failed. +HttpStatus: 500 + +Value: 5002 +Name: NAMESTORE_ZONE_NOT_FOUND +Description: Zone not found. +HttpStatus: 404 + +Value: 5003 +Name: NAMESTORE_RECORD_NOT_FOUND +Description: Record not found. +HttpStatus: 404 + +Value: 5004 +Name: NAMESTORE_RECORD_DELETE_FAILED +Description: Zone iteration failed. +HttpStatus: 500 + +Value: 5005 +Name: NAMESTORE_ZONE_EMPTY +Description: Zone does not contain any records. +HttpStatus: 404 + +Value: 5006 +Name: NAMESTORE_LOOKUP_ERROR +Description: Failed to lookup record. +HttpStatus: 500 + +Value: 5007 +Name: NAMESTORE_NO_RECORDS_GIVEN +Description: No records given. +HttpStatus: 400 + +Value: 5008 +Name: NAMESTORE_RECORD_DATA_INVALID +Description: Record data invalid. +HttpStatus: 400 + +Value: 5009 +Name: NAMESTORE_NO_LABEL_GIVEN +Description: No label given. +HttpStatus: 400 + +Value: 5010 +Name: NAMESTORE_NO_RESULTS +Description: No results given. +HttpStatus: 404 + +Value: 5011 +Name: NAMESTORE_RECORD_EXISTS +Description: Record already exists. +HttpStatus: 409 + +Value: 5012 +Name: NAMESTORE_RECORD_TOO_BIG +Description: Record size exceeds maximum limit. +HttpStatus: 500 + +Value: 5013 +Name: NAMESTORE_BACKEND_FAILED +Description: There was an error in the database backend. +HttpStatus: 500 + +Value: 5014 +Name: NAMESTORE_STORE_FAILED +Description: Failed to store the given records. +HttpStatus: 500 + +Value: 5015 +Name: NAMESTORE_LABEL_INVALID +Description: Label invalid or malformed. +HttpStatus: 400 + + diff --git a/gnunet-error-codes/rst.footer b/gnunet-error-codes/rst.footer diff --git a/gnunet-error-codes/rst.header b/gnunet-error-codes/rst.header @@ -0,0 +1,4 @@ +Registry for GNUnet error codes +------------------------------- + + diff --git a/gnunet-error-codes/rst.template b/gnunet-error-codes/rst.template @@ -0,0 +1,10 @@ + + +=================== =========================================================== + GNUNET_EC_{{Name}} +------------------- ----------------------------------------------------------- +Value {{Value}} +HTTP Status Code {{HttpStatus_Value}} +Description {{Description}} +=================== =========================================================== + diff --git a/gnunet-error-codes/ts.footer b/gnunet-error-codes/ts.footer @@ -0,0 +1,3 @@ + + +} diff --git a/gnunet-error-codes/ts.header b/gnunet-error-codes/ts.header @@ -0,0 +1,21 @@ +/* + This file is part of GNUnet + Copyright (C) 2012-2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ + +export enum GnunetErrorCode { diff --git a/gnunet-error-codes/ts.template b/gnunet-error-codes/ts.template @@ -0,0 +1,7 @@ + + + /** + * {{Description}} + * Returned with an HTTP status code of #MHD_HTTP_{{HttpStatus_Identifier}} ({{HttpStatus_Value}}). + */ + {{Name}} = {{Value}},