security/nss/lib/util/secport.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/util/secport.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,250 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * secport.h - portability interfaces for security libraries
    1.10 + */
    1.11 +
    1.12 +#ifndef _SECPORT_H_
    1.13 +#define _SECPORT_H_
    1.14 +
    1.15 +#include "utilrename.h"
    1.16 +#include "prlink.h"
    1.17 +
    1.18 +/*
    1.19 + * define XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
    1.20 + * by anyone else
    1.21 + */
    1.22 +#ifdef _WINDOWS
    1.23 +# ifndef XP_WIN
    1.24 +# define XP_WIN
    1.25 +# endif
    1.26 +#if defined(_WIN32) || defined(WIN32)
    1.27 +# ifndef XP_WIN32
    1.28 +# define XP_WIN32
    1.29 +# endif
    1.30 +#endif
    1.31 +#endif
    1.32 +
    1.33 +#ifdef __BEOS__
    1.34 +# ifndef XP_BEOS
    1.35 +# define XP_BEOS
    1.36 +# endif
    1.37 +#endif
    1.38 +
    1.39 +#ifdef unix
    1.40 +# ifndef XP_UNIX
    1.41 +# define XP_UNIX
    1.42 +# endif
    1.43 +#endif
    1.44 +
    1.45 +#include <sys/types.h>
    1.46 +
    1.47 +#include <ctype.h>
    1.48 +#include <string.h>
    1.49 +#include <stddef.h>
    1.50 +#include <stdlib.h>
    1.51 +#include "prtypes.h"
    1.52 +#include "prlog.h"	/* for PR_ASSERT */
    1.53 +#include "plarena.h"
    1.54 +#include "plstr.h"
    1.55 +
    1.56 +/*
    1.57 + * HACK for NSS 2.8 to allow Admin to compile without source changes.
    1.58 + */
    1.59 +#ifndef SEC_BEGIN_PROTOS
    1.60 +#include "seccomon.h"
    1.61 +#endif
    1.62 +
    1.63 +SEC_BEGIN_PROTOS
    1.64 +
    1.65 +extern void *PORT_Alloc(size_t len);
    1.66 +extern void *PORT_Realloc(void *old, size_t len);
    1.67 +extern void *PORT_AllocBlock(size_t len);
    1.68 +extern void *PORT_ReallocBlock(void *old, size_t len);
    1.69 +extern void PORT_FreeBlock(void *ptr);
    1.70 +extern void *PORT_ZAlloc(size_t len);
    1.71 +extern void PORT_Free(void *ptr);
    1.72 +extern void PORT_ZFree(void *ptr, size_t len);
    1.73 +extern char *PORT_Strdup(const char *s);
    1.74 +extern time_t PORT_Time(void);
    1.75 +extern void PORT_SetError(int value);
    1.76 +extern int PORT_GetError(void);
    1.77 +
    1.78 +extern PLArenaPool *PORT_NewArena(unsigned long chunksize);
    1.79 +extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size);
    1.80 +extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size);
    1.81 +extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero);
    1.82 +extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr,
    1.83 +			    size_t oldsize, size_t newsize);
    1.84 +extern void *PORT_ArenaMark(PLArenaPool *arena);
    1.85 +extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark);
    1.86 +extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark);
    1.87 +extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark);
    1.88 +extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str);
    1.89 +
    1.90 +SEC_END_PROTOS
    1.91 +
    1.92 +#define PORT_Assert PR_ASSERT
    1.93 +#define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type))
    1.94 +#define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
    1.95 +#define PORT_ArenaNew(poolp, type)	\
    1.96 +		(type*) PORT_ArenaAlloc(poolp, sizeof(type))
    1.97 +#define PORT_ArenaZNew(poolp, type)	\
    1.98 +		(type*) PORT_ArenaZAlloc(poolp, sizeof(type))
    1.99 +#define PORT_NewArray(type, num)	\
   1.100 +		(type*) PORT_Alloc (sizeof(type)*(num))
   1.101 +#define PORT_ZNewArray(type, num)	\
   1.102 +		(type*) PORT_ZAlloc (sizeof(type)*(num))
   1.103 +#define PORT_ArenaNewArray(poolp, type, num)	\
   1.104 +		(type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num))
   1.105 +#define PORT_ArenaZNewArray(poolp, type, num)	\
   1.106 +		(type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num))
   1.107 +
   1.108 +/* Please, keep these defines sorted alphabetically.  Thanks! */
   1.109 +
   1.110 +#define PORT_Atoi(buff)	(int)strtol(buff, NULL, 10)
   1.111 +
   1.112 +/* Returns a UTF-8 encoded constant error string for err.
   1.113 + * Returns NULL if initialization of the error tables fails
   1.114 + * due to insufficient memory.
   1.115 + *
   1.116 + * This string must not be modified by the application.
   1.117 + */
   1.118 +#define PORT_ErrorToString(err) PR_ErrorToString((err), PR_LANGUAGE_I_DEFAULT)
   1.119 +
   1.120 +#define PORT_ErrorToName PR_ErrorToName
   1.121 +
   1.122 +#define PORT_Memcmp 	memcmp
   1.123 +#define PORT_Memcpy 	memcpy
   1.124 +#ifndef SUNOS4
   1.125 +#define PORT_Memmove 	memmove
   1.126 +#else /*SUNOS4*/
   1.127 +#define PORT_Memmove(s,ct,n)    bcopy ((ct), (s), (n))
   1.128 +#endif/*SUNOS4*/
   1.129 +#define PORT_Memset 	memset
   1.130 +
   1.131 +#define PORT_Strcasecmp PL_strcasecmp
   1.132 +#define PORT_Strcat 	strcat
   1.133 +#define PORT_Strchr 	strchr
   1.134 +#define PORT_Strrchr    strrchr
   1.135 +#define PORT_Strcmp 	strcmp
   1.136 +#define PORT_Strcpy 	strcpy
   1.137 +#define PORT_Strlen(s) 	strlen(s)
   1.138 +#define PORT_Strncasecmp PL_strncasecmp
   1.139 +#define PORT_Strncat 	strncat
   1.140 +#define PORT_Strncmp 	strncmp
   1.141 +#define PORT_Strncpy 	strncpy
   1.142 +#define PORT_Strpbrk    strpbrk
   1.143 +#define PORT_Strstr 	strstr
   1.144 +#define PORT_Strtok 	strtok
   1.145 +
   1.146 +#define PORT_Tolower 	tolower
   1.147 +
   1.148 +typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode,
   1.149 +			unsigned char *inBuf, unsigned int inBufLen,
   1.150 +			unsigned char *outBuf, unsigned int maxOutBufLen,
   1.151 +			unsigned int *outBufLen, PRBool swapBytes);
   1.152 +
   1.153 +typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode,
   1.154 +			unsigned char *inBuf, unsigned int inBufLen,
   1.155 +			unsigned char *outBuf, unsigned int maxOutBufLen,
   1.156 +			unsigned int *outBufLen);
   1.157 +
   1.158 +SEC_BEGIN_PROTOS
   1.159 +
   1.160 +void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
   1.161 +void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc);
   1.162 +PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
   1.163 +			unsigned int inBufLen, unsigned char *outBuf,
   1.164 +			unsigned int maxOutBufLen, unsigned int *outBufLen);
   1.165 +PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf,
   1.166 +			unsigned int inBufLen, unsigned char *outBuf,
   1.167 +			unsigned int maxOutBufLen, unsigned int *outBufLen,
   1.168 +			PRBool swapBytes);
   1.169 +void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
   1.170 +PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
   1.171 +			unsigned int inBufLen, unsigned char *outBuf,
   1.172 +			unsigned int maxOutBufLen, unsigned int *outBufLen);
   1.173 +
   1.174 +/* One-way conversion from ISO-8859-1 to UTF-8 */
   1.175 +PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf,
   1.176 +			unsigned int inBufLen, unsigned char *outBuf,
   1.177 +			unsigned int maxOutBufLen, unsigned int *outBufLen);
   1.178 +
   1.179 +extern PRBool
   1.180 +sec_port_ucs4_utf8_conversion_function
   1.181 +(
   1.182 +  PRBool toUnicode,
   1.183 +  unsigned char *inBuf,
   1.184 +  unsigned int inBufLen,
   1.185 +  unsigned char *outBuf,
   1.186 +  unsigned int maxOutBufLen,
   1.187 +  unsigned int *outBufLen
   1.188 +);
   1.189 +
   1.190 +extern PRBool
   1.191 +sec_port_ucs2_utf8_conversion_function
   1.192 +(
   1.193 +  PRBool toUnicode,
   1.194 +  unsigned char *inBuf,
   1.195 +  unsigned int inBufLen,
   1.196 +  unsigned char *outBuf,
   1.197 +  unsigned int maxOutBufLen,
   1.198 +  unsigned int *outBufLen
   1.199 +);
   1.200 +
   1.201 +/* One-way conversion from ISO-8859-1 to UTF-8 */
   1.202 +extern PRBool
   1.203 +sec_port_iso88591_utf8_conversion_function
   1.204 +(
   1.205 +  const unsigned char *inBuf,
   1.206 +  unsigned int inBufLen,
   1.207 +  unsigned char *outBuf,
   1.208 +  unsigned int maxOutBufLen,
   1.209 +  unsigned int *outBufLen
   1.210 +);
   1.211 +
   1.212 +extern int NSS_PutEnv(const char * envVarName, const char * envValue);
   1.213 +
   1.214 +extern int NSS_SecureMemcmp(const void *a, const void *b, size_t n);
   1.215 +
   1.216 +/*
   1.217 + * Load a shared library called "newShLibName" in the same directory as
   1.218 + * a shared library that is already loaded, called existingShLibName.
   1.219 + * A pointer to a static function in that shared library,
   1.220 + * staticShLibFunc, is required.
   1.221 + *
   1.222 + * existingShLibName:
   1.223 + *   The file name of the shared library that shall be used as the 
   1.224 + *   "reference library". The loader will attempt to load the requested
   1.225 + *   library from the same directory as the reference library.
   1.226 + *
   1.227 + * staticShLibFunc:
   1.228 + *   Pointer to a static function in the "reference library".
   1.229 + *
   1.230 + * newShLibName:
   1.231 + *   The simple file name of the new shared library to be loaded.
   1.232 + *
   1.233 + * We use PR_GetLibraryFilePathname to get the pathname of the loaded 
   1.234 + * shared lib that contains this function, and then do a
   1.235 + * PR_LoadLibraryWithFlags with an absolute pathname for the shared
   1.236 + * library to be loaded.
   1.237 + *
   1.238 + * On Windows, the "alternate search path" strategy is employed, if available.
   1.239 + * On Unix, if existingShLibName is a symbolic link, and no link exists for the
   1.240 + * new library, the original link will be resolved, and the new library loaded
   1.241 + * from the resolved location.
   1.242 + *
   1.243 + * If the new shared library is not found in the same location as the reference
   1.244 + * library, it will then be loaded from the normal system library path.
   1.245 + */
   1.246 +PRLibrary *
   1.247 +PORT_LoadLibraryFromOrigin(const char* existingShLibName,
   1.248 +                 PRFuncPtr staticShLibFunc,
   1.249 +                 const char *newShLibName);
   1.250 +
   1.251 +SEC_END_PROTOS
   1.252 +
   1.253 +#endif /* _SECPORT_H_ */

mercurial