Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | * secport.h - portability interfaces for security libraries |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef _SECPORT_H_ |
michael@0 | 10 | #define _SECPORT_H_ |
michael@0 | 11 | |
michael@0 | 12 | #include "utilrename.h" |
michael@0 | 13 | #include "prlink.h" |
michael@0 | 14 | |
michael@0 | 15 | /* |
michael@0 | 16 | * define XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined |
michael@0 | 17 | * by anyone else |
michael@0 | 18 | */ |
michael@0 | 19 | #ifdef _WINDOWS |
michael@0 | 20 | # ifndef XP_WIN |
michael@0 | 21 | # define XP_WIN |
michael@0 | 22 | # endif |
michael@0 | 23 | #if defined(_WIN32) || defined(WIN32) |
michael@0 | 24 | # ifndef XP_WIN32 |
michael@0 | 25 | # define XP_WIN32 |
michael@0 | 26 | # endif |
michael@0 | 27 | #endif |
michael@0 | 28 | #endif |
michael@0 | 29 | |
michael@0 | 30 | #ifdef __BEOS__ |
michael@0 | 31 | # ifndef XP_BEOS |
michael@0 | 32 | # define XP_BEOS |
michael@0 | 33 | # endif |
michael@0 | 34 | #endif |
michael@0 | 35 | |
michael@0 | 36 | #ifdef unix |
michael@0 | 37 | # ifndef XP_UNIX |
michael@0 | 38 | # define XP_UNIX |
michael@0 | 39 | # endif |
michael@0 | 40 | #endif |
michael@0 | 41 | |
michael@0 | 42 | #include <sys/types.h> |
michael@0 | 43 | |
michael@0 | 44 | #include <ctype.h> |
michael@0 | 45 | #include <string.h> |
michael@0 | 46 | #include <stddef.h> |
michael@0 | 47 | #include <stdlib.h> |
michael@0 | 48 | #include "prtypes.h" |
michael@0 | 49 | #include "prlog.h" /* for PR_ASSERT */ |
michael@0 | 50 | #include "plarena.h" |
michael@0 | 51 | #include "plstr.h" |
michael@0 | 52 | |
michael@0 | 53 | /* |
michael@0 | 54 | * HACK for NSS 2.8 to allow Admin to compile without source changes. |
michael@0 | 55 | */ |
michael@0 | 56 | #ifndef SEC_BEGIN_PROTOS |
michael@0 | 57 | #include "seccomon.h" |
michael@0 | 58 | #endif |
michael@0 | 59 | |
michael@0 | 60 | SEC_BEGIN_PROTOS |
michael@0 | 61 | |
michael@0 | 62 | extern void *PORT_Alloc(size_t len); |
michael@0 | 63 | extern void *PORT_Realloc(void *old, size_t len); |
michael@0 | 64 | extern void *PORT_AllocBlock(size_t len); |
michael@0 | 65 | extern void *PORT_ReallocBlock(void *old, size_t len); |
michael@0 | 66 | extern void PORT_FreeBlock(void *ptr); |
michael@0 | 67 | extern void *PORT_ZAlloc(size_t len); |
michael@0 | 68 | extern void PORT_Free(void *ptr); |
michael@0 | 69 | extern void PORT_ZFree(void *ptr, size_t len); |
michael@0 | 70 | extern char *PORT_Strdup(const char *s); |
michael@0 | 71 | extern time_t PORT_Time(void); |
michael@0 | 72 | extern void PORT_SetError(int value); |
michael@0 | 73 | extern int PORT_GetError(void); |
michael@0 | 74 | |
michael@0 | 75 | extern PLArenaPool *PORT_NewArena(unsigned long chunksize); |
michael@0 | 76 | extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size); |
michael@0 | 77 | extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size); |
michael@0 | 78 | extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero); |
michael@0 | 79 | extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr, |
michael@0 | 80 | size_t oldsize, size_t newsize); |
michael@0 | 81 | extern void *PORT_ArenaMark(PLArenaPool *arena); |
michael@0 | 82 | extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark); |
michael@0 | 83 | extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark); |
michael@0 | 84 | extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark); |
michael@0 | 85 | extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str); |
michael@0 | 86 | |
michael@0 | 87 | SEC_END_PROTOS |
michael@0 | 88 | |
michael@0 | 89 | #define PORT_Assert PR_ASSERT |
michael@0 | 90 | #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type)) |
michael@0 | 91 | #define PORT_New(type) (type*)PORT_Alloc(sizeof(type)) |
michael@0 | 92 | #define PORT_ArenaNew(poolp, type) \ |
michael@0 | 93 | (type*) PORT_ArenaAlloc(poolp, sizeof(type)) |
michael@0 | 94 | #define PORT_ArenaZNew(poolp, type) \ |
michael@0 | 95 | (type*) PORT_ArenaZAlloc(poolp, sizeof(type)) |
michael@0 | 96 | #define PORT_NewArray(type, num) \ |
michael@0 | 97 | (type*) PORT_Alloc (sizeof(type)*(num)) |
michael@0 | 98 | #define PORT_ZNewArray(type, num) \ |
michael@0 | 99 | (type*) PORT_ZAlloc (sizeof(type)*(num)) |
michael@0 | 100 | #define PORT_ArenaNewArray(poolp, type, num) \ |
michael@0 | 101 | (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num)) |
michael@0 | 102 | #define PORT_ArenaZNewArray(poolp, type, num) \ |
michael@0 | 103 | (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num)) |
michael@0 | 104 | |
michael@0 | 105 | /* Please, keep these defines sorted alphabetically. Thanks! */ |
michael@0 | 106 | |
michael@0 | 107 | #define PORT_Atoi(buff) (int)strtol(buff, NULL, 10) |
michael@0 | 108 | |
michael@0 | 109 | /* Returns a UTF-8 encoded constant error string for err. |
michael@0 | 110 | * Returns NULL if initialization of the error tables fails |
michael@0 | 111 | * due to insufficient memory. |
michael@0 | 112 | * |
michael@0 | 113 | * This string must not be modified by the application. |
michael@0 | 114 | */ |
michael@0 | 115 | #define PORT_ErrorToString(err) PR_ErrorToString((err), PR_LANGUAGE_I_DEFAULT) |
michael@0 | 116 | |
michael@0 | 117 | #define PORT_ErrorToName PR_ErrorToName |
michael@0 | 118 | |
michael@0 | 119 | #define PORT_Memcmp memcmp |
michael@0 | 120 | #define PORT_Memcpy memcpy |
michael@0 | 121 | #ifndef SUNOS4 |
michael@0 | 122 | #define PORT_Memmove memmove |
michael@0 | 123 | #else /*SUNOS4*/ |
michael@0 | 124 | #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n)) |
michael@0 | 125 | #endif/*SUNOS4*/ |
michael@0 | 126 | #define PORT_Memset memset |
michael@0 | 127 | |
michael@0 | 128 | #define PORT_Strcasecmp PL_strcasecmp |
michael@0 | 129 | #define PORT_Strcat strcat |
michael@0 | 130 | #define PORT_Strchr strchr |
michael@0 | 131 | #define PORT_Strrchr strrchr |
michael@0 | 132 | #define PORT_Strcmp strcmp |
michael@0 | 133 | #define PORT_Strcpy strcpy |
michael@0 | 134 | #define PORT_Strlen(s) strlen(s) |
michael@0 | 135 | #define PORT_Strncasecmp PL_strncasecmp |
michael@0 | 136 | #define PORT_Strncat strncat |
michael@0 | 137 | #define PORT_Strncmp strncmp |
michael@0 | 138 | #define PORT_Strncpy strncpy |
michael@0 | 139 | #define PORT_Strpbrk strpbrk |
michael@0 | 140 | #define PORT_Strstr strstr |
michael@0 | 141 | #define PORT_Strtok strtok |
michael@0 | 142 | |
michael@0 | 143 | #define PORT_Tolower tolower |
michael@0 | 144 | |
michael@0 | 145 | typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode, |
michael@0 | 146 | unsigned char *inBuf, unsigned int inBufLen, |
michael@0 | 147 | unsigned char *outBuf, unsigned int maxOutBufLen, |
michael@0 | 148 | unsigned int *outBufLen, PRBool swapBytes); |
michael@0 | 149 | |
michael@0 | 150 | typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode, |
michael@0 | 151 | unsigned char *inBuf, unsigned int inBufLen, |
michael@0 | 152 | unsigned char *outBuf, unsigned int maxOutBufLen, |
michael@0 | 153 | unsigned int *outBufLen); |
michael@0 | 154 | |
michael@0 | 155 | SEC_BEGIN_PROTOS |
michael@0 | 156 | |
michael@0 | 157 | void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc); |
michael@0 | 158 | void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc); |
michael@0 | 159 | PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, |
michael@0 | 160 | unsigned int inBufLen, unsigned char *outBuf, |
michael@0 | 161 | unsigned int maxOutBufLen, unsigned int *outBufLen); |
michael@0 | 162 | PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf, |
michael@0 | 163 | unsigned int inBufLen, unsigned char *outBuf, |
michael@0 | 164 | unsigned int maxOutBufLen, unsigned int *outBufLen, |
michael@0 | 165 | PRBool swapBytes); |
michael@0 | 166 | void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc); |
michael@0 | 167 | PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, |
michael@0 | 168 | unsigned int inBufLen, unsigned char *outBuf, |
michael@0 | 169 | unsigned int maxOutBufLen, unsigned int *outBufLen); |
michael@0 | 170 | |
michael@0 | 171 | /* One-way conversion from ISO-8859-1 to UTF-8 */ |
michael@0 | 172 | PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf, |
michael@0 | 173 | unsigned int inBufLen, unsigned char *outBuf, |
michael@0 | 174 | unsigned int maxOutBufLen, unsigned int *outBufLen); |
michael@0 | 175 | |
michael@0 | 176 | extern PRBool |
michael@0 | 177 | sec_port_ucs4_utf8_conversion_function |
michael@0 | 178 | ( |
michael@0 | 179 | PRBool toUnicode, |
michael@0 | 180 | unsigned char *inBuf, |
michael@0 | 181 | unsigned int inBufLen, |
michael@0 | 182 | unsigned char *outBuf, |
michael@0 | 183 | unsigned int maxOutBufLen, |
michael@0 | 184 | unsigned int *outBufLen |
michael@0 | 185 | ); |
michael@0 | 186 | |
michael@0 | 187 | extern PRBool |
michael@0 | 188 | sec_port_ucs2_utf8_conversion_function |
michael@0 | 189 | ( |
michael@0 | 190 | PRBool toUnicode, |
michael@0 | 191 | unsigned char *inBuf, |
michael@0 | 192 | unsigned int inBufLen, |
michael@0 | 193 | unsigned char *outBuf, |
michael@0 | 194 | unsigned int maxOutBufLen, |
michael@0 | 195 | unsigned int *outBufLen |
michael@0 | 196 | ); |
michael@0 | 197 | |
michael@0 | 198 | /* One-way conversion from ISO-8859-1 to UTF-8 */ |
michael@0 | 199 | extern PRBool |
michael@0 | 200 | sec_port_iso88591_utf8_conversion_function |
michael@0 | 201 | ( |
michael@0 | 202 | const unsigned char *inBuf, |
michael@0 | 203 | unsigned int inBufLen, |
michael@0 | 204 | unsigned char *outBuf, |
michael@0 | 205 | unsigned int maxOutBufLen, |
michael@0 | 206 | unsigned int *outBufLen |
michael@0 | 207 | ); |
michael@0 | 208 | |
michael@0 | 209 | extern int NSS_PutEnv(const char * envVarName, const char * envValue); |
michael@0 | 210 | |
michael@0 | 211 | extern int NSS_SecureMemcmp(const void *a, const void *b, size_t n); |
michael@0 | 212 | |
michael@0 | 213 | /* |
michael@0 | 214 | * Load a shared library called "newShLibName" in the same directory as |
michael@0 | 215 | * a shared library that is already loaded, called existingShLibName. |
michael@0 | 216 | * A pointer to a static function in that shared library, |
michael@0 | 217 | * staticShLibFunc, is required. |
michael@0 | 218 | * |
michael@0 | 219 | * existingShLibName: |
michael@0 | 220 | * The file name of the shared library that shall be used as the |
michael@0 | 221 | * "reference library". The loader will attempt to load the requested |
michael@0 | 222 | * library from the same directory as the reference library. |
michael@0 | 223 | * |
michael@0 | 224 | * staticShLibFunc: |
michael@0 | 225 | * Pointer to a static function in the "reference library". |
michael@0 | 226 | * |
michael@0 | 227 | * newShLibName: |
michael@0 | 228 | * The simple file name of the new shared library to be loaded. |
michael@0 | 229 | * |
michael@0 | 230 | * We use PR_GetLibraryFilePathname to get the pathname of the loaded |
michael@0 | 231 | * shared lib that contains this function, and then do a |
michael@0 | 232 | * PR_LoadLibraryWithFlags with an absolute pathname for the shared |
michael@0 | 233 | * library to be loaded. |
michael@0 | 234 | * |
michael@0 | 235 | * On Windows, the "alternate search path" strategy is employed, if available. |
michael@0 | 236 | * On Unix, if existingShLibName is a symbolic link, and no link exists for the |
michael@0 | 237 | * new library, the original link will be resolved, and the new library loaded |
michael@0 | 238 | * from the resolved location. |
michael@0 | 239 | * |
michael@0 | 240 | * If the new shared library is not found in the same location as the reference |
michael@0 | 241 | * library, it will then be loaded from the normal system library path. |
michael@0 | 242 | */ |
michael@0 | 243 | PRLibrary * |
michael@0 | 244 | PORT_LoadLibraryFromOrigin(const char* existingShLibName, |
michael@0 | 245 | PRFuncPtr staticShLibFunc, |
michael@0 | 246 | const char *newShLibName); |
michael@0 | 247 | |
michael@0 | 248 | SEC_END_PROTOS |
michael@0 | 249 | |
michael@0 | 250 | #endif /* _SECPORT_H_ */ |