Deleted old unfinished code under Framework.Communications that wasn't being used anywhere.

Also folded GenericAsyncResult into RestClient, since it is used only there. This is preparation to remove Framework.Communications entirely.
0.8.2-post-fixes
Diva Canto 2015-09-04 14:14:53 -07:00
parent 1559fc42b6
commit 9005365115
13 changed files with 154 additions and 1007 deletions

View File

@ -1,185 +0,0 @@
/*
* 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.Threading;
namespace OpenSim.Framework.Communications
{
internal class SimpleAsyncResult : IAsyncResult
{
private readonly AsyncCallback m_callback;
/// <summary>
/// Is process completed?
/// </summary>
/// <remarks>Should really be boolean, but VolatileRead has no boolean method</remarks>
private byte m_completed;
/// <summary>
/// Did process complete synchronously?
/// </summary>
/// <remarks>I have a hard time imagining a scenario where this is the case, again, same issue about
/// booleans and VolatileRead as m_completed
/// </remarks>
private byte m_completedSynchronously;
private readonly object m_asyncState;
private ManualResetEvent m_waitHandle;
private Exception m_exception;
internal SimpleAsyncResult(AsyncCallback cb, object state)
{
m_callback = cb;
m_asyncState = state;
m_completed = 0;
m_completedSynchronously = 1;
}
#region IAsyncResult Members
public object AsyncState
{
get { return m_asyncState; }
}
public WaitHandle AsyncWaitHandle
{
get
{
if (m_waitHandle == null)
{
bool done = IsCompleted;
ManualResetEvent mre = new ManualResetEvent(done);
if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null)
{
mre.Close();
}
else
{
if (!done && IsCompleted)
{
m_waitHandle.Set();
}
}
}
return m_waitHandle;
}
}
public bool CompletedSynchronously
{
get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; }
}
public bool IsCompleted
{
get { return Thread.VolatileRead(ref m_completed) == 1; }
}
#endregion
#region class Methods
internal void SetAsCompleted(bool completedSynchronously)
{
m_completed = 1;
if (completedSynchronously)
m_completedSynchronously = 1;
else
m_completedSynchronously = 0;
SignalCompletion();
}
internal void HandleException(Exception e, bool completedSynchronously)
{
m_completed = 1;
if (completedSynchronously)
m_completedSynchronously = 1;
else
m_completedSynchronously = 0;
m_exception = e;
SignalCompletion();
}
private void SignalCompletion()
{
if (m_waitHandle != null) m_waitHandle.Set();
if (m_callback != null) m_callback(this);
}
public void EndInvoke()
{
// This method assumes that only 1 thread calls EndInvoke
if (!IsCompleted)
{
// If the operation isn't done, wait for it
AsyncWaitHandle.WaitOne();
AsyncWaitHandle.Close();
m_waitHandle.Close();
m_waitHandle = null; // Allow early GC
}
// Operation is done: if an exception occured, throw it
if (m_exception != null) throw m_exception;
}
#endregion
}
internal class AsyncResult<T> : SimpleAsyncResult
{
private T m_result = default(T);
public AsyncResult(AsyncCallback asyncCallback, Object state) :
base(asyncCallback, state)
{
}
public void SetAsCompleted(T result, bool completedSynchronously)
{
// Save the asynchronous operation's result
m_result = result;
// Tell the base class that the operation completed
// sucessfully (no exception)
base.SetAsCompleted(completedSynchronously);
}
public new T EndInvoke()
{
base.EndInvoke();
return m_result;
}
}
}

View File

@ -1,66 +0,0 @@
/*
* 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.
*/
namespace OpenSim.Framework.Communications.Limit
{
/// <summary>
/// Interface for strategies that can limit requests from the client. Currently only used in the
/// texture modules to deal with repeated requests for certain textures. However, limiting strategies
/// could be used with other requests.
/// </summary>
public interface IRequestLimitStrategy<TId>
{
/// <summary>
/// Should the request be allowed? If the id is not monitored, then the request is always allowed.
/// Otherwise, the strategy criteria will be applied.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
bool AllowRequest(TId id);
/// <summary>
/// Has the request been refused just once?
/// </summary>
/// <returns>False if the request has not yet been refused, or if the request has been refused more
/// than once.</returns>
bool IsFirstRefusal(TId id);
/// <summary>
/// Start monitoring for future AllowRequest calls. If the id is already monitored, then monitoring
/// continues.
/// </summary>
/// <param name="id"></param>
void MonitorRequests(TId id);
/// <summary>
/// Is the id being monitored?
/// </summary>
/// <param name="uuid"> </param>
/// <returns></returns>
bool IsMonitoringRequests(TId id);
}
}

