mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-09 18:15:23 +02:00
Added support for non alfanumeric service names
This commit is contained in:
parent
6e3b83803b
commit
602fe77bf7
1 changed files with 73 additions and 74 deletions
|
@ -116,8 +116,9 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
private final String LEGACY_SERVICE_DISCOVERY_COMMAND = Messages.getString("DNSSDProtocol.legacyServiceDiscoveryCommand"); //$NON-NLS-1$
|
private final String LEGACY_SERVICE_DISCOVERY_COMMAND = Messages.getString("DNSSDProtocol.legacyServiceDiscoveryCommand"); //$NON-NLS-1$
|
||||||
|
|
||||||
// Patterns to parse service name and service type
|
// Patterns to parse service name and service type
|
||||||
private final Pattern serviceNamePattern = Pattern.compile("^_?(\\w+)\\..+"); //$NON-NLS-1$
|
|
||||||
private final Pattern serviceTypeNamePattern = Pattern.compile("^[^\\.]+\\._?(\\w+)\\..+"); //$NON-NLS-1$
|
private final Pattern srvPattern = Pattern.compile("^(.+)\\._(.+)._.+\\.local."); //$NON-NLS-1$
|
||||||
|
private final Pattern ptrPattern = Pattern.compile("^_(.+)._.+\\.local."); //$NON-NLS-1$
|
||||||
|
|
||||||
private Resource resource = null;
|
private Resource resource = null;
|
||||||
private ITransport transport = null;
|
private ITransport transport = null;
|
||||||
|
@ -381,12 +382,11 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
//parse the service type name
|
//parse the service type name
|
||||||
if(!(serviceTypeName.equals(SERVICE_DISCOVERY_COMMAND) || serviceTypeName.equals(LEGACY_SERVICE_DISCOVERY_COMMAND)))
|
if(!(serviceTypeName.equals(SERVICE_DISCOVERY_COMMAND) || serviceTypeName.equals(LEGACY_SERVICE_DISCOVERY_COMMAND)))
|
||||||
{
|
{
|
||||||
Matcher matcher = serviceNamePattern.matcher(name);
|
Matcher matcher = ptrPattern.matcher(name);
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
serviceTypeName = matcher.group(1);
|
serviceTypeName = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//find if we have a serviceType with this name...
|
//find if we have a serviceType with this name...
|
||||||
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -416,7 +416,7 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//parse the service type name
|
//parse the service type name
|
||||||
Matcher matcher = serviceNamePattern.matcher(ptrDataName);
|
Matcher matcher = srvPattern.matcher(ptrDataName);
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
serviceName = matcher.group(1);
|
serviceName = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
@ -459,13 +459,18 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//find if we have a serviceType with this name...
|
String serviceTypeName = null;
|
||||||
String serviceTypeName = null; //name.substring(name.indexOf('.') + 1);
|
String serviceName = null;
|
||||||
|
|
||||||
//parse the service type name
|
//parse the service type name and the service name
|
||||||
Matcher matcher = serviceTypeNamePattern.matcher(name);
|
Matcher matcher = srvPattern.matcher(name);
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
serviceTypeName = matcher.group(1);
|
{
|
||||||
|
serviceTypeName = matcher.group(2);
|
||||||
|
serviceName = matcher.group(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// find if we have a serviceType with this name...
|
||||||
|
|
||||||
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -485,12 +490,6 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
//find if we have a service with this name...
|
//find if we have a service with this name...
|
||||||
String serviceName = null;
|
|
||||||
|
|
||||||
Matcher matcher2 = serviceNamePattern.matcher(name);
|
|
||||||
if (matcher2.matches())
|
|
||||||
serviceName = matcher2.group(1);
|
|
||||||
|
|
||||||
Iterator serviceIterator = serviceType.getService().iterator();
|
Iterator serviceIterator = serviceType.getService().iterator();
|
||||||
found = false;
|
found = false;
|
||||||
while (serviceIterator.hasNext()) {
|
while (serviceIterator.hasNext()) {
|
||||||
|
@ -553,12 +552,17 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find if we have a serviceType with this name...
|
String serviceName = null;
|
||||||
String serviceTypeName = null;
|
String serviceTypeName = null;
|
||||||
|
|
||||||
Matcher matcher1 = serviceTypeNamePattern.matcher(recordName);
|
// Find if we have a serviceType with this name...
|
||||||
if (matcher1.matches())
|
|
||||||
serviceTypeName = matcher1.group(1);
|
Matcher matcher = srvPattern.matcher(recordName);
|
||||||
|
if (matcher.matches())
|
||||||
|
{
|
||||||
|
serviceName = matcher.group(1);
|
||||||
|
serviceTypeName = matcher.group(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
Iterator serviceTypeIterator = device.getServiceType().iterator();
|
||||||
|
@ -581,12 +585,6 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find if we have a service with this name...
|
// Find if we have a service with this name...
|
||||||
String serviceName = null;
|
|
||||||
|
|
||||||
Matcher matcher2 = serviceNamePattern.matcher(recordName);
|
|
||||||
if (matcher2.matches())
|
|
||||||
serviceName = matcher2.group(1);
|
|
||||||
|
|
||||||
|
|
||||||
Iterator serviceIterator = serviceType.getService().iterator();
|
Iterator serviceIterator = serviceType.getService().iterator();
|
||||||
found = false;
|
found = false;
|
||||||
|
@ -608,37 +606,41 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
//process "key=value" pairs
|
//process "key=value" pairs
|
||||||
//only alfanumeric key/value allowed
|
|
||||||
StringBuffer dataBuffer = new StringBuffer();
|
|
||||||
for (int j = 0; j < dataLength; j++) {
|
|
||||||
if (data[j] >= '0') {
|
|
||||||
dataBuffer.append((char) data[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(j == 0) && (data[j] < '0' || j == dataLength - 1)) {
|
StringBuffer dataBuffer = new StringBuffer();
|
||||||
StringTokenizer stk = new StringTokenizer(dataBuffer.toString(), "="); //$NON-NLS-1$
|
int entryLength = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < dataLength; j += entryLength + 1) {
|
||||||
|
|
||||||
|
dataBuffer.setLength(0);
|
||||||
|
|
||||||
|
entryLength = data[j];
|
||||||
|
|
||||||
|
for (int k = 1; k <= entryLength; k++)
|
||||||
|
dataBuffer.append((char) data[j + k]);
|
||||||
|
|
||||||
|
StringTokenizer stk = new StringTokenizer(dataBuffer.toString(),"="); //$NON-NLS-1$
|
||||||
|
|
||||||
String key = stk.nextToken();
|
String key = stk.nextToken();
|
||||||
|
|
||||||
//DNS-Based Service Discovery
|
// DNS-Based Service Discovery
|
||||||
//6.4 Rules for Names in DNS-SD Name/Value Pairs
|
// 6.4 Rules for Names in DNS-SD Name/Value Pairs
|
||||||
//If a key has no value, assume "true"
|
// If a key has no value, assume "true"
|
||||||
String value = "true"; //$NON-NLS-1$
|
String value = "true"; //$NON-NLS-1$
|
||||||
|
|
||||||
try {
|
try {
|
||||||
value = stk.nextToken();
|
value = stk.nextToken();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//no value, assume "true"
|
// no value, assume "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
//find if we are updating the value of a key...
|
// find if we are updating the value of a key...
|
||||||
Pair text = null;
|
Pair text = null;
|
||||||
Iterator pairIterator = service.getPair().iterator();
|
Iterator pairIterator = service.getPair().iterator();
|
||||||
found = false;
|
found = false;
|
||||||
while (pairIterator.hasNext()) {
|
while (pairIterator.hasNext()) {
|
||||||
Pair aPair = (Pair) pairIterator.next();
|
Pair aPair = (Pair) pairIterator.next();
|
||||||
if (aPair != null)
|
if (aPair != null) {
|
||||||
{
|
|
||||||
if (aPair.getKey().equals(key)) {
|
if (aPair.getKey().equals(key)) {
|
||||||
String current = aPair.getValue();
|
String current = aPair.getValue();
|
||||||
if (!current.equals(value))
|
if (!current.equals(value))
|
||||||
|
@ -655,9 +657,6 @@ public class DNSSDProtocol implements IProtocol {
|
||||||
text.setValue(value);
|
text.setValue(value);
|
||||||
service.getPair().add(text);
|
service.getPair().add(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataBuffer = new StringBuffer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue