📄 slpd_knownda.c
字号:
size += spistrlen; size += daadvertauthlen; #endif result = SLPBufferRealloc(result, size); if ( result == 0 ) { /* Out of memory, what should we do here! */ errorcode = SLP_ERROR_INTERNAL_ERROR; goto FINISHED; } /*----------------*/ /* Add the header */ /*----------------*/ /*version*/ *(result->start) = 2; /*function id*/ *(result->start + 1) = SLP_FUNCT_DAADVERT; /*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,xid); /*lang tag len*/ ToUINT16(result->start + 12, G_SlpdProperty.localeLen); /*lang tag*/ memcpy(result->start + 14, G_SlpdProperty.locale, G_SlpdProperty.localeLen); result->curpos = result->start + 14 + G_SlpdProperty.localeLen; /*--------------------------*/ /* Add rest of the DAAdvert */ /*--------------------------*/ /* error code */ ToUINT16(result->curpos,errorcode); result->curpos = result->curpos + 2; if ( errorcode == 0 ) { /* timestamp */ if ( deadda ) { ToUINT32(result->curpos,0); } else { ToUINT32(result->curpos,G_SlpdProperty.DATimestamp); } result->curpos = result->curpos + 4; /* url len */ ToUINT16(result->curpos, G_SlpdProperty.myUrlLen); result->curpos = result->curpos + 2; /* url */ memcpy(result->curpos, G_SlpdProperty.myUrl, G_SlpdProperty.myUrlLen); result->curpos = result->curpos + G_SlpdProperty.myUrlLen; /* scope list len */ ToUINT16(result->curpos, G_SlpdProperty.useScopesLen); result->curpos = result->curpos + 2; /* scope list */ memcpy(result->curpos, G_SlpdProperty.useScopes, G_SlpdProperty.useScopesLen); result->curpos = result->curpos + G_SlpdProperty.useScopesLen; /* attr list len */ ToUINT16(result->curpos, 0); result->curpos = result->curpos + 2; /* attr list */ /* memcpy(result->start, ???, 0); */ /* result->curpos = result->curpos + daentry->attrlistlen; */ /* SPI List */#ifdef ENABLE_SLPv2_SECURITY ToUINT16(result->curpos,spistrlen); result->curpos = result->curpos + 2; memcpy(result->curpos,spistr,spistrlen); result->curpos = result->curpos + spistrlen;#else ToUINT16(result->curpos,0); result->curpos = result->curpos + 2;#endif /* authblock count */#ifdef ENABLE_SLPv2_SECURITY if ( daadvertauth ) { /* authcount */ *(result->curpos) = 1; result->curpos = result->curpos + 1; /* authblock */ memcpy(result->curpos,daadvertauth,daadvertauthlen); result->curpos = result->curpos + daadvertauthlen; } else#endif { *(result->curpos) = 0; result->curpos = result->curpos + 1; } } FINISHED:#ifdef ENABLE_SLPv2_SECURITY if ( daadvertauth ) xfree(daadvertauth); if ( spistr ) xfree(spistr);#endif *sendbuf = result; return errorcode;}#if defined(ENABLE_SLPv1)/*=========================================================================*/int SLPDKnownDAGenerateMyV1DAAdvert(int errorcode, int encoding, unsigned int xid, SLPBuffer* sendbuf)/* Pack a buffer with a v1 DAAdvert using information from a SLPDAentry *//* *//* errorcode (IN) the errorcode for the DAAdvert *//* *//* encoding (IN) the SLPv1 language encoding for the DAAdvert *//* *//* xid (IN) the xid to for the DAAdvert *//* *//* sendbuf (OUT) pointer to the SLPBuffer that will be packed with a *//* DAAdvert *//* *//* returns: zero on success, non-zero on error *//*=========================================================================*/{ int size = 0; int urllen = INT_MAX; int scopelistlen = INT_MAX; SLPBuffer result = *sendbuf; /*-------------------------------------------------------------*/ /* ensure the buffer is big enough to handle the whole srvrply */ /*-------------------------------------------------------------*/ size = 18; /* 12 bytes for header */ /* 2 errorcode */ /* 2 bytes for url len */ /* 2 bytes for scope list len */ if ( !errorcode ) { errorcode = SLPv1ToEncoding(0, &urllen, encoding, G_SlpdProperty.myUrl, G_SlpdProperty.myUrlLen); if ( !errorcode ) { size += urllen;#ifndef FAKE_UNSCOPED_DA errorcode = SLPv1ToEncoding(0, &scopelistlen, encoding, G_SlpdProperty.useScopes, G_SlpdProperty.useScopesLen);#else scopelistlen = 0; /* pretend that we're unscoped */#endif if ( !errorcode ) { size += scopelistlen; } } } else { /* don't add these */ urllen = scopelistlen = 0; } result = SLPBufferRealloc(result, size); if ( result == 0 ) { /* TODO: out of memory, what should we do here! */ errorcode = SLP_ERROR_INTERNAL_ERROR; goto FINISHED; } /*----------------*/ /* Add the header */ /*----------------*/ /*version*/ *(result->start) = 1; /*function id*/ *(result->start + 1) = SLP_FUNCT_DAADVERT; /*length*/ ToUINT16(result->start + 2, size); /*flags - TODO we have to handle monoling and all that crap */ ToUINT16(result->start + 4, (size > SLP_MAX_DATAGRAM_SIZE ? SLPv1_FLAG_OVERFLOW : 0)); /*dialect*/ *(result->start + 5) = 0; /*language code*/ if ( G_SlpdProperty.locale ) { memcpy(result->start + 6, G_SlpdProperty.locale, 2); } ToUINT16(result->start + 8, encoding); /*xid*/ ToUINT16(result->start + 10,xid); result->curpos = result->start + 12; /*--------------------------*/ /* Add rest of the DAAdvert */ /*--------------------------*/ /* error code */ ToUINT16(result->curpos,errorcode); result->curpos = result->curpos + 2; ToUINT16(result->curpos, urllen); result->curpos = result->curpos + 2; /* url */ SLPv1ToEncoding(result->curpos, &urllen, encoding, G_SlpdProperty.myUrl, G_SlpdProperty.myUrlLen); result->curpos = result->curpos + urllen; /* scope list len */ ToUINT16(result->curpos, scopelistlen); result->curpos = result->curpos + 2; /* scope list */#ifndef FAKE_UNSCOPED_DA SLPv1ToEncoding(result->curpos, &scopelistlen, encoding, G_SlpdProperty.useScopes, G_SlpdProperty.useScopesLen);#endif result->curpos = result->curpos + scopelistlen; FINISHED: *sendbuf = result; return errorcode;}#endif/*=========================================================================*/void SLPDKnownDAEcho(SLPMessage msg, SLPBuffer buf)/* Echo a srvreg message to a known DA *//* *//* msg (IN) the SrvReg message descriptor *//* *//* buf (IN) the SrvReg message buffer to echo *//* *//* Returns: none *//*=========================================================================*/{ SLPBuffer dup; SLPDatabaseHandle dh; SLPDatabaseEntry* entry; SLPDAAdvert* entrydaadvert; SLPDSocket* sock; const char* msgscope; int msgscopelen; /* Do not echo registrations if we are a DA unless they were made */ /* local through the API! */ if ( G_SlpdProperty.isDA && !ISLOCAL(msg->peer.sin_addr) ) { return; } if ( msg->header.functionid == SLP_FUNCT_SRVREG ) { msgscope = msg->body.srvreg.scopelist; msgscopelen = msg->body.srvreg.scopelistlen; } else if ( msg->header.functionid == SLP_FUNCT_SRVDEREG ) { msgscope = msg->body.srvdereg.scopelist; msgscopelen = msg->body.srvdereg.scopelistlen; } else { /* We only echo SRVREG and SRVDEREG */ return; } dh = SLPDatabaseOpen(&G_SlpdKnownDAs); if ( dh ) { /*-----------------------------------------------------*/ /* Check to see if there is already an identical entry */ /*-----------------------------------------------------*/ while ( 1 ) { entry = SLPDatabaseEnum(dh); if ( entry == NULL ) break; /* entrydaadvert is the DAAdvert message from the database */ entrydaadvert = &(entry->msg->body.daadvert); /* Send to all DAs that have matching scope */ if ( SLPIntersectStringList(msgscopelen, msgscope, entrydaadvert->scopelistlen, entrydaadvert->scopelist) ) { /* Do not echo to ourselves if we are a DA*/ if ( G_SlpdProperty.isDA && SLPCompareString(G_SlpdProperty.myUrlLen, G_SlpdProperty.myUrl, entrydaadvert->urllen, entrydaadvert->url) == 0 ) { /* don't do anything because it makes no sense to echo */ /* to myself */ } else { /*------------------------------------------*/ /* Load the socket with the message to send */ /*------------------------------------------*/ sock = SLPDOutgoingConnect(&(entry->msg->peer.sin_addr)); if ( sock ) { dup = SLPBufferDup(buf); if ( dup )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -