err.h revision 59191
1581Srgrimes/* crypto/err/err.h */ 2581Srgrimes/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3581Srgrimes * All rights reserved. 4581Srgrimes * 5581Srgrimes * This package is an SSL implementation written 6581Srgrimes * by Eric Young (eay@cryptsoft.com). 7581Srgrimes * The implementation was written so as to conform with Netscapes SSL. 8581Srgrimes * 9581Srgrimes * This library is free for commercial and non-commercial use as long as 102281Swollman * the following conditions are aheared to. The following conditions 112281Swollman * apply to all code found in this distribution, be it the RC4, RSA, 122281Swollman * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1324909Sgibbs * included with this distribution is covered by the same copyright terms 1424909Sgibbs * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1524909Sgibbs * 1624909Sgibbs * Copyright remains Eric Young's, and as such any Copyright notices in 17581Srgrimes * the code are not to be removed. 18581Srgrimes * If this package is used in a product, Eric Young should be given attribution 19581Srgrimes * as the author of the parts of the library used. 20581Srgrimes * This can be in the form of a textual message at program startup or 21581Srgrimes * in documentation (online or textual) provided with the package. 22581Srgrimes * 23581Srgrimes * Redistribution and use in source and binary forms, with or without 24581Srgrimes * modification, are permitted provided that the following conditions 25581Srgrimes * are met: 26581Srgrimes * 1. Redistributions of source code must retain the copyright 27581Srgrimes * notice, this list of conditions and the following disclaimer. 28581Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 29581Srgrimes * notice, this list of conditions and the following disclaimer in the 3024909Sgibbs * documentation and/or other materials provided with the distribution. 3124909Sgibbs * 3. All advertising materials mentioning features or use of this software 3224909Sgibbs * must display the following acknowledgement: 3324909Sgibbs * "This product includes cryptographic software written by 34581Srgrimes * Eric Young (eay@cryptsoft.com)" 35581Srgrimes * The word 'cryptographic' can be left out if the rouines from the library 36581Srgrimes * being used are not cryptographic related :-). 37581Srgrimes * 4. If you include any Windows specific code (or a derivative thereof) from 38581Srgrimes * the apps directory (application code) you must include an acknowledgement: 39581Srgrimes * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40581Srgrimes * 41581Srgrimes * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42581Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43581Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44581Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45581Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46581Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47581Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48581Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49581Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5059812Smdodd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51581Srgrimes * SUCH DAMAGE. 52581Srgrimes * 53119418Sobrien * The licence and distribution terms for any publically available version or 54119418Sobrien * derivative of this code cannot be changed. i.e. this code cannot simply be 55119418Sobrien * copied and put under another distribution licence 56581Srgrimes * [including the GNU Public Licence.] 57581Srgrimes */ 58581Srgrimes 59581Srgrimes#ifndef HEADER_ERR_H 60581Srgrimes#define HEADER_ERR_H 61581Srgrimes 62581Srgrimes#ifdef __cplusplus 6326996Sgibbsextern "C" { 64581Srgrimes#endif 65581Srgrimes 66581Srgrimes#ifndef NO_FP_API 67581Srgrimes#include <stdio.h> 68581Srgrimes#endif 698876Srgrimes 7024909Sgibbs/* The following is a bit of a trick to help the object files only contain 71581Srgrimes * the 'name of the file' string once. Since 'err.h' is protected by the 72581Srgrimes * HEADER_ERR_H stuff, this should be included only once per file. */ 73581Srgrimes 74112765Smdodd#define ERR_file_name __FILE__ 75112765Smdodd 76112765Smdodd#ifndef NO_ERR 77112765Smdodd#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) 78112765Smdodd#else 79112765Smdodd#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) 80112765Smdodd#endif 81112765Smdodd 82112765Smdodd#include <errno.h> 83112765Smdodd 84112765Smdodd#define ERR_TXT_MALLOCED 0x01 85112765Smdodd#define ERR_TXT_STRING 0x02 86112765Smdodd 87112765Smdodd#define ERR_NUM_ERRORS 16 88112765Smdoddtypedef struct err_state_st 89112765Smdodd { 90112765Smdodd unsigned long pid; 91112765Smdodd unsigned long err_buffer[ERR_NUM_ERRORS]; 92112765Smdodd char *err_data[ERR_NUM_ERRORS]; 93112765Smdodd int err_data_flags[ERR_NUM_ERRORS]; 94112765Smdodd const char *err_file[ERR_NUM_ERRORS]; 95112765Smdodd int err_line[ERR_NUM_ERRORS]; 96112765Smdodd int top,bottom; 97112765Smdodd } ERR_STATE; 98112765Smdodd 99112765Smdodd/* library */ 100112765Smdodd#define ERR_LIB_NONE 1 101112765Smdodd#define ERR_LIB_SYS 2 102112765Smdodd#define ERR_LIB_BN 3 103112765Smdodd#define ERR_LIB_RSA 4 104112765Smdodd#define ERR_LIB_DH 5 105112765Smdodd#define ERR_LIB_EVP 6 106112765Smdodd#define ERR_LIB_BUF 7 107112765Smdodd#define ERR_LIB_OBJ 8 108112765Smdodd#define ERR_LIB_PEM 9 109112765Smdodd#define ERR_LIB_DSA 10 110112765Smdodd#define ERR_LIB_X509 11 111112765Smdodd#define ERR_LIB_METH 12 112112765Smdodd#define ERR_LIB_ASN1 13 113581Srgrimes#define ERR_LIB_CONF 14 1142056Swollman#define ERR_LIB_CRYPTO 15 1152056Swollman#define ERR_LIB_SSL 20 11650135Smsmith#define ERR_LIB_SSL23 21 11710080Sbde#define ERR_LIB_SSL2 22 11829024Sbde#define ERR_LIB_SSL3 23 1192056Swollman#define ERR_LIB_RSAREF 30 1202056Swollman#define ERR_LIB_PROXY 31 12124204Sbde#define ERR_LIB_BIO 32 1222056Swollman#define ERR_LIB_PKCS7 33 123581Srgrimes#define ERR_LIB_X509V3 34 124112790Smdodd#define ERR_LIB_PKCS12 35 125112790Smdodd#define ERR_LIB_RAND 36 126112790Smdodd 127112790Smdodd#define ERR_LIB_USER 128 128112790Smdodd 129112790Smdodd#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),ERR_file_name,__LINE__) 130112790Smdodd#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),ERR_file_name,__LINE__) 13150026Smdodd#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),ERR_file_name,__LINE__) 1322056Swollman#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),ERR_file_name,__LINE__) 1332056Swollman#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),ERR_file_name,__LINE__) 1342056Swollman#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),ERR_file_name,__LINE__) 135581Srgrimes#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),ERR_file_name,__LINE__) 13650026Smdodd#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),ERR_file_name,__LINE__) 13750026Smdodd#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),ERR_file_name,__LINE__) 13850026Smdodd#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),ERR_file_name,__LINE__) 13979077Simp#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),ERR_file_name,__LINE__) 140112790Smdodd#define METHerr(f,r) ERR_PUT_error(ERR_LIB_METH,(f),(r),ERR_file_name,__LINE__) 14155953Speter#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),ERR_file_name,__LINE__) 14255953Speter#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),ERR_file_name,__LINE__) 14355953Speter#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),ERR_file_name,__LINE__) 1442268Sats#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),ERR_file_name,__LINE__) 145581Srgrimes#define SSL23err(f,r) ERR_PUT_error(ERR_LIB_SSL23,(f),(r),ERR_file_name,__LINE__) 1462056Swollman#define SSL2err(f,r) ERR_PUT_error(ERR_LIB_SSL2,(f),(r),ERR_file_name,__LINE__) 147581Srgrimes#define SSL3err(f,r) ERR_PUT_error(ERR_LIB_SSL3,(f),(r),ERR_file_name,__LINE__) 148581Srgrimes#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__) 14926996Sgibbs#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__) 15026996Sgibbs#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__) 15126996Sgibbs#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__) 15226996Sgibbs#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__) 15326996Sgibbs#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__) 15433181Seivind 15526996Sgibbs/* Borland C seems too stupid to be able to shift and do longs in 156581Srgrimes * the pre-processor :-( */ 157581Srgrimes#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \ 15826996Sgibbs ((((unsigned long)f)&0xfffL)*0x1000)| \ 159581Srgrimes ((((unsigned long)r)&0xfffL))) 160581Srgrimes#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL) 161581Srgrimes#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL) 162581Srgrimes#define ERR_GET_REASON(l) (int)((l)&0xfffL) 163112734Smdodd#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL) 164179491Sjhb 165112734Smdodd/* OS functions */ 166112734Smdodd#define SYS_F_FOPEN 1 167112734Smdodd#define SYS_F_CONNECT 2 168179491Sjhb#define SYS_F_GETSERVBYNAME 3 16924909Sgibbs#define SYS_F_SOCKET 4 170112734Smdodd#define SYS_F_IOCTLSOCKET 5 171112734Smdodd#define SYS_F_BIND 6 172112734Smdodd#define SYS_F_LISTEN 7 173112734Smdodd#define SYS_F_ACCEPT 8 174112734Smdodd#define SYS_F_WSASTARTUP 9 /* Winsock stuff */ 175112734Smdodd#define SYS_F_OPENDIR 10 17624909Sgibbs 177112734Smdodd#define ERR_R_FATAL 32 178112734Smdodd/* reasons */ 179112734Smdodd#define ERR_R_SYS_LIB ERR_LIB_SYS 180112734Smdodd#define ERR_R_BN_LIB ERR_LIB_BN 181112734Smdodd#define ERR_R_RSA_LIB ERR_LIB_RSA 182112734Smdodd#define ERR_R_DSA_LIB ERR_LIB_DSA 183112734Smdodd#define ERR_R_DH_LIB ERR_LIB_DH 184112734Smdodd#define ERR_R_EVP_LIB ERR_LIB_EVP 185112734Smdodd#define ERR_R_BUF_LIB ERR_LIB_BUF 186112734Smdodd#define ERR_R_BIO_LIB ERR_LIB_BIO 187112734Smdodd#define ERR_R_OBJ_LIB ERR_LIB_OBJ 188112734Smdodd#define ERR_R_PEM_LIB ERR_LIB_PEM 189112734Smdodd#define ERR_R_X509_LIB ERR_LIB_X509 190112734Smdodd#define ERR_R_METH_LIB ERR_LIB_METH 191112734Smdodd#define ERR_R_ASN1_LIB ERR_LIB_ASN1 192112734Smdodd#define ERR_R_CONF_LIB ERR_LIB_CONF 193112734Smdodd#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO 194112734Smdodd#define ERR_R_SSL_LIB ERR_LIB_SSL 195112734Smdodd#define ERR_R_SSL23_LIB ERR_LIB_SSL23 196581Srgrimes#define ERR_R_SSL2_LIB ERR_LIB_SSL2 197581Srgrimes#define ERR_R_SSL3_LIB ERR_LIB_SSL3 198112734Smdodd#define ERR_R_PROXY_LIB ERR_LIB_PROXY 19933181Seivind#define ERR_R_BIO_LIB ERR_LIB_BIO 20033181Seivind#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 201581Srgrimes#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 202581Srgrimes 20312724Sphk/* fatal error */ 204112790Smdodd#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) 20526996Sgibbs#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) 20626996Sgibbs#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) 20726996Sgibbs#define ERR_R_NESTED_ASN1_ERROR (4) 20826996Sgibbs#define ERR_R_BAD_ASN1_OBJECT_HEADER (5) 20926996Sgibbs#define ERR_R_BAD_GET_ASN1_OBJECT_CALL (6) 21026996Sgibbs#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE (7) 21126996Sgibbs#define ERR_R_ASN1_LENGTH_MISMATCH (8) 212581Srgrimes#define ERR_R_MISSING_ASN1_EOS (9) 213581Srgrimes 2148876Srgrimestypedef struct ERR_string_data_st 215112765Smdodd { 216112765Smdodd unsigned long error; 217112765Smdodd const char *string; 218112765Smdodd } ERR_STRING_DATA; 219112765Smdodd 220112765Smdoddvoid ERR_put_error(int lib, int func,int reason,const char *file,int line); 221112765Smdoddvoid ERR_set_error_data(char *data,int flags); 222112765Smdodd 223112765Smdoddunsigned long ERR_get_error(void ); 224112765Smdoddunsigned long ERR_get_error_line(const char **file,int *line); 225112765Smdoddunsigned long ERR_get_error_line_data(const char **file,int *line, 226112765Smdodd const char **data, int *flags); 227112765Smdoddunsigned long ERR_peek_error(void ); 228112765Smdoddunsigned long ERR_peek_error_line(const char **file,int *line); 229112765Smdoddunsigned long ERR_peek_error_line_data(const char **file,int *line, 230112765Smdodd const char **data,int *flags); 231112765Smdoddvoid ERR_clear_error(void ); 232112765Smdoddchar *ERR_error_string(unsigned long e,char *buf); 233112765Smdoddconst char *ERR_lib_error_string(unsigned long e); 234112765Smdoddconst char *ERR_func_error_string(unsigned long e); 235112765Smdoddconst char *ERR_reason_error_string(unsigned long e); 236112765Smdodd#ifndef NO_FP_API 237581Srgrimesvoid ERR_print_errors_fp(FILE *fp); 238112783Smdodd#endif 239112783Smdodd#ifdef HEADER_BIO_H 240112783Smdoddvoid ERR_print_errors(BIO *bp); 241112783Smdoddvoid ERR_add_error_data(int num, ...); 242112783Smdodd#endif 243581Srgrimesvoid ERR_load_strings(int lib,ERR_STRING_DATA str[]); 24438232Sbdevoid ERR_load_ERR_strings(void); 24538232Sbdevoid ERR_load_crypto_strings(void); 246581Srgrimesvoid ERR_free_strings(void); 247181134Sjhb 248181134Sjhbvoid ERR_remove_state(unsigned long pid); /* if zero we look it up */ 24924909SgibbsERR_STATE *ERR_get_state(void); 25024909Sgibbs 251112734Smdodd#ifdef HEADER_LHASH_H 252112734SmdoddLHASH *ERR_get_string_table(void ); 253112734SmdoddLHASH *ERR_get_err_state_table(void ); 25424909Sgibbs#else 25524909Sgibbschar *ERR_get_string_table(void ); 256581Srgrimeschar *ERR_get_err_state_table(void ); 257581Srgrimes#endif 258581Srgrimes 259112790Smdoddint ERR_get_next_error_library(void ); 260112790Smdodd 261581Srgrimes#ifdef __cplusplus 262112790Smdodd} 263112790Smdodd#endif 264112790Smdodd 265179491Sjhb#endif 266581Srgrimes