Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
base.h File Reference
#include "baset.h"
#include "nssbase.h"
#include "plhash.h"
#include "prthread.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define nss_ZNEW(arenaOpt, type)   ((type *)nss_ZAlloc((arenaOpt), sizeof(type)))
#define nss_ZNEWARRAY(arenaOpt, type, quantity)   ((type *)nss_ZAlloc((arenaOpt), sizeof(type) * (quantity)))
#define nss_ZREALLOCARRAY(p, type, quantity)   ((type *)nss_ZRealloc((p), sizeof(type) * (quantity)))
#define nssArena_VERIFYPOINTER(p)   (((NSSArena *)NULL == (p))?PR_FAILURE:PR_SUCCESS)
#define nsslibc_offsetof(str, memb)   ((PRPtrdiff)(&(((str *)0)->memb)))

Functions

PR_BEGIN_EXTERN_C NSS_EXTERN
NSSArena * 
nssArena_Create (void)
NSS_EXTERN PRStatus nssArena_Destroy (NSSArena *arena)
NSS_EXTERN nssArenaMark * nssArena_Mark (NSSArena *arena)
NSS_EXTERN PRStatus nssArena_Release (NSSArena *arena, nssArenaMark *arenaMark)
NSS_EXTERN PRStatus nssArena_Unmark (NSSArena *arena, nssArenaMark *arenaMark)
NSS_EXTERN voidnss_ZAlloc (NSSArena *arenaOpt, PRUint32 size)
NSS_EXTERN PRStatus nss_ZFreeIf (void *pointer)
NSS_EXTERN voidnss_ZRealloc (void *pointer, PRUint32 newSize)
NSS_EXTERN void nss_SetError (PRUint32 error)
NSS_EXTERN void nss_ClearErrorStack (void)
NSS_EXTERN NSSItem * nssItem_Create (NSSArena *arenaOpt, NSSItem *rvOpt, PRUint32 length, const void *data)
NSS_EXTERN void nssItem_Destroy (NSSItem *item)
NSS_EXTERN NSSItem * nssItem_Duplicate (NSSItem *obj, NSSArena *arenaOpt, NSSItem *rvOpt)
NSS_EXTERN PRBool nssItem_Equal (const NSSItem *one, const NSSItem *two, PRStatus *statusOpt)
NSS_EXTERN PRBool nssUTF8_CaseIgnoreMatch (const NSSUTF8 *a, const NSSUTF8 *b, PRStatus *statusOpt)
NSS_EXTERN NSSUTF8nssUTF8_Duplicate (const NSSUTF8 *s, NSSArena *arenaOpt)
NSS_EXTERN PRBool nssUTF8_PrintableMatch (const NSSUTF8 *a, const NSSUTF8 *b, PRStatus *statusOpt)
NSS_EXTERN PRUint32 nssUTF8_Size (const NSSUTF8 *s, PRStatus *statusOpt)
NSS_EXTERN PRUint32 nssUTF8_Length (const NSSUTF8 *s, PRStatus *statusOpt)
NSS_EXTERN NSSUTF8nssUTF8_Create (NSSArena *arenaOpt, nssStringType type, const void *inputString, PRUint32 size)
NSS_EXTERN NSSItem * nssUTF8_GetEncoding (NSSArena *arenaOpt, NSSItem *rvOpt, nssStringType type, NSSUTF8 *string)
NSS_EXTERN PRStatus nssUTF8_CopyIntoFixedBuffer (NSSUTF8 *string, char *buffer, PRUint32 bufferSize, char pad)
NSS_EXTERN PRBool nssUTF8_Equal (const NSSUTF8 *a, const NSSUTF8 *b, PRStatus *statusOpt)
NSS_EXTERN nssList * nssList_Create (NSSArena *arenaOpt, PRBool threadSafe)
NSS_EXTERN PRStatus nssList_Destroy (nssList *list)
NSS_EXTERN void nssList_Clear (nssList *list, nssListElementDestructorFunc destructor)
NSS_EXTERN void nssList_SetCompareFunction (nssList *list, nssListCompareFunc compareFunc)
NSS_EXTERN void nssList_SetSortFunction (nssList *list, nssListSortFunc sortFunc)
NSS_EXTERN PRStatus nssList_Add (nssList *list, void *data)
NSS_EXTERN PRStatus nssList_AddUnique (nssList *list, void *data)
NSS_EXTERN PRStatus nssList_Remove (nssList *list, void *data)
NSS_EXTERN voidnssList_Get (nssList *list, void *data)
NSS_EXTERN PRUint32 nssList_Count (nssList *list)
NSS_EXTERN PRStatus nssList_GetArray (nssList *list, void **rvArray, PRUint32 maxElements)
NSS_EXTERN nssListIterator * nssList_CreateIterator (nssList *list)
NSS_EXTERN nssList * nssList_Clone (nssList *list)
NSS_EXTERN void nssListIterator_Destroy (nssListIterator *iter)
NSS_EXTERN voidnssListIterator_Start (nssListIterator *iter)
NSS_EXTERN voidnssListIterator_Next (nssListIterator *iter)
NSS_EXTERN PRStatus nssListIterator_Finish (nssListIterator *iter)
NSS_EXTERN nssHash * nssHash_Create (NSSArena *arenaOpt, PRUint32 numBuckets, PLHashFunction keyHash, PLHashComparator keyCompare, PLHashComparator valueCompare)
NSS_EXTERN nssHash * nssHash_CreatePointer (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_EXTERN nssHash * nssHash_CreateString (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_EXTERN nssHash * nssHash_CreateItem (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_EXTERN void nssHash_Destroy (nssHash *hash)
NSS_EXTERN PRStatus nssHash_Add (nssHash *hash, const void *key, const void *value)
NSS_EXTERN void nssHash_Remove (nssHash *hash, const void *it)
NSS_EXTERN PRUint32 nssHash_Count (nssHash *hash)
NSS_EXTERN PRBool nssHash_Exists (nssHash *hash, const void *it)
NSS_EXTERN voidnssHash_Lookup (nssHash *hash, const void *it)
NSS_EXTERN void nssHash_Iterate (nssHash *hash, nssHashIterator fcn, void *closure)
NSS_EXTERN voidnsslibc_memcpy (void *dest, const void *source, PRUint32 n)
NSS_EXTERN voidnsslibc_memset (void *dest, PRUint8 byte, PRUint32 n)
NSS_EXTERN PRBool nsslibc_memequal (const void *a, const void *b, PRUint32 len, PRStatus *statusOpt)
NSS_EXTERN PRStatus nss_NewThreadPrivateIndex (PRUintn *ip, PRThreadPrivateDTOR dtor)
NSS_EXTERN voidnss_GetThreadPrivate (PRUintn i)
NSS_EXTERN void nss_SetThreadPrivate (PRUintn i, void *v)

Variables

const NSSError NSS_ERROR_NO_MEMORY
const NSSError NSS_ERROR_INVALID_ARENA
const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
const NSSError NSS_ERROR_INVALID_ARENA_MARK
const NSSError NSS_ERROR_INVALID_POINTER
NSS_EXTERN_DATA PLHashAllocOps nssArenaHashAllocOps
const NSSError NSS_ERROR_VALUE_TOO_LARGE
const NSSError NSS_ERROR_INVALID_STRING
const NSSError NSS_ERROR_UNSUPPORTED_TYPE
const NSSError NSS_ERROR_INVALID_ARGUMENT
const NSSError NSS_ERROR_HASH_COLLISION

Define Documentation

#define nss_ZNEW (   arenaOpt,
  type 
)    ((type *)nss_ZAlloc((arenaOpt), sizeof(type)))

Definition at line 432 of file base.h.

#define nss_ZNEWARRAY (   arenaOpt,
  type,
  quantity 
)    ((type *)nss_ZAlloc((arenaOpt), sizeof(type) * (quantity)))

Definition at line 455 of file base.h.

#define nss_ZREALLOCARRAY (   p,
  type,
  quantity 
)    ((type *)nss_ZRealloc((p), sizeof(type) * (quantity)))

