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