1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Support routines for SECItemArray data structure.
15 #define NSSUTIL_VERSION_NUM \
16 (NSSUTIL_VMAJOR * 10000 + NSSUTIL_VMINOR * 100 + NSSUTIL_VPATCH)
17 #if NSSUTIL_VERSION_NUM < 31500
19 typedef struct SECItemArrayStr SECItemArray
;
21 struct SECItemArrayStr
{
28 SECITEM_AllocArray(PLArenaPool
*arena
, SECItemArray
*array
, unsigned int len
)
30 SECItemArray
*result
= NULL
;
34 mark
= PORT_ArenaMark(arena
);
39 result
= PORT_ArenaZAlloc(arena
, sizeof(SECItemArray
));
41 result
= PORT_ZAlloc(sizeof(SECItemArray
));
47 PORT_Assert(array
->items
== NULL
);
54 result
->items
= PORT_ArenaZNewArray(arena
, SECItem
, len
);
56 result
->items
= PORT_ZNewArray(SECItem
, len
);
58 if (result
->items
== NULL
) {
66 PORT_ArenaUnmark(arena
, mark
);
71 if ( arena
!= NULL
) {
73 PORT_ArenaRelease(arena
, mark
);
80 if (result
!= NULL
&& array
== NULL
) {
84 * If array is not NULL, the above has set array->data and
92 secitem_FreeArray(SECItemArray
*array
, PRBool zero_items
, PRBool freeit
)
96 if (!array
|| !array
->len
|| !array
->items
)
99 for (i
=0; i
<array
->len
; ++i
) {
100 SECItem
*item
= &array
->items
[i
];
104 SECITEM_ZfreeItem(item
, PR_FALSE
);
106 SECITEM_FreeItem(item
, PR_FALSE
);
110 PORT_Free(array
->items
);
118 void SECITEM_FreeArray(SECItemArray
*array
, PRBool freeit
)
120 secitem_FreeArray(array
, PR_FALSE
, freeit
);
123 void SECITEM_ZfreeArray(SECItemArray
*array
, PRBool freeit
)
125 secitem_FreeArray(array
, PR_TRUE
, freeit
);
129 SECITEM_DupArray(PLArenaPool
*arena
, const SECItemArray
*from
)
131 SECItemArray
*result
;
134 if (!from
|| !from
->items
|| !from
->len
)
137 result
= SECITEM_AllocArray(arena
, NULL
, from
->len
);
141 for (i
=0; i
<from
->len
; ++i
) {
142 SECStatus rv
= SECITEM_CopyItem(arena
,
143 &result
->items
[i
], &from
->items
[i
]);
144 if (rv
!= SECSuccess
) {
145 SECITEM_ZfreeArray(result
, PR_TRUE
);