Beispiel #1
0
/*-------------------------------------------------------------------------*/
void ProcessDAAdvert(SLPDPeerInfo* peerinfo,
                     SLPMessage message,
                     SLPBuffer result)
/*-------------------------------------------------------------------------*/
{

    /* TODO: enable the following when we link to libslp and        */
    /* have SLPParseSrvURL()                                        */
    #if(0)
    SLPSrvURL*      srvurl;
    struct hostent* he;
    #endif 
    
    /* DAAdverts should never be replied to.  Set result buffer to empty*/
    result->end = result->start;
    
    /* Do not look at DAAdverts if we are a DA */
    if(G_SlpdProperty.isDA == 0)
    {
    
        /* Only process if errorcode is not set */
        if(message->body.daadvert.errorcode == SLP_ERROR_OK)
        {
            
            /* TODO: enable the following when we link to libslp and        */
            /* have SLPParseSrvURL()                                        */
            #if(0)  
            /* yes, we could just get the host addr from peer info. Looking */
            /* it up is safer                                               */
            if(SLPParseSrvURL(message->body.daadvert.url, &srvurl) == 0)
            {
                he = gethostbyname(srvurl->s_pcHost);
                if(he)
                {
                    /* Add the DA to a list of known DAs (ignore return)*/
                    SLPDKnownDAAdd((struct in_addr*)(he->h_addr_list[0]),
                                   message->body.daadvert.bootstamp,
                                   message->body.daadvert.scopelist,
                                   message->body.daadvert.scopelistlen);
                }
                
                SLPFree(srvurl);
            }
            #endif
            
            /* TODO: the following is allows for easy DA masquarading (unsafe) */
            /*       remove it when the above is fixed                         */
            SLPDKnownDAAdd(&(peerinfo->peeraddr.sin_addr), 
                           message->body.daadvert.bootstamp,
                           message->body.daadvert.scopelist,
                           message->body.daadvert.scopelistlen);
        }
                                   
        /* If necessary log that we received a DAAdvert */
        if(G_SlpdProperty.traceDATraffic)
        {
            SLPDLogDATrafficMsg("IN", peerinfo, message);
        }
    }
}
Beispiel #2
0
/*=========================================================================*/
int SLPDProcessMessage(struct sockaddr_in* peerinfo,
                       SLPBuffer recvbuf,
                       SLPBuffer* sendbuf)
/* Processes the recvbuf and places the results in sendbuf                 */
/*                                                                         */
/* recvfd   - the socket the message was received on                       */
/*                                                                         */
/* recvbuf  - message to process                                           */
/*                                                                         */
/* sendbuf  - results of the processed message                             */
/*                                                                         */
/* Returns  - zero on success SLP_ERROR_PARSE_ERROR or                     */
/*            SLP_ERROR_INTERNAL_ERROR on ENOMEM.                          */
/*=========================================================================*/
{
    SLPMessage  message   = 0;
    int         errorcode  = 0;

    message = SLPMessageAlloc();
    if(message == 0)
    {
        return SLP_ERROR_INTERNAL_ERROR;
    }

    errorcode = SLPMessageParseBuffer(recvbuf, message);

#if defined(ENABLE_SLPv1)
    if(message->header.version == 1)
        return SLPDv1ProcessMessage(peerinfo, recvbuf, sendbuf,
                                    message, errorcode);
#endif




    /* Log trace message */
    SLPDLogTraceMsg("IN",peerinfo,recvbuf);

    switch(message->header.functionid)
    {
    case SLP_FUNCT_SRVRQST:
        errorcode = ProcessSrvRqst(peerinfo, message, sendbuf, errorcode);
        break;

    case SLP_FUNCT_SRVREG:
        errorcode = ProcessSrvReg(peerinfo, message,sendbuf, errorcode);
        if(errorcode == 0)
        {
            SLPDKnownDAEcho(peerinfo, message, recvbuf);
        }
        break;

    case SLP_FUNCT_SRVDEREG:
        errorcode = ProcessSrvDeReg(peerinfo, message,sendbuf, errorcode);
        if(errorcode == 0)
        {
            SLPDKnownDAEcho(peerinfo, message, recvbuf);
        }
        break;

    case SLP_FUNCT_SRVACK:
        errorcode = ProcessSrvAck(peerinfo, message,sendbuf, errorcode);        
        break;

    case SLP_FUNCT_ATTRRQST:
        errorcode = ProcessAttrRqst(peerinfo, message,sendbuf, errorcode);
        break;

    case SLP_FUNCT_DAADVERT:
        errorcode = ProcessDAAdvert(peerinfo, message, sendbuf, errorcode);
        /* If necessary log that we received a DAAdvert */
        SLPDLogDATrafficMsg("IN", peerinfo, message);
        break;

    case SLP_FUNCT_SRVTYPERQST:
        errorcode = ProcessSrvTypeRqst(peerinfo, message, sendbuf, errorcode);
        break;

    case SLP_FUNCT_SAADVERT:
        errorcode = ProcessSAAdvert(peerinfo, message, sendbuf, errorcode);
        break;

    default:
        /* This may happen on a really early parse error or version not */
        /* supported error */

        /* TODO log errorcode here */

        break;
    }

    /* Log traceMsg of message was received and the one that will be sent */
    SLPDLogTraceMsg("OUT",peerinfo,*sendbuf);

    SLPMessageFree(message);

    /* Log reception of important errors */
    switch(errorcode)
    {
    case SLP_ERROR_DA_BUSY_NOW:
        SLPLog("DA_BUSY from %s\n",
               inet_ntoa(peerinfo->sin_addr));
        break;
    case SLP_ERROR_INTERNAL_ERROR:
        SLPLog("INTERNAL_ERROR from %s\n",
               inet_ntoa(peerinfo->sin_addr));
        break;
    case SLP_ERROR_PARSE_ERROR:
        SLPLog("PARSE_ERROR from %s\n",
               inet_ntoa(peerinfo->sin_addr));
        break;
    case SLP_ERROR_VER_NOT_SUPPORTED:
        SLPLog("VER_NOT_SUPPORTED from %s\n",
               inet_ntoa(peerinfo->sin_addr));
        break;                    
    }

    return errorcode;
}