Skip to content

Commit

Permalink
Relaxed device matching with Ceton discovery
Browse files Browse the repository at this point in the history
Fixed bug where app would not respond to HDHomeRun discovery requests on the correct local IP
Fixed PCI device discovery
  • Loading branch information
Craig Moksnes committed Mar 9, 2020
1 parent 9978812 commit 45d846d
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions ProxyServerModuleUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,12 @@ procedure TProxyServerModule.StartServer;

try
fSSDPServer.Bindings.Clear;

if lListenIP = '' then
begin
// If listening on all IPs, have to explicitly create a binding for each local IP
// so that we can properly read which IP that UDP packets come in on
for lLocalIPInfo in lLocalIPs do
with fSSDPServer.Bindings.Add do
begin
IP := lLocalIPInfo.IP;
Port := 0;
end;
end
else
begin
for lLocalIPInfo in lLocalIPs do
with fSSDPServer.Bindings.Add do
begin
IP := lListenIP;
IP := lLocalIPInfo.IP;
Port := 0;
end;
end;

fSSDPServer.Active := True;
except
TLogger.Log('Unable to create SSDP server');
Expand Down Expand Up @@ -496,8 +481,10 @@ function TProxyServerModule.TryGetAddress(const aRequestLocalIP: String; out aAd
lAddresses := lAddresses.Remove(ProxyServiceModule.Client.ListenIP);
end;

// Choose a local IP that we should respond to
aAddress := lAddresses.LowestMetric(4).IP;
Result := not SameText(aRequestLocalIP, aAddress);
// Return whether the local ip that the request came in on is equal to that chosen IP
Result := SameText(aRequestLocalIP, aAddress);
end
else
begin
Expand Down Expand Up @@ -588,7 +575,7 @@ function TProxyServerModule.CreateSSDPDiscoverPacket: String;
cSSDPDiscover =
'M-SEARCH * HTTP/1.1'#13#10+
'Host: 239.255.255.250:1900'#13#10+
'ST: urn:schemas-cetoncorp-com:device:SecureContainer:1'#13#10+
'ST: '+{'ssdp:all'}'urn:schemas-cetoncorp-com:device:SecureContainer:1'#13#10+
'Man: "ssdp:discover"'#13#10+
'MX: 3'#13#10#13#10;
begin
Expand Down Expand Up @@ -621,7 +608,7 @@ procedure TProxyServerModule.SSDPClientRead(Sender: TObject;
end
else if String(lData).StartsWith('NOTIFY', True) then
begin
if String(lData).Contains('NT: urn:schemas-cetoncorp-com:device:SecureContainer:1') then
if String(lData).ToLower.Contains('cetoncorp') then
begin
TLogger.LogFmt('Received NOTIFY from ceton device %s on %s: %s', [ABinding.PeerIP, ABinding.IP, String(lData)]);

Expand Down Expand Up @@ -732,7 +719,7 @@ procedure TProxyServerModule.SSDPServerRead(AThread: TIdUDPListenerThread; const
lValues.NameValueSeparator := ':';
lValues.Text := String(lData);

if SameText(Trim(lValues.Values['ST']), 'urn:schemas-cetoncorp-com:device:SecureContainer:1') then
if Trim(lValues.Values['ST']).ToLower.Contains('cetoncorp') then
begin
lLocation := Trim(lValues.Values['LOCATION']);

Expand Down

0 comments on commit 45d846d

Please sign in to comment.