/*=========================================================================*/ int SLPStringListContains(int listlen, const char* list, int stringlen, const char* string) /* Checks a string-list for the occurence of a string */ /* */ /* list - pointer to the string-list to be checked */ /* */ /* listlen - length in bytes of the list to be checked */ /* */ /* string - pointer to a string to find in the string-list */ /* */ /* stringlen - the length of the string in bytes */ /* */ /* Returns - zero if string is NOT contained in the list. non-zero if it*/ /* is. */ /*=========================================================================*/ { char* listend = (char*)list + listlen; char* itembegin = (char*)list; char* itemend = itembegin; while(itemend < listend) { itembegin = itemend; /* seek to the end of the next list item */ while(1) { if(itemend == listend || *itemend == ',') { if (*(itemend - 1) != '\\') { break; } } itemend ++; } if(SLPStringCompare(itemend - itembegin, itembegin, stringlen, string) == 0) { return 1; } itemend ++; } return 0; }
/*-------------------------------------------------------------------------*/ void ProcessSrvRqst(SLPDPeerInfo* peerinfo, SLPMessage message, SLPBuffer result) /*-------------------------------------------------------------------------*/ { int i; int size = 0; int count = 0; int found = 0; SLPDDatabaseSrvUrl* srvarray = 0; int errorcode = 0; /*-------------------------------------------------*/ /* Check for one of our IP addresses in the prlist */ /*-------------------------------------------------*/ if(SLPStringListIntersect(message->body.srvrqst.prlistlen, message->body.srvrqst.prlist, G_SlpdProperty.interfacesLen, G_SlpdProperty.interfaces)) { result->end = result->start; goto FINISHED; } /*------------------------------------------------*/ /* Check to to see if a this is a special SrvRqst */ /*------------------------------------------------*/ if(SLPStringCompare(message->body.srvrqst.srvtypelen, message->body.srvrqst.srvtype, 23, "service:directory-agent") == 0) { ProcessDASrvRqst(peerinfo, message, result); goto FINISHED; } if(SLPStringCompare(message->body.srvrqst.srvtypelen, message->body.srvrqst.srvtype, 21, "service:service-agent") == 0) { ProcessSASrvRqst(peerinfo, message, result); goto FINISHED; } /*------------------------------------*/ /* Make sure that we handle the scope */ /*------ -----------------------------*/ if(SLPStringListIntersect(message->body.srvrqst.scopelistlen, message->body.srvrqst.scopelist, G_SlpdProperty.useScopesLen, G_SlpdProperty.useScopes) != 0) { /*-------------------------------*/ /* Find services in the database */ /*-------------------------------*/ while(found == count) { count += SLPDPROCESS_RESULT_COUNT; if(srvarray) free(srvarray); srvarray = (SLPDDatabaseSrvUrl*)malloc(sizeof(SLPDDatabaseSrvUrl) * count); if(srvarray == 0) { found = 0; errorcode = SLP_ERROR_INTERNAL_ERROR; break; } found = SLPDDatabaseFindSrv(&(message->body.srvrqst), srvarray, count); if(found < 0) { found = 0; errorcode = SLP_ERROR_INTERNAL_ERROR; break; } } } else { errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED; } /*----------------------------------------------------------------*/ /* Do not send error codes or empty replies to multicast requests */ /*----------------------------------------------------------------*/ if(found <= 0 && (message->header.flags & SLP_FLAG_MCAST)) { result->end = result->start; goto FINISHED; } /*-------------------------------------------------------------*/ /* ensure the buffer is big enough to handle the whole srvrply */ /*-------------------------------------------------------------*/ size = message->header.langtaglen + 18; /* 14 bytes for header */ /* 2 bytes for error code */ /* 2 bytes for url count */ for(i=0;i<found;i++) { size += srvarray[i].urllen + 6; /* 1 byte for reserved */ /* 2 bytes for lifetime */ /* 2 bytes for urllen */ /* 1 byte for authcount */ /* TODO: Fix this for authentication */ } result = SLPBufferRealloc(result,size); if(result == 0) { found = 0; errorcode = SLP_ERROR_INTERNAL_ERROR; } /*----------------*/ /* Add the header */ /*----------------*/ /*version*/ *(result->start) = 2; /*function id*/ *(result->start + 1) = SLP_FUNCT_SRVRPLY; /*length*/ ToUINT24(result->start + 2, size); /*flags*/ ToUINT16(result->start + 5, size > SLP_MAX_DATAGRAM_SIZE ? SLP_FLAG_OVERFLOW : 0); /*ext offset*/ ToUINT24(result->start + 7,0); /*xid*/ ToUINT16(result->start + 10,message->header.xid); /*lang tag len*/ ToUINT16(result->start + 12,message->header.langtaglen); /*lang tag*/ memcpy(result->start + 14, message->header.langtag, message->header.langtaglen); /*-------------------------*/ /* Add rest of the SrvRply */ /*-------------------------*/ result->curpos = result->start + 14 + message->header.langtaglen; /* error code*/ ToUINT16(result->curpos, errorcode); result->curpos = result->curpos + 2; /* urlentry count */ ToUINT16(result->curpos, found); result->curpos = result->curpos + 2; for(i=0;i<found;i++) { /* url-entry reserved */ *result->curpos = 0; result->curpos = result->curpos + 1; /* url-entry lifetime */ ToUINT16(result->curpos,srvarray[i].lifetime); result->curpos = result->curpos + 2; /* url-entry urllen */ ToUINT16(result->curpos,srvarray[i].urllen); result->curpos = result->curpos + 2; /* url-entry url */ memcpy(result->curpos,srvarray[i].url,srvarray[i].urllen); result->curpos = result->curpos + srvarray[i].urllen; /* url-entry authcount */ *result->curpos = 0; result->curpos = result->curpos + 1; /* TODO: put in authentication stuff too */ } FINISHED: if(srvarray) free(srvarray); }