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