1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/util/secitem.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef _SECITEM_H_ 1.9 +#define _SECITEM_H_ 1.10 + 1.11 +#include "utilrename.h" 1.12 + 1.13 +/* 1.14 + * secitem.h - public data structures and prototypes for handling 1.15 + * SECItems 1.16 + */ 1.17 + 1.18 +#include "plarena.h" 1.19 +#include "plhash.h" 1.20 +#include "seccomon.h" 1.21 + 1.22 +SEC_BEGIN_PROTOS 1.23 + 1.24 +/* 1.25 +** Allocate an item. If "arena" is not NULL, then allocate from there, 1.26 +** otherwise allocate from the heap. If "item" is not NULL, allocate 1.27 +** only the data buffer for the item, not the item itself. If "len" is 1.28 +** 0, do not allocate the data buffer for the item; simply set the data 1.29 +** field to NULL and the len field to 0. The item structure is allocated 1.30 +** zero-filled; the data buffer is not zeroed. The caller is responsible 1.31 +** for initializing the type field of the item. 1.32 +** 1.33 +** The resulting item is returned; NULL if any error occurs. 1.34 +** 1.35 +** XXX This probably should take a SECItemType, but since that is mostly 1.36 +** unused and our improved APIs (aka Stan) are looming, I left it out. 1.37 +*/ 1.38 +extern SECItem *SECITEM_AllocItem(PLArenaPool *arena, SECItem *item, 1.39 + unsigned int len); 1.40 + 1.41 +/* 1.42 +** This is a legacy function containing bugs. It doesn't update item->len, 1.43 +** and it has other issues as described in bug 298649 and bug 298938. 1.44 +** However, the function is kept unchanged for consumers that might depend 1.45 +** on the broken behaviour. New code should call SECITEM_ReallocItemV2. 1.46 +** 1.47 +** Reallocate the data for the specified "item". If "arena" is not NULL, 1.48 +** then reallocate from there, otherwise reallocate from the heap. 1.49 +** In the case where oldlen is 0, the data is allocated (not reallocated). 1.50 +** In any case, "item" is expected to be a valid SECItem pointer; 1.51 +** SECFailure is returned if it is not. If the allocation succeeds, 1.52 +** SECSuccess is returned. 1.53 +*/ 1.54 +extern SECStatus SECITEM_ReallocItem( /* deprecated function */ 1.55 + PLArenaPool *arena, SECItem *item, 1.56 + unsigned int oldlen, unsigned int newlen); 1.57 + 1.58 +/* 1.59 +** Reallocate the data for the specified "item". If "arena" is not NULL, 1.60 +** then reallocate from there, otherwise reallocate from the heap. 1.61 +** If item->data is NULL, the data is allocated (not reallocated). 1.62 +** In any case, "item" is expected to be a valid SECItem pointer; 1.63 +** SECFailure is returned if it is not, and the item will remain unchanged. 1.64 +** If the allocation succeeds, the item is updated and SECSuccess is returned. 1.65 + */ 1.66 +extern SECStatus SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, 1.67 + unsigned int newlen); 1.68 + 1.69 +/* 1.70 +** Compare two items returning the difference between them. 1.71 +*/ 1.72 +extern SECComparison SECITEM_CompareItem(const SECItem *a, const SECItem *b); 1.73 + 1.74 +/* 1.75 +** Compare two items -- if they are the same, return true; otherwise false. 1.76 +*/ 1.77 +extern PRBool SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b); 1.78 + 1.79 +/* 1.80 +** Copy "from" to "to" 1.81 +*/ 1.82 +extern SECStatus SECITEM_CopyItem(PLArenaPool *arena, SECItem *to, 1.83 + const SECItem *from); 1.84 + 1.85 +/* 1.86 +** Allocate an item and copy "from" into it. 1.87 +*/ 1.88 +extern SECItem *SECITEM_DupItem(const SECItem *from); 1.89 + 1.90 +/* 1.91 +** Allocate an item and copy "from" into it. The item itself and the 1.92 +** data it points to are both allocated from the arena. If arena is 1.93 +** NULL, this function is equivalent to SECITEM_DupItem. 1.94 +*/ 1.95 +extern SECItem *SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from); 1.96 + 1.97 +/* 1.98 +** Free "zap". If freeit is PR_TRUE then "zap" itself is freed. 1.99 +*/ 1.100 +extern void SECITEM_FreeItem(SECItem *zap, PRBool freeit); 1.101 + 1.102 +/* 1.103 +** Zero and then free "zap". If freeit is PR_TRUE then "zap" itself is freed. 1.104 +*/ 1.105 +extern void SECITEM_ZfreeItem(SECItem *zap, PRBool freeit); 1.106 + 1.107 +PLHashNumber PR_CALLBACK SECITEM_Hash ( const void *key); 1.108 + 1.109 +PRIntn PR_CALLBACK SECITEM_HashCompare ( const void *k1, const void *k2); 1.110 + 1.111 +extern SECItemArray *SECITEM_AllocArray(PLArenaPool *arena, 1.112 + SECItemArray *array, 1.113 + unsigned int len); 1.114 +extern SECItemArray *SECITEM_DupArray(PLArenaPool *arena, 1.115 + const SECItemArray *from); 1.116 +extern void SECITEM_FreeArray(SECItemArray *array, PRBool freeit); 1.117 +extern void SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit); 1.118 + 1.119 +SEC_END_PROTOS 1.120 + 1.121 +#endif /* _SECITEM_H_ */