Ejemplo n.º 1
0
SsdpListenerUnicast::SsdpListenerUnicast(Environment& aEnv, ISsdpNotifyHandler& aNotifyHandler, TIpAddress aInterface)
    : SsdpListener("SsdpListenerU")
    , iEnv(aEnv)
    , iNotifyHandler(aNotifyHandler)
    , iInterface(aInterface)
    , iSocket(aEnv, 0, aInterface)
    , iSocketWriter(iSocket, Endpoint(Ssdp::kMulticastPort, Ssdp::kMulticastAddress))
    , iSocketReader(iSocket)
    , iWriteBuffer(iSocketWriter)
    , iWriter(iWriteBuffer)
    , iReadBuffer(iSocketReader)
    , iReaderUntil(iReadBuffer)
    , iReaderResponse(aEnv, iReaderUntil)
    , iWriterLock("SSLU")
    , iExiting(false)
    , iRecreateSocket(false)
{
    try {
        iSocket.SetMulticastIf(aInterface);
    }
    catch (NetworkError&) {} // risk startup crashes if we don't suppress errors here
    iSocket.SetTtl(aEnv.InitParams()->MsearchTtl());
    try {
        iSocket.SetRecvBufBytes(kRecvBufBytes);
    }
    catch (NetworkError&) {}
    aEnv.AddResumeObserver(*this);
    
    iReaderResponse.AddHeader(iHeaderCacheControl);
    iReaderResponse.AddHeader(iHeaderExt);
    iReaderResponse.AddHeader(iHeaderLocation);
    iReaderResponse.AddHeader(iHeaderServer);
    iReaderResponse.AddHeader(iHeaderSt);
    iReaderResponse.AddHeader(iHeaderUsn);
}
Ejemplo n.º 2
0
void Ssdp::WriteMaxAge(Environment& aEnv, IWriterHttpHeader& aWriter)
{
    IWriterAscii& stream = aWriter.WriteHeaderField(Ssdp::kHeaderCacheControl);
    stream.Write(kSsdpMaxAge);
    stream.Write(kSsdpMaxAgeSeparator);
    stream.WriteUint(aEnv.InitParams()->DvMaxUpdateTimeSecs());
    stream.WriteFlush();
}
Ejemplo n.º 3
0
SsdpSocketReader::SsdpSocketReader(Environment& aEnv, TIpAddress aInterface, const Endpoint& aMulticast)
    : SocketUdpMulticast(aEnv, aInterface, aMulticast)
{
    SetTtl(aEnv.InitParams()->MsearchTtl()); 
    iReader = new UdpReader(*this);
}
Ejemplo n.º 4
0
void TestSsdpUListen(Environment& aEnv, const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint mx("-mx", "--mx", 0, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
    parser.AddOption(&adapter);
    OptionBool all("-a", "--all", "Search for all devices and services");
    parser.AddOption(&all);
    OptionBool root("-r", "--root", "Search for root devices only");
    parser.AddOption(&root);
    Brn emptyString("");
    OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device");
    parser.AddOption(&uuid);
    OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]");
    parser.AddOption(&urn);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

    //Debug::SetLevel(Debug::kSsdpMulticast);
    TBool block = true;
    SsdpNotifyLoggerU logger;
    SsdpListenerUnicast* uListener = new SsdpListenerUnicast(aEnv, logger, NetworkIf(aEnv, adapter.Value()));
    uListener->Start();
    if (all.Value()) {
        Print("Search all...\n");
        uListener->MsearchAll();
    }
    else if (root.Value()) {
        Print("Search root...\n");
        uListener->MsearchRoot();
    }
    else if (uuid.Value().Bytes() > 0) {
        Print("Search uuid...\n");
        uListener->MsearchUuid(uuid.Value());
    }
    else if (urn.Value().Bytes() > 0) {
        Print("Search device/service...\n");
        Brn domainName;
        Brn deviceType;
        TUint ver;
        if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, deviceType, ver)) {
            uListener->MsearchDeviceType(domainName, deviceType, ver);
        }
        else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, deviceType, ver)) {
            uListener->MsearchServiceType(domainName, deviceType, ver);
        }
        else {
            parser.DisplayHelp();
            block = false;
        }
    }
    else {
        parser.DisplayHelp();
        block = false;
    }

    if (block) {
        Blocker* blocker = new Blocker(aEnv);
        blocker->Wait(aEnv.InitParams()->MsearchTimeSecs());
        delete blocker;
    }
    delete uListener;
}