Using checks of the existence of HEADER_{foo}_H in other header files
authorRichard Levitte <levitte@openssl.org>
Fri, 9 Jun 2000 10:41:35 +0000 (10:41 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 9 Jun 2000 10:41:35 +0000 (10:41 +0000)
was a really bad idea.  For example, the following:

#include <x509.h>
#include <bio.h>
#include <asn1.h>

would make sure that things like ASN1_UTCTIME_print() wasn't defined
unless you moved the inclusion of bio.h to above the inclusion of
x509.h.  The reason is that x509.h includes asn1.h, and the
declaration of ASN1_UTCTIME_print() depended on the definition of
HEADER_BIO_H.  That's what I call an obscure bug.

Instead, this change makes sure that whatever header files are needed
for the correct process of one header file are included automagically,
and that the definitions of, for example, BIO-related things are
dependent on the absence of the NO_{foo} macros.  This is also
consistent with the way parts of OpenSSL can be excluded at will.

14 files changed:
crypto/asn1/asn1.h
crypto/dh/dh.h
crypto/dsa/dsa.h
crypto/err/err.h
crypto/evp/evp.h
crypto/lhash/lh_stats.c
crypto/lhash/lhash.h
crypto/pem/pem.h
crypto/rsa/rsa.h
crypto/txt_db/txt_db.h
crypto/x509/x509.h
crypto/x509/x509_vfy.h
ssl/ssl.h
ssl/ssl3.h

index 50a0cfb16250fc366fcafebf2fc7fe51526fa1c9..791636cbcb286ce0dbd55a5805109507c5fe4587 100644 (file)
@@ -60,6 +60,9 @@
 #define HEADER_ASN1_H
 
 #include <time.h>
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/bn.h>
 #include <openssl/stack.h>
 #include <openssl/safestack.h>
@@ -695,7 +698,7 @@ int         ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
 int            ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
 int            ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
                                BIT_STRING_BITNAME *tbl, int indent);
 #endif
@@ -823,7 +826,7 @@ STACK *             d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
                        char *(*func)(), void (*free_func)(),
                        int ex_tag, int ex_class);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
 int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
 int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
@@ -878,7 +881,7 @@ char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
 int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
 int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
 int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
index 19bd570309eda8a602dde36fcb9bdc32d2586773..a15fc1c65f7ec0fd6f3dd102d6355a9b49fcc711 100644 (file)
@@ -63,6 +63,9 @@
 #error DH is disabled.
 #endif
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/bn.h>
 #include <openssl/crypto.h>
        
@@ -169,7 +172,7 @@ int i2d_DHparams(DH *a,unsigned char **pp);
 #ifndef NO_FP_API
 int    DHparams_print_fp(FILE *fp, DH *x);
 #endif
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int    DHparams_print(BIO *bp, DH *x);
 #else
 int    DHparams_print(char *bp, DH *x);
index ca301c533632a949a00fcdb9b85d6c3ba9c8e32d..3ebcc4ae0a4011a7a4879d7d9c7cca72b101e89f 100644 (file)
@@ -69,6 +69,9 @@
 #error DSA is disabled.
 #endif
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/bn.h>
 #include <openssl/crypto.h>
 #ifndef NO_DH
@@ -188,7 +191,7 @@ int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
 int    i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
 int    i2d_DSAparams(DSA *a,unsigned char **pp);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int    DSAparams_print(BIO *bp, DSA *x);
 int    DSA_print(BIO *bp, DSA *x, int off);
 #endif
index 519a9c5b0913704f1572b12d33913b6461820920..2c3d39c68c05af3a07d1ca95c7c1d45d48cd01fe 100644 (file)
 #include <stdlib.h>
 #endif
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
+#ifndef NO_LHASH
+#include <openssl/lhash.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -241,7 +248,7 @@ const char *ERR_reason_error_string(unsigned long e);
 #ifndef NO_FP_API
 void ERR_print_errors_fp(FILE *fp);
 #endif
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 void ERR_print_errors(BIO *bp);
 void ERR_add_error_data(int num, ...);
 #endif
@@ -253,7 +260,7 @@ void ERR_free_strings(void);
 void ERR_remove_state(unsigned long pid); /* if zero we look it up */
 ERR_STATE *ERR_get_state(void);
 
-#ifdef HEADER_LHASH_H
+#ifndef NO_LHASH
 LHASH *ERR_get_string_table(void);
 LHASH *ERR_get_err_state_table(void); /* even less thread-safe than
                                       * ERR_get_string_table :-) */
index 56a7e081899e95a38e5468866cf8c267e0c04742..f3b2b7456a479dc39e5ad68251382d67d490ffff 100644 (file)
@@ -67,6 +67,9 @@
 # undef OPENSSL_ALGORITHM_DEFINES
 #endif
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #ifndef NO_MD2
 #include <openssl/md2.h>
 #endif
@@ -593,7 +596,7 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 BIO_METHOD *BIO_f_md(void);
 BIO_METHOD *BIO_f_base64(void);
 BIO_METHOD *BIO_f_cipher(void);
index 80b931c12b76c6a128822d534666657d764c7997..ee0600060e07901d00fa42bcde325d25a763dcd6 100644 (file)
  * and things should work as expected */
 #include "cryptlib.h"
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/lhash.h>
 
-#ifndef HEADER_BIO_H
+#ifdef NO_BIO
 
 void lh_stats(LHASH *lh, FILE *out)
        {
index 868d5352605fa0e3749f3e01ae378c9dfafd8a28..b8ff021906975180902c4719e4d9dbca226d1890 100644 (file)
 #include <stdio.h>
 #endif
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -132,7 +136,7 @@ void lh_node_stats(LHASH *lh, FILE *out);
 void lh_node_usage_stats(LHASH *lh, FILE *out);
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 void lh_stats_bio(LHASH *lh, BIO *out);
 void lh_node_stats_bio(LHASH *lh, BIO *out);
 void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
index 38b98015c4cecef9396a3425b69fd9dbeb52249e..46aafa68153d8d122a44b6c6e2ab96d84202b330 100644 (file)
 #ifndef HEADER_PEM_H
 #define HEADER_PEM_H
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
+#ifndef NO_STACK
+#include <openssl/stack.h>
+#endif
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/pem2.h>
@@ -165,7 +171,7 @@ typedef struct pem_ctx_st
        int num_recipient;
        PEM_USER **recipient;
 
-#ifdef HEADER_STACK_H
+#ifndef NO_STACK
        STACK *x509_chain;      /* certificate chain */
 #else
        char *x509_chain;       /* certificate chain */
@@ -289,7 +295,7 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
 
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 #define DECLARE_PEM_read_bio(name, type) \
        type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
 
@@ -477,7 +483,7 @@ int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
 int    PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
        pem_password_cb *callback,void *u);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int    PEM_read_bio(BIO *bp, char **name, char **header,
                unsigned char **data,long *len);
 int    PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
index 74033cf60780b3a30b894eb658bbb6dc406a3c1d..69b76484305024fa731d2d5ac8cde387b572a9aa 100644 (file)
@@ -59,6 +59,9 @@
 #ifndef HEADER_RSA_H
 #define HEADER_RSA_H
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/bn.h>
 #include <openssl/crypto.h>
 
@@ -209,7 +212,7 @@ int         i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
 int    RSA_print_fp(FILE *fp, RSA *r,int offset);
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int    RSA_print(BIO *bp, RSA *r,int offset);
 #endif
 
index 22a54f06ee896568f998880cd395f2d2f475d8ab..342533d40dbbfb0f0d9c1343caca84d013026d24 100644 (file)
@@ -59,6 +59,9 @@
 #ifndef HEADER_TXT_DB_H
 #define HEADER_TXT_DB_H
 
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/stack.h>
 #include <openssl/lhash.h>
 
@@ -85,7 +88,7 @@ typedef struct txt_db_st
        char **arg_row;
        } TXT_DB;
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 TXT_DB *TXT_DB_read(BIO *in, int num);
 long TXT_DB_write(BIO *out, TXT_DB *db);
 #else
index 1dae31a233c186c3cfcbdddcd959119061db9357..87f192fa80bb1421f242c04ee4e03c538c9c3a7f 100644 (file)
 #define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
 #endif
 
+#ifndef NO_BUFFER
+#include <openssl/buffer.h>
+#endif
+#ifndef NO_EVP
+#include <openssl/evp.h>
+#endif
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/stack.h>
 #include <openssl/asn1.h>
 #include <openssl/safestack.h>
@@ -242,7 +251,7 @@ typedef struct X509_name_st
        {
        STACK_OF(X509_NAME_ENTRY) *entries;
        int modified;   /* true if 'bytes' needs to be built */
-#ifdef HEADER_BUFFER_H
+#ifndef NO_BUFFER
        BUF_MEM *bytes;
 #else
        char *bytes;
@@ -663,7 +672,7 @@ typedef struct private_key_st
        int references;
        } X509_PKEY;
 
