Esempio n. 1
0
void Http::WriteHeaderRangeFirstOnly(WriterHttpHeader& aWriter, TUint64 aFirst)
{
    Bws<6+20+1> buf;
    buf.Append(Http::kRangeBytes);
    Ascii::AppendDec(buf, aFirst);
    buf.Append(Http::kRangeSeparator);

    aWriter.WriteHeader(Http::kHeaderRange, buf);
}
Esempio n. 2
0
void CpiDeviceUpnp::GetServiceUri(Uri& aUri, const TChar* aType, const ServiceType& aServiceType)
{
    Brn root = XmlParserBasic::Find("root", iXml);
    Brn device = XmlParserBasic::Find("device", root);
    Brn udn = XmlParserBasic::Find("UDN", device);
    if (!CpiDeviceUpnp::UdnMatches(udn, Udn())) {
        Brn deviceList = XmlParserBasic::Find("deviceList", device);
        do {
            Brn remaining;
            device.Set(XmlParserBasic::Find("device", deviceList, remaining));
            udn.Set(XmlParserBasic::Find("UDN", device));
            deviceList.Set(remaining);
        } while (!CpiDeviceUpnp::UdnMatches(udn, Udn()));
    }
    Brn serviceList = XmlParserBasic::Find("serviceList", device);
    Brn service;
    Brn serviceType;
    Brn devServiceTypeNoVer;
    const Brx& targServiceType = aServiceType.FullName();
    // Must have backwards compatibility. Need to compare service type and version separately.
    Parser serviceParser = targServiceType;
    serviceParser.Next(':');    // urn
    serviceParser.Next(':');    // schema url
    serviceParser.Next(':');    // service
    serviceParser.Next(':');    // name
    Brn targServiceTypeNoVer(targServiceType.Ptr(), serviceParser.Index()); // full name minus ":x" (where x is version)
    do {
        Brn remaining;
        service.Set(XmlParserBasic::Find("service", serviceList, remaining));
        serviceType.Set(XmlParserBasic::Find("serviceType", service));
        serviceList.Set(remaining);
        // Parse service type and version separately.
        serviceParser.Set(serviceType);
        serviceParser.Next(':');    // urn
        serviceParser.Next(':');    // schema url
        serviceParser.Next(':');    // service
        serviceParser.Next(':');    // name
        devServiceTypeNoVer.Set(serviceType.Ptr(), serviceParser.Index()); // full name minus ":x" (where x is version)
        // MUST allow use of device with version >= target version
    } while (devServiceTypeNoVer != targServiceTypeNoVer);
    Brn path = XmlParserBasic::Find(aType, service);
    if (path.Bytes() == 0) {
        // no event url => service doesn't have any evented state variables
        THROW(XmlError);
    }

    // now create a uri using the scheme/host/port of the device xml location
    // plus the path we've just constructed
    Bws<40> base; // just need space for http://xxx.xxx.xxx.xxx:xxxxx
    aUri.Replace(iLocation);
    base.Append(aUri.Scheme());
    base.Append("://");
    base.Append(aUri.Host());
    base.Append(':');
    Ascii::AppendDec(base, aUri.Port());
    aUri.Replace(base, path);
}
Esempio n. 3
0
void CpiSubscription::DoSubscribe()
{
    CpStack& cpStack = iDevice.GetCpStack();
    Bws<Uri::kMaxUriBytes> uri;
    uri.Append(Http::kSchemeHttp);
    NetworkAdapter* nif = cpStack.Env().NetworkAdapterList().CurrentAdapter("CpiSubscription::DoSubscribe");
    if (nif == NULL) {
        THROW(NetworkError);
    }
    TIpAddress nifAddr = nif->Address();
    nif->RemoveRef("CpiSubscription::DoSubscribe");
    Endpoint endpt(cpStack.SubscriptionManager().EventServerPort(), nifAddr);
    Endpoint::EndpointBuf buf;
    endpt.AppendEndpoint(buf);
    uri.Append(buf);
    uri.Append('/');
    Uri subscriber(uri);

    LOG(kEvent, "Subscribing - service = ");
    LOG(kEvent, iServiceType.FullName());
    LOG(kEvent, "\n    subscriber = ");
    LOG(kEvent, subscriber.AbsoluteUri());
    LOG(kEvent, "\n");

    iNextSequenceNumber = 0;
    TUint renewSecs;
    try {
        renewSecs = iDevice.Subscribe(*this, subscriber);
    }
    catch (XmlError&) {
        // we don't expect to ever get here.  Its worth capturing some debug info if we do.
        Brh deviceXml;
        if (!iDevice.GetAttribute("Upnp.DeviceXml", deviceXml)) {
            deviceXml.Set("[missing]");
        }
        const Brx& udn = iDevice.Udn();
        cpStack.Env().Mutex().Wait();
        Log::Print("XmlError attempting to subscribe to device ");
        Log::Print(udn);
        Log::Print(", with xml\n\n");
        Log::Print(deviceXml);
        Log::Print("\n\n");
        cpStack.Env().Mutex().Signal();
        THROW(XmlError);
    }

    cpStack.SubscriptionManager().Add(*this);

    LOG(kEvent, "Subscription for ");
    LOG(kEvent, iServiceType.FullName());
    LOG(kEvent, " completed\n    Sid is ");
    LOG(kEvent, iSid);
    LOG(kEvent, "\n    Renew in %u secs\n", renewSecs);

    SetRenewTimer(renewSecs);
}
Esempio n. 4
0
Brn DeviceXml::ServiceVersion(const Brx& aServiceType) const
{
    const TUint kMaxDomainBytes = 64;
    const TUint kMaxTypeBytes = 64;
    
    Bws<kMaxDomainBytes> domain;
    Bws<kMaxTypeBytes> upnpType;
    
    Parser parser(aServiceType);
    
    TUint count = 0;
    
    while (!parser.Finished()) {
        upnpType.Replace(parser.Next('.'));
        count++;
    }

    parser.Restart();
        
    while (--count) {
        Brn element = parser.Next('.');
        
        if (domain.Bytes() > 0) {
            domain.Append('.');
        }
        
        domain.Append(element);
    }
    
    Bws<kMaxDomainBytes> upnpDomain;
    
    Ssdp::CanonicalDomainToUpnp(domain, upnpDomain);
    
    Brn serviceList = XmlParserBasic::Find("serviceList", iXml);
    
    for (;;) {
        Brn service = XmlParserBasic::Find("service", serviceList, serviceList);
        Brn type = XmlParserBasic::Find("serviceType", service);

        Parser parser(type);
        
        if (parser.Next(':') == Brn("urn")) {
            if (parser.Next(':') == upnpDomain) {
                if (parser.Next(':') == Brn("service")) {
                    if (parser.Next(':') == upnpType) {
                        return (parser.Remaining());
                    }
                }
            }
        }
    }
}
Esempio n. 5
0
TUint Ascii::AppendDec(Bwx& aBuffer, TInt64 aValue)
{
    Bws<20> reversed; // Maximum value requires 20 digits

    if (aValue == 0) {
        aBuffer.Append('0');
        return (1);
    }

    TUint extra = 0;

    if (aValue < 0) {
        aBuffer.Append('-');
        extra++;
    }

    while(aValue != 0) {
        reversed.Append((TChar)('0' + abs((TInt)(aValue % 10))));
        aValue = aValue / 10;
    }

    for (TUint i = reversed.Bytes(); i > 0; i--) {
        aBuffer.Append(reversed[i - 1]);
    }

    return (reversed.Bytes() + extra);
}
Esempio n. 6
0
 void StandbyCallback(MockCbData<TBool>* aArgs)
 {
     TBool i = aArgs->iData;
     FunctorGeneric<const Brx&> f = aArgs->iCallback;
     Bws<100> buf;
     buf.Replace(Brn("Standby "));
     if (i)
     {
         buf.Append(Brn("True"));
     }
     else
     {
         buf.Append(Brn("False"));
     }
     f(buf);
     delete aArgs;
 }
