Estonian ID Card C-library
DigiDocError.h
1 #ifndef __DIGI_DOC_ERROR_H__
2 #define __DIGI_DOC_ERROR_H__
3 //==================================================
4 // FILE: DigiDocError.h
5 // PROJECT: Digi Doc
6 // DESCRIPTION: Digi Doc error codes and functions
7 // AUTHOR: Veiko Sinivee, S|E|B IT Partner Estonia
8 //==================================================
9 // Copyright (C) AS Sertifitseerimiskeskus
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.ode
18 // GNU Lesser General Public Licence is available at
19 // http://www.gnu.org/copyleft/lesser.html
20 //==========< HISTORY >=============================
21 //==================================================
22 
23 #ifdef WIN32
24  #include <windows.h>
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 //==========< error codes >=======================
32 
33 #define ERR_OK 0
34 #define ERR_UNSUPPORTED_DIGEST 1
35 #define ERR_FILE_READ 2
36 #define ERR_FILE_WRITE 3
37 #define ERR_DIGEST_LEN 4
38 #define ERR_BUF_LEN 5
39 #define ERR_SIGNATURE_LEN 6
40 #define ERR_PRIVKEY_READ 7
41 #define ERR_PUBKEY_READ 8
42 #define ERR_CERT_READ 9
43 #define ERR_SIGNEDINFO_CREATE 10
44 #define ERR_SIGNEDINFO_DATA 11
45 #define ERR_SIGNEDINFO_FINAL 12
46 #define ERR_UNSUPPORTED_FORMAT 13
47 #define ERR_BAD_INDEX 14
48 #define ERR_TIMESTAMP_DECODE 15
49 #define ERR_DIGIDOC_PARSE 16
50 #define ERR_UNSUPPORTED_SIGNATURE 17
51 #define ERR_CERT_STORE_READ 18
52 #define ERR_SIGPROP_DIGEST 19
53 #define ERR_COMPARE 20
54 #define ERR_DOC_DIGEST 21
55 #define ERR_MIME_DIGEST 22
56 #define ERR_SIGNATURE 23
57 #define ERR_CERT_INVALID 24
58 #define ERR_OCSP_UNSUCCESSFUL 25
59 #define ERR_OCSP_UNKNOWN_TYPE 26
60 #define ERR_OCSP_NO_BASIC_RESP 27
61 #define ERR_OCSP_WRONG_VERSION 28
62 #define ERR_OCSP_WRONG_RESPID 29
63 #define ERR_OCSP_ONE_RESPONSE 30
64 #define ERR_OCSP_RESP_STATUS 31
65 #define ERR_OCSP_NO_SINGLE_EXT 32
66 #define ERR_OCSP_NO_NONCE 33
67 #define ERR_NOTARY_NO_SIGNATURE 34
68 #define ERR_NOTARY_SIG_MATCH 35
69 #define ERR_SIGNERS_CERT_NOT_TRUSTED 36
70 
71 #define ERR_WRONG_CERT 37
72 #define ERR_NULL_POINTER 38
73 #define ERR_NULL_CERT_POINTER 39
74 #define ERR_NULL_SER_NUM_POINTER 40
75 #define ERR_NULL_KEY_POINTER 41
76 #define ERR_EMPTY_STRING 42
77 #define ERR_BAD_DATAFILE_INDEX 43
78 #define ERR_BAD_DATAFILE_COUNT 44
79 #define ERR_BAD_ATTR_COUNT 45
80 #define ERR_BAD_ATTR_INDEX 46
81 #define ERR_BAD_SIG_INDEX 47
82 #define ERR_BAD_SIG_COUNT 48
83 #define ERR_BAD_ROLE_INDEX 49
84 #define ERR_BAD_DOCINFO_COUNT 50
85 #define ERR_BAD_DOCINFO_INDEX 51
86 #define ERR_BAD_NOTARY_INDEX 52
87 #define ERR_BAD_NOTARY_ID 53
88 #define ERR_BAD_NOTARY_COUNT 54
89 #define ERR_X509_DIGEST 55
90 #define ERR_CERT_LENGTH 56
91 #define ERR_PKCS_LIB_LOAD 57
92 #define ERR_PKCS_SLOT_LIST 58
93 #define ERR_PKCS_WRONG_SLOT 59
94 #define ERR_PKCS_LOGIN 60
95 #define ERR_PKCS_PK 61
96 #define ERR_PKCS_CERT_LOC 62
97 #define ERR_PKCS_CERT_DECODE 63
98 #define ERR_PKCS_SIGN_DATA 64
99 #define ERR_PKCS_CARD_READ 65
100 #define ERR_CSP_NO_CARD_DATA 66
101 #define ERR_CSP_OPEN_STORE 67
102 #define ERR_CSP_CERT_FOUND 68
103 #define ERR_CSP_SIGN 69
104 #define ERR_CSP_NO_HASH_START 70
105 #define ERR_CSP_NO_HASH 71
106 #define ERR_CSP_NO_HASH_RESULT 72
107 #define ERR_CSP_OPEN_KEY 73
108 #define ERR_CSP_READ_KEY 74
109 #define ERR_OCSP_SIGN_NOT_SUPPORTED 75
110 #define ERR_OCSP_SIGN_CSP_NAME 76
111 #define ERR_CSP_CERT_DECODE 77
112 #define ERR_OCSP_SIGN_PKCS_NAME 78
113 #define ERR_OCSP_SIGN_OSLL_CERT 79
114 #define ERR_OCSP_SIGN 80
115 #define ERR_CERT_ISSUER 81
116 #define ERR_OCSP_PKCS12_CONTAINER 82
117 #define ERR_MODIFY_SIGNED_DOC 83
118 #define ERR_NOTARY_EXISTS 84
119 #define ERR_UNSUPPORTED_CERT_SEARCH 85
120 #define ERR_INCORRECT_CERT_SEARCH 86
121 #define ERR_BAD_OCSP_RESPONSE_DIGEST 87
122 #define ERR_LAST_ESTID_CACHED 88
123 #define ERR_BAD_DATAFILE_XML 89
124 #define ERR_UNSUPPORTED_VERSION 90
125 #define ERR_UNSUPPORTED_CHARSET 91
126 #define ERR_PKCS12_EXPIRED 92
127 #define ERR_CSP_USER_CANCEL 93
128 #define ERR_CSP_NODEFKEY_CONTAINER 94
129 #define ERR_CONNECTION_FAILURE 95
130 #define ERR_WRONG_URL_OR_PROXY 96
131 #define ERR_NULL_PARAM 97
132 #define ERR_BAD_ALLOC 98
133 #define ERR_CONF_FILE 99
134 #define ERR_CONF_LINE 100
135 #define ERR_OCSP_CERT_REVOKED 101
136 #define ERR_OCSP_CERT_UNKNOWN 102
137 #define ERR_OCSP_PKCS12_NO_FILE 103
138 #define ERR_OCSP_PKCS12_NO_PASSWD 104
139 #define ERR_BAD_DATAFILE_CONTENT_TYPE 105
140 #define ERR_OCSP_WRONG_URL 106
141 #define ERR_OCSP_MALFORMED 107
142 #define ERR_OCSP_INTERNALERR 108
143 #define ERR_OCSP_TRYLATER 109
144 #define ERR_OCSP_SIGREQUIRED 110
145 #define ERR_OCSP_UNAUTHORIZED 111
146 #define ERR_UNKNOWN_CA 112
147 // DigiDocEnc errors
148 #define ERR_DENC_ENC_METHOD 113
149 #define ERR_DENC_ENC_XMLNS 114
150 #define ERR_DENC_BAD_PROP_IDX 115
151 #define ERR_DENC_BAD_KEY_IDX 116
152 #define ERR_DENC_KEY_STATUS 117
153 #define ERR_DENC_DATA_STATUS 118
154 #define ERR_DENC_DECRYPT 119
155 #define ERR_CHARSET_CONVERT 120
156 #define ERR_COMPRESS 121
157 #define ERR_DECOMPRESS 122
158 #define ERR_OCSP_CERT_NOTFOUND 123
159 #define ERR_INVALID_CONTENT 124
160 #define ERR_DENC_NO_KEY_FOUND 125
161 #define ERR_OCSP_RESP_NOT_TRUSTED 126
162 #define ERR_PRIV_CERT_NOT_FOUND 127
163 #define ERR_NO_OCSP 128
164 #define ERR_OCSP_WRONG_SIGNATURE 129
165 #define ERR_BAD_PARAM 130
166 #define ERR_GENERIC_SOAP_ERR 131
167 
168 #define ERR_TS_TIMESTAMPINFO_TYPE 132
169 #define ERR_TS_BAD_INCLUDEINFO_IDX 133
170 #define ERR_TS_BAD_TIMESTAMPINFO_IDX 134
171 #define ERR_TS_CREATE_TS_REQ 135
172 #define ERR_CREATE_NONCE 136
173 #define ERR_TXT2OID 137
174 #define ERR_HTTP_ERR 138
175 
176 #define ERR_BAD_CERTID_IDX 139
177 #define ERR_BAD_CERTVALUE_IDX 140
178 #define ERR_TS_VERIFY 141
179 #define ERR_TS_REQUEST 142
180 #define ERR_TSA_NOT_TRUSTED 143
181 #define ERR_ORPHONED_SIGNATURE 144
182 
183 #define ERR_WPKI_UNKNOWN_USER 145
184 #define ERR_WPKI_INVALID_PHONE_NO 146
185 #define ERR_WPKI_UNTRUSTED_SRVICE 147
186 #define ERR_WPKI_UNTRUSTED_USER 148
187 
188 #define ERR_WPKI_UNUSABLE_PHONE 149
189 #define ERR_WPKI_TIMEOUT 150
190 #define ERR_WPKI_CANCELLED 151
191 #define ERR_WPKI_MID_NOT_READY 152
192 #define ERR_WPKI_PHONE_NOT_REACHABLE 153
193 #define ERR_WPKI_SENDING_ERROR 154
194 #define ERR_WPKI_SIM_ERROR 155
195 #define ERR_WPKI_SERVICE_ERR 156
196 //AM 18.03.08
197 #define ERR_ZIP_FILE_READ 157
198 #define ERR_ZIP 158
199 #define ERR_MANIFEST 159
200 #define ERR_DATAFILE_NOT_MANIFEST 160
201 #define ERR_SIG_INVALID_PROFILE 161
202 #define ERR_SIGNERS_CERT_NON_REPU 162
203 #define ERR_OCSP_NONCE_SIGVAL_NOMATCH 163
204 #define ERR_VALIDATE 164
205 #define ERR_OCSP_NONCE_INVALID 165
206 #define ERR_SIGVAL_ASN1 166
207 #define ERR_MAX_1_ROLES 167
208 #define ERR_DF_NAME 168
209 #define ERR_DF_WRONG_DIG 169
210 #define ERR_ISSUER_XMLNS 170
211 #define ERR_OLD_VERSION 171
212 #define ERR_TEST_SIGNATURE 172
213 #define ERR_UNKNOWN_ERROR 173
214 #define ERR_TRANSFORM_UNSUPPORTED 174
215 #define ERR_NETWORK_SYNC 175
216 #define ERR_XML_VALIDATION 176
217 
218 #define ERROR_BUF_LENGTH 20
219 
220 
221 typedef struct ErrorMessage_st {
222  char *errorMessage;
223  int errorClass;
224 } ErrorMessage;
225 
226 typedef int ErrorClass;
227 
228 // Error classes
229 
230 // Wasn't an error at all, no reaction neccessary
231 #define NO_ERRORS 0
232 // Various problems of technical nature
233 #define TECHNICAL 1
234 // User-repairable errors
235 #define USER 2
236 // Bug in DigiDoc library (?)
237 #define LIBRARY 3
238 
239 //==========< error info structure >==============
240 
241 typedef struct ErrorInfo_st {
242  int code;
243  char *fileName;
244  int line;
245  char *assertion;
246 } ErrorInfo;
247 
248 #ifdef WIN32
249 extern CRITICAL_SECTION cs_ddocErrors;
250 #endif
251 
252 // checks and prints errors
253 EXP_OPTION long checkErrors();
254 
255 //returns textual explanation of the error code
256 EXP_OPTION char* getErrorString(int code);
257 
258 //returns the classification for the error code
259 EXP_OPTION ErrorClass getErrorClass(int code);
260 
261 //returns the code of the error that occurred in the library
262 EXP_OPTION ErrorInfo* getErrorInfo(void);
263 
264 //returns 1, if all errors are read and 0 otherwise
265 EXP_OPTION int hasUnreadErrors(void);
266 
267 //resets error information
268 EXP_OPTION void clearErrors(void);
269 
270 EXP_OPTION void addError(int code, char *fileName, int line, char *assertion);
271 
272 EXP_OPTION int checkDigiDocErrors(void);
273 
274 EXP_OPTION int getLastError();
275 
276 //returns -1, if all errors are read and valid index otherwise
277 EXP_OPTION int getLastErrorsIdx();
278 
279 //returns NULL, if all errors are read and valid ErrorInfo structre pointer otherwise
280 // does not mark error as read so it can be found again
281 EXP_OPTION ErrorInfo* getErrorsInfo(int nIdx);
282 
283 // return ERR_UNKNOWN_ERROR if multiple different errors exist, otherwise first error code
284 EXP_OPTION int checkUnknownErr();
285 
286 //==========< macros >====================
287 
288 #define SET_LAST_ERROR(code) (addError((code), __FILE__, __LINE__, ""))
289 #define SET_LAST_ERROR_IF_NOT(expr, code) { if(!(expr)) addError((code), __FILE__, __LINE__, #expr); }
290 #define SET_LAST_ERROR_RETURN(code, retVal) { SET_LAST_ERROR(code); return (retVal); }
291 #define SET_LAST_ERROR_RETURN_IF_NOT(expr, code, retVal) { if(!(expr)) { addError((code), __FILE__, __LINE__, #expr); return (retVal); } }
292 #define SET_LAST_ERROR_RETURN_VOID_IF_NOT(expr, code) { if(!(expr)) { addError((code), __FILE__, __LINE__, #expr); return; } }
293 #define SET_LAST_ERROR_RETURN_VOID_IF(expr, code) { if(expr) { addError((code), __FILE__, __LINE__, #expr); return; } }
294 #define RETURN_IF_NOT(expr, code) SET_LAST_ERROR_RETURN_IF_NOT((expr), (code), (code));
295 #define RETURN_IF_NULL(p) RETURN_IF_NOT((p), ERR_NULL_POINTER);
296 #define RETURN_VOID_IF_NULL(p) SET_LAST_ERROR_RETURN_VOID_IF_NOT((p), ERR_NULL_POINTER);
297 #define RETURN_OBJ_IF_NULL(p, obj) SET_LAST_ERROR_RETURN_IF_NOT((p), ERR_NULL_POINTER, (obj));
298 #define SET_LAST_ERROR_RETURN_CODE(code) { SET_LAST_ERROR(code); return (code); }
299 #define RETURN_IF_NULL_PARAM(p) RETURN_IF_NOT((p), ERR_NULL_PARAM);
300 #define RETURN_IF_BAD_ALLOC(p) RETURN_IF_NOT((p), ERR_BAD_ALLOC)
301 #define RETURN_VOID_IF_BAD_ALLOC(p) SET_LAST_ERROR_RETURN_VOID_IF_NOT((p), ERR_BAD_ALLOC);
302 
303 //========================================
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif
310 
Definition: DigiDocError.h:221
Definition: DigiDocError.h:241