andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * secport.h - portability interfaces for security libraries andre@0: */ andre@0: andre@0: #ifndef _SECPORT_H_ andre@0: #define _SECPORT_H_ andre@0: andre@0: #include "utilrename.h" andre@0: #include "prlink.h" andre@0: andre@0: /* andre@0: * define XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined andre@0: * by anyone else andre@0: */ andre@0: #ifdef _WINDOWS andre@0: # ifndef XP_WIN andre@0: # define XP_WIN andre@0: # endif andre@0: #if defined(_WIN32) || defined(WIN32) andre@0: # ifndef XP_WIN32 andre@0: # define XP_WIN32 andre@0: # endif andre@0: #endif andre@0: #endif andre@0: andre@0: #ifdef __BEOS__ andre@0: # ifndef XP_BEOS andre@0: # define XP_BEOS andre@0: # endif andre@0: #endif andre@0: andre@0: #ifdef unix andre@0: # ifndef XP_UNIX andre@0: # define XP_UNIX andre@0: # endif andre@0: #endif andre@0: andre@0: #include andre@0: andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include "prtypes.h" andre@0: #include "prlog.h" /* for PR_ASSERT */ andre@0: #include "plarena.h" andre@0: #include "plstr.h" andre@0: andre@0: /* andre@0: * HACK for NSS 2.8 to allow Admin to compile without source changes. andre@0: */ andre@0: #ifndef SEC_BEGIN_PROTOS andre@0: #include "seccomon.h" andre@0: #endif andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: extern void *PORT_Alloc(size_t len); andre@0: extern void *PORT_Realloc(void *old, size_t len); andre@0: extern void *PORT_AllocBlock(size_t len); andre@0: extern void *PORT_ReallocBlock(void *old, size_t len); andre@0: extern void PORT_FreeBlock(void *ptr); andre@0: extern void *PORT_ZAlloc(size_t len); andre@0: extern void PORT_Free(void *ptr); andre@0: extern void PORT_ZFree(void *ptr, size_t len); andre@0: extern char *PORT_Strdup(const char *s); andre@0: extern time_t PORT_Time(void); andre@0: extern void PORT_SetError(int value); andre@0: extern int PORT_GetError(void); andre@0: andre@0: extern PLArenaPool *PORT_NewArena(unsigned long chunksize); andre@0: extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size); andre@0: extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size); andre@0: extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero); andre@0: extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr, andre@0: size_t oldsize, size_t newsize); andre@0: extern void *PORT_ArenaMark(PLArenaPool *arena); andre@0: extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark); andre@0: extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark); andre@0: extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark); andre@0: extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #define PORT_Assert PR_ASSERT andre@0: #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type)) andre@0: #define PORT_New(type) (type*)PORT_Alloc(sizeof(type)) andre@0: #define PORT_ArenaNew(poolp, type) \ andre@0: (type*) PORT_ArenaAlloc(poolp, sizeof(type)) andre@0: #define PORT_ArenaZNew(poolp, type) \ andre@0: (type*) PORT_ArenaZAlloc(poolp, sizeof(type)) andre@0: #define PORT_NewArray(type, num) \ andre@0: (type*) PORT_Alloc (sizeof(type)*(num)) andre@0: #define PORT_ZNewArray(type, num) \ andre@0: (type*) PORT_ZAlloc (sizeof(type)*(num)) andre@0: #define PORT_ArenaNewArray(poolp, type, num) \ andre@0: (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num)) andre@0: #define PORT_ArenaZNewArray(poolp, type, num) \ andre@0: (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num)) andre@0: andre@0: /* Please, keep these defines sorted alphabetically. Thanks! */ andre@0: andre@0: #define PORT_Atoi(buff) (int)strtol(buff, NULL, 10) andre@0: andre@0: /* Returns a UTF-8 encoded constant error string for err. andre@0: * Returns NULL if initialization of the error tables fails andre@0: * due to insufficient memory. andre@0: * andre@0: * This string must not be modified by the application. andre@0: */ andre@0: #define PORT_ErrorToString(err) PR_ErrorToString((err), PR_LANGUAGE_I_DEFAULT) andre@0: andre@0: #define PORT_ErrorToName PR_ErrorToName andre@0: andre@0: #define PORT_Memcmp memcmp andre@0: #define PORT_Memcpy memcpy andre@0: #ifndef SUNOS4 andre@0: #define PORT_Memmove memmove andre@0: #else /*SUNOS4*/ andre@0: #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n)) andre@0: #endif/*SUNOS4*/ andre@0: #define PORT_Memset memset andre@0: andre@0: #define PORT_Strcasecmp PL_strcasecmp andre@0: #define PORT_Strcat strcat andre@0: #define PORT_Strchr strchr andre@0: #define PORT_Strrchr strrchr andre@0: #define PORT_Strcmp strcmp andre@0: #define PORT_Strcpy strcpy andre@0: #define PORT_Strlen(s) strlen(s) andre@0: #define PORT_Strncasecmp PL_strncasecmp andre@0: #define PORT_Strncat strncat andre@0: #define PORT_Strncmp strncmp andre@0: #define PORT_Strncpy strncpy andre@0: #define PORT_Strpbrk strpbrk andre@0: #define PORT_Strstr strstr andre@0: #define PORT_Strtok strtok andre@0: andre@0: #define PORT_Tolower tolower andre@0: andre@0: typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode, andre@0: unsigned char *inBuf, unsigned int inBufLen, andre@0: unsigned char *outBuf, unsigned int maxOutBufLen, andre@0: unsigned int *outBufLen, PRBool swapBytes); andre@0: andre@0: typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode, andre@0: unsigned char *inBuf, unsigned int inBufLen, andre@0: unsigned char *outBuf, unsigned int maxOutBufLen, andre@0: unsigned int *outBufLen); andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc); andre@0: void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc); andre@0: PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, andre@0: unsigned int inBufLen, unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, unsigned int *outBufLen); andre@0: PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf, andre@0: unsigned int inBufLen, unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, unsigned int *outBufLen, andre@0: PRBool swapBytes); andre@0: void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc); andre@0: PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, andre@0: unsigned int inBufLen, unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, unsigned int *outBufLen); andre@0: andre@0: /* One-way conversion from ISO-8859-1 to UTF-8 */ andre@0: PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf, andre@0: unsigned int inBufLen, unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, unsigned int *outBufLen); andre@0: andre@0: extern PRBool andre@0: sec_port_ucs4_utf8_conversion_function andre@0: ( andre@0: PRBool toUnicode, andre@0: unsigned char *inBuf, andre@0: unsigned int inBufLen, andre@0: unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, andre@0: unsigned int *outBufLen andre@0: ); andre@0: andre@0: extern PRBool andre@0: sec_port_ucs2_utf8_conversion_function andre@0: ( andre@0: PRBool toUnicode, andre@0: unsigned char *inBuf, andre@0: unsigned int inBufLen, andre@0: unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, andre@0: unsigned int *outBufLen andre@0: ); andre@0: andre@0: /* One-way conversion from ISO-8859-1 to UTF-8 */ andre@0: extern PRBool andre@0: sec_port_iso88591_utf8_conversion_function andre@0: ( andre@0: const unsigned char *inBuf, andre@0: unsigned int inBufLen, andre@0: unsigned char *outBuf, andre@0: unsigned int maxOutBufLen, andre@0: unsigned int *outBufLen andre@0: ); andre@0: andre@0: extern int NSS_PutEnv(const char * envVarName, const char * envValue); andre@0: andre@0: extern int NSS_SecureMemcmp(const void *a, const void *b, size_t n); andre@0: andre@0: #ifndef NSS_STATIC andre@0: /* andre@0: * Load a shared library called "newShLibName" in the same directory as andre@0: * a shared library that is already loaded, called existingShLibName. andre@0: * A pointer to a static function in that shared library, andre@0: * staticShLibFunc, is required. andre@0: * andre@0: * existingShLibName: andre@0: * The file name of the shared library that shall be used as the andre@0: * "reference library". The loader will attempt to load the requested andre@0: * library from the same directory as the reference library. andre@0: * andre@0: * staticShLibFunc: andre@0: * Pointer to a static function in the "reference library". andre@0: * andre@0: * newShLibName: andre@0: * The simple file name of the new shared library to be loaded. andre@0: * andre@0: * We use PR_GetLibraryFilePathname to get the pathname of the loaded andre@0: * shared lib that contains this function, and then do a andre@0: * PR_LoadLibraryWithFlags with an absolute pathname for the shared andre@0: * library to be loaded. andre@0: * andre@0: * On Windows, the "alternate search path" strategy is employed, if available. andre@0: * On Unix, if existingShLibName is a symbolic link, and no link exists for the andre@0: * new library, the original link will be resolved, and the new library loaded andre@0: * from the resolved location. andre@0: * andre@0: * If the new shared library is not found in the same location as the reference andre@0: * library, it will then be loaded from the normal system library path. andre@0: */ andre@0: PRLibrary * andre@0: PORT_LoadLibraryFromOrigin(const char* existingShLibName, andre@0: PRFuncPtr staticShLibFunc, andre@0: const char *newShLibName); andre@0: #endif /* NSS_STATIC */ andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif /* _SECPORT_H_ */