Esempio n. 7
0
void SuiteFileStream::Test()
{
    const TUint kBytes = 256;
    Bws<kBytes> b;
    // Populate each position in the buffer with it's index.
    for (TUint i=0; i<kBytes; i++) {
        b.Append((TChar)i);
    }
    FileBrx f(b);
    FileStream stream;
    stream.SetFile(&f);
    TEST(stream.Bytes() == kBytes);

    // test basic reading
    Bws<kBytes> buf;
    stream.Read(buf);
    TEST(buf == b);
    TEST(stream.Tell() == kBytes);

    // test that reads on a full buffer and at the end of a file throw
    TEST_THROWS(stream.Read(buf), ReaderError);
    buf.SetBytes(0);
    TEST_THROWS(stream.Read(buf), ReaderError);

    // test seeking
    stream.Seek(0);
    TEST(stream.Tell() == 0);

    // test a stream can be (un)interrupted
    stream.ReadInterrupt();
    Bws<10> buf2;
    TEST_THROWS(stream.Read(buf2), ReaderError);
    stream.Interrupt(false);
    stream.Read(buf2);
    TEST(buf2.Bytes() == buf2.MaxBytes());
    for (TUint i=0; i<10; i++) {
        TEST(buf2[i] == b[i]);
    }
    
    // test that Read appends to a buffer
    buf.SetBytes(0);
    buf.Append(buf2);
    stream.Read(buf);
    TEST(buf.Bytes() == kBytes);
    TEST(buf == b);
}
Esempio n. 8
0
    void SourcesCallback(MockCbData<ITopology2Source*>* aArgs)
    {
        // w("Source " + v.Index + " " + v.Name + " " + v.Type + " " + v.Visible));
        ITopology2Source* src = aArgs->iData;
        FunctorGeneric<const Brx&> f = aArgs->iCallback;

        Bws<100> buf;
        buf.Replace(Brn("Source "));
        Ascii::AppendDec(buf, src->Index());
        buf.Append(Brn(" "));

        Brn name(src->Name());

        buf.Append(src->Name());
        buf.Append(Brn(" "));
        buf.Append(src->Type());
        buf.Append(Brn(" "));
        if (src->Visible())
        {
            buf.Append(Brn("True"));
        }
        else
        {
            buf.Append(Brn("False"));
        }
        f(buf);
        delete aArgs;
    }
