org.eclipse.ecf.provider.jmdns_4.1.0.v20111230-0120

16:43:14.676 INFO  jd.cli.Main - Decompiling org.eclipse.ecf.provider.jmdns_4.1.0.v20111230-0120.jar
package javax.jmdns;

import java.io.IOException;
import java.net.InetAddress;
import javax.jmdns.impl.JmDNSImpl;

public abstract class JmDNS
{
  public static String VERSION = "2.0";
  
  public static JmDNS create()
    throws IOException
  {
    return new JmDNSImpl();
  }
  
  public static JmDNS create(InetAddress addr)
    throws IOException
  {
    return new JmDNSImpl(addr);
  }
  
  public abstract String getHostName();
  
  public abstract InetAddress getInterface()
    throws IOException;
  
  public abstract ServiceInfo getServiceInfo(String paramString1, String paramString2);
  
  public abstract ServiceInfo getServiceInfo(String paramString1, String paramString2, int paramInt);
  
  public abstract void requestServiceInfo(String paramString1, String paramString2);
  
  public abstract void requestServiceInfo(String paramString1, String paramString2, int paramInt);
  
  public abstract void addServiceTypeListener(ServiceTypeListener paramServiceTypeListener)
    throws IOException;
  
  public abstract void removeServiceTypeListener(ServiceTypeListener paramServiceTypeListener);
  
  public abstract void addServiceListener(String paramString, ServiceListener paramServiceListener);
  
  public abstract void removeServiceListener(String paramString, ServiceListener paramServiceListener);
  
  public abstract void registerService(ServiceInfo paramServiceInfo)
    throws IOException;
  
  public abstract void unregisterService(ServiceInfo paramServiceInfo);
  
  public abstract void unregisterAllServices();
  
  public abstract void registerServiceType(String paramString);
  
  public abstract void close();
  
  public abstract void printServices();
  
  public abstract ServiceInfo[] list(String paramString);
}

/* Location:
 * Qualified Name:     javax.jmdns.JmDNS
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns;

import java.util.EventObject;

public abstract class ServiceEvent
  extends EventObject
{
  public ServiceEvent(Object source)
  {
    super(source);
  }
  
  public abstract JmDNS getDNS();
  
  public abstract String getType();
  
  public abstract String getName();
  
  public abstract ServiceInfo getInfo();
}

/* Location:
 * Qualified Name:     javax.jmdns.ServiceEvent
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns;

import java.net.InetAddress;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.jmdns.impl.ServiceInfoImpl;

public abstract class ServiceInfo
{
  public static final byte[] NO_VALUE = new byte[0];
  
  public static ServiceInfo create(String type, String name, int port, String text)
  {
    return new ServiceInfoImpl(type, name, port, text);
  }
  
  public static ServiceInfo create(String type, String name, int port, int weight, int priority, String text)
  {
    return new ServiceInfoImpl(type, name, port, weight, priority, text);
  }
  
  public static ServiceInfo create(String type, String name, int port, int weight, int priority, Hashtable props)
  {
    return new ServiceInfoImpl(type, name, port, weight, priority, props);
  }
  
  public static ServiceInfo create(String type, String name, int port, int weight, int priority, byte[] text)
  {
    return new ServiceInfoImpl(type, name, port, weight, priority, text);
  }
  
  public abstract String getType();
  
  public abstract String getName();
  
  public abstract String getQualifiedName();
  
  public abstract String getServer();
  
  public abstract String getHostAddress();
  
  public abstract InetAddress getAddress();
  
  public abstract InetAddress getInetAddress();
  
  public abstract int getPort();
  
  public abstract int getPriority();
  
  public abstract int getWeight();
  
  public abstract byte[] getTextBytes();
  
  public abstract String getTextString();
  
  public abstract String getURL();
  
  public abstract String getURL(String paramString);
  
  public abstract byte[] getPropertyBytes(String paramString);
  
  public abstract String getPropertyString(String paramString);
  
  public abstract Enumeration getPropertyNames();
  
  public abstract String getNiceTextString();
  
  public abstract String getProtocol();
  
  public abstract String getDomain();
}

/* Location:
 * Qualified Name:     javax.jmdns.ServiceInfo
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns;

import java.util.EventListener;

public abstract interface ServiceListener
  extends EventListener
{
  public abstract void serviceAdded(ServiceEvent paramServiceEvent);
  
  public abstract void serviceRemoved(ServiceEvent paramServiceEvent);
  
  public abstract void serviceResolved(ServiceEvent paramServiceEvent);
}

/* Location:
 * Qualified Name:     javax.jmdns.ServiceListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns;

import java.util.EventListener;

public abstract interface ServiceTypeListener
  extends EventListener
{
  public abstract void serviceTypeAdded(ServiceEvent paramServiceEvent);
}

/* Location:
 * Qualified Name:     javax.jmdns.ServiceTypeListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

public class DNSCache$CacheNode
{
  private final DNSEntry value;
  private CacheNode next;
  
  public DNSCache$CacheNode(DNSEntry value)
  {
    this.value = value;
  }
  
  public CacheNode next()
  {
    return next;
  }
  
  public DNSEntry getValue()
  {
    return value;
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSCache.CacheNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public class DNSCache
{
  private int size;
  private final HashMap hashtable;
  
  public static class CacheNode
  {
    private final DNSEntry value;
    private CacheNode next;
    
    public CacheNode(DNSEntry value)
    {
      this.value = value;
    }
    
    public CacheNode next()
    {
      return next;
    }
    
    public DNSEntry getValue()
    {
      return value;
    }
  }
  
  public DNSCache(int size)
  {
    hashtable = new HashMap(size);
  }
  
  public synchronized void clear()
  {
    hashtable.clear();
    size = 0;
  }
  
  public synchronized void add(DNSEntry entry)
  {
    CacheNode newValue = new CacheNode(entry);
    CacheNode node = (CacheNode)hashtable.get(entry.getName());
    if (node == null)
    {
      hashtable.put(entry.getName(), newValue);
    }
    else
    {
      next = next;
      next = newValue;
    }
    size += 1;
  }
  
  public synchronized boolean remove(DNSEntry entry)
  {
    CacheNode node = (CacheNode)hashtable.get(entry.getName());
    if (node != null)
    {
      if (value == entry)
      {
        if (next == null) {
          hashtable.remove(entry.getName());
        } else {
          hashtable.put(entry.getName(), next);
        }
        size -= 1;
        return true;
      }
      CacheNode previous = node;
      node = next;
      while (node != null)
      {
        if (value == entry)
        {
          next = next;
          size -= 1;
          return true;
        }
        previous = node;
        node = next;
      }
    }
    return false;
  }
  
  public synchronized DNSEntry get(DNSEntry entry)
  {
    for (CacheNode node = find(entry.getName()); node != null; node = next) {
      if (value.equals(entry)) {
        return value;
      }
    }
    return null;
  }
  
  public synchronized DNSEntry get(String name, int type, int clazz)
  {
    for (CacheNode node = find(name); node != null; node = next) {
      if ((value.type == type) && (value.clazz == clazz)) {
        return value;
      }
    }
    return null;
  }
  
  public synchronized Iterator iterator()
  {
    return new ArrayList(hashtable.values()).iterator();
  }
  
  public synchronized CacheNode find(String name)
  {
    return (CacheNode)hashtable.get(name);
  }
  
  public synchronized void print()
  {
    CacheNode n;
    for (Iterator i = iterator(); i.hasNext(); n != null)
    {
      n = (CacheNode)i.next(); continue;
      
      System.out.println(value);n = next;
    }
  }
  
  public synchronized String toString()
  {
    StringBuffer aLog = new StringBuffer();
    aLog.append("\t---- cache ----");
    CacheNode n;
    for (Iterator i = iterator(); i.hasNext(); n != null)
    {
      n = (CacheNode)i.next(); continue;
      
      aLog.append("\n\t\t" + value);n = next;
    }
    return aLog.toString();
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSCache
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

public final class DNSConstants
{
  public static final String MDNS_GROUP = "224.0.0.251";
  public static final String MDNS_GROUP_IPV6 = "FF02::FB";
  public static final int MDNS_PORT = Integer.parseInt(System.getProperty("net.mdns.port", "5353"));
  public static final int DNS_PORT = 53;
  public static final int DNS_TTL = 3600;
  public static final int MAX_MSG_TYPICAL = 1460;
  public static final int MAX_MSG_ABSOLUTE = 8972;
  public static final int FLAGS_QR_MASK = 32768;
  public static final int FLAGS_QR_QUERY = 0;
  public static final int FLAGS_QR_RESPONSE = 32768;
  public static final int FLAGS_AA = 1024;
  public static final int FLAGS_TC = 512;
  public static final int FLAGS_RD = 256;
  public static final int FLAGS_RA = 32768;
  public static final int FLAGS_Z = 64;
  public static final int FLAGS_AD = 32;
  public static final int FLAGS_CD = 16;
  public static final int CLASS_IN = 1;
  public static final int CLASS_CS = 2;
  public static final int CLASS_CH = 3;
  public static final int CLASS_HS = 4;
  public static final int CLASS_NONE = 254;
  public static final int CLASS_ANY = 255;
  public static final int CLASS_MASK = 32767;
  public static final int CLASS_UNIQUE = 32768;
  public static final int TYPE_IGNORE = 0;
  public static final int TYPE_A = 1;
  public static final int TYPE_NS = 2;
  public static final int TYPE_MD = 3;
  public static final int TYPE_MF = 4;
  public static final int TYPE_CNAME = 5;
  public static final int TYPE_SOA = 6;
  public static final int TYPE_MB = 7;
  public static final int TYPE_MG = 8;
  public static final int TYPE_MR = 9;
  public static final int TYPE_NULL = 10;
  public static final int TYPE_WKS = 11;
  public static final int TYPE_PTR = 12;
  public static final int TYPE_HINFO = 13;
  public static final int TYPE_MINFO = 14;
  public static final int TYPE_MX = 15;
  public static final int TYPE_TXT = 16;
  public static final int TYPE_RP = 17;
  public static final int TYPE_AFSDB = 18;
  public static final int TYPE_X25 = 19;
  public static final int TYPE_ISDN = 20;
  public static final int TYPE_RT = 21;
  public static final int TYPE_NSAP = 22;
  public static final int TYPE_NSAP_PTR = 23;
  public static final int TYPE_SIG = 24;
  public static final int TYPE_KEY = 25;
  public static final int TYPE_PX = 26;
  public static final int TYPE_GPOS = 27;
  public static final int TYPE_AAAA = 28;
  public static final int TYPE_LOC = 29;
  public static final int TYPE_NXT = 30;
  public static final int TYPE_EID = 31;
  public static final int TYPE_NIMLOC = 32;
  public static final int TYPE_SRV = 33;
  public static final int TYPE_ATMA = 34;
  public static final int TYPE_NAPTR = 35;
  public static final int TYPE_KX = 36;
  public static final int TYPE_CERT = 37;
  public static final int TYPE_A6 = 38;
  public static final int TYPE_DNAME = 39;
  public static final int TYPE_SINK = 40;
  public static final int TYPE_OPT = 41;
  public static final int TYPE_APL = 42;
  public static final int TYPE_DS = 43;
  public static final int TYPE_SSHFP = 44;
  public static final int TYPE_RRSIG = 46;
  public static final int TYPE_NSEC = 47;
  public static final int TYPE_DNSKEY = 48;
  public static final int TYPE_UINFO = 100;
  public static final int TYPE_UID = 101;
  public static final int TYPE_GID = 102;
  public static final int TYPE_UNSPEC = 103;
  public static final int TYPE_TKEY = 249;
  public static final int TYPE_TSIG = 250;
  public static final int TYPE_IXFR = 251;
  public static final int TYPE_AXFR = 252;
  public static final int TYPE_MAILA = 253;
  public static final int TYPE_MAILB = 254;
  public static final int TYPE_ANY = 255;
  public static final int SHARED_QUERY_TIME = 20;
  public static final int QUERY_WAIT_INTERVAL = 225;
  public static final int PROBE_WAIT_INTERVAL = 250;
  public static final int RESPONSE_MIN_WAIT_INTERVAL = 20;
  public static final int RESPONSE_MAX_WAIT_INTERVAL = 115;
  public static final int PROBE_CONFLICT_INTERVAL = 1000;
  public static final int PROBE_THROTTLE_COUNT = 10;
  public static final int PROBE_THROTTLE_COUNT_INTERVAL = 5000;
  public static final int ANNOUNCE_WAIT_INTERVAL = 1000;
  public static final int RECORD_REAPER_INTERVAL = 10000;
  public static final int KNOWN_ANSWER_TTL = 120;
  public static final int ANNOUNCED_RENEWAL_TTL_INTERVAL = 1800000;
  public static final String DNS_META_QUERY = "._dns-sd._udp.";
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSConstants
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

public class DNSEntry
{
  String key;
  String name;
  int type;
  int clazz;
  boolean unique;
  
  DNSEntry(String name, int type, int clazz)
  {
    key = name.toLowerCase();
    this.name = name;
    this.type = type;
    this.clazz = (clazz & 0x7FFF);
    unique = ((clazz & 0x8000) != 0);
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof DNSEntry))
    {
      DNSEntry other = (DNSEntry)obj;
      return (name.equals(name)) && (type == type) && (clazz == clazz);
    }
    return false;
  }
  
  public String getName()
  {
    return name;
  }
  
  public int getType()
  {
    return type;
  }
  
  public int hashCode()
  {
    return name.hashCode() + type + clazz;
  }
  
  static String getClazz(int clazz)
  {
    switch (clazz & 0x7FFF)
    {
    case 1: 
      return "in";
    case 2: 
      return "cs";
    case 3: 
      return "ch";
    case 4: 
      return "hs";
    case 254: 
      return "none";
    case 255: 
      return "any";
    }
    return "?";
  }
  
  static String getType(int type)
  {
    switch (type)
    {
    case 1: 
      return "a";
    case 28: 
      return "aaaa";
    case 2: 
      return "ns";
    case 3: 
      return "md";
    case 4: 
      return "mf";
    case 5: 
      return "cname";
    case 6: 
      return "soa";
    case 7: 
      return "mb";
    case 8: 
      return "mg";
    case 9: 
      return "mr";
    case 10: 
      return "null";
    case 11: 
      return "wks";
    case 12: 
      return "ptr";
    case 13: 
      return "hinfo";
    case 14: 
      return "minfo";
    case 15: 
      return "mx";
    case 16: 
      return "txt";
    case 33: 
      return "srv";
    case 255: 
      return "any";
    }
    return "?";
  }
  
  public String toString(String hdr, String other)
  {
    return hdr + "[" + getType(type) + "," + getClazz(clazz) + (unique ? "-unique," : ",") + name + (other != null ? "," + other + "]" : "]");
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSEntry
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public final class DNSIncoming
{
  public static boolean USE_DOMAIN_NAME_FORMAT_FOR_SRV_TARGET = true;
  private DatagramPacket packet;
  private int off;
  private int len;
  private byte[] data;
  int id;
  private int flags;
  private int numQuestions;
  int numAnswers;
  private int numAuthorities;
  private int numAdditionals;
  private long receivedTime;
  private List questions;
  List answers;
  
  DNSIncoming(DatagramPacket packet)
    throws IOException
  {
    this.packet = packet;
    InetAddress source = packet.getAddress();
    data = packet.getData();
    this.len = packet.getLength();
    off = packet.getOffset();
    questions = Collections.EMPTY_LIST;
    answers = Collections.EMPTY_LIST;
    receivedTime = System.currentTimeMillis();
    try
    {
      id = readUnsignedShort();
      flags = readUnsignedShort();
      numQuestions = readUnsignedShort();
      numAnswers = readUnsignedShort();
      numAuthorities = readUnsignedShort();
      numAdditionals = readUnsignedShort();
      if (numQuestions > 0)
      {
        questions = Collections.synchronizedList(new ArrayList(numQuestions));
        for (int i = 0; i < numQuestions; i++)
        {
          DNSQuestion question = new DNSQuestion(readName(), readUnsignedShort(), readUnsignedShort());
          questions.add(question);
        }
      }
      int n = numAnswers + numAuthorities + numAdditionals;
      if (n > 0)
      {
        answers = Collections.synchronizedList(new ArrayList(n));
        for (int i = 0; i < n; i++)
        {
          String domain = readName();
          int type = readUnsignedShort();
          int clazz = readUnsignedShort();
          int ttl = readInt();
          int len = readUnsignedShort();
          int end = off + len;
          DNSRecord rec = null;
          switch (type)
          {
          case 1: 
          case 28: 
            rec = new DNSRecord.Address(domain, type, clazz, ttl, readBytes(off, len));
            break;
          case 5: 
          case 12: 
            String service = "";
            try
            {
              service = readName();
            }
            catch (IOException e)
            {
              e.printStackTrace();
            }
            rec = new DNSRecord.Pointer(domain, type, clazz, ttl, service);
            break;
          case 16: 
            rec = new DNSRecord.Text(domain, type, clazz, ttl, readBytes(off, len));
            break;
          case 33: 
            int priority = readUnsignedShort();
            int weight = readUnsignedShort();
            int port = readUnsignedShort();
            String target = "";
            try
            {
              if (USE_DOMAIN_NAME_FORMAT_FOR_SRV_TARGET) {
                target = readName();
              } else {
                target = readNonNameString();
              }
            }
            catch (IOException e)
            {
              e.printStackTrace();
            }
            rec = new DNSRecord.Service(domain, type, clazz, ttl, 
              priority, weight, port, target);
            break;
          case 13: 
            break;
          }
          if (rec != null)
          {
            rec.setRecordSource(source);
            
            answers.add(rec);
          }
          else if (answers.size() < numAnswers)
          {
            numAnswers -= 1;
          }
          else if (answers.size() < numAnswers + numAuthorities)
          {
            numAuthorities -= 1;
          }
          else if (answers.size() < numAnswers + numAuthorities + numAdditionals)
          {
            numAdditionals -= 1;
          }
          off = end;
        }
      }
    }
    catch (IOException e)
    {
      throw e;
    }
  }
  
  boolean isQuery()
  {
    return (flags & 0x8000) == 0;
  }
  
  public boolean isTruncated()
  {
    return (flags & 0x200) != 0;
  }
  
  boolean isResponse()
  {
    return (flags & 0x8000) == 32768;
  }
  
  private int get(int off)
    throws IOException
  {
    if ((off < 0) || (off >= len)) {
      throw new IOException("parser error: offset=" + off);
    }
    return data[off] & 0xFF;
  }
  
  private int readUnsignedShort()
    throws IOException
  {
    return (get(off++) << 8) + get(off++);
  }
  
  private int readInt()
    throws IOException
  {
    return (readUnsignedShort() << 16) + readUnsignedShort();
  }
  
  private byte[] readBytes(int off, int len)
    throws IOException
  {
    byte[] bytes = new byte[len];
    System.arraycopy(data, off, bytes, 0, len);
    return bytes;
  }
  
  private void readUTF(StringBuffer buf, int off, int len)
    throws IOException
  {
    for (int end = off + len; off < end;)
    {
      int ch = get(off++);
      switch (ch >> 4)
      {
      case 0: 
      case 1: 
      case 2: 
      case 3: 
      case 4: 
      case 5: 
      case 6: 
      case 7: 
        break;
      case 12: 
      case 13: 
        ch = (ch & 0x1F) << 6 | get(off++) & 0x3F;
        break;
      case 14: 
        ch = (ch & 0xF) << 12 | (get(off++) & 0x3F) << 6 | get(off++) & 0x3F;
        break;
      case 8: 
      case 9: 
      case 10: 
      case 11: 
      default: 
        ch = (ch & 0x3F) << 4 | get(off++) & 0xF;
      }
      buf.append((char)ch);
    }
  }
  
  private String readNonNameString()
    throws IOException
  {
    StringBuffer buf = new StringBuffer();
    int off = this.off;
    int len = get(off++);
    readUTF(buf, off, len);
    
    return buf.toString();
  }
  
  private String readName()
    throws IOException
  {
    StringBuffer buf = new StringBuffer();
    int off = this.off;
    int next = -1;
    int first = off;
    int len;
    for (;;)
    {
      len = get(off++);
      if (len == 0) {
        break;
      }
      switch (len & 0xC0)
      {
      case 0: 
        readUTF(buf, off, len);
        off += len;
        buf.append('.');
        break;
      case 192: 
        if (next < 0) {
          next = off + 1;
        }
        off = (len & 0x3F) << 8 | get(off++);
        if (off >= first) {
          throw new IOException("bad domain name: possible circular name detected. name start: " + 
            first + 
            " bad offset: 0x" + Integer.toHexString(off));
        }
        first = off;
      }
    }
    throw new IOException("unsupported dns label type: '" + Integer.toHexString(len & 0xC0) + "' at " + (off - 1));
    
    this.off = (next >= 0 ? next : off);
    return buf.toString();
  }
  
  String print(boolean dump)
  {
    StringBuffer buf = new StringBuffer();
    buf.append(toString() + "\n");
    for (Iterator iterator = questions.iterator(); iterator.hasNext();) {
      buf.append("    ques:" + iterator.next() + "\n");
    }
    int count = 0;
    for (Iterator iterator = answers.iterator(); iterator.hasNext(); count++)
    {
      if (count < numAnswers) {
        buf.append("    answ:");
      } else if (count < numAnswers + numAuthorities) {
        buf.append("    auth:");
      } else {
        buf.append("    addi:");
      }
      buf.append(iterator.next() + "\n");
    }
    if (dump)
    {
      int off = 0;
      for (int len = packet.getLength(); off < len; off += 32)
      {
        int n = Math.min(32, len - off);
        if (off < 10) {
          buf.append(' ');
        }
        if (off < 100) {
          buf.append(' ');
        }
        buf.append(off);
        buf.append(':');
        for (int i = 0; i < n; i++)
        {
          if (i % 8 == 0) {
            buf.append(' ');
          }
          buf.append(Integer.toHexString((data[(off + i)] & 0xF0) >> 4));
          buf.append(Integer.toHexString((data[(off + i)] & 0xF) >> 0));
        }
        buf.append("\n");
        buf.append("    ");
        for (int i = 0; i < n; i++)
        {
          if (i % 8 == 0) {
            buf.append(' ');
          }
          buf.append(' ');
          int ch = data[(off + i)] & 0xFF;
          buf.append((ch > 32) && (ch < 127) ? (char)ch : '.');
        }
        buf.append("\n");
        if (off + 32 >= 256)
        {
          buf.append("....\n");
          break;
        }
      }
    }
    return buf.toString();
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append(isQuery() ? "dns[query," : "dns[response,");
    if (packet.getAddress() != null) {
      buf.append(packet.getAddress().getHostAddress());
    }
    buf.append(':');
    buf.append(packet.getPort());
    buf.append(",len=");
    buf.append(packet.getLength());
    buf.append(",id=0x");
    buf.append(Integer.toHexString(id));
    if (flags != 0)
    {
      buf.append(",flags=0x");
      buf.append(Integer.toHexString(flags));
      if ((flags & 0x8000) != 0) {
        buf.append(":r");
      }
      if ((flags & 0x400) != 0) {
        buf.append(":aa");
      }
      if ((flags & 0x200) != 0) {
        buf.append(":tc");
      }
    }
    if (numQuestions > 0)
    {
      buf.append(",questions=");
      buf.append(numQuestions);
    }
    if (numAnswers > 0)
    {
      buf.append(",answers=");
      buf.append(numAnswers);
    }
    if (numAuthorities > 0)
    {
      buf.append(",authorities=");
      buf.append(numAuthorities);
    }
    if (numAdditionals > 0)
    {
      buf.append(",additionals=");
      buf.append(numAdditionals);
    }
    buf.append("]");
    return buf.toString();
  }
  
  void append(DNSIncoming that)
  {
    if ((isQuery()) && (isTruncated()) && (that.isQuery()))
    {
      if (numQuestions > 0)
      {
        if (Collections.EMPTY_LIST.equals(questions)) {
          questions = Collections.synchronizedList(new ArrayList(numQuestions));
        }
        questions.addAll(questions);
        numQuestions += numQuestions;
      }
      if (Collections.EMPTY_LIST.equals(answers)) {
        answers = Collections.synchronizedList(new ArrayList());
      }
      if (numAnswers > 0)
      {
        answers.addAll(numAnswers, answers.subList(0, numAnswers));
        numAnswers += numAnswers;
      }
      if (numAuthorities > 0)
      {
        answers.addAll(numAnswers + numAuthorities, answers.subList(numAnswers, numAnswers + numAuthorities));
        numAuthorities += numAuthorities;
      }
      if (numAdditionals > 0)
      {
        answers.addAll(answers.subList(numAnswers + numAuthorities, numAnswers + numAuthorities + numAdditionals));
        numAdditionals += numAdditionals;
      }
    }
    else
    {
      throw new IllegalArgumentException();
    }
  }
  
  public int elapseSinceArrival()
  {
    return (int)(System.currentTimeMillis() - receivedTime);
  }
  
  public List getQuestions()
  {
    return questions;
  }
  
  public List getAnswers()
  {
    return answers;
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSIncoming
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

abstract interface DNSListener
{
  public abstract void updateRecord(JmDNSImpl paramJmDNSImpl, long paramLong, DNSRecord paramDNSRecord);
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

import java.io.IOException;
import java.util.Hashtable;
import java.util.LinkedList;

public final class DNSOutgoing
{
  public static boolean USE_DOMAIN_NAME_COMPRESSION = true;
  int id;
  int flags;
  private boolean multicast;
  private int numQuestions;
  private int numAnswers;
  private int numAuthorities;
  private int numAdditionals;
  private Hashtable names;
  byte[] data;
  int off;
  int len;
  
  public DNSOutgoing(int flags)
  {
    this(flags, true);
  }
  
  public DNSOutgoing(int flags, boolean multicast)
  {
    this.flags = flags;
    this.multicast = multicast;
    names = new Hashtable();
    data = new byte['?'];
    off = 12;
  }
  
  public void addQuestion(DNSQuestion rec)
    throws IOException
  {
    if ((numAnswers > 0) || (numAuthorities > 0) || (numAdditionals > 0)) {
      throw new IllegalStateException("Questions must be added before answers");
    }
    numQuestions += 1;
    writeQuestion(rec);
  }
  
  void addAnswer(DNSIncoming in, DNSRecord rec)
    throws IOException
  {
    if ((numAuthorities > 0) || (numAdditionals > 0)) {
      throw new IllegalStateException("Answers must be added before authorities and additionals");
    }
    if (!rec.suppressedBy(in)) {
      addAnswer(rec, 0L);
    }
  }
  
  void addAdditionalAnswer(DNSIncoming in, DNSRecord rec)
    throws IOException
  {
    if ((off < 1260) && (!rec.suppressedBy(in)))
    {
      writeRecord(rec, 0L);
      numAdditionals += 1;
    }
  }
  
  public void addAnswer(DNSRecord rec, long now)
    throws IOException
  {
    if ((numAuthorities > 0) || (numAdditionals > 0)) {
      throw new IllegalStateException("Questions must be added before answers");
    }
    if (rec != null) {
      if ((now == 0L) || (!rec.isExpired(now)))
      {
        writeRecord(rec, now);
        numAnswers += 1;
      }
    }
  }
  
  private LinkedList authorativeAnswers = new LinkedList();
  
  public void addAuthorativeAnswer(DNSRecord rec)
    throws IOException
  {
    if (numAdditionals > 0) {
      throw new IllegalStateException("Authorative answers must be added before additional answers");
    }
    authorativeAnswers.add(rec);
    writeRecord(rec, 0L);
    numAuthorities += 1;
  }
  
  void writeByte(int value)
    throws IOException
  {
    if (off >= data.length) {
      throw new IOException("buffer full");
    }
    data[(off++)] = ((byte)value);
  }
  
  void writeBytes(String str, int off, int len)
    throws IOException
  {
    for (int i = 0; i < len; i++) {
      writeByte(str.charAt(off + i));
    }
  }
  
  void writeBytes(byte[] data)
    throws IOException
  {
    if (data != null) {
      writeBytes(data, 0, data.length);
    }
  }
  
  void writeBytes(byte[] data, int off, int len)
    throws IOException
  {
    for (int i = 0; i < len; i++) {
      writeByte(data[(off + i)]);
    }
  }
  
  void writeShort(int value)
    throws IOException
  {
    writeByte(value >> 8);
    writeByte(value);
  }
  
  void writeInt(int value)
    throws IOException
  {
    writeShort(value >> 16);
    writeShort(value);
  }
  
  void writeUTF(String str, int off, int len)
    throws IOException
  {
    int utflen = 0;
    for (int i = 0; i < len; i++)
    {
      int ch = str.charAt(off + i);
      if ((ch >= 1) && (ch <= 127)) {
        utflen++;
      } else if (ch > 2047) {
        utflen += 3;
      } else {
        utflen += 2;
      }
    }
    writeByte(utflen);
    for (int i = 0; i < len; i++)
    {
      int ch = str.charAt(off + i);
      if ((ch >= 1) && (ch <= 127))
      {
        writeByte(ch);
      }
      else if (ch > 2047)
      {
        writeByte(0xE0 | ch >> 12 & 0xF);
        writeByte(0x80 | ch >> 6 & 0x3F);
        writeByte(0x80 | ch >> 0 & 0x3F);
      }
      else
      {
        writeByte(0xC0 | ch >> 6 & 0x1F);
        writeByte(0x80 | ch >> 0 & 0x3F);
      }
    }
  }
  
  void writeName(String name)
    throws IOException
  {
    writeName(name, true);
  }
  
  void writeName(String name, boolean useCompression)
    throws IOException
  {
    for (;;)
    {
      int n = name.indexOf('.');
      if (n < 0) {
        n = name.length();
      }
      if (n <= 0)
      {
        writeByte(0);
        return;
      }
      if ((useCompression) && (USE_DOMAIN_NAME_COMPRESSION))
      {
        Integer offset = (Integer)names.get(name);
        if (offset != null)
        {
          int val = offset.intValue();
          
          writeByte(val >> 8 | 0xC0);
          writeByte(val & 0xFF);
          return;
        }
        names.put(name, Integer.valueOf(off));
      }
      writeUTF(name, 0, n);
      name = name.substring(n);
      if (name.startsWith(".")) {
        name = name.substring(1);
      }
    }
  }
  
  void writeQuestion(DNSQuestion question)
    throws IOException
  {
    writeName(name);
    writeShort(type);
    writeShort(clazz);
  }
  
  void writeRecord(DNSRecord rec, long now)
    throws IOException
  {
    int save = off;
    try
    {
      writeName(name);
      writeShort(type);
      writeShort(clazz | ((unique) && (multicast) ? 32768 : 0));
      writeInt(now == 0L ? rec.getTtl() : rec.getRemainingTTL(now));
      writeShort(0);
      int start = off;
      rec.write(this);
      int len = off - start;
      data[(start - 2)] = ((byte)(len >> 8));
      data[(start - 1)] = ((byte)(len & 0xFF));
    }
    catch (IOException e)
    {
      off = save;
      throw e;
    }
  }
  
  void finish()
    throws IOException
  {
    int save = off;
    off = 0;
    
    writeShort(multicast ? 0 : id);
    writeShort(flags);
    writeShort(numQuestions);
    writeShort(numAnswers);
    writeShort(numAuthorities);
    writeShort(numAdditionals);
    off = save;
  }
  
  boolean isQuery()
  {
    return (flags & 0x8000) == 0;
  }
  
  public boolean isEmpty()
  {
    return (numQuestions == 0) && (numAuthorities == 0) && (numAdditionals == 0) && (numAnswers == 0);
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append(isQuery() ? "dns[query," : "dns[response,");
    
    buf.append(':');
    
    buf.append(",id=0x");
    buf.append(Integer.toHexString(id));
    if (flags != 0)
    {
      buf.append(",flags=0x");
      buf.append(Integer.toHexString(flags));
      if ((flags & 0x8000) != 0) {
        buf.append(":r");
      }
      if ((flags & 0x400) != 0) {
        buf.append(":aa");
      }
      if ((flags & 0x200) != 0) {
        buf.append(":tc");
      }
    }
    if (numQuestions > 0)
    {
      buf.append(",questions=");
      buf.append(numQuestions);
    }
    if (numAnswers > 0)
    {
      buf.append(",answers=");
      buf.append(numAnswers);
    }
    if (numAuthorities > 0)
    {
      buf.append(",authorities=");
      buf.append(numAuthorities);
    }
    if (numAdditionals > 0)
    {
      buf.append(",additionals=");
      buf.append(numAdditionals);
    }
    buf.append(",\nnames=" + names);
    buf.append(",\nauthorativeAnswers=" + authorativeAnswers);
    
    buf.append("]");
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSOutgoing
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

public final class DNSQuestion
  extends DNSEntry
{
  public DNSQuestion(String name, int type, int clazz)
  {
    super(name, type, clazz);
  }
  
  boolean answeredBy(DNSRecord rec)
  {
    return (clazz == clazz) && ((type == type) || (type == 255)) && (name.equals(name));
  }
  
  public String toString()
  {
    return toString("question", null);
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSQuestion
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

class DNSRecord$Address
  extends DNSRecord
{
  InetAddress addr;
  
  DNSRecord$Address(String name, int type, int clazz, int ttl, InetAddress addr)
  {
    super(name, type, clazz, ttl);
    this.addr = addr;
  }
  
  DNSRecord$Address(String name, int type, int clazz, int ttl, byte[] rawAddress)
  {
    super(name, type, clazz, ttl);
    try
    {
      addr = InetAddress.getByAddress(rawAddress);
    }
    catch (UnknownHostException localUnknownHostException) {}
  }
  
  void write(DNSOutgoing out)
    throws IOException
  {
    if (addr != null)
    {
      byte[] buffer = addr.getAddress();
      if (1 == type)
      {
        if (!(addr instanceof Inet4Address))
        {
          byte[] tempbuffer = buffer;
          buffer = new byte[4];
          System.arraycopy(tempbuffer, 12, buffer, 0, 4);
        }
      }
      else if ((addr instanceof Inet4Address))
      {
        byte[] tempbuffer = buffer;
        buffer = new byte[16];
        for (int i = 0; i < 16; i++) {
          if (i < 11) {
            buffer[i] = tempbuffer[(i - 12)];
          } else {
            buffer[i] = 0;
          }
        }
      }
      int length = buffer.length;
      out.writeBytes(buffer, 0, length);
    }
  }
  
  boolean same(DNSRecord other)
  {
    return (sameName(other)) && (sameValue(other));
  }
  
  boolean sameName(DNSRecord other)
  {
    return name.equalsIgnoreCase(name);
  }
  
  boolean sameValue(DNSRecord other)
  {
    return addr.equals(((Address)other).getAddress());
  }
  
  InetAddress getAddress()
  {
    return addr;
  }
  
  private byte[] toByteArray()
  {
    try
    {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      DataOutputStream dout = new DataOutputStream(bout);
      dout.write(name.getBytes("UTF8"));
      dout.writeShort(type);
      dout.writeShort(clazz);
      
      byte[] buffer = addr.getAddress();
      for (int i = 0; i < buffer.length; i++) {
        dout.writeByte(buffer[i]);
      }
      dout.close();
      return bout.toByteArray();
    }
    catch (IOException e)
    {
      throw new InternalError();
    }
  }
  
  private int lexCompare(Address that)
  {
    byte[] thisBytes = toByteArray();
    byte[] thatBytes = that.toByteArray();
    int i = 0;
    for (int n = Math.min(thisBytes.length, thatBytes.length); i < n; i++)
    {
      if (thisBytes[i] > thatBytes[i]) {
        return 1;
      }
      if (thisBytes[i] < thatBytes[i]) {
        return -1;
      }
    }
    return thisBytes.length - thatBytes.length;
  }
  
  boolean handleQuery(JmDNSImpl dns, long expirationTime)
  {
    Address dnsAddress = dns.getLocalHost().getDNSAddressRecord(this);
    if (dnsAddress != null) {
      if ((dnsAddress.sameType(this)) && (dnsAddress.sameName(this)) && (!dnsAddress.sameValue(this)))
      {
        if ((dns.getState().isProbing()) && (lexCompare(dnsAddress) >= 0))
        {
          dns.getLocalHost().incrementHostName();
          dns.getCache().clear();
          for (Iterator i = dns.getServices().values().iterator(); i.hasNext();)
          {
            ServiceInfoImpl info = (ServiceInfoImpl)i.next();
            info.revertState();
          }
        }
        dns.revertState();
        return true;
      }
    }
    return false;
  }
  
  boolean handleResponse(JmDNSImpl dns)
  {
    Address dnsAddress = dns.getLocalHost().getDNSAddressRecord(this);
    if (dnsAddress != null) {
      if ((dnsAddress.sameType(this)) && (dnsAddress.sameName(this)) && (!dnsAddress.sameValue(this)))
      {
        if (dns.getState().isProbing())
        {
          dns.getLocalHost().incrementHostName();
          dns.getCache().clear();
          for (Iterator i = dns.getServices().values().iterator(); i.hasNext();)
          {
            ServiceInfoImpl info = (ServiceInfoImpl)i.next();
            info.revertState();
          }
        }
        dns.revertState();
        return true;
      }
    }
    return false;
  }
  
  DNSOutgoing addAnswer(JmDNSImpl dns, DNSIncoming in, InetAddress addr, int port, DNSOutgoing out)
    throws IOException
  {
    return out;
  }
  
  public String toString()
  {
    return toString(" address '" + (addr != null ? addr.getHostAddress() : "null") + "'");
  }
}

/* Location:
 * Qualified Name:     javax.jmdns.impl.DNSRecord.Address
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package javax.jmdns.impl;

import java.io.IOException;
import java.net.InetAddress;

public class DNSRecord$Pointer
  extends DNSRecord
{
  String alias;
  
  public DNSRecord$Pointer(String name, int type, int clazz, int ttl, String alias)
  {
    super(name, type, clazz, ttl);
    this.alias = alias;
  }
  
  void write(DNSOutgoing out)
    throws IOException
  {
    out.writeName(alias);
  }
  
  boolean sameValue(DNSRecord other)
  {
    return alias.equals(alias);
  }
  
  boolean handleQuery(JmDNSImpl dns, long expirationTime)
  {
    return false;
  }
  
  boolean handleResponse(JmDNSImpl dns)
  {
    return false;
  }
  
  String getAlias()
  {
    return alias;
  }
  
  DNSOutgoing addAnswer(
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd