예제 #1
0
 void onGotGoodbye(const SyncSource& source, const std::string& reason)
 {
     cout << "I got a Goodbye packet from "
          << hex << (int)source.getID() << "@"
          << dec
          << source.getNetworkAddress() << ":"
          << source.getControlTransportPort() << endl;
     cout << "   Goodbye reason: \"" << reason << "\"" << endl;
 }
예제 #2
0
 // redefined from QueueRTCPManager
 void onGotRR(SyncSource& source, RecvReport& RR, uint8 blocks)
 {
     SingleThreadRTPSession::onGotRR(source,RR,blocks);
     cout << "I got an RR RTCP report from "
          << hex << (int)source.getID() << "@"
          << dec
          << source.getNetworkAddress() << ":"
          << source.getControlTransportPort() << endl;
 }
예제 #3
0
	// redefined from QueueRTCPManager
	void
	onGotSR(SyncSource& source, SendReport& SR, uint8 blocks)
	{
		RTPSession::onGotSR(source,SR,blocks);
		cout << "I got an SR RTCP report from "
		     << hex << (int)source.getID() << "@"
		     << dec
		     << source.getNetworkAddress() << ":" 
		     << source.getControlTransportPort() << endl;
	}
예제 #4
0
/*
 * Processes the initialization response. Returns 0 in case of success, an
 * error code in case of error.
 *
 * @param msg the response from the server
 */
int SyncMLProcessor::processServerAlert(SyncSource& source, SyncML* syncml) {

    int ret             = -1;
    int iterator        = 0;
    AbstractCommand* a  = NULL;
    bool found          = false;

    ret = 0;
    do {
        a = getCommand(syncml->getSyncBody(), ALERT, iterator);
        if (a == NULL) {
            // This happens with the Synthesis server's reply:
            // instead of sending SyncBody/Alert we get SyncBody/Put
            // with device infos and a SyncBody/Get requesting our own
            // device infos. Ignoring the request is not correct, but
            // allows synchronization to proceed and complete eventually
            // without any further errors. For that to work we must not
            // set lastErrorCode here, as it will be checked at the end of
            // the sync.
            //
            // lastErrorCode = ERR_REPRESENTATION;
            // sprintf(lastErrorMsg, "SyncBody/Alert not found!");
            goto finally;
        }
        Alert* alert = (Alert*)a;
        Item* item = NULL;
        ArrayList* itemList = alert->getItems();

        for (int i = 0; i < itemList->size(); i++) {
            item = (Item*)getArrayElement(itemList, i);
            const char *locURI = ((Target*)item->getTarget())->getLocURI();
            if (strcmp( locURI, _wcc(source.getName()) ) == 0) {
                if ( !alert->getData() ) {
                    setError(ERR_REPRESENTATION, "SyncBody/Alert/Data not found!");
                    goto finally;
                }

                source.setSyncMode((SyncMode)alert->getData());
                ret = 0;
                found = true;
                break;
            }
        }
        iterator++;
        if (found)
            break;

    } while(a);

finally:

    return ret;
}
예제 #5
0
	// redefined from QueueRTCPManager
	bool
	onGotSDESChunk(SyncSource& source, SDESChunk& chunk, size_t len)
	{ 
		bool result = RTPSession::onGotSDESChunk(source,chunk,len);
		cout << "I got a SDES chunk from "
		     << hex << (int)source.getID() << "@" 
		     << dec
		     << source.getNetworkAddress() << ":" 
		     << source.getControlTransportPort()
		     << " (" 
		     << source.getParticipant()->getSDESItem(SDESItemTypeCNAME)
		     << ") " << endl;
		return result;
	}
예제 #6
0
파일: rtp.cpp 프로젝트: dyfet/ccrtp
void RTPAudio::onGotHello(const SyncSource &src)
{
	RTPEvent *event = RTPEvent::first;

	slog(Slog::levelDebug) << "hello(" << src.getID() << ") ";
        Participant* p = src.getParticipant();
	slog() << p->getSDESItem(SDESItemTypeCNAME) << std::endl;

	while(event)
	{
		event->gotHello(src);
		event = event->next;
	}
}
예제 #7
0
파일: rtp.cpp 프로젝트: dyfet/ccrtp
void RTPAudio::onGotGoodbye(const SyncSource &src, const string& reason)
{
	RTPEvent *event = RTPEvent::first;

	slog(Slog::levelDebug) << "bye(" << src.getID() << ") ";
	Participant* p = src.getParticipant();
	slog() << p->getSDESItem(SDESItemTypeCNAME) << "; " << reason;
	slog() << std::endl;

	while(event)
	{
		event->gotGoodbye(src, reason);
		event = event->next;
	}
}
static bool checkSourceUnderSync(const WCHAR* sourceName, SyncSource& source) {

    if (!wcscmp(source.getName(), sourceName)) {
        return true;
    }
    return false;
}
예제 #9
0
int SyncMLProcessor::processAlertStatus(SyncSource& source, SyncML* syncml, ArrayList* alerts) {

    int ret = -1;
    const char* name = NULL;
    Status* s     = NULL;
    SourceRef* sourceRef    = NULL;

    if (alerts->size()) {
        ArrayList* list = syncml->getSyncBody()->getCommands();

        for (int i = 0; i < list->size(); i++) {
            // is returned the pointer to the element not a new element
            name = ((AbstractCommand*)(list->get(i)))->getName();
            if (name && strcmp(name, STATUS) == 0) {
                s = (Status*)list->get(i);
                if (strcmp(s->getCmd(), ALERT) == 0) {
                    sourceRef = (SourceRef*)(s->getSourceRef()->get(0));

                    if (sourceRef) {
                        if (strcmp(_wcc(source.getName()),
                                    sourceRef->getValue()) == 0) {
                            ret = getAlertStatusCode(s, _wcc(source.getName()));
                            break;
                        }
                    } else {
                        // Server did not include <SourceRef>, which
                        // is a violation of the standard for commands
                        // which were sent with <SourceRef>. Happens
                        // with Synthesis server if authentication
                        // failed, in which case we can simply ignore
                        // it.
                    }
                }
            }
        }
    }

    // Fire a syncStatus event: Alert status from server
    fireSyncStatusEvent(ALERT, ret, source.getConfig().getName(), source.getConfig().getURI(), NULL, SERVER_STATUS);

    return ret;

}
예제 #10
0
	// redefined from IncomingDataQueue
	void onNewSyncSource(const SyncSource& src)
	{
		cout << "* New synchronization source: " <<
		     hex << (int)src.getID() << endl;
	}
