SLPFindSrvs
OpenSLP Programmer's Guide » Service Location Functions » SLPFindSrvs

Declaration

#include <slp.h>

SLPEXP SLPError SLPAPI SLPFindSrvs(
    SLPHandle         hslp,
    const char *      srvtype,
    const char *      scopelist,
    const char *      filter,
    SLPSrvURLCallback callback,
    void *            cookie);

Description

Issue a query for services.

Parameters

hslp The language specific SLPHandle on which to register the service.
srvtype The service type string, including the authority string (if any) for the request.  May not be the empty string, "". May not be NULL.  See Syntax more information on Service Type syntax. 
scopelist A pointer to a comma separated list of scope names.  May be the empty string if you wish to use scopes this machine is configured for.. 
filter A query formulated of attribute pattern matching expressions in the form of an LDAPv3 search filter.  Pass in  the empty string, "" for all services of the requested type.  See Syntax for more information on LDAP3 search filter syntax.
callback The address of an SLPSrvURLCallback function that will be called to report the results of the query.  May not be NULL. See Callbacks for more information on how callbacks are used by the SLPAPI.
cookie Pointer to memory that gets passed to the callback code.  May be NULL.

Returns

SLP_OK Indicates that the no error occurred during the operation.
SLP_PARSE_ERROR The SLP message was rejected by a remote SLP agent. The API returns this error only when no information was retrieved, and at least one SA or DA indicated a protocol error. The data supplied through the API may be malformed or a may have been damaged in transit.
SLP_AUTHENTICATION_ABSENT If the SLP framework supports authentication, this error arises when the UA or SA failed to send an authenticator for requests or registrations.
SLP_AUTHENTICATION_FAILED If the SLP framework supports authentication, this error arises when a authentication on an SLP message failed.
SLP_NETWORK_TIMED_OUT When no reply can be obtained in the time specified by the configured timeout interval for a unicast request, this error is returned.  In other words, slpd is running, but something is wrong with it
SLP_NETWORK_INIT_FAILED If the network cannot initialize properly, this error is returned. Will also be returned if an SA or DA agent (slpd) can not be contacted.  slpd must be running in order to call SLPReg() or SLPDereg().
SLP_MEMORY_ALLOC_FAILED  Out of memory error
SLP_PARAMETER_BAD If a parameter passed into a function is bad, this error is returned.
SLP_NETWORK_ERROR The failure of networking during normal operations causes this error to be returned.  In OpenSLP, this is the error you'll get if an underlying socket() call failed.
SLP_INTERNAL_SYSTEM_ERROR A basic failure of the API causes this error to be returned. This occurs when a system call or library fails. The operation could not recover.
SLP_HANDLE_IN_USE Callback functions are not permitted to recursively call into the API on the same SLPHandle, either directly or indirectly. If an attempt is made to do so, this error is returned from the called API function.

If no services can be found, no error is returned.  However, no calls (other than the SLP_LAST_CALL) will be made to the SLPSrvURLCallback.  Be aware, especially if the call is async, of error codes that may be passed to the SLPSrvURLCallback callback function.

Status

OpenSLP 0.9.1 Implemented as specified by RFC 2614.

See Also

Syntax, Callbacks

Example Code

  #include <slp.h>

  SLPBoolean MySLPSrvURLCallback(
      SLPHandle hslp,
      const char* srvurl,
      unsigned short lifetime,
      SLPError errcode,
      void* cookie )
  {
      if(errcode == SLP_OK || errcode == SLP_LAST_CALL)
      {
          printf("Service URL     = %s\n",srvurl);
          printf("Service Timeout = %i\n",lifetime);
          *(SLPError*)cookie = SLP_OK;
      }
      else
      {
          *(SLPError*)cookie = errcode;
      }
      
      /* return SLP_TRUE because we want to be called again */
      /* if more services were found                        */
      
      return SLP_TRUE;
  }
  
  int main( int argc, char* argv[])
  {
      SLPError err;
      SLPError callbackerr;
      SLPHandle hslp;
      
      err = SLPOpen("en",SLP_FALSE,&hslp);
 
      if(err != SLP_OK)
      {
          printf("Error opening slp handle %i\n",err);
          return err;
      }
      
      err =
          SLPFindSrvs( hslp,
              "myservice.myorg",
              0,  /* use configured scopes */
              0,   /* no attr filter        */
              MySLPSrvURLCallback,                         
              &callbackerr );
              
      /* err may contain an error code that occurred as the slp library    */
      /* _prepared_ to make the call.                                      */
      
      if((err != SLP_OK) || (callbackerr != SLP_OK))
      {
          printf("Error registering service with slp %i\n",err);
          return err;
      }
      
      /* callbackerr may contain an error code (that was assigned through  */
      /* the callback cookie) that occurred as slp packets were sent on    */
      /* the wire */
      
      if( callbackerr != SLP_OK)
      {
          printf("Error registering service with slp %i\n",callbackerr);
          return callbackerr;
      }
      
      /* Now that we're done using slp, close the slp handle */
      SLPClose(hslp);

      /* rest of program */
  }