📄 libslp_findsrvs.c
字号:
#ifdef ENABLE_SLPv2_SECURITY if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled"))) { SLPSpiGetDefaultSPI(handle->hspi, SLPSPI_KEY_TYPE_PUBLIC, &spistrlen, &spistr); }#endif /*-------------------------------------------------------------------*/ /* determine the size of the fixed portion of the SRVRQST */ /*-------------------------------------------------------------------*/ bufsize = handle->params.findsrvs.srvtypelen + 2; /* 2 bytes for len field */ bufsize += handle->params.findsrvs.scopelistlen + 2; /* 2 bytes for len field */ bufsize += handle->params.findsrvs.predicatelen + 2; /* 2 bytes for len field */ bufsize += 2; /* 2 bytes for spistr len*/#ifdef ENABLE_SLPv2_SECURITY bufsize += spistrlen;#endif buf = curpos = (char*)xmalloc(bufsize); if(buf == 0) { result = SLP_MEMORY_ALLOC_FAILED; goto FINISHED; } /*------------------------------------------------------------*/ /* Build a buffer containing the fixed portion of the SRVRQST */ /*------------------------------------------------------------*/ /* service type */ ToUINT16(curpos,handle->params.findsrvs.srvtypelen); curpos = curpos + 2; memcpy(curpos, handle->params.findsrvs.srvtype, handle->params.findsrvs.srvtypelen); curpos = curpos + handle->params.findsrvs.srvtypelen; /* scope list */ ToUINT16(curpos,handle->params.findsrvs.scopelistlen); curpos = curpos + 2; memcpy(curpos, handle->params.findsrvs.scopelist, handle->params.findsrvs.scopelistlen); curpos = curpos + handle->params.findsrvs.scopelistlen; /* predicate */ ToUINT16(curpos,handle->params.findsrvs.predicatelen); curpos = curpos + 2; memcpy(curpos, handle->params.findsrvs.predicate, handle->params.findsrvs.predicatelen); curpos = curpos + handle->params.findsrvs.predicatelen;#ifdef ENABLE_SLPv2_SECURITY ToUINT16(curpos,spistrlen); curpos = curpos + 2; memcpy(curpos,spistr,spistrlen); curpos = curpos + spistrlen;#else ToUINT16(curpos,0);#endif /*--------------------------*/ /* Call the RqstRply engine */ /*--------------------------*/ do { #ifndef UNICAST_NOT_SUPPORTED if ( handle->dounicast == 1 ) { void *cookie = (PSLPHandleInfo) handle; result = NetworkUcastRqstRply(handle, buf, SLP_FUNCT_SRVRQST, bufsize, ProcessSrvRplyCallback, cookie); break; } else #endif if(strncasecmp(handle->params.findsrvs.srvtype, SLP_SA_SERVICE_TYPE, handle->params.findsrvs.srvtypelen)) { sock = NetworkConnectToDA(handle, handle->params.findsrvs.scopelist, handle->params.findsrvs.scopelistlen, &peeraddr); } if(sock == -1) { /* use multicast as a last resort */ #ifndef MI_NOT_SUPPORTED result = NetworkMcastRqstRply(handle, buf, SLP_FUNCT_SRVRQST, bufsize, ProcessSrvRplyCallback, NULL); #else result = NetworkMcastRqstRply(handle->langtag, buf, SLP_FUNCT_SRVRQST, bufsize, ProcessSrvRplyCallback, handle); #endif /* MI_NOT_SUPPORTED */ break; } result = NetworkRqstRply(sock, &peeraddr, handle->langtag, 0, buf, SLP_FUNCT_SRVRQST, bufsize, ProcessSrvRplyCallback, handle); if(result) { NetworkDisconnectDA(handle); } }while(result == SLP_NETWORK_ERROR); FINISHED: if(buf) xfree(buf);#ifdef ENABLE_SLPv2_SECURITY if(spistr) xfree(spistr);#endif return result;} #ifdef ENABLE_ASYNC_API/*-------------------------------------------------------------------------*/ SLPError AsyncProcessSrvRqst(PSLPHandleInfo handle)/*-------------------------------------------------------------------------*/{ SLPError result = ProcessSrvRqst(handle); xfree((void*)handle->params.findsrvs.srvtype); xfree((void*)handle->params.findsrvs.scopelist); xfree((void*)handle->params.findsrvs.predicate); handle->inUse = SLP_FALSE; return result;}#endif/*=========================================================================*/SLPError SLPAPI SLPFindSrvs(SLPHandle hSLP, const char *pcServiceType, const char *pcScopeList, const char *pcSearchFilter, SLPSrvURLCallback callback, void *pvCookie)/* *//* Issue the query for services on the language specific SLPHandle and *//* return the results through the callback. The parameters determine *//* the results *//* *//* hSLP The language specific SLPHandle on which to search for *//* services. *//* *//* pcServiceType The Service Type String, including authority string if *//* any, for the request, such as can be discovered using *//* SLPSrvTypes(). This could be, for example *//* "service:printer:lpr" or "service:nfs". May not be *//* the empty string or NULL. *//* *//* *//* pcScopeList A pointer to a char containing comma separated list of *//* scope names. Pass in the NULL or the empty string "" *//* to find services in all the scopes the local host is *//* configured query. *//* *//* pcSearchFilter A query formulated of attribute pattern matching *//* expressions in the form of a LDAPv3 Search Filter. *//* If this filter is NULL or empty, i.e. "", all *//* services of the requested type in the specified scopes *//* are returned. *//* *//* callback A callback function through which the results of the *//* operation are reported. May not be NULL *//* *//* pvCookie Memory passed to the callback code from the client. *//* May be NULL. *//* *//* Returns: If an error occurs in starting the operation, one of *//* the SLPError codes is returned. *//* *//*=========================================================================*/{ PSLPHandleInfo handle; SLPError result; /*------------------------------*/ /* check for invalid parameters */ /*------------------------------*/ if(hSLP == 0 || *(unsigned int*)hSLP != SLP_HANDLE_SIG || pcServiceType == 0 || *pcServiceType == 0 || /* srvtype can't be empty string */ callback == 0) { return SLP_PARAMETER_BAD; } /*-----------------------------------------*/ /* cast the SLPHandle into a SLPHandleInfo */ /*-----------------------------------------*/ handle = (PSLPHandleInfo)hSLP; /*-----------------------------------------*/ /* Check to see if the handle is in use */ /*-----------------------------------------*/ if(handle->inUse == SLP_TRUE) { return SLP_HANDLE_IN_USE; } handle->inUse = SLP_TRUE; /*-------------------------------------------*/ /* Set the handle up to reference parameters */ /*-------------------------------------------*/ handle->params.findsrvs.srvtypelen = strlen(pcServiceType); handle->params.findsrvs.srvtype = pcServiceType; if(pcScopeList && *pcScopeList) { handle->params.findsrvs.scopelistlen = strlen(pcScopeList); handle->params.findsrvs.scopelist = pcScopeList; } else { handle->params.findsrvs.scopelist = SLPGetProperty("net.slp.useScopes"); handle->params.findsrvs.scopelistlen = strlen(handle->params.findsrvs.scopelist); } if(pcSearchFilter) { handle->params.findsrvs.predicatelen = strlen(pcSearchFilter); handle->params.findsrvs.predicate = pcSearchFilter; } else { handle->params.findsrvs.predicatelen = 0; handle->params.findsrvs.predicate = (char*)&handle->params.findsrvs.predicatelen; } handle->params.findsrvs.callback = callback; handle->params.findsrvs.cookie = pvCookie; /*----------------------------------------------*/ /* Check to see if we should be async or sync */ /*----------------------------------------------*/#ifdef ENABLE_ASYNC_API if(handle->isAsync) { /* COPY all the referenced parameters */ handle->params.findsrvs.srvtype = xstrdup(handle->params.findsrvs.srvtype); handle->params.findsrvs.scopelist = xstrdup(handle->params.findsrvs.scopelist); handle->params.findsrvs.predicate = xstrdup(handle->params.findsrvs.predicate); /* make sure strdups did not fail */ if(handle->params.findsrvs.srvtype && handle->params.findsrvs.scopelist && handle->params.findsrvs.predicate) { result = ThreadCreate((ThreadStartProc)AsyncProcessSrvRqst,handle); } else { result = SLP_MEMORY_ALLOC_FAILED; } if(result) { if(handle->params.findsrvs.srvtype) xfree((void*)handle->params.findsrvs.srvtype); if(handle->params.findsrvs.scopelist) xfree((void*)handle->params.findsrvs.scopelist); if(handle->params.findsrvs.predicate) xfree((void*)handle->params.findsrvs.predicate); handle->inUse = SLP_FALSE; } } else#endif /* ifdef ENABLE_ASYNC_API */ { /* Leave all parameters REFERENCED */ result = ProcessSrvRqst(handle); handle->inUse = SLP_FALSE; } return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -