diff options
Diffstat (limited to 'gnu-taler-error-codes')
-rw-r--r-- | gnu-taler-error-codes/.gitignore | 5 | ||||
-rw-r--r-- | gnu-taler-error-codes/Makefile | 16 | ||||
-rw-r--r-- | gnu-taler-error-codes/c-length.template | 9 | ||||
-rw-r--r-- | gnu-taler-error-codes/c.footer | 33 | ||||
-rw-r--r-- | gnu-taler-error-codes/c.header | 47 | ||||
-rw-r--r-- | gnu-taler-error-codes/c.template | 5 | ||||
-rw-r--r-- | gnu-taler-error-codes/h.footer | 10 | ||||
-rw-r--r-- | gnu-taler-error-codes/registry.rec | 4 |
8 files changed, 127 insertions, 2 deletions
diff --git a/gnu-taler-error-codes/.gitignore b/gnu-taler-error-codes/.gitignore index 9111c0f..4331786 100644 --- a/gnu-taler-error-codes/.gitignore +++ b/gnu-taler-error-codes/.gitignore | |||
@@ -1,8 +1,13 @@ | |||
1 | taler-error-codes.h | 1 | taler-error-codes.h |
2 | taler-error-codes.c | ||
2 | taler-error-codes.ts | 3 | taler-error-codes.ts |
3 | taler-error-codes.kt | 4 | taler-error-codes.kt |
4 | 5 | ||
5 | combined.tmp | 6 | combined.tmp |
7 | combined-escaped.tmp | ||
8 | length.tmp | ||
6 | taler-error-codes.h.tmp | 9 | taler-error-codes.h.tmp |
10 | taler-error-codes.c.tmp | ||
11 | taler-error-codes-length.c.tmp | ||
7 | taler-error-codes.ts.tmp | 12 | taler-error-codes.ts.tmp |
8 | taler-error-codes.kt.tmp | 13 | taler-error-codes.kt.tmp |
diff --git a/gnu-taler-error-codes/Makefile b/gnu-taler-error-codes/Makefile index c0bb208..2837753 100644 --- a/gnu-taler-error-codes/Makefile +++ b/gnu-taler-error-codes/Makefile | |||
@@ -1,4 +1,5 @@ | |||
1 | FILES=taler-error-codes.h \ | 1 | FILES=taler-error-codes.h \ |
2 | taler-error-codes.c \ | ||
2 | taler-error-codes.ts \ | 3 | taler-error-codes.ts \ |
3 | taler-error-codes.kt | 4 | taler-error-codes.kt |
4 | all: check $(FILES) | 5 | all: check $(FILES) |
@@ -17,12 +18,27 @@ prep: | |||
17 | combined.tmp: registry.rec prep | 18 | combined.tmp: registry.rec prep |
18 | recsel -t TalerErrorCode -j HttpStatus -p Description,Name,Value,HttpStatus,HttpStatus.Value,HttpStatus.Identifier ../http-status-codes/registry.rec registry.rec > $@ | 19 | recsel -t TalerErrorCode -j HttpStatus -p Description,Name,Value,HttpStatus,HttpStatus.Value,HttpStatus.Identifier ../http-status-codes/registry.rec registry.rec > $@ |
19 | 20 | ||
21 | combined-escaped.tmp: combined.tmp | ||
22 | sed 's/"/\\"/g' $^ > $@ | ||
23 | |||
24 | length.tmp: combined.tmp | ||
25 | recsel -p "Count(Description):ECS_LENGTH" combined.tmp > $@ | ||
26 | |||
20 | taler-error-codes.h.tmp: combined.tmp h.template | 27 | taler-error-codes.h.tmp: combined.tmp h.template |
21 | ../format.sh h.template < combined.tmp > $@ | 28 | ../format.sh h.template < combined.tmp > $@ |
22 | 29 | ||
23 | taler-error-codes.h: h.header taler-error-codes.h.tmp h.footer | 30 | taler-error-codes.h: h.header taler-error-codes.h.tmp h.footer |
24 | cat $^ > $@ | 31 | cat $^ > $@ |
25 | 32 | ||
33 | taler-error-codes.c.tmp: combined-escaped.tmp c.template | ||
34 | ../format.sh c.template < combined-escaped.tmp > $@ | ||
35 | |||
36 | taler-error-codes-length.c.tmp: length.tmp c-length.template | ||
37 | ../format.sh c-length.template < length.tmp > $@ | ||
38 | |||
39 | taler-error-codes.c: c.header taler-error-codes.c.tmp taler-error-codes-length.c.tmp c.footer | ||
40 | cat $^ > $@ | ||
41 | |||
26 | taler-error-codes.ts.tmp: combined.tmp ts.template | 42 | taler-error-codes.ts.tmp: combined.tmp ts.template |
27 | ../format.sh ts.template < combined.tmp > $@ | 43 | ../format.sh ts.template < combined.tmp > $@ |
28 | 44 | ||
diff --git a/gnu-taler-error-codes/c-length.template b/gnu-taler-error-codes/c-length.template new file mode 100644 index 0000000..24e3e41 --- /dev/null +++ b/gnu-taler-error-codes/c-length.template | |||
@@ -0,0 +1,9 @@ | |||
1 | |||
2 | |||
3 | }; | ||
4 | |||
5 | |||
6 | /** | ||
7 | * The length of @e code_hint_pairs. | ||
8 | */ | ||
9 | static const unsigned int code_hint_pairs_length = {{ECS_LENGTH}}; | ||
diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer new file mode 100644 index 0000000..c348200 --- /dev/null +++ b/gnu-taler-error-codes/c.footer | |||
@@ -0,0 +1,33 @@ | |||
1 | |||
2 | |||
3 | |||
4 | /** | ||
5 | * Returns a hint for a given error code. | ||
6 | * | ||
7 | * @param ec the error code. | ||
8 | * @return the hint if it could be found, otherwise NULL. | ||
9 | */ | ||
10 | const char * | ||
11 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) | ||
12 | { | ||
13 | unsigned int lower = 0; | ||
14 | unsigned int upper = code_hint_pairs_length - 1; | ||
15 | unsigned int mid = upper / 2; | ||
16 | while (lower <= upper) | ||
17 | { | ||
18 | mid = (upper + lower) / 2; | ||
19 | if (code_hint_pairs[mid].ec < ec) | ||
20 | { | ||
21 | lower = mid + 1; | ||
22 | } | ||
23 | else if (code_hint_pairs[mid].ec > ec) | ||
24 | { | ||
25 | upper = mid - 1; | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | return code_hint_pairs[mid].hint; | ||
30 | } | ||
31 | } | ||
32 | return NULL; | ||
33 | } | ||
diff --git a/gnu-taler-error-codes/c.header b/gnu-taler-error-codes/c.header new file mode 100644 index 0000000..434bcee --- /dev/null +++ b/gnu-taler-error-codes/c.header | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | This file is part of GNU Taler | ||
3 | Copyright (C) 2012-2020 Taler Systems SA | ||
4 | |||
5 | GNU Taler is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Lesser General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNU Taler is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: LGPL3.0-or-later | ||
19 | |||
20 | Note: the LGPL does not apply to all components of GNU Taler, | ||
21 | but it does apply to this file. | ||
22 | */ | ||
23 | #include "taler-error-codes.h" | ||
24 | #include <stddef.h> | ||
25 | |||
26 | |||
27 | /** | ||
28 | * A pair containing an error code and its hint. | ||
29 | */ | ||
30 | struct ErrorCodeAndHint | ||
31 | { | ||
32 | /** | ||
33 | * The error code. | ||
34 | */ | ||
35 | enum TALER_ErrorCode ec; | ||
36 | |||
37 | /** | ||
38 | * The hint. | ||
39 | */ | ||
40 | const char *hint; | ||
41 | }; | ||
42 | |||
43 | |||
44 | /** | ||
45 | * The list of all error codes with their hints. | ||
46 | */ | ||
47 | static const struct ErrorCodeAndHint code_hint_pairs[] = { | ||
diff --git a/gnu-taler-error-codes/c.template b/gnu-taler-error-codes/c.template new file mode 100644 index 0000000..02c39ed --- /dev/null +++ b/gnu-taler-error-codes/c.template | |||
@@ -0,0 +1,5 @@ | |||
1 | |||
2 | { | ||
3 | .ec = TALER_EC_{{Name}}, | ||
4 | .hint = "{{Description}}" | ||
5 | }, | ||
diff --git a/gnu-taler-error-codes/h.footer b/gnu-taler-error-codes/h.footer index 5d32ee9..1357a9e 100644 --- a/gnu-taler-error-codes/h.footer +++ b/gnu-taler-error-codes/h.footer | |||
@@ -3,6 +3,16 @@ | |||
3 | }; | 3 | }; |
4 | 4 | ||
5 | 5 | ||
6 | /** | ||
7 | * Returns a hint for a given error code. | ||
8 | * | ||
9 | * @param ec the error code. | ||
10 | * @return the hint if it could be found, otherwise NULL. | ||
11 | */ | ||
12 | const char * | ||
13 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec); | ||
14 | |||
15 | |||
6 | #if 0 /* keep Emacsens' auto-indent happy */ | 16 | #if 0 /* keep Emacsens' auto-indent happy */ |
7 | { | 17 | { |
8 | #endif | 18 | #endif |
diff --git a/gnu-taler-error-codes/registry.rec b/gnu-taler-error-codes/registry.rec index 5fb2954..e7ca9e1 100644 --- a/gnu-taler-error-codes/registry.rec +++ b/gnu-taler-error-codes/registry.rec | |||
@@ -74,7 +74,7 @@ HttpStatus: 0 | |||
74 | 74 | ||
75 | Value: 10 | 75 | Value: 10 |
76 | Name: ENDPOINT_UNKNOWN | 76 | Name: ENDPOINT_UNKNOWN |
77 | Description: There is no endpoint defined for the URL provided by the client ( | 77 | Description: There is no endpoint defined for the URL provided by the client. |
78 | HttpStatus: 404 | 78 | HttpStatus: 404 |
79 | 79 | ||
80 | Value: 11 | 80 | Value: 11 |
@@ -84,7 +84,7 @@ HttpStatus: 414 | |||
84 | 84 | ||
85 | Value: 12 | 85 | Value: 12 |
86 | Name: WRONG_NUMBER_OF_SEGMENTS | 86 | Name: WRONG_NUMBER_OF_SEGMENTS |
87 | Description: The number of segments included in the URI does not match the number of segments expected by the endpoint. ( | 87 | Description: The number of segments included in the URI does not match the number of segments expected by the endpoint. |
88 | HttpStatus: 404 | 88 | HttpStatus: 404 |
89 | 89 | ||
90 | Value: 13 | 90 | Value: 13 |