(file) Return to PegasusSLPWrapper.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Client

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2