openldap/include/ldap_cdefs.h

240 lines
8.9 KiB
C
Raw Normal View History

1999-08-31 09:17:01 +08:00
/* $OpenLDAP$ */
2003-11-26 15:16:36 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2004-01-02 03:15:16 +08:00
* Copyright 1998-2004 The OpenLDAP Foundation.
1998-12-29 03:51:35 +08:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
2003-11-26 15:16:36 +08:00
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
1998-12-29 03:51:35 +08:00
*/
1998-10-25 09:41:42 +08:00
/* LDAP C Defines */
#ifndef _LDAP_CDEFS_H
#define _LDAP_CDEFS_H
1999-07-14 02:41:00 +08:00
#if defined(__cplusplus) || defined(c_plusplus)
1998-10-25 09:41:42 +08:00
# define LDAP_BEGIN_DECL extern "C" {
# define LDAP_END_DECL }
#else
# define LDAP_BEGIN_DECL /* begin declarations */
# define LDAP_END_DECL /* end declarations */
1998-10-25 09:41:42 +08:00
#endif
#if !defined(LDAP_NO_PROTOTYPES) && ( defined(LDAP_NEEDS_PROTOTYPES) || \
1999-07-14 02:41:00 +08:00
defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) )
1998-10-25 09:41:42 +08:00
/* ANSI C or C++ */
# define LDAP_P(protos) protos
# define LDAP_CONCAT1(x,y) x ## y
# define LDAP_CONCAT(x,y) LDAP_CONCAT1(x,y)
# define LDAP_STRING(x) #x /* stringify without expanding x */
# define LDAP_XSTRING(x) LDAP_STRING(x) /* expand x, then stringify */
#ifndef LDAP_CONST
# define LDAP_CONST const
#endif
#else /* no prototypes */
1998-10-25 09:41:42 +08:00
/* traditional C */
# define LDAP_P(protos) ()
# define LDAP_CONCAT(x,y) x/**/y
# define LDAP_STRING(x) "x"
#ifndef LDAP_CONST
# define LDAP_CONST /* no const */
#endif
#endif /* no prototypes */
#if (__GNUC__) * 1000 + (__GNUC_MINOR__) >= 2006
# define LDAP_GCCATTR(attrs) __attribute__(attrs)
#else
# define LDAP_GCCATTR(attrs)
#endif
2001-12-07 12:03:25 +08:00
/*
* Support for Windows DLLs.
*
* When external source code includes header files for dynamic libraries,
* the external source code is "importing" DLL symbols into its resulting
* object code. On Windows, symbols imported from DLLs must be explicitly
* indicated in header files with the __declspec(dllimport) directive.
* This is not totally necessary for functions because the compiler
* (gcc or MSVC) will generate stubs when this directive is absent.
* However, this is required for imported variables.
*
* The LDAP libraries, i.e. liblber and libldap, can be built as
* static or shared, based on configuration. Just about all other source
* code in OpenLDAP use these libraries. If the LDAP libraries
* are configured as shared, 'configure' defines the LDAP_LIBS_DYNAMIC
* macro. When other source files include LDAP library headers, the
* LDAP library symbols will automatically be marked as imported. When
* the actual LDAP libraries are being built, the symbols will not
* be marked as imported because the LBER_LIBRARY or LDAP_LIBRARY macros
* will be respectively defined.
*
* Any project outside of OpenLDAP with source code wanting to use
* LDAP dynamic libraries should explicitly define LDAP_LIBS_DYNAMIC.
* This will ensure that external source code appropriately marks symbols
* that will be imported.
*
* The slapd executable, itself, can be used as a dynamic library.
* For example, if a backend module is compiled as shared, it will
* import symbols from slapd. When this happens, the slapd symbols
* must be marked as imported in header files that the backend module
* includes. Remember that slapd links with various static libraries.
* If the LDAP libraries were configured as static, their object
* code is also part of the monolithic slapd executable. Thus, when
* a backend module imports symbols from slapd, it imports symbols from
* all of the static libraries in slapd as well. Thus, the SLAP_IMPORT
* macro, when defined, will appropriately mark symbols as imported.
* This macro should be used by shared backend modules as well as any
* other external source code that imports symbols from the slapd
* executable as if it were a DLL.
*
* Note that we don't actually have to worry about using the
* __declspec(dllexport) directive anywhere. This is because both
* MSVC and Mingw provide alternate (more effective) methods for exporting
* symbols out of binaries, i.e. the use of a DEF file.
*
* NOTE ABOUT BACKENDS: Backends can be configured as static or dynamic.
* When a backend is configured as dynamic, slapd will load the backend
* explicitly and populate function pointer structures by calling
* the backend's well-known initialization function. Because of this
* procedure, slapd never implicitly imports symbols from dynamic backends.
* This makes it unnecessary to tag various backend functions with the
* __declspec(dllimport) directive. This is because neither slapd nor
* any other external binary should ever be implicitly loading a backend
* dynamic module.
*
* Backends are supposed to be self-contained. However, it appears that
* back-meta DOES implicitly import symbols from back-ldap. This means
* that the __declspec(dllimport) directive should be marked on back-ldap
* functions (in its header files) if and only if we're compiling for
* windows AND back-ldap has been configured as dynamic AND back-meta
* is the client of back-ldap. When client is slapd, there is no effect
* since slapd does not implicitly import symbols.
*
* TODO(?): Currently, back-meta nor back-ldap is supported for Mingw32.
* Thus, there's no need to worry about this right now. This is something that
* may or may not have to be addressed in the future.
*/
/* LBER library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && \
((defined(LDAP_LIBS_DYNAMIC) && !defined(LBER_LIBRARY)) || \
(!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
# define LBER_F(type) extern __declspec(dllimport) type
# define LBER_V(type) extern __declspec(dllimport) type
#else
2000-06-20 11:53:12 +08:00
# define LBER_F(type) extern type
# define LBER_V(type) extern type
#endif
/* LDAP library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && \
((defined(LDAP_LIBS_DYNAMIC) && !defined(LDAP_LIBRARY)) || \
(!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
# define LDAP_F(type) extern __declspec(dllimport) type
# define LDAP_V(type) extern __declspec(dllimport) type
#else
2000-06-20 11:53:12 +08:00
# define LDAP_F(type) extern type
# define LDAP_V(type) extern type
#endif
1999-11-28 07:40:08 +08:00
/* AVL library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_AVL_F(type) extern __declspec(dllimport) type
# define LDAP_AVL_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
2001-12-07 12:03:25 +08:00
# define LDAP_AVL_F(type) extern type
# define LDAP_AVL_V(type) extern type
#endif
1999-11-28 07:40:08 +08:00
/* LDBM library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_LDBM_F(type) extern __declspec(dllimport) type
# define LDAP_LDBM_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
# define LDAP_LDBM_F(type) extern type
2000-06-20 11:53:12 +08:00
# define LDAP_LDBM_V(type) extern type
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
#endif
1998-10-25 09:41:42 +08:00
/* LDIF library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_LDIF_F(type) extern __declspec(dllimport) type
# define LDAP_LDIF_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
# define LDAP_LDIF_F(type) extern type
2000-06-20 11:53:12 +08:00
# define LDAP_LDIF_V(type) extern type
1999-11-28 07:40:08 +08:00
#endif
/* LUNICODE library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_LUNICODE_F(type) extern __declspec(dllimport) type
# define LDAP_LUNICODE_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
# define LDAP_LUNICODE_F(type) extern type
2000-06-20 11:53:12 +08:00
# define LDAP_LUNICODE_V(type) extern type
1999-11-28 07:40:08 +08:00
#endif
/* LUTIL library */
2001-12-07 12:03:25 +08:00
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_LUTIL_F(type) extern __declspec(dllimport) type
# define LDAP_LUTIL_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
# define LDAP_LUTIL_F(type) extern type
2000-06-20 11:53:12 +08:00
# define LDAP_LUTIL_V(type) extern type
1999-11-28 07:40:08 +08:00
#endif
2001-12-07 12:03:25 +08:00
/* REWRITE library */
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_REWRITE_F(type) extern __declspec(dllimport) type
# define LDAP_REWRITE_V(type) extern __declspec(dllimport) type
#else
# define LDAP_REWRITE_F(type) extern type
# define LDAP_REWRITE_V(type) extern type
#endif
/* SLAPD (as a dynamic library exporting symbols) */
#if defined(_WIN32) && defined(SLAPD_IMPORT)
# define LDAP_SLAPD_F(type) extern __declspec(dllimport) type
# define LDAP_SLAPD_V(type) extern __declspec(dllimport) type
1999-11-28 07:40:08 +08:00
#else
# define LDAP_SLAPD_F(type) extern type
2000-06-20 11:53:12 +08:00
# define LDAP_SLAPD_V(type) extern type
1999-11-28 07:40:08 +08:00
#endif
2001-12-07 12:03:25 +08:00
/*
* C library. Mingw32 links with the dynamic C run-time library by default,
* so the explicit definition of CSTATIC will keep dllimport from
* being defined, if desired.
*
* MSVC defines the _DLL macro when the compiler is invoked with /MD or /MDd,
* which means the resulting object code will be linked with the dynamic
* C run-time library.
*
* Technically, it shouldn't be necessary to redefine any functions that
* the headers for the C library should already contain. Nevertheless, this
* is here as a safe-guard.
*
* TODO: Determine if these macros ever get expanded for Windows. If not,
* the declspec expansion can probably be removed.
*/
#if (defined(__MINGW32__) && !defined(CSTATIC)) || \
(defined(_MSC_VER) && defined(_DLL))
# define LDAP_LIBC_F(type) extern __declspec(dllimport) type
# define LDAP_LIBC_V(type) extern __declspec(dllimport) type
#else
# define LDAP_LIBC_F(type) extern type
# define LDAP_LIBC_V(type) extern type
#endif
1999-11-28 07:40:08 +08:00
#endif /* _LDAP_CDEFS_H */