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 org.metricshub.wbem.sblim.slp.ServiceLocationAttribute;
51 import org.metricshub.wbem.sblim.slp.ServiceLocationException;
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 = SAAdvert = 11) |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of
58 * URL | URL \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
59 * Length of <scope-list> | <scope-list> \
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Length of
61 * <attr-list> | <attr-list> \
62 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | # auth
63 * blocks | authentication block (if any) \
64 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 *
66 */
67
68 /**
69 * SAAdvert message
70 *
71 */
72 public class SAAdvert extends ReplyMessage {
73 private String iURLStr;
74
75 private List<String> iScopeList;
76
77 private List<ServiceLocationAttribute> iAttrList;
78
79 /**
80 * parse
81 *
82 * @param pHdr
83 * @param pInStr
84 * @return SLPMessage
85 * @throws ServiceLocationException
86 * @throws IOException
87 */
88 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException {
89 return new SAAdvert(pHdr, pInStr.readString(), pInStr.readStringList(), pInStr.readAttributeList());
90 }
91
92 /**
93 * Ctor.
94 *
95 * @param pURLStr
96 * @param pScopeList
97 * - list of scope strings
98 * @param pAttrList
99 * - list of ServiceLocationAttributes
100 */
101 public SAAdvert(String pURLStr, List<String> pScopeList, List<ServiceLocationAttribute> pAttrList) {
102 super(SA_ADVERT, 0);
103 init(pURLStr, pScopeList, pAttrList);
104 }
105
106 /**
107 * Ctor.
108 *
109 * @param pLangTag
110 * @param pURLStr
111 * @param pScopeList
112 * - list of scope strings
113 * @param pAttrList
114 * - list of ServiceLocationAttributes
115 */
116 public SAAdvert(String pLangTag, String pURLStr, List<String> pScopeList, List<ServiceLocationAttribute> pAttrList) {
117 super(SA_ADVERT, pLangTag, 0);
118 init(pURLStr, pScopeList, pAttrList);
119 }
120
121 /**
122 * Ctor.
123 *
124 * @param pHeader
125 * @param pURLStr
126 * @param pScopeList
127 * - list of scope strings
128 * @param pAttrList
129 * - list of ServiceLocationAttributes
130 */
131 public SAAdvert(
132 MsgHeader pHeader,
133 String pURLStr,
134 List<String> pScopeList,
135 List<ServiceLocationAttribute> pAttrList
136 ) {
137 super(pHeader, 0);
138 init(pURLStr, pScopeList, pAttrList);
139 }
140
141 @Override
142 public Iterator<String> getResultIterator() {
143 ArrayList<String> list = new ArrayList<String>();
144 list.add(this.iURLStr);
145 return list.iterator();
146 }
147
148 /**
149 * @param pOption
150 */
151 @Override
152 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) {
153 return (
154 pOutStr.write(this.iURLStr) &&
155 pOutStr.writeStringList(this.iScopeList) &&
156 pOutStr.writeAttributeList(this.iAttrList)
157 );
158 }
159
160 private void init(String pURLStr, List<String> pScopeList, List<ServiceLocationAttribute> pAttrList) {
161 this.iURLStr = pURLStr;
162 this.iScopeList = pScopeList;
163 this.iAttrList = pAttrList;
164 }
165
166 @Override
167 public Iterator<Exception> getExceptionIterator() {
168 // this message doesn't have exception table
169 return null;
170 }
171 }