netsite.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #ifndef NETSITE_H
  13. #define NETSITE_H
  14. #ifndef NOINTNSAPI
  15. #define INTNSAPI
  16. #endif /* !NOINTNSAPI */
  17. /*
  18. * Standard defs for NetSite servers.
  19. */
  20. /*
  21. ** Macro shorthands for conditional C++ extern block delimiters.
  22. ** Don't redefine for compatability with NSPR.
  23. */
  24. #ifndef NSPR_BEGIN_EXTERN_C
  25. #ifdef __cplusplus
  26. #define NSPR_BEGIN_EXTERN_C extern "C" {
  27. #define NSPR_END_EXTERN_C }
  28. #else
  29. #define NSPR_BEGIN_EXTERN_C
  30. #define NSPR_END_EXTERN_C
  31. #endif
  32. #endif /* NSPR_BEGIN_EXTERN_C */
  33. #ifdef __cplusplus
  34. #define EXTERNC extern "C"
  35. #else
  36. #define EXTERNC
  37. #endif
  38. #ifndef BASE_SYSTEMS_H
  39. #include "base/systems.h"
  40. #endif /* !BASE_SYSTEMS_H */
  41. #ifndef VOID
  42. #define VOID void
  43. #endif
  44. #if !defined (boolean) && !defined (__GNUC__)
  45. typedef int boolean;
  46. #endif
  47. #define NS_TRUE 1
  48. #define NS_FALSE 0
  49. NSPR_BEGIN_EXTERN_C
  50. #ifndef APSTUDIO_READONLY_SYMBOLS
  51. /* Include the public netsite.h definitions */
  52. #ifndef PUBLIC_NETSITE_H
  53. #ifdef MALLOC_DEBUG
  54. #define NS_MALLOC_DEBUG
  55. #endif /* MALLOC_DEBUG */
  56. #include "public/netsite.h"
  57. #endif /* PUBLIC_NETSITE_H */
  58. #endif /* !APSTUDIO_READONLY_SYMBOLS */
  59. /*
  60. * If NS_MALLOC_DEBUG is defined, declare the debug version of the memory
  61. * allocation API.
  62. */
  63. #ifdef NS_MALLOC_DEBUG
  64. #define PERM_MALLOC(size) INTsystem_malloc_perm(size, __LINE__, __FILE__)
  65. NSAPI_PUBLIC void *INTsystem_malloc_perm(int size, int line, char *file);
  66. #define PERM_CALLOC(size) INTsystem_calloc_perm(size, __LINE__, __FILE__)
  67. NSAPI_PUBLIC void *INTsystem_calloc_perm(int size, int line, char *file);
  68. #define PERM_REALLOC(ptr, size) INTsystem_realloc_perm(ptr, size, __LINE__, __FILE__)
  69. NSAPI_PUBLIC void *INTsystem_realloc_perm(void *ptr, int size, int line, char *file);
  70. #define PERM_FREE(ptr) INTsystem_free_perm((void *) ptr, __LINE__, __FILE__)
  71. NSAPI_PUBLIC void INTsystem_free_perm(void *ptr, int line, char *file);
  72. #define PERM_STRDUP(ptr) INTsystem_strdup_perm(ptr, __LINE__, __FILE__)
  73. NSAPI_PUBLIC char *INTsystem_strdup_perm(const char *ptr, int line, char *file);
  74. #endif /* NS_MALLOC_DEBUG */
  75. /*
  76. * Only the mainline needs to set the malloc key.
  77. */
  78. void setThreadMallocKey(int key);
  79. /* This probably belongs somewhere else, perhaps with a different name */
  80. NSAPI_PUBLIC char *INTdns_guess_domain(char * hname);
  81. /* --- Begin public functions --- */
  82. #ifdef INTNSAPI
  83. NSAPI_PUBLIC char *INTsystem_version();
  84. /*
  85. Depending on the system, memory allocated via these macros may come from
  86. an arena. If these functions are called from within an Init function, they
  87. will be allocated from permanent storage. Otherwise, they will be freed
  88. when the current request is finished.
  89. */
  90. #define MALLOC(size) INTsystem_malloc(size)
  91. NSAPI_PUBLIC void *INTsystem_malloc(int size);
  92. #define CALLOC(size) INTsystem_calloc(size)
  93. NSAPI_PUBLIC void *INTsystem_calloc(int size);
  94. #define REALLOC(ptr, size) INTsystem_realloc(ptr, size)
  95. NSAPI_PUBLIC void *INTsystem_realloc(void *ptr, int size);
  96. #define FREE(ptr) INTsystem_free((void *) ptr)
  97. NSAPI_PUBLIC void INTsystem_free(void *ptr);
  98. #define STRDUP(ptr) INTsystem_strdup(ptr)
  99. NSAPI_PUBLIC char *INTsystem_strdup(const char *ptr);
  100. /*
  101. These macros always provide permanent storage, for use in global variables
  102. and such. They are checked at runtime to prevent them from returning NULL.
  103. */
  104. #ifndef NS_MALLOC_DEBUG
  105. #define PERM_MALLOC(size) INTsystem_malloc_perm(size)
  106. NSAPI_PUBLIC void *INTsystem_malloc_perm(int size);
  107. #define PERM_CALLOC(size) INTsystem_calloc_perm(size)
  108. NSAPI_PUBLIC void *INTsystem_calloc_perm(int size);
  109. #define PERM_REALLOC(ptr, size) INTsystem_realloc_perm(ptr, size)
  110. NSAPI_PUBLIC void *INTsystem_realloc_perm(void *ptr, int size);
  111. #define PERM_FREE(ptr) INTsystem_free_perm((void *) ptr)
  112. NSAPI_PUBLIC void INTsystem_free_perm(void *ptr);
  113. #define PERM_STRDUP(ptr) INTsystem_strdup_perm(ptr)
  114. NSAPI_PUBLIC char *INTsystem_strdup_perm(const char *ptr);
  115. #endif /* !NS_MALLOC_DEBUG */
  116. /* Thread-Private data key index for accessing the thread-private memory pool.
  117. * Each thread creates its own pool for allocating data. The MALLOC/FREE/etc
  118. * macros have been defined to check the thread private data area with the
  119. * thread_malloc_key index to find the address for the pool currently in use.
  120. *
  121. * If a thread wants to use a different pool, it must change the thread-local-
  122. * storage[thread_malloc_key].
  123. */
  124. NSAPI_PUBLIC int INTgetThreadMallocKey(void);
  125. /* Not sure where to put this. */
  126. NSAPI_PUBLIC void INTmagnus_atrestart(void (*fn)(void *), void *data);
  127. #endif /* INTNSAPI */
  128. /* --- End public functions --- */
  129. NSPR_END_EXTERN_C
  130. #define system_version_set INTsystem_version_set
  131. #define dns_guess_domain INTdns_guess_domain
  132. #ifdef INTNSAPI
  133. #define system_version INTsystem_version
  134. #define system_malloc INTsystem_malloc
  135. #define system_calloc INTsystem_calloc
  136. #define system_realloc INTsystem_realloc
  137. #define system_free INTsystem_free
  138. #define system_strdup INTsystem_strdup
  139. #define system_malloc_perm INTsystem_malloc_perm
  140. #define system_calloc_perm INTsystem_calloc_perm
  141. #define system_realloc_perm INTsystem_realloc_perm
  142. #define system_free_perm INTsystem_free_perm
  143. #define system_strdup_perm INTsystem_strdup_perm
  144. #define getThreadMallocKey INTgetThreadMallocKey
  145. #define magnus_atrestart INTmagnus_atrestart
  146. #endif /* INTNSAPI */
  147. #endif /* NETSITE_H */