Definition at line 474 of file base.h.

#define nssArena_VERIFYPOINTER (   p)    (((NSSArena *)NULL == (p))?PR_FAILURE:PR_SUCCESS)

Definition at line 520 of file base.h.

#define nsslibc_offsetof (   str,
  memb 
)    ((PRPtrdiff)(&(((str *)0)->memb)))

Definition at line 1408 of file base.h.


Function Documentation

Definition at line 276 of file error.c.

{
  error_stack *es = error_get_my_stack();
  if( (error_stack *)NULL == es ) {
    /* Oh, well. */
    return;
  }

  es->header.count = 0;
  es->stack[0] = 0;
  return;
}

Here is the caller graph for this function:

Definition at line 127 of file whatnspr.c.

{
  switch( WHATNSPR ) {
  case 1:
    {
      PRLibrary *l = (PRLibrary *)0;
      void *f = PR_FindSymbolAndLibrary("PR_GetThreadPrivate", &l);
      typedef void *(*gtpt)(PRThread *, PRInt32);
      gtpt gtp = (gtpt) f;

      PR_ASSERT((void *)0 != f);

      return gtp(PR_CurrentThread(), i);
    }
  case 2:
  default:
    return PR_GetThreadPrivate(i);
  }
}

Here is the caller graph for this function:

Definition at line 101 of file whatnspr.c.

{
  switch( WHATNSPR ) {
  case 1:
    {
      PRLibrary *l = (PRLibrary *)0;
      void *f = PR_FindSymbolAndLibrary("PR_NewThreadPrivateID", &l);
      typedef PRInt32 (*ntpt)(void);
      ntpt ntp = (ntpt) f;

      PR_ASSERT((void *)0 != f);

      *ip = ntp();
      return PR_SUCCESS;
    }
  case 2:
  default:
    return PR_NewThreadPrivateIndex(ip, dtor);
  }
}

Here is the caller graph for this function:

Definition at line 244 of file error.c.

{
  error_stack *es;

  if( 0 == error ) {
    nss_ClearErrorStack();
    return;
  }

  es = error_get_my_stack();
  if( (error_stack *)NULL == es ) {
    /* Oh, well. */
    return;
  }

  if (es->header.count < es->header.space) {
    es->stack[ es->header.count++ ] = error;
  } else {
    memmove(es->stack, es->stack + 1, 
              (es->header.space - 1) * (sizeof es->stack[0]));
    es->stack[ es->header.space - 1 ] = error;
  }
  return;
}
NSS_EXTERN void nss_SetThreadPrivate ( PRUintn  i,
void v 
)

Definition at line 151 of file whatnspr.c.

{
  switch( WHATNSPR ) {
  case 1:
    {
      PRLibrary *l = (PRLibrary *)0;
      void *f = PR_FindSymbolAndLibrary("PR_SetThreadPrivate", &l);
      typedef PRStatus (*stpt)(PRThread *, PRInt32, void *);
      stpt stp = (stpt) f;

      PR_ASSERT((void *)0 != f);

      (void)stp(PR_CurrentThread(), i, v);
      return;
    }
  case 2:
  default:
    (void)PR_SetThreadPrivate(i, v);
    return;
  }
}

Here is the caller graph for this function:

NSS_EXTERN void* nss_ZAlloc ( NSSArena *  arenaOpt,
PRUint32  size 
)

Definition at line 875 of file arena.c.

{
  struct pointer_header *h;
  PRUint32 my_size = size + sizeof(struct pointer_header);

  if( my_size < sizeof(struct pointer_header) ) {
    /* Wrapped */
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (void *)NULL;
  }

  if( (NSSArena *)NULL == arenaOpt ) {
    /* Heap allocation, no locking required. */
    h = (struct pointer_header *)PR_Calloc(1, my_size);
    if( (struct pointer_header *)NULL == h ) {
      nss_SetError(NSS_ERROR_NO_MEMORY);
      return (void *)NULL;
    }

    h->arena = (NSSArena *)NULL;
    h->size = size;
    /* We used calloc: it's already zeroed */

    return (void *)((char *)h + sizeof(struct pointer_header));
  } else {
    void *rv;
    /* Arena allocation */
#ifdef NSSDEBUG
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (void *)NULL;
    }
#endif /* NSSDEBUG */

    if( (PRLock *)NULL == arenaOpt->lock ) {
      /* Just got destroyed */
      nss_SetError(NSS_ERROR_INVALID_ARENA);
      return (void *)NULL;
    }
    PR_Lock(arenaOpt->lock);

#ifdef ARENA_THREADMARK
    if( (PRThread *)NULL != arenaOpt->marking_thread ) {
      if( PR_GetCurrentThread() != arenaOpt->marking_thread ) {
        nss_SetError(NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD);
        PR_Unlock(arenaOpt->lock);
        return (void *)NULL;
      }
    }
#endif /* ARENA_THREADMARK */

    rv = nss_zalloc_arena_locked(arenaOpt, size);

    PR_Unlock(arenaOpt->lock);
    return rv;
  }
  /*NOTREACHED*/
}

Definition at line 956 of file arena.c.

{
  struct pointer_header *h;

  if( (void *)NULL == pointer ) {
    return PR_SUCCESS;
  }

  h = (struct pointer_header *)((char *)pointer
    - sizeof(struct pointer_header));

  /* Check any magic here */

  if( (NSSArena *)NULL == h->arena ) {
    /* Heap */
    (void)nsslibc_memset(pointer, 0, h->size);
    PR_Free(h);
    return PR_SUCCESS;
  } else {
    /* Arena */
#ifdef NSSDEBUG
    if( PR_SUCCESS != nssArena_verifyPointer(h->arena) ) {
      return PR_FAILURE;
    }
#endif /* NSSDEBUG */

    PR_Lock(h->arena->lock);
    if( (PRLock *)NULL == h->arena->lock ) {
      /* Just got destroyed.. so this pointer is invalid */
      nss_SetError(NSS_ERROR_INVALID_POINTER);
      return PR_FAILURE;
    }

    (void)nsslibc_memset(pointer, 0, h->size);

    /* No way to "free" it within an NSPR arena. */

    PR_Unlock(h->arena->lock);
    return PR_SUCCESS;
  }
  /*NOTREACHED*/
}
NSS_EXTERN void* nss_ZRealloc ( void pointer,
PRUint32  newSize 
)

Definition at line 1023 of file arena.c.

{
  struct pointer_header *h, *new_h;
  PRUint32 my_newSize = newSize + sizeof(struct pointer_header);
  void *rv;

  if( my_newSize < sizeof(struct pointer_header) ) {
    /* Wrapped */
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (void *)NULL;
  }

  if( (void *)NULL == pointer ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (void *)NULL;
  }

  h = (struct pointer_header *)((char *)pointer
    - sizeof(struct pointer_header));

  /* Check any magic here */

  if( newSize == h->size ) {
    /* saves thrashing */
    return pointer;
  }

  if( (NSSArena *)NULL == h->arena ) {
    /* Heap */
    new_h = (struct pointer_header *)PR_Calloc(1, my_newSize);
    if( (struct pointer_header *)NULL == new_h ) {
      nss_SetError(NSS_ERROR_NO_MEMORY);
      return (void *)NULL;
    }

    new_h->arena = (NSSArena *)NULL;
    new_h->size = newSize;
    rv = (void *)((char *)new_h + sizeof(struct pointer_header));

    if( newSize > h->size ) {
      (void)nsslibc_memcpy(rv, pointer, h->size);
      (void)nsslibc_memset(&((char *)rv)[ h->size ], 
                           0, (newSize - h->size));
    } else {
      (void)nsslibc_memcpy(rv, pointer, newSize);
    }

    (void)nsslibc_memset(pointer, 0, h->size);
    h->size = 0;
    PR_Free(h);

    return rv;
  } else {
    void *p;
    /* Arena */
#ifdef NSSDEBUG
    if( PR_SUCCESS != nssArena_verifyPointer(h->arena) ) {
      return (void *)NULL;
    }
#endif /* NSSDEBUG */

    PR_Lock(h->arena->lock);
    if( (PRLock *)NULL == h->arena->lock ) {
      /* Just got destroyed.. so this pointer is invalid */
      nss_SetError(NSS_ERROR_INVALID_POINTER);
      return (void *)NULL;
    }

#ifdef ARENA_THREADMARK
    if( (PRThread *)NULL != h->arena->marking_thread ) {
      if( PR_GetCurrentThread() != h->arena->marking_thread ) {
        PR_Unlock(h->arena->lock);
        nss_SetError(NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD);
        return (void *)NULL;
      }
    }
#endif /* ARENA_THREADMARK */

    if( newSize < h->size ) {
      /*
       * We have no general way of returning memory to the arena
       * (mark/release doesn't work because things may have been
       * allocated after this object), so the memory is gone
       * anyway.  We might as well just return the same pointer to
       * the user, saying "yeah, uh-hunh, you can only use less of
       * it now."  We'll zero the leftover part, of course.  And
       * in fact we might as well *not* adjust h->size-- this way,
       * if the user reallocs back up to something not greater than
       * the original size, then voila, there's the memory!  This
       * way a thrash big/small/big/small doesn't burn up the arena.
       */
      char *extra = &((char *)pointer)[ newSize ];
      (void)nsslibc_memset(extra, 0, (h->size - newSize));
      PR_Unlock(h->arena->lock);
      return pointer;
    }

    PR_ARENA_ALLOCATE(p, &h->arena->pool, my_newSize);
    if( (void *)NULL == p ) {
      PR_Unlock(h->arena->lock);
      nss_SetError(NSS_ERROR_NO_MEMORY);
      return (void *)NULL;
    }

    new_h = (struct pointer_header *)p;
    new_h->arena = h->arena;
    new_h->size = newSize;
    rv = (void *)((char *)new_h + sizeof(struct pointer_header));
    if (rv != pointer) {
       (void)nsslibc_memcpy(rv, pointer, h->size);
       (void)nsslibc_memset(pointer, 0, h->size);
    }
    (void)nsslibc_memset(&((char *)rv)[ h->size ], 0, (newSize - h->size));
    h->arena = (NSSArena *)NULL;
    h->size = 0;
    PR_Unlock(new_h->arena->lock);
    return rv;
  }
  /*NOTREACHED*/
}

Definition at line 406 of file arena.c.

{
  NSSArena *rv = (NSSArena *)NULL;

  rv = nss_ZNEW((NSSArena *)NULL, NSSArena);
  if( (NSSArena *)NULL == rv ) {
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (NSSArena *)NULL;
  }

  rv->lock = PR_NewLock();
  if( (PRLock *)NULL == rv->lock ) {
    (void)nss_ZFreeIf(rv);
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (NSSArena *)NULL;
  }

  /*
   * Arena sizes.  The current security code has 229 occurrences of
   * PORT_NewArena.  The default chunksizes specified break down as
   *
   *  Size    Mult.   Specified as
   *   512       1    512
   *  1024       7    1024
   *  2048       5    2048
   *  2048       5    CRMF_DEFAULT_ARENA_SIZE
   *  2048     190    DER_DEFAULT_CHUNKSIZE
   *  2048      20    SEC_ASN1_DEFAULT_ARENA_SIZE
   *  4096       1    4096
   *
   * Obviously this "default chunksize" flexibility isn't very 
   * useful to us, so I'll just pick 2048.
   */

  PL_InitArenaPool(&rv->pool, "NSS", 2048, sizeof(double));

#ifdef DEBUG
  {
    PRStatus st;
    st = arena_add_pointer(rv);
    if( PR_SUCCESS != st ) {
      PL_FinishArenaPool(&rv->pool);
      PR_DestroyLock(rv->lock);
      (void)nss_ZFreeIf(rv);
      return (NSSArena *)NULL;
    }
  }
#endif /* DEBUG */

  return rv;
}
NSS_EXTERN PRStatus nssArena_Destroy ( NSSArena *  arena)

Definition at line 511 of file arena.c.

{
  PRLock *lock;

#ifdef NSSDEBUG
  if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
    return PR_FAILURE;
  }
#endif /* NSSDEBUG */

  if( (PRLock *)NULL == arena->lock ) {
    /* Just got destroyed */
    nss_SetError(NSS_ERROR_INVALID_ARENA);
    return PR_FAILURE;
  }
  PR_Lock(arena->lock);
  
#ifdef DEBUG
  if( PR_SUCCESS != arena_remove_pointer(arena) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

#ifdef ARENA_DESTRUCTOR_LIST
  /* Note that the arena is locked at this time */
  nss_arena_call_destructor_chain(arena->first_destructor);
#endif /* ARENA_DESTRUCTOR_LIST */

  PL_FinishArenaPool(&arena->pool);
  lock = arena->lock;
  arena->lock = (PRLock *)NULL;
  PR_Unlock(lock);
  PR_DestroyLock(lock);
  (void)nss_ZFreeIf(arena);
  return PR_SUCCESS;
}
NSS_EXTERN nssArenaMark* nssArena_Mark ( NSSArena *  arena)

Definition at line 575 of file arena.c.

{
  nssArenaMark *rv;
  void *p;

#ifdef NSSDEBUG
  if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
    return (nssArenaMark *)NULL;
  }
#endif /* NSSDEBUG */

  if( (PRLock *)NULL == arena->lock ) {
    /* Just got destroyed */
    nss_SetError(NSS_ERROR_INVALID_ARENA);
    return (nssArenaMark *)NULL;
  }
  PR_Lock(arena->lock);

#ifdef ARENA_THREADMARK
  if( (PRThread *)NULL == arena->marking_thread ) {
    /* Unmarked.  Store our thread ID */
    arena->marking_thread = PR_GetCurrentThread();
    /* This call never fails. */
  } else {
    /* Marked.  Verify it's the current thread */
    if( PR_GetCurrentThread() != arena->marking_thread ) {
      PR_Unlock(arena->lock);
      nss_SetError(NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD);
      return (nssArenaMark *)NULL;
    }
  }
#endif /* ARENA_THREADMARK */

  p = PL_ARENA_MARK(&arena->pool);
  /* No error possible */

  /* Do this after the mark */
  rv = (nssArenaMark *)nss_zalloc_arena_locked(arena, sizeof(nssArenaMark));
  if( (nssArenaMark *)NULL == rv ) {
    PR_Unlock(arena->lock);
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (nssArenaMark *)NULL;
  }

#ifdef ARENA_THREADMARK
  if ( (nssArenaMark *)NULL == arena->first_mark) {
    arena->first_mark = rv;
    arena->last_mark = rv;
  } else {
    arena->last_mark->next = rv;
    arena->last_mark = rv;
  }
#endif /* ARENA_THREADMARK */

  rv->mark = p;
  rv->magic = MARK_MAGIC;

#ifdef ARENA_DESTRUCTOR_LIST
  rv->prev_destructor = arena->last_destructor;
#endif /* ARENA_DESTRUCTOR_LIST */

  PR_Unlock(arena->lock);

  return rv;
}
NSS_EXTERN PRStatus nssArena_Release ( NSSArena *  arena,
nssArenaMark *  arenaMark 
)

Definition at line 768 of file arena.c.

{
  return nss_arena_unmark_release(arena, arenaMark, PR_TRUE);
}
NSS_EXTERN PRStatus nssArena_Unmark ( NSSArena *  arena,
nssArenaMark *  arenaMark 
)

Definition at line 800 of file arena.c.

{
  return nss_arena_unmark_release(arena, arenaMark, PR_FALSE);
}
NSS_EXTERN PRStatus nssHash_Add ( nssHash *  hash,
const void key,
const void value 
)

Definition at line 246 of file hash.c.

{
  PRStatus error = PR_FAILURE;
  PLHashEntry *he;

  PZ_Lock(hash->mutex);
  
  he = PL_HashTableAdd(hash->plHashTable, key, (void *)value);
  if( (PLHashEntry *)NULL == he ) {
    nss_SetError(NSS_ERROR_NO_MEMORY);
  } else if (he->value != value) {
    nss_SetError(NSS_ERROR_HASH_COLLISION);
  } else {
    hash->count++;
    error = PR_SUCCESS;
  }

  (void)PZ_Unlock(hash->mutex);

  return error;
}

Here is the caller graph for this function:

NSS_EXTERN PRUint32 nssHash_Count ( nssHash *  hash)

Definition at line 302 of file hash.c.

{
  PRUint32 count;

  PZ_Lock(hash->mutex);

  count = hash->count;

  (void)PZ_Unlock(hash->mutex);

  return count;
}

Here is the caller graph for this function:

NSS_EXTERN nssHash* nssHash_Create ( NSSArena *  arenaOpt,
PRUint32  numBuckets,
PLHashFunction  keyHash,
PLHashComparator  keyCompare,
PLHashComparator  valueCompare 
)

Definition at line 121 of file hash.c.

{
  nssHash *rv;
  NSSArena *arena;
  PRBool i_alloced;

#ifdef NSSDEBUG
  if( arenaOpt && PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssHash *)NULL;
  }
#endif /* NSSDEBUG */

  if (arenaOpt) {
    arena = arenaOpt;
    i_alloced = PR_FALSE;
  } else {
    arena = nssArena_Create();
    i_alloced = PR_TRUE;
  }

  rv = nss_ZNEW(arena, nssHash);
  if( (nssHash *)NULL == rv ) {
    goto loser;
  }

  rv->mutex = PZ_NewLock(nssILockOther);
  if( (PZLock *)NULL == rv->mutex ) {
    goto loser;
  }

  rv->plHashTable = PL_NewHashTable(numBuckets, 
                                    keyHash, keyCompare, valueCompare,
                                    &nssArenaHashAllocOps, arena);
  if( (PLHashTable *)NULL == rv->plHashTable ) {
    (void)PZ_DestroyLock(rv->mutex);
    goto loser;
  }

  rv->count = 0;
  rv->arena = arena;
  rv->i_alloced_arena = i_alloced;

  return rv;
loser:
  (void)nss_ZFreeIf(rv);
  return (nssHash *)NULL;
}

Here is the caller graph for this function:

NSS_EXTERN nssHash* nssHash_CreateItem ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 212 of file hash.c.

{
  return nssHash_Create(arenaOpt, numBuckets, 
                        nss_item_hash, nss_compare_items, PL_CompareValues);
}

Here is the caller graph for this function:

NSS_EXTERN nssHash* nssHash_CreatePointer ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 182 of file hash.c.

NSS_EXTERN nssHash* nssHash_CreateString ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 197 of file hash.c.

{
  return nssHash_Create(arenaOpt, numBuckets, 
                        PL_HashString, PL_CompareStrings, PL_CompareStrings);
}

Here is the caller graph for this function:

NSS_EXTERN void nssHash_Destroy ( nssHash *  hash)

Definition at line 227 of file hash.c.

{
  (void)PZ_DestroyLock(hash->mutex);
  PL_HashTableDestroy(hash->plHashTable);
  if (hash->i_alloced_arena) {
    nssArena_Destroy(hash->arena);
  } else {
    nss_ZFreeIf(hash);
  }
}

Here is the caller graph for this function:

NSS_EXTERN PRBool nssHash_Exists ( nssHash *  hash,
const void it 
)

Definition at line 323 of file hash.c.

