Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef _SECITEM_H_ |
michael@0 | 6 | #define _SECITEM_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "utilrename.h" |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | * secitem.h - public data structures and prototypes for handling |
michael@0 | 12 | * SECItems |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #include "plarena.h" |
michael@0 | 16 | #include "plhash.h" |
michael@0 | 17 | #include "seccomon.h" |
michael@0 | 18 | |
michael@0 | 19 | SEC_BEGIN_PROTOS |
michael@0 | 20 | |
michael@0 | 21 | /* |
michael@0 | 22 | ** Allocate an item. If "arena" is not NULL, then allocate from there, |
michael@0 | 23 | ** otherwise allocate from the heap. If "item" is not NULL, allocate |
michael@0 | 24 | ** only the data buffer for the item, not the item itself. If "len" is |
michael@0 | 25 | ** 0, do not allocate the data buffer for the item; simply set the data |
michael@0 | 26 | ** field to NULL and the len field to 0. The item structure is allocated |
michael@0 | 27 | ** zero-filled; the data buffer is not zeroed. The caller is responsible |
michael@0 | 28 | ** for initializing the type field of the item. |
michael@0 | 29 | ** |
michael@0 | 30 | ** The resulting item is returned; NULL if any error occurs. |
michael@0 | 31 | ** |
michael@0 | 32 | ** XXX This probably should take a SECItemType, but since that is mostly |
michael@0 | 33 | ** unused and our improved APIs (aka Stan) are looming, I left it out. |
michael@0 | 34 | */ |
michael@0 | 35 | extern SECItem *SECITEM_AllocItem(PLArenaPool *arena, SECItem *item, |
michael@0 | 36 | unsigned int len); |
michael@0 | 37 | |
michael@0 | 38 | /* |
michael@0 | 39 | ** This is a legacy function containing bugs. It doesn't update item->len, |
michael@0 | 40 | ** and it has other issues as described in bug 298649 and bug 298938. |
michael@0 | 41 | ** However, the function is kept unchanged for consumers that might depend |
michael@0 | 42 | ** on the broken behaviour. New code should call SECITEM_ReallocItemV2. |
michael@0 | 43 | ** |
michael@0 | 44 | ** Reallocate the data for the specified "item". If "arena" is not NULL, |
michael@0 | 45 | ** then reallocate from there, otherwise reallocate from the heap. |
michael@0 | 46 | ** In the case where oldlen is 0, the data is allocated (not reallocated). |
michael@0 | 47 | ** In any case, "item" is expected to be a valid SECItem pointer; |
michael@0 | 48 | ** SECFailure is returned if it is not. If the allocation succeeds, |
michael@0 | 49 | ** SECSuccess is returned. |
michael@0 | 50 | */ |
michael@0 | 51 | extern SECStatus SECITEM_ReallocItem( /* deprecated function */ |
michael@0 | 52 | PLArenaPool *arena, SECItem *item, |
michael@0 | 53 | unsigned int oldlen, unsigned int newlen); |
michael@0 | 54 | |
michael@0 | 55 | /* |
michael@0 | 56 | ** Reallocate the data for the specified "item". If "arena" is not NULL, |
michael@0 | 57 | ** then reallocate from there, otherwise reallocate from the heap. |
michael@0 | 58 | ** If item->data is NULL, the data is allocated (not reallocated). |
michael@0 | 59 | ** In any case, "item" is expected to be a valid SECItem pointer; |
michael@0 | 60 | ** SECFailure is returned if it is not, and the item will remain unchanged. |
michael@0 | 61 | ** If the allocation succeeds, the item is updated and SECSuccess is returned. |
michael@0 | 62 | */ |
michael@0 | 63 | extern SECStatus SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, |
michael@0 | 64 | unsigned int newlen); |
michael@0 | 65 | |
michael@0 | 66 | /* |
michael@0 | 67 | ** Compare two items returning the difference between them. |
michael@0 | 68 | */ |
michael@0 | 69 | extern SECComparison SECITEM_CompareItem(const SECItem *a, const SECItem *b); |
michael@0 | 70 | |
michael@0 | 71 | /* |
michael@0 | 72 | ** Compare two items -- if they are the same, return true; otherwise false. |
michael@0 | 73 | */ |
michael@0 | 74 | extern PRBool SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b); |
michael@0 | 75 | |
michael@0 | 76 | /* |
michael@0 | 77 | ** Copy "from" to "to" |
michael@0 | 78 | */ |
michael@0 | 79 | extern SECStatus SECITEM_CopyItem(PLArenaPool *arena, SECItem *to, |
michael@0 | 80 | const SECItem *from); |
michael@0 | 81 | |
michael@0 | 82 | /* |
michael@0 | 83 | ** Allocate an item and copy "from" into it. |
michael@0 | 84 | */ |
michael@0 | 85 | extern SECItem *SECITEM_DupItem(const SECItem *from); |
michael@0 | 86 | |
michael@0 | 87 | /* |
michael@0 | 88 | ** Allocate an item and copy "from" into it. The item itself and the |
michael@0 | 89 | ** data it points to are both allocated from the arena. If arena is |
michael@0 | 90 | ** NULL, this function is equivalent to SECITEM_DupItem. |
michael@0 | 91 | */ |
michael@0 | 92 | extern SECItem *SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from); |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | ** Free "zap". If freeit is PR_TRUE then "zap" itself is freed. |
michael@0 | 96 | */ |
michael@0 | 97 | extern void SECITEM_FreeItem(SECItem *zap, PRBool freeit); |
michael@0 | 98 | |
michael@0 | 99 | /* |
michael@0 | 100 | ** Zero and then free "zap". If freeit is PR_TRUE then "zap" itself is freed. |
michael@0 | 101 | */ |
michael@0 | 102 | extern void SECITEM_ZfreeItem(SECItem *zap, PRBool freeit); |
michael@0 | 103 | |
michael@0 | 104 | PLHashNumber PR_CALLBACK SECITEM_Hash ( const void *key); |
michael@0 | 105 | |
michael@0 | 106 | PRIntn PR_CALLBACK SECITEM_HashCompare ( const void *k1, const void *k2); |
michael@0 | 107 | |
michael@0 | 108 | extern SECItemArray *SECITEM_AllocArray(PLArenaPool *arena, |
michael@0 | 109 | SECItemArray *array, |
michael@0 | 110 | unsigned int len); |
michael@0 | 111 | extern SECItemArray *SECITEM_DupArray(PLArenaPool *arena, |
michael@0 | 112 | const SECItemArray *from); |
michael@0 | 113 | extern void SECITEM_FreeArray(SECItemArray *array, PRBool freeit); |
michael@0 | 114 | extern void SECITEM_ZfreeArray(SECItemArray *array, PRBool freeit); |
michael@0 | 115 | |
michael@0 | 116 | SEC_END_PROTOS |
michael@0 | 117 | |
michael@0 | 118 | #endif /* _SECITEM_H_ */ |