View File

@ -1,40 +0,0 @@
/*
* 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.
*/
namespace OpenSim.Framework.Communications.Limit
{
/// <summary>
/// Strategy which polices no limits
/// </summary>
public class NullLimitStrategy<TId> : IRequestLimitStrategy<TId>
{
public bool AllowRequest(TId id) { return true; }
public bool IsFirstRefusal(TId id) { return false; }
public void MonitorRequests(TId id) { /* intentionally blank */ }
public bool IsMonitoringRequests(TId id) { return false; }
}
}

View File

@ -1,109 +0,0 @@
/*
* 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.Collections.Generic;
namespace OpenSim.Framework.Communications.Limit
{
/// <summary>
/// Limit requests by discarding them after they've been repeated a certain number of times.
/// </summary>
public class RepeatLimitStrategy<TId> : IRequestLimitStrategy<TId>
{
/// <summary>
/// Record each asset request that we're notified about.
/// </summary>
private readonly Dictionary<TId, int> requestCounts = new Dictionary<TId, int>();
/// <summary>
/// The maximum number of requests that can be made before we drop subsequent requests.
/// </summary>
private readonly int m_maxRequests;
public int MaxRequests
{
get { return m_maxRequests; }
}
/// <summary></summary>
/// <param name="maxRequests">The maximum number of requests that may be served before all further
/// requests are dropped.</param>
public RepeatLimitStrategy(int maxRequests)
{
m_maxRequests = maxRequests;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool AllowRequest(TId id)
{
if (requestCounts.ContainsKey(id))
{
requestCounts[id] += 1;
if (requestCounts[id] > m_maxRequests)
{
return false;
}
}
return true;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool IsFirstRefusal(TId id)
{
if (requestCounts.ContainsKey(id) && m_maxRequests + 1 == requestCounts[id])
{
return true;
}
return false;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public void MonitorRequests(TId id)
{
if (!IsMonitoringRequests(id))
{
requestCounts.Add(id, 1);
}
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool IsMonitoringRequests(TId id)
{
return requestCounts.ContainsKey(id);
}
}
}

View File

@ -1,140 +0,0 @@
/*
* 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;
namespace OpenSim.Framework.Communications.Limit
{
/// <summary>
/// Limit requests by discarding repeat attempts that occur within a given time period
///
/// XXX Don't use this for limiting texture downloading, at least not until we better handle multiple requests
/// for the same texture at different resolutions.
/// </summary>
public class TimeLimitStrategy<TId> : IRequestLimitStrategy<TId>
{
/// <summary>
/// Record the time at which an asset request occurs.
/// </summary>
private readonly Dictionary<TId, Request> requests = new Dictionary<TId, Request>();
/// <summary>
/// The minimum time period between which requests for the same data will be serviced.
/// </summary>
private readonly TimeSpan m_repeatPeriod;
public TimeSpan RepeatPeriod
{
get { return m_repeatPeriod; }
}
/// <summary></summary>
/// <param name="repeatPeriod"></param>
public TimeLimitStrategy(TimeSpan repeatPeriod)
{
m_repeatPeriod = repeatPeriod;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool AllowRequest(TId id)
{
if (IsMonitoringRequests(id))
{
DateTime now = DateTime.Now;
TimeSpan elapsed = now - requests[id].Time;
if (elapsed < RepeatPeriod)
{
requests[id].Refusals += 1;
return false;
}
requests[id].Time = now;
}
return true;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool IsFirstRefusal(TId id)
{
if (IsMonitoringRequests(id))
{
if (1 == requests[id].Refusals)
{
return true;
}
}
return false;
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public void MonitorRequests(TId id)
{
if (!IsMonitoringRequests(id))
{
requests.Add(id, new Request(DateTime.Now));
}
}
/// <summary>
/// <see cref="IRequestLimitStrategy"/>
/// </summary>
public bool IsMonitoringRequests(TId id)
{
return requests.ContainsKey(id);
}
}
/// <summary>
/// Private request details.
/// </summary>
class Request
{
/// <summary>
/// Time of last request
/// </summary>
public DateTime Time;
/// <summary>
/// Number of refusals associated with this request
/// </summary>
public int Refusals;
public Request(DateTime time)
{
Time = time;
}
}
}

View File

@ -519,4 +519,158 @@ namespace OpenSim.Framework.Communications
#endregion Async Invocation
}
internal class SimpleAsyncResult : IAsyncResult
{
private readonly AsyncCallback m_callback;
/// <summary>
/// Is process completed?
/// </summary>
/// <remarks>Should really be boolean, but VolatileRead has no boolean method</remarks>
private byte m_completed;
/// <summary>
/// Did process complete synchronously?
/// </summary>
/// <remarks>I have a hard time imagining a scenario where this is the case, again, same issue about
/// booleans and VolatileRead as m_completed
/// </remarks>
private byte m_completedSynchronously;
private readonly object m_asyncState;
private ManualResetEvent m_waitHandle;
private Exception m_exception;
internal SimpleAsyncResult(AsyncCallback cb, object state)
{
m_callback = cb;
m_asyncState = state;
m_completed = 0;
m_completedSynchronously = 1;
}
#region IAsyncResult Members
public object AsyncState
{
get { return m_asyncState; }
}
public WaitHandle AsyncWaitHandle
{
get
{
if (m_waitHandle == null)
{
bool done = IsCompleted;
ManualResetEvent mre = new ManualResetEvent(done);
if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null)
{
mre.Close();
}
else
{
if (!done && IsCompleted)
{
m_waitHandle.Set();
}
}
}
return m_waitHandle;
}
}
public bool CompletedSynchronously
{
get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; }
}
public bool IsCompleted
{
get { return Thread.VolatileRead(ref m_completed) == 1; }
}
#endregion
#region class Methods
internal void SetAsCompleted(bool completedSynchronously)
{
m_completed = 1;
if (completedSynchronously)
m_completedSynchronously = 1;
else
m_completedSynchronously = 0;
SignalCompletion();
}
internal void HandleException(Exception e, bool completedSynchronously)
{
m_completed = 1;
if (completedSynchronously)
m_completedSynchronously = 1;
else
m_completedSynchronously = 0;
m_exception = e;
SignalCompletion();
}
private void SignalCompletion()
{
if (m_waitHandle != null) m_waitHandle.Set();
if (m_callback != null) m_callback(this);
}
public void EndInvoke()
{
// This method assumes that only 1 thread calls EndInvoke
if (!IsCompleted)
{
// If the operation isn't done, wait for it
AsyncWaitHandle.WaitOne();
AsyncWaitHandle.Close();
m_waitHandle.Close();
m_waitHandle = null; // Allow early GC
}
// Operation is done: if an exception occured, throw it
if (m_exception != null) throw m_exception;
}
#endregion
}
internal class AsyncResult<T> : SimpleAsyncResult
{
private T m_result = default(T);
public AsyncResult(AsyncCallback asyncCallback, Object state) :
base(asyncCallback, state)
{
}
public void SetAsCompleted(T result, bool completedSynchronously)
{
// Save the asynchronous operation's result
m_result = result;
// Tell the base class that the operation completed
// sucessfully (no exception)
base.SetAsCompleted(completedSynchronously);
}
public new T EndInvoke()
{
base.EndInvoke();
return m_result;
}
}
}

View File

@ -1,39 +0,0 @@
/*
* 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.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
[XmlRoot("error")]
public class XmppErrorStanza
{
public XmppErrorStanza()
{
}
}
}

View File

@ -1,60 +0,0 @@
/*
* 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.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
/// <summary>
/// An IQ needs to have one of the follow types set.
/// </summary>
public enum XmppIqType
{
[XmlEnum("set")] set,
[XmlEnum("get")] get,
[XmlEnum("result")] result,
[XmlEnum("error")] error,
}
/// <summary>
/// XmppIqStanza needs to be subclassed as the query content is
/// specific to the query type.
/// </summary>
[XmlRoot("iq")]
public abstract class XmppIqStanza: XmppStanza
{
/// <summary>
/// IQ type: one of set, get, result, error
/// </summary>
[XmlAttribute("type")]
public XmppIqType Type;
public XmppIqStanza(): base()
{
}
}
}

View File

@ -1,93 +0,0 @@
/*
* 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.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
/// <summary>
/// Message types.
/// </summary>
public enum XmppMessageType
{
[XmlEnum("chat")] chat,
[XmlEnum("error")] error,
[XmlEnum("groupchat")] groupchat,
[XmlEnum("headline")] headline,
[XmlEnum("normal")] normal,
}
/// <summary>
/// Message body.
/// </summary>
public class XmppMessageBody
{
[XmlText]
public string Text;
public XmppMessageBody()
{
}
public XmppMessageBody(string message)
{
Text = message;
}
new public string ToString()
{
return Text;
}
}
[XmlRoot("message")]
public class XmppMessageStanza: XmppStanza
{
/// <summary>
/// IQ type: one of set, get, result, error
/// </summary>
[XmlAttribute("type")]
public XmppMessageType MessageType;
// [XmlAttribute("error")]
// public XmppError Error;
[XmlElement("body")]
public XmppMessageBody Body;
public XmppMessageStanza() : base()
{
}
public XmppMessageStanza(string fromJid, string toJid, XmppMessageType mType, string message) :
base(fromJid, toJid)
{
MessageType = mType;
Body = new XmppMessageBody(message);
}
}
}

View File

@ -1,69 +0,0 @@
/*
* 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.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
/// <summary>
/// Message types.
/// </summary>
public enum XmppPresenceType
{
[XmlEnum("unavailable")] unavailable,
[XmlEnum("subscribe")] subscribe,
[XmlEnum("subscribed")] subscribed,
[XmlEnum("unsubscribe")] unsubscribe,
[XmlEnum("unsubscribed")] unsubscribed,
[XmlEnum("probe")] probe,
[XmlEnum("error")] error,
}
[XmlRoot("message")]
public class XmppPresenceStanza: XmppStanza
{
/// <summary>
/// IQ type: one of set, get, result, error
/// </summary>
[XmlAttribute("type")]
public XmppPresenceType PresenceType;
// [XmlAttribute("error")]
// public XmppError Error;
public XmppPresenceStanza() : base()
{
}
public XmppPresenceStanza(string fromJid, string toJid, XmppPresenceType pType) :
base(fromJid, toJid)
{
PresenceType = pType;
}
}
}

View File

@ -1,79 +0,0 @@
/*
* 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.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
public class XmppSerializer
{
// private static readonly ILog _log =
// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// need to do it this way, as XmlSerializer(type, extratypes)
// does not work on mono (at least).
private Dictionary<Type, XmlSerializer> _serializerForType = new Dictionary<Type, XmlSerializer>();
private Dictionary<string, XmlSerializer> _serializerForName = new Dictionary<string, XmlSerializer>();
private XmlSerializerNamespaces _xmlNs;
private string _defaultNS;
public XmppSerializer(bool server)
{
_xmlNs = new XmlSerializerNamespaces();
_xmlNs.Add(String.Empty, String.Empty);
if (server)
_defaultNS = "jabber:server";
else
_defaultNS = "jabber:client";
// TODO: do this via reflection
_serializerForType[typeof(XmppMessageStanza)] = _serializerForName["message"] =
new XmlSerializer(typeof(XmppMessageStanza), _defaultNS);
}
public void Serialize(XmlWriter xw, object o)
{
if (!_serializerForType.ContainsKey(o.GetType()))
throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType()));
_serializerForType[o.GetType()].Serialize(xw, o, _xmlNs);
}
public object Deserialize(XmlReader xr)
{
// position on next element
xr.Read();
if (!_serializerForName.ContainsKey(xr.LocalName))
throw new ArgumentException(String.Format("no serializer available for name {0}", xr.LocalName));
return _serializerForName[xr.LocalName].Deserialize(xr);
}
}
}

View File

@ -1,70 +0,0 @@
/*
* 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.Xml.Serialization;
namespace OpenSim.Framework.Communications.XMPP
{
public abstract class XmppStanza
{
/// <summary>
/// counter used for generating ID
/// </summary>
[XmlIgnore]
private static ulong _ctr = 0;
/// <summary>
/// recipient JID
/// </summary>
[XmlAttribute("to")]
public string ToJid;
/// <summary>
/// sender JID
/// </summary>
[XmlAttribute("from")]
public string FromJid;
/// <summary>
/// unique ID.
/// </summary>
[XmlAttribute("id")]
public string MessageId;
public XmppStanza()
{
}
public XmppStanza(string fromJid, string toJid)
{
ToJid = toJid;
FromJid = fromJid;
MessageId = String.Format("OpenSim_{0}{1}", DateTime.UtcNow.Ticks, _ctr++);
}
}
}

View File

@ -1,57 +0,0 @@
/*
* 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.IO;
using System.Text;
using System.Xml;
using IOStream = System.IO.Stream;
namespace OpenSim.Framework.Communications.XMPP
{
public class XMPPWriter: XmlTextWriter
{
public XMPPWriter(TextWriter textWriter) : base(textWriter)
{
}
public XMPPWriter(IOStream stream) : this(stream, Util.UTF8)
{
}
public XMPPWriter(IOStream stream, Encoding enc) : base(stream, enc)
{
}
public override void WriteStartDocument()
{
}
public override void WriteStartDocument(bool standalone)
{
}
}
}