Exemple #1
0
int main(int argc, char **argv)
{
#ifdef PEGASUS_ENABLE_IPV6
    struct in6_addr ip6_loop = PEGASUS_IPV6_LOOPBACK_INIT;
    struct in6_addr ip6_addr;
#endif
    struct slp_client *client;
    lslpMsg responses, *temp;

    if (FALSE == get_options(argc, argv))
    {
        usage();
    }
    else
    {
        if (scopes == NULL)
        {
            scopes = strdup("DEFAULT");
        }
        if (test == TRUE)
        {
            return test_query(type, predicate, scopes);
        }
        if(NULL != (client = create_slp_client(
            addr,
            _interface,
            port,
            "DSA",
            scopes,
            FALSE,
            dir_agent,
            type)))
        {
            if (slp_is_loop_back_addr(addr))
            {
                client->local_srv_req(client, type, predicate, scopes);
            }
            else if (converge)
            {
                client->_convergence = converge ;
                client->converge_srv_req(client, type, predicate, scopes);
            }
            else
            {
                if (!addr)
                {
                    client->converge_srv_req(client, type, predicate, scopes);
                }
                else
                {
#ifdef PEGASUS_ENABLE_IPV6
                    SOCKADDR_IN6 ip6;
#endif
                    SOCKADDR_IN ip4;
                    void *target = 0;

                    if (slp_is_valid_ip4_addr(addr))
                    {
                        ip4.sin_port = htons(port);
                        ip4.sin_family = AF_INET;
                        ip4.sin_addr.s_addr = inet_addr(addr);
                        target = &ip4;
                    }
#ifdef PEGASUS_ENABLE_IPV6
                    else
                    {
                        memset(&ip6, 0, sizeof(ip6));
                        ip6.sin6_port = htons(port);
                        ip6.sin6_family = AF_INET6;
                        slp_pton(AF_INET6, addr, &ip6.sin6_addr);
                        target = &ip6;
                    }
#endif
                    if(target)
                    {
                        client->unicast_srv_req(
                            client,
                            type,
                            predicate,
                            scopes,
                            (SOCKADDR*)target);
                    }
                }
            }

            responses.isHead = TRUE;
            responses.next = responses.prev = &responses;

            client->get_response(client, &responses);
            while (! _LSLP_IS_EMPTY(&responses))
            {
                temp = responses.next;
                if (temp->type == srvRply)
                {
                    if (parsable == TRUE)
                    {
                        lslp_print_srv_rply_parse(temp, fs, rs);
                    }
                    else
                    {
                        lslp_print_srv_rply(temp);
                    }
                }
                _LSLP_UNLINK(temp);
                lslpDestroySLPMsg(temp, LSLP_DESTRUCTOR_DYNAMIC);
            }
            destroy_slp_client(client);
        }
    }

    free_globals();
    return 1;
}
/*
 * PegasusSLP supports return of attributes piggybacked on the srvReply,
 * other implementations may not
 */
static BOOL
_lookup_attrs(const String &save_url, Array<Attribute>& attribs,const SLPClientOptions* options)
{
    struct slp_client *client = NULL;
    lslpMsg responses, *attrReplyEntry;
    
    const char *scopes;
    const char *spi;
    char *iface;
    char *addr;
    const char *type;
    const char *predicate;
    int16 port;
    BOOL dir_agent;
    
    char* tags = (char*)NULL;
    int16 converge=(int16)0;
    if(0==save_url.size()){
        /* Pilot error */
        return FALSE;
    }

    char* url=strdup((const char*)save_url.getCString());
    if (url == NULL)
    {
        return FALSE;
    }

    if((SLPClientOptions*)NULL == options){
        addr = NULL;
        iface = NULL;
        port = 427;
        scopes = "DEFAULT";
        spi="DSA";
        type = "service:wbem";
        predicate = NULL;
        dir_agent = FALSE;
    }else{
        scopes = (char*)options->scopes;
        spi = (char*)options->spi;
        iface = options->local_interface;
        addr = options->target_address;
        type = options->service_type;
        predicate = options->predicate;
        port = options->target_port;
        dir_agent = options->use_directory_agent==true?1:0;
    }
    /* largely cut-and-paste from slp_attrreq.cpp
     * with gratuitous reformatting
     */
    if(NULL != (client = create_slp_client(
                    addr,
                    iface,
                    port,
                    spi,
                    scopes,
                    FALSE, 
                    dir_agent))) {
        if(addr != NULL && inet_addr(addr) == inet_addr("127.0.0.1")) {
            client->local_attr_req(client, url, scopes, tags);
        } else if(converge) {
            client->_convergence = converge ;
            client->converge_attr_req(client, url, scopes, tags);
        } else {
            SOCKADDR_IN address;
            address.sin_port = htons(port);
            address.sin_family = AF_INET;
            if(addr != NULL) {
                address.sin_addr.s_addr = inet_addr(addr);
                client->unicast_attr_req(client, url, scopes, tags, &address);
            }else {
                address.sin_addr.s_addr = _LSLP_MCAST;
                client->converge_attr_req(client, url, scopes, tags);
            }
        } /* end of request  */

        responses.isHead = TRUE;
        responses.next = responses.prev = &responses;

        client->get_response(client, &responses);
        while( ! _LSLP_IS_EMPTY(&responses) ) {
            attrReplyEntry = responses.next;
            if(attrReplyEntry->type == attrRep) {
                if( attrReplyEntry->msg.attrRep.attrListLen > 0) {
                    String attrString = attrReplyEntry->msg.attrRep.attrList;
                    _extractAttributes(attrString,attribs);
                }
                
            }/* if we got an attr rply */ 
            _LSLP_UNLINK(attrReplyEntry);
            lslpDestroySLPMsg(attrReplyEntry, LSLP_DESTRUCTOR_DYNAMIC);
        } /* while traversing response list */ 

        destroy_slp_client(client);

     } /* client successfully created */ 

    free(url);
    return TRUE;
}/*static BOOL _lookup_attrs()*/
Exemple #3
0
int main(int argc, char **argv)
{
    struct slp_client *client;
    lslpMsg responses, *temp;

    if (FALSE == get_options(argc, argv))
    {
        usage();
        return 0;
    }
    else
    {
        if (scopes == NULL)
        scopes = strdup("DEFAULT");

        if (NULL != (client = create_slp_client(
            addr,
            _interface,
            port,
            "DSA",
            scopes,
            FALSE,
            dir_agent,
            0)))
        {
            if (slp_is_loop_back_addr(addr))
            {
                client->local_attr_req(client, url, scopes, tags);
            }
            else if (converge)
            {
                client->_convergence = converge ;
                client->converge_attr_req(client, url, scopes, tags);
            }
            else
            {
                if (!addr)
                {
                    client->converge_attr_req(client, url, scopes, tags);
                }
                else
                {
#ifdef PEGASUS_ENABLE_IPV6
                    SOCKADDR_IN6 ip6;
#endif
                    SOCKADDR_IN ip4;
                    void *target = 0;

                    if (slp_is_valid_ip4_addr(addr))
                    {
                        ip4.sin_port = htons(port);
                        ip4.sin_family = AF_INET;
                        ip4.sin_addr.s_addr = inet_addr(addr);
                        target = &ip4;
                    }
#ifdef PEGASUS_ENABLE_IPV6
                    else
                    {
                        memset(&ip6, 0, sizeof(ip6));
                        ip6.sin6_port = htons(port);
                        ip6.sin6_family = AF_INET6;
                        slp_pton(AF_INET6, addr, &ip6.sin6_addr);
                        target = &ip6;
                    }
#endif
                    if(target)
                    {
                        client->unicast_attr_req(
                            client,
                            url,
                            scopes,
                            tags,
                            (SOCKADDR*)target);
                    }
                }
            }

            responses.isHead = TRUE;
            responses.next = responses.prev = &responses;

            client->get_response(client, &responses);
            while ( ! _LSLP_IS_EMPTY(&responses) )
            {
                temp = responses.next;
                if (temp->type == attrRep)
                {
                    if(parsable == TRUE && temp->msg.attrRep.attrListLen > 0)
                    {
                        lslp_print_attr_rply_parse(temp, fs, rs);
                    }
                    else
                    {
                        if( temp->msg.attrRep.attrListLen > 0)
                        {
                            printf("Attr. Reply for %s\n", url);
                            lslp_print_attr_rply(temp);
                        }
                    }
                }/* if we got an attr rply */
                _LSLP_UNLINK(temp);
                lslpDestroySLPMsg(temp, LSLP_DESTRUCTOR_DYNAMIC);

            } /* while traversing response list */
            destroy_slp_client(client);

        } /* client successfully created */
    }
    free_globals();
    return 1 ;
}
Array<CIMServerDescription>
CIMServerDiscoveryRep::lookup(const Array<Attribute> & criteria, const SLPClientOptions* options)
{
  struct slp_client *client = NULL;
  lslpMsg responses, *srvReplyEntry;
  
  const char *scopes; // = strdup("DEFAULT");
  const char *spi; // = strdup("DSA");
  char *iface; // = NULL;
  char *addr; // = NULL;
  const char *type; // = strdup("service:wbem");
  const char *predicate; // = NULL;
  int16 port; // = 427;
  BOOL dir_agent; // = FALSE;
 
  if((SLPClientOptions*)NULL == options){
      addr = NULL;
      iface = NULL;
      port = 427;
      scopes = "DEFAULT";
      spi="DSA";
      type = "service:wbem";
      predicate = NULL;
      dir_agent = FALSE;
  }else{
      scopes = (char*)options->scopes;
      spi = (char*)options->spi;
      iface = options->local_interface;
      addr = options->target_address;
      type = options->service_type;
      predicate = options->predicate;
      port = options->target_port;
      dir_agent = options->use_directory_agent==true?1:0;
      options->print();
      
  }
  Array<CIMServerDescription> connections;
  
  if (NULL != (client = create_slp_client(
                  addr, // target_addr
                  iface, // local_interface
                  port, // target_port
                  spi, // spi
                  scopes, // scopes
                  FALSE, // should_listen
                  dir_agent // use_das
                  )))
    {
      if (addr != NULL && inet_addr(addr) == inet_addr("127.0.0.1"))
        {
          client->local_srv_req(client, type, predicate, scopes);
        }
      else
        {
          SOCKADDR_IN address;
          address.sin_port = htons(port);
          address.sin_family = AF_INET;
          if (addr != NULL){
            address.sin_addr.s_addr = inet_addr(addr);
      }else{
            address.sin_addr.s_addr = _LSLP_MCAST;
      }
          client->unicast_srv_req(client, type, predicate, scopes, &address);
        }

      responses.isHead = TRUE;
      responses.next = responses.prev = &responses;
      
      client->get_response(client, &responses);
      while(!_LSLP_IS_EMPTY(&responses))
      {
          srvReplyEntry = responses.next;
          if (srvReplyEntry->type == srvRply) 
            {
              lslpURL *url_list;
              if (srvReplyEntry != NULL && srvReplyEntry->type == srvRply)
                {
                  if ((NULL != srvReplyEntry->msg.srvRply.urlList) && 
                     (!_LSLP_IS_EMPTY( srvReplyEntry->msg.srvRply.urlList)))
                    {
                      url_list = srvReplyEntry->msg.srvRply.urlList->next;
                      while(!_LSLP_IS_HEAD(url_list))
                        {
                          /* check for urls */
                          if (NULL != url_list->url)
                            {
                              CIMServerDescription connection(url_list->url);

                              Array<Attribute> attributes;

                              /* check for attributes */
                              /* PegasusSLP reurns attributes with srvReply
                               * per RFC 3059. Other implementations do not.
                               */
                              if (NULL != url_list->attrs && !_LSLP_IS_HEAD(url_list->attrs->next))
                                {
                                  lslpAtomList *attrs = url_list->attrs->next;
                                  while(!_LSLP_IS_HEAD(attrs))
                                    {
                                      _extractAttributes(String(attrs->str), attributes);
                                      attrs = attrs->next;
                                    }
                                }/*if attrs*/
                  /* add to connections array */
                  /* VRTS - interop. Add unconditionally.
                   * Not initialised in contsructor */
                  connection.setAttributes(attributes);
                  connections.append(connection);
                            }/*if url*/
              url_list = url_list->next;
                        }/*while we have urls*/
                    }/*if urlList*/
                }/*if srvReply*/
            }/*if type==srvReply*/
          _LSLP_UNLINK(srvReplyEntry);
          lslpDestroySLPMsg(srvReplyEntry, LSLP_DESTRUCTOR_DYNAMIC);
        }/*while*/
      destroy_slp_client(client);
    }

    /* If no attributes were present, then the attributes array
     * has zero size. Rescan the connections and create a fresh slp_client to 
     * get the attributes, if none present
     */
    if(0==connections.size()){
      return connections;
    }
    for(int i=0; i< connections.size();i++){
        Array<Attribute> attrs = connections[i].getAttributes();
        if(0==attrs.size()){
            String url=connections[i].getUrl();
            if(TRUE==_lookup_attrs(url,attrs,options)){
                connections[i].setAttributes(attrs);
            }
        }
    }

  return connections;
}