Changeset 2004:f990a3d680ce in roaraudio


Ignore:
Timestamp:
06/15/09 18:05:10 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

impemented everything but the callback

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/slp.c

    r2002 r2004  
    3535#include "libroar.h" 
    3636 
     37SLPBoolean roar_slp_url_callback(SLPHandle        hslp, 
     38                                 const char     * srvurl, 
     39                                 unsigned short   lifetime, 
     40                                 SLPError         errcode, 
     41                                 void           * cookie); 
     42 
     43int roar_slp_search          (struct roar_slp_cookie * cookie, char * type) { 
     44#ifdef ROAR_HAVE_LIBSLP 
     45 SLPError err; 
     46 SLPError callbackerr; 
     47 SLPHandle hslp; 
     48 
     49 if ( cookie->search != NULL ) /* currently only non-search filter mode supported */ 
     50  return -1; 
     51 
     52 err = SLPOpen("en", SLP_FALSE, &hslp); 
     53 if (err != SLP_OK) { 
     54  return -1; 
     55 } 
     56 
     57 err = SLPFindSrvs(hslp, 
     58                   type, 
     59                   0,                    /* use configured scopes */ 
     60                   0,                    /* no attr filter        */ 
     61                   roar_slp_url_callback, 
     62                   &callbackerr); 
     63 
     64  /* err may contain an error code that occurred as the slp library    */ 
     65  /* _prepared_ to make the call.                                     */ 
     66  if(err != SLP_OK) { 
     67   return -1; 
     68  } 
     69 
     70 /* callbackerr may contain an error code (that was assigned through */ 
     71 /* the callback cookie) that occurred as slp packets were sent on    */ 
     72 /* the wire */ 
     73 if (callbackerr != SLP_OK) { 
     74  return -1; 
     75 } 
     76 
     77 /* Now that we're done using slp, close the slp handle */ 
     78 SLPClose(hslp); 
     79 
     80 return -1; 
     81#else 
     82 return -1; 
     83#endif 
     84} 
     85 
     86int roar_slp_cookie_init     (struct roar_slp_cookie * cookie, struct roar_slp_search * search) { 
     87 if ( cookie == NULL ) 
     88  return -1; 
     89 
     90 memset(cookie, 0, sizeof(struct roar_slp_cookie)); 
     91 
     92 cookie->search = search; 
     93 
     94 return 0; 
     95} 
     96 
     97 
    3798char * roar_slp_find_roard   (void) { 
    3899 static char addr[80]; 
     
    45106 
    46107int    roar_slp_find_roard_r (char * addr, size_t len) { 
    47  return -1; 
     108 struct roar_slp_cookie cookie; 
     109 
     110 if ( addr == NULL || len == 0 ) 
     111  return -1; 
     112 
     113 *addr = 0; // just in case... 
     114 
     115 if ( roar_slp_cookie_init(&cookie, NULL) == -1 ) 
     116  return -1; 
     117 
     118 if ( roar_slp_search(&cookie, "service:mixer.fellig:roar") == -1 ) 
     119  return -1; 
     120 
     121 if ( cookie.matchcount == 0 ) 
     122  return -1; 
     123 
     124 strncpy(addr, cookie.match[0].url, len); 
     125 addr[len-1] = 0; // also just in case. 
     126 
     127 return 0; 
    48128} 
    49129 
Note: See TracChangeset for help on using the changeset viewer.