security/nss/lib/util/secport.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial