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.sentrysoftware.wbem.sblim.slp.internal.msg;
25
26 /*-
27 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
28 * WBEM Java Client
29 * ჻჻჻჻჻჻
30 * Copyright (C) 2023 Sentry Software
31 * ჻჻჻჻჻჻
32 * This program is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU Lesser General Public License as
34 * published by the Free Software Foundation, either version 3 of the
35 * License, or (at your option) any later version.
36 *
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Lesser Public License for more details.
41 *
42 * You should have received a copy of the GNU General Lesser Public
43 * License along with this program. If not, see
44 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
45 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
46 */
47
48 import java.io.IOException;
49 import java.util.Iterator;
50 import java.util.List;
51
52 import org.sentrysoftware.wbem.sblim.slp.ServiceLocationAttribute;
53 import org.sentrysoftware.wbem.sblim.slp.ServiceLocationException;
54 import org.sentrysoftware.wbem.sblim.slp.internal.TRC;
55
56 /*
57 * 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
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service
59 * Location header (function = AttrRply = 7) |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error
61 * Code | length of <attr-list> |
62 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
63 * <attr-list> \
64 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |# of
65 * AttrAuths | Attribute Authentication Block (if present) \
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 *
68 */
69
70 /**
71 * AttributeReply message
72 *
73 */
74 public class AttributeReply extends ReplyMessage {
75
76 private List<ServiceLocationAttribute> iAttrList;
77
78 /**
79 * parse
80 *
81 * @param pHdr
82 * @param pInStr
83 * @return SLPMessage
84 * @throws ServiceLocationException
85 * @throws IOException
86 */
87 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr)
88 throws ServiceLocationException, IOException {
89 AttributeReply reply = new AttributeReply(pHdr, pInStr.read16(), pInStr.readAttributeList());
90 if (pInStr.readAuthBlockList() != null) TRC.warning("Non empty auth block!");
91 return reply;
92 }
93
94 /**
95 * Ctor.
96 *
97 * @param pErrorCode
98 * @param pAttrList
99 * - list of ServiceLocationAttributes
100 */
101 public AttributeReply(int pErrorCode, List<ServiceLocationAttribute> pAttrList) {
102 super(ATTR_RPLY, pErrorCode);
103 this.iAttrList = pAttrList;
104 }
105
106 /**
107 * Ctor.
108 *
109 * @param pLangTag
110 * @param pErrorCode
111 * @param pAttrList
112 * - list of ServiceLocationAttributes
113 */
114 public AttributeReply(String pLangTag, int pErrorCode, List<ServiceLocationAttribute> pAttrList) {
115 super(ATTR_RPLY, pLangTag, pErrorCode);
116 this.iAttrList = pAttrList;
117 }
118
119 /**
120 * Ctor.
121 *
122 * @param pHeader
123 * @param pErrorCode
124 * @param pAttrList
125 * - list of ServiceLocationAttributes
126 */
127 public AttributeReply(MsgHeader pHeader, int pErrorCode,
128 List<ServiceLocationAttribute> pAttrList) {
129 super(pHeader, pErrorCode);
130 this.iAttrList = pAttrList;
131 }
132
133 @Override
134 public Iterator<ServiceLocationAttribute> getResultIterator() {
135 return this.iAttrList == null ? null : this.iAttrList.iterator();
136 }
137
138 /**
139 * @param pOption
140 */
141 @Override
142 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) {
143 return pOutStr.write16(getErrorCode()) && pOutStr.writeAttributeList(this.iAttrList)
144 && pOutStr.writeAuthBlockList(null);
145 }
146
147 @Override
148 public Iterator<Exception> getExceptionIterator() {
149 // this message doesn't have exception table
150 return null;
151 }
152
153 }