/*-------------------------------------------------------------------------*/ SLPBoolean ProcessSrvRplyCallback(SLPError errorcode, struct sockaddr_in* peerinfo, SLPBuffer replybuf, void* cookie) /*-------------------------------------------------------------------------*/ { int i; SLPUrlEntry* urlentry; SLPMessage replymsg; PSLPHandleInfo handle = (PSLPHandleInfo) cookie; SLPBoolean result = SLP_TRUE; #ifdef ENABLE_SLPv2_SECURITY int securityenabled; securityenabled = SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")); #endif /*-------------------------------------------*/ /* Check the errorcode and bail if it is set */ /*-------------------------------------------*/ if(errorcode != SLP_OK) { return ColateSLPSrvURLCallback((SLPHandle)handle, 0, 0, errorcode, handle->params.findsrvs.cookie); } /*--------------------*/ /* Parse the replybuf */ /*--------------------*/ replymsg = SLPMessageAlloc(); if(replymsg) { if(SLPMessageParseBuffer(peerinfo,replybuf,replymsg) == 0) { if(replymsg->header.functionid == SLP_FUNCT_SRVRPLY && replymsg->body.srvrply.errorcode == 0) { urlentry = replymsg->body.srvrply.urlarray; for(i=0;i<replymsg->body.srvrply.urlcount;i++) { #ifdef ENABLE_SLPv2_SECURITY /*-------------------------------*/ /* Validate the authblocks */ /*-------------------------------*/ if(securityenabled && SLPAuthVerifyUrl(handle->hspi, 1, &(urlentry[i]))) { /* authentication failed skip this URLEntry */ continue; } #endif /*--------------------------------*/ /* Send the URL to the API caller */ /*--------------------------------*/ /* TRICKY: null terminate the url by setting the authcount to 0 */ ((char*)(urlentry[i].url))[urlentry[i].urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, urlentry[i].url, (unsigned short)urlentry[i].lifetime, SLP_OK, handle->params.findsrvs.cookie); if(result == SLP_FALSE) { break; } } } else if(replymsg->header.functionid == SLP_FUNCT_DAADVERT && replymsg->body.daadvert.errorcode == 0) { #ifdef ENABLE_SLPv2_SECURITY if(securityenabled && SLPAuthVerifyDAAdvert(handle->hspi, 1, &(replymsg->body.daadvert))) { /* Verification failed. Ignore message */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif ((char*)(replymsg->body.daadvert.url))[replymsg->body.daadvert.urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, replymsg->body.daadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK, handle->params.findsrvs.cookie); } else if(replymsg->header.functionid == SLP_FUNCT_SAADVERT) { #ifdef ENABLE_SLPv2_SECURITY if(securityenabled && SLPAuthVerifySAAdvert(handle->hspi, 1, &(replymsg->body.saadvert))) { /* Verification failed. Ignore message */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif ((char*)(replymsg->body.saadvert.url))[replymsg->body.saadvert.urllen] = 0; result = ColateSLPSrvURLCallback((SLPHandle)handle, replymsg->body.saadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK, handle->params.findsrvs.cookie); } } SLPMessageFree(replymsg); } return result; }
/** SLPFindSrvs callback routine for NetworkRqstRply. * * @param[in] errorcode - The network operation error code. * @param[in] peeraddr - The network address of the responder. * @param[in] replybuf - The response buffer from the network request. * @param[in] cookie - Callback context data from ProcessSrvReg. * * @return SLP_FALSE (to stop any iterative callbacks). * * @internal */ static SLPBoolean ProcessSrvRplyCallback(SLPError errorcode, void * peeraddr, SLPBuffer replybuf, void * cookie) { SLPMessage * replymsg; SLPBoolean result = SLP_TRUE; SLPHandleInfo * handle = (SLPHandleInfo *)cookie; #ifdef ENABLE_SLPv2_SECURITY SLPBoolean securityEnabled = SLPPropertyAsBoolean("net.slp.securityEnabled"); #endif /* Check the errorcode and bail if it is set. */ if (errorcode != SLP_OK) return CollateToSLPSrvURLCallback(handle, 0, 0, errorcode); /* parse the replybuf */ replymsg = SLPMessageAlloc(); if (replymsg) { if (!SLPMessageParseBuffer(peeraddr, 0, replybuf, replymsg)) { if (replymsg->header.functionid == SLP_FUNCT_SRVRPLY && replymsg->body.srvrply.errorcode == 0) { int i; SLPUrlEntry * urlentry = replymsg->body.srvrply.urlarray; for (i = 0; i < replymsg->body.srvrply.urlcount; i++) { #ifdef ENABLE_SLPv2_SECURITY /* Validate the service authblocks. */ if (securityEnabled && SLPAuthVerifyUrl(handle->hspi, 1, &urlentry[i])) continue; /* Authentication failed, skip this URLEntry. */ #endif result = CollateToSLPSrvURLCallback(handle, urlentry[i].url, (unsigned short)urlentry[i].lifetime, SLP_OK); if (result == SLP_FALSE) break; } } else if (replymsg->header.functionid == SLP_FUNCT_DAADVERT && replymsg->body.daadvert.errorcode == 0) { #ifdef ENABLE_SLPv2_SECURITY if (securityEnabled && SLPAuthVerifyDAAdvert(handle->hspi, 1, &replymsg->body.daadvert)) { /* Verification failed. Ignore message. */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif result = CollateToSLPSrvURLCallback(handle, replymsg->body.daadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK); } else if (replymsg->header.functionid == SLP_FUNCT_SAADVERT) { #ifdef ENABLE_SLPv2_SECURITY if (securityEnabled && SLPAuthVerifySAAdvert(handle->hspi, 1, &replymsg->body.saadvert)) { /* Verification failed. Ignore message. */ SLPMessageFree(replymsg); return SLP_TRUE; } #endif result = CollateToSLPSrvURLCallback(handle, replymsg->body.saadvert.url, SLP_LIFETIME_MAXIMUM, SLP_OK); } } SLPMessageFree(replymsg); } return result; }