diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
index 5f5dc025e7..8b831a5d99 100644
--- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
+++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
@@ -32,6 +32,8 @@
+
+
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs
new file mode 100644
index 0000000000..0c8ee61e6d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using log4net;
+using Nini.Config;
+using OpenSim.Region.Framework.Interfaces;
+using OpenSim.Region.Framework.Scenes;
+using OpenSim.Server.Base;
+using OpenSim.Services.Interfaces;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
+{
+ public class LocalAvatarServicesConnector : ISharedRegionModule, IAvatarService
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(
+ MethodBase.GetCurrentMethod().DeclaringType);
+
+ private IAvatarService m_AvatarService;
+
+ private bool m_Enabled = false;
+
+ #region ISharedRegionModule
+
+ public Type ReplaceableInterface
+ {
+ get { return null; }
+ }
+
+ public string Name
+ {
+ get { return "LocalAvatarServicesConnector"; }
+ }
+
+ public void Initialise(IConfigSource source)
+ {
+ IConfig moduleConfig = source.Configs["Modules"];
+ if (moduleConfig != null)
+ {
+ string name = moduleConfig.GetString("AvatarServices", "");
+ if (name == Name)
+ {
+ IConfig userConfig = source.Configs["AvatarService"];
+ if (userConfig == null)
+ {
+ m_log.Error("[USER CONNECTOR]: AvatarService missing from OpenSim.ini");
+ return;
+ }
+
+ string serviceDll = userConfig.GetString("LocalServiceModule",
+ String.Empty);
+
+ if (serviceDll == String.Empty)
+ {
+ m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section AvatarService");
+ return;
+ }
+
+ Object[] args = new Object[] { source };
+ m_AvatarService =
+ ServerUtils.LoadPlugin(serviceDll,
+ args);
+
+ if (m_AvatarService == null)
+ {
+ m_log.Error("[USER CONNECTOR]: Can't load user account service");
+ return;
+ }
+ m_Enabled = true;
+ m_log.Info("[USER CONNECTOR]: Local avatar connector enabled");
+ }
+ }
+ }
+
+ public void PostInitialise()
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void Close()
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void AddRegion(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+
+ scene.RegisterModuleInterface(m_AvatarService);
+ }
+
+ public void RemoveRegion(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void RegionLoaded(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ #endregion
+
+ #region IAvatarService
+
+ public AvatarData GetAvatar(UUID userID)
+ {
+ return m_AvatarService.GetAvatar(userID);
+ }
+
+ public bool SetAvatar(UUID userID, AvatarData avatar)
+ {
+ return m_AvatarService.SetAvatar(userID, avatar);
+ }
+
+ public bool ResetAvatar(UUID userID)
+ {
+ return m_AvatarService.ResetAvatar(userID);
+ }
+
+ public bool SetItems(UUID userID, string[] names, string[] values)
+ {
+ return m_AvatarService.SetItems(userID, names, values);
+ }
+
+ public bool RemoveItems(UUID userID, string[] names)
+ {
+ return m_AvatarService.RemoveItems(userID, names);
+ }
+
+ #endregion
+
+ }
+}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs
new file mode 100644
index 0000000000..48759b57a5
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Nini.Config;
+using log4net;
+using System.Reflection;
+using OpenSim.Region.Framework.Interfaces;
+using OpenSim.Region.Framework.Scenes;
+using OpenSim.Services.Interfaces;
+using OpenSim.Services.Connectors;
+
+namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
+{
+ public class RemoteAvatarServicesConnector : AvatarServicesConnector,
+ ISharedRegionModule, IAvatarService
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(
+ MethodBase.GetCurrentMethod().DeclaringType);
+
+ private bool m_Enabled = false;
+
+ public Type ReplaceableInterface
+ {
+ get { return null; }
+ }
+
+ public string Name
+ {
+ get { return "RemoteAvatarServicesConnector"; }
+ }
+
+ public override void Initialise(IConfigSource source)
+ {
+ IConfig moduleConfig = source.Configs["Modules"];
+ if (moduleConfig != null)
+ {
+ string name = moduleConfig.GetString("AvatarServices", "");
+ if (name == Name)
+ {
+ IConfig userConfig = source.Configs["AvatarService"];
+ if (userConfig == null)
+ {
+ m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpanSim.ini");
+ return;
+ }
+
+ m_Enabled = true;
+
+ base.Initialise(source);
+
+ m_log.Info("[AVATAR CONNECTOR]: Remote avatars enabled");
+ }
+ }
+ }
+
+ public void PostInitialise()
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void Close()
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void AddRegion(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+
+ scene.RegisterModuleInterface(this);
+ }
+
+ public void RemoveRegion(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+ }
+
+ public void RegionLoaded(Scene scene)
+ {
+ if (!m_Enabled)
+ return;
+ }
+ }
+}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
index d322abad69..7d61b20cea 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
@@ -60,13 +60,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
- string name = moduleConfig.GetString("UserServices", "");
+ string name = moduleConfig.GetString("UserAccountServices", "");
if (name == Name)
{
- IConfig userConfig = source.Configs["UserService"];
+ IConfig userConfig = source.Configs["UserAccountService"];
if (userConfig == null)
{
- m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini");
+ m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpanSim.ini");
return;
}
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
new file mode 100644
index 0000000000..9a57cd9ddc
--- /dev/null
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Nini.Config;
+using OpenSim.Server.Base;
+using OpenSim.Services.Interfaces;
+using OpenSim.Framework.Servers.HttpServer;
+using OpenSim.Server.Handlers.Base;
+
+namespace OpenSim.Server.Handlers.Avatar
+{
+ public class AvatarServiceConnector : ServiceConnector
+ {
+ private IAvatarService m_AvatarService;
+ private string m_ConfigName = "AvatarService";
+
+ public AvatarServiceConnector(IConfigSource config, IHttpServer server, string configName) :
+ base(config, server, configName)
+ {
+ IConfig serverConfig = config.Configs[m_ConfigName];
+ if (serverConfig == null)
+ throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
+
+ string avatarService = serverConfig.GetString("LocalServiceModule",
+ String.Empty);
+
+ if (avatarService == String.Empty)
+ throw new Exception("No LocalServiceModule in config file");
+
+ Object[] args = new Object[] { config };
+ m_AvatarService = ServerUtils.LoadPlugin(avatarService, args);
+
+ server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService));
+ }
+ }
+}
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
new file mode 100644
index 0000000000..c781cce513
--- /dev/null
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using Nini.Config;
+using log4net;
+using System;
+using System.Reflection;
+using System.IO;
+using System.Net;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Xml;
+using System.Xml.Serialization;
+using System.Collections.Generic;
+using OpenSim.Server.Base;
+using OpenSim.Services.Interfaces;
+using OpenSim.Framework;
+using OpenSim.Framework.Servers.HttpServer;
+using OpenMetaverse;
+
+namespace OpenSim.Server.Handlers.Avatar
+{
+ public class AvatarServerPostHandler : BaseStreamHandler
+ {
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ private IAvatarService m_AvatarService;
+
+ public AvatarServerPostHandler(IAvatarService service) :
+ base("POST", "/avatar")
+ {
+ m_AvatarService = service;
+ }
+
+ public override byte[] Handle(string path, Stream requestData,
+ OSHttpRequest httpRequest, OSHttpResponse httpResponse)
+ {
+ StreamReader sr = new StreamReader(requestData);
+ string body = sr.ReadToEnd();
+ sr.Close();
+ body = body.Trim();
+
+ //m_log.DebugFormat("[XXX]: query String: {0}", body);
+
+ try
+ {
+ Dictionary request =
+ ServerUtils.ParseQueryString(body);
+
+ if (!request.ContainsKey("METHOD"))
+ return FailureResult();
+
+ string method = request["METHOD"].ToString();
+
+ switch (method)
+ {
+ case "getavatar":
+ return GetAvatar(request);
+ case "setavatar":
+ return SetAvatar(request);
+ case "resetavatar":
+ return ResetAvatar(request);
+ case "setitems":
+ return SetItems(request);
+ case "removeitems":
+ return RemoveItems(request);
+ }
+ m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method);
+ }
+ catch (Exception e)
+ {
+ m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e);
+ }
+
+ return FailureResult();
+
+ }
+
+ byte[] GetAvatar(Dictionary request)
+ {
+ UUID user = UUID.Zero;
+
+ if (!request.ContainsKey("UserID"))
+ return FailureResult();
+
+ if (UUID.TryParse(request["UserID"].ToString(), out user))
+ {
+ AvatarData avatar = m_AvatarService.GetAvatar(user);
+ if (avatar == null)
+ return FailureResult();
+
+ Dictionary result = new Dictionary();
+ if (avatar == null)
+ result["result"] = "null";
+ else
+ result["result"] = avatar.ToKeyValuePairs();
+
+ string xmlString = ServerUtils.BuildXmlResponse(result);
+
+ UTF8Encoding encoding = new UTF8Encoding();
+ return encoding.GetBytes(xmlString);
+ }
+
+ return FailureResult();
+ }
+
+ byte[] SetAvatar(Dictionary request)
+ {
+ UUID user = UUID.Zero;
+
+ if (!request.ContainsKey("UserID"))
+ return FailureResult();
+
+ if (!UUID.TryParse(request["UserID"].ToString(), out user))
+ return FailureResult();
+
+ if (request.ContainsKey("Avatar") && request["Avatar"] is Dictionary)
+ {
+ AvatarData avatar = new AvatarData((Dictionary)request["Avatar"]);
+ if (m_AvatarService.SetAvatar(user, avatar))
+ return SuccessResult();
+ }
+
+ return FailureResult();
+ }
+
+ byte[] ResetAvatar(Dictionary request)
+ {
+ UUID user = UUID.Zero;
+ if (!request.ContainsKey("UserID"))
+ return FailureResult();
+
+ if (!UUID.TryParse(request["UserID"].ToString(), out user))
+ return FailureResult();
+
+ if (m_AvatarService.ResetAvatar(user))
+ return SuccessResult();
+
+ return FailureResult();
+ }
+
+ byte[] SetItems(Dictionary request)
+ {
+ UUID user = UUID.Zero;
+ string[] names, values;
+
+ if (!request.ContainsKey("UserID") || !request.ContainsKey("Names") || !request.ContainsKey("Values"))
+ return FailureResult();
+
+ if (!UUID.TryParse(request["UserID"].ToString(), out user))
+ return FailureResult();
+
+ if (!(request["Names"] is List || request["Values"] is List))
+ return FailureResult();
+
+ List _names = (List)request["Names"];
+ names = _names.ToArray();
+ List _values = (List)request["Values"];
+ values = _values.ToArray();
+
+ if (m_AvatarService.SetItems(user, names, values))
+ return SuccessResult();
+
+ return FailureResult();
+ }
+
+ byte[] RemoveItems(Dictionary request)
+ {
+ UUID user = UUID.Zero;
+ string[] names;
+
+ if (!request.ContainsKey("UserID") || !request.ContainsKey("Names"))
+ return FailureResult();
+
+ if (!UUID.TryParse(request["UserID"].ToString(), out user))
+ return FailureResult();
+
+ if (!(request["Names"] is List))
+ return FailureResult();
+
+ List _names = (List)request["Names"];
+ names = _names.ToArray();
+
+ if (m_AvatarService.RemoveItems(user, names))
+ return SuccessResult();
+
+ return FailureResult();
+ }
+
+
+
+ private byte[] SuccessResult()
+ {
+ XmlDocument doc = new XmlDocument();
+
+ XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
+ "", "");
+
+ doc.AppendChild(xmlnode);
+
+ XmlElement rootElement = doc.CreateElement("", "ServerResponse",
+ "");
+
+ doc.AppendChild(rootElement);
+
+ XmlElement result = doc.CreateElement("", "result", "");
+ result.AppendChild(doc.CreateTextNode("Success"));
+
+ rootElement.AppendChild(result);
+
+ return DocToBytes(doc);
+ }
+
+ private byte[] FailureResult()
+ {
+ XmlDocument doc = new XmlDocument();
+
+ XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
+ "", "");
+
+ doc.AppendChild(xmlnode);
+
+ XmlElement rootElement = doc.CreateElement("", "ServerResponse",
+ "");
+
+ doc.AppendChild(rootElement);
+
+ XmlElement result = doc.CreateElement("", "result", "");
+ result.AppendChild(doc.CreateTextNode("Failure"));
+
+ rootElement.AppendChild(result);
+
+ return DocToBytes(doc);
+ }
+
+ private byte[] DocToBytes(XmlDocument doc)
+ {
+ MemoryStream ms = new MemoryStream();
+ XmlTextWriter xw = new XmlTextWriter(ms, null);
+ xw.Formatting = Formatting.Indented;
+ doc.WriteTo(xw);
+ xw.Flush();
+
+ return ms.ToArray();
+ }
+
+ }
+}
diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs
new file mode 100644
index 0000000000..bd78c1a662
--- /dev/null
+++ b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs
@@ -0,0 +1,312 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using log4net;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using Nini.Config;
+using OpenSim.Framework;
+using OpenSim.Framework.Communications;
+using OpenSim.Framework.Servers.HttpServer;
+using OpenSim.Services.Interfaces;
+using GridRegion = OpenSim.Services.Interfaces.GridRegion;
+using IAvatarService = OpenSim.Services.Interfaces.IAvatarService;
+using OpenSim.Server.Base;
+using OpenMetaverse;
+
+namespace OpenSim.Services.Connectors
+{
+ public class AvatarServicesConnector : IAvatarService
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(
+ MethodBase.GetCurrentMethod().DeclaringType);
+
+ private string m_ServerURI = String.Empty;
+
+ public AvatarServicesConnector()
+ {
+ }
+
+ public AvatarServicesConnector(string serverURI)
+ {
+ m_ServerURI = serverURI.TrimEnd('/');
+ }
+
+ public AvatarServicesConnector(IConfigSource source)
+ {
+ Initialise(source);
+ }
+
+ public virtual void Initialise(IConfigSource source)
+ {
+ IConfig gridConfig = source.Configs["AvatarService"];
+ if (gridConfig == null)
+ {
+ m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini");
+ throw new Exception("Avatar connector init error");
+ }
+
+ string serviceURI = gridConfig.GetString("AvatarServerURI",
+ String.Empty);
+
+ if (serviceURI == String.Empty)
+ {
+ m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService");
+ throw new Exception("Avatar connector init error");
+ }
+ m_ServerURI = serviceURI;
+ }
+
+
+ #region IAvatarService
+
+ public AvatarData GetAvatar(UUID userID)
+ {
+ Dictionary sendData = new Dictionary();
+ //sendData["SCOPEID"] = scopeID.ToString();
+ sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
+ sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
+ sendData["METHOD"] = "getavatar";
+
+ sendData["UserID"] = userID;
+
+ string reply = string.Empty;
+ string reqString = ServerUtils.BuildQueryString(sendData);
+ // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
+ try
+ {
+ reply = SynchronousRestFormsRequester.MakeRequest("POST",
+ m_ServerURI + "/avatar",
+ reqString);
+ if (reply == null || (reply != null && reply == string.Empty))
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply");
+ return null;
+ }
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
+ }
+
+ Dictionary replyData = ServerUtils.ParseXmlResponse(reply);
+ AvatarData avatar = null;
+
+ if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
+ {
+ if (replyData["result"] is Dictionary)
+ {
+ avatar = new AvatarData((Dictionary)replyData["result"]);
+ }
+ }
+
+ return avatar;
+
+ }
+
+ public bool SetAvatar(UUID userID, AvatarData avatar)
+ {
+ Dictionary sendData = new Dictionary();
+ //sendData["SCOPEID"] = scopeID.ToString();
+ sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
+ sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
+ sendData["METHOD"] = "setavatar";
+
+ sendData["UserID"] = userID.ToString();
+ sendData["Avatar"] = avatar.ToKeyValuePairs();
+
+ string reqString = ServerUtils.BuildQueryString(sendData);
+ // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
+ try
+ {
+ string reply = SynchronousRestFormsRequester.MakeRequest("POST",
+ m_ServerURI + "/avatar",
+ reqString);
+ if (reply != string.Empty)
+ {
+ Dictionary replyData = ServerUtils.ParseXmlResponse(reply);
+
+ if (replyData.ContainsKey("result"))
+ {
+ if (replyData["result"].ToString().ToLower() == "success")
+ return true;
+ else
+ return false;
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field");
+
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply");
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
+ }
+
+ return false;
+ }
+
+ public bool ResetAvatar(UUID userID)
+ {
+ Dictionary sendData = new Dictionary();
+ //sendData["SCOPEID"] = scopeID.ToString();
+ sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
+ sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
+ sendData["METHOD"] = "resetavatar";
+
+ sendData["UserID"] = userID.ToString();
+
+ string reqString = ServerUtils.BuildQueryString(sendData);
+ // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
+ try
+ {
+ string reply = SynchronousRestFormsRequester.MakeRequest("POST",
+ m_ServerURI + "/avatar",
+ reqString);
+ if (reply != string.Empty)
+ {
+ Dictionary replyData = ServerUtils.ParseXmlResponse(reply);
+
+ if (replyData.ContainsKey("result"))
+ {
+ if (replyData["result"].ToString().ToLower() == "success")
+ return true;
+ else
+ return false;
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
+
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
+ }
+
+ return false;
+ }
+
+ public bool SetItems(UUID userID, string[] names, string[] values)
+ {
+ Dictionary sendData = new Dictionary();
+ sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
+ sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
+ sendData["METHOD"] = "setitems";
+
+ sendData["UserID"] = userID.ToString();
+ sendData["Names"] = new List(names);
+ sendData["Values"] = new List(values);
+
+ string reqString = ServerUtils.BuildQueryString(sendData);
+ // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
+ try
+ {
+ string reply = SynchronousRestFormsRequester.MakeRequest("POST",
+ m_ServerURI + "/avatar",
+ reqString);
+ if (reply != string.Empty)
+ {
+ Dictionary replyData = ServerUtils.ParseXmlResponse(reply);
+
+ if (replyData.ContainsKey("result"))
+ {
+ if (replyData["result"].ToString().ToLower() == "success")
+ return true;
+ else
+ return false;
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
+
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
+ }
+
+ return false;
+ }
+
+ public bool RemoveItems(UUID userID, string[] names)
+ {
+ Dictionary sendData = new Dictionary();
+ //sendData["SCOPEID"] = scopeID.ToString();
+ sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
+ sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
+ sendData["METHOD"] = "removeitems";
+
+ sendData["UserID"] = userID.ToString();
+ sendData["Names"] = new List(names);
+
+ string reqString = ServerUtils.BuildQueryString(sendData);
+ // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
+ try
+ {
+ string reply = SynchronousRestFormsRequester.MakeRequest("POST",
+ m_ServerURI + "/avatar",
+ reqString);
+ if (reply != string.Empty)
+ {
+ Dictionary replyData = ServerUtils.ParseXmlResponse(reply);
+
+ if (replyData.ContainsKey("result"))
+ {
+ if (replyData["result"].ToString().ToLower() == "success")
+ return true;
+ else
+ return false;
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field");
+
+ }
+ else
+ m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply");
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
+ }
+
+ return false;
+ }
+
+ #endregion
+
+ }
+}