OLD | NEW |
| (Empty) |
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/. */ | |
4 | |
5 /* | |
6 * secport.h - portability interfaces for security libraries | |
7 */ | |
8 | |
9 #ifndef _SECPORT_H_ | |
10 #define _SECPORT_H_ | |
11 | |
12 #include "utilrename.h" | |
13 #include "prlink.h" | |
14 | |
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 | |
29 | |
30 #ifdef __BEOS__ | |
31 # ifndef XP_BEOS | |
32 # define XP_BEOS | |
33 # endif | |
34 #endif | |
35 | |
36 #ifdef unix | |
37 # ifndef XP_UNIX | |
38 # define XP_UNIX | |
39 # endif | |
40 #endif | |
41 | |
42 #include <sys/types.h> | |
43 | |
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" | |
52 | |
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 | |
59 | |
60 SEC_BEGIN_PROTOS | |
61 | |
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); | |
74 | |
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); | |
86 | |
87 SEC_END_PROTOS | |
88 | |
89 #define PORT_Assert PR_ASSERT | |
90 /* This runs a function that should return SECSuccess. | |
91 * Intended for NSS internal use only. | |
92 * The return value is asserted in a debug build, otherwise it is ignored. | |
93 * This is no substitute for proper error handling. It is OK only if you | |
94 * have ensured that the function cannot fail by other means such as checking | |
95 * prerequisites. In that case this can be used as a safeguard against | |
96 * unexpected changes in a function. | |
97 */ | |
98 #ifdef DEBUG | |
99 #define PORT_CheckSuccess(f) PR_ASSERT((f) == SECSuccess) | |
100 #else | |
101 #define PORT_CheckSuccess(f) (f) | |
102 #endif | |
103 #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type)) | |
104 #define PORT_New(type) (type*)PORT_Alloc(sizeof(type)) | |
105 #define PORT_ArenaNew(poolp, type) \ | |
106 (type*) PORT_ArenaAlloc(poolp, sizeof(type)) | |
107 #define PORT_ArenaZNew(poolp, type) \ | |
108 (type*) PORT_ArenaZAlloc(poolp, sizeof(type)) | |
109 #define PORT_NewArray(type, num) \ | |
110 (type*) PORT_Alloc (sizeof(type)*(num)) | |
111 #define PORT_ZNewArray(type, num) \ | |
112 (type*) PORT_ZAlloc (sizeof(type)*(num)) | |
113 #define PORT_ArenaNewArray(poolp, type, num) \ | |
114 (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num)) | |
115 #define PORT_ArenaZNewArray(poolp, type, num) \ | |
116 (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num)) | |
117 | |
118 /* Please, keep these defines sorted alphabetically. Thanks! */ | |
119 | |
120 #define PORT_Atoi(buff) (int)strtol(buff, NULL, 10) | |
121 | |
122 /* Returns a UTF-8 encoded constant error string for err. | |
123 * Returns NULL if initialization of the error tables fails | |
124 * due to insufficient memory. | |
125 * | |
126 * This string must not be modified by the application. | |
127 */ | |
128 #define PORT_ErrorToString(err) PR_ErrorToString((err), PR_LANGUAGE_I_DEFAULT) | |
129 | |
130 #define PORT_ErrorToName PR_ErrorToName | |
131 | |
132 #define PORT_Memcmp memcmp | |
133 #define PORT_Memcpy memcpy | |
134 #ifndef SUNOS4 | |
135 #define PORT_Memmove memmove | |
136 #else /*SUNOS4*/ | |
137 #define PORT_Memmove(s,ct,n) bcopy ((ct), (s), (n)) | |
138 #endif/*SUNOS4*/ | |
139 #define PORT_Memset memset | |
140 | |
141 #define PORT_Strcasecmp PL_strcasecmp | |
142 #define PORT_Strcat strcat | |
143 #define PORT_Strchr strchr | |
144 #define PORT_Strrchr strrchr | |
145 #define PORT_Strcmp strcmp | |
146 #define PORT_Strcpy strcpy | |
147 #define PORT_Strlen(s) strlen(s) | |
148 #define PORT_Strncasecmp PL_strncasecmp | |
149 #define PORT_Strncat strncat | |
150 #define PORT_Strncmp strncmp | |
151 #define PORT_Strncpy strncpy | |
152 #define PORT_Strpbrk strpbrk | |
153 #define PORT_Strstr strstr | |
154 #define PORT_Strtok strtok | |
155 | |
156 #define PORT_Tolower tolower | |
157 | |
158 typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode, | |
159 unsigned char *inBuf, unsigned int inBufLen, | |
160 unsigned char *outBuf, unsigned int maxOutBufLen, | |
161 unsigned int *outBufLen, PRBool swapBytes); | |
162 | |
163 typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode, | |
164 unsigned char *inBuf, unsigned int inBufLen, | |
165 unsigned char *outBuf, unsigned int maxOutBufLen, | |
166 unsigned int *outBufLen); | |
167 | |
168 SEC_BEGIN_PROTOS | |
169 | |
170 void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc); | |
171 void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc); | |
172 PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, | |
173 unsigned int inBufLen, unsigned char *outBuf, | |
174 unsigned int maxOutBufLen, unsigned int *outBufLen); | |
175 PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf, | |
176 unsigned int inBufLen, unsigned char *outBuf, | |
177 unsigned int maxOutBufLen, unsigned int *outBufLen, | |
178 PRBool swapBytes); | |
179 void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc); | |
180 PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf, | |
181 unsigned int inBufLen, unsigned char *outBuf, | |
182 unsigned int maxOutBufLen, unsigned int *outBufLen); | |
183 | |
184 /* One-way conversion from ISO-8859-1 to UTF-8 */ | |
185 PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf, | |
186 unsigned int inBufLen, unsigned char *outBuf, | |
187 unsigned int maxOutBufLen, unsigned int *outBufLen); | |
188 | |
189 extern PRBool | |
190 sec_port_ucs4_utf8_conversion_function | |
191 ( | |
192 PRBool toUnicode, | |
193 unsigned char *inBuf, | |
194 unsigned int inBufLen, | |
195 unsigned char *outBuf, | |
196 unsigned int maxOutBufLen, | |
197 unsigned int *outBufLen | |
198 ); | |
199 | |
200 extern PRBool | |
201 sec_port_ucs2_utf8_conversion_function | |
202 ( | |
203 PRBool toUnicode, | |
204 unsigned char *inBuf, | |
205 unsigned int inBufLen, | |
206 unsigned char *outBuf, | |
207 unsigned int maxOutBufLen, | |
208 unsigned int *outBufLen | |
209 ); | |
210 | |
211 /* One-way conversion from ISO-8859-1 to UTF-8 */ | |
212 extern PRBool | |
213 sec_port_iso88591_utf8_conversion_function | |
214 ( | |
215 const unsigned char *inBuf, | |
216 unsigned int inBufLen, | |
217 unsigned char *outBuf, | |
218 unsigned int maxOutBufLen, | |
219 unsigned int *outBufLen | |
220 ); | |
221 | |
222 extern int NSS_PutEnv(const char * envVarName, const char * envValue); | |
223 | |
224 extern int NSS_SecureMemcmp(const void *a, const void *b, size_t n); | |
225 | |
226 #ifndef NSS_STATIC | |
227 /* | |
228 * Load a shared library called "newShLibName" in the same directory as | |
229 * a shared library that is already loaded, called existingShLibName. | |
230 * A pointer to a static function in that shared library, | |
231 * staticShLibFunc, is required. | |
232 * | |
233 * existingShLibName: | |
234 * The file name of the shared library that shall be used as the | |
235 * "reference library". The loader will attempt to load the requested | |
236 * library from the same directory as the reference library. | |
237 * | |
238 * staticShLibFunc: | |
239 * Pointer to a static function in the "reference library". | |
240 * | |
241 * newShLibName: | |
242 * The simple file name of the new shared library to be loaded. | |
243 * | |
244 * We use PR_GetLibraryFilePathname to get the pathname of the loaded | |
245 * shared lib that contains this function, and then do a | |
246 * PR_LoadLibraryWithFlags with an absolute pathname for the shared | |
247 * library to be loaded. | |
248 * | |
249 * On Windows, the "alternate search path" strategy is employed, if available. | |
250 * On Unix, if existingShLibName is a symbolic link, and no link exists for the | |
251 * new library, the original link will be resolved, and the new library loaded | |
252 * from the resolved location. | |
253 * | |
254 * If the new shared library is not found in the same location as the reference | |
255 * library, it will then be loaded from the normal system library path. | |
256 */ | |
257 PRLibrary * | |
258 PORT_LoadLibraryFromOrigin(const char* existingShLibName, | |
259 PRFuncPtr staticShLibFunc, | |
260 const char *newShLibName); | |
261 #endif /* NSS_STATIC */ | |
262 | |
263 SEC_END_PROTOS | |
264 | |
265 #endif /* _SECPORT_H_ */ | |
OLD | NEW |