1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 package uk.co.westhawk.snmp.stack;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 import java.io.*;
67 import java.util.*;
68
69
70
71
72
73
74
75
76
77 class AsnSequence extends AsnObject {
78 private static final String version_id = "@(#)$Id: AsnSequence.java,v 3.15 2006/11/29 16:35:29 birgit Exp $ Copyright Westhawk Ltd";
79
80 private Vector children;
81
82
83
84
85 AsnSequence() {
86 this(CONS_SEQ);
87 }
88
89
90
91
92 AsnSequence(byte oddtype) {
93 type = oddtype;
94 children = new Vector(1, 1);
95 }
96
97
98
99
100
101
102 AsnSequence(InputStream in, int len, int pos) throws IOException {
103 this();
104 if (debug > 10) {
105 System.out.println("AsnSequence(): Length = " + len
106 + ", Pos = " + pos);
107 }
108 AsnObject a = null;
109 while (true) {
110 a = AsnReadHeader(in, pos);
111 if (a != null) {
112 pos += (a.headerLength + a.contentsLength);
113 add(a);
114 } else {
115 break;
116 }
117 }
118 }
119
120
121
122
123
124
125 public String toString() {
126 return "";
127 }
128
129
130
131
132 AsnObject add(AsnObject child) {
133 if (child.isCorrect == true) {
134 children.addElement(child);
135 }
136 return child;
137 }
138
139
140
141
142
143 AsnObject replaceChild(AsnObject oldChild, AsnObject newChild) {
144 AsnObject ret = oldChild;
145 int at = children.indexOf(oldChild);
146 if (at > -1) {
147 children.setElementAt(newChild, at);
148 ret = newChild;
149 }
150 return ret;
151 }
152
153
154
155
156 int size() throws EncodingException {
157 Enumeration childList = children.elements();
158 int cnt, sz = 0;
159
160 while (childList.hasMoreElements()) {
161
162 cnt = ((AsnObject) childList.nextElement()).size();
163
164
165 cnt += (1 + getLengthBytes(cnt));
166 sz += cnt;
167 }
168 return sz;
169 }
170
171 void write(OutputStream out)
172 throws IOException, EncodingException {
173 write(out, 0);
174 }
175
176 void write(OutputStream out, int pos)
177 throws IOException, EncodingException {
178
179 int length = size();
180 startPos = pos;
181 AsnBuildHeader(out, type, length);
182 if (debug > 10) {
183 System.out.println("\tAsnSequence.write(): begin, startPos = "
184 + startPos);
185 }
186
187
188 pos += headerLength;
189 Enumeration childList = children.elements();
190 while (childList.hasMoreElements()) {
191 AsnObject child = ((AsnObject) childList.nextElement());
192 child.write(out, pos);
193 child.startPos = pos;
194 pos += child.headerLength + child.contentsLength;
195 }
196
197 if (debug > 10) {
198 System.out.println("\tAsnSequence.write(): end");
199 }
200 }
201
202
203
204
205 AsnObject findPdu() {
206 AsnObject res = null;
207
208 Enumeration childList = children.elements();
209 while (childList.hasMoreElements()) {
210 AsnObject child = ((AsnObject) childList.nextElement());
211 res = child.findPdu();
212 if (res != null) {
213 break;
214 }
215 }
216
217 if (this.isCorrect == false && res != null) {
218 res.isCorrect = false;
219 }
220 return res;
221 }
222
223
224
225
226 AsnObject findTrapPduv1() {
227 AsnObject res = null;
228
229 Enumeration childList = children.elements();
230 while (childList.hasMoreElements()) {
231 AsnObject child = ((AsnObject) childList.nextElement());
232 res = child.findTrapPduv1();
233 if (res != null) {
234 break;
235 }
236 }
237 if (this.isCorrect == false && res != null) {
238 res.isCorrect = false;
239 }
240 return res;
241 }
242
243 AsnObject getObj(int offset) {
244 AsnObject res = new AsnNull();
245 try {
246 res = (AsnObject) children.elementAt(offset);
247 } catch (ArrayIndexOutOfBoundsException exc) {
248 }
249 return res;
250 }
251
252 int getObjCount() {
253 return children.size();
254 }
255
256 }