From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- OpenSim/Server/Base/ServerUtils.cs | 179 ++++++++++++++++++++++++------------- 1 file changed, 116 insertions(+), 63 deletions(-) (limited to 'OpenSim/Server/Base/ServerUtils.cs') diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 18a4266..cc506bc 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -39,7 +39,7 @@ using OpenMetaverse; using Mono.Addins; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Framework.Servers; - +using OpenMetaverse.StructuredData; // LitJson is hidden on this [assembly:AddinRoot("Robust", OpenSim.VersionInfo.VersionNumber)] namespace OpenSim.Server.Base @@ -104,7 +104,7 @@ namespace OpenSim.Server.Base // libomv, which has a hard-coded path to "." for pinvoke // to load the openjpeg dll // - // Will look for a way to fix, but for now this keeps the + // Will look for a way to fix, but for now this keeps the // confusion to a minimum. this was copied from our region // plugin loader, we have been doing this in there for a long time. // @@ -183,7 +183,7 @@ namespace OpenSim.Server.Base if(port != 0) server = MainServer.GetHttpServer(port); - else + else server = MainServer.Instance; return server; @@ -222,19 +222,19 @@ namespace OpenSim.Server.Base // This is good to debug configuration problems //if (dllName == string.Empty) // Util.PrintCallStack(); - + string className = String.Empty; // The path for a dynamic plugin will contain ":" on Windows string[] parts = dllName.Split (new char[] {':'}); - if (parts [0].Length > 1) + if (parts [0].Length > 1) { dllName = parts [0]; if (parts.Length > 1) className = parts[1]; - } - else + } + else { // This is Windows - we must replace the ":" in the path dllName = String.Format ("{0}:{1}", parts [0], parts [1]); @@ -242,6 +242,18 @@ namespace OpenSim.Server.Base className = parts[2]; } + // Handle extra string arguments in a more generic way + if (dllName.Contains("@")) + { + string[] dllNameParts = dllName.Split(new char[] {'@'}); + dllName = dllNameParts[dllNameParts.Length - 1]; + List argList = new List(args); + for (int i = 0 ; i < dllNameParts.Length - 1 ; ++i) + argList.Add(dllNameParts[i]); + + args = argList.ToArray(); + } + return LoadPlugin(dllName, className, args); } @@ -264,10 +276,10 @@ namespace OpenSim.Server.Base { if (pluginType.IsPublic) { - if (className != String.Empty + if (className != String.Empty && pluginType.ToString() != pluginType.Namespace + "." + className) continue; - + Type typeInterface = pluginType.GetInterface(interfaceName); if (typeInterface != null) @@ -283,8 +295,8 @@ namespace OpenSim.Server.Base if (!(e is System.MissingMethodException)) { m_log.Error(string.Format("[SERVER UTILS]: Error loading plugin {0} from {1}. Exception: {2}", - interfaceName, - dllName, + interfaceName, + dllName, e.InnerException == null ? e.Message : e.InnerException.Message), e); } @@ -315,49 +327,62 @@ namespace OpenSim.Server.Base public static Dictionary ParseQueryString(string query) { - Dictionary result = new Dictionary(); string[] terms = query.Split(new char[] {'&'}); - if (terms.Length == 0) - return result; + int nterms = terms.Length; + if (nterms == 0) + return new Dictionary(); - foreach (string t in terms) + Dictionary result = new Dictionary(nterms); + string name; + + for(int i = 0; i < nterms; ++i) { - string[] elems = t.Split(new char[] {'='}); + string[] elems = terms[i].Split(new char[] {'='}); + if (elems.Length == 0) continue; - string name = System.Web.HttpUtility.UrlDecode(elems[0]); - string value = String.Empty; + if(String.IsNullOrWhiteSpace(elems[0])) + continue; - if (elems.Length > 1) - value = System.Web.HttpUtility.UrlDecode(elems[1]); + name = System.Web.HttpUtility.UrlDecode(elems[0]); if (name.EndsWith("[]")) { - string cleanName = name.Substring(0, name.Length - 2); - if (result.ContainsKey(cleanName)) + name = name.Substring(0, name.Length - 2); + if(String.IsNullOrWhiteSpace(name)) + continue; + if (result.ContainsKey(name)) { - if (!(result[cleanName] is List)) + if (!(result[name] is List)) continue; - List l = (List)result[cleanName]; - - l.Add(value); + List l = (List)result[name]; + if (elems.Length > 1 && !String.IsNullOrWhiteSpace(elems[1])) + l.Add(System.Web.HttpUtility.UrlDecode(elems[1])); + else + l.Add(String.Empty); } else { List newList = new List(); - - newList.Add(value); - - result[cleanName] = newList; + if (elems.Length > 1 && !String.IsNullOrWhiteSpace(elems[1])) + newList.Add(System.Web.HttpUtility.UrlDecode(elems[1])); + else + newList.Add(String.Empty); + result[name] = newList; } } else { if (!result.ContainsKey(name)) - result[name] = value; + { + if (elems.Length > 1 && !String.IsNullOrWhiteSpace(elems[1])) + result[name] = System.Web.HttpUtility.UrlDecode(elems[1]); + else + result[name] = String.Empty; + } } } @@ -366,47 +391,70 @@ namespace OpenSim.Server.Base public static string BuildQueryString(Dictionary data) { - string qstring = String.Empty; + // this is not conform to html url encoding + // can only be used on Body of POST or PUT + StringBuilder sb = new StringBuilder(4096); - string part; + string pvalue; foreach (KeyValuePair kvp in data) { if (kvp.Value is List) { List l = (List)kvp.Value; - - foreach (string s in l) + int llen = l.Count; + string nkey = System.Web.HttpUtility.UrlEncode(kvp.Key); + for(int i = 0; i < llen; ++i) { - part = System.Web.HttpUtility.UrlEncode(kvp.Key) + - "[]=" + System.Web.HttpUtility.UrlEncode(s); - - if (qstring != String.Empty) - qstring += "&"; - - qstring += part; + if (sb.Length != 0) + sb.Append("&"); + sb.Append(nkey); + sb.Append("[]="); + sb.Append(System.Web.HttpUtility.UrlEncode(l[i])); } } - else + else if(kvp.Value is Dictionary) { - if (kvp.Value.ToString() != String.Empty) + // encode complex structures as JSON + // needed for estate bans with the encoding used on xml + // encode can be here because object does contain the structure information + // but decode needs to be on estateSettings (or other user) + string js; + try { - part = System.Web.HttpUtility.UrlEncode(kvp.Key) + - "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); + // bypass libovm, we dont need even more useless high level maps + // this should only be called once.. but no problem, i hope + // (other uses may need more..) + LitJson.JsonMapper.RegisterExporter((uuid, writer) => writer.Write(uuid.ToString()) ); + js = LitJson.JsonMapper.ToJson(kvp.Value); } - else + // catch(Exception e) + catch { - part = System.Web.HttpUtility.UrlEncode(kvp.Key); + continue; + } + if (sb.Length != 0) + sb.Append("&"); + sb.Append(System.Web.HttpUtility.UrlEncode(kvp.Key)); + sb.Append("="); + sb.Append(System.Web.HttpUtility.UrlEncode(js)); + } + else + { + if (sb.Length != 0) + sb.Append("&"); + sb.Append(System.Web.HttpUtility.UrlEncode(kvp.Key)); + + pvalue = kvp.Value.ToString(); + if (!String.IsNullOrEmpty(pvalue)) + { + sb.Append("="); + sb.Append(System.Web.HttpUtility.UrlEncode(pvalue)); } - - if (qstring != String.Empty) - qstring += "&"; - - qstring += part; } } - return qstring; + return sb.ToString(); } public static string BuildXmlResponse(Dictionary data) @@ -465,18 +513,23 @@ namespace OpenSim.Server.Base Dictionary ret = new Dictionary(); XmlDocument doc = new XmlDocument(); + doc.XmlResolver = null; + try + { + doc.LoadXml(data); + XmlNodeList rootL = doc.GetElementsByTagName("ServerResponse"); - doc.LoadXml(data); - - XmlNodeList rootL = doc.GetElementsByTagName("ServerResponse"); - - if (rootL.Count != 1) - return ret; - - XmlNode rootNode = rootL[0]; + if (rootL.Count != 1) + return ret; - ret = ParseElement(rootNode); + XmlNode rootNode = rootL[0]; + ret = ParseElement(rootNode); + } + catch (Exception e) + { + m_log.DebugFormat("[serverUtils.ParseXmlResponse]: failed error: {0} \n --- string: {1} - ",e.Message, data); + } return ret; } -- cgit v1.1