예제 #11
0
int SyncMLProcessor::processItemStatus(SyncSource& source, SyncBody* syncBody) {

    ArrayList* items = NULL;
    Item* item       = NULL;
    SourceRef* sourceRef = NULL;
    Status* s = NULL;
    const char* name = NULL;
    Data* data = NULL;
    int ret = 0;

    ArrayList* list = getCommands(syncBody, STATUS);

    for (int i = 0; i < list->size(); i++) {
        s = (Status*)list->get(i);
        name = s->getCmd();
        data = s->getData();
        if (strcmp(name, SYNC) == 0){
            char *srcname = toMultibyte(source.getName());
            int alertStatus = getAlertStatusCode(s, srcname);
            delete [] srcname;

            /*
            * Try to find if the server send a message together the error code if any
            * The items in the status message should be always one...
            */
            char *statusMessage = NULL;
            items = s->getItems();
			for (int k = 0; k < items->size(); k++) {
                item = (Item*)items->get(k);
                if (item) {
                    ComplexData* cd = item->getData();
                    if (cd) {
                        statusMessage = stringdup(cd->getData());
                    }
                }
            }
            // Fire Sync Status Event: sync status from server
            fireSyncStatusEvent(SYNC, s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), NULL, SERVER_STATUS);

            if(alertStatus < 0 || alertStatus >=300){
                if (statusMessage) {
                    //strcpy(lastErrorMsg, statusMessage);
                    setError( alertStatus, statusMessage);
                } else {
                    //strcpy(lastErrorMsg, "Error in sync status sent by server.");
                    setError( alertStatus, "Error in sync status sent by server.");
                }
                if ((ret = alertStatus) < 0)
                    LOG.error("processItemStatus: status not found in SYNC");
                else
                    LOG.error("processItemStatus: server sent status %d in SYNC", alertStatus);
                break;
            }
            if (statusMessage) {
                delete [] statusMessage;
            }
        }

        else if (strcmp(name, ADD) == 0 ||
            strcmp(name, REPLACE) == 0 ||
            strcmp(name, DEL) == 0) {

            int k;

            items = s->getItems();
            long val = strtol(data->getData() , NULL, 10);
            for (k = 0; k < items->size(); k++) {
                item = (Item*)items->get(k);
                if (item) {
                    Source* itemSource = item->getSource();
                    if (itemSource) {
                        WCHAR *uri = toWideChar(itemSource->getLocURI());

                        ComplexData* cd = item->getData();
                        WCHAR *statusMessage = NULL;
                        if (cd) {
                            statusMessage = toWideChar(cd->getData());
                        }

                        // Fire Sync Status Event: item status from server
                        fireSyncStatusEvent(s->getCmd(), s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), uri, SERVER_STATUS);
                        // Update SyncReport
                        source.getReport()->addItem(SERVER, s->getCmd(), uri, s->getStatusCode(), statusMessage);

                        source.setItemStatus(uri, val, name);
                        delete [] uri;
                        if (statusMessage)
                            delete [] statusMessage;
                    } else {
                        // the item might consist of additional information, as in:
                        // <SourceRef>pas-id-44B544A600000092</SourceRef>
                        // <Data>200</Data>
                        // <Item><Data>Conflict resolved by server</Data></Item>
                    }
                }
            }
            items = s->getSourceRef();
            for (k = 0; k < items->size(); k++) {
                sourceRef = (SourceRef*)items->get(k);
                if (sourceRef) {
                    WCHAR *srcref = toWideChar(sourceRef->getValue());
			        // Fire Sync Status Event: item status from server
                    fireSyncStatusEvent(s->getCmd(), s->getStatusCode(), source.getConfig().getName(), source.getConfig().getURI(), srcref, SERVER_STATUS);
                    // Update SyncReport
                    source.getReport()->addItem(SERVER, s->getCmd(), srcref, s->getStatusCode(), NULL);

                    source.setItemStatus(srcref, val, name);
                    delete [] srcref;
                }
            }
        }
    }

    //deleteArrayList(&list);
    if (list){
        delete list;
        list = NULL;
    }
    return ret;
}
예제 #12
0
size_t
ZrtpQueue::rtpDataPacket(unsigned char* buffer, int32 rtn, InetHostAddress network_address, tpport_t transport_port)
{
     // Special handling of padding to take care of encrypted content.
    // In case of SRTP the padding length field is also encrypted, thus
    // it gives a wrong length. Check and clear padding bit before
    // creating the RTPPacket. Will be set and re-computed after a possible
    // SRTP decryption.
    uint8 padSet = (*buffer & 0x20);
    if (padSet) {
        *buffer = *buffer & ~0x20;          // clear padding bit
    }
    //  build a packet. It will link itself to its source
    IncomingRTPPkt* packet =
        new IncomingRTPPkt(buffer,rtn);

    // Generic header validity check.
    if ( !packet->isHeaderValid() ) {
        delete packet;
        return 0;
    }

    // Look for a CryptoContext for this packet's SSRC
    CryptoContext* pcc = getInQueueCryptoContext(packet->getSSRC());

    // If no crypto context is available for this SSRC but we are already in
    // Secure state then create a CryptoContext for this SSRC.
    // Assumption: every SSRC stream sent via this connection is secured
    // _and_ uses the same crypto parameters.
    if (pcc == NULL) {
        pcc = getInQueueCryptoContext(0);
        if (pcc != NULL) {
            pcc = pcc->newCryptoContextForSSRC(packet->getSSRC(), 0, 0L);
            if (pcc != NULL) {
                pcc->deriveSrtpKeys(0);
                setInQueueCryptoContext(pcc);
            }
        }
    }
    // If no crypto context: then either ZRTP is off or in early state
    // If crypto context is available then unprotect data here. If an error
    // occurs report the error and discard the packet.
    if (pcc != NULL) {
        int32 ret;
        if ((ret = packet->unprotect(pcc)) < 0) {
            if (!onSRTPPacketError(*packet, ret)) {
                delete packet;
                return 0;
            }
        }
        if (started && zrtpEngine->inState(WaitConfAck)) {
            zrtpEngine->conf2AckSecure();
        }
    }

    // virtual for profile-specific validation and processing.
    if (!onRTPPacketRecv(*packet) ) {
        delete packet;
        return 0;
    }
    if (padSet) {
        packet->reComputePayLength(true);
    }
    // get time of arrival
    struct timeval recvtime;
    gettimeofday(&recvtime,NULL);

    bool source_created;
    SyncSourceLink* sourceLink =
            getSourceBySSRC(packet->getSSRC(),source_created);
    SyncSource* s = sourceLink->getSource();
    if ( source_created ) {
        // Set data transport address.
        setDataTransportPort(*s,transport_port);
        // Network address is assumed to be the same as the control one
        setNetworkAddress(*s,network_address);
        sourceLink->initStats();
        // First packet arrival time.
        sourceLink->setInitialDataTime(recvtime);
        sourceLink->setProbation(getMinValidPacketSequence());
        if ( sourceLink->getHello() )
            onNewSyncSource(*s);
    }
    else if ( 0 == s->getDataTransportPort() ) {
        // Test if RTCP packets had been received but this is the
        // first data packet from this source.
        setDataTransportPort(*s,transport_port);
    }

    // Before inserting in the queue,
    // 1) check for collisions and loops. If the packet cannot be
    //    assigned to a source, it will be rejected.
    // 2) check the source is a sufficiently well known source
    // TODO: also check CSRC identifiers.
    if (checkSSRCInIncomingRTPPkt(*sourceLink, source_created,
        network_address, transport_port) &&
        recordReception(*sourceLink,*packet,recvtime) ) {
        // now the packet link is linked in the queues
        IncomingRTPPktLink* packetLink = new IncomingRTPPktLink(packet, sourceLink, recvtime,
                                       packet->getTimestamp() - sourceLink->getInitialDataTimestamp(),
                                       NULL,NULL,NULL,NULL);
        insertRecvPacket(packetLink);
    } else {
        // must be discarded due to collision or loop or
        // invalid source
        delete packet;
        return 0;
    }
    // Start the ZRTP engine after we got a at least one RTP packet and
    // sent some as well or we are in multi-stream mode.
    if (!started && enableZrtp) {
        startZrtp();
    }
    return rtn;
}