Back to index

openldap  2.4.31
ldap_cdefs.h
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  * 
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 /* LDAP C Defines */
00016 
00017 #ifndef _LDAP_CDEFS_H
00018 #define _LDAP_CDEFS_H
00019 
00020 #if defined(__cplusplus) || defined(c_plusplus)
00021 #      define LDAP_BEGIN_DECL      extern "C" {
00022 #      define LDAP_END_DECL }
00023 #else
00024 #      define LDAP_BEGIN_DECL      /* begin declarations */
00025 #      define LDAP_END_DECL /* end declarations */
00026 #endif
00027 
00028 #if !defined(LDAP_NO_PROTOTYPES) && ( defined(LDAP_NEEDS_PROTOTYPES) || \
00029        defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) )
00030 
00031        /* ANSI C or C++ */
00032 #      define LDAP_P(protos)       protos
00033 #      define LDAP_CONCAT1(x,y)    x ## y
00034 #      define LDAP_CONCAT(x,y)     LDAP_CONCAT1(x,y)
00035 #      define LDAP_STRING(x)       #x /* stringify without expanding x */
00036 #      define LDAP_XSTRING(x)      LDAP_STRING(x) /* expand x, then stringify */
00037 
00038 #ifndef LDAP_CONST
00039 #      define LDAP_CONST    const
00040 #endif
00041 
00042 #else /* no prototypes */
00043 
00044        /* traditional C */
00045 #      define LDAP_P(protos)       ()
00046 #      define LDAP_CONCAT(x,y)     xy
00047 #      define LDAP_STRING(x)       "x"
00048 
00049 #ifndef LDAP_CONST
00050 #      define LDAP_CONST    /* no const */
00051 #endif
00052 
00053 #endif /* no prototypes */
00054 
00055 #if (__GNUC__) * 1000 + (__GNUC_MINOR__) >= 2006
00056 #      define LDAP_GCCATTR(attrs)  __attribute__(attrs)
00057 #else
00058 #      define LDAP_GCCATTR(attrs)
00059 #endif
00060 
00061 /*
00062  * Support for Windows DLLs.
00063  *
00064  * When external source code includes header files for dynamic libraries,
00065  * the external source code is "importing" DLL symbols into its resulting
00066  * object code. On Windows, symbols imported from DLLs must be explicitly
00067  * indicated in header files with the __declspec(dllimport) directive.
00068  * This is not totally necessary for functions because the compiler
00069  * (gcc or MSVC) will generate stubs when this directive is absent.
00070  * However, this is required for imported variables.
00071  *
00072  * The LDAP libraries, i.e. liblber and libldap, can be built as
00073  * static or shared, based on configuration. Just about all other source
00074  * code in OpenLDAP use these libraries. If the LDAP libraries
00075  * are configured as shared, 'configure' defines the LDAP_LIBS_DYNAMIC
00076  * macro. When other source files include LDAP library headers, the
00077  * LDAP library symbols will automatically be marked as imported. When
00078  * the actual LDAP libraries are being built, the symbols will not
00079  * be marked as imported because the LBER_LIBRARY or LDAP_LIBRARY macros
00080  * will be respectively defined.
00081  *
00082  * Any project outside of OpenLDAP with source code wanting to use
00083  * LDAP dynamic libraries should explicitly define LDAP_LIBS_DYNAMIC.
00084  * This will ensure that external source code appropriately marks symbols
00085  * that will be imported.
00086  *
00087  * The slapd executable, itself, can be used as a dynamic library.
00088  * For example, if a backend module is compiled as shared, it will
00089  * import symbols from slapd. When this happens, the slapd symbols
00090  * must be marked as imported in header files that the backend module
00091  * includes. Remember that slapd links with various static libraries.
00092  * If the LDAP libraries were configured as static, their object
00093  * code is also part of the monolithic slapd executable. Thus, when
00094  * a backend module imports symbols from slapd, it imports symbols from
00095  * all of the static libraries in slapd as well. Thus, the SLAP_IMPORT
00096  * macro, when defined, will appropriately mark symbols as imported.
00097  * This macro should be used by shared backend modules as well as any
00098  * other external source code that imports symbols from the slapd
00099  * executable as if it were a DLL.
00100  *
00101  * Note that we don't actually have to worry about using the
00102  * __declspec(dllexport) directive anywhere. This is because both
00103  * MSVC and Mingw provide alternate (more effective) methods for exporting
00104  * symbols out of binaries, i.e. the use of a DEF file.
00105  *
00106  * NOTE ABOUT BACKENDS: Backends can be configured as static or dynamic.
00107  * When a backend is configured as dynamic, slapd will load the backend
00108  * explicitly and populate function pointer structures by calling
00109  * the backend's well-known initialization function. Because of this
00110  * procedure, slapd never implicitly imports symbols from dynamic backends.
00111  * This makes it unnecessary to tag various backend functions with the
00112  * __declspec(dllimport) directive. This is because neither slapd nor
00113  * any other external binary should ever be implicitly loading a backend
00114  * dynamic module.
00115  *
00116  * Backends are supposed to be self-contained. However, it appears that
00117  * back-meta DOES implicitly import symbols from back-ldap. This means
00118  * that the __declspec(dllimport) directive should be marked on back-ldap
00119  * functions (in its header files) if and only if we're compiling for
00120  * windows AND back-ldap has been configured as dynamic AND back-meta
00121  * is the client of back-ldap. When client is slapd, there is no effect
00122  * since slapd does not implicitly import symbols.
00123  *
00124  * TODO(?): Currently, back-meta nor back-ldap is supported for Mingw32.
00125  * Thus, there's no need to worry about this right now. This is something that
00126  * may or may not have to be addressed in the future.
00127  */
00128 
00129 /* LBER library */
00130 #if defined(_WIN32) && \
00131     ((defined(LDAP_LIBS_DYNAMIC) && !defined(LBER_LIBRARY)) || \
00132      (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
00133 #      define LBER_F(type)         extern __declspec(dllimport) type
00134 #      define LBER_V(type)         extern __declspec(dllimport) type
00135 #else
00136 #      define LBER_F(type)         extern type
00137 #      define LBER_V(type)         extern type
00138 #endif
00139 
00140 /* LDAP library */
00141 #if defined(_WIN32) && \
00142     ((defined(LDAP_LIBS_DYNAMIC) && !defined(LDAP_LIBRARY)) || \
00143      (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
00144 #      define LDAP_F(type)         extern __declspec(dllimport) type
00145 #      define LDAP_V(type)         extern __declspec(dllimport) type
00146 #else
00147 #      define LDAP_F(type)         extern type
00148 #      define LDAP_V(type)         extern type
00149 #endif
00150 
00151 /* AVL library */
00152 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00153 #      define LDAP_AVL_F(type)            extern __declspec(dllimport) type
00154 #      define LDAP_AVL_V(type)            extern __declspec(dllimport) type
00155 #else
00156 #      define LDAP_AVL_F(type)            extern type
00157 #      define LDAP_AVL_V(type)            extern type
00158 #endif
00159 
00160 /* LDIF library */
00161 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00162 #      define LDAP_LDIF_F(type)    extern __declspec(dllimport) type
00163 #      define LDAP_LDIF_V(type)    extern __declspec(dllimport) type
00164 #else
00165 #      define LDAP_LDIF_F(type)    extern type
00166 #      define LDAP_LDIF_V(type)    extern type
00167 #endif
00168 
00169 /* LUNICODE library */
00170 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00171 #      define LDAP_LUNICODE_F(type)       extern __declspec(dllimport) type
00172 #      define LDAP_LUNICODE_V(type)       extern __declspec(dllimport) type
00173 #else
00174 #      define LDAP_LUNICODE_F(type)       extern type
00175 #      define LDAP_LUNICODE_V(type)       extern type
00176 #endif
00177 
00178 /* LUTIL library */
00179 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00180 #      define LDAP_LUTIL_F(type)   extern __declspec(dllimport) type
00181 #      define LDAP_LUTIL_V(type)   extern __declspec(dllimport) type
00182 #else
00183 #      define LDAP_LUTIL_F(type)   extern type
00184 #      define LDAP_LUTIL_V(type)   extern type
00185 #endif
00186 
00187 /* REWRITE library */
00188 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00189 #      define LDAP_REWRITE_F(type) extern __declspec(dllimport) type
00190 #      define LDAP_REWRITE_V(type) extern __declspec(dllimport) type
00191 #else
00192 #      define LDAP_REWRITE_F(type) extern type
00193 #      define LDAP_REWRITE_V(type) extern type
00194 #endif
00195 
00196 /* SLAPD (as a dynamic library exporting symbols) */
00197 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00198 #      define LDAP_SLAPD_F(type)   extern __declspec(dllimport) type
00199 #      define LDAP_SLAPD_V(type)   extern __declspec(dllimport) type
00200 #else
00201 #      define LDAP_SLAPD_F(type)   extern type
00202 #      define LDAP_SLAPD_V(type)   extern type
00203 #endif
00204 
00205 /* SLAPD (as a dynamic library exporting symbols) */
00206 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00207 #      define LDAP_SLAPI_F(type)   extern __declspec(dllimport) type
00208 #      define LDAP_SLAPI_V(type)   extern __declspec(dllimport) type
00209 #else
00210 #      define LDAP_SLAPI_F(type)   extern type
00211 #      define LDAP_SLAPI_V(type)   extern type
00212 #endif
00213 
00214 /* SLAPD (as a dynamic library exporting symbols) */
00215 #if defined(_WIN32) && defined(SLAPD_IMPORT)
00216 #      define SLAPI_F(type)        extern __declspec(dllimport) type
00217 #      define SLAPI_V(type)        extern __declspec(dllimport) type
00218 #else
00219 #      define SLAPI_F(type)        extern type
00220 #      define SLAPI_V(type)        extern type
00221 #endif
00222 
00223 /*
00224  * C library. Mingw32 links with the dynamic C run-time library by default,
00225  * so the explicit definition of CSTATIC will keep dllimport from
00226  * being defined, if desired.
00227  *
00228  * MSVC defines the _DLL macro when the compiler is invoked with /MD or /MDd,
00229  * which means the resulting object code will be linked with the dynamic
00230  * C run-time library.
00231  *
00232  * Technically, it shouldn't be necessary to redefine any functions that
00233  * the headers for the C library should already contain. Nevertheless, this
00234  * is here as a safe-guard.
00235  *
00236  * TODO: Determine if these macros ever get expanded for Windows. If not,
00237  * the declspec expansion can probably be removed.
00238  */
00239 #if (defined(__MINGW32__) && !defined(CSTATIC)) || \
00240     (defined(_MSC_VER) && defined(_DLL))
00241 #      define LDAP_LIBC_F(type)    extern __declspec(dllimport) type
00242 #      define LDAP_LIBC_V(type)    extern __declspec(dllimport) type
00243 #else
00244 #      define LDAP_LIBC_F(type)    extern type
00245 #      define LDAP_LIBC_V(type)    extern type
00246 #endif
00247 
00248 #endif /* _LDAP_CDEFS_H */