Ejemplo n.º 1
0
void DviProtocolUpnpServiceXmlWriter::GetRelatedVariableName(Bwh& aName, const Brx& aActionName, const Brx& aParameterName)
{
    static const Brn prefix("A_ARG_TYPE_");
    const TUint len = prefix.Bytes() + aActionName.Bytes() + 1 + aParameterName.Bytes();
    aName.Grow(len);
    aName.Append(prefix);
    aName.Append(aActionName);
    aName.Append('_');
    aName.Append(aParameterName);
}
Ejemplo n.º 2
0
static void RandomiseUdn(Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    NetworkInterface* nif = Stack::NetworkInterfaceList().CurrentInterface();
    TUint max = nif->Address();
    delete nif;
    (void)Ascii::AppendDec(buf, Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
Ejemplo n.º 3
0
void OpenHome::TestFramework::RandomiseUdn(Environment& aEnv, Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    std::vector<NetworkAdapter*>* subnetList = aEnv.NetworkAdapterList().CreateSubnetList();
    TUint max = (subnetList->size() > 0? (*subnetList)[0]->Address() : UINT_MAX);
    aEnv.NetworkAdapterList().DestroySubnetList(subnetList);
    (void)Ascii::AppendDec(buf, aEnv.Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
Ejemplo n.º 4
0
static void RandomiseUdn(Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    std::vector<NetworkAdapter*>* subnetList = Stack::NetworkAdapterList().CreateSubnetList();
    TUint max = (*subnetList)[0]->Address();
    TUint seed = DviStack::ServerUpnp().Port((*subnetList)[0]->Address());
    SetRandomSeed(seed);
    Stack::NetworkAdapterList().DestroySubnetList(subnetList);
    (void)Ascii::AppendDec(buf, Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
Ejemplo n.º 5
0
static void RandomiseUdn(Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    NetworkAdapter* nif = Stack::NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    TUint max = nif->Address();
    TUint seed = DviStack::ServerUpnp().Port(nif->Address());
    SetRandomSeed(seed);
    nif->RemoveRef(kAdapterCookie);
    (void)Ascii::AppendDec(buf, Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
Ejemplo n.º 6
0
static void RandomiseUdn(std::string& aUdn)
{
    Bwh udn;
    udn.Grow((TUint)aUdn.length() + 1 + Ascii::kMaxUintStringBytes + 1);
    Brn buf((const TByte*)aUdn.c_str(), (TUint)aUdn.length());
    udn.Append(buf);
    udn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> addr;
    std::vector<NetworkAdapter*>* subnetList = gEnv->NetworkAdapterList().CreateSubnetList();
    TUint max = (*subnetList)[0]->Address();
    TUint seed = gDvStack->ServerUpnp().Port((*subnetList)[0]->Address());
    SetRandomSeed(seed);
    gEnv->NetworkAdapterList().DestroySubnetList(subnetList);
    (void)Ascii::AppendDec(addr, Random(max));
    udn.Append(addr);
    udn.PtrZ();
    aUdn.assign((const char*)udn.Ptr(), udn.Bytes());
}
Ejemplo n.º 7
0
    virtual void UnorderedRemove(ITopology2Group* aItem)
    {
        Bwh* result = new Bwh(100);
        result->Replace(aItem->Device().Udn());
        result->Append(" Group Removed");

        iFactory->Destroy(aItem->Device().Udn());
        iRunner.Result(result);
    }
Ejemplo n.º 8
0
void DviDevice::GetUriBase(Bwh& aUriBase, TIpAddress aInterface, TUint aPort, IDvProtocol& aProtocol)
{
    static const TUint kMaxAddressBytes = 21; // xxx.xxx.xxx.xxx:xxxxx
    const Brx& name = aProtocol.ProtocolName();
    aUriBase.Grow(Http::kUriPrefix.Bytes() + kMaxAddressBytes + iUdn.Bytes() + name.Bytes() + 3); // +2 for slashes after port, udn & name
    aUriBase.Append(Http::kUriPrefix);
    Endpoint endpt(aPort, aInterface);
    Endpoint::EndpointBuf buf;
    endpt.AppendEndpoint(buf);
    aUriBase.Append(buf);
    aUriBase.Append('/');
    aUriBase.Append(iUdn);
    aUriBase.Append('/');
    aUriBase.Append(name);
    aUriBase.Append('/');
}
Ejemplo n.º 9
0
    virtual void UnorderedAdd(ITopology2Group* aItem)
    {
        Bwh* result = new Bwh(100);
        result->Replace(aItem->Device().Udn());
        result->Append(Brn(" Group Added"));
        iRunner.Result(result);

        FunctorGeneric<MockCbData<Brn>*> fRoom = MakeFunctorGeneric(*this, &GroupWatcher::RoomCallback);
        FunctorGeneric<MockCbData<Brn>*> fName = MakeFunctorGeneric(*this, &GroupWatcher::NameCallback);
        FunctorGeneric<MockCbData<TUint>*> fSourceIndex = MakeFunctorGeneric(*this, &GroupWatcher::SourceIndexCallback);
        FunctorGeneric<MockCbData<TBool>*> fStandby = MakeFunctorGeneric(*this, &GroupWatcher::StandbyCallback);

        iFactory->Create<Brn>(aItem->Device().Udn(), aItem->RoomName(), fRoom);
        iFactory->Create<Brn>(aItem->Device().Udn(), aItem->Name(), fName);
        iFactory->Create<TUint>(aItem->Device().Udn(), aItem->SourceIndex(), fSourceIndex);
        iFactory->Create<TBool>(aItem->Device().Udn(), aItem->Standby(), fStandby);

        std::vector<Watchable<ITopology2Source*>*> sources = aItem->Sources();
        for(TUint i=0; i<sources.size(); i++)
        {
            iFactory->Create<ITopology2Source*>(aItem->Device().Udn(), *(sources[i]), MakeFunctorGeneric(*this, &GroupWatcher::SourcesCallback));
        }

    }
Ejemplo n.º 10
0
void InvocationUpnp::ReadResponse()
{
    OutputProcessorUpnp outputProcessor;
    HttpHeaderContentLength headerContentLength;
    HttpHeaderTransferEncoding headerTransferEncoding;
    Bwh entity;

    iReaderResponse.AddHeader(headerContentLength);
    iReaderResponse.AddHeader(headerTransferEncoding);
    iReaderResponse.Read(kResponseTimeoutMs);
    const HttpStatus& status = iReaderResponse.Status();
    if (status != HttpStatus::kOk) {
        LOG2(kService, kError, "InvocationUpnp::ReadResponse, http error %u ", status.Code());
        LOG2(kService, kError, status.Reason());
        LOG2(kService, kError, "\n");
        if (status != HttpStatus::kInternalServerError) {
            iInvocation.SetError(Error::eHttp, status.Code(), status.Reason());
            THROW(HttpError);
        }
    }

    if (headerTransferEncoding.IsChunked()) {
        ReaderHttpChunked dechunker(iReadBuffer);
        dechunker.Read();
        dechunker.TransferTo(entity);
    }
    else {
        TUint length = headerContentLength.ContentLength();
        if (length != 0) {
            Bwh buf(length);
            while (length > 0) {
                TUint readBytes = (length<kMaxReadBytes? length : kMaxReadBytes);
                buf.Append(iReadBuffer.Read(readBytes));
                length -= readBytes;
            }
            buf.TransferTo(entity);
        }
        else { // no content length - read until connection closed by server
            try {
                for (;;) {
                    Brn buf = iReadBuffer.Read(kMaxReadBytes);
                    entity.Grow(entity.Bytes() + kMaxReadBytes);
                    entity.Append(buf);
                }
            }
            catch (ReaderError&) {
                Brn snaffle = iReadBuffer.Snaffle();
                entity.Grow(entity.Bytes() + snaffle.Bytes());
                entity.Append(snaffle);
            }
        }
    }

    if (status == HttpStatus::kInternalServerError) {
        Brn envelope = XmlParserBasic::Find("Envelope", entity);
        Brn body = XmlParserBasic::Find("Body", envelope);
        Brn fault = XmlParserBasic::Find("Fault", body);
        Brn detail = XmlParserBasic::Find("detail", fault);
        Brn code = XmlParserBasic::Find("errorCode", detail);
        Brn description = XmlParserBasic::Find("errorDescription", detail);
        iInvocation.SetError(Error::eUpnp, Ascii::Uint(code), description);
        THROW(HttpError);
    }

    const Invocation::VectorArguments& outArgs = iInvocation.OutputArguments();
    const TUint count = (TUint)outArgs.size();
    Brn envelope = XmlParserBasic::Find("Envelope", entity);
    Brn body = XmlParserBasic::Find("Body", envelope);
    const Brn responseTagTrailer("Response");
    const Brx& actionName = iInvocation.Action().Name();
    TUint len = actionName.Bytes() + responseTagTrailer.Bytes();
    Bwh responseTag(len);
    responseTag.Append(actionName);
    responseTag.Append(responseTagTrailer);
    Brn response = XmlParserBasic::Find(responseTag, body);
    for (TUint i=0; i<count; i++) {
        const Brx& name = outArgs[i]->Parameter().Name();
        Brn value = XmlParserBasic::Find(name, response);
        outArgs[i]->ProcessOutput(outputProcessor, value);
    }
}
Ejemplo n.º 11
0
void EventSessionUpnp::Run()
{
    CpiSubscription* subscription = NULL;
    iErrorStatus = &HttpStatus::kOk;
    try {
        iReaderRequest->Flush();
        iReaderRequest->Read();
        // check headers
        if (iReaderRequest->MethodNotAllowed()) {
            Error(HttpStatus::kBadRequest);
        }

        if (!iHeaderNt.Received() || !iHeaderNts.Received()) {
            Error(HttpStatus::kBadRequest);
        }

        if (iHeaderNt.Value() != kExpectedNt || iHeaderNts.Value() != kExpectedNts ||
            !iHeaderSid.Received() || iHeaderSid.Sid().Bytes() == 0 || !iHeaderSeq.Received()) {
            Error(HttpStatus::kPreconditionFailed);
        }

        subscription = CpiSubscriptionManager::FindSubscription(iHeaderSid.Sid());
        if (subscription == NULL) {
            /* the UPnP spec contains a potential race condition where the first NOTIFY
               message can be processed ahead of the SUBSCRIBE reply which provides
               the sid.  Wait until any in-progress subscriptions complete and try
               again in case that's what has happened here */
            CpiSubscriptionManager::WaitForPendingAdds();
            subscription = CpiSubscriptionManager::FindSubscription(iHeaderSid.Sid());
            if (subscription == NULL) {
                LOG2(kEvent, kError, "notification for unexpected device - ")
                LOG2(kEvent, kError, iHeaderSid.Sid());
                LOG2(kEvent, kError, "\n");
                Error(HttpStatus::kPreconditionFailed);
            }
        }

        if (!subscription->UpdateSequenceNumber(iHeaderSeq.Seq())) {
            subscription->SetNotificationError();
            subscription->RemoveRef();
            subscription = NULL;
        }
    }
    catch(HttpError) {}
    catch(ReaderError) {}

    try {
        // write response
        Sws<128> writerBuffer(*this);
        WriterHttpResponse response(writerBuffer);
        response.WriteStatus(*iErrorStatus, Http::eHttp11);
        response.WriteFlush();

        // read entity
        if (subscription != NULL) {
            Bwh entity;
            if (iHeaderTransferEncoding.IsChunked()) {
                ReaderHttpChunked dechunker(*iReadBuffer);
                dechunker.Read();
                dechunker.TransferTo(entity);
            }
            else {
                TUint length = iHeaderContentLength.ContentLength();
                if (length == 0) {
                    THROW(HttpError);
                }
                entity.Grow(length);
                while (length > 0) {
                    TUint readBytes = (length<kMaxReadBytes? length : kMaxReadBytes);
                    entity.Append(iReadBuffer->Read(readBytes));
                    length -= readBytes;
                }
            }

            // process entity
            LOG(kEvent, "EventSessionUpnp::Run, sid - ");
            LOG(kEvent, iHeaderSid.Sid());
            LOG(kEvent, " seq - %u\n", iHeaderSeq.Seq());
            ProcessNotification(*subscription, entity);
        }
    }
    catch(HttpError) {
        LogError(subscription, "HttpError");
    }
    catch(ReaderError) {
        LogError(subscription, "ReaderError");
    }
    catch(WriterError) {
        LogError(subscription, "WriterError");
    }
    catch(NetworkError) {
        LogError(subscription, "NetworkError");
    }
    catch(XmlError) {
        LogError(subscription, "XmlError");
    }
    if (subscription != NULL) {
        subscription->RemoveRef();
    }    
}