/*=========================================================================*/ int KnownDAGetScopes(int* scopelistlen, char** scopelist) /* Gets a list of scopes from the known DA list */ /* */ /* scopelistlen (OUT) stringlen of the scopelist */ /* */ /* scopelist (OUT) NULL terminated list of scopes */ /* */ /* returns: zero on success, non-zero on failure */ /*=========================================================================*/ { time_t curtime; SLPDAEntry* entry; int newlen; /* Refresh the cache if necessary */ curtime = time(&curtime); if(G_KnownDALastCacheRefresh == 0 || curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL) { G_KnownDALastCacheRefresh = curtime; /* discover DAs */ if(KnownDADiscoverFromIPC() == 0) { KnownDADiscoverFromDHCP(); KnownDADiscoverFromProperties(); KnownDADiscoverFromMulticast(0,""); } /* TODO: */ /* enumerate through all the knownda entries and generate a */ /* scopelist */ entry = (SLPDAEntry*)G_KnownDACache.head; while(entry) { newlen = G_KnownDAScopesLen; while(SLPUnionStringList(G_KnownDAScopesLen, G_KnownDAScopes, entry->scopelistlen, entry->scopelist, &newlen, G_KnownDAScopes) < 0) { G_KnownDAScopes = realloc(G_KnownDAScopes,newlen); if(G_KnownDAScopes == 0) { G_KnownDAScopesLen = 0; break; } } G_KnownDAScopesLen = newlen; entry = (SLPDAEntry*) entry->listitem.next; } /* Explicitly add in the useScopes property */ newlen = G_KnownDAScopesLen; while(SLPUnionStringList(G_KnownDAScopesLen, G_KnownDAScopes, strlen(SLPPropertyGet("net.slp.useScopes")), SLPPropertyGet("net.slp.useScopes"), &newlen, G_KnownDAScopes) < 0) { G_KnownDAScopes = realloc(G_KnownDAScopes,newlen); if(G_KnownDAScopes == 0) { G_KnownDAScopesLen = 0; break; } } G_KnownDAScopesLen = newlen; } if(G_KnownDAScopesLen) { *scopelist = malloc(G_KnownDAScopesLen + 1); if(*scopelist == 0) { return -1; } memcpy(*scopelist,G_KnownDAScopes, G_KnownDAScopesLen); (*scopelist)[G_KnownDAScopesLen] = 0; *scopelistlen = G_KnownDAScopesLen; } else { *scopelist = strdup(""); if(*scopelist == 0) { return -1; } *scopelistlen = 0; } return 0; }
/*----------------------------------------------------------------------------*/ SLPBoolean ColateSrvTypeCallback(SLPHandle hSLP, const char* pcSrvTypes, SLPError errCode, void *pvCookie) /*----------------------------------------------------------------------------*/ { PSLPHandleInfo handle; SLPBoolean result; int srvtypeslen; char* srvtypes; handle = (PSLPHandleInfo) hSLP; handle->callbackcount ++; #ifdef ENABLE_ASYNC_API /* Do not colate for async calls */ if(handle->isAsync) { return handle->params.findsrvtypes.callback(hSLP, pcSrvTypes, errCode, pvCookie); } #endif if(errCode == SLP_LAST_CALL || handle->callbackcount > SLPPropertyAsInteger(SLPGetProperty("net.slp.maxResults"))) { /* We're done. Send back the colated srvtype string */ result = SLP_TRUE; if(handle->collatedsrvtypes) { result = handle->params.findsrvtypes.callback((SLPHandle)handle, handle->collatedsrvtypes, SLP_OK, handle->params.findsrvtypes.cookie); if(result == SLP_TRUE) { handle->params.findsrvtypes.callback((SLPHandle)handle, NULL, SLP_LAST_CALL, handle->params.findsrvtypes.cookie); } } /* Free the colatedsrvtype string */ if(handle->collatedsrvtypes) { xfree(handle->collatedsrvtypes); handle->collatedsrvtypes = NULL; } handle->callbackcount = 0; return SLP_FALSE; } else if(errCode != SLP_OK) { return SLP_TRUE; } /* Add the service types to the colation */ srvtypeslen = strlen(pcSrvTypes) + 1; if(handle->collatedsrvtypes) { srvtypeslen += strlen(handle->collatedsrvtypes); } srvtypes = xmalloc(srvtypeslen); if(srvtypes) { if(handle->collatedsrvtypes) { if(SLPUnionStringList(strlen(handle->collatedsrvtypes), handle->collatedsrvtypes, strlen(pcSrvTypes), pcSrvTypes, &srvtypeslen, srvtypes) != srvtypeslen) { xfree(handle->collatedsrvtypes); handle->collatedsrvtypes = srvtypes; } else { xfree(srvtypes); } } else { strcpy(srvtypes,pcSrvTypes); handle->collatedsrvtypes = srvtypes; } } return SLP_TRUE; }
/*=========================================================================*/ int KnownDAGetScopes(int* scopelistlen, char** scopelist) /* Gets a list of scopes from the known DA list */ /* */ /* scopelistlen (OUT) stringlen of the scopelist */ /* */ /* scopelist (OUT) NULL terminated list of scopes */ /* */ /* returns: zero on success, non-zero on failure */ /*=========================================================================*/ { int newlen; time_t curtime; SLPDatabaseHandle dh; SLPDatabaseEntry* entry; /* Refresh the cache if necessary */ curtime = time(&curtime); if(G_KnownDALastCacheRefresh == 0 || curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL) { G_KnownDALastCacheRefresh = curtime; /* discover DAs */ if(KnownDADiscoverFromIPC() == 0) { KnownDADiscoverFromDHCP(); KnownDADiscoverFromProperties(); KnownDADiscoverFromMulticast(0,""); } } /* enumerate through all the knownda entries and generate a */ /* scopelist */ dh = SLPDatabaseOpen(&G_KnownDACache); if(dh) { /*-----------------------------------*/ /* Check to find the requested entry */ /*-----------------------------------*/ while(1) { entry = SLPDatabaseEnum(dh); if(entry == NULL) break; newlen = G_KnownDAScopesLen; while(SLPUnionStringList(G_KnownDAScopesLen, G_KnownDAScopes, entry->msg->body.daadvert.scopelistlen, entry->msg->body.daadvert.scopelist, &newlen, G_KnownDAScopes) < 0) { G_KnownDAScopes = xrealloc(G_KnownDAScopes,newlen); if(G_KnownDAScopes == 0) { G_KnownDAScopesLen = 0; break; } } G_KnownDAScopesLen = newlen; } SLPDatabaseClose(dh); } /* Explicitly add in the useScopes property */ newlen = G_KnownDAScopesLen; while(SLPUnionStringList(G_KnownDAScopesLen, G_KnownDAScopes, strlen(SLPPropertyGet("net.slp.useScopes")), SLPPropertyGet("net.slp.useScopes"), &newlen, G_KnownDAScopes) < 0) { G_KnownDAScopes = xrealloc(G_KnownDAScopes,newlen); if(G_KnownDAScopes == 0) { G_KnownDAScopesLen = 0; break; } } G_KnownDAScopesLen = newlen; if(G_KnownDAScopesLen) { *scopelist = xmalloc(G_KnownDAScopesLen + 1); if(*scopelist == 0) { return -1; } memcpy(*scopelist,G_KnownDAScopes, G_KnownDAScopesLen); (*scopelist)[G_KnownDAScopesLen] = 0; *scopelistlen = G_KnownDAScopesLen; } else { *scopelist = xstrdup(""); if(*scopelist == 0) { return -1; } *scopelistlen = 0; } return 0; }
/** Collates response data to user callback for SLPFindSrvType requests. * * @param[in] hSLP - The SLP handle object associated with the request. * @param[in] pcSrvTypes - The service type for this pass. * @param[in] errorcode - The error code received on this pass. * * @return An SLP boolean value; SLP_TRUE indicates we are finished; * SLP_FALSE indicates we should continue. * * @todo Trace the logic of CollateToSLPSrvTypeCallback to ensure that * it works. * * @internal */ static SLPBoolean CollateToSLPSrvTypeCallback(SLPHandle hSLP, const char * pcSrvTypes, SLPError errorcode) { int maxResults; char * srvtypes; size_t srvtypeslen; SLPHandleInfo * handle = hSLP; handle->callbackcount++; #ifdef ENABLE_ASYNC_API /* Do not collate for async calls. */ if (handle->isAsync) return handle->params.findsrvtypes.callback(hSLP, pcSrvTypes, errorcode, handle->params.findsrvtypes.cookie); #endif /* Configure behaviour for desired max results. */ maxResults = SLPPropertyAsInteger("net.slp.maxResults"); if (maxResults == -1) maxResults = INT_MAX; if (errorcode == SLP_LAST_CALL || handle->callbackcount > maxResults) { /* We're done. Send back the collated srvtype string. */ if (handle->collatedsrvtypes) if (handle->params.findsrvtypes.callback(handle, handle->collatedsrvtypes, SLP_OK, handle->params.findsrvtypes.cookie) == SLP_TRUE) handle->params.findsrvtypes.callback(handle, 0, SLP_LAST_CALL, handle->params.findsrvtypes.cookie); /* Free the collatedsrvtype string. */ if (handle->collatedsrvtypes) { xfree(handle->collatedsrvtypes); handle->collatedsrvtypes = 0; } handle->callbackcount = 0; return SLP_FALSE; } else if (errorcode != SLP_OK) return SLP_TRUE; /* Add the service types to the colation. */ srvtypeslen = strlen(pcSrvTypes) + 1; /* +1 - terminator */ if (handle->collatedsrvtypes) srvtypeslen += strlen(handle->collatedsrvtypes) + 1; /* +1 - comma */ srvtypes = xmalloc(srvtypeslen); if (srvtypes) { if (handle->collatedsrvtypes) { if (SLPUnionStringList(strlen(handle->collatedsrvtypes), handle->collatedsrvtypes, strlen(pcSrvTypes), pcSrvTypes, &srvtypeslen, srvtypes) != (int)srvtypeslen) { xfree(handle->collatedsrvtypes); handle->collatedsrvtypes = srvtypes; } else { #ifndef COLLATION_CHANGES xfree(handle->collatedsrvtypes); handle->collatedsrvtypes = srvtypes; handle->collatedsrvtypes[srvtypeslen] = 0; #else xfree(srvtypes); #endif } } else { strcpy(srvtypes, pcSrvTypes); handle->collatedsrvtypes = srvtypes; } } return SLP_TRUE; }