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-15 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 java.util.SortedSet;
48 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
49 import org.metricshub.wbem.sblim.slp.ServiceType;
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 = SrvRqst = 1) |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
56 * <PRList> | <PRList> String \
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
58 * <service-type> | <service-type> String \
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
60 * <scope-list> | <scope-list> String \
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
62 * predicate string | Service Request <predicate> \
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length of
64 * <SLP SPI> string | <SLP SPI> String \
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 */
67
68 /*
69 * The <SLP SPI> string indicates a SLP SPI that the requester has been
70 * configured with. If this string is omitted, the responder does not include
71 * any Authentication Blocks in its reply. If it is included, the responder MUST
72 * return a reply which has an associated authentication block with the SLP SPI
73 * in the SrvRqst. If no replies may be returned because the SLP SPI is not
74 * supported, the responder returns an AUTHENTICATION_UNKNOWN error.
75 */
76
77 /**
78 * ServiceRequest message
79 *
80 */
81 public class ServiceRequest extends RequestMessage {
82 private ServiceType iServiceType;
83
84 private String iPredicate, iSlpSpi;
85
86 private static final int[] ALLOWED_RSPS = { SRV_RPLY, DA_ADVERT, SA_ADVERT };
87
88 /**
89 * parse
90 *
91 * @param pHdr
92 * @param pInStr
93 * @return SLPMessage
94 * @throws ServiceLocationException
95 * @throws IOException
96 */
97 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
98 return new ServiceRequest(
99 pHdr,
100 pInStr.readStringSet(), // prevResponders
101 pInStr.readServiceType(), // serviceType
102 pInStr.readStringList(), // scopeList
103 pInStr.readString(), // predicate
104 pInStr.readString() // SlpSpi
105 );
106 }
107
108 /**
109 * Ctor.
110 *
111 * @param pLangTag
112 * @param pPrevResponderSet
113 * - set of address strings
114 * @param pServiceType
115 * @param pScopeList
116 * - list of scope strings
117 * @param pPredicate
118 * @param pSlpSpi
119 */
120 public ServiceRequest(
121 String pLangTag,
122 SortedSet<String> pPrevResponderSet,
123 ServiceType pServiceType,
124 List<String> pScopeList,
125 String pPredicate,
126 String pSlpSpi
127 ) {
128 super(SRV_RQST, pLangTag, pPrevResponderSet, pScopeList);
129 init(pServiceType, pPredicate, pSlpSpi);
130 }
131
132 /**
133 * Ctor.
134 *
135 * @param pPrevResponderSet
136 * - set of address strings
137 * @param pServiceType
138 * @param pScopeList
139 * - list of scope strings
140 * @param pPredicate
141 * @param pSlpSpi
142 */
143 public ServiceRequest(
144 SortedSet<String> pPrevResponderSet,
145 ServiceType pServiceType,
146 List<String> pScopeList,
147 String pPredicate,
148 String pSlpSpi
149 ) {
150 super(SRV_RQST, pPrevResponderSet, pScopeList);
151 init(pServiceType, pPredicate, pSlpSpi);
152 }
153
154 /**
155 * @param pHeader
156 * @param pPrevResponderSet
157 * - set of address strings
158 * @param pServiceType
159 * @param pScopeList
160 * - list of scope strings
161 * @param pPredicate
162 * - LDAPv3 search filter
163 * @param pSlpSpi
164 */
165 public ServiceRequest(
166 MsgHeader pHeader,
167 SortedSet<String> pPrevResponderSet,
168 ServiceType pServiceType,
169 List<String> pScopeList,
170 String pPredicate,
171 String pSlpSpi
172 ) {
173 super(pHeader, pPrevResponderSet, pScopeList);
174 init(pServiceType, pPredicate, pSlpSpi);
175 }
176
177 /**
178 * getServiceType
179 *
180 * @return ServiceType
181 */
182 public ServiceType getServiceType() {
183 return this.iServiceType;
184 }
185
186 @Override
187 protected boolean serializeRequestBody(SLPOutputStream pOutStr) {
188 return (
189 pOutStr.write(this.iServiceType) &&
190 pOutStr.writeStringList(getScopeList()) &&
191 pOutStr.write(this.iPredicate) &&
192 pOutStr.write(this.iSlpSpi)
193 );
194 }
195
196 @Override
197 protected int[] getAllowedResponseIDs() {
198 return ALLOWED_RSPS;
199 }
200
201 private void init(ServiceType pServiceType, String pPredicate, String pSlpSpi) {
202 this.iServiceType = pServiceType;
203 this.iPredicate = pPredicate;
204 this.iSlpSpi = pSlpSpi;
205 }
206 }