Add plugin path, separate search plugins
[WebThing.git] / Config.cs
index 3ffd66d..b8f04cd 100644 (file)
--- a/Config.cs
+++ b/Config.cs
@@ -5,14 +5,27 @@ using System.Collections.Generic;
 using System.Text.RegularExpressions;
 
 namespace bytex64.WebThing {
+    public struct SearchHandlerPair {
+        public string Shortcut;
+        public string Plugin;
+
+        public SearchHandlerPair(string s, string p) {
+            Shortcut = s;
+            Plugin = p;
+        }
+    }
+
     public class Config {
         public static List<string> ConfigPath;
         public static string ConfigPathOut = null;
+        public static List<string> PluginPath;
 
         public static Dictionary<string,string> Options;
         public static Dictionary<string,Dictionary<string,string>> PluginOptions;
         public static string[] Arguments;
         public static List<string> Plugins;
+        public static List<SearchHandlerPair> SearchHandlers;
+        public static string DefaultSearchHandler;
 
         private static HashSet<string> CommandLineOptions;
         private static Regex item_re = new Regex(@"^(?:([\w.]+)\.)?(\w+)$");
@@ -24,6 +37,7 @@ namespace bytex64.WebThing {
             PluginOptions = new Dictionary<string,Dictionary<string,string>>();
             CommandLineOptions = new HashSet<string>();
             Plugins = new List<string>();
+            SearchHandlers = new List<SearchHandlerPair>();
 
             // Set up ConfigPath
             IDictionary Env = Environment.GetEnvironmentVariables();
@@ -42,6 +56,11 @@ namespace bytex64.WebThing {
                 if (Directory.Exists(homepath))
                     ConfigPathOut = homepath;
             }
+
+            // Set up PluginPath
+            PluginPath = new List<string>();
+            PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/plugins");
+            PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/searchplugins");
         }
 
         private static void ParseOption(string key, string val) {
@@ -53,8 +72,7 @@ namespace bytex64.WebThing {
                     PluginOptions[plugin] = new Dictionary<string,string>();
                 PluginOptions[plugin][name] = val;
             } else {                   // Global Option
-                switch(key) {
-                case "Plugin":
+                switch(key.ToLower()) {
                 case "plugin":
                     Plugins.Add(val);
                     break;
@@ -169,12 +187,22 @@ namespace bytex64.WebThing {
 
                 m = file_command_re.Match(line);
                 if (m.Success) {
-                    string cmd = m.Groups[1].Value;
+                    string cmd = m.Groups[1].Value.ToLower();
                     switch(cmd) {
-                    case "Plugin":
                     case "plugin":
                         Plugins.Add(m.Groups[2].Value);
                         break;
+                    case "searchhandler":
+                        string[] args = Regex.Split(m.Groups[2].Value, @"\s+");
+                        if (args.Length != 2) {
+                            Console.WriteLine("Expecting two arguments for SearchHandler.");
+                            break;
+                        }
+                        SearchHandlers.Add(new SearchHandlerPair(args[0], args[1]));
+                        break;
+                    case "defaultsearchhandler":
+                        DefaultSearchHandler = m.Groups[2].Value;
+                        break;
                     default:
                         Console.WriteLine("Unknown Command in {0}: {1}", filename, line);
                         break;