Deprecate the public definition of ERR_STATE
[openssl.git] / include / openssl / err.h
index e5a1a0dc1eeaf4493ddb057f41c6734e24bdbcb1..fc7326b7c9aa017d4d00e5caadc50a7a21fcc2cb 100644 (file)
 extern "C" {
 #endif
 
-# ifndef OPENSSL_NO_ERR
-#  define ERR_PUT_error(l,f,r,fn,ln)      ERR_put_error(l,f,r,fn,ln)
-#  define ERR_PUT_func_error(l,f,r,fn,ln) ERR_put_func_error(l,f,r,fn,ln)
-# else
-#  define ERR_PUT_error(l,f,r,fn,ln)      ERR_put_error(l,f,r,NULL,0)
-#  define ERR_PUT_func_error(l,f,r,fn,ln) ERR_put_func_error(l,f,r,NULL,0)
+# if !OPENSSL_API_3
+#  ifndef OPENSSL_NO_FILENAMES
+#   define ERR_PUT_error(l,f,r,fn,ln)      ERR_put_error(l,f,r,fn,ln)
+#  else
+#   define ERR_PUT_error(l,f,r,fn,ln)      ERR_put_error(l,f,r,NULL,0)
+#  endif
 # endif
 
 # include <errno.h>
@@ -38,11 +38,12 @@ extern "C" {
 # define ERR_TXT_MALLOCED        0x01
 # define ERR_TXT_STRING          0x02
 
-# define ERR_FLAG_MARK           0x01
-# define ERR_FLAG_CLEAR          0x02
+# if !OPENSSL_API_3 || defined(OSSL_FORCE_ERR_STATE)
+#  define ERR_FLAG_MARK           0x01
+#  define ERR_FLAG_CLEAR          0x02
 
-# define ERR_NUM_ERRORS  16
-typedef struct err_state_st {
+#  define ERR_NUM_ERRORS  16
+struct err_state_st {
     int err_flags[ERR_NUM_ERRORS];
     unsigned long err_buffer[ERR_NUM_ERRORS];
     char *err_data[ERR_NUM_ERRORS];
@@ -52,7 +53,8 @@ typedef struct err_state_st {
     int err_line[ERR_NUM_ERRORS];
     const char *err_func[ERR_NUM_ERRORS];
     int top, bottom;
-} ERR_STATE;
+};
+# endif
 
 /* library */
 # define ERR_LIB_NONE            1
@@ -97,13 +99,12 @@ typedef struct err_state_st {
 /* # define ERR_LIB_JPAKE       49 */
 # define ERR_LIB_CT              50
 # define ERR_LIB_ASYNC           51
-# define ERR_LIB_KDF             52
-# define ERR_LIB_SM2             53
-# define ERR_LIB_ESS             54
-# define ERR_LIB_PROP            55
-# define ERR_LIB_CRMF            56
-# define ERR_LIB_PROV            57
-# define ERR_LIB_CMP             58
+# define ERR_LIB_SM2             52
+# define ERR_LIB_ESS             53
+# define ERR_LIB_PROP            54
+# define ERR_LIB_CRMF            55
+# define ERR_LIB_PROV            56
+# define ERR_LIB_CMP             57
 
 # define ERR_LIB_USER            128
 
@@ -145,7 +146,6 @@ typedef struct err_state_st {
 # define HMACerr(f,r) ERR_raise(ERR_LIB_HMAC,(r))
 # define CTerr(f,r) ERR_raise(ERR_LIB_CT,(r))
 # define ASYNCerr(f,r) ERR_raise(ERR_LIB_ASYNC,(r))
-# define KDFerr(f,r) ERR_raise(ERR_LIB_KDF,(r))
 # define SM2err(f,r) ERR_raise(ERR_LIB_SM2,(r))
 # define ESSerr(f,r) ERR_raise(ERR_LIB_ESS,(r))
 # define PROPerr(f,r) ERR_raise(ERR_LIB_PROP,(r))
@@ -245,48 +245,81 @@ void ERR_set_error(int lib, int reason, const char *fmt, ...);
 void ERR_vset_error(int lib, int reason, const char *fmt, va_list args);
 
 /* Main error raising functions */
-#define ERR_raise(lib, reason) ERR_raise_data((lib),(reason),NULL)
-#define ERR_raise_data                                          \
+# define ERR_raise(lib, reason) ERR_raise_data((lib),(reason),NULL)
+# define ERR_raise_data                                         \
     (ERR_new(),                                                 \
      ERR_set_debug(OPENSSL_FILE,OPENSSL_LINE,OPENSSL_FUNC),     \
      ERR_set_error)
 
-#if !OPENSSL_API_3
+# if !OPENSSL_API_3
 /* Backward compatibility */
-#define ERR_put_error(lib, func, reason, file, line)            \
+#  define ERR_put_error(lib, func, reason, file, line)          \
     (ERR_new(),                                                 \
-     ERR_set_debug((file), (line), NULL),                       \
+     ERR_set_debug((file), (line), OPENSSL_FUNC),               \
      ERR_set_error((lib), (reason), NULL))
-#endif
+# endif
 
 void ERR_set_error_data(char *data, int flags);
 
 unsigned long ERR_get_error(void);
+/*
+ * TODO(3.0) consider if the following three functions should be deprecated.
+ * They all drop the error record from the error queue, so regardless of which
+ * one is used, the rest of the information is lost, making them not so useful.
+ * The recommendation should be to use the peek functions to extract all the
+ * additional data.
+ */
 unsigned long ERR_get_error_line(const char **file, int *line);
-unsigned long ERR_get_error_line_data(const char **file, int *line,
-                                      const char **data, int *flags);
+unsigned long ERR_get_error_func(const char **func);
+unsigned long ERR_get_error_data(const char **data, int *flags);
+unsigned long ERR_get_error_all(const char **file, int *line,
+                                const char **func,
+                                const char **data, int *flags);
+DEPRECATEDIN_3(unsigned long ERR_get_error_line_data(const char **file,
+                                                     int *line,
+                                                     const char **data,
+                                                     int *flags))
 unsigned long ERR_peek_error(void);
 unsigned long ERR_peek_error_line(const char **file, int *line);
-unsigned long ERR_peek_error_line_data(const char **file, int *line,
-                                       const char **data, int *flags);
+unsigned long ERR_peek_error_func(const char **func);
+unsigned long ERR_peek_error_data(const char **data, int *flags);
+unsigned long ERR_peek_error_all(const char **file, int *line,
+                                 const char **func,
+                                 const char **data, int *flags);
+DEPRECATEDIN_3(unsigned long ERR_peek_error_line_data(const char **file,
+                                                      int *line,
+                                                      const char **data,
+                                                      int *flags))
 unsigned long ERR_peek_last_error(void);
 unsigned long ERR_peek_last_error_line(const char **file, int *line);
-unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
-                                            const char **data, int *flags);
+unsigned long ERR_peek_last_error_func(const char **func);
+unsigned long ERR_peek_last_error_data(const char **data, int *flags);
+unsigned long ERR_peek_last_error_all(const char **file, int *line,
+                                      const char **func,
+                                      const char **data, int *flags);
+DEPRECATEDIN_3(unsigned long ERR_peek_last_error_line_data(const char **file,
+                                                           int *line,
+                                                           const char **data,
+                                                           int *flags))
+
 void ERR_clear_error(void);
+
 char *ERR_error_string(unsigned long e, char *buf);
 void ERR_error_string_n(unsigned long e, char *buf, size_t len);
 const char *ERR_lib_error_string(unsigned long e);
-const char *ERR_func_error_string(unsigned long e);
+DEPRECATEDIN_3(const char *ERR_func_error_string(unsigned long e))
 const char *ERR_reason_error_string(unsigned long e);
+
 void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
                          void *u);
 # ifndef OPENSSL_NO_STDIO
 void ERR_print_errors_fp(FILE *fp);
 # endif
 void ERR_print_errors(BIO *bp);
+
 void ERR_add_error_data(int num, ...);
 void ERR_add_error_vdata(int num, va_list args);
+
 int ERR_load_strings(int lib, ERR_STRING_DATA *str);
 int ERR_load_strings_const(const ERR_STRING_DATA *str);
 int ERR_unload_strings(int lib, ERR_STRING_DATA *str);