示例#1
0
TBool CpListenerMsearch::LogUdn(const Brx& aUuid, const Brx& aLocation)
{
    Uri uri(aLocation);
    Endpoint endpt(0, uri.Host());
    NetworkAdapter* nif = iEnv.NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    TBool correctSubnet = nif->ContainsAddress(endpt.Address());
    nif->RemoveRef(kAdapterCookie);
    if (!correctSubnet) {
#if 0
        Print("Discarding advertisement from ");
        Print(aUuid);
        Endpoint::EndpointBuf buf;
        endpt.AppendEndpoint(buf);
        Print(" at %s\n", buf.Ptr());
#endif
        return false;
    }

    if (aUuid == SuiteMsearch::gNameDevice1){
        iUdnsReceived |= 1;
    }
    else if (aUuid == SuiteMsearch::gNameDevice2){
        iUdnsReceived |= 2;
    }
    else if (aUuid == SuiteMsearch::gNameDevice2Embedded1) {
        iUdnsReceived |= 4;
    }
    else {
#if 0
        Print("Didn't match advertisement from ");
        Print(aUuid);
        Endpoint::EndpointBuf buf;
        endpt.AppendEndpoint(buf);
        Print(" at %s\n", buf.Ptr());
#endif
        return false;
    }
    iTotal++;
    return true;
}
示例#2
0
void SsdpListenerMulticast::Run()
{
    Signal();
    for (;;) {
        iReaderRequest.Flush();

        try {
            LOG(kSsdpMulticast, "SSDP Multicast      Listen\n");
            iReaderRequest.Read(0);
            if (iReaderRequest.Version() == Http::eHttp11) {
                if (iReaderRequest.Uri() == Ssdp::kMethodUri) {
                    const Brx& method = iReaderRequest.Method();
                    if (method == Ssdp::kMethodNotify) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Notify\n");
                        iLock.Wait();
                        EraseDisabled(iNotifyHandlers);
                        VectorNotifyHandler callbacks;
                        TUint count = (TUint)iNotifyHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iNotifyHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Notify(*(callbacks[i]));
                        }
                    }
                    else if (method == Ssdp::kMethodMsearch) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Msearch\n");
                        iLock.Wait();
                        EraseDisabled(iMsearchHandlers);
                        VectorMsearchHandler callbacks;
                        TUint count = (TUint)iMsearchHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iMsearchHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Msearch(*(callbacks[i]));
                        }
                    }
                }
            }
        }
        catch (HttpError& ex) {
            Endpoint::EndpointBuf epb;
            iSocket.Sender().AppendEndpoint(epb);
            epb.PtrZ();
            try {
                Brn buf = iReaderUntil.Read(kMaxBufferBytes);
                LOG2(kSsdpMulticast, kError, "SSDP Multicast      HttpError (sender=%s) from %s:%u.  Received: %.*s\n\n",
                                             (const char*)epb.Ptr(), ex.File(), ex.Line(), PBUF(buf));
            }
            catch (ReaderError&) {
            }
        }
        catch (WriterError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      WriterError\n");
        }
        catch (ReaderError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      ReaderError\n");
            if (iExiting) {
                break;
            }
        }
        if (iRecreateSocket) {
            try {
                iSocket.Interrupt(false);
                iSocket.ReCreate();
                iRecreateSocket = false;
            }
            catch (NetworkError&) {
                LOG2(kSsdpMulticast, kError, "SSDP Multicast      failed to recreate socket after library Resumed\n");
            }
        }
    }
}
示例#3
0
static void PrintEndpoint(const Endpoint& aEndpoint)
{
    Endpoint::EndpointBuf buf;
    aEndpoint.AppendEndpoint(buf);
    Print("%s", buf.Ptr());
}