/gecko_api/include/secport.h

http://firefox-mac-pdf.googlecode.com/ · C Header · 262 lines · 180 code · 32 blank · 50 comment · 2 complexity · c2b3551ffd3ecc6fbbec2149c449484e MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. *
  23. * Alternatively, the contents of this file may be used under the terms of
  24. * either the GNU General Public License Version 2 or later (the "GPL"), or
  25. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26. * in which case the provisions of the GPL or the LGPL are applicable instead
  27. * of those above. If you wish to allow use of your version of this file only
  28. * under the terms of either the GPL or the LGPL, and not to allow others to
  29. * use your version of this file under the terms of the MPL, indicate your
  30. * decision by deleting the provisions above and replace them with the notice
  31. * and other provisions required by the GPL or the LGPL. If you do not delete
  32. * the provisions above, a recipient may use your version of this file under
  33. * the terms of any one of the MPL, the GPL or the LGPL.
  34. *
  35. * ***** END LICENSE BLOCK ***** */
  36. /*
  37. * secport.h - portability interfaces for security libraries
  38. *
  39. * $Id: secport.h,v 1.15 2008/02/14 18:41:38 wtc%google.com Exp $
  40. */
  41. #ifndef _SECPORT_H_
  42. #define _SECPORT_H_
  43. #include "utilrename.h"
  44. /*
  45. * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
  46. * by anyone else
  47. */
  48. #ifdef macintosh
  49. # ifndef XP_MAC
  50. # define XP_MAC 1
  51. # endif
  52. #endif
  53. #ifdef _WINDOWS
  54. # ifndef XP_WIN
  55. # define XP_WIN
  56. # endif
  57. #if defined(_WIN32) || defined(WIN32)
  58. # ifndef XP_WIN32
  59. # define XP_WIN32
  60. # endif
  61. #else
  62. # ifndef XP_WIN16
  63. # define XP_WIN16
  64. # endif
  65. #endif
  66. #endif
  67. #ifdef __BEOS__
  68. # ifndef XP_BEOS
  69. # define XP_BEOS
  70. # endif
  71. #endif
  72. #ifdef unix
  73. # ifndef XP_UNIX
  74. # define XP_UNIX
  75. # endif
  76. #endif
  77. #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
  78. #include "watcomfx.h"
  79. #endif
  80. #if defined(_WIN32_WCE)
  81. #include <windef.h>
  82. #include <types.h>
  83. #elif defined( XP_MAC )
  84. #include <types.h>
  85. #include <time.h> /* for time_t below */
  86. #else
  87. #include <sys/types.h>
  88. #endif
  89. #include <ctype.h>
  90. #include <string.h>
  91. #if defined(_WIN32_WCE)
  92. #include <stdlib.h> /* WinCE puts some stddef symbols here. */
  93. #else
  94. #include <stddef.h>
  95. #endif
  96. #include <stdlib.h>
  97. #include "prtypes.h"
  98. #include "prlog.h" /* for PR_ASSERT */
  99. #include "plarena.h"
  100. #include "plstr.h"
  101. /*
  102. * HACK for NSS 2.8 to allow Admin to compile without source changes.
  103. */
  104. #ifndef SEC_BEGIN_PROTOS
  105. #include "seccomon.h"
  106. #endif
  107. SEC_BEGIN_PROTOS
  108. extern void *PORT_Alloc(size_t len);
  109. extern void *PORT_Realloc(void *old, size_t len);
  110. extern void *PORT_AllocBlock(size_t len);
  111. extern void *PORT_ReallocBlock(void *old, size_t len);
  112. extern void PORT_FreeBlock(void *ptr);
  113. extern void *PORT_ZAlloc(size_t len);
  114. extern void PORT_Free(void *ptr);
  115. extern void PORT_ZFree(void *ptr, size_t len);
  116. extern char *PORT_Strdup(const char *s);
  117. extern time_t PORT_Time(void);
  118. extern void PORT_SetError(int value);
  119. extern int PORT_GetError(void);
  120. extern PLArenaPool *PORT_NewArena(unsigned long chunksize);
  121. extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size);
  122. extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size);
  123. extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero);
  124. extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr,
  125. size_t oldsize, size_t newsize);
  126. extern void *PORT_ArenaMark(PLArenaPool *arena);
  127. extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark);
  128. extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark);
  129. extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark);
  130. extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str);
  131. SEC_END_PROTOS
  132. #define PORT_Assert PR_ASSERT
  133. #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type))
  134. #define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
  135. #define PORT_ArenaNew(poolp, type) \
  136. (type*) PORT_ArenaAlloc(poolp, sizeof(type))
  137. #define PORT_ArenaZNew(poolp, type) \
  138. (type*) PORT_ArenaZAlloc(poolp, sizeof(type))
  139. #define PORT_NewArray(type, num) \
  140. (type*) PORT_Alloc (sizeof(type)*(num))
  141. #define PORT_ZNewArray(type, num) \
  142. (type*) PORT_ZAlloc (sizeof(type)*(num))
  143. #define PORT_ArenaNewArray(poolp, type, num) \
  144. (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num))
  145. #define PORT_ArenaZNewArray(poolp, type, num) \
  146. (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num))
  147. /* Please, keep these defines sorted alphabetically. Thanks! */
  148. #define PORT_Atoi atoi
  149. #define PORT_Memcmp memcmp
  150. #define PORT_Memcpy memcpy
  151. #ifndef SUNOS4
  152. #define PORT_Memmove memmove
  153. #else /*SUNOS4*/
  154. #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n))
  155. #endif/*SUNOS4*/
  156. #define PORT_Memset memset
  157. #define PORT_Strcasecmp PL_strcasecmp
  158. #define PORT_Strcat strcat
  159. #define PORT_Strchr strchr
  160. #define PORT_Strrchr strrchr
  161. #define PORT_Strcmp strcmp
  162. #define PORT_Strcpy strcpy
  163. #define PORT_Strlen(s) strlen(s)
  164. #define PORT_Strncasecmp PL_strncasecmp
  165. #define PORT_Strncat strncat
  166. #define PORT_Strncmp strncmp
  167. #define PORT_Strncpy strncpy
  168. #define PORT_Strpbrk strpbrk
  169. #define PORT_Strstr strstr
  170. #define PORT_Strtok strtok
  171. #define PORT_Tolower tolower
  172. typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode,
  173. unsigned char *inBuf, unsigned int inBufLen,
  174. unsigned char *outBuf, unsigned int maxOutBufLen,
  175. unsigned int *outBufLen, PRBool swapBytes);
  176. typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode,
  177. unsigned char *inBuf, unsigned int inBufLen,
  178. unsigned char *outBuf, unsigned int maxOutBufLen,
  179. unsigned int *outBufLen);
  180. SEC_BEGIN_PROTOS
  181. void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
  182. void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc);
  183. PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
  184. unsigned int inBufLen, unsigned char *outBuf,
  185. unsigned int maxOutBufLen, unsigned int *outBufLen);
  186. PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf,
  187. unsigned int inBufLen, unsigned char *outBuf,
  188. unsigned int maxOutBufLen, unsigned int *outBufLen,
  189. PRBool swapBytes);
  190. void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
  191. PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
  192. unsigned int inBufLen, unsigned char *outBuf,
  193. unsigned int maxOutBufLen, unsigned int *outBufLen);
  194. /* One-way conversion from ISO-8859-1 to UTF-8 */
  195. PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf,
  196. unsigned int inBufLen, unsigned char *outBuf,
  197. unsigned int maxOutBufLen, unsigned int *outBufLen);
  198. PR_EXTERN(PRBool)
  199. sec_port_ucs4_utf8_conversion_function
  200. (
  201. PRBool toUnicode,
  202. unsigned char *inBuf,
  203. unsigned int inBufLen,
  204. unsigned char *outBuf,
  205. unsigned int maxOutBufLen,
  206. unsigned int *outBufLen
  207. );
  208. PR_EXTERN(PRBool)
  209. sec_port_ucs2_utf8_conversion_function
  210. (
  211. PRBool toUnicode,
  212. unsigned char *inBuf,
  213. unsigned int inBufLen,
  214. unsigned char *outBuf,
  215. unsigned int maxOutBufLen,
  216. unsigned int *outBufLen
  217. );
  218. /* One-way conversion from ISO-8859-1 to UTF-8 */
  219. extern PRBool
  220. sec_port_iso88591_utf8_conversion_function
  221. (
  222. const unsigned char *inBuf,
  223. unsigned int inBufLen,
  224. unsigned char *outBuf,
  225. unsigned int maxOutBufLen,
  226. unsigned int *outBufLen
  227. );
  228. extern int NSS_PutEnv(const char * envVarName, const char * envValue);
  229. SEC_END_PROTOS
  230. #endif /* _SECPORT_H_ */