Back to index

lightning-sunbird  0.9+nobinonly
secport.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038  * secport.h - portability interfaces for security libraries
00039  *
00040  * $Id: secport.h,v 1.12.10.1 2006/08/16 00:08:19 wtchang%redhat.com Exp $
00041  */
00042 
00043 #ifndef _SECPORT_H_
00044 #define _SECPORT_H_
00045 
00046 /*
00047  * define XP_MAC, XP_WIN, XP_BEOS, or XP_UNIX, in case they are not defined
00048  * by anyone else
00049  */
00050 #ifdef macintosh
00051 # ifndef XP_MAC
00052 # define XP_MAC 1
00053 # endif
00054 #endif
00055 
00056 #ifdef _WINDOWS
00057 # ifndef XP_WIN
00058 # define XP_WIN
00059 # endif
00060 #if defined(_WIN32) || defined(WIN32)
00061 # ifndef XP_WIN32
00062 # define XP_WIN32
00063 # endif
00064 #else
00065 # ifndef XP_WIN16
00066 # define XP_WIN16
00067 # endif
00068 #endif
00069 #endif
00070 
00071 #ifdef __BEOS__
00072 # ifndef XP_BEOS
00073 # define XP_BEOS
00074 # endif
00075 #endif
00076 
00077 #ifdef unix
00078 # ifndef XP_UNIX
00079 # define XP_UNIX
00080 # endif
00081 #endif
00082 
00083 #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
00084 #include "watcomfx.h"
00085 #endif
00086 
00087 #if defined(_WIN32_WCE)
00088 #include <windef.h>
00089 #include <types.h>
00090 #elif defined( XP_MAC ) 
00091 #include <types.h>
00092 #include <time.h> /* for time_t below */
00093 #else
00094 #include <sys/types.h>
00095 #endif
00096 
00097 #include <ctype.h>
00098 #include <string.h>
00099 #if defined(_WIN32_WCE)
00100 #include <stdlib.h>  /* WinCE puts some stddef symbols here. */
00101 #else
00102 #include <stddef.h>
00103 #endif
00104 #include <stdlib.h>
00105 #include "prtypes.h"
00106 #include "prlog.h"   /* for PR_ASSERT */
00107 #include "plarena.h"
00108 #include "plstr.h"
00109 
00110 /*
00111  * HACK for NSS 2.8 to allow Admin to compile without source changes.
00112  */
00113 #ifndef SEC_BEGIN_PROTOS
00114 #include "seccomon.h"
00115 #endif
00116 
00117 SEC_BEGIN_PROTOS
00118 
00119 extern void *PORT_Alloc(size_t len);
00120 extern void *PORT_Realloc(void *old, size_t len);
00121 extern void *PORT_AllocBlock(size_t len);
00122 extern void *PORT_ReallocBlock(void *old, size_t len);
00123 extern void PORT_FreeBlock(void *ptr);
00124 extern void *PORT_ZAlloc(size_t len);
00125 extern void PORT_Free(void *ptr);
00126 extern void PORT_ZFree(void *ptr, size_t len);
00127 extern char *PORT_Strdup(const char *s);
00128 extern time_t PORT_Time(void);
00129 extern void PORT_SetError(int value);
00130 extern int PORT_GetError(void);
00131 
00132 extern PLArenaPool *PORT_NewArena(unsigned long chunksize);
00133 extern void *PORT_ArenaAlloc(PLArenaPool *arena, size_t size);
00134 extern void *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size);
00135 extern void PORT_FreeArena(PLArenaPool *arena, PRBool zero);
00136 extern void *PORT_ArenaGrow(PLArenaPool *arena, void *ptr,
00137                          size_t oldsize, size_t newsize);
00138 extern void *PORT_ArenaMark(PLArenaPool *arena);
00139 extern void PORT_ArenaRelease(PLArenaPool *arena, void *mark);
00140 extern void PORT_ArenaZRelease(PLArenaPool *arena, void *mark);
00141 extern void PORT_ArenaUnmark(PLArenaPool *arena, void *mark);
00142 extern char *PORT_ArenaStrdup(PLArenaPool *arena, const char *str);
00143 
00144 #ifdef __cplusplus
00145 }
00146 #endif
00147 
00148 #define PORT_Assert PR_ASSERT
00149 #define PORT_ZNew(type) (type*)PORT_ZAlloc(sizeof(type))
00150 #define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
00151 #define PORT_ArenaNew(poolp, type) \
00152               (type*) PORT_ArenaAlloc(poolp, sizeof(type))
00153 #define PORT_ArenaZNew(poolp, type)       \
00154               (type*) PORT_ArenaZAlloc(poolp, sizeof(type))
00155 #define PORT_NewArray(type, num)   \
00156               (type*) PORT_Alloc (sizeof(type)*(num))
00157 #define PORT_ZNewArray(type, num)  \
00158               (type*) PORT_ZAlloc (sizeof(type)*(num))
00159 #define PORT_ArenaNewArray(poolp, type, num)     \
00160               (type*) PORT_ArenaAlloc (poolp, sizeof(type)*(num))
00161 #define PORT_ArenaZNewArray(poolp, type, num)    \
00162               (type*) PORT_ArenaZAlloc (poolp, sizeof(type)*(num))
00163 
00164 /* Please, keep these defines sorted alphabetically.  Thanks! */
00165 
00166 #define PORT_Atoi    atoi
00167 
00168 #define PORT_Memcmp  memcmp
00169 #define PORT_Memcpy  memcpy
00170 #ifndef SUNOS4
00171 #define PORT_Memmove        memmove
00172 #else /*SUNOS4*/
00173 #define PORT_Memmove(s,ct,n)    bcopy ((ct), (s), (n))
00174 #endif/*SUNOS4*/
00175 #define PORT_Memset  memset
00176 
00177 #define PORT_Strcasecmp PL_strcasecmp
00178 #define PORT_Strcat  strcat
00179 #define PORT_Strchr  strchr
00180 #define PORT_Strrchr    strrchr
00181 #define PORT_Strcmp  strcmp
00182 #define PORT_Strcpy  strcpy
00183 #define PORT_Strlen(s)      strlen(s)
00184 #define PORT_Strncasecmp PL_strncasecmp
00185 #define PORT_Strncat        strncat
00186 #define PORT_Strncmp        strncmp
00187 #define PORT_Strncpy        strncpy
00188 #define PORT_Strpbrk    strpbrk
00189 #define PORT_Strstr  strstr
00190 #define PORT_Strtok  strtok
00191 
00192 #define PORT_Tolower        tolower
00193 
00194 typedef PRBool (PR_CALLBACK * PORTCharConversionWSwapFunc) (PRBool toUnicode,
00195                      unsigned char *inBuf, unsigned int inBufLen,
00196                      unsigned char *outBuf, unsigned int maxOutBufLen,
00197                      unsigned int *outBufLen, PRBool swapBytes);
00198 
00199 typedef PRBool (PR_CALLBACK * PORTCharConversionFunc) (PRBool toUnicode,
00200                      unsigned char *inBuf, unsigned int inBufLen,
00201                      unsigned char *outBuf, unsigned int maxOutBufLen,
00202                      unsigned int *outBufLen);
00203 
00204 #ifdef __cplusplus
00205 extern "C" {
00206 #endif
00207 
00208 void PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
00209 void PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc);
00210 PRBool PORT_UCS4_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
00211                      unsigned int inBufLen, unsigned char *outBuf,
00212                      unsigned int maxOutBufLen, unsigned int *outBufLen);
00213 PRBool PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf,
00214                      unsigned int inBufLen, unsigned char *outBuf,
00215                      unsigned int maxOutBufLen, unsigned int *outBufLen,
00216                      PRBool swapBytes);
00217 void PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc);
00218 PRBool PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
00219                      unsigned int inBufLen, unsigned char *outBuf,
00220                      unsigned int maxOutBufLen, unsigned int *outBufLen);
00221 
00222 /* One-way conversion from ISO-8859-1 to UTF-8 */
00223 PRBool PORT_ISO88591_UTF8Conversion(const unsigned char *inBuf,
00224                      unsigned int inBufLen, unsigned char *outBuf,
00225                      unsigned int maxOutBufLen, unsigned int *outBufLen);
00226 
00227 PR_EXTERN(PRBool)
00228 sec_port_ucs4_utf8_conversion_function
00229 (
00230   PRBool toUnicode,
00231   unsigned char *inBuf,
00232   unsigned int inBufLen,
00233   unsigned char *outBuf,
00234   unsigned int maxOutBufLen,
00235   unsigned int *outBufLen
00236 );
00237 
00238 PR_EXTERN(PRBool)
00239 sec_port_ucs2_utf8_conversion_function
00240 (
00241   PRBool toUnicode,
00242   unsigned char *inBuf,
00243   unsigned int inBufLen,
00244   unsigned char *outBuf,
00245   unsigned int maxOutBufLen,
00246   unsigned int *outBufLen
00247 );
00248 
00249 /* One-way conversion from ISO-8859-1 to UTF-8 */
00250 extern PRBool
00251 sec_port_iso88591_utf8_conversion_function
00252 (
00253   const unsigned char *inBuf,
00254   unsigned int inBufLen,
00255   unsigned char *outBuf,
00256   unsigned int maxOutBufLen,
00257   unsigned int *outBufLen
00258 );
00259 
00260 extern int NSS_PutEnv(const char * envVarName, const char * envValue);
00261 
00262 SEC_END_PROTOS
00263 
00264 #endif /* _SECPORT_H_ */