1 karl 1.7 //%2005////////////////////////////////////////////////////////////////////////
|
2 tony 1.1 //
|
3 karl 1.5 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 tony 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.5 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 tony 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Tony Fiorentino (fiorentino_tony@emc.com)
31 //
|
32 david.dillard 1.4 // Modified By: Stuart Naisbitt (stuartn@veritas.com)
33 // David Dillard (david.dillard@veritas.com)
|
34 tony 1.1 //
35 //%/////////////////////////////////////////////////////////////////////////////
36
37 #include "PegasusSLPWrapper.h"
38
39 PEGASUS_NAMESPACE_BEGIN
40
|
41 tony 1.2 static void
42 _extractAttributes(const String &attrList,
43 Array<Attribute> &attrArray)
44 {
45 Uint32 posAttrKey=0, posEqual=0;
46
47 posAttrKey = attrList.find(PEG_SLP_ATTR_BEGIN);
48 while (posAttrKey != PEG_NOT_FOUND && (posAttrKey+1) < attrList.size())
49 {
50 posEqual = attrList.find(posEqual+1, PEG_SLP_ATTR_END);
51 String attrKey(attrList.subString((posAttrKey+1), (posEqual-posAttrKey-1)));
52
53 attrArray.append(Attribute(attrKey));
54
55 // ATTN: skip over anything in value that is a '(', '=', ')', or ','?
56 posAttrKey = attrList.find(posAttrKey+1, PEG_SLP_ATTR_BEGIN);
57 }
58 }
59
|
60 tony 1.1 CIMServerDiscoveryRep::CIMServerDiscoveryRep()
61 {
62 }
63
64 CIMServerDiscoveryRep::~CIMServerDiscoveryRep()
65 {
66 }
67
|
68 david.dillard 1.4 /*
69 * PegasusSLP supports return of attributes piggybacked on the srvReply,
70 * other implementations may not
71 */
72 static BOOL
73 _lookup_attrs(const String &save_url, Array<Attribute>& attribs,const SLPClientOptions* options)
74 {
75 struct slp_client *client = NULL;
76 lslpMsg responses, *attrReplyEntry;
77
|
78 david.dillard 1.8 const char *scopes;
79 const char *spi;
80 char *iface;
81 char *addr;
82 const char *type;
83 const char *predicate;
|
84 david.dillard 1.4 int16 port;
85 BOOL dir_agent;
86
|
87 david.dillard 1.8 char* tags = (char*)NULL;
|
88 david.dillard 1.4 int16 converge=(int16)0;
89 if(0==save_url.size()){
90 /* Pilot error */
91 return FALSE;
92 }
93
94 char* url=strdup((const char*)save_url.getCString());
95 if (url == NULL)
96 {
97 return FALSE;
98 }
99
100 if((SLPClientOptions*)NULL == options){
101 addr = NULL;
102 iface = NULL;
103 port = 427;
104 scopes = "DEFAULT";
105 spi="DSA";
106 type = "service:wbem";
107 predicate = NULL;
108 dir_agent = FALSE;
109 david.dillard 1.4 }else{
110 scopes = (char*)options->scopes;
111 spi = (char*)options->spi;
112 iface = options->local_interface;
113 addr = options->target_address;
114 type = options->service_type;
115 predicate = options->predicate;
116 port = options->target_port;
117 dir_agent = options->use_directory_agent==true?1:0;
118 }
119 /* largely cut-and-paste from slp_attrreq.cpp
120 * with gratuitous reformatting
121 */
122 if(NULL != (client = create_slp_client(
123 addr,
124 iface,
125 port,
126 spi,
127 scopes,
128 FALSE,
129 dir_agent))) {
130 david.dillard 1.4 if(addr != NULL && inet_addr(addr) == inet_addr("127.0.0.1")) {
131 client->local_attr_req(client, url, scopes, tags);
132 } else if(converge) {
133 client->_convergence = converge ;
134 client->converge_attr_req(client, url, scopes, tags);
135 } else {
136 SOCKADDR_IN address;
137 address.sin_port = htons(port);
138 address.sin_family = AF_INET;
139 if(addr != NULL) {
140 address.sin_addr.s_addr = inet_addr(addr);
141 client->unicast_attr_req(client, url, scopes, tags, &address);
142 }else {
143 address.sin_addr.s_addr = _LSLP_MCAST;
144 client->converge_attr_req(client, url, scopes, tags);
145 }
146 } /* end of request */
147
148 responses.isHead = TRUE;
149 responses.next = responses.prev = &responses;
150
151 david.dillard 1.4 client->get_response(client, &responses);
152 while( ! _LSLP_IS_EMPTY(&responses) ) {
153 attrReplyEntry = responses.next;
154 if(attrReplyEntry->type == attrRep) {
155 if( attrReplyEntry->msg.attrRep.attrListLen > 0) {
156 String attrString = attrReplyEntry->msg.attrRep.attrList;
157 _extractAttributes(attrString,attribs);
158 }
159
160 }/* if we got an attr rply */
161 _LSLP_UNLINK(attrReplyEntry);
162 lslpDestroySLPMsg(attrReplyEntry, LSLP_DESTRUCTOR_DYNAMIC);
163 } /* while traversing response list */
164
165 destroy_slp_client(client);
166
167 } /* client successfully created */
168
169 free(url);
170 return TRUE;
171 }/*static BOOL _lookup_attrs()*/
172 david.dillard 1.4
|
173 tony 1.1 Array<CIMServerDescription>
|
174 karl 1.3 CIMServerDiscoveryRep::lookup(const Array<Attribute> & criteria, const SLPClientOptions* options)
|
175 tony 1.1 {
176 struct slp_client *client = NULL;
177 lslpMsg responses, *srvReplyEntry;
178
|
179 david.dillard 1.8 const char *scopes; // = strdup("DEFAULT");
180 const char *spi; // = strdup("DSA");
181 char *iface; // = NULL;
182 char *addr; // = NULL;
183 const char *type; // = strdup("service:wbem");
184 const char *predicate; // = NULL;
|
185 karl 1.3 int16 port; // = 427;
186 BOOL dir_agent; // = FALSE;
187
188 if((SLPClientOptions*)NULL == options){
|
189 david.dillard 1.4 addr = NULL;
190 iface = NULL;
191 port = 427;
192 scopes = "DEFAULT";
193 spi="DSA";
194 type = "service:wbem";
195 predicate = NULL;
196 dir_agent = FALSE;
|
197 karl 1.3 }else{
|
198 david.dillard 1.4 scopes = (char*)options->scopes;
199 spi = (char*)options->spi;
200 iface = options->local_interface;
201 addr = options->target_address;
202 type = options->service_type;
203 predicate = options->predicate;
204 port = options->target_port;
205 dir_agent = options->use_directory_agent==true?1:0;
206 options->print();
207
|
208 karl 1.3 }
|
209 tony 1.2 Array<CIMServerDescription> connections;
210
|
211 karl 1.3 if (NULL != (client = create_slp_client(
|
212 david.dillard 1.4 addr, // target_addr
213 iface, // local_interface
214 port, // target_port
215 spi, // spi
216 scopes, // scopes
217 FALSE, // should_listen
218 dir_agent // use_das
219 )))
|
220 tony 1.1 {
221 if (addr != NULL && inet_addr(addr) == inet_addr("127.0.0.1"))
222 {
223 client->local_srv_req(client, type, predicate, scopes);
224 }
225 else
226 {
227 SOCKADDR_IN address;
228 address.sin_port = htons(port);
229 address.sin_family = AF_INET;
|
230 karl 1.3 if (addr != NULL){
|
231 tony 1.1 address.sin_addr.s_addr = inet_addr(addr);
|
232 david.dillard 1.4 }else{
|
233 tony 1.1 address.sin_addr.s_addr = _LSLP_MCAST;
|
234 david.dillard 1.4 }
|
235 tony 1.1 client->unicast_srv_req(client, type, predicate, scopes, &address);
236 }
237
238 responses.isHead = TRUE;
239 responses.next = responses.prev = &responses;
240
241 client->get_response(client, &responses);
242 while(!_LSLP_IS_EMPTY(&responses))
|
243 david.dillard 1.4 {
|
244 tony 1.1 srvReplyEntry = responses.next;
245 if (srvReplyEntry->type == srvRply)
246 {
247 lslpURL *url_list;
248 if (srvReplyEntry != NULL && srvReplyEntry->type == srvRply)
249 {
250 if ((NULL != srvReplyEntry->msg.srvRply.urlList) &&
251 (!_LSLP_IS_EMPTY( srvReplyEntry->msg.srvRply.urlList)))
252 {
253 url_list = srvReplyEntry->msg.srvRply.urlList->next;
254 while(!_LSLP_IS_HEAD(url_list))
255 {
256 /* check for urls */
257 if (NULL != url_list->url)
258 {
259 CIMServerDescription connection(url_list->url);
260
261 Array<Attribute> attributes;
|
262 david.dillard 1.4
|
263 tony 1.1 /* check for attributes */
|
264 david.dillard 1.4 /* PegasusSLP reurns attributes with srvReply
265 * per RFC 3059. Other implementations do not.
266 */
|
267 tony 1.1 if (NULL != url_list->attrs && !_LSLP_IS_HEAD(url_list->attrs->next))
268 {
269 lslpAtomList *attrs = url_list->attrs->next;
270 while(!_LSLP_IS_HEAD(attrs))
271 {
|
272 tony 1.2 _extractAttributes(String(attrs->str), attributes);
|
273 tony 1.1 attrs = attrs->next;
274 }
|
275 david.dillard 1.4 }/*if attrs*/
276 /* add to connections array */
277 /* VRTS - interop. Add unconditionally.
278 * Not initialised in contsructor */
279 connection.setAttributes(attributes);
280 connections.append(connection);
281 }/*if url*/
282 url_list = url_list->next;
283 }/*while we have urls*/
284 }/*if urlList*/
285 }/*if srvReply*/
286 }/*if type==srvReply*/
287 _LSLP_UNLINK(srvReplyEntry);
288 lslpDestroySLPMsg(srvReplyEntry, LSLP_DESTRUCTOR_DYNAMIC);
289 }/*while*/
290 destroy_slp_client(client);
291 }
|
292 tony 1.2
|
293 david.dillard 1.4 /* If no attributes were present, then the attributes array
294 * has zero size. Rescan the connections and create a fresh slp_client to
295 * get the attributes, if none present
296 */
297 if(0==connections.size()){
298 return connections;
299 }
300 for(int i=0; i< connections.size();i++){
301 Array<Attribute> attrs = connections[i].getAttributes();
302 if(0==attrs.size()){
303 String url=connections[i].getUrl();
304 if(TRUE==_lookup_attrs(url,attrs,options)){
305 connections[i].setAttributes(attrs);
|
306 tony 1.1 }
307 }
308 }
309
|
310 tony 1.2 return connections;
|
311 tony 1.1 }
312
313 PEGASUS_NAMESPACE_END
|