Esempio n. 9
0
 void NameCallback(MockCbData<Brn>* aArgs)
 {
     Brn str = aArgs->iData;
     FunctorGeneric<const Brx&> f = aArgs->iCallback;
     Bws<100> buf;
     buf.Replace(Brn("Name "));
     buf.Append(str);
     f(buf);
     delete aArgs;
 }
Esempio n. 10
0
void CpiDeviceUpnp::GetServiceUri(Uri& aUri, const TChar* aType, const ServiceType& aServiceType)
{
    Brn root = XmlParserBasic::Find("root", iXml);
    Brn device = XmlParserBasic::Find("device", root);
    Brn udn = XmlParserBasic::Find("UDN", device);
    if (!CpiDeviceUpnp::UdnMatches(udn, Udn())) {
        Brn deviceList = XmlParserBasic::Find("deviceList", device);
        do {
            Brn remaining;
            device.Set(XmlParserBasic::Find("device", deviceList, remaining));
            udn.Set(XmlParserBasic::Find("UDN", device));
            deviceList.Set(remaining);
        } while (!CpiDeviceUpnp::UdnMatches(udn, Udn()));
    }
    Brn serviceList = XmlParserBasic::Find("serviceList", device);
    Brn service;
    Brn serviceType;
    const Brx& targServiceType = aServiceType.FullName();
    do {
        Brn remaining;
        service.Set(XmlParserBasic::Find("service", serviceList, remaining));
        serviceType.Set(XmlParserBasic::Find("serviceType", service));
        serviceList.Set(remaining);
    } while (serviceType != targServiceType);
    Brn path = XmlParserBasic::Find(aType, service);
    if (path.Bytes() == 0) {
        // no event url => service doesn't have any evented state variables
        THROW(XmlError);
    }

    // now create a uri using the scheme/host/port of the device xml location
    // plus the path we've just constructed
    Bws<40> base; // just need space for http://xxx.xxx.xxx.xxx:xxxxx
    aUri.Replace(iLocation);
    base.Append(aUri.Scheme());
    base.Append("://");
    base.Append(aUri.Host());
    base.Append(':');
    Ascii::AppendDec(base, aUri.Port());
    aUri.Replace(base, path);
}
Esempio n. 11
0
TUint Ascii::AppendDec(Bwx& aBuffer, TUint64 aValue)
{
    Bws<20> reversed; // Maximum value requires 20 digits

    if (aValue == 0) {
        aBuffer.Append('0');
        return (1);
    }

    while(aValue > 0) {
        reversed.Append((TChar)('0' + aValue % 10));
        aValue = aValue / 10;
    }

    for (TUint i = reversed.Bytes(); i > 0; i--) {
        aBuffer.Append(reversed[i - 1]);
    }

    return (reversed.Bytes());
}
Esempio n. 12
0
void WsProtocol80::Read(Brn& aData, TBool& aClosed)
{
    aData.Set(NULL, 0);
    aClosed = false;

    static const TByte kBitMaskFinalFragment = 1<<7;
    static const TByte kBitMaskRsv123        = 0x70;
    static const TByte kBitMaskOpcode        = 0xf;
    static const TByte kBitMaskPayloadMask   = 1<<7;
    static const TByte kBitMaskPayloadLen    = 0x7f;

    // validate framing
    Bws<2> ctrl;
    ctrl.Append(iReadBuffer.Read(2));
    const TByte& byte0 = ctrl.At(0);
    const TByte& byte1 = ctrl.At(1);
    const TBool fragment = ((byte0 & kBitMaskFinalFragment) == 0);
    if (byte0 & kBitMaskRsv123) {
        LOG2(kDvWebSocket, kError, "WS: RSV bit(s) set - %u - but no extension negotiated\n", (byte0 & kBitMaskRsv123) >> 4);
        Close(kCloseProtocolError);
        aClosed = true;
        return;
    }
Esempio n. 13
0
void SuiteFileBrx::Test()
{
    const TUint kBytes = 256;
    Bws<kBytes> b;
    // Populate each position in the buffer with it's index.
    for (TUint i=0; i<kBytes; i++) {
        b.Append((TChar)i);
    }

    FileBrx f(b);
    Bws<kBytes> buff;

    f.Read(buff);       // Read full buffer
    TEST(buff == b);

    buff.SetBytes(0);
    TEST_THROWS(f.Read(buff), FileReadError); // Attempt full buffer from end

    f.Seek(0, eSeekFromStart);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 0);
    TEST(buff[9] == 9);

    f.Seek(10, eSeekFromStart);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 10);
    TEST(buff[9] == 19);
    
    f.Seek(10, eSeekFromCurrent);
    buff.SetBytes(0);
    f.Read(buff, 10);
    TEST(buff[0] == 30);
    TEST(buff[9] == 39);
}
Esempio n. 14
0
ExampleMediaPlayer::ExampleMediaPlayer(HWND hwnd,
                                       Net::DvStack& aDvStack,
                                       const Brx& aUdn,
                                       const TChar* aRoom,
                                       const TChar* aProductName,
                                       const Brx& aUserAgent)
    : iSemShutdown("TMPS", 0)
    , iDisabled("test", 0)
    , iHwnd(hwnd)
    , iCpProxy(NULL)
    , iTxTimestamper(NULL)
    , iRxTimestamper(NULL)
    , iTxTsMapper(NULL)
    , iRxTsMapper(NULL)
    , iUserAgent(aUserAgent)
{
    iShell = new Shell(aDvStack.Env(), kShellPort);
    iShellDebug = new ShellCommandDebug(*iShell);

    Bws<256> friendlyName;
    friendlyName.Append(aRoom);
    friendlyName.Append(':');
    friendlyName.Append(aProductName);

    // create UPnP device
    iDevice = new DvDeviceStandard(aDvStack, aUdn, *this);
    iDevice->SetAttribute("Upnp.Domain", "av.openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Source");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", friendlyName.PtrZ());
    iDevice->SetAttribute("Upnp.Manufacturer", "OpenHome");
    iDevice->SetAttribute("Upnp.ModelName", "ExampleMediaPlayer");

    // create separate UPnP device for standard MediaRenderer
    Bws<256> buf(aUdn);
    buf.Append("-MediaRenderer");

    // The renderer name should be <room name>:<UPnP AV source name> to allow
    // our control point to match the renderer device to the upnp av source.
    Bws<256> rendererName(aRoom);
    rendererName.Append(":");
    rendererName.Append(SourceUpnpAv::kSourceName);
    iDeviceUpnpAv = new DvDeviceStandard(aDvStack, buf);
    iDeviceUpnpAv->SetAttribute("Upnp.Domain", "upnp.org");
    iDeviceUpnpAv->SetAttribute("Upnp.Type", "MediaRenderer");
    iDeviceUpnpAv->SetAttribute("Upnp.Version", "1");
    friendlyName.Append(":MediaRenderer");
    iDeviceUpnpAv->SetAttribute("Upnp.FriendlyName", rendererName.PtrZ());
    iDeviceUpnpAv->SetAttribute("Upnp.Manufacturer", "OpenHome");
    iDeviceUpnpAv->SetAttribute("Upnp.ModelName", "ExampleMediaPlayer");

    // create read/write store.  This creates a number of static (constant)
    // entries automatically
    iRamStore = new RamStore();

    // create a read/write store using the new config framework
    iConfigRegStore = new ConfigRegStore();

    iConfigRegStore->Write(Brn("Product.Room"), Brn(aRoom));
    iConfigRegStore->Write(Brn("Product.Name"), Brn(aProductName));

    // Volume Control
    VolumeProfile  volumeProfile;
    VolumeConsumer volumeInit;
    volumeInit.SetVolume(iVolume);
    volumeInit.SetBalance(iVolume);
    volumeInit.SetFade(iVolume);

    // Set pipeline thread priority just below the pipeline animator.
    iInitParams = PipelineInitParams::New();
    iInitParams->SetThreadPriorityMax(kPriorityHighest);
    iInitParams->SetStarvationMonitorMaxSize(Jiffies::kPerMs * 100);

    // create MediaPlayer
    iMediaPlayer = new MediaPlayer(aDvStack, *iDevice, *iShell, *iRamStore,
                                   *iConfigRegStore, iInitParams,
                                   volumeInit, volumeProfile, aUdn, Brn(aRoom),
                                   Brn(aProductName));

    iPipelineStateLogger = new LoggingPipelineObserver();
    iMediaPlayer->Pipeline().AddObserver(*iPipelineStateLogger);

    // Set up config app.
    static const TUint addr = 0;    // Bind to all addresses.
    static const TUint port = 0;    // Bind to whatever free port the OS
    // allocates to the framework server.

    iAppFramework = new WebAppFramework(aDvStack.Env(),
                                        addr,
                                        port,
                                        kMaxUiTabs,
                                        kUiSendQueueSize);
}
Esempio n. 15
0
static void GetThreadName(Bws<5>& aThName)
{
    aThName.SetBytes(0);
    aThName.Append(Thread::CurrentThreadName());
    aThName.PtrZ();
}
Esempio n. 16
0
Soundcard::Soundcard(TIpAddress /* aSubnet */, TUint aChannel, TUint aTtl, TBool aMulticast, TBool aEnabled, TUint aPreset, ReceiverCallback aReceiverCallback, void* aReceiverPtr)
	: iReceiverCallback(aReceiverCallback)
	, iReceiverPtr(aReceiverPtr)
{
	InitialisationParams* initParams = InitialisationParams::Create();

	UpnpLibrary::Initialise(initParams);

	std::vector<NetworkInterface*>* list = UpnpLibrary::SubnetList();

	ASSERT(list->size() > 0);

	NetworkInterface* iface = *list->begin();

	delete (list);

	UpnpLibrary::SetCurrentSubnet(*iface);

	printf("Using %x\n", iface->Address());
    
    UpnpLibrary::StartCombined();

	Bws<kMaxUdnBytes> computer;
	Bws<kMaxUdnBytes> udn;
	Bws<kMaxUdnBytes + 1> friendly;

	TUint bytes = computer.MaxBytes();

	if (!GetComputerName((LPSTR)computer.Ptr(), (LPDWORD)&bytes)) {
		THROW(SoundcardError);
	}

	computer.SetBytes(bytes);
	udn.Replace("ohSoundcard-");
	udn.Append(computer);
	friendly.Replace(udn);
	friendly.Append('\0');

	iDevice = new DvDeviceStandard(udn);
    
	iDevice->SetAttribute("Upnp.Domain", "av.openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Soundcard");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", (TChar*)friendly.Ptr());
    iDevice->SetAttribute("Upnp.Manufacturer", "Openhome");
    iDevice->SetAttribute("Upnp.ManufacturerUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.ModelDescription", "OpenHome Soundcard");
    iDevice->SetAttribute("Upnp.ModelName", "ohSoundcard");
    iDevice->SetAttribute("Upnp.ModelNumber", "1");
    iDevice->SetAttribute("Upnp.ModelUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.SerialNumber", "");
    iDevice->SetAttribute("Upnp.Upc", "");

    iDriver = new OhmSenderDriverWindows();
    
	Brn icon(icon_png, icon_png_len);

	iSender = new OhmSender(*iDevice, *iDriver, computer, aChannel, iface->Address(), aTtl, aMulticast, aEnabled, icon, Brn("image/png"), aPreset);
	
    iDevice->SetEnabled();

	iReceiverManager = new ReceiverManager3(*this, iSender->SenderUri(), iSender->SenderMetadata());
}