owamp/protocol.c
/*
 * This function is called on the server side to read the first block
 * of client requests. The remaining read request messages MUST be called
 * next!.
 * It is also called by the client side from OWPStopSessionsWait and
 * OWPStopSessions.
 *
 * This function does NOT add any data to the HMAC.
 */
This function is called on the server side to read the first block
of client requests. The remaining read request messages MUST be called
next!.
It is also called by the client side from OWPStopSessionsWait and
OWPStopSessions.

This function does NOT add any data to the HMAC.
This function is called on the server side to read the first block of client requests . The remaining read request messages MUST be called next! . It is also called by the client side from OWPStopSessionsWait and OWPStopSessions . This function does NOT add any data to the HMAC .
OWPRequestType
OWPReadRequestType(
        OWPControl  cntrl,
        int         *retn_on_intr
        )
{
    uint8_t msgtype;
    int     n;
    int     ival=0;
    int     *intr = &ival;
    if(retn_on_intr){
        intr = retn_on_intr;
    }
    if(!_OWPStateIsRequest(cntrl) || _OWPStateIsReading(cntrl)){
        OWPError(cntrl->ctx,OWPErrFATAL,OWPErrINVALID,
                "OWPReadRequestType:called in wrong state.");
        return OWPReqInvalid;
    }
    n = _OWPReceiveBlocksIntr(cntrl,(uint8_t *)cntrl->msg,1,intr);
    if(n != 1){
        cntrl->state = _OWPStateInvalid;
        if((n < 0) && *intr && (errno == EINTR)){
            return OWPReqSockIntr;
        }
        return OWPReqSockClose;
    }
    msgtype = *(char *)cntrl->msg;
    if((_OWPStateIs(_OWPStateTest,cntrl) && (msgtype != 3)) ||
            (!_OWPStateIs(_OWPStateTest,cntrl) && (msgtype == 3))){
        cntrl->state = _OWPStateInvalid;
        OWPError(cntrl->ctx,OWPErrFATAL,OWPErrINVALID,
                "OWPReadRequestType: Invalid request.");
        return OWPReqInvalid;
    }
    switch(msgtype){
        case        1:
            cntrl->state |= _OWPStateTestRequest;
            break;
        case        2:
            cntrl->state |= _OWPStateStartSessions;
            break;
        case        3:
            cntrl->state |= _OWPStateStopSessions;
            break;
        case        4:
            cntrl->state |= _OWPStateFetchSession;
            break;
        case        5:
            cntrl->state |= _OWPStateTestRequestTW;
            break;
        default:
            cntrl->state = _OWPStateInvalid;
            OWPError(cntrl->ctx,OWPErrFATAL,OWPErrINVALID,
                    "OWPReadRequestType: Unknown msg:%d",msgtype);
            return OWPReqInvalid;
    }
    return (OWPRequestType)msgtype;
}
OWPRequestType OWPReadRequestType ( OWPControl cntrl , int * retn_on_intr ) { uint8_t msgtype ; int n ; int ival = 0 ; int * intr = & ival ; if ( retn_on_intr ) { intr = retn_on_intr ; } if ( ! _OWPStateIsRequest ( cntrl ) || _OWPStateIsReading ( cntrl ) ) { OWPError ( cntrl -> ctx , OWPErrFATAL , OWPErrINVALID , " " ) ; return OWPReqInvalid ; } n = _OWPReceiveBlocksIntr ( cntrl , ( uint8_t * ) cntrl -> msg , 1 , intr ) ; if ( n != 1 ) { cntrl -> state = _OWPStateInvalid ; if ( ( n < 0 ) && * intr && ( errno == EINTR ) ) { return OWPReqSockIntr ; } return OWPReqSockClose ; } msgtype = * ( char * ) cntrl -> msg ; if ( ( _OWPStateIs ( _OWPStateTest , cntrl ) && ( msgtype != 3 ) ) || ( ! _OWPStateIs ( _OWPStateTest , cntrl ) && ( msgtype == 3 ) ) ) { cntrl -> state = _OWPStateInvalid ; OWPError ( cntrl -> ctx , OWPErrFATAL , OWPErrINVALID , " " ) ; return OWPReqInvalid ; } switch ( msgtype ) { case 1 : cntrl -> state |= _OWPStateTestRequest ; break ; case 2 : cntrl -> state |= _OWPStateStartSessions ; break ; case 3 : cntrl -> state |= _OWPStateStopSessions ; break ; case 4 : cntrl -> state |= _OWPStateFetchSession ; break ; case 5 : cntrl -> state |= _OWPStateTestRequestTW ; break ; default : cntrl -> state = _OWPStateInvalid ; OWPError ( cntrl -> ctx , OWPErrFATAL , OWPErrINVALID , " " , msgtype ) ; return OWPReqInvalid ; } return ( OWPRequestType ) msgtype ; }
This function is called on the server side to read the first block
 of client requests.
This function is called on the server side to read the first block of client requests .
/* Read one block so we can peek at the message type */ /*
     * StopSessions(3) message is only allowed during active tests,
     * and it is the only message allowed during active tests.
     */ /*
         * TestRequest
         */