aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs')
-rw-r--r--Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs337
1 files changed, 168 insertions, 169 deletions
diff --git a/Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs b/Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs
index c94d0a260..7d8dd8bbf 100644
--- a/Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs
+++ b/Emby.Common.Implementations/IO/SharpCifs/Netbios/Lmhosts.cs
@@ -21,182 +21,181 @@ using SharpCifs.Util.Sharpen;
namespace SharpCifs.Netbios
{
- public class Lmhosts
- {
- private static readonly string Filename = Config.GetProperty("jcifs.netbios.lmhosts"
- );
+ public class Lmhosts
+ {
+ private static readonly string Filename = Config.GetProperty("jcifs.netbios.lmhosts");
- private static readonly Hashtable Tab = new Hashtable();
+ private static readonly Hashtable Tab = new Hashtable();
- private static long _lastModified = 1L;
+ private static long _lastModified = 1L;
- private static int _alt;
+ private static int _alt;
- private static LogStream _log = LogStream.GetInstance();
+ private static LogStream _log = LogStream.GetInstance();
- /// <summary>
- /// This is really just for
- /// <see cref="SharpCifs.UniAddress">Jcifs.UniAddress</see>
- /// . It does
- /// not throw an
- /// <see cref="UnknownHostException">Sharpen.UnknownHostException</see>
- /// because this
- /// is queried frequently and exceptions would be rather costly to
- /// throw on a regular basis here.
- /// </summary>
- public static NbtAddress GetByName(string host)
- {
- lock (typeof(Lmhosts))
- {
- return GetByName(new Name(host, 0x20, null));
- }
- }
+ /// <summary>
+ /// This is really just for
+ /// <see cref="SharpCifs.UniAddress">Jcifs.UniAddress</see>
+ /// . It does
+ /// not throw an
+ /// <see cref="UnknownHostException">Sharpen.UnknownHostException</see>
+ /// because this
+ /// is queried frequently and exceptions would be rather costly to
+ /// throw on a regular basis here.
+ /// </summary>
+ public static NbtAddress GetByName(string host)
+ {
+ lock (typeof(Lmhosts))
+ {
+ return GetByName(new Name(host, 0x20, null));
+ }
+ }
- internal static NbtAddress GetByName(Name name)
- {
- lock (typeof(Lmhosts))
- {
- NbtAddress result = null;
- try
- {
- if (Filename != null)
- {
- FilePath f = new FilePath(Filename);
- long lm;
- if ((lm = f.LastModified()) > _lastModified)
- {
- _lastModified = lm;
- Tab.Clear();
- _alt = 0;
-
- //path -> fileStream
- //Populate(new FileReader(f));
+ internal static NbtAddress GetByName(Name name)
+ {
+ lock (typeof(Lmhosts))
+ {
+ NbtAddress result = null;
+ try
+ {
+ if (Filename != null)
+ {
+ FilePath f = new FilePath(Filename);
+ long lm;
+ if ((lm = f.LastModified()) > _lastModified)
+ {
+ _lastModified = lm;
+ Tab.Clear();
+ _alt = 0;
+
+ //path -> fileStream
+ //Populate(new FileReader(f));
Populate(new FileReader(new FileStream(f, FileMode.Open)));
- }
- result = (NbtAddress)Tab[name];
- }
- }
- catch (FileNotFoundException fnfe)
- {
- if (_log.Level > 1)
- {
- _log.WriteLine("lmhosts file: " + Filename);
- Runtime.PrintStackTrace(fnfe, _log);
- }
- }
- catch (IOException ioe)
- {
- if (_log.Level > 0)
- {
- Runtime.PrintStackTrace(ioe, _log);
- }
- }
- return result;
- }
- }
+ }
+ result = (NbtAddress)Tab[name];
+ }
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ if (_log.Level > 1)
+ {
+ _log.WriteLine("lmhosts file: " + Filename);
+ Runtime.PrintStackTrace(fnfe, _log);
+ }
+ }
+ catch (IOException ioe)
+ {
+ if (_log.Level > 0)
+ {
+ Runtime.PrintStackTrace(ioe, _log);
+ }
+ }
+ return result;
+ }
+ }
- /// <exception cref="System.IO.IOException"></exception>
- internal static void Populate(StreamReader r)
- {
- string line;
+ /// <exception cref="System.IO.IOException"></exception>
+ internal static void Populate(StreamReader r)
+ {
+ string line;
BufferedReader br = new BufferedReader((InputStreamReader)r);
- while ((line = br.ReadLine()) != null)
- {
- line = line.ToUpper().Trim();
- if (line.Length == 0)
- {
- }
- else
- {
- if (line[0] == '#')
- {
- if (line.StartsWith("#INCLUDE "))
- {
- line = Runtime.Substring(line, line.IndexOf('\\'));
- string url = "smb:" + line.Replace('\\', '/');
- if (_alt > 0)
- {
- try
- {
- Populate(new InputStreamReader(new SmbFileInputStream(url)));
- }
- catch (IOException ioe)
- {
- _log.WriteLine("lmhosts URL: " + url);
- Runtime.PrintStackTrace(ioe, _log);
- continue;
- }
- _alt--;
- while ((line = br.ReadLine()) != null)
- {
- line = line.ToUpper().Trim();
- if (line.StartsWith("#END_ALTERNATE"))
- {
- break;
- }
- }
- }
- else
- {
- Populate(new InputStreamReader(new SmbFileInputStream(url)));
- }
- }
- else
- {
- if (line.StartsWith("#BEGIN_ALTERNATE"))
- {
- _alt++;
- }
- else
- {
- if (line.StartsWith("#END_ALTERNATE") && _alt > 0)
- {
- _alt--;
- throw new IOException("no lmhosts alternate includes loaded");
- }
- }
- }
- }
- else
- {
- if (char.IsDigit(line[0]))
- {
- char[] data = line.ToCharArray();
- int ip;
- int i;
- int j;
- Name name;
- NbtAddress addr;
- char c;
- c = '.';
- ip = i = 0;
- for (; i < data.Length && c == '.'; i++)
- {
- int b = unchecked(0x00);
- for (; i < data.Length && (c = data[i]) >= 48 && c <= 57; i++)
- {
- b = b * 10 + c - '0';
- }
- ip = (ip << 8) + b;
- }
- while (i < data.Length && char.IsWhiteSpace(data[i]))
- {
- i++;
- }
- j = i;
- while (j < data.Length && char.IsWhiteSpace(data[j]) == false)
- {
- j++;
- }
- name = new Name(Runtime.Substring(line, i, j), unchecked(0x20), null
- );
- addr = new NbtAddress(name, ip, false, NbtAddress.BNode, false, false, true, true
- , NbtAddress.UnknownMacAddress);
- Tab.Put(name, addr);
- }
- }
- }
- }
- }
- }
+ while ((line = br.ReadLine()) != null)
+ {
+ line = line.ToUpper().Trim();
+ if (line.Length == 0)
+ {
+ }
+ else
+ {
+ if (line[0] == '#')
+ {
+ if (line.StartsWith("#INCLUDE "))
+ {
+ line = Runtime.Substring(line, line.IndexOf('\\'));
+ string url = "smb:" + line.Replace('\\', '/');
+ if (_alt > 0)
+ {
+ try
+ {
+ Populate(new InputStreamReader(new SmbFileInputStream(url)));
+ }
+ catch (IOException ioe)
+ {
+ _log.WriteLine("lmhosts URL: " + url);
+ Runtime.PrintStackTrace(ioe, _log);
+ continue;
+ }
+ _alt--;
+ while ((line = br.ReadLine()) != null)
+ {
+ line = line.ToUpper().Trim();
+ if (line.StartsWith("#END_ALTERNATE"))
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ Populate(new InputStreamReader(new SmbFileInputStream(url)));
+ }
+ }
+ else
+ {
+ if (line.StartsWith("#BEGIN_ALTERNATE"))
+ {
+ _alt++;
+ }
+ else
+ {
+ if (line.StartsWith("#END_ALTERNATE") && _alt > 0)
+ {
+ _alt--;
+ throw new IOException("no lmhosts alternate includes loaded");
+ }
+ }
+ }
+ }
+ else
+ {
+ if (char.IsDigit(line[0]))
+ {
+ char[] data = line.ToCharArray();
+ int ip;
+ int i;
+ int j;
+ Name name;
+ NbtAddress addr;
+ char c;
+ c = '.';
+ ip = i = 0;
+ for (; i < data.Length && c == '.'; i++)
+ {
+ int b = unchecked(0x00);
+ for (; i < data.Length && (c = data[i]) >= 48 && c <= 57; i++)
+ {
+ b = b * 10 + c - '0';
+ }
+ ip = (ip << 8) + b;
+ }
+ while (i < data.Length && char.IsWhiteSpace(data[i]))
+ {
+ i++;
+ }
+ j = i;
+ while (j < data.Length && char.IsWhiteSpace(data[j]) == false)
+ {
+ j++;
+ }
+ name = new Name(Runtime.Substring(line, i, j), unchecked(0x20), null
+ );
+ addr = new NbtAddress(name, ip, false, NbtAddress.BNode, false, false, true, true
+ , NbtAddress.UnknownMacAddress);
+ Tab.Put(name, addr);
+ }
+ }
+ }
+ }
+ }
+ }
}