-#ifdef HEADER_ENVELOPE_H
+#ifndef NO_EVP
 typedef struct X509_info_st
        {
        X509 *x509;
@@ -950,7 +959,7 @@ extern "C" {
 const char *X509_verify_cert_error_string(long n);
 
 #ifndef SSLEAY_MACROS
-#ifdef HEADER_ENVELOPE_H
+#ifndef NO_EVP
 int X509_verify(X509 *a, EVP_PKEY *r);
 
 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
@@ -1010,7 +1019,7 @@ int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
 EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 X509 *d2i_X509_bio(BIO *bp,X509 **x509);
 int i2d_X509_bio(BIO *bp,X509 *x509);
 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
@@ -1216,7 +1225,7 @@ NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
 void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
 
-#ifdef HEADER_ENVELOPE_H
+#ifndef NO_EVP
 X509_INFO *    X509_INFO_new(void);
 void           X509_INFO_free(X509_INFO *a);
 char *         X509_NAME_oneline(X509_NAME *a,char *buf,int size);
@@ -1296,7 +1305,7 @@ int               X509_CRL_print_fp(FILE *bp,X509_CRL *x);
 int            X509_REQ_print_fp(FILE *bp,X509_REQ *req);
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int            X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
 int            X509_print(BIO *bp,X509 *x);
 int            X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
index 313b8678027f4a6e96bfae28151fa6b97d801b39..f842e4ac720bf42a935de39f7938c725d6b3dec2 100644 (file)
@@ -65,6 +65,9 @@
 #ifndef HEADER_X509_VFY_H
 #define HEADER_X509_VFY_H
 
+#ifndef NO_LHASH
+#include <openssl/lhash.h>
+#endif
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
 
@@ -190,7 +193,7 @@ typedef struct x509_store_st
        {
        /* The following is a cache of trusted certs */
        int cache;      /* if true, stash any hits */
-#ifdef HEADER_LHASH_H
+#ifndef NO_LHASH
        LHASH *certs;   /* cached certs; */ 
 #else
        char *certs;
@@ -315,7 +318,7 @@ struct x509_store_state_st      /* X509_STORE_CTX */
 #define X509v3_add_standard_extensions oX509v3_add_standard_extensions
 #endif
 
-#ifdef HEADER_LHASH_H
+#ifndef NO_LHASH
 X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h,int type,X509_NAME *name);
 #endif
 void X509_OBJECT_up_ref_count(X509_OBJECT *a);
index 16fe6940b8248eb9b76618eb421ac1380700afe9..7c60bb74015d3e038d1bf717a23277a45cb1c735 100644 (file)
--- a/ssl/ssl.h
+++ b/ssl/ssl.h
 #ifndef HEADER_SSL_H 
 #define HEADER_SSL_H 
 
+#ifndef NO_COMP
+#include <openssl/comp.h>
+#endif
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
+#ifndef NO_X509
+#include <openssl/x509.h>
+#endif
 #include <openssl/safestack.h>
 
 #ifdef  __cplusplus
@@ -385,7 +394,7 @@ typedef struct ssl_comp_st
 {
     int id;
     char *name;
-#ifdef HEADER_COMP_H
+#ifndef NO_COMP
     COMP_METHOD *method;
 #else
     char *method;
@@ -603,7 +612,7 @@ struct ssl_st
         * same.  This is so data can be read and written to different
         * handlers */
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
        BIO *rbio; /* used by SSL_read */
        BIO *wbio; /* used by SSL_write */
        BIO *bbio; /* used during session-id reuse to concatinate
@@ -667,7 +676,7 @@ struct ssl_st
 
        EVP_CIPHER_CTX *enc_read_ctx;           /* cryptographic state */
        const EVP_MD *read_hash;                /* used for mac generation */
-#ifdef HEADER_COMP_H
+#ifndef NO_COMP
        COMP_CTX *expand;                       /* uncompress */
 #else
        char *expand;
@@ -675,7 +684,7 @@ struct ssl_st
 
        EVP_CIPHER_CTX *enc_write_ctx;          /* cryptographic state */
        const EVP_MD *write_hash;               /* used for mac generation */
-#ifdef HEADER_COMP_H
+#ifndef NO_COMP
        COMP_CTX *compress;                     /* compression */
 #else
        char *compress; 
@@ -961,7 +970,7 @@ size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);
 #define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
 #endif
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 BIO_METHOD *BIO_f_ssl(void);
 BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
 BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
@@ -998,7 +1007,7 @@ int        SSL_set_fd(SSL *s, int fd);
 int    SSL_set_rfd(SSL *s, int fd);
 int    SSL_set_wfd(SSL *s, int fd);
 #endif
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 void   SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
 BIO *  SSL_get_rbio(SSL *s);
 BIO *  SSL_get_wbio(SSL *s);
@@ -1053,7 +1062,7 @@ int       SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
 #ifndef NO_FP_API
 int    SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
 #endif
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int    SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
 #endif
 void   SSL_SESSION_free(SSL_SESSION *ses);
@@ -1249,7 +1258,7 @@ void SSL_set_tmp_dh_callback(SSL *ssl,
                                           int keylength));
 #endif
 
-#ifdef HEADER_COMP_H
+#ifndef NO_COMP
 int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
 #else
 int SSL_COMP_add_compression_method(int id,char *cm);
index f616763830e3362da08ab44b0a90c247b5d2bd7e..7ee1feaa677cb3785a2dfebbb83bd6948fe7c0b3 100644 (file)
@@ -59,6 +59,9 @@
 #ifndef HEADER_SSL3_H 
 #define HEADER_SSL3_H 
 
+#ifndef NO_COMP
+#include <openssl/comp.h>
+#endif
 #include <openssl/buffer.h>
 #include <openssl/evp.h>
 #include <openssl/ssl.h>
@@ -310,7 +313,7 @@ typedef struct ssl3_state_st
 
                const EVP_CIPHER *new_sym_enc;
                const EVP_MD *new_hash;
-#ifdef HEADER_COMP_H
+#ifndef NO_COMP
                const SSL_COMP *new_compression;
 #else
                char *new_compression;