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.ArrayList;
48 import java.util.Iterator;
49 import java.util.List;
50 import java.util.TreeSet;
51 import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute;
52 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
53
54 /*
55 * 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
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service
57 * Location header (function = DAAdvert = 8) |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error
59 * Code | DA Stateless Boot Timestamp |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |DA
61 * Stateless Boot Time,, contd.| Length of URL |
62 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \ URL \
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of
64 * <scope-list> | <scope-list> \
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of
66 * <attr-list> | <attr-list> \
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of
68 * <SLP SPI List> | <SLP SPI List> String \
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # Auth
70 * Blocks | Authentication block (if any) \
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ FIXME: is
72 * this URL an URL-entry or an URL String. Assuming URL String.
73 */
74
75 /**
76 * DAAdvert message
77 *
78 */
79 public class DAAdvert extends ReplyMessage {
80 private long iStatelessBootTime;
81
82 private String iURLStr;
83
84 private List<String> iScopeList;
85
86 private List<ServiceLocationAttribute> iAttrList;
87
88 private List<String> iSPIList;
89
90 /**
91 * parse
92 *
93 * @param pHdr
94 * @param pInStr
95 * @return SLPMessage
96 * @throws ServiceLocationException
97 * @throws IOException
98 */
99 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
100 return new DAAdvert(
101 pHdr,
102 pInStr.read16(),
103 pInStr.read32(),
104 pInStr.readString(),
105 pInStr.readStringList(),
106 pInStr.readAttributeList(),
107 pInStr.readStringList()
108 );
109 }
110
111 /**
112 * Ctor.
113 *
114 * @param pErrorCode
115 * @param pStatelessBootTime
116 * @param pURLStr
117 * @param pScopeList
118 * - list of scope strings
119 * @param pAttrList
120 * - list of ServiceLocationAttributes
121 * @param pSPIList
122 */
123 public DAAdvert(
124 int pErrorCode,
125 long pStatelessBootTime,
126 String pURLStr,
127 List<String> pScopeList,
128 List<ServiceLocationAttribute> pAttrList,
129 List<String> pSPIList
130 ) {
131 super(DA_ADVERT, pErrorCode);
132 init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList);
133 }
134
135 /**
136 * Ctor.
137 *
138 * @param pLangTag
139 * @param pErrorCode
140 * @param pStatelessBootTime
141 * @param pURLStr
142 * @param pScopeList
143 * - list of scope strings
144 * @param pAttrList
145 * - list of ServiceLocationAttributes
146 * @param pSPIList
147 */
148 public DAAdvert(
149 String pLangTag,
150 int pErrorCode,
151 long pStatelessBootTime,
152 String pURLStr,
153 List<String> pScopeList,
154 List<ServiceLocationAttribute> pAttrList,
155 List<String> pSPIList
156 ) {
157 super(DA_ADVERT, pLangTag, pErrorCode);
158 init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList);
159 }
160
161 /**
162 * Ctor.
163 *
164 * @param pHeader
165 * @param pErrorCode
166 * @param pStatelessBootTime
167 * @param pURLStr
168 * @param pScopeList
169 * - list of scope strings
170 * @param pAttrList
171 * - list of ServiceLocationAttributes
172 * @param pSPIList
173 */
174 public DAAdvert(
175 MsgHeader pHeader,
176 int pErrorCode,
177 long pStatelessBootTime,
178 String pURLStr,
179 List<String> pScopeList,
180 List<ServiceLocationAttribute> pAttrList,
181 List<String> pSPIList
182 ) {
183 super(pHeader, pErrorCode);
184 init(pStatelessBootTime, pURLStr, pScopeList, pAttrList, pSPIList);
185 }
186
187 /**
188 * @return Iterator of DADescriptors
189 * @see ReplyMessage#getResultIterator()
190 */
191 @Override
192 public Iterator<DADescriptor> getResultIterator() {
193 ArrayList<DADescriptor> list = new ArrayList<DADescriptor>(1);
194 list.add(new DADescriptor(this.iURLStr, new TreeSet<String>(this.iScopeList), this.iAttrList));
195 return list.iterator();
196 }
197
198 /**
199 * @param pOption
200 */
201 @Override
202 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) {
203 return (
204 pOutStr.write16(getErrorCode()) &&
205 pOutStr.write32(this.iStatelessBootTime) &&
206 pOutStr.write(this.iURLStr) &&
207 pOutStr.writeStringList(this.iScopeList) &&
208 pOutStr.writeAttributeList(this.iAttrList) &&
209 pOutStr.writeStringList(this.iSPIList)
210 );
211 }
212
213 private void init(
214 long pStatelessBootTime,
215 String pURLStr,
216 List<String> pScopeList,
217 List<ServiceLocationAttribute> pAttrList,
218 List<String> pSPIList
219 ) {
220 this.iStatelessBootTime = pStatelessBootTime;
221 this.iURLStr = pURLStr;
222 this.iScopeList = pScopeList;
223 this.iAttrList = pAttrList;
224 this.iSPIList = pSPIList;
225 }
226
227 @Override
228 public Iterator<Exception> getExceptionIterator() {
229 // this message doesn't have exception table
230 return null;
231 }
232 }