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