Proto: Typed Tree implementation for VirtualHost
This commit is contained in:
parent
492b37747d
commit
6868e16d6e
|
@ -31,6 +31,10 @@ namespace Sharp.Augeas
|
||||||
public Augeas(AugSettings augSettings)
|
public Augeas(AugSettings augSettings)
|
||||||
{
|
{
|
||||||
_augeas = init_aug(augSettings, NO_STDINC | NO_LOAD);
|
_augeas = init_aug(augSettings, NO_STDINC | NO_LOAD);
|
||||||
|
if (_augeas == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Augeas is not a valid instance.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -44,20 +48,35 @@ namespace Sharp.Augeas
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finalize the augeas instance.
|
/// Get the exact value of the matchPath.
|
||||||
|
/// Returns a empty string if no match is valid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Close()
|
/// <param name="matchPath">Augeas path to filter out the configuration.</param>
|
||||||
|
public string GetNode(string matchPath)
|
||||||
|
{
|
||||||
|
return new string(get_node(_augeas, matchPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Close augeas pointer.
|
||||||
|
/// </summary>
|
||||||
|
private void Close()
|
||||||
{
|
{
|
||||||
close_aug(_augeas);
|
close_aug(_augeas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finalize the augeas instance.
|
/// Loads a file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="configurationFilePath">Full path to the configuration file</param>
|
||||||
public void LoadFile(string configurationFilePath)
|
public void LoadFile(string configurationFilePath)
|
||||||
{
|
{
|
||||||
if (_augeas == IntPtr.Zero) return;
|
bool success = load_file(_augeas, configurationFilePath);
|
||||||
load_file(_augeas, configurationFilePath);
|
if (!success)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unable to load {configurationFilePath}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Sharp.Augeas
|
||||||
[DllImport(_libName)] public static extern void print_preview(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
[DllImport(_libName)] public static extern void print_preview(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
||||||
[DllImport(_libName)] public static extern void print_tree(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
[DllImport(_libName)] public static extern void print_tree(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
||||||
[DllImport(_libName)] public static extern char* get_tree(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
[DllImport(_libName)] public static extern char* get_tree(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
||||||
[DllImport(_libName)] public static extern void defNode( AugSettings settings, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
[DllImport(_libName)] public static extern char* get_node(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string matchPath);
|
||||||
[DllImport(_libName)] public static extern void load_file(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string filePath);
|
[DllImport(_libName)] public static extern bool load_file(IntPtr augeas, [MarshalAs(UnmanagedType.LPStr)] string filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,6 @@ public interface IProxyArg : IArg, IProxyData { }
|
||||||
|
|
||||||
public interface IDirectiveConfig<T> : IAugConfig { }
|
public interface IDirectiveConfig<T> : IAugConfig { }
|
||||||
|
|
||||||
public interface IVirtualHostConfig : IAugConfig { }
|
public interface IVirtualHost : IAugConfig, IVirtualHostData { }
|
||||||
|
|
||||||
public interface IVirtualHostArg : IArg, IVirtualHostData { };
|
public interface IVirtualHostArg : IArg, IVirtualHostData { };
|
|
@ -0,0 +1,20 @@
|
||||||
|
namespace Sharp.Augeas;
|
||||||
|
|
||||||
|
public class Argument<T> : Node where T: Node
|
||||||
|
{
|
||||||
|
public new T Parent;
|
||||||
|
|
||||||
|
public string Value;
|
||||||
|
|
||||||
|
public Argument(T parent, string value)
|
||||||
|
{
|
||||||
|
Parent = parent;
|
||||||
|
Children = null;
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Argument()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Sharp.Augeas;
|
||||||
|
|
||||||
|
public class Directive<T> : Node where T: Node
|
||||||
|
{
|
||||||
|
public string Value;
|
||||||
|
public List<Argument<Directive<T>>> Arguments;
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Sharp.Augeas.VirtualHost;
|
|
||||||
|
|
||||||
public class DirectiveArg
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
namespace Sharp.Augeas;
|
||||||
|
|
||||||
|
public class Node
|
||||||
|
{
|
||||||
|
public Node Parent;
|
||||||
|
public List<Node> Children;
|
||||||
|
|
||||||
|
|
||||||
|
public Node()
|
||||||
|
{
|
||||||
|
Parent = null;
|
||||||
|
Children = new List<Node>();
|
||||||
|
}
|
||||||
|
public Node(Node parent)
|
||||||
|
{
|
||||||
|
Parent = parent;
|
||||||
|
Children = new List<Node>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] GetChildren<T>()
|
||||||
|
{
|
||||||
|
return Children
|
||||||
|
.OfType<T>()
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node(Node parent, List<Node> children)
|
||||||
|
{
|
||||||
|
Parent = parent;
|
||||||
|
Children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddChild(Node node)
|
||||||
|
{
|
||||||
|
Children.Add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveChild(Node child)
|
||||||
|
{
|
||||||
|
if (Children.Contains(child))
|
||||||
|
{
|
||||||
|
Children.Remove(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveAllChildren()
|
||||||
|
{
|
||||||
|
Children = new List<Node>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace Sharp.Augeas;
|
||||||
|
|
||||||
|
public class Proxy : Node
|
||||||
|
{
|
||||||
|
public new VirtualHost Parent;
|
||||||
|
public List<Directive<Proxy>> Directives;
|
||||||
|
public List<Argument<Proxy>> Arguments;
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Sharp.Augeas.VirtualHost;
|
|
||||||
|
|
||||||
public class ProxyArg
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Sharp.Augeas.VirtualHost;
|
|
||||||
|
|
||||||
public class ProxyDirective
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Sharp.Augeas
|
||||||
|
{
|
||||||
|
public class VirtualHost
|
||||||
|
{
|
||||||
|
public List<Directive<Proxy>> Directives;
|
||||||
|
public List<Argument<Proxy>> Arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Sharp.Augeas.VirtualHost;
|
|
||||||
|
|
||||||
public class VirtualHostArg
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Sharp.Augeas.VirtualHost;
|
|
||||||
|
|
||||||
public class VirtualHostDirective
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
namespace Sharp.Augeas;
|
||||||
|
|
||||||
|
public static class VirtualHostTreeGenerator
|
||||||
|
{
|
||||||
|
public static VirtualHost Generate(Dictionary<string,string> dic)
|
||||||
|
{
|
||||||
|
var keys = dic.Keys;
|
||||||
|
var virtualHost = new VirtualHost();
|
||||||
|
foreach (var key in keys)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return virtualHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsProxy(string key)
|
||||||
|
{
|
||||||
|
return key.Contains("f/VirtualHost/Proxy/");
|
||||||
|
}
|
||||||
|
private static bool IsVirtualHostArg(string key)
|
||||||
|
{
|
||||||
|
return key.Contains("f/VirtualHost/arg;");
|
||||||
|
}
|
||||||
|
private static bool IsProxyDirective(string key)
|
||||||
|
{
|
||||||
|
return key.Contains("f/VirtualHost/Proxy/directive");
|
||||||
|
}
|
||||||
|
private static bool IsVirtualHostDirective(string key)
|
||||||
|
{
|
||||||
|
return key.Contains("f/VirtualHost/directive");
|
||||||
|
}
|
||||||
|
private static bool IsDirectiveArg(string key)
|
||||||
|
{
|
||||||
|
return key.Contains("f/VirtualHost/directive");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ DESTIN=$SCRIPT_DIR/bin/Debug/net6.0
|
||||||
# Set the $CLAUG_LIB_PATH to the PATH where the claugeas library is located before running this script
|
# Set the $CLAUG_LIB_PATH to the PATH where the claugeas library is located before running this script
|
||||||
|
|
||||||
if [[ -z "${CLAUG_LIB_PATH}" ]]; then
|
if [[ -z "${CLAUG_LIB_PATH}" ]]; then
|
||||||
echo "error: set the CLAUG_LIB_PATH in the ${LIB_FILE} location."
|
echo "error: set the CLAUG_LIB_PATH with the ${LIB_FILE} location."
|
||||||
echo
|
echo
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue