]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/src/tbl-free.c
Security-54.1.3.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-lib / src / tbl-free.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 #ifdef TTBL
20
21 /*
22 * tbl_free.c - frees data structs returned by type table driven decoder.
23 *
24 *
25 * Mike Sample
26 *
27 * Copyright (C) 1993 Michael Sample
28 * and the University of British Columbia
29 * This library is free software; you can redistribute it and/or
30 * modify it provided that this copyright/license information is retained
31 * in original form.
32 *
33 * If you modify this file, you must clearly indicate your changes.
34 *
35 * This source code is distributed in the hope that it will be
36 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
37 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 */
39
40
41 #include <stdio.h>
42 #include "tbl-incl.h"
43
44
45 void
46 TblFree PARAMS ((tbl, modName, typeName, v),
47 TBL *tbl _AND_
48 char *modName _AND_
49 char *typeName _AND_
50 AVal *v)
51 {
52 TBLModule *tblMod;
53 TBLTypeDef *tblTd;
54
55 tblTd = TblFindTypeDef (tbl, modName, typeName, &tblMod);
56 if (tblTd == NULL)
57 {
58 TblError ("TblFree: Could not find a type definition with the given module and name");
59 }
60
61 TblFreeType (tblTd->type, v);
62 } /* TblDecode p*/
63
64
65 void
66 TblFreeType PARAMS ((tblT, v),
67 TBLType *tblT _AND_
68 AVal *v)
69 {
70 AVal *elmtVPtr;
71 unsigned int currElmt;
72 TBLType *listElmtType;
73 TBLType *structElmtType;
74 TBLType *choiceElmtType;
75 AChoiceVal *cVal;
76 AStructVal *sVal;
77 AsnList *lVal;
78 void *tmp;
79
80
81 switch (tblT->typeId)
82 {
83 case TBL_TYPEREF:
84 TblFreeType (tblT->content->a.typeRef->typeDefPtr->type, v);
85 break;
86
87 case TBL_SEQUENCE:
88 case TBL_SET:
89 sVal = (AStructVal*)v;
90 currElmt = 0;
91 tmp = CURR_LIST_NODE (tblT->content->a.elmts);
92 FOR_EACH_LIST_ELMT (structElmtType, tblT->content->a.elmts)
93 {
94 if (!((structElmtType->optional) && (sVal[currElmt] == NULL)))
95 TblFreeType (structElmtType, sVal[currElmt]);
96 currElmt++;
97 }
98 SET_CURR_LIST_NODE (tblT->content->a.elmts, tmp);
99 Asn1Free (v);
100 break;
101
102
103 case TBL_SEQUENCEOF:
104 case TBL_SETOF:
105 listElmtType = FIRST_LIST_ELMT (tblT->content->a.elmts);
106 lVal = (AsnList*)v;
107 FOR_EACH_LIST_ELMT (elmtVPtr, lVal)
108 {
109 TblFreeType (listElmtType, elmtVPtr);
110 }
111 AsnListFree (lVal);
112 break;
113
114 case TBL_CHOICE:
115 cVal = (AChoiceVal*)v;
116 choiceElmtType = (TBLType*)GetAsnListElmt (tblT->content->a.elmts, cVal->choiceId);
117 TblFreeType (choiceElmtType, cVal->val);
118 Asn1Free (cVal);
119 break;
120
121 case TBL_BOOLEAN:
122 FreeAsnBool ((AsnBool*)v);
123 Asn1Free (v);
124 break;
125
126 case TBL_INTEGER:
127 case TBL_ENUMERATED:
128 FreeAsnInt ((AsnInt*)v);
129 Asn1Free (v);
130 break;
131
132 case TBL_BITSTRING:
133 FreeAsnBits ((AsnBits*)v);
134 Asn1Free (v);
135 break;
136
137 case TBL_OCTETSTRING:
138 FreeAsnOcts ((AsnOcts*)v);
139 Asn1Free (v);
140 break;
141
142 case TBL_NULL:
143 FreeAsnNull ((AsnNull*)v);
144 Asn1Free (v);
145 break;
146
147 case TBL_OID:
148 FreeAsnOid ((AsnOid*)v);
149 Asn1Free (v);
150 break;
151
152 case TBL_REAL:
153 FreeAsnReal ((AsnReal*)v);
154 Asn1Free (v);
155 break;
156
157 default:
158 break;
159 }
160
161 } /* TblFreeType */
162
163 #endif /* TTBL */