/gecko_api/include/secport.h
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/* 38 * secport.h - portability interfaces for security libraries 39 * 40 * $Id: secport.h,v 1.15 2008/02/14 18:41:38 wtc%google.com Exp $ 41 */ 42 43#ifndef _SECPORT_H_ 44#define _SECPORT_H_ 45 46#include "utilrename.h" 47 48/* 49 * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined 50 * by anyone else 51 */ 52#ifdef macintosh 53# ifndef XP_MAC 54# define XP_MAC 1 55# endif 56#endif 57 58#ifdef _WINDOWS 59# ifndef XP_WIN 60# define XP_WIN 61# endif 62#if defined(_WIN32) || defined(WIN32) 63# ifndef XP_WIN32 64# define XP_WIN32 65# endif 66#else 67# ifndef XP_WIN16 68# define XP_WIN16 69# endif 70#endif 71#endif 72 73#ifdef __BEOS__ 74# ifndef XP_BEOS 75# define XP_BEOS 76# endif 77#endif 78 79#ifdef unix 80# ifndef XP_UNIX 81# define XP_UNIX 82# endif 83#endif 84 85#if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__) 86#include "watcomfx.h" 87#endif 88 89#if defined(_WIN32_WCE) 90#include <windef.h> 91#include <types.h> 92#elif defined( XP_MAC ) 93#include <types.h> 94#include <time.h> /* for time_t below */ 95#else 96#include <sys/types.h> 97#endif 98 99#include <ctype.h> 100#include <string.h> 101#if defined(_WIN32_WCE) 102#include <stdlib.h> /* WinCE puts some stddef symbols here. */ 103#else 104#include <stddef.h> 105#endif 106#include <stdlib.h> 107#include "prtypes.h" 108#include "prlog.h" /* for PR_ASSERT */ 109#include "plarena.h" 110#include "plstr.h" 111 112/* 113 * HACK for NSS 2.8 to allow Admin to compile without source changes. 114 */ 115#ifndef SEC_BEGIN_PROTOS 116#include "seccomon.h" 117#endif 118 119SEC_BEGIN_PROTOS 120 121extern void *PORT_Alloc(size_t len); 122extern void *PORT_Realloc(void *old, size_t len); 123extern void *PORT_AllocBlock(size_t len); 124extern void *PORT_ReallocBlock(void *old, size_t len); 125extern void PORT_FreeBlock(void *ptr); 126extern void *PORT_ZAlloc(size_t len); 127extern void PORT_Free(void *ptr); 128extern void PORT_ZFree(void *ptr, size_t len); 129extern char *PORT_Strdup(const char *s); 130extern time_t PORT_Time(void); 131extern void PORT_SetError(int value); 132extern int PORT_GetError(void); 133 134extern PLArenaPool *PORT_NewArena(unsigned long chunksize); 135extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size); 136extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size); 137extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero); 138extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr, 139 size_t oldsize, size_t newsize); 140extern void *PORT_ArenaMark(PLArenaPool *arena); 141extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark); 142extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark); 143extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark); 144extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str); 145 146SEC_END_PROTOS 147 148#define PORT_Assert PR_ASSERT 149#define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type)) 150#define PORT_New(type) (type*)PORT_Alloc(sizeof(type)) 151#define PORT_ArenaNew(poolp, type) \ 152 (type*) PORT_ArenaAlloc(poolp, sizeof(type)) 153#define PORT_ArenaZNew(poolp, type) \ 154 (type*) PORT_ArenaZAlloc(poolp, sizeof(type)) 155#define PORT_NewArray(type, num) \ 156 (type*) PORT_Alloc (sizeof(type)*(num)) 157#define PORT_ZNewArray(type, num) \ 158 (type*) PORT_ZAlloc (sizeof(type)*(num)) 159#define PORT_ArenaNewArray(poolp, type, num) \ 160 (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num)) 161#define PORT_ArenaZNewArray(poolp, type, num) \ 162 (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num)) 163 164/* Please, keep these defines sorted alphabetically. Thanks! */ 165 166#define PORT_Atoi atoi 167 168#define PORT_Memcmp memcmp 169#define PORT_Memcpy memcpy 170#ifndef SUNOS4 171#define PORT_Memmove memmove 172#else /*SUNOS4*/ 173#define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n)) 174#endif/*SUNOS4*/ 175#define PORT_Memset memset 176 177#define PORT_Strcasecmp PL_strcasecmp 178#define PORT_Strcat strcat 179#define PORT_Strchr strchr 180#define PORT_Strrchr strrchr 181#define PORT_Strcmp strcmp 182#define PORT_Strcpy strcpy 183#define PORT_Strlen(s) strlen(s) 184#define PORT_Strncasecmp PL_strncasecmp 185#define PORT_Strncat strncat 186#define PORT_Strncmp strncmp 187#define PORT_Strncpy strncpy 188#define PORT_Strpbrk strpbrk 189#define PORT_Strstr strstr 190#define PORT_Strtok strtok 191 192#define PORT_Tolower tolower 193 194typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode, 195 unsigned char *inBuf, unsigned int inBufLen, 196 unsigned char *outBuf, unsigned int maxOutBufLen, 197 unsigned int *outBufLen, PRBool swapBytes); 198 199typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode, 200 unsigned char *inBuf, unsigned int inBufLen, 201 unsigned char *outBuf, unsigned int maxOutBufLen, 202 unsigned int *outBufLen); 203 204SEC_BEGIN_PROTOS 205 206void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc); 207void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc); 208PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, 209 unsigned int inBufLen, unsigned char *outBuf, 210 unsigned int maxOutBufLen, unsigned int *outBufLen); 211PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf, 212 unsigned int inBufLen, unsigned char *outBuf, 213 unsigned int maxOutBufLen, unsigned int *outBufLen, 214 PRBool swapBytes); 215void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc); 216PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, 217 unsigned int inBufLen, unsigned char *outBuf, 218 unsigned int maxOutBufLen, unsigned int *outBufLen); 219 220/* One-way conversion from ISO-8859-1 to UTF-8 */ 221PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf, 222 unsigned int inBufLen, unsigned char *outBuf, 223 unsigned int maxOutBufLen, unsigned int *outBufLen); 224 225PR_EXTERN(PRBool) 226sec_port_ucs4_utf8_conversion_function 227( 228 PRBool toUnicode, 229 unsigned char *inBuf, 230 unsigned int inBufLen, 231 unsigned char *outBuf, 232 unsigned int maxOutBufLen, 233 unsigned int *outBufLen 234); 235 236PR_EXTERN(PRBool) 237sec_port_ucs2_utf8_conversion_function 238( 239 PRBool toUnicode, 240 unsigned char *inBuf, 241 unsigned int inBufLen, 242 unsigned char *outBuf, 243 unsigned int maxOutBufLen, 244 unsigned int *outBufLen 245); 246 247/* One-way conversion from ISO-8859-1 to UTF-8 */ 248extern PRBool 249sec_port_iso88591_utf8_conversion_function 250( 251 const unsigned char *inBuf, 252 unsigned int inBufLen, 253 unsigned char *outBuf, 254 unsigned int maxOutBufLen, 255 unsigned int *outBufLen 256); 257 258extern int NSS_PutEnv(const char * envVarName, const char * envValue); 259 260SEC_END_PROTOS 261 262#endif /* _SECPORT_H_ */