{
  void *value;

  PZ_Lock(hash->mutex);

  value = PL_HashTableLookup(hash->plHashTable, it);

  (void)PZ_Unlock(hash->mutex);

  if( (void *)NULL == value ) {
    return PR_FALSE;
  } else {
    return PR_TRUE;
  }
}
NSS_EXTERN void nssHash_Iterate ( nssHash *  hash,
nssHashIterator  fcn,
void closure 
)

Definition at line 390 of file hash.c.

{
  struct arg_str as;
  as.fcn = fcn;
  as.closure = closure;

  PZ_Lock(hash->mutex);

  PL_HashTableEnumerateEntries(hash->plHashTable, nss_hash_enumerator, &as);

  (void)PZ_Unlock(hash->mutex);

  return;
}

Here is the caller graph for this function:

NSS_EXTERN void* nssHash_Lookup ( nssHash *  hash,
const void it 
)

Definition at line 349 of file hash.c.

{
  void *rv;

  PZ_Lock(hash->mutex);

  rv = PL_HashTableLookup(hash->plHashTable, it);

  (void)PZ_Unlock(hash->mutex);

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN void nssHash_Remove ( nssHash *  hash,
const void it 
)

Definition at line 278 of file hash.c.

{
  PRBool found;

  PZ_Lock(hash->mutex);

  found = PL_HashTableRemove(hash->plHashTable, it);
  if( found ) {
    hash->count--;
  }

  (void)PZ_Unlock(hash->mutex);
  return;
}

Here is the caller graph for this function:

NSS_EXTERN NSSItem* nssItem_Create ( NSSArena *  arenaOpt,
NSSItem *  rvOpt,
PRUint32  length,
const void data 
)

Definition at line 69 of file item.c.

{
  NSSItem *rv = (NSSItem *)NULL;

#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSItem *)NULL;
    }
  }

  if( (const void *)NULL == data ) {
    if( length > 0 ) {
      nss_SetError(NSS_ERROR_INVALID_POINTER);
      return (NSSItem *)NULL;
    }
  }
#endif /* DEBUG */

  if( (NSSItem *)NULL == rvOpt ) {
    rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
    if( (NSSItem *)NULL == rv ) {
      goto loser;
    }
  } else {
    rv = rvOpt;
  }

  rv->size = length;
  rv->data = nss_ZAlloc(arenaOpt, length);
  if( (void *)NULL == rv->data ) {
    goto loser;
  }

  if( length > 0 ) {
    (void)nsslibc_memcpy(rv->data, data, length);
  }

  return rv;

 loser:
  if( rv != rvOpt ) {
    nss_ZFreeIf(rv);
  }

  return (NSSItem *)NULL;
}

Here is the caller graph for this function:

NSS_EXTERN void nssItem_Destroy ( NSSItem *  item)

Definition at line 124 of file item.c.

{
  nss_ClearErrorStack();

  nss_ZFreeIf(item->data);
  nss_ZFreeIf(item);

}

Here is the caller graph for this function:

NSS_EXTERN NSSItem* nssItem_Duplicate ( NSSItem *  obj,
NSSArena *  arenaOpt,
NSSItem *  rvOpt 
)

Definition at line 153 of file item.c.

{
#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSItem *)NULL;
    }
  }

  if( (NSSItem *)NULL == obj ) {
    nss_SetError(NSS_ERROR_INVALID_ITEM);
    return (NSSItem *)NULL;
  }
#endif /* DEBUG */

  return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
}

Here is the caller graph for this function:

NSS_EXTERN PRBool nssItem_Equal ( const NSSItem *  one,
const NSSItem *  two,
PRStatus statusOpt 
)

Definition at line 221 of file item.c.

{
  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
    return PR_TRUE;
  }

  if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
    return PR_FALSE;
  }

  if( one->size != two->size ) {
    return PR_FALSE;
  }

  return nsslibc_memequal(one->data, two->data, one->size, statusOpt);
}

Here is the caller graph for this function:

NSS_EXTERN void* nsslibc_memcpy ( void dest,
const void source,
PRUint32  n 
)

Definition at line 78 of file libc.c.

{
#ifdef NSSDEBUG
  if( ((void *)NULL == dest) || ((const void *)NULL == source) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (void *)NULL;
  }
#endif /* NSSDEBUG */

  return memcpy(dest, source, (size_t)n);
}

Here is the caller graph for this function:

NSS_EXTERN PRBool nsslibc_memequal ( const void a,
const void b,
PRUint32  len,
PRStatus statusOpt 
)

Definition at line 137 of file libc.c.

{
#ifdef NSSDEBUG
  if( (((void *)NULL == a) || ((void *)NULL == b)) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return PR_FALSE;
  }
#endif /* NSSDEBUG */

  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  if( 0 == memcmp(a, b, len) ) {
    return PR_TRUE;
  } else {
    return PR_FALSE;
  }
}

Here is the caller graph for this function:

NSS_EXTERN void* nsslibc_memset ( void dest,
PRUint8  byte,
PRUint32  n 
)

Definition at line 107 of file libc.c.

{
#ifdef NSSDEBUG
  if( ((void *)NULL == dest) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (void *)NULL;
  }
#endif /* NSSDEBUG */

  return memset(dest, (int)byte, (size_t)n);
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssList_Add ( nssList *  list,
void data 
)

Definition at line 254 of file list.c.

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssList_AddUnique ( nssList *  list,
void data 
)

Definition at line 264 of file list.c.

{
    PRStatus nssrv;
    nssListElement *node;
    NSSLIST_LOCK_IF(list);
    node = nsslist_get_matching_element(list, data);
    if (node) {
       /* already in, finish */
       NSSLIST_UNLOCK_IF(list);
       return PR_SUCCESS;
    }
    nssrv = nsslist_add_element(list, data);
    NSSLIST_UNLOCK_IF(list);
    return nssrv;
}

Here is the caller graph for this function:

NSS_EXTERN void nssList_Clear ( nssList *  list,
nssListElementDestructorFunc  destructor 
)

Definition at line 192 of file list.c.

{
    PRCList *link;
    nssListElement *node, *tmp;
    NSSLIST_LOCK_IF(list);
    node = list->head;
    list->head = NULL;
    while (node && list->count > 0) {
       if (destructor) (*destructor)(node->data);
       link = &node->link;
       tmp = (nssListElement *)PR_NEXT_LINK(link);
       PR_REMOVE_LINK(link);
       nss_ZFreeIf(node);
       node = tmp;
       --list->count;
    }
    NSSLIST_UNLOCK_IF(list);
}

Here is the caller graph for this function:

NSS_EXTERN nssList* nssList_Clone ( nssList *  list)

Definition at line 340 of file list.c.

{
    nssList *rvList;
    nssListElement *node;
    rvList = nssList_Create(NULL, (list->lock != NULL));
    if (!rvList) {
       return NULL;
    }
    NSSLIST_LOCK_IF(list);
    if (list->count > 0) {
       node = list->head;
       while (PR_TRUE) {
           nssList_Add(rvList, node->data);
           node = (nssListElement *)PR_NEXT_LINK(&node->link);
           if (node == list->head) {
              break;
           }
       }
    }
    NSSLIST_UNLOCK_IF(list);
    return rvList;
}

Here is the caller graph for this function:

NSS_EXTERN PRUint32 nssList_Count ( nssList *  list)

Definition at line 311 of file list.c.

{
    return list->count;
}

Here is the caller graph for this function:

NSS_EXTERN nssList* nssList_Create ( NSSArena *  arenaOpt,
PRBool  threadSafe 
)

Definition at line 113 of file list.c.

{
    NSSArena *arena;
    nssList *list;
    PRBool i_alloced;
    if (arenaOpt) {
       arena = arenaOpt;
       i_alloced = PR_FALSE;
    } else {
       arena = nssArena_Create();
       i_alloced = PR_TRUE;
    }
    if (!arena) {
       return (nssList *)NULL;
    }
    list = nss_ZNEW(arena, nssList);
    if (!list) {
       if (!arenaOpt) {
           NSSArena_Destroy(arena);
       }
       return (nssList *)NULL;
    }
    if (threadSafe) {
       list->lock = PZ_NewLock(nssILockOther);
       if (!list->lock) {
           if (arenaOpt) {
              nss_ZFreeIf(list);
           } else {
              NSSArena_Destroy(arena);
           }
           return (nssList *)NULL;
       }
    }
    list->arena = arena;
    list->i_alloced_arena = i_alloced;
    list->compareFunc = pointer_compare;
    return list;
}

Here is the caller graph for this function:

NSS_EXTERN nssListIterator* nssList_CreateIterator ( nssList *  list)

Definition at line 364 of file list.c.

{
    nssListIterator *rvIterator;
    rvIterator = nss_ZNEW(NULL, nssListIterator);
    if (!rvIterator) {
       return NULL;
    }
    rvIterator->list = nssList_Clone(list);
    if (!rvIterator->list) {
       nss_ZFreeIf(rvIterator);
       return NULL;
    }
    rvIterator->current = rvIterator->list->head;
    if (list->lock) {
       rvIterator->lock = PZ_NewLock(nssILockOther);
       if (!rvIterator->lock) {
           nssList_Destroy(rvIterator->list);
           nss_ZFreeIf(rvIterator);
       }
    }
    return rvIterator;
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssList_Destroy ( nssList *  list)

Definition at line 156 of file list.c.

{
    if (!list->i_alloced_arena) {
       nssList_Clear(list, NULL);
    }
    if (list->lock) {
       (void)PZ_DestroyLock(list->lock);
    }
    if (list->i_alloced_arena) {
       NSSArena_Destroy(list->arena);
       list = NULL;
    }
    nss_ZFreeIf(list);
    return PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_EXTERN void* nssList_Get ( nssList *  list,
void data 
)

Definition at line 301 of file list.c.

{
    nssListElement *node;
    NSSLIST_LOCK_IF(list);
    node = nsslist_get_matching_element(list, data);
    NSSLIST_UNLOCK_IF(list);
    return (node) ? node->data : NULL;
}
NSS_EXTERN PRStatus nssList_GetArray ( nssList *  list,
void **  rvArray,
PRUint32  maxElements 
)

Definition at line 317 of file list.c.

{
    nssListElement *node;
    PRUint32 i = 0;
    PR_ASSERT(maxElements > 0);
    node = list->head;
    if (!node) {
       return PR_SUCCESS;
    }
    NSSLIST_LOCK_IF(list);
    while (node) {
       rvArray[i++] = node->data;
       if (i == maxElements) break;
       node = (nssListElement *)PR_NEXT_LINK(&node->link);
       if (node == list->head) {
           break;
       }
    }
    NSSLIST_UNLOCK_IF(list);
    return PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssList_Remove ( nssList *  list,
void data 
)

Definition at line 281 of file list.c.

{
    nssListElement *node;
    NSSLIST_LOCK_IF(list);
    node = nsslist_get_matching_element(list, data);
    if (node) {
       if (node == list->head) {
           list->head = (nssListElement *)PR_NEXT_LINK(&node->link);
       }
       PR_REMOVE_LINK(&node->link);
       nss_ZFreeIf(node);
       if (--list->count == 0) {
           list->head = NULL;
       }
    }
    NSSLIST_UNLOCK_IF(list);
    return PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_EXTERN void nssList_SetCompareFunction ( nssList *  list,
nssListCompareFunc  compareFunc 
)

Definition at line 173 of file list.c.

{
    list->compareFunc = compareFunc;
}
NSS_EXTERN void nssList_SetSortFunction ( nssList *  list,
nssListSortFunc  sortFunc 
)

Definition at line 179 of file list.c.

{
    /* XXX if list already has elements, sort them */
    list->sortFunc = sortFunc;
}

Here is the caller graph for this function:

NSS_EXTERN void nssListIterator_Destroy ( nssListIterator *  iter)

Definition at line 388 of file list.c.

{
    if (iter->lock) {
       (void)PZ_DestroyLock(iter->lock);
    }
    nssList_Destroy(iter->list);
    nss_ZFreeIf(iter);
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssListIterator_Finish ( nssListIterator *  iter)

Definition at line 431 of file list.c.

{
    iter->current = iter->list->head;
    return (iter->lock) ? PZ_Unlock(iter->lock) : PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_EXTERN void* nssListIterator_Next ( nssListIterator *  iter)

Definition at line 409 of file list.c.

{
    nssListElement *node;
    PRCList *link;
    if (iter->list->count == 1 || iter->current == NULL) {
       /* Reached the end of the list.  Don't change the state, force to
        * user to call nssList_Finish to clean up.
        */
       return NULL;
    }
    node = (nssListElement *)PR_NEXT_LINK(&iter->current->link);
    link = &node->link;
    if (link == PR_LIST_TAIL(&iter->list->head->link)) {
       /* Signal the end of the list. */
       iter->current = NULL;
       return node->data;
    }
    iter->current = node;
    return node->data;
}

Here is the caller graph for this function:

NSS_EXTERN void* nssListIterator_Start ( nssListIterator *  iter)

Definition at line 398 of file list.c.

{
    NSSLIST_LOCK_IF(iter);
    if (iter->list->count == 0) {
       return NULL;
    }
    iter->current = iter->list->head;
    return iter->current->data;
}

Here is the caller graph for this function:

Definition at line 78 of file utf8.c.

{
#ifdef NSSDEBUG
  if( ((const NSSUTF8 *)NULL == a) ||
      ((const NSSUTF8 *)NULL == b) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return PR_FALSE;
  }
#endif /* NSSDEBUG */

  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  /*
   * XXX fgmr
   *
   * This is, like, so wrong!
   */
  if( 0 == PL_strcasecmp((const char *)a, (const char *)b) ) {
    return PR_TRUE;
  } else {
    return PR_FALSE;
  }
}

Here is the caller graph for this function:

NSS_EXTERN PRStatus nssUTF8_CopyIntoFixedBuffer ( NSSUTF8 string,
char *  buffer,
PRUint32  bufferSize,
char  pad 
)

Definition at line 658 of file utf8.c.

{
  PRUint32 stringSize = 0;

#ifdef NSSDEBUG
  if( (char *)NULL == buffer ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return PR_FALSE;
  }

  if( 0 == bufferSize ) {
    nss_SetError(NSS_ERROR_INVALID_ARGUMENT);
    return PR_FALSE;
  }

  if( (pad & 0x80) != 0x00 ) {
    nss_SetError(NSS_ERROR_INVALID_ARGUMENT);
    return PR_FALSE;
  }
#endif /* NSSDEBUG */

  if( (NSSUTF8 *)NULL == string ) {
    string = (NSSUTF8 *) "";
  }

  stringSize = nssUTF8_Size(string, (PRStatus *)NULL);
  stringSize--; /* don't count the trailing null */
  if( stringSize > bufferSize ) {
    PRUint32 bs = bufferSize;
    (void)nsslibc_memcpy(buffer, string, bufferSize);
    
    if( (            ((buffer[ bs-1 ] & 0x80) == 0x00)) ||
        ((bs > 1) && ((buffer[ bs-2 ] & 0xE0) == 0xC0)) ||
        ((bs > 2) && ((buffer[ bs-3 ] & 0xF0) == 0xE0)) ||
        ((bs > 3) && ((buffer[ bs-4 ] & 0xF8) == 0xF0)) ||
        ((bs > 4) && ((buffer[ bs-5 ] & 0xFC) == 0xF8)) ||
        ((bs > 5) && ((buffer[ bs-6 ] & 0xFE) == 0xFC)) ) {
      /* It fit exactly */
      return PR_SUCCESS;
    }

    /* Too long.  We have to trim the last character */
    for( /*bs*/; bs != 0; bs-- ) {
      if( (buffer[bs-1] & 0xC0) != 0x80 ) {
        buffer[bs-1] = pad;
        break;
      } else {
        buffer[bs-1] = pad;
      }
    }      
  } else {
    (void)nsslibc_memset(buffer, pad, bufferSize);
    (void)nsslibc_memcpy(buffer, string, stringSize);
  }

  return PR_SUCCESS;
}

Here is the caller graph for this function:

NSS_EXTERN NSSUTF8* nssUTF8_Create ( NSSArena *  arenaOpt,
nssStringType  type,
const void inputString,
PRUint32  size 
)

Definition at line 465 of file utf8.c.

{
  NSSUTF8 *rv = NULL;

#ifdef NSSDEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSUTF8 *)NULL;
    }
  }

  if( (const void *)NULL == inputString ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSUTF8 *)NULL;
  }
#endif /* NSSDEBUG */

  switch( type ) {
  case nssStringType_DirectoryString:
    /* This is a composite type requiring BER */
    nss_SetError(NSS_ERROR_UNSUPPORTED_TYPE);
    break;
  case nssStringType_TeletexString:
    /*
     * draft-ietf-pkix-ipki-part1-11 says in part:
     *
     * In addition, many legacy implementations support names encoded 
     * in the ISO 8859-1 character set (Latin1String) but tag them as 
     * TeletexString.  The Latin1String includes characters used in 
     * Western European countries which are not part of the 
     * TeletexString charcter set.  Implementations that process 
     * TeletexString SHOULD be prepared to handle the entire ISO 
     * 8859-1 character set.[ISO 8859-1].
     */
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_PrintableString:
    /*
     * PrintableString consists of A-Za-z0-9 ,()+,-./:=?
     * This is a subset of ASCII, which is a subset of UTF8.
     * So we can just duplicate the string over.
     */

    if( 0 == size ) {
      rv = nssUTF8_Duplicate((const NSSUTF8 *)inputString, arenaOpt);
    } else {
      rv = nss_ZAlloc(arenaOpt, size+1);
      if( (NSSUTF8 *)NULL == rv ) {
        return (NSSUTF8 *)NULL;
      }

      (void)nsslibc_memcpy(rv, inputString, size);
    }

    break;
  case nssStringType_UniversalString:
    /* 4-byte unicode */
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_BMPString:
    /* Base Multilingual Plane of Unicode */
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_UTF8String:
    if( 0 == size ) {
      rv = nssUTF8_Duplicate((const NSSUTF8 *)inputString, arenaOpt);
    } else {
      rv = nss_ZAlloc(arenaOpt, size+1);
      if( (NSSUTF8 *)NULL == rv ) {
        return (NSSUTF8 *)NULL;
      }

      (void)nsslibc_memcpy(rv, inputString, size);
    }

    break;
  case nssStringType_PHGString:
    /* 
     * PHGString is an IA5String (with case-insensitive comparisons).
     * IA5 is ~almost~ ascii; ascii has dollar-sign where IA5 has
     * currency symbol.
     */
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_GeneralString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  default:
    nss_SetError(NSS_ERROR_UNSUPPORTED_TYPE);
    break;
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSUTF8* nssUTF8_Duplicate ( const NSSUTF8 s,
NSSArena *  arenaOpt 
)

Definition at line 241 of file utf8.c.

{
  NSSUTF8 *rv;
  PRUint32 len;

#ifdef NSSDEBUG
  if( (const NSSUTF8 *)NULL == s ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSUTF8 *)NULL;
  }

  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSUTF8 *)NULL;
    }
  }
#endif /* NSSDEBUG */

  len = PL_strlen((const char *)s);
#ifdef PEDANTIC
  if( '\0' != ((const char *)s)[ len ] ) {
    /* must have wrapped, e.g., too big for PRUint32 */
    nss_SetError(NSS_ERROR_NO_MEMORY);
    return (NSSUTF8 *)NULL;
  }
#endif /* PEDANTIC */
  len++; /* zero termination */

  rv = nss_ZAlloc(arenaOpt, len);
  if( (void *)NULL == rv ) {
    return (NSSUTF8 *)NULL;
  }

  (void)nsslibc_memcpy(rv, s, len);
  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN PRBool nssUTF8_Equal ( const NSSUTF8 a,
const NSSUTF8 b,
PRStatus statusOpt 
)

Definition at line 728 of file utf8.c.

{
  PRUint32 la, lb;

#ifdef NSSDEBUG
  if( ((const NSSUTF8 *)NULL == a) ||
      ((const NSSUTF8 *)NULL == b) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return PR_FALSE;
  }
#endif /* NSSDEBUG */

  la = nssUTF8_Size(a, statusOpt);
  if( 0 == la ) {
    return PR_FALSE;
  }

  lb = nssUTF8_Size(b, statusOpt);
  if( 0 == lb ) {
    return PR_FALSE;
  }

  if( la != lb ) {
    return PR_FALSE;
  }

  return nsslibc_memequal(a, b, la, statusOpt);
}

Here is the caller graph for this function:

NSS_EXTERN NSSItem* nssUTF8_GetEncoding ( NSSArena *  arenaOpt,
NSSItem *  rvOpt,
nssStringType  type,
NSSUTF8 string 
)

Definition at line 567 of file utf8.c.

{
  NSSItem *rv = (NSSItem *)NULL;
  PRStatus status = PR_SUCCESS;

#ifdef NSSDEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSItem *)NULL;
    }
  }

  if( (NSSUTF8 *)NULL == string ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSItem *)NULL;
  }
#endif /* NSSDEBUG */

  switch( type ) {
  case nssStringType_DirectoryString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_TeletexString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_PrintableString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_UniversalString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_BMPString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  case nssStringType_UTF8String:
    {
      NSSUTF8 *dup = nssUTF8_Duplicate(string, arenaOpt);
      if( (NSSUTF8 *)NULL == dup ) {
        return (NSSItem *)NULL;
      }

      if( (NSSItem *)NULL == rvOpt ) {
        rv = nss_ZNEW(arenaOpt, NSSItem);
        if( (NSSItem *)NULL == rv ) {
          (void)nss_ZFreeIf(dup);
          return (NSSItem *)NULL;
        }
      } else {
        rv = rvOpt;
      }

      rv->data = dup;
      dup = (NSSUTF8 *)NULL;
      rv->size = nssUTF8_Size(rv->data, &status);
      if( (0 == rv->size) && (PR_SUCCESS != status) ) {
        if( (NSSItem *)NULL == rvOpt ) {
          (void)nss_ZFreeIf(rv);
        }
        return (NSSItem *)NULL;
      }
    }
    break;
  case nssStringType_PHGString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR); /* unimplemented */
    break;
  default:
    nss_SetError(NSS_ERROR_UNSUPPORTED_TYPE);
    break;
  }

  return rv;
}

Definition at line 354 of file utf8.c.

{
  PRUint32 l = 0;
  const PRUint8 *c = (const PRUint8 *)s;

#ifdef NSSDEBUG
  if( (const NSSUTF8 *)NULL == s ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    goto loser;
  }
#endif /* NSSDEBUG */

  /*
   * From RFC 2044:
   *
   * UCS-4 range (hex.)           UTF-8 octet sequence (binary)
   * 0000 0000-0000 007F   0xxxxxxx
   * 0000 0080-0000 07FF   110xxxxx 10xxxxxx
   * 0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
   * 0001 0000-001F FFFF   11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
   * 0020 0000-03FF FFFF   111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
   * 0400 0000-7FFF FFFF   1111110x 10xxxxxx ... 10xxxxxx
   */  

  while( 0 != *c ) {
    PRUint32 incr;
    if( (*c & 0x80) == 0 ) {
      incr = 1;
    } else if( (*c & 0xE0) == 0xC0 ) {
      incr = 2;
    } else if( (*c & 0xF0) == 0xE0 ) {
      incr = 3;
    } else if( (*c & 0xF8) == 0xF0 ) {
      incr = 4;
    } else if( (*c & 0xFC) == 0xF8 ) {
      incr = 5;
    } else if( (*c & 0xFE) == 0xFC ) {
      incr = 6;
    } else {
      nss_SetError(NSS_ERROR_INVALID_STRING);
      goto loser;
    }

    l += incr;

#ifdef PEDANTIC
    if( l < incr ) {
      /* Wrapped-- too big */
      nss_SetError(NSS_ERROR_VALUE_TOO_LARGE);
      goto loser;
    }

    {
      PRUint8 *d;
      for( d = &c[1]; d < &c[incr]; d++ ) {
        if( (*d & 0xC0) != 0xF0 ) {
          nss_SetError(NSS_ERROR_INVALID_STRING);
          goto loser;
        }
      }
    }
#endif /* PEDANTIC */

    c += incr;
  }

  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  return l;

 loser:
  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_FAILURE;
  }

  return 0;
}

Here is the caller graph for this function:

Definition at line 135 of file utf8.c.

{
  PRUint8 *c;
  PRUint8 *d;

#ifdef NSSDEBUG
  if( ((const NSSUTF8 *)NULL == a) ||
      ((const NSSUTF8 *)NULL == b) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return PR_FALSE;
  }
#endif /* NSSDEBUG */

  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  c = (PRUint8 *)a;
  d = (PRUint8 *)b;

  while( ' ' == *c ) {
    c++;
  }

  while( ' ' == *d ) {
    d++;
  }

  while( ('\0' != *c) && ('\0' != *d) ) {
    PRUint8 e, f;

    e = *c;
    f = *d;
    
    if( ('a' <= e) && (e <= 'z') ) {
      e -= ('a' - 'A');
    }

    if( ('a' <= f) && (f <= 'z') ) {
      f -= ('a' - 'A');
    }

    if( e != f ) {
      return PR_FALSE;
    }

    c++;
    d++;

    if( ' ' == *c ) {
      while( ' ' == *c ) {
        c++;
      }
      c--;
    }

    if( ' ' == *d ) {
      while( ' ' == *d ) {
        d++;
      }
      d--;
    }
  }

  while( ' ' == *c ) {
    c++;
  }

  while( ' ' == *d ) {
    d++;
  }

  if( *c == *d ) {
    /* And both '\0', btw */
    return PR_TRUE;
  } else {
    return PR_FALSE;
  }
}

Here is the caller graph for this function:

NSS_EXTERN PRUint32 nssUTF8_Size ( const NSSUTF8 s,
PRStatus statusOpt 
)

Definition at line 299 of file utf8.c.

{
  PRUint32 sv;

#ifdef NSSDEBUG
  if( (const NSSUTF8 *)NULL == s ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return 0;
  }
#endif /* NSSDEBUG */

  sv = PL_strlen((const char *)s) + 1;
#ifdef PEDANTIC
  if( '\0' != ((const char *)s)[ sv-1 ] ) {
    /* wrapped */
    nss_SetError(NSS_ERROR_VALUE_TOO_LARGE);
    if( (PRStatus *)NULL != statusOpt ) {
      *statusOpt = PR_FAILURE;
    }
    return 0;
  }
#endif /* PEDANTIC */

  if( (PRStatus *)NULL != statusOpt ) {
    *statusOpt = PR_SUCCESS;
  }

  return sv;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 246 of file base.h.

Definition at line 91 of file errorval.c.

Definition at line 182 of file base.h.

Definition at line 245 of file base.h.

Definition at line 75 of file errorval.c.

Definition at line 407 of file base.h.

Definition at line 264 of file nsspki1.h.

Definition at line 183 of file base.h.

Definition at line 63 of file errorval.c.

Definition at line 748 of file base.h.

Definition at line 534 of file base.h.