michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef BASE_H michael@0: #define BASE_H michael@0: michael@0: /* michael@0: * base.h michael@0: * michael@0: * This header file contains basic prototypes and preprocessor michael@0: * definitions used throughout nss but not available publicly. michael@0: */ michael@0: michael@0: #ifndef BASET_H michael@0: #include "baset.h" michael@0: #endif /* BASET_H */ michael@0: michael@0: #ifndef NSSBASE_H michael@0: #include "nssbase.h" michael@0: #endif /* NSSBASE_H */ michael@0: michael@0: #include "plhash.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /* michael@0: * NSSArena michael@0: * michael@0: * The nonpublic methods relating to this type are: michael@0: * michael@0: * nssArena_Create -- constructor michael@0: * nssArena_Destroy michael@0: * nssArena_Mark michael@0: * nssArena_Release michael@0: * nssArena_Unmark michael@0: * michael@0: * nss_ZAlloc michael@0: * nss_ZFreeIf michael@0: * nss_ZRealloc michael@0: * michael@0: * Additionally, there are some preprocessor macros: michael@0: * michael@0: * nss_ZNEW michael@0: * nss_ZNEWARRAY michael@0: * michael@0: * In debug builds, the following calls are available: michael@0: * michael@0: * nssArena_verifyPointer michael@0: * nssArena_registerDestructor michael@0: * nssArena_deregisterDestructor michael@0: * michael@0: * The following preprocessor macro is also always available: michael@0: * michael@0: * nssArena_VERIFYPOINTER michael@0: * michael@0: * A constant PLHashAllocOps structure is available for users michael@0: * of the NSPL PLHashTable routines. michael@0: * michael@0: * nssArenaHashAllocOps michael@0: */ michael@0: michael@0: /* michael@0: * nssArena_Create michael@0: * michael@0: * This routine creates a new memory arena. This routine may return michael@0: * NULL upon error, in which case it will have set an error on the michael@0: * error stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_NO_MEMORY michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to an NSSArena upon success michael@0: */ michael@0: michael@0: /* michael@0: * XXX fgmr michael@0: * Arenas can be named upon creation; this is mostly of use when michael@0: * debugging. Should we expose that here, allowing an optional michael@0: * "const char *name" argument? Should the public version of this michael@0: * call (NSSArena_Create) have it too? michael@0: */ michael@0: michael@0: NSS_EXTERN NSSArena * michael@0: nssArena_Create michael@0: ( michael@0: void michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: michael@0: /* michael@0: * nssArena_Destroy michael@0: * michael@0: * This routine will destroy the specified arena, freeing all memory michael@0: * allocated from it. This routine returns a PRStatus value; if michael@0: * successful, it will return PR_SUCCESS. If unsuccessful, it will michael@0: * set an error on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssArena_Destroy michael@0: ( michael@0: NSSArena *arena michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: michael@0: /* michael@0: * nssArena_Mark michael@0: * michael@0: * This routine "marks" the current state of an arena. Space michael@0: * allocated after the arena has been marked can be freed by michael@0: * releasing the arena back to the mark with nssArena_Release, michael@0: * or committed by calling nssArena_Unmark. When successful, michael@0: * this routine returns a valid nssArenaMark pointer. This michael@0: * routine may return NULL upon error, in which case it will michael@0: * have set an error on the error stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * NULL upon failure michael@0: * An nssArenaMark pointer upon success michael@0: */ michael@0: michael@0: NSS_EXTERN nssArenaMark * michael@0: nssArena_Mark michael@0: ( michael@0: NSSArena *arena michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; michael@0: michael@0: /* michael@0: * nssArena_Release michael@0: * michael@0: * This routine invalidates and releases all memory allocated from michael@0: * the specified arena after the point at which the specified mark michael@0: * was obtained. This routine returns a PRStatus value; if successful, michael@0: * it will return PR_SUCCESS. If unsuccessful, it will set an error michael@0: * on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_INVALID_ARENA_MARK michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssArena_Release michael@0: ( michael@0: NSSArena *arena, michael@0: nssArenaMark *arenaMark michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; michael@0: michael@0: /* michael@0: * nssArena_Unmark michael@0: * michael@0: * This routine "commits" the indicated mark and any marks after michael@0: * it, making them unreleasable. Note that any earlier marks can michael@0: * still be released, and such a release will invalidate these michael@0: * later unmarked regions. If an arena is to be safely shared by michael@0: * more than one thread, all marks must be either released or michael@0: * unmarked. This routine returns a PRStatus value; if successful, michael@0: * it will return PR_SUCCESS. If unsuccessful, it will set an error michael@0: * on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_INVALID_ARENA_MARK michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssArena_Unmark michael@0: ( michael@0: NSSArena *arena, michael@0: nssArenaMark *arenaMark michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA_MARK; michael@0: extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; michael@0: michael@0: #ifdef ARENA_DESTRUCTOR_LIST michael@0: michael@0: /* michael@0: * nssArena_registerDestructor michael@0: * michael@0: * This routine stores a pointer to a callback and an arbitrary michael@0: * pointer-sized argument in the arena, at the current point in michael@0: * the mark stack. If the arena is destroyed, or an "earlier" michael@0: * mark is released, then this destructor will be called at that michael@0: * time. Note that the destructor will be called with the arena michael@0: * locked, which means the destructor may free memory in that michael@0: * arena, but it may not allocate or cause to be allocated any michael@0: * memory. This callback facility was included to support our michael@0: * debug-version pointer-tracker feature; overuse runs counter to michael@0: * the the original intent of arenas. This routine returns a michael@0: * PRStatus value; if successful, it will return PR_SUCCESS. If michael@0: * unsuccessful, it will set an error on the error stack and michael@0: * return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssArena_registerDestructor michael@0: ( michael@0: NSSArena *arena, michael@0: void (*destructor)(void *argument), michael@0: void *arg michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: michael@0: /* michael@0: * nssArena_deregisterDestructor michael@0: * michael@0: * This routine will remove the first destructor in the specified michael@0: * arena which has the specified destructor and argument values. michael@0: * The destructor will not be called. This routine returns a michael@0: * PRStatus value; if successful, it will return PR_SUCCESS. If michael@0: * unsuccessful, it will set an error on the error stack and michael@0: * return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NOT_FOUND michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssArena_deregisterDestructor michael@0: ( michael@0: NSSArena *arena, michael@0: void (*destructor)(void *argument), michael@0: void *arg michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ITEM; michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_NOT_FOUND; michael@0: michael@0: #endif /* ARENA_DESTRUCTOR_LIST */ michael@0: michael@0: /* michael@0: * nss_ZAlloc michael@0: * michael@0: * This routine allocates and zeroes a section of memory of the michael@0: * size, and returns to the caller a pointer to that memory. If michael@0: * the optional arena argument is non-null, the memory will be michael@0: * obtained from that arena; otherwise, the memory will be obtained michael@0: * from the heap. This routine may return NULL upon error, in michael@0: * which case it will have set an error upon the error stack. The michael@0: * value specified for size may be zero; in which case a valid michael@0: * zero-length block of memory will be allocated. This block may michael@0: * be expanded by calling nss_ZRealloc. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to the new segment of zeroed memory michael@0: */ michael@0: michael@0: NSS_EXTERN void * michael@0: nss_ZAlloc michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRUint32 size michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; michael@0: michael@0: /* michael@0: * nss_ZFreeIf michael@0: * michael@0: * If the specified pointer is non-null, then the region of memory michael@0: * to which it points -- which must have been allocated with michael@0: * nss_ZAlloc -- will be zeroed and released. This routine michael@0: * returns a PRStatus value; if successful, it will return PR_SUCCESS. michael@0: * If unsuccessful, it will set an error on the error stack and return michael@0: * PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nss_ZFreeIf michael@0: ( michael@0: void *pointer michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: michael@0: /* michael@0: * nss_ZRealloc michael@0: * michael@0: * This routine reallocates a block of memory obtained by calling michael@0: * nss_ZAlloc or nss_ZRealloc. The portion of memory michael@0: * between the new and old sizes -- which is either being newly michael@0: * obtained or released -- is in either case zeroed. This routine michael@0: * may return NULL upon failure, in which case it will have placed michael@0: * an error on the error stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to the replacement segment of memory michael@0: */ michael@0: michael@0: NSS_EXTERN void * michael@0: nss_ZRealloc michael@0: ( michael@0: void *pointer, michael@0: PRUint32 newSize michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD; michael@0: michael@0: /* michael@0: * nss_ZNEW michael@0: * michael@0: * This preprocessor macro will allocate memory for a new object michael@0: * of the specified type with nss_ZAlloc, and will cast the michael@0: * return value appropriately. If the optional arena argument is michael@0: * non-null, the memory will be obtained from that arena; otherwise, michael@0: * the memory will be obtained from the heap. This routine may michael@0: * return NULL upon error, in which case it will have set an error michael@0: * upon the error stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to the new segment of zeroed memory michael@0: */ michael@0: michael@0: /* The following line exceeds 72 characters, but emacs screws up if I split it. */ michael@0: #define nss_ZNEW(arenaOpt, type) ((type *)nss_ZAlloc((arenaOpt), sizeof(type))) michael@0: michael@0: /* michael@0: * nss_ZNEWARRAY michael@0: * michael@0: * This preprocessor macro will allocate memory for an array of michael@0: * new objects, and will cast the return value appropriately. michael@0: * If the optional arena argument is non-null, the memory will michael@0: * be obtained from that arena; otherwise, the memory will be michael@0: * obtained from the heap. This routine may return NULL upon michael@0: * error, in which case it will have set an error upon the error michael@0: * stack. The array size may be specified as zero. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to the new segment of zeroed memory michael@0: */ michael@0: michael@0: /* The following line exceeds 72 characters, but emacs screws up if I split it. */ michael@0: #define nss_ZNEWARRAY(arenaOpt, type, quantity) ((type *)nss_ZAlloc((arenaOpt), sizeof(type) * (quantity))) michael@0: michael@0: /* michael@0: * nss_ZREALLOCARRAY michael@0: * michael@0: * This preprocessor macro will reallocate memory for an array of michael@0: * new objects, and will cast the return value appropriately. michael@0: * This routine may return NULL upon error, in which case it will michael@0: * have set an error upon the error stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A pointer to the replacement segment of memory michael@0: */ michael@0: #define nss_ZREALLOCARRAY(p, type, quantity) ((type *)nss_ZRealloc((p), sizeof(type) * (quantity))) michael@0: michael@0: /* michael@0: * nssArena_verifyPointer michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * If the specified pointer is a valid pointer to an NSSArena object, michael@0: * this routine will return PR_SUCCESS. Otherwise, it will put an michael@0: * error on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS if the pointer is valid michael@0: * PR_FAILURE if it isn't michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssArena_verifyPointer michael@0: ( michael@0: const NSSArena *arena michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_ARENA; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * nssArena_VERIFYPOINTER michael@0: * michael@0: * This macro is always available. In debug builds it will call michael@0: * nssArena_verifyPointer; in non-debug builds, it will merely michael@0: * check that the pointer is not null. Note that in non-debug michael@0: * builds it cannot place an error on the error stack. michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS if the pointer is valid michael@0: * PR_FAILURE if it isn't michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: #define nssArena_VERIFYPOINTER(p) nssArena_verifyPointer(p) michael@0: #else /* DEBUG */ michael@0: /* The following line exceeds 72 characters, but emacs screws up if I split it. */ michael@0: #define nssArena_VERIFYPOINTER(p) (((NSSArena *)NULL == (p))?PR_FAILURE:PR_SUCCESS) michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * Private function to be called by NSS_Shutdown to cleanup nssArena michael@0: * bookkeeping. michael@0: */ michael@0: extern PRStatus michael@0: nssArena_Shutdown(void); michael@0: michael@0: /* michael@0: * nssArenaHashAllocOps michael@0: * michael@0: * This constant structure contains allocation callbacks designed for michael@0: * use with the NSPL routine PL_NewHashTable. For example: michael@0: * michael@0: * NSSArena *hashTableArena = nssArena_Create(); michael@0: * PLHashTable *t = PL_NewHashTable(n, hasher, key_compare, michael@0: * value_compare, nssArenaHashAllocOps, hashTableArena); michael@0: */ michael@0: michael@0: NSS_EXTERN_DATA PLHashAllocOps nssArenaHashAllocOps; michael@0: michael@0: /* michael@0: * The error stack michael@0: * michael@0: * The nonpublic methods relating to the error stack are: michael@0: * michael@0: * nss_SetError michael@0: * nss_ClearErrorStack michael@0: */ michael@0: michael@0: /* michael@0: * nss_SetError michael@0: * michael@0: * This routine places a new error code on the top of the calling michael@0: * thread's error stack. Calling this routine wiht an error code michael@0: * of zero will clear the error stack. michael@0: */ michael@0: michael@0: NSS_EXTERN void michael@0: nss_SetError michael@0: ( michael@0: PRUint32 error michael@0: ); michael@0: michael@0: /* michael@0: * nss_ClearErrorStack michael@0: * michael@0: * This routine clears the calling thread's error stack. michael@0: */ michael@0: michael@0: NSS_EXTERN void michael@0: nss_ClearErrorStack michael@0: ( michael@0: void michael@0: ); michael@0: michael@0: /* michael@0: * nss_DestroyErrorStack michael@0: * michael@0: * This routine frees the calling thread's error stack. michael@0: */ michael@0: michael@0: NSS_EXTERN void michael@0: nss_DestroyErrorStack michael@0: ( michael@0: void michael@0: ); michael@0: michael@0: /* michael@0: * NSSItem michael@0: * michael@0: * nssItem_Create michael@0: * nssItem_Duplicate michael@0: * nssItem_Equal michael@0: */ michael@0: michael@0: NSS_EXTERN NSSItem * michael@0: nssItem_Create michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: NSSItem *rvOpt, michael@0: PRUint32 length, michael@0: const void *data michael@0: ); michael@0: michael@0: NSS_EXTERN void michael@0: nssItem_Destroy michael@0: ( michael@0: NSSItem *item michael@0: ); michael@0: michael@0: NSS_EXTERN NSSItem * michael@0: nssItem_Duplicate michael@0: ( michael@0: NSSItem *obj, michael@0: NSSArena *arenaOpt, michael@0: NSSItem *rvOpt michael@0: ); michael@0: michael@0: NSS_EXTERN PRBool michael@0: nssItem_Equal michael@0: ( michael@0: const NSSItem *one, michael@0: const NSSItem *two, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: /* michael@0: * NSSUTF8 michael@0: * michael@0: * nssUTF8_CaseIgnoreMatch michael@0: * nssUTF8_Duplicate michael@0: * nssUTF8_Size michael@0: * nssUTF8_Length michael@0: * nssUTF8_CopyIntoFixedBuffer michael@0: */ michael@0: michael@0: /* michael@0: * nssUTF8_CaseIgnoreMatch michael@0: * michael@0: * Returns true if the two UTF8-encoded strings pointed to by the michael@0: * two specified NSSUTF8 pointers differ only in typcase. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * PR_TRUE if the strings match, ignoring case michael@0: * PR_FALSE if they don't michael@0: * PR_FALSE upon error michael@0: */ michael@0: michael@0: NSS_EXTERN PRBool michael@0: nssUTF8_CaseIgnoreMatch michael@0: ( michael@0: const NSSUTF8 *a, michael@0: const NSSUTF8 *b, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: /* michael@0: * nssUTF8_Duplicate michael@0: * michael@0: * This routine duplicates the UTF8-encoded string pointed to by the michael@0: * specified NSSUTF8 pointer. If the optional arenaOpt argument is michael@0: * not null, the memory required will be obtained from that arena; michael@0: * otherwise, the memory required will be obtained from the heap. michael@0: * A pointer to the new string will be returned. In case of error, michael@0: * an error will be placed on the error stack and NULL will be michael@0: * returned. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_INVALID_ARENA michael@0: * NSS_ERROR_NO_MEMORY michael@0: */ michael@0: michael@0: NSS_EXTERN NSSUTF8 * michael@0: nssUTF8_Duplicate michael@0: ( michael@0: const NSSUTF8 *s, michael@0: NSSArena *arenaOpt michael@0: ); michael@0: michael@0: /* michael@0: * nssUTF8_PrintableMatch michael@0: * michael@0: * Returns true if the two Printable strings pointed to by the michael@0: * two specified NSSUTF8 pointers match when compared with the michael@0: * rules for Printable String (leading and trailing spaces are michael@0: * disregarded, extents of whitespace match irregardless of length, michael@0: * and case is not significant), then PR_TRUE will be returned. michael@0: * Otherwise, PR_FALSE will be returned. Upon failure, PR_FALSE michael@0: * will be returned. If the optional statusOpt argument is not michael@0: * NULL, then PR_SUCCESS or PR_FAILURE will be stored in that michael@0: * location. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * PR_TRUE if the strings match, ignoring case michael@0: * PR_FALSE if they don't michael@0: * PR_FALSE upon error michael@0: */ michael@0: michael@0: NSS_EXTERN PRBool michael@0: nssUTF8_PrintableMatch michael@0: ( michael@0: const NSSUTF8 *a, michael@0: const NSSUTF8 *b, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: /* michael@0: * nssUTF8_Size michael@0: * michael@0: * This routine returns the length in bytes (including the terminating michael@0: * null) of the UTF8-encoded string pointed to by the specified michael@0: * NSSUTF8 pointer. Zero is returned on error. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_VALUE_TOO_LARGE michael@0: * michael@0: * Return value: michael@0: * nonzero size of the string michael@0: * 0 on error michael@0: */ michael@0: michael@0: NSS_EXTERN PRUint32 michael@0: nssUTF8_Size michael@0: ( michael@0: const NSSUTF8 *s, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; michael@0: michael@0: /* michael@0: * nssUTF8_Length michael@0: * michael@0: * This routine returns the length in characters (not including the michael@0: * terminating null) of the UTF8-encoded string pointed to by the michael@0: * specified NSSUTF8 pointer. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_VALUE_TOO_LARGE michael@0: * NSS_ERROR_INVALID_STRING michael@0: * michael@0: * Return value: michael@0: * length of the string (which may be zero) michael@0: * 0 on error michael@0: */ michael@0: michael@0: NSS_EXTERN PRUint32 michael@0: nssUTF8_Length michael@0: ( michael@0: const NSSUTF8 *s, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: extern const NSSError NSS_ERROR_VALUE_TOO_LARGE; michael@0: extern const NSSError NSS_ERROR_INVALID_STRING; michael@0: michael@0: /* michael@0: * nssUTF8_Create michael@0: * michael@0: * This routine creates a UTF8 string from a string in some other michael@0: * format. Some types of string may include embedded null characters, michael@0: * so for them the length parameter must be used. For string types michael@0: * that are null-terminated, the length parameter is optional; if it michael@0: * is zero, it will be ignored. If the optional arena argument is michael@0: * non-null, the memory used for the new string will be obtained from michael@0: * that arena, otherwise it will be obtained from the heap. This michael@0: * routine may return NULL upon error, in which case it will have michael@0: * placed an error on the error stack. michael@0: * michael@0: * The error may be one of the following: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_UNSUPPORTED_TYPE michael@0: * michael@0: * Return value: michael@0: * NULL upon error michael@0: * A non-null pointer to a new UTF8 string otherwise michael@0: */ michael@0: michael@0: NSS_EXTERN NSSUTF8 * michael@0: nssUTF8_Create michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: nssStringType type, michael@0: const void *inputString, michael@0: PRUint32 size /* in bytes, not characters */ michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: extern const NSSError NSS_ERROR_UNSUPPORTED_TYPE; michael@0: michael@0: NSS_EXTERN NSSItem * michael@0: nssUTF8_GetEncoding michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: NSSItem *rvOpt, michael@0: nssStringType type, michael@0: NSSUTF8 *string michael@0: ); michael@0: michael@0: /* michael@0: * nssUTF8_CopyIntoFixedBuffer michael@0: * michael@0: * This will copy a UTF8 string into a fixed-length buffer, making michael@0: * sure that the all characters are valid. Any remaining space will michael@0: * be padded with the specified ASCII character, typically either michael@0: * null or space. michael@0: * michael@0: * Blah, blah, blah. michael@0: */ michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: extern const NSSError NSS_ERROR_INVALID_ARGUMENT; michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssUTF8_CopyIntoFixedBuffer michael@0: ( michael@0: NSSUTF8 *string, michael@0: char *buffer, michael@0: PRUint32 bufferSize, michael@0: char pad michael@0: ); michael@0: michael@0: /* michael@0: * nssUTF8_Equal michael@0: * michael@0: */ michael@0: michael@0: NSS_EXTERN PRBool michael@0: nssUTF8_Equal michael@0: ( michael@0: const NSSUTF8 *a, michael@0: const NSSUTF8 *b, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: /* michael@0: * nssList michael@0: * michael@0: * The goal is to provide a simple, optionally threadsafe, linked list michael@0: * class. Since NSS did not seem to use the circularity of PRCList michael@0: * much before, this provides a list that appears to be a linear, michael@0: * NULL-terminated list. michael@0: */ michael@0: michael@0: /* michael@0: * nssList_Create michael@0: * michael@0: * If threadsafe is true, the list will be locked during modifications michael@0: * and traversals. michael@0: */ michael@0: NSS_EXTERN nssList * michael@0: nssList_Create michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRBool threadSafe michael@0: ); michael@0: michael@0: /* michael@0: * nssList_Destroy michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssList_Destroy michael@0: ( michael@0: nssList *list michael@0: ); michael@0: michael@0: NSS_EXTERN void michael@0: nssList_Clear michael@0: ( michael@0: nssList *list, michael@0: nssListElementDestructorFunc destructor michael@0: ); michael@0: michael@0: /* michael@0: * nssList_SetCompareFunction michael@0: * michael@0: * By default, two list elements will be compared by comparing their michael@0: * data pointers. By setting this function, the user can control michael@0: * how elements are compared. michael@0: */ michael@0: NSS_EXTERN void michael@0: nssList_SetCompareFunction michael@0: ( michael@0: nssList *list, michael@0: nssListCompareFunc compareFunc michael@0: ); michael@0: michael@0: /* michael@0: * nssList_SetSortFunction michael@0: * michael@0: * Sort function to use for an ordered list. michael@0: */ michael@0: NSS_EXTERN void michael@0: nssList_SetSortFunction michael@0: ( michael@0: nssList *list, michael@0: nssListSortFunc sortFunc michael@0: ); michael@0: michael@0: /* michael@0: * nssList_Add michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssList_Add michael@0: ( michael@0: nssList *list, michael@0: void *data michael@0: ); michael@0: michael@0: /* michael@0: * nssList_AddUnique michael@0: * michael@0: * This will use the compare function to see if the element is already michael@0: * in the list. michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssList_AddUnique michael@0: ( michael@0: nssList *list, michael@0: void *data michael@0: ); michael@0: michael@0: /* michael@0: * nssList_Remove michael@0: * michael@0: * Uses the compare function to locate the element and remove it. michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssList_Remove(nssList *list, void *data); michael@0: michael@0: /* michael@0: * nssList_Get michael@0: * michael@0: * Uses the compare function to locate an element. Also serves as michael@0: * nssList_Exists. michael@0: */ michael@0: NSS_EXTERN void * michael@0: nssList_Get michael@0: ( michael@0: nssList *list, michael@0: void *data michael@0: ); michael@0: michael@0: /* michael@0: * nssList_Count michael@0: */ michael@0: NSS_EXTERN PRUint32 michael@0: nssList_Count michael@0: ( michael@0: nssList *list michael@0: ); michael@0: michael@0: /* michael@0: * nssList_GetArray michael@0: * michael@0: * Fill rvArray, up to maxElements, with elements in the list. The michael@0: * array is NULL-terminated, so its allocated size must be maxElements + 1. michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssList_GetArray michael@0: ( michael@0: nssList *list, michael@0: void **rvArray, michael@0: PRUint32 maxElements michael@0: ); michael@0: michael@0: /* michael@0: * nssList_CreateIterator michael@0: * michael@0: * Create an iterator for list traversal. michael@0: */ michael@0: NSS_EXTERN nssListIterator * michael@0: nssList_CreateIterator michael@0: ( michael@0: nssList *list michael@0: ); michael@0: michael@0: NSS_EXTERN nssList * michael@0: nssList_Clone michael@0: ( michael@0: nssList *list michael@0: ); michael@0: michael@0: /* michael@0: * nssListIterator_Destroy michael@0: */ michael@0: NSS_EXTERN void michael@0: nssListIterator_Destroy michael@0: ( michael@0: nssListIterator *iter michael@0: ); michael@0: michael@0: /* michael@0: * nssListIterator_Start michael@0: * michael@0: * Begin a list iteration. After this call, if the list is threadSafe, michael@0: * the list is *locked*. michael@0: */ michael@0: NSS_EXTERN void * michael@0: nssListIterator_Start michael@0: ( michael@0: nssListIterator *iter michael@0: ); michael@0: michael@0: /* michael@0: * nssListIterator_Next michael@0: * michael@0: * Continue a list iteration. michael@0: */ michael@0: NSS_EXTERN void * michael@0: nssListIterator_Next michael@0: ( michael@0: nssListIterator *iter michael@0: ); michael@0: michael@0: /* michael@0: * nssListIterator_Finish michael@0: * michael@0: * Complete a list iteration. This *must* be called in order for the michael@0: * lock to be released. michael@0: */ michael@0: NSS_EXTERN PRStatus michael@0: nssListIterator_Finish michael@0: ( michael@0: nssListIterator *iter michael@0: ); michael@0: michael@0: /* michael@0: * nssHash michael@0: * michael@0: * nssHash_Create michael@0: * nssHash_Destroy michael@0: * nssHash_Add michael@0: * nssHash_Remove michael@0: * nssHash_Count michael@0: * nssHash_Exists michael@0: * nssHash_Lookup michael@0: * nssHash_Iterate michael@0: */ michael@0: michael@0: /* michael@0: * nssHash_Create michael@0: * michael@0: */ michael@0: michael@0: NSS_EXTERN nssHash * michael@0: nssHash_Create michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRUint32 numBuckets, michael@0: PLHashFunction keyHash, michael@0: PLHashComparator keyCompare, michael@0: PLHashComparator valueCompare michael@0: ); michael@0: michael@0: NSS_EXTERN nssHash * michael@0: nssHash_CreatePointer michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRUint32 numBuckets michael@0: ); michael@0: michael@0: NSS_EXTERN nssHash * michael@0: nssHash_CreateString michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRUint32 numBuckets michael@0: ); michael@0: michael@0: NSS_EXTERN nssHash * michael@0: nssHash_CreateItem michael@0: ( michael@0: NSSArena *arenaOpt, michael@0: PRUint32 numBuckets michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Destroy michael@0: * michael@0: */ michael@0: NSS_EXTERN void michael@0: nssHash_Destroy michael@0: ( michael@0: nssHash *hash michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Add michael@0: * michael@0: */ michael@0: michael@0: extern const NSSError NSS_ERROR_HASH_COLLISION; michael@0: michael@0: NSS_EXTERN PRStatus michael@0: nssHash_Add michael@0: ( michael@0: nssHash *hash, michael@0: const void *key, michael@0: const void *value michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Remove michael@0: * michael@0: */ michael@0: NSS_EXTERN void michael@0: nssHash_Remove michael@0: ( michael@0: nssHash *hash, michael@0: const void *it michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Count michael@0: * michael@0: */ michael@0: NSS_EXTERN PRUint32 michael@0: nssHash_Count michael@0: ( michael@0: nssHash *hash michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Exists michael@0: * michael@0: */ michael@0: NSS_EXTERN PRBool michael@0: nssHash_Exists michael@0: ( michael@0: nssHash *hash, michael@0: const void *it michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Lookup michael@0: * michael@0: */ michael@0: NSS_EXTERN void * michael@0: nssHash_Lookup michael@0: ( michael@0: nssHash *hash, michael@0: const void *it michael@0: ); michael@0: michael@0: /* michael@0: * nssHash_Iterate michael@0: * michael@0: */ michael@0: NSS_EXTERN void michael@0: nssHash_Iterate michael@0: ( michael@0: nssHash *hash, michael@0: nssHashIterator fcn, michael@0: void *closure michael@0: ); michael@0: michael@0: michael@0: /* michael@0: * nssPointerTracker michael@0: * michael@0: * This type and these methods are only present in debug builds. michael@0: * michael@0: * The nonpublic methods relating to this type are: michael@0: * michael@0: * nssPointerTracker_initialize michael@0: * nssPointerTracker_finalize michael@0: * nssPointerTracker_add michael@0: * nssPointerTracker_remove michael@0: * nssPointerTracker_verify michael@0: */ michael@0: michael@0: /* michael@0: * nssPointerTracker_initialize michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * This routine initializes an nssPointerTracker object. Note that michael@0: * the object must have been declared *static* to guarantee that it michael@0: * is in a zeroed state initially. This routine is idempotent, and michael@0: * may even be safely called by multiple threads simultaneously with michael@0: * the same argument. This routine returns a PRStatus value; if michael@0: * successful, it will return PR_SUCCESS. On failure it will set an michael@0: * error on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_NO_MEMORY michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssPointerTracker_initialize michael@0: ( michael@0: nssPointerTracker *tracker michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * nssPointerTracker_finalize michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * This routine returns the nssPointerTracker object to the pre- michael@0: * initialized state, releasing all resources used by the object. michael@0: * It will *NOT* destroy the objects being tracked by the pointer michael@0: * (should any remain), and therefore cannot be used to "sweep up" michael@0: * remaining objects. This routine returns a PRStatus value; if michael@0: * successful, it will return PR_SUCCES. On failure it will set an michael@0: * error on the error stack and return PR_FAILURE. If any objects michael@0: * remain in the tracker when it is finalized, that will be treated michael@0: * as an error. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_TRACKER_NOT_EMPTY michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssPointerTracker_finalize michael@0: ( michael@0: nssPointerTracker *tracker michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_TRACKER_NOT_EMPTY; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * nssPointerTracker_add michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * This routine adds the specified pointer to the nssPointerTracker michael@0: * object. It should be called in constructor objects to register michael@0: * new valid objects. The nssPointerTracker is threadsafe, but this michael@0: * call is not idempotent. This routine returns a PRStatus value; michael@0: * if successful it will return PR_SUCCESS. On failure it will set michael@0: * an error on the error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_NO_MEMORY michael@0: * NSS_ERROR_TRACKER_NOT_INITIALIZED michael@0: * NSS_ERROR_DUPLICATE_POINTER michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssPointerTracker_add michael@0: ( michael@0: nssPointerTracker *tracker, michael@0: const void *pointer michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_NO_MEMORY; michael@0: extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; michael@0: extern const NSSError NSS_ERROR_DUPLICATE_POINTER; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * nssPointerTracker_remove michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * This routine removes the specified pointer from the michael@0: * nssPointerTracker object. It does not call any destructor for the michael@0: * object; rather, this should be called from the object's destructor. michael@0: * The nssPointerTracker is threadsafe, but this call is not michael@0: * idempotent. This routine returns a PRStatus value; if successful michael@0: * it will return PR_SUCCESS. On failure it will set an error on the michael@0: * error stack and return PR_FAILURE. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_TRACKER_NOT_INITIALIZED michael@0: * NSS_ERROR_POINTER_NOT_REGISTERED michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILURE michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssPointerTracker_remove michael@0: ( michael@0: nssPointerTracker *tracker, michael@0: const void *pointer michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED; michael@0: extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * nssPointerTracker_verify michael@0: * michael@0: * This method is only present in debug builds. michael@0: * michael@0: * This routine verifies that the specified pointer has been registered michael@0: * with the nssPointerTracker object. The nssPointerTracker object is michael@0: * threadsafe, and this call may be safely called from multiple threads michael@0: * simultaneously with the same arguments. This routine returns a michael@0: * PRStatus value; if the pointer is registered this will return michael@0: * PR_SUCCESS. Otherwise it will set an error on the error stack and michael@0: * return PR_FAILURE. Although the error is suitable for leaving on michael@0: * the stack, callers may wish to augment the information available by michael@0: * placing a more type-specific error on the stack. michael@0: * michael@0: * The error may be one of the following values: michael@0: * NSS_ERROR_POINTER_NOT_REGISTERED michael@0: * michael@0: * Return value: michael@0: * PR_SUCCESS michael@0: * PR_FAILRUE michael@0: */ michael@0: michael@0: #ifdef DEBUG michael@0: NSS_EXTERN PRStatus michael@0: nssPointerTracker_verify michael@0: ( michael@0: nssPointerTracker *tracker, michael@0: const void *pointer michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED; michael@0: #endif /* DEBUG */ michael@0: michael@0: /* michael@0: * libc michael@0: * michael@0: * nsslibc_memcpy michael@0: * nsslibc_memset michael@0: * nsslibc_offsetof michael@0: */ michael@0: michael@0: /* michael@0: * nsslibc_memcpy michael@0: * michael@0: * Errors: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * NULL on error michael@0: * The destination pointer on success michael@0: */ michael@0: michael@0: NSS_EXTERN void * michael@0: nsslibc_memcpy michael@0: ( michael@0: void *dest, michael@0: const void *source, michael@0: PRUint32 n michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: michael@0: /* michael@0: * nsslibc_memset michael@0: * michael@0: * Errors: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * NULL on error michael@0: * The destination pointer on success michael@0: */ michael@0: michael@0: NSS_EXTERN void * michael@0: nsslibc_memset michael@0: ( michael@0: void *dest, michael@0: PRUint8 byte, michael@0: PRUint32 n michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: michael@0: /* michael@0: * nsslibc_memequal michael@0: * michael@0: * Errors: michael@0: * NSS_ERROR_INVALID_POINTER michael@0: * michael@0: * Return value: michael@0: * PR_TRUE if they match michael@0: * PR_FALSE if they don't michael@0: * PR_FALSE upon error michael@0: */ michael@0: michael@0: NSS_EXTERN PRBool michael@0: nsslibc_memequal michael@0: ( michael@0: const void *a, michael@0: const void *b, michael@0: PRUint32 len, michael@0: PRStatus *statusOpt michael@0: ); michael@0: michael@0: extern const NSSError NSS_ERROR_INVALID_POINTER; michael@0: michael@0: #define nsslibc_offsetof(str, memb) ((PRPtrdiff)(&(((str *)0)->memb))) michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* BASE_H */