Back to index

lightning-sunbird  0.9+nobinonly
Functions
secitem.h File Reference
#include "plarena.h"
#include "plhash.h"
#include "seccomon.h"

Go to the source code of this file.

Functions

SEC_BEGIN_PROTOS SECItem * SECITEM_AllocItem (PRArenaPool *arena, SECItem *item, unsigned int len)
SECStatus SECITEM_ReallocItem (PRArenaPool *arena, SECItem *item, unsigned int oldlen, unsigned int newlen)
SECComparison SECITEM_CompareItem (const SECItem *a, const SECItem *b)
PRBool SECITEM_ItemsAreEqual (const SECItem *a, const SECItem *b)
SECStatus SECITEM_CopyItem (PRArenaPool *arena, SECItem *to, const SECItem *from)
SECItem * SECITEM_DupItem (const SECItem *from)
SECItem * SECITEM_ArenaDupItem (PRArenaPool *arena, const SECItem *from)
void SECITEM_FreeItem (SECItem *zap, PRBool freeit)
void SECITEM_ZfreeItem (SECItem *zap, PRBool freeit)
PLHashNumber PR_CALLBACK SECITEM_Hash (const void *key)
PRIntn PR_CALLBACK SECITEM_HashCompare (const void *k1, const void *k2)

Function Documentation

SEC_BEGIN_PROTOS SECItem* SECITEM_AllocItem ( PRArenaPool arena,
SECItem *  item,
unsigned int  len 
)

Definition at line 49 of file secitem.c.

{
    SECItem *result = NULL;
    void *mark = NULL;

    if (arena != NULL) {
       mark = PORT_ArenaMark(arena);
    }

    if (item == NULL) {
       if (arena != NULL) {
           result = PORT_ArenaZAlloc(arena, sizeof(SECItem));
       } else {
           result = PORT_ZAlloc(sizeof(SECItem));
       }
       if (result == NULL) {
           goto loser;
       }
    } else {
       PORT_Assert(item->data == NULL);
       result = item;
    }

    result->len = len;
    if (len) {
       if (arena != NULL) {
           result->data = PORT_ArenaAlloc(arena, len);
       } else {
           result->data = PORT_Alloc(len);
       }
    }

    if (mark) {
       PORT_ArenaUnmark(arena, mark);
    }
    return(result);

loser:
    if ( arena != NULL ) {
       if (mark) {
           PORT_ArenaRelease(arena, mark);
       }
       if (item != NULL) {
           item->data = NULL;
           item->len = 0;
       }
    } else {
       if (result != NULL) {
           SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE);
       }
    }
    return(NULL);
}

Here is the call graph for this function:

SECItem* SECITEM_ArenaDupItem ( PRArenaPool arena,
const SECItem *  from 
)

Definition at line 190 of file secitem.c.

{
    SECItem *to;
    
    if ( from == NULL ) {
       return(NULL);
    }
    
    if ( arena != NULL ) {
       to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem));
    } else {
       to = (SECItem *)PORT_Alloc(sizeof(SECItem));
    }
    if ( to == NULL ) {
       return(NULL);
    }

    if ( arena != NULL ) {
       to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len);
    } else {
       to->data = (unsigned char *)PORT_Alloc(from->len);
    }
    if ( to->data == NULL ) {
       PORT_Free(to);
       return(NULL);
    }

    to->len = from->len;
    to->type = from->type;
    if ( to->len ) {
       PORT_Memcpy(to->data, from->data, to->len);
    }
    
    return(to);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SECComparison SECITEM_CompareItem ( const SECItem *  a,
const SECItem *  b 
)

Definition at line 144 of file secitem.c.

{
    unsigned m;
    SECComparison rv;

    if (!a || !a->len || !a->data) 
        return (!b || !b->len || !b->data) ? SECEqual : SECLessThan;
    if (!b || !b->len || !b->data) 
       return SECGreaterThan;

    m = ( ( a->len < b->len ) ? a->len : b->len );
    
    rv = (SECComparison) PORT_Memcmp(a->data, b->data, m);
    if (rv) {
       return rv;
    }
    if (a->len < b->len) {
       return SECLessThan;
    }
    if (a->len == b->len) {
       return SECEqual;
    }
    return SECGreaterThan;
}

Here is the caller graph for this function:

SECStatus SECITEM_CopyItem ( PRArenaPool arena,
SECItem *  to,
const SECItem *  from 
)

Definition at line 227 of file secitem.c.

{
    to->type = from->type;
    if (from->data && from->len) {
       if ( arena ) {
           to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len);
       } else {
           to->data = (unsigned char*) PORT_Alloc(from->len);
       }
       
       if (!to->data) {
           return SECFailure;
       }
       PORT_Memcpy(to->data, from->data, from->len);
       to->len = from->len;
    } else {
       to->data = 0;
       to->len = 0;
    }
    return SECSuccess;
}

Here is the call graph for this function:

SECItem* SECITEM_DupItem ( const SECItem *  from)

Definition at line 184 of file secitem.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void SECITEM_FreeItem ( SECItem *  zap,
PRBool  freeit 
)

Definition at line 250 of file secitem.c.

{
    if (zap) {
       PORT_Free(zap->data);
       zap->data = 0;
       zap->len = 0;
       if (freeit) {
           PORT_Free(zap);
       }
    }
}

Here is the call graph for this function:

Definition at line 68 of file crlgen.c.

{
    const SECItem *item = (const SECItem *)key;
    PLHashNumber rv = 0;

    PRUint8 *data = (PRUint8 *)item->data;
    PRUint32 i;
    PRUint8 *rvc = (PRUint8 *)&rv;

    for( i = 0; i < item->len; i++ ) {
        rvc[ i % sizeof(rv) ] ^= *data;
        data++;
    }

    return rv;
}

Here is the caller graph for this function:

PRIntn PR_CALLBACK SECITEM_HashCompare ( const void k1,
const void k2 
)

Definition at line 92 of file crlgen.c.

{
    const SECItem *i1 = (const SECItem *)k1;
    const SECItem *i2 = (const SECItem *)k2;

    return SECITEM_ItemsAreEqual(i1,i2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool SECITEM_ItemsAreEqual ( const SECItem *  a,
const SECItem *  b 
)

Definition at line 170 of file secitem.c.

{
    if (a->len != b->len)
        return PR_FALSE;
    if (!a->len)
       return PR_TRUE;
    if (!a->data || !b->data) {
        /* avoid null pointer crash. */
       return (PRBool)(a->data == b->data);
    }
    return (PRBool)!PORT_Memcmp(a->data, b->data, a->len);
}

Here is the caller graph for this function:

SECStatus SECITEM_ReallocItem ( PRArenaPool arena,
SECItem *  item,
unsigned int  oldlen,
unsigned int  newlen 
)

Definition at line 104 of file secitem.c.

{
    PORT_Assert(item != NULL);
    if (item == NULL) {
       /* XXX Set error.  But to what? */
       return SECFailure;
    }

    /*
     * If no old length, degenerate to just plain alloc.
     */
    if (oldlen == 0) {
       PORT_Assert(item->data == NULL || item->len == 0);
       if (newlen == 0) {
           /* Nothing to do.  Weird, but not a failure.  */
           return SECSuccess;
       }
       item->len = newlen;
       if (arena != NULL) {
           item->data = PORT_ArenaAlloc(arena, newlen);
       } else {
           item->data = PORT_Alloc(newlen);
       }
    } else {
       if (arena != NULL) {
           item->data = PORT_ArenaGrow(arena, item->data, oldlen, newlen);
       } else {
           item->data = PORT_Realloc(item->data, newlen);
       }
    }

    if (item->data == NULL) {
       return SECFailure;
    }

    return SECSuccess;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SECITEM_ZfreeItem ( SECItem *  zap,
PRBool  freeit 
)

Definition at line 263 of file secitem.c.

{
    if (zap) {
       PORT_ZFree(zap->data, zap->len);
       zap->data = 0;
       zap->len = 0;
       if (freeit) {
           PORT_ZFree(zap, sizeof(SECItem));
       }
    }
}

Here is the call graph for this function: