1 /*
2 (C) Copyright IBM Corp. 2007, 2009
3
4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7
8 You can obtain a current copy of the Eclipse Public License from
9 http://www.opensource.org/licenses/eclipse-1.0.php
10
11 @author : Endre Bak, IBM, ebak@de.ibm.com
12 *
13 * Change History
14 * Flag Date Prog Description
15 *-------------------------------------------------------------------------------
16 * 1804402 2007-09-28 ebak IPv6 ready SLP
17 * 1892103 2008-02-12 ebak SLP improvements
18 * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery
19 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
20 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
21 * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2)
22 */
23
24 package org.metricshub.wbem.sblim.slp.internal.msg;
25
26 /*-
27 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
28 * WBEM Java Client
29 * ჻჻჻჻჻჻
30 * Copyright 2023 - 2025 MetricsHub
31 * ჻჻჻჻჻჻
32 * Licensed under the Apache License, Version 2.0 (the "License");
33 * you may not use this file except in compliance with the License.
34 * You may obtain a copy of the License at
35 *
36 * http://www.apache.org/licenses/LICENSE-2.0
37 *
38 * Unless required by applicable law or agreed to in writing, software
39 * distributed under the License is distributed on an "AS IS" BASIS,
40 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41 * See the License for the specific language governing permissions and
42 * limitations under the License.
43 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
44 */
45
46 import java.io.IOException;
47 import java.util.Iterator;
48 import java.util.List;
49 import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute;
50 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
51 import org.metricshub.wbem.sblim.slp.internal.TRC;
52
53 /*
54 * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service
56 * Location header (function = AttrRply = 7) |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error
58 * Code | length of <attr-list> |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
60 * <attr-list> \
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of
62 * AttrAuths | Attribute Authentication Block (if present) \
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 *
65 */
66
67 /**
68 * AttributeReply message
69 *
70 */
71 public class AttributeReply extends ReplyMessage {
72 private List<ServiceLocationAttribute> iAttrList;
73
74 /**
75 * parse
76 *
77 * @param pHdr
78 * @param pInStr
79 * @return SLPMessage
80 * @throws ServiceLocationException
81 * @throws IOException
82 */
83 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
84 AttributeReply reply = new AttributeReply(pHdr, pInStr.read16(), pInStr.readAttributeList());
85 if (pInStr.readAuthBlockList() != null) TRC.warning("Non empty auth block!");
86 return reply;
87 }
88
89 /**
90 * Ctor.
91 *
92 * @param pErrorCode
93 * @param pAttrList
94 * - list of ServiceLocationAttributes
95 */
96 public AttributeReply(int pErrorCode, List<ServiceLocationAttribute> pAttrList) {
97 super(ATTR_RPLY, pErrorCode);
98 this.iAttrList = pAttrList;
99 }
100
101 /**
102 * Ctor.
103 *
104 * @param pLangTag
105 * @param pErrorCode
106 * @param pAttrList
107 * - list of ServiceLocationAttributes
108 */
109 public AttributeReply(String pLangTag, int pErrorCode, List<ServiceLocationAttribute> pAttrList) {
110 super(ATTR_RPLY, pLangTag, pErrorCode);
111 this.iAttrList = pAttrList;
112 }
113
114 /**
115 * Ctor.
116 *
117 * @param pHeader
118 * @param pErrorCode
119 * @param pAttrList
120 * - list of ServiceLocationAttributes
121 */
122 public AttributeReply(MsgHeader pHeader, int pErrorCode, List<ServiceLocationAttribute> pAttrList) {
123 super(pHeader, pErrorCode);
124 this.iAttrList = pAttrList;
125 }
126
127 @Override
128 public Iterator<ServiceLocationAttribute> getResultIterator() {
129 return this.iAttrList == null ? null : this.iAttrList.iterator();
130 }
131
132 /**
133 * @param pOption
134 */
135 @Override
136 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) {
137 return (
138 pOutStr.write16(getErrorCode()) && pOutStr.writeAttributeList(this.iAttrList) && pOutStr.writeAuthBlockList(null)
139 );
140 }
141
142 @Override
143 public Iterator<Exception> getExceptionIterator() {
144 // this message doesn't have exception table
145 return null;
146 }
147 }