Ejemplo n.º 1
0
static void RandomiseUdn(DvStack& aDvStack, Bwh& aUdn)
{
    aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
    aUdn.Append('-');
    Bws<Ascii::kMaxUintStringBytes> buf;
    std::vector<NetworkAdapter*>* subnetList = aDvStack.Env().NetworkAdapterList().CreateSubnetList();
    TUint max = (*subnetList)[0]->Address();
    TUint seed = aDvStack.ServerUpnp().Port((*subnetList)[0]->Address());
    SetRandomSeed(seed);
    aDvStack.Env().NetworkAdapterList().DestroySubnetList(subnetList);
    (void)Ascii::AppendDec(buf, Random(max));
    aUdn.Append(buf);
    aUdn.PtrZ();
}
Ejemplo n.º 2
0
DviSessionUpnp::DviSessionUpnp(DvStack& aDvStack, TIpAddress aInterface, TUint aPort, IRedirector& aRedirector)
    : iDvStack(aDvStack)
    , iInterface(aInterface)
    , iPort(aPort)
    , iRedirector(aRedirector)
    , iShutdownSem("DSUS", 1)
{
    iReadBuffer = new Srs<kMaxRequestBytes>(*this);
    iReaderRequest = new ReaderHttpRequest(aDvStack.GetStack(), *iReadBuffer);
    iWriterChunked = new WriterHttpChunked(*this);
    iWriterBuffer = new Sws<kMaxResponseBytes>(*iWriterChunked);
    iWriterResponse = new WriterHttpResponse(*iWriterBuffer);

    iReaderRequest->AddMethod(Http::kMethodGet);
    iReaderRequest->AddMethod(Http::kMethodPost);
    iReaderRequest->AddMethod(Http::kMethodHead);
    iReaderRequest->AddMethod(kUpnpMethodSubscribe);
    iReaderRequest->AddMethod(kUpnpMethodUnsubscribe);

    iReaderRequest->AddHeader(iHeaderHost);
    iReaderRequest->AddHeader(iHeaderContentLength);
    iReaderRequest->AddHeader(iHeaderConnection);
    iReaderRequest->AddHeader(iHeaderExpect);
    iReaderRequest->AddHeader(iHeaderSoapAction);
    iReaderRequest->AddHeader(iHeaderSid);
    iReaderRequest->AddHeader(iHeaderTimeout);
    iReaderRequest->AddHeader(iHeaderNt);
    iReaderRequest->AddHeader(iHeaderCallback);
    iReaderRequest->AddHeader(iHeaderAcceptLanguage);

    iPropertyWriterFactory = new PropertyWriterFactory(iDvStack, aInterface, aPort);
}
Ejemplo n.º 3
0
void TestDvSubscription(CpStack& aCpStack, DvStack& aDvStack)
{
    Environment& env = aDvStack.Env();
    InitialisationParams& initParams = env.InitParams();
    TUint oldMsearchTime = initParams.MsearchTimeSecs();
    initParams.SetMsearchTime(1);
    Print("TestDvSubscription - starting\n");

    Semaphore* sem = new Semaphore("SEM1", 0);
    DeviceBasic* device = new DeviceBasic(aDvStack);
    CpDevices* deviceList = new CpDevices(*sem, device->Udn());
    FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed);
    Brn domainName("openhome.org");
    Brn serviceType("TestBasic");
    TUint ver = 1;
    CpDeviceListUpnpServiceType* list =
                new CpDeviceListUpnpServiceType(aCpStack, domainName, serviceType, ver, added, removed);
    sem->Wait(30*1000); // allow up to 30 seconds to issue the msearch and receive a response
    delete sem;
    deviceList->Test();
    delete list;
    delete deviceList;
    delete device;

    Print("TestDvSubscription - completed\n");
    initParams.SetMsearchTime(oldMsearchTime);
}
Ejemplo n.º 4
0
DvDevices::DvDevices(DvStack& aDvStack)
{
    RandomiseUdn(aDvStack.Env(), gNameDevice1);
    RandomiseUdn(aDvStack.Env(), gNameDevice1_1);
    RandomiseUdn(aDvStack.Env(), gNameDevice1_2);
    RandomiseUdn(aDvStack.Env(), gNameDevice2);

    DviDeviceStandard* device = new DviDeviceStandard(aDvStack, Brn(gNameDevice1));
    iDevices[0] = device;
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "test1");
    device->SetAttribute("Upnp.Version", "1");
    device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1.Ptr());
    AddService(device, new DviService(aDvStack, "a.b.c", "service1", 1));

    device = new DviDeviceStandard(aDvStack, Brn(gNameDevice1_1));
    iDevices[0]->AddDevice(device);
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "test3");
    device->SetAttribute("Upnp.Version", "1");
    device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1_1.Ptr());
    AddService(device, new DviService(aDvStack, "a.b.c", "service2", 1));
    AddService(device, new DviService(aDvStack, "a.b.c", "service3", 1));
    device->SetEnabled();

    device = new DviDeviceStandard(aDvStack, Brn(gNameDevice1_2));
    iDevices[0]->AddDevice(device);
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "test4");
    device->SetAttribute("Upnp.Version", "1");
    device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1_2.Ptr());
    AddService(device, new DviService(aDvStack, "a.b.c", "service4", 1));
    device->SetEnabled();
    iDevices[0]->SetEnabled();

    device = new DviDeviceStandard(aDvStack, Brn(gNameDevice2));
    iDevices[1] = device;
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "test2");
    device->SetAttribute("Upnp.Version", "1");
    device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice2.Ptr());
    AddService(device, new DviService(aDvStack, "a.b.c", "service1", 1));
    AddService(device, new DviService(aDvStack, "a.b.c", "service2", 1));
    iDevices[1]->SetEnabled();
}
Ejemplo n.º 5
0
SsdpNotifier::SsdpNotifier(DvStack& aDvStack)
    : iDvStack(aDvStack)
    , iSocket(aDvStack.Env())
    , iSocketWriter(iSocket, Endpoint(Ssdp::kMulticastPort, Ssdp::kMulticastAddress))
    , iBuffer(iSocketWriter)
    , iWriter(iBuffer)
    , iConfigId(0)
{
}
Ejemplo n.º 6
0
DviService::DviService(DvStack& aDvStack, const TChar* aDomain, const TChar* aName, TUint aVersion)
    : Service(aDvStack.Env(), aDomain, aName, aVersion)
    , iDvStack(aDvStack)
    , iLock("DVSM")
    , iRefCount(1)
    , iPropertiesLock("SPRM")
    , iDisabled(true)
    , iCurrentInvocationCount(0)
    , iDisabledSem("DVSS", 0)
{
    iDisabledSem.Signal();
    iDvStack.Env().AddObject(this);
}
Ejemplo n.º 7
0
DeviceBasic::DeviceBasic(DvStack& aDvStack)
{
    RandomiseUdn(aDvStack.Env(), gDeviceName);
    iDevice = new DvDevice(aDvStack, gDeviceName);
    iDevice->SetAttribute("Upnp.Domain", "openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Test");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", "ohNetTestDevice");
    iDevice->SetAttribute("Upnp.Manufacturer", "None");
    iDevice->SetAttribute("Upnp.ModelName", "ohNet test device");
    iTestBasic = new ProviderTestBasic(*iDevice);
    iDevice->SetEnabled();
}
Ejemplo n.º 8
0
void TestDviDiscovery(DvStack& aDvStack)
{
    InitialisationParams* initParams = aDvStack.Env().InitParams();
    TUint oldMsearchTime = initParams->MsearchTimeSecs();
    initParams->SetMsearchTime(3); // higher time to give valgrind tests a hope of completing

    //Debug::SetLevel(Debug::kNetwork);
    Runner runner("SSDP discovery\n");
    runner.Add(new SuiteAlive(aDvStack));
    runner.Add(new SuiteMsearch(aDvStack));
    runner.Run();

    initParams->SetMsearchTime(oldMsearchTime);
}
Ejemplo n.º 9
0
DviSubscriptionManager::DviSubscriptionManager(DvStack& aDvStack)
    : Thread("DVSM")
    , iDvStack(aDvStack)
    , iLock("DSBM")
    , iFree(aDvStack.Env().InitParams().DvNumPublisherThreads())
{
    const TUint numPublisherThreads = iDvStack.Env().InitParams().DvNumPublisherThreads();
    LOG(kDvEvent, "> DviSubscriptionManager: creating %u publisher threads\n", numPublisherThreads);
    TChar thName[5];
    iPublishers = (Publisher**)malloc(sizeof(*iPublishers) * numPublisherThreads);
    for (TUint i=0; i<numPublisherThreads; i++) {
        (void)sprintf(&thName[0], "DP%2lu", (unsigned long)i);
        iPublishers[i] = new Publisher(&thName[0], iFree);
        iFree.Write(iPublishers[i]);
        iPublishers[i]->Start();
    }
    Start();
}
Ejemplo n.º 10
0
void TestDviDeviceList(CpStack& aCpStack, DvStack& aDvStack)
{
    InitialisationParams* initParams = aDvStack.Env().InitParams();
    TUint oldMsearchTime = initParams->MsearchTimeSecs();
    initParams->SetMsearchTime(1);

//    Debug::SetLevel(/*Debug::kDevice | Debug::kDvDevice | Debug::kXmlFetch | Debug::kError);

    Print("TestDviDeviceList - starting\n");

    DvDevices* devices = new DvDevices(aDvStack);
    CpDevices* deviceList = new CpDevices;
    FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed);

    Print("Count devices implementing service1\n");
    Brn domainName("a.b.c");
    Brn serviceType("service1");
    TUint ver = 1;
    CpDeviceListUpnpServiceType* list =
                new CpDeviceListUpnpServiceType(aCpStack, domainName, serviceType, ver, added, removed);
    std::vector<const char*> udns;
    udns.push_back((const char*)gNameDevice1.Ptr());
    udns.push_back((const char*)gNameDevice2.Ptr());
    deviceList->Validate(udns);
    udns.clear();
    delete list;
    deviceList->Clear();

    Print("Count devices implementing service2\n");
    serviceType.Set("service2");
    list = new CpDeviceListUpnpServiceType(aCpStack, domainName, serviceType, ver, added, removed);
    udns.push_back((const char*)gNameDevice1_1.Ptr());
    udns.push_back((const char*)gNameDevice2.Ptr());
    deviceList->Validate(udns);
    udns.clear();
    delete list;

    delete deviceList;
    delete devices;

    Print("TestDviDeviceList - completed\n");
    initParams->SetMsearchTime(oldMsearchTime);
}
Ejemplo n.º 11
0
DviSubscriptionManager::DviSubscriptionManager(DvStack& aDvStack)
    : Thread("DvSubscriptionMgr")
    , iDvStack(aDvStack)
    , iLock("DSBM")
    , iFree(aDvStack.Env().InitParams()->DvNumPublisherThreads())
{
    const TUint numPublisherThreads = iDvStack.Env().InitParams()->DvNumPublisherThreads();
    LOG(kDvEvent, "> DviSubscriptionManager: creating %u publisher threads\n", numPublisherThreads);
    iPublishers = (Publisher**)malloc(sizeof(*iPublishers) * numPublisherThreads);
    for (TUint i=0; i<numPublisherThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("Publisher %d", i);
        thName.PtrZ();
        iPublishers[i] = new Publisher((const TChar*)thName.Ptr(), iFree);
        iFree.Write(iPublishers[i]);
        iPublishers[i]->Start();
    }
    Start();
}
Ejemplo n.º 12
0
PropertyWriterUpnp::PropertyWriterUpnp(DvStack& aDvStack, const Endpoint& aPublisher, const Endpoint& aSubscriber,
                                       const Brx& aSubscriberPath, const Brx& aSid, TUint aSequenceNumber)
    : iDvStack(aDvStack)
{
    iSocket.Open();
    iSocket.Connect(aSubscriber, aDvStack.GetStack().InitParams().TcpConnectTimeoutMs());
    iWriterChunked = new WriterHttpChunked(iSocket);
    iWriteBuffer = new Sws<kMaxRequestBytes>(*iWriterChunked);
    iWriterEvent = new WriterHttpRequest(*iWriteBuffer);
    SetWriter(*iWriteBuffer);

    iWriterEvent->WriteMethod(kUpnpMethodNotify, aSubscriberPath, Http::eHttp11);

    IWriterAscii& writer = iWriterEvent->WriteHeaderField(Http::kHeaderHost);
    Endpoint::EndpointBuf buf;
    aPublisher.AppendEndpoint(buf);
    writer.Write(buf);
    writer.WriteFlush();

    iWriterEvent->WriteHeader(Http::kHeaderContentType, Brn("text/xml; charset=\"utf-8\""));
    iWriterEvent->WriteHeader(kUpnpHeaderNt, Brn("upnp:event"));
    iWriterEvent->WriteHeader(kUpnpHeaderNts, Brn("upnp:propchange"));

    writer = iWriterEvent->WriteHeaderField(HeaderSid::kHeaderSid);
    writer.Write(HeaderSid::kFieldSidPrefix);
    writer.Write(aSid);
    writer.WriteFlush();

    iWriterEvent->WriteHeader(Http::kHeaderTransferEncoding, Http::kTransferEncodingChunked);

    writer = iWriterEvent->WriteHeaderField(kUpnpHeaderSeq);
    writer.WriteUint(aSequenceNumber);
    writer.WriteFlush();

    iWriterEvent->WriteHeader(Http::kHeaderConnection, Http::kConnectionClose);
    iWriterEvent->WriteFlush();
    iWriterChunked->SetChunked(true);

    iWriteBuffer->Write(Brn("<?xml version=\"1.0\"?>"));
    iWriteBuffer->Write(Brn("<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">"));
}
Ejemplo n.º 13
0
void Ssdp::WriteNextBootId(DvStack& aDvStack, IWriterHttpHeader& aWriter)
{
    IWriterAscii& stream = aWriter.WriteHeaderField(Ssdp::kHeaderNextBootId);
    stream.WriteUint(aDvStack.NextBootId());
    stream.WriteFlush();
}