コード例 #1
0
ファイル: EventUpnp.cpp プロジェクト: wifigeek/ohNet
void EventSessionUpnp::ProcessNotification(IEventProcessor& aEventProcessor, const Brx& aEntity)
{
    aEventProcessor.EventUpdateStart();
    OutputProcessorUpnp outputProcessor;
    Brn propertySet = XmlParserBasic::Find("propertyset", aEntity);
    Brn prop;
    Brn remaining;
    try {
        for (;;) {
            prop.Set(XmlParserBasic::Find("property", propertySet, remaining));
            prop.Set(Ascii::Trim(prop));
            if (prop.Bytes() < 8 || prop[0] != '<' || prop[1] == '/') {
                THROW(XmlError);
            }
            Parser parser(prop);
            (void)parser.Next('<');
            Brn tagName = parser.Next('>');
            Brn val = parser.Next('<');
            Brn closingTag = parser.Next('/');
            closingTag.Set(parser.Next('>'));
            if (tagName != closingTag) {
                THROW(XmlError);
            }

            try {
                aEventProcessor.EventUpdate(tagName, val, outputProcessor);
            }
            catch(AsciiError&) {
                THROW(XmlError);
            }

            propertySet.Set(remaining);
        }
    }
    catch(XmlError&) {}
    aEventProcessor.EventUpdateEnd();
}
コード例 #2
0
ファイル: EventUpnp.cpp プロジェクト: sewood/ohNet
void EventSessionUpnp::ProcessNotification(IEventProcessor& aEventProcessor, const Brx& aEntity)
{
    aEventProcessor.EventUpdateStart();
    OutputProcessorUpnp outputProcessor;
    Brn propertySet = XmlParserBasic::Find("propertyset", aEntity);
    Brn prop;
    Brn remaining;
    try {
        for (;;) {
            try {
                prop.Set(XmlParserBasic::Find("property", propertySet, remaining));
            }
            catch (XmlError&) {
                // we've successfully processed all <property> tags from aEntity
                break;
            }
            prop.Set(Ascii::Trim(prop));
            if (prop.Bytes() < 8 || prop[0] != '<' || prop[1] == '/') {
                THROW(XmlError);
            }
            Parser parser(prop);
            (void)parser.Next('<');
            Brn tagNameFull = parser.Next('>');
            Brn tagName = tagNameFull;
            TUint bytes = tagNameFull.Bytes();
            TUint i;
            for (i = 0; i < bytes; i++) {
                if (Ascii::IsWhitespace(tagNameFull[i])) {
                    break;
                }
            }
            if (i < bytes) {
                tagName.Set(tagNameFull.Split(0, i));
            }
            Brn val;
            if (bytes > 0 && tagNameFull[bytes-1] == '/') {
                // empty element tag
                val.Set(Brx::Empty());
                if (i == bytes) { // no white space before '/'
                    tagName.Set(tagName.Split(0, bytes-1));
                }
            }
            else {
                val.Set(parser.Next('<'));
                Brn closingTag = parser.Next('/');
                closingTag.Set(parser.Next('>'));
                if (tagName != closingTag) {
                    THROW(XmlError);
                }
            }

            try {
                aEventProcessor.EventUpdate(tagName, val, outputProcessor);
            }
            catch(AsciiError&) {
                THROW(XmlError);
            }

            propertySet.Set(remaining);
        }
        aEventProcessor.EventUpdateEnd();
    }
    catch(XmlError&) {
        aEventProcessor.EventUpdateError();
    }
}
コード例 #3
0
ファイル: CpiDeviceLpec.cpp プロジェクト: Jacik/ohNet
void CpiDeviceLpec::HandleEventedUpdate(const Brx& aUpdate)
{
    Parser parser(aUpdate);
    Brn lpecId = parser.Next(' ');
    Bws<128> sid(iDevice->Udn());
    sid.Append('-');
    sid.Append(lpecId);
    CpiSubscription* subscription = iCpStack.SubscriptionManager().FindSubscription(sid);
    if (subscription == NULL) {
        /* There is a very short window between Subscribe() returning and the new
           subscription being added to its manager.  As a lazy workaround for this,
           sleep for a short period and retry before rejecting the update */
        Thread::Sleep(1000);
        subscription = iCpStack.SubscriptionManager().FindSubscription(sid);
    }
    if (subscription == NULL) {
        LOG(kLpec, "LPEC: evented update received for unknown subscription - ");
        LOG(kLpec, sid);
        LOG(kLpec, "\n");
        return;
    }
    Brn seqBuf = parser.Next(' ');
    TUint seq;
    try {
        seq = Ascii::Uint(seqBuf);
    }
    catch (AsciiError&) {
        LOG(kLpec, "LPEC: invalid sequence number - ");
        LOG(kLpec, seqBuf);
        LOG(kLpec, "in evented update\n");
        subscription->RemoveRef();
        return;
    }
    if (!subscription->UpdateSequenceNumber(seq)) {
        LOG(kLpec, "LPEC: out of sequence update (%d) for ", seq);
        LOG(kLpec, sid);
        LOG(kLpec, "\n");
        subscription->SetNotificationError();
        subscription->RemoveRef();
        return;
    }
    IEventProcessor* processor = static_cast<IEventProcessor*>(subscription);
    processor->EventUpdateStart();
    OutputProcessor outputProcessor;
    try {
        for (;;) {
            Brn propName = parser.Next(' ');
            if (propName.Bytes() == 0) {
                // processed entire update
                break;
            }
            (void)parser.Next(Lpec::kArgumentDelimiter);
            Brn propVal = parser.Next(Lpec::kArgumentDelimiter);
            processor->EventUpdate(propName, propVal, outputProcessor);
        }
        processor->EventUpdateEnd();
    }
    catch (AsciiError&) {
        LOG2(kLpec, kError, "LPEC: Invalid evented update - ");
        LOG2(kLpec, kError, aUpdate);
        LOG2(kLpec, kError, "\n");
        processor->EventUpdateError();
    }
    subscription->Unlock();
    subscription->RemoveRef();
}