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 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
19 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
20 * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2)
21 */
22
23 package org.metricshub.wbem.sblim.slp.internal.msg;
24
25 /*-
26 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
27 * WBEM Java Client
28 * ჻჻჻჻჻჻
29 * Copyright 2023 - 2025 MetricsHub
30 * ჻჻჻჻჻჻
31 * Licensed under the Apache License, Version 2.0 (the "License");
32 * you may not use this file except in compliance with the License.
33 * You may obtain a copy of the License at
34 *
35 * http://www.apache.org/licenses/LICENSE-2.0
36 *
37 * Unless required by applicable law or agreed to in writing, software
38 * distributed under the License is distributed on an "AS IS" BASIS,
39 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40 * See the License for the specific language governing permissions and
41 * limitations under the License.
42 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
43 */
44
45 import java.io.IOException;
46 import java.util.List;
47 import org.metricshub.wbem.sblim.slp.ServiceLocationAttribute;
48 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
49 import org.metricshub.wbem.sblim.slp.ServiceURL;
50
51 /*
52 * 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
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service
54 * Location header (function = SrvReg = 3) |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
56 * <URL-Entry> \
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
58 * service type string | <service-type> \
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
60 * <scope-list> | <scope-list> \
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
62 * attr-list string | <attr-list> \
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of
64 * AttrAuths |(if present) Attribute Authentication Blocks...\
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 */
67 /**
68 * ServiceRegistration message
69 *
70 */
71 public class ServiceRegistration extends SLPMessage {
72 private ServiceURL iServURL;
73
74 private List<String> iScopeList;
75
76 private List<ServiceLocationAttribute> iAttrList;
77
78 private List<?> iAuthBlockList;
79
80 /**
81 * parse
82 *
83 * @param pHdr
84 * @param pInStr
85 * @return SLPMessage
86 * @throws ServiceLocationException
87 * @throws IOException
88 */
89 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
90 ServiceURL url = pInStr.readURL();
91 pInStr.readServiceType(); // FIXME reading dummy SrvType. Correct?
92 return new ServiceRegistration(
93 pHdr,
94 url,
95 pInStr.readStringList(),
96 pInStr.readAttributeList(),
97 pInStr.readAuthBlockList()
98 );
99 }
100
101 /**
102 * Ctor.
103 *
104 * @param pServURL
105 * @param pScopeList
106 * - list of scope strings
107 * @param pAttrList
108 * - list of ServiceLocationAttributes
109 * @param pAuthBlockList
110 */
111 public ServiceRegistration(
112 ServiceURL pServURL,
113 List<String> pScopeList,
114 List<ServiceLocationAttribute> pAttrList,
115 List<?> pAuthBlockList
116 ) {
117 super(SRV_REG);
118 init(pServURL, pScopeList, pAttrList, pAuthBlockList);
119 }
120
121 /**
122 * Ctor.
123 *
124 * @param pLangTag
125 * @param pServURL
126 * @param pScopeList
127 * - list of scope strings
128 * @param pAttrList
129 * - list of ServiceLocationAttributes
130 * @param pAuthBlockList
131 */
132 public ServiceRegistration(
133 String pLangTag,
134 ServiceURL pServURL,
135 List<String> pScopeList,
136 List<ServiceLocationAttribute> pAttrList,
137 List<?> pAuthBlockList
138 ) {
139 super(SRV_REG, pLangTag);
140 init(pServURL, pScopeList, pAttrList, pAuthBlockList);
141 }
142
143 /**
144 * Ctor.
145 *
146 * @param pHeader
147 * @param pServURL
148 * @param pScopeList
149 * - list of scope strings
150 * @param pAttrList
151 * - list of ServiceLocationAttributes
152 * @param pAuthBlockList
153 */
154 public ServiceRegistration(
155 MsgHeader pHeader,
156 ServiceURL pServURL,
157 List<String> pScopeList,
158 List<ServiceLocationAttribute> pAttrList,
159 List<?> pAuthBlockList
160 ) {
161 super(pHeader);
162 init(pServURL, pScopeList, pAttrList, pAuthBlockList);
163 }
164
165 /**
166 * getServiceURL
167 *
168 * @return ServiceURL
169 */
170 public ServiceURL getServiceURL() {
171 return this.iServURL;
172 }
173
174 /**
175 * getScopeList
176 *
177 * @return List
178 */
179 public List<String> getScopeList() {
180 return this.iScopeList;
181 }
182
183 /**
184 * getAttributeList
185 *
186 * @return List
187 */
188 public List<ServiceLocationAttribute> getAttributeList() {
189 return this.iAttrList;
190 }
191
192 /**
193 * @param pOption
194 */
195 @Override
196 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) {
197 return (
198 pOutStr.write(this.iServURL) &&
199 pOutStr.write(this.iServURL.getServiceType()) &&
200 pOutStr.writeStringList(this.iScopeList) &&
201 pOutStr.writeAttributeList(this.iAttrList) &&
202 pOutStr.writeAuthBlockList(this.iAuthBlockList)
203 );
204 }
205
206 private void init(
207 ServiceURL pServURL,
208 List<String> pScopeList,
209 List<ServiceLocationAttribute> pAttrList,
210 List<?> pAuthBlockList
211 ) {
212 this.iServURL = pServURL;
213 this.iScopeList = pScopeList;
214 this.iAttrList = pAttrList;
215 this.iAuthBlockList = pAuthBlockList;
216 }
217 }