OLD | NEW |
1 /* crypto/err/err_prn.c */ | 1 /* crypto/err/err_prn.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), | 66 void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), |
67 void *u) | 67 void *u) |
68 { | 68 { |
69 unsigned long l; | 69 unsigned long l; |
70 char buf[256]; | 70 char buf[256]; |
71 char buf2[4096]; | 71 char buf2[4096]; |
72 const char *file,*data; | 72 const char *file,*data; |
73 int line,flags; | 73 int line,flags; |
74 unsigned long es; | 74 unsigned long es; |
| 75 CRYPTO_THREADID cur; |
75 | 76 |
76 » es=CRYPTO_thread_id(); | 77 » CRYPTO_THREADID_current(&cur); |
| 78 » es=CRYPTO_THREADID_hash(&cur); |
77 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) | 79 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) |
78 { | 80 { |
79 ERR_error_string_n(l, buf, sizeof buf); | 81 ERR_error_string_n(l, buf, sizeof buf); |
80 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf, | 82 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf, |
81 file, line, (flags & ERR_TXT_STRING) ? data : ""); | 83 file, line, (flags & ERR_TXT_STRING) ? data : ""); |
82 if (cb(buf2, strlen(buf2), u) <= 0) | 84 if (cb(buf2, strlen(buf2), u) <= 0) |
83 break; /* abort outputting the error report */ | 85 break; /* abort outputting the error report */ |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 #ifndef OPENSSL_NO_FP_API | 89 #ifndef OPENSSL_NO_FP_API |
88 static int print_fp(const char *str, size_t len, void *fp) | 90 static int print_fp(const char *str, size_t len, void *fp) |
89 { | 91 { |
90 BIO bio; | 92 BIO bio; |
91 | 93 |
92 BIO_set(&bio,BIO_s_file()); | 94 BIO_set(&bio,BIO_s_file()); |
93 BIO_set_fp(&bio,fp,BIO_NOCLOSE); | 95 BIO_set_fp(&bio,fp,BIO_NOCLOSE); |
94 | 96 |
95 return BIO_printf(&bio, "%s", str); | 97 return BIO_printf(&bio, "%s", str); |
96 } | 98 } |
97 void ERR_print_errors_fp(FILE *fp) | 99 void ERR_print_errors_fp(FILE *fp) |
98 { | 100 { |
99 ERR_print_errors_cb(print_fp, fp); | 101 ERR_print_errors_cb(print_fp, fp); |
100 } | 102 } |
101 #endif | 103 #endif |
102 | 104 |
103 void ERR_error_string_n(unsigned long e, char *buf, size_t len) | 105 static int print_bio(const char *str, size_t len, void *bp) |
104 { | 106 { |
105 » char lsbuf[64], fsbuf[64], rsbuf[64]; | 107 » return BIO_write((BIO *)bp, str, len); |
106 » const char *ls,*fs,*rs; | 108 » } |
107 » unsigned long l,f,r; | 109 void ERR_print_errors(BIO *bp) |
108 | 110 » { |
109 » l=ERR_GET_LIB(e); | 111 » ERR_print_errors_cb(print_bio, bp); |
110 » f=ERR_GET_FUNC(e); | |
111 » r=ERR_GET_REASON(e); | |
112 | |
113 » ls=ERR_lib_error_string(e); | |
114 » fs=ERR_func_error_string(e); | |
115 » rs=ERR_reason_error_string(e); | |
116 | |
117 » if (ls == NULL) | |
118 » » BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l); | |
119 » if (fs == NULL) | |
120 » » BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f); | |
121 » if (rs == NULL) | |
122 » » BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r); | |
123 | |
124 » BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf, | |
125 » » fs?fs:fsbuf, rs?rs:rsbuf); | |
126 » if (strlen(buf) == len-1) | |
127 » » { | |
128 » » /* output may be truncated; make sure we always have 5 | |
129 » » * colon-separated fields, i.e. 4 colons ... */ | |
130 #define NUM_COLONS 4 | |
131 » » if (len > NUM_COLONS) /* ... if possible */ | |
132 » » » { | |
133 » » » int i; | |
134 » » » char *s = buf; | |
135 » » » | |
136 » » » for (i = 0; i < NUM_COLONS; i++) | |
137 » » » » { | |
138 » » » » char *colon = strchr(s, ':'); | |
139 » » » » if (colon == NULL || colon > &buf[len-1] - NUM_C
OLONS + i) | |
140 » » » » » { | |
141 » » » » » /* set colon no. i at last possible posi
tion | |
142 » » » » » * (buf[len-1] is the terminating 0)*/ | |
143 » » » » » colon = &buf[len-1] - NUM_COLONS + i; | |
144 » » » » » *colon = ':'; | |
145 » » » » » } | |
146 » » » » s = colon + 1; | |
147 » » » » } | |
148 » » » } | |
149 » » } | |
150 } | 112 } |
151 | 113 |
152 /* BAD for multi-threading: uses a local buffer if ret == NULL */ | 114 » |
153 /* ERR_error_string_n should be used instead for ret != NULL | |
154 * as ERR_error_string cannot know how large the buffer is */ | |
155 char *ERR_error_string(unsigned long e, char *ret) | |
156 » { | |
157 » static char buf[256]; | |
158 | |
159 » if (ret == NULL) ret=buf; | |
160 » ERR_error_string_n(e, ret, 256); | |
161 | |
162 » return ret; | |
163 » } | |
OLD | NEW |