📄 libslp_knownda.c
字号:
/* returns: valid socket file descriptor or -1 if no DA is found *//*=========================================================================*/{ struct timeval timeout; int sock = -1; int spistrlen = 0; char* spistr = 0;#ifdef ENABLE_SLPv2_SECURITY if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled"))) { SLPSpiGetDefaultSPI(handle->hspi, SLPSPI_KEY_TYPE_PUBLIC, &spistrlen, &spistr); }#endif /* Set up connect timeout */ timeout.tv_sec = SLPPropertyAsInteger(SLPGetProperty("net.slp.DADiscoveryMaximumWait")); timeout.tv_usec = (timeout.tv_sec % 1000) * 1000; timeout.tv_sec = timeout.tv_sec / 1000; while(1) { memset(peeraddr,0,sizeof(peeraddr)); if(KnownDAFromCache(scopelistlen, scopelist, spistrlen, spistr,#ifndef MI_NOT_SUPPORTED &(peeraddr->sin_addr), handle) == 0)#else &(peeraddr->sin_addr)) == 0)#endif /* MI_NOT_SUPPORTED */ { break; } peeraddr->sin_family = PF_INET; peeraddr->sin_port = htons(SLP_RESERVED_PORT); sock = SLPNetworkConnectStream(peeraddr,&timeout); if(sock >= 0) { break; } KnownDABadDA(&(peeraddr->sin_addr)); }#ifdef ENABLE_SLPv2_SECURITY if(spistr) xfree(spistr);#endif return sock;}/*=========================================================================*/void KnownDABadDA(struct in_addr* daaddr)/* Mark a KnownDA as a Bad DA. *//* *//* daaddr (IN) address of the bad DA *//* *//* Returns: none *//*=========================================================================*/{ SLPDatabaseHandle dh; SLPDatabaseEntry* entry; dh = SLPDatabaseOpen(&G_KnownDACache); if(dh) { /*-----------------------------------*/ /* Check to find the requested entry */ /*-----------------------------------*/ while(1) { entry = SLPDatabaseEnum(dh); if(entry == NULL) break; /* Assume DAs are identical if their in_addrs match */ if(memcmp(daaddr,&(entry->msg->peer.sin_addr),sizeof(struct in_addr)) == 0) { SLPDatabaseRemove(dh,entry); break; } } SLPDatabaseClose(dh); }}/*=========================================================================*/int KnownDAGetScopes(int* scopelistlen,#ifndef MI_NOT_SUPPORTED char** scopelist, PSLPHandleInfo handle)#else char** scopelist)#endif/* 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; SLPDatabaseHandle dh; SLPDatabaseEntry* entry; /* discover all DAs */#ifndef MI_NOT_SUPPORTED if(KnownDADiscoverFromIPC(handle) == 0)#else if(KnownDADiscoverFromIPC() == 0)#endif {#ifndef MI_NOT_SUPPORTED KnownDADiscoverFromDHCP(handle); KnownDADiscoverFromProperties(0,"", handle); KnownDADiscoverFromMulticast(0,"", handle);#else KnownDADiscoverFromDHCP(); KnownDADiscoverFromProperties(0,""); KnownDADiscoverFromMulticast(0,"");#endif } /* 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;}/*=========================================================================*/void KnownDAProcessSrvRqst(PSLPHandleInfo handle)/* Process a SrvRqst for service:directory-agent *//* *//* handle (IN) the handle used to make the SrvRqst *//* *//* returns: none *//*=========================================================================*/{ SLPDatabaseHandle dh; SLPDatabaseEntry* entry; SLPBoolean cb_result; char tmp; /* discover all DAs */#ifndef MI_NOT_SUPPORTED if(KnownDADiscoverFromIPC(handle) == 0)#else if(KnownDADiscoverFromIPC() == 0)#endif {#ifndef MI_NOT_SUPPORTED KnownDADiscoverFromDHCP(handle); KnownDADiscoverFromProperties(0,"", handle); KnownDADiscoverFromMulticast(0,"", handle);#else KnownDADiscoverFromDHCP(); KnownDADiscoverFromProperties(0,""); KnownDADiscoverFromMulticast(0,"");#endif } /* Enumerate through knownDA database */ dh = SLPDatabaseOpen(&G_KnownDACache); if(dh) { /* Check to see if there a matching entry */ while(1) { entry = SLPDatabaseEnum(dh); /* is there anything left? */ if(entry == NULL) break; /* TRICKY temporary null termination of DA url */ tmp = entry->msg->body.daadvert.url[entry->msg->body.daadvert.urllen]; ((char*)(entry->msg->body.daadvert.url))[entry->msg->body.daadvert.urllen] = 0; /* Call the SrvURLCallback */ cb_result = handle->params.findsrvs.callback((SLPHandle)handle, entry->msg->body.daadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK, handle->params.findsrvs.cookie); /* TRICKY: undo temporary null termination of DA url */ ((char*)(entry->msg->body.daadvert.url))[entry->msg->body.daadvert.urllen] = tmp; /* does the caller want more? */ if(cb_result == SLP_FALSE) { break; } } SLPDatabaseClose(dh); } /* Make SLP_LAST_CALL */ handle->params.findsrvs.callback((SLPHandle)handle, NULL, 0, SLP_LAST_CALL, handle->params.findsrvs.cookie);}#ifdef DEBUG/*=========================================================================*/void KnownDAFreeAll()/* Frees all (cached) resources associated with known DAs *//* *//* returns: none *//*=========================================================================*/{ SLPDatabaseHandle dh; SLPDatabaseEntry* entry; dh = SLPDatabaseOpen(&G_KnownDACache); if(dh) { while(1) { entry = SLPDatabaseEnum(dh); if(entry == NULL) break; SLPDatabaseRemove(dh,entry); } SLPDatabaseClose(dh); } if(G_KnownDAScopes) xfree(G_KnownDAScopes); G_KnownDAScopesLen = 0; G_KnownDALastCacheRefresh = 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -