andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef _SECITEM_H_ andre@0: #define _SECITEM_H_ andre@0: andre@0: #include "utilrename.h" andre@0: andre@0: /* andre@0: * secitem.h - public data structures and prototypes for handling andre@0: * SECItems andre@0: */ andre@0: andre@0: #include "plarena.h" andre@0: #include "plhash.h" andre@0: #include "seccomon.h" andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: /* andre@0: ** Allocate an item. If "arena" is not NULL, then allocate from there, andre@0: ** otherwise allocate from the heap. If "item" is not NULL, allocate andre@0: ** only the data buffer for the item, not the item itself. If "len" is andre@0: ** 0, do not allocate the data buffer for the item; simply set the data andre@0: ** field to NULL and the len field to 0. The item structure is allocated andre@0: ** zero-filled; the data buffer is not zeroed. The caller is responsible andre@0: ** for initializing the type field of the item. andre@0: ** andre@0: ** The resulting item is returned; NULL if any error occurs. andre@0: ** andre@0: ** XXX This probably should take a SECItemType, but since that is mostly andre@0: ** unused and our improved APIs (aka Stan) are looming, I left it out. andre@0: */ andre@0: extern SECItem *SECITEM_AllocItem(PLArenaPool *arena, SECItem *item, andre@0: unsigned int len); andre@0: andre@0: /* andre@0: ** This is a legacy function containing bugs. It doesn't update item->len, andre@0: ** and it has other issues as described in bug 298649 and bug 298938. andre@0: ** However, the function is kept unchanged for consumers that might depend andre@0: ** on the broken behaviour. New code should call SECITEM_ReallocItemV2. andre@0: ** andre@0: ** Reallocate the data for the specified "item". If "arena" is not NULL, andre@0: ** then reallocate from there, otherwise reallocate from the heap. andre@0: ** In the case where oldlen is 0, the data is allocated (not reallocated). andre@0: ** In any case, "item" is expected to be a valid SECItem pointer; andre@0: ** SECFailure is returned if it is not. If the allocation succeeds, andre@0: ** SECSuccess is returned. andre@0: */ andre@0: extern SECStatus SECITEM_ReallocItem( /* deprecated function */ andre@0: PLArenaPool *arena, SECItem *item, andre@0: unsigned int oldlen, unsigned int newlen); andre@0: andre@0: /* andre@0: ** Reallocate the data for the specified "item". If "arena" is not NULL, andre@0: ** then reallocate from there, otherwise reallocate from the heap. andre@0: ** If item->data is NULL, the data is allocated (not reallocated). andre@0: ** In any case, "item" is expected to be a valid SECItem pointer; andre@0: ** SECFailure is returned if it is not, and the item will remain unchanged. andre@0: ** If the allocation succeeds, the item is updated and SECSuccess is returned. andre@0: */ andre@0: extern SECStatus SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, andre@0: unsigned int newlen); andre@0: andre@0: /* andre@0: ** Compare two items returning the difference between them. andre@0: */ andre@0: extern SECComparison SECITEM_CompareItem(const SECItem *a, const SECItem *b); andre@0: andre@0: /* andre@0: ** Compare two items -- if they are the same, return true; otherwise false. andre@0: */ andre@0: extern PRBool SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b); andre@0: andre@0: /* andre@0: ** Copy "from" to "to" andre@0: */ andre@0: extern SECStatus SECITEM_CopyItem(PLArenaPool *arena, SECItem *to, andre@0: const SECItem *from); andre@0: andre@0: /* andre@0: ** Allocate an item and copy "from" into it. andre@0: */ andre@0: extern SECItem *SECITEM_DupItem(const SECItem *from); andre@0: andre@0: /* andre@0: ** Allocate an item and copy "from" into it. The item itself and the andre@0: ** data it points to are both allocated from the arena. If arena is andre@0: ** NULL, this function is equivalent to SECITEM_DupItem. andre@0: */ andre@0: extern SECItem *SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from); andre@0: andre@0: /* andre@0: ** Free "zap". If freeit is PR_TRUE then "zap" itself is freed. andre@0: */ andre@0: extern void SECITEM_FreeItem(SECItem *zap, PRBool freeit); andre@0: andre@0: /* andre@0: ** Zero and then free "zap". If freeit is PR_TRUE then "zap" itself is freed. andre@0: */ andre@0: extern void SECITEM_ZfreeItem(SECItem *zap, PRBool freeit); andre@0: andre@0: PLHashNumber PR_CALLBACK SECITEM_Hash ( const void *key); andre@0: andre@0: PRIntn PR_CALLBACK SECITEM_HashCompare ( const void *k1, const void *k2); andre@0: andre@0: extern SECItemArray *SECITEM_AllocArray(PLArenaPool *arena, andre@0: SECItemArray *array, andre@0: unsigned int len); andre@0: extern SECItemArray *SECITEM_DupArray(PLArenaPool *arena, andre@0: const SECItemArray *from); andre@0: extern void SECITEM_FreeArray(SECItemArray *array, PRBool freeit); andre@0: extern void SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif /* _SECITEM_H_ */