예제 #1
0
/*=========================================================================*/
int SLPDv1ProcessMessage(struct sockaddr_in* peeraddr,
                         SLPBuffer recvbuf,
                         SLPBuffer* sendbuf)
/* Processes the SLPv1 message and places the results in sendbuf           */
/*                                                                         */
/* peeraddr - 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.                          */
/*=========================================================================*/
{
    SLPHeader   header;
    SLPMessage  message;
    int         errorcode   = 0;

    if (!G_SlpdProperty.isDA)
    {
        /* SLPv1 messages are handled only by DAs */
        errorcode = SLP_ERROR_VER_NOT_SUPPORTED;
    }

    /* Parse just the message header the reset the buffer "curpos" pointer */
    recvbuf->curpos = recvbuf->start;
    errorcode = SLPv1MessageParseHeader(recvbuf, &header);

    /* TRICKY: Duplicate SRVREG recvbufs *before* parsing them   */
    /*         it because we are going to keep them in the       */
    if (header.functionid == SLP_FUNCT_SRVREG)
    {
        recvbuf = SLPBufferDup(recvbuf);
        if (recvbuf == NULL)
        {
            return SLP_ERROR_INTERNAL_ERROR;
        }
    }

    /* Allocate the message descriptor */
    message = SLPMessageAlloc();
    if (message)
    {
        /* Parse the message and fill out the message descriptor */
        errorcode = SLPv1MessageParseBuffer(peeraddr,recvbuf, message);
        if (errorcode == 0)
        {
            /* Process messages based on type */
            switch (message->header.functionid)
            {
            case SLP_FUNCT_SRVRQST:
                errorcode = v1ProcessSrvRqst(peeraddr, message, sendbuf, errorcode);
                break;

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

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

            case SLP_FUNCT_ATTRRQST:
                errorcode = v1ProcessAttrRqst(peeraddr, message, sendbuf, errorcode);
                break;

            case SLP_FUNCT_SRVTYPERQST:
                errorcode = v1ProcessSrvTypeRqst(peeraddr, message, sendbuf, errorcode);
                break;

            case SLP_FUNCT_DAADVERT:
                /* we are a SLPv2 DA, ignore other v1 DAs */
                (*sendbuf)->end = (*sendbuf)->start;
                break;

            default:
                /* Should never happen... but we're paranoid */
                errorcode = SLP_ERROR_PARSE_ERROR;
                break;
            }   
        }

        if (header.functionid == SLP_FUNCT_SRVREG)
        {
            /* TRICKY: Do not free the message descriptor for SRVREGs */
            /*         because we are keeping them in the database    */
            /*         unless there is an error then we free memory   */
            if (errorcode)
            {
                SLPMessageFree(message);
                SLPBufferFree(recvbuf);
            }
        }
        else
        {
            SLPMessageFree(message);
        }
    }
    else
    {
        /* out of memory */
        errorcode = SLP_ERROR_INTERNAL_ERROR;
    }

    return errorcode;
}                
예제 #2
0
/*=========================================================================*/
int SLPDv1ProcessMessage(struct sockaddr_in* peeraddr,
                         SLPBuffer recvbuf,
                         SLPBuffer* sendbuf,
                         SLPMessage message,
                         int errorcode)
/* Processes the SLPv1 message and places the results in sendbuf           */
/*                                                                         */
/* recvfd   - the socket the message was received on                       */
/*                                                                         */
/* recvbuf  - message to process                                           */
/*                                                                         */
/* sendbuf  - results of the processed message                             */
/*                                                                         */
/* message  - the parsed message from recvbuf                              */
/*                                                                         */
/* errorcode - error code from parsing the SLPv1 packet                    */
/*                                                                         */
/* Returns  - zero on success SLP_ERROR_PARSE_ERROR or                     */
/*            SLP_ERROR_INTERNAL_ERROR on ENOMEM.                          */
/*=========================================================================*/
{

    SLPDLogTraceMsg("IN",peeraddr,recvbuf);
    
    if(!G_SlpdProperty.isDA)
    {
        /* SLPv1 messages are handled only by DAs */
        errorcode = SLP_ERROR_VER_NOT_SUPPORTED;
    }

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

    case SLP_FUNCT_SRVREG:
        errorcode = v1ProcessSrvReg(peeraddr, message, sendbuf, errorcode);
        /* We are a DA so there is no need to register with known DAs */
        break;

    case SLP_FUNCT_SRVDEREG:
        errorcode = v1ProcessSrvDeReg(peeraddr, message, sendbuf, errorcode);
        /* We are a DA so there is no need to deregister with known DAs */
        break;

    case SLP_FUNCT_ATTRRQST:
        errorcode = v1ProcessAttrRqst(peeraddr, message, sendbuf, errorcode);
        break;

    case SLP_FUNCT_SRVTYPERQST:
        errorcode = v1ProcessSrvTypeRqst(peeraddr, message, sendbuf, errorcode);
        break;

    case SLP_FUNCT_DAADVERT:
        errorcode = 0;      /* we are a SLPv2 DA, ignore other DAs */
        (*sendbuf)->end = (*sendbuf)->start;
        break;

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

    SLPDLogTraceMsg("OUT",peeraddr,*sendbuf);

    return errorcode;
}