1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME:
80**
81**      commonp.h
82**
83**  FACILITY:
84**
85**      Remote Procedure Call (RPC)
86**
87**  ABSTRACT:
88**
89**  Definitions of types/constants internal to runtime.
90**
91**
92*/
93
94/* ========================================================================= */
95
96/*
97 * Your OS / machine specific configuration file can override any of the
98 * default definitions / includes in this file.  Additional definitions /
99 * overrides that exist:
100 *
101 *  Controls for generic conditional compilation:
102 *      NCS1_COMPATIBILITY  - enable inclusion of NCS 1.5.1 API support
103 *      FTN_INTERLUDES      - enable inclusion of FTN callable API
104 *      DEBUG               - enable inclusion of various runtime debugging
105 *                            features
106 *      RPC_MUTEX_DEBUG     - enable mutex lock / cond var debugging
107 *      RPC_MUTEX_STATS     - enable mutex lock / cond var statistics
108 *      MAX_DEBUG           - enable inclusion of additional debug code
109 *                          (e.g. DG pkt logging capability)
110 *      RPC_DG_LOSSY        - enable inclusion of DG lossy test code
111 *
112 *      INET                - enable inclusion of Internet Domain family support
113 *      DDS                 - enable inclusion of Apollo DOMAIN Domain family
114 *                            support
115 *       NO_ELLIPSIS        - disable function prototypes which have
116 *                            an ellipsis in them.
117 *
118 *      CONVENTIONAL_ALIGNMENT
119 *
120 *  Controls for alternate implementations of things:
121 *      STDARG_PRINTF       - use ANSI C stdarg.h for rpc__printf
122 *                          (otherwise use varargs.h)
123 *      NO_VARARGS_PRINTF   - no varargs.h for rpc__printf; wing it
124 *      NO_RPC_PRINTF       - none of the various rpc__printf implementations
125 *                          is appropriate - provide your own. e.g.
126 *                              #define rpc__printf printf
127 *      NO_SSCANF           - define to prevent direct use of sscanf()
128 *      NO_SPRINTF          - define to prevent direct use of sprintf()
129 *      NO_GETENV           - define to prevent direct use of getenv()
130 */
131
132#ifndef _COMMONP_H
133#define _COMMONP_H  1
134
135#ifdef HAVE_CONFIG_H
136#include <config.h>
137#endif
138
139/*
140 * Include a OS / machine specific configuration file.
141 */
142
143#ifdef DCE_RPC_DEBUG
144#define DCE_DEBUG	1
145#endif
146
147#include <sysconf.h>
148
149/* For FreeDCE, use these to declare loadable image entry point functions */
150#if HAVE_DLFCN_H
151# define _RPC_MODULE_ENTRY_PTR(func_name)	void * rpc_module_init_func = (void*)func_name
152#else
153# define _RPC_MODULE_ENTRY_PTR(func_name)	/* nothing */
154#endif
155
156/* ========================================================================= */
157
158/* ========================================================================= */
159
160/*
161 * EXTERNAL
162 *      Applied to variables that are external to a module.
163 * GLOBAL
164 *      Applied to defining instance of a variable.
165 * PUBLIC
166 *      Applied to (global) functions that are part of the defined API.
167 * PRIVATE
168 *      Applied to (global) functions that are NOT part of the defined API.
169 * INTERNAL
170 *      Applied to functions and variables that are private to a module.
171 */
172
173#ifndef EXTERNAL
174#  define EXTERNAL      extern
175#endif
176
177#ifndef GLOBAL
178#  define GLOBAL
179#endif
180
181#ifndef PUBLIC
182#  define PUBLIC
183#endif
184
185#ifndef PRIVATE
186#  define PRIVATE
187#endif
188
189#ifndef INTERNAL
190#  define INTERNAL        static
191#endif
192
193/* ========================================================================= */
194
195#ifndef NULL
196#define NULL 0
197#endif
198
199/*
200 * This boolean type is only for use internal to the runtime (it's smaller,
201 * so it saves storage in structures). All API routines should use boolean32,
202 * which is defined in nbase.idl (as are the values for 'true' and 'false').
203 */
204
205/* typedef unsigned char boolean;*/
206
207/*
208 * This definition is for use by towers.
209 */
210
211/*#was_define  byte_t  idl_byte  */
212typedef idl_byte byte_t ;
213
214/* ========================================================================= */
215
216#include <dce/nbase.h>
217#include <dce/lbase.h>
218#include <dce/rpc.h>
219#include <dce/stubbase.h>
220#include <rpclog.h>
221#include <dce/dce_error.h>
222
223/* ========================================================================= */
224
225#ifdef DCE_RPC_SVC
226#  include <rpcsvc.h>
227#else
228
229#ifndef EPRINTF
230#  define EPRINTF           rpc__printf
231#endif /* EPRINTF */
232
233#ifndef DIE
234#  define DIE(text)         rpc__die(text, __FILE__, __LINE__)
235#endif /* DIE */
236
237#endif	/* DCE_RPC_SVC */
238
239/* ========================================================================= */
240
241#ifndef UUID_EQ
242#  define UUID_EQ(uuid1, uuid2, st) \
243        (uuid_equal(&(uuid1), &(uuid2), (st)))
244#endif /* UUID_EQ */
245
246/*
247 * Macros to deal with NULL UUID pointers.
248 */
249
250#ifndef UUID_PTR
251#  define UUID_PTR(uuid_ptr) \
252        ((uuid_ptr) != NULL ? (uuid_ptr) : &uuid_g_nil_uuid)
253#endif /* UUID_PTR */
254
255#ifndef UUID_SET
256#  define UUID_SET(uuid_ptr_dst, uuid_src) \
257        if ((uuid_ptr_dst) != NULL) \
258	  *(uuid_ptr_dst) = (uuid_src);
259#endif /* UUID_SET */
260
261#ifndef UUID_IS_NIL
262#  define UUID_IS_NIL(uuid_ptr, st) \
263        (*(st) = 0, (uuid_ptr) == NULL || UUID_EQ(*(uuid_ptr), uuid_g_nil_uuid, st))
264#endif /* UUID_IS_NIL */
265
266#ifndef UUID_CREATE_NIL
267#  define UUID_CREATE_NIL(uuid_ptr) \
268    UUID_SET((uuid_ptr), uuid_g_nil_uuid)
269#endif /* UUID_CREATE_NIL */
270
271/* ========================================================================= */
272
273#ifndef MIN
274#  define MIN(x, y)         ((x) < (y) ? (x) : (y))
275#endif
276
277#ifndef MAX
278#  define MAX(x, y)         ((x) > (y) ? (x) : (y))
279#endif
280
281/* ========================================================================= */
282
283#ifndef CLOBBER_PTR
284#  ifdef DCE_RPC_DEBUG
285#    define CLOBBER_PTR(p) (*(dce_pointer_t *)&(p) = (dce_pointer_t) 0xdeaddead)
286#  else
287#    define CLOBBER_PTR(p)
288#  endif
289#endif /* CLOBBER_PTR */
290
291/* ========================================================================= */
292
293/*
294 * Macros for swapping bytes in integers and UUIDs.
295 */
296
297#ifndef SWAB_16
298#define SWAB_16(field) ( \
299    ((field & 0xff00) >> 8) | \
300    ((field & 0x00ff) << 8)   \
301)
302#endif /* SWAB_16 */
303
304#ifndef SWAB_32
305#define SWAB_32(field) ( \
306    ((field & 0xff000000) >> 24) | \
307    ((field & 0x00ff0000) >> 8)  | \
308    ((field & 0x0000ff00) << 8)  | \
309    ((field & 0x000000ff) << 24)   \
310)
311#endif /* SWAB_32 */
312
313#ifndef SWAB_INPLACE_16
314#define SWAB_INPLACE_16(field) { \
315    field = SWAB_16(field); \
316}
317#endif /* SWAB_INPLACE_16 */
318
319#ifndef SWAB_INPLACE_32
320#define SWAB_INPLACE_32(field) { \
321    field = SWAB_32(field); \
322}
323#endif /* SWAB_INPLACE_32 */
324
325#ifndef SWAB_INPLACE_UUID
326#define SWAB_INPLACE_UUID(ufield) { \
327    SWAB_INPLACE_32((ufield).time_low); \
328    SWAB_INPLACE_16((ufield).time_mid); \
329    SWAB_INPLACE_16((ufield).time_hi_and_version); \
330}
331#endif /* SWAB_INPLACE_UUID */
332
333#ifndef SWAP_INPLACE_16
334#define SWAP_INPLACE_16(ptr, end_of_pkt, st) { \
335    if (((unsigned8 *) (ptr) + 1) < (const unsigned8 *) (end_of_pkt)) \
336    { \
337        *(ptr) = SWAB_16(*(ptr)); \
338        *(st) = rpc_s_ok; \
339    } \
340    else \
341    { \
342        *(st) = rpc_s_bad_pkt; \
343    } \
344}
345#endif /* SWAP_INPLACE_16 */
346
347#ifndef SWAP_INPLACE_32
348#define SWAP_INPLACE_32(ptr, end_of_pkt, st) { \
349    if (((unsigned8 *) (ptr) + 3) < (const unsigned8 *) (end_of_pkt)) \
350    { \
351        *(ptr) = SWAB_32(*(ptr)); \
352        *(st) = rpc_s_ok; \
353    } \
354    else \
355    { \
356        *(st) = rpc_s_bad_pkt; \
357    } \
358}
359#endif /* SWAP_INPLACE_32 */
360
361/*
362 * Macros for converting to little endian, our data representation
363 * for writing towers and other integer data into the namespace.
364 */
365#ifndef RPC_RESOLVE_ENDIAN_INT16
366#define RPC_RESOLVE_ENDIAN_INT16(field) \
367{ \
368    if (NDR_LOCAL_INT_REP != ndr_c_int_little_endian) \
369    { \
370        SWAB_INPLACE_16 ((field)); \
371    } \
372}
373#endif /* RPC_RESOLVE_ENDIAN_INT16 */
374
375#ifndef RPC_RESOLVE_ENDIAN_INT32
376#define RPC_RESOLVE_ENDIAN_INT32(field) \
377{ \
378    if (NDR_LOCAL_INT_REP != ndr_c_int_little_endian) \
379    { \
380        SWAB_INPLACE_32 ((field)); \
381    } \
382}
383#endif /* RPC_RESOLVE_ENDIAN_INT32 */
384
385#ifndef RPC_RESOLVE_ENDIAN_UUID
386#define RPC_RESOLVE_ENDIAN_UUID(field) \
387{ \
388    if (NDR_LOCAL_INT_REP != ndr_c_int_little_endian) \
389    { \
390        SWAB_INPLACE_UUID ((field)); \
391    } \
392}
393#endif /* RPC_RESOLVE_ENDIAN_UUID */
394
395/* ========================================================================= */
396
397#ifdef ALT_COMMON_INCLUDE
398#  include ALT_COMMON_INCLUDE
399#else
400#  include <rpcfork.h>
401#  include <rpcdbg.h>
402#  include <rpcclock.h>
403#  include <rpcmem.h>
404#  include <rpcmutex.h>
405#  include <rpctimer.h>
406#  include <rpclist.h>
407#  include <rpcrand.h>
408#endif /* ALT_COMMON_INCLUDE */
409
410/* ========================================================================= */
411
412#endif /* _COMMON_H */
413