diff options
author | Diva Canto | 2015-09-04 14:14:53 -0700 |
---|---|---|
committer | Diva Canto | 2015-09-04 14:14:53 -0700 |
commit | 9005365115a0c56c4d4827bff67bf8e5e317e5d6 (patch) | |
tree | f8f08dba663031a5c62c707fc02c7bda77a923fe | |
parent | Deleted unused interface (diff) | |
download | opensim-SC-9005365115a0c56c4d4827bff67bf8e5e317e5d6.zip opensim-SC-9005365115a0c56c4d4827bff67bf8e5e317e5d6.tar.gz opensim-SC-9005365115a0c56c4d4827bff67bf8e5e317e5d6.tar.bz2 opensim-SC-9005365115a0c56c4d4827bff67bf8e5e317e5d6.tar.xz |
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.
13 files changed, 154 insertions, 1007 deletions
diff --git a/OpenSim/Framework/Communications/GenericAsyncResult.cs b/OpenSim/Framework/Communications/GenericAsyncResult.cs deleted file mode 100644 index 8e3f62b..0000000 --- a/OpenSim/Framework/Communications/GenericAsyncResult.cs +++ /dev/null | |||
@@ -1,185 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Threading; | ||
30 | |||
31 | namespace OpenSim.Framework.Communications | ||
32 | { | ||
33 | internal class SimpleAsyncResult : IAsyncResult | ||
34 | { | ||
35 | private readonly AsyncCallback m_callback; | ||
36 | |||
37 | /// <summary> | ||
38 | /// Is process completed? | ||
39 | /// </summary> | ||
40 | /// <remarks>Should really be boolean, but VolatileRead has no boolean method</remarks> | ||
41 | private byte m_completed; | ||
42 | |||
43 | /// <summary> | ||
44 | /// Did process complete synchronously? | ||
45 | /// </summary> | ||
46 | /// <remarks>I have a hard time imagining a scenario where this is the case, again, same issue about | ||
47 | /// booleans and VolatileRead as m_completed | ||
48 | /// </remarks> | ||
49 | private byte m_completedSynchronously; | ||
50 | |||
51 | private readonly object m_asyncState; | ||
52 | private ManualResetEvent m_waitHandle; | ||
53 | private Exception m_exception; | ||
54 | |||
55 | internal SimpleAsyncResult(AsyncCallback cb, object state) | ||
56 | { | ||
57 | m_callback = cb; | ||
58 | m_asyncState = state; | ||
59 | m_completed = 0; | ||
60 | m_completedSynchronously = 1; | ||
61 | } | ||
62 | |||
63 | #region IAsyncResult Members | ||
64 | |||
65 | public object AsyncState | ||
66 | { | ||
67 | get { return m_asyncState; } | ||
68 | } | ||
69 | |||
70 | public WaitHandle AsyncWaitHandle | ||
71 | { | ||
72 | get | ||
73 | { | ||
74 | if (m_waitHandle == null) | ||
75 | { | ||
76 | bool done = IsCompleted; | ||
77 | ManualResetEvent mre = new ManualResetEvent(done); | ||
78 | if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null) | ||
79 | { | ||
80 | mre.Close(); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | if (!done && IsCompleted) | ||
85 | { | ||
86 | m_waitHandle.Set(); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | return m_waitHandle; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | |||
96 | public bool CompletedSynchronously | ||
97 | { | ||
98 | get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; } | ||
99 | } | ||
100 | |||
101 | |||
102 | public bool IsCompleted | ||
103 | { | ||
104 | get { return Thread.VolatileRead(ref m_completed) == 1; } | ||
105 | } | ||
106 | |||
107 | #endregion | ||
108 | |||
109 | #region class Methods | ||
110 | |||
111 | internal void SetAsCompleted(bool completedSynchronously) | ||
112 | { | ||
113 | m_completed = 1; | ||
114 | if (completedSynchronously) | ||
115 | m_completedSynchronously = 1; | ||
116 | else | ||
117 | m_completedSynchronously = 0; | ||
118 | |||
119 | SignalCompletion(); | ||
120 | } | ||
121 | |||
122 | internal void HandleException(Exception e, bool completedSynchronously) | ||
123 | { | ||
124 | m_completed = 1; | ||
125 | if (completedSynchronously) | ||
126 | m_completedSynchronously = 1; | ||
127 | else | ||
128 | m_completedSynchronously = 0; | ||
129 | m_exception = e; | ||
130 | |||
131 | SignalCompletion(); | ||
132 | } | ||
133 | |||
134 | private void SignalCompletion() | ||
135 | { | ||
136 | if (m_waitHandle != null) m_waitHandle.Set(); | ||
137 | |||
138 | if (m_callback != null) m_callback(this); | ||
139 | } | ||
140 | |||
141 | public void EndInvoke() | ||
142 | { | ||
143 | // This method assumes that only 1 thread calls EndInvoke | ||
144 | if (!IsCompleted) | ||
145 | { | ||
146 | // If the operation isn't done, wait for it | ||
147 | AsyncWaitHandle.WaitOne(); | ||
148 | AsyncWaitHandle.Close(); | ||
149 | m_waitHandle.Close(); | ||
150 | m_waitHandle = null; // Allow early GC | ||
151 | } | ||
152 | |||
153 | // Operation is done: if an exception occured, throw it | ||
154 | if (m_exception != null) throw m_exception; | ||
155 | } | ||
156 | |||
157 | #endregion | ||
158 | } | ||
159 | |||
160 | internal class AsyncResult<T> : SimpleAsyncResult | ||
161 | { | ||
162 | private T m_result = default(T); | ||
163 | |||
164 | public AsyncResult(AsyncCallback asyncCallback, Object state) : | ||
165 | base(asyncCallback, state) | ||
166 | { | ||
167 | } | ||
168 | |||
169 | public void SetAsCompleted(T result, bool completedSynchronously) | ||
170 | { | ||
171 | // Save the asynchronous operation's result | ||
172 | m_result = result; | ||
173 | |||
174 | // Tell the base class that the operation completed | ||
175 | // sucessfully (no exception) | ||
176 | base.SetAsCompleted(completedSynchronously); | ||
177 | } | ||
178 | |||
179 | public new T EndInvoke() | ||
180 | { | ||
181 | base.EndInvoke(); | ||
182 | return m_result; | ||
183 | } | ||
184 | } | ||
185 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Communications/Limit/IRequestLimitStrategy.cs b/OpenSim/Framework/Communications/Limit/IRequestLimitStrategy.cs deleted file mode 100644 index 070d106..0000000 --- a/OpenSim/Framework/Communications/Limit/IRequestLimitStrategy.cs +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Communications.Limit | ||
29 | { | ||
30 | /// <summary> | ||
31 | /// Interface for strategies that can limit requests from the client. Currently only used in the | ||
32 | /// texture modules to deal with repeated requests for certain textures. However, limiting strategies | ||
33 | /// could be used with other requests. | ||
34 | /// </summary> | ||
35 | public interface IRequestLimitStrategy<TId> | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Should the request be allowed? If the id is not monitored, then the request is always allowed. | ||
39 | /// Otherwise, the strategy criteria will be applied. | ||
40 | /// </summary> | ||
41 | /// <param name="id"></param> | ||
42 | /// <returns></returns> | ||
43 | bool AllowRequest(TId id); | ||
44 | |||
45 | /// <summary> | ||
46 | /// Has the request been refused just once? | ||
47 | /// </summary> | ||
48 | /// <returns>False if the request has not yet been refused, or if the request has been refused more | ||
49 | /// than once.</returns> | ||
50 | bool IsFirstRefusal(TId id); | ||
51 | |||
52 | /// <summary> | ||
53 | /// Start monitoring for future AllowRequest calls. If the id is already monitored, then monitoring | ||
54 | /// continues. | ||
55 | /// </summary> | ||
56 | /// <param name="id"></param> | ||
57 | void MonitorRequests(TId id); | ||
58 | |||
59 | /// <summary> | ||
60 | /// Is the id being monitored? | ||
61 | /// </summary> | ||
62 | /// <param name="uuid"> </param> | ||
63 | /// <returns></returns> | ||
64 | bool IsMonitoringRequests(TId id); | ||
65 | } | ||
66 | } | ||
diff --git a/OpenSim/Framework/Communications/Limit/NullLimitStrategy.cs b/OpenSim/Framework/Communications/Limit/NullLimitStrategy.cs deleted file mode 100644 index 7672653..0000000 --- a/OpenSim/Framework/Communications/Limit/NullLimitStrategy.cs +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Communications.Limit | ||
29 | { | ||
30 | /// <summary> | ||
31 | /// Strategy which polices no limits | ||
32 | /// </summary> | ||
33 | public class NullLimitStrategy<TId> : IRequestLimitStrategy<TId> | ||
34 | { | ||
35 | public bool AllowRequest(TId id) { return true; } | ||
36 | public bool IsFirstRefusal(TId id) { return false; } | ||
37 | public void MonitorRequests(TId id) { /* intentionally blank */ } | ||
38 | public bool IsMonitoringRequests(TId id) { return false; } | ||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/Framework/Communications/Limit/RepeatLimitStrategy.cs b/OpenSim/Framework/Communications/Limit/RepeatLimitStrategy.cs deleted file mode 100644 index 44dd592..0000000 --- a/OpenSim/Framework/Communications/Limit/RepeatLimitStrategy.cs +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | |||
30 | namespace OpenSim.Framework.Communications.Limit | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Limit requests by discarding them after they've been repeated a certain number of times. | ||
34 | /// </summary> | ||
35 | public class RepeatLimitStrategy<TId> : IRequestLimitStrategy<TId> | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Record each asset request that we're notified about. | ||
39 | /// </summary> | ||
40 | private readonly Dictionary<TId, int> requestCounts = new Dictionary<TId, int>(); | ||
41 | |||
42 | /// <summary> | ||
43 | /// The maximum number of requests that can be made before we drop subsequent requests. | ||
44 | /// </summary> | ||
45 | private readonly int m_maxRequests; | ||
46 | public int MaxRequests | ||
47 | { | ||
48 | get { return m_maxRequests; } | ||
49 | } | ||
50 | |||
51 | /// <summary></summary> | ||
52 | /// <param name="maxRequests">The maximum number of requests that may be served before all further | ||
53 | /// requests are dropped.</param> | ||
54 | public RepeatLimitStrategy(int maxRequests) | ||
55 | { | ||
56 | m_maxRequests = maxRequests; | ||
57 | } | ||
58 | |||
59 | /// <summary> | ||
60 | /// <see cref="IRequestLimitStrategy"/> | ||
61 | /// </summary> | ||
62 | public bool AllowRequest(TId id) | ||
63 | { | ||
64 | if (requestCounts.ContainsKey(id)) | ||
65 | { | ||
66 | requestCounts[id] += 1; | ||
67 | |||
68 | if (requestCounts[id] > m_maxRequests) | ||
69 | { | ||
70 | return false; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | return true; | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// <see cref="IRequestLimitStrategy"/> | ||
79 | /// </summary> | ||
80 | public bool IsFirstRefusal(TId id) | ||
81 | { | ||
82 | if (requestCounts.ContainsKey(id) && m_maxRequests + 1 == requestCounts[id]) | ||
83 | { | ||
84 | return true; | ||
85 | } | ||
86 | |||
87 | return false; | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// <see cref="IRequestLimitStrategy"/> | ||
92 | /// </summary> | ||
93 | public void MonitorRequests(TId id) | ||
94 | { | ||
95 | if (!IsMonitoringRequests(id)) | ||
96 | { | ||
97 | requestCounts.Add(id, 1); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// <see cref="IRequestLimitStrategy"/> | ||
103 | /// </summary> | ||
104 | public bool IsMonitoringRequests(TId id) | ||
105 | { | ||
106 | return requestCounts.ContainsKey(id); | ||
107 | } | ||
108 | } | ||
109 | } | ||
diff --git a/OpenSim/Framework/Communications/Limit/TimeLimitStrategy.cs b/OpenSim/Framework/Communications/Limit/TimeLimitStrategy.cs deleted file mode 100644 index 7ac8293..0000000 --- a/OpenSim/Framework/Communications/Limit/TimeLimitStrategy.cs +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | |||
31 | namespace OpenSim.Framework.Communications.Limit | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// Limit requests by discarding repeat attempts that occur within a given time period | ||
35 | /// | ||
36 | /// XXX Don't use this for limiting texture downloading, at least not until we better handle multiple requests | ||
37 | /// for the same texture at different resolutions. | ||
38 | /// </summary> | ||
39 | public class TimeLimitStrategy<TId> : IRequestLimitStrategy<TId> | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Record the time at which an asset request occurs. | ||
43 | /// </summary> | ||
44 | private readonly Dictionary<TId, Request> requests = new Dictionary<TId, Request>(); | ||
45 | |||
46 | /// <summary> | ||
47 | /// The minimum time period between which requests for the same data will be serviced. | ||
48 | /// </summary> | ||
49 | private readonly TimeSpan m_repeatPeriod; | ||
50 | public TimeSpan RepeatPeriod | ||
51 | { | ||
52 | get { return m_repeatPeriod; } | ||
53 | } | ||
54 | |||
55 | /// <summary></summary> | ||
56 | /// <param name="repeatPeriod"></param> | ||
57 | public TimeLimitStrategy(TimeSpan repeatPeriod) | ||
58 | { | ||
59 | m_repeatPeriod = repeatPeriod; | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// <see cref="IRequestLimitStrategy"/> | ||
64 | /// </summary> | ||
65 | public bool AllowRequest(TId id) | ||
66 | { | ||
67 | if (IsMonitoringRequests(id)) | ||
68 | { | ||
69 | DateTime now = DateTime.Now; | ||
70 | TimeSpan elapsed = now - requests[id].Time; | ||
71 | |||
72 | if (elapsed < RepeatPeriod) | ||
73 | { | ||
74 | requests[id].Refusals += 1; | ||
75 | return false; | ||
76 | } | ||
77 | |||
78 | requests[id].Time = now; | ||
79 | } | ||
80 | |||
81 | return true; | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// <see cref="IRequestLimitStrategy"/> | ||
86 | /// </summary> | ||
87 | public bool IsFirstRefusal(TId id) | ||
88 | { | ||
89 | if (IsMonitoringRequests(id)) | ||
90 | { | ||
91 | if (1 == requests[id].Refusals) | ||
92 | { | ||
93 | return true; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | return false; | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// <see cref="IRequestLimitStrategy"/> | ||
102 | /// </summary> | ||
103 | public void MonitorRequests(TId id) | ||
104 | { | ||
105 | if (!IsMonitoringRequests(id)) | ||
106 | { | ||
107 | requests.Add(id, new Request(DateTime.Now)); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | /// <summary> | ||
112 | /// <see cref="IRequestLimitStrategy"/> | ||
113 | /// </summary> | ||
114 | public bool IsMonitoringRequests(TId id) | ||
115 | { | ||
116 | return requests.ContainsKey(id); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Private request details. | ||
122 | /// </summary> | ||
123 | class Request | ||
124 | { | ||
125 | /// <summary> | ||
126 | /// Time of last request | ||
127 | /// </summary> | ||
128 | public DateTime Time; | ||
129 | |||
130 | /// <summary> | ||
131 | /// Number of refusals associated with this request | ||
132 | /// </summary> | ||
133 | public int Refusals; | ||
134 | |||
135 | public Request(DateTime time) | ||
136 | { | ||
137 | Time = time; | ||
138 | } | ||
139 | } | ||
140 | } | ||
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs index 6f517b6..ff7cb4d 100644 --- a/OpenSim/Framework/Communications/RestClient.cs +++ b/OpenSim/Framework/Communications/RestClient.cs | |||
@@ -519,4 +519,158 @@ namespace OpenSim.Framework.Communications | |||
519 | 519 | ||
520 | #endregion Async Invocation | 520 | #endregion Async Invocation |
521 | } | 521 | } |
522 | |||
523 | internal class SimpleAsyncResult : IAsyncResult | ||
524 | { | ||
525 | private readonly AsyncCallback m_callback; | ||
526 | |||
527 | /// <summary> | ||
528 | /// Is process completed? | ||
529 | /// </summary> | ||
530 | /// <remarks>Should really be boolean, but VolatileRead has no boolean method</remarks> | ||
531 | private byte m_completed; | ||
532 | |||
533 | /// <summary> | ||
534 | /// Did process complete synchronously? | ||
535 | /// </summary> | ||
536 | /// <remarks>I have a hard time imagining a scenario where this is the case, again, same issue about | ||
537 | /// booleans and VolatileRead as m_completed | ||
538 | /// </remarks> | ||
539 | private byte m_completedSynchronously; | ||
540 | |||
541 | private readonly object m_asyncState; | ||
542 | private ManualResetEvent m_waitHandle; | ||
543 | private Exception m_exception; | ||
544 | |||
545 | internal SimpleAsyncResult(AsyncCallback cb, object state) | ||
546 | { | ||
547 | m_callback = cb; | ||
548 | m_asyncState = state; | ||
549 | m_completed = 0; | ||
550 | m_completedSynchronously = 1; | ||
551 | } | ||
552 | |||
553 | #region IAsyncResult Members | ||
554 | |||
555 | public object AsyncState | ||
556 | { | ||
557 | get { return m_asyncState; } | ||
558 | } | ||
559 | |||
560 | public WaitHandle AsyncWaitHandle | ||
561 | { | ||
562 | get | ||
563 | { | ||
564 | if (m_waitHandle == null) | ||
565 | { | ||
566 | bool done = IsCompleted; | ||
567 | ManualResetEvent mre = new ManualResetEvent(done); | ||
568 | if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null) | ||
569 | { | ||
570 | mre.Close(); | ||
571 | } | ||
572 | else | ||
573 | { | ||
574 | if (!done && IsCompleted) | ||
575 | { | ||
576 | m_waitHandle.Set(); | ||
577 | } | ||
578 | } | ||
579 | } | ||
580 | |||
581 | return m_waitHandle; | ||
582 | } | ||
583 | } | ||
584 | |||
585 | |||
586 | public bool CompletedSynchronously | ||
587 | { | ||
588 | get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; } | ||
589 | } | ||
590 | |||
591 | |||
592 | public bool IsCompleted | ||
593 | { | ||
594 | get { return Thread.VolatileRead(ref m_completed) == 1; } | ||
595 | } | ||
596 | |||
597 | #endregion | ||
598 | |||
599 | #region class Methods | ||
600 | |||
601 | internal void SetAsCompleted(bool completedSynchronously) | ||
602 | { | ||
603 | m_completed = 1; | ||
604 | if (completedSynchronously) | ||
605 | m_completedSynchronously = 1; | ||
606 | else | ||
607 | m_completedSynchronously = 0; | ||
608 | |||
609 | SignalCompletion(); | ||
610 | } | ||
611 | |||
612 | internal void HandleException(Exception e, bool completedSynchronously) | ||
613 | { | ||
614 | m_completed = 1; | ||
615 | if (completedSynchronously) | ||
616 | m_completedSynchronously = 1; | ||
617 | else | ||
618 | m_completedSynchronously = 0; | ||
619 | m_exception = e; | ||
620 | |||
621 | SignalCompletion(); | ||
622 | } | ||
623 | |||
624 | private void SignalCompletion() | ||
625 | { | ||
626 | if (m_waitHandle != null) m_waitHandle.Set(); | ||
627 | |||
628 | if (m_callback != null) m_callback(this); | ||
629 | } | ||
630 | |||
631 | public void EndInvoke() | ||
632 | { | ||
633 | // This method assumes that only 1 thread calls EndInvoke | ||
634 | if (!IsCompleted) | ||
635 | { | ||
636 | // If the operation isn't done, wait for it | ||
637 | AsyncWaitHandle.WaitOne(); | ||
638 | AsyncWaitHandle.Close(); | ||
639 | m_waitHandle.Close(); | ||
640 | m_waitHandle = null; // Allow early GC | ||
641 | } | ||
642 | |||
643 | // Operation is done: if an exception occured, throw it | ||
644 | if (m_exception != null) throw m_exception; | ||
645 | } | ||
646 | |||
647 | #endregion | ||
648 | } | ||
649 | |||
650 | internal class AsyncResult<T> : SimpleAsyncResult | ||
651 | { | ||
652 | private T m_result = default(T); | ||
653 | |||
654 | public AsyncResult(AsyncCallback asyncCallback, Object state) : | ||
655 | base(asyncCallback, state) | ||
656 | { | ||
657 | } | ||
658 | |||
659 | public void SetAsCompleted(T result, bool completedSynchronously) | ||
660 | { | ||
661 | // Save the asynchronous operation's result | ||
662 | m_result = result; | ||
663 | |||
664 | // Tell the base class that the operation completed | ||
665 | // sucessfully (no exception) | ||
666 | base.SetAsCompleted(completedSynchronously); | ||
667 | } | ||
668 | |||
669 | public new T EndInvoke() | ||
670 | { | ||
671 | base.EndInvoke(); | ||
672 | return m_result; | ||
673 | } | ||
674 | } | ||
675 | |||
522 | } \ No newline at end of file | 676 | } \ No newline at end of file |
diff --git a/OpenSim/Framework/Communications/XMPP/XmppError.cs b/OpenSim/Framework/Communications/XMPP/XmppError.cs deleted file mode 100644 index 3d36e9c..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppError.cs +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Xml.Serialization; | ||
29 | |||
30 | namespace OpenSim.Framework.Communications.XMPP | ||
31 | { | ||
32 | [XmlRoot("error")] | ||
33 | public class XmppErrorStanza | ||
34 | { | ||
35 | public XmppErrorStanza() | ||
36 | { | ||
37 | } | ||
38 | } | ||
39 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppIqStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppIqStanza.cs deleted file mode 100644 index 12263f4..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppIqStanza.cs +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Xml.Serialization; | ||
29 | |||
30 | namespace OpenSim.Framework.Communications.XMPP | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// An IQ needs to have one of the follow types set. | ||
34 | /// </summary> | ||
35 | public enum XmppIqType | ||
36 | { | ||
37 | [XmlEnum("set")] set, | ||
38 | [XmlEnum("get")] get, | ||
39 | [XmlEnum("result")] result, | ||
40 | [XmlEnum("error")] error, | ||
41 | } | ||
42 | |||
43 | /// <summary> | ||
44 | /// XmppIqStanza needs to be subclassed as the query content is | ||
45 | /// specific to the query type. | ||
46 | /// </summary> | ||
47 | [XmlRoot("iq")] | ||
48 | public abstract class XmppIqStanza: XmppStanza | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// IQ type: one of set, get, result, error | ||
52 | /// </summary> | ||
53 | [XmlAttribute("type")] | ||
54 | public XmppIqType Type; | ||
55 | |||
56 | public XmppIqStanza(): base() | ||
57 | { | ||
58 | } | ||
59 | } | ||
60 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs deleted file mode 100644 index 1e8c33e..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Xml.Serialization; | ||
29 | |||
30 | namespace OpenSim.Framework.Communications.XMPP | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Message types. | ||
34 | /// </summary> | ||
35 | public enum XmppMessageType | ||
36 | { | ||
37 | [XmlEnum("chat")] chat, | ||
38 | [XmlEnum("error")] error, | ||
39 | [XmlEnum("groupchat")] groupchat, | ||
40 | [XmlEnum("headline")] headline, | ||
41 | [XmlEnum("normal")] normal, | ||
42 | } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Message body. | ||
46 | /// </summary> | ||
47 | public class XmppMessageBody | ||
48 | { | ||
49 | [XmlText] | ||
50 | public string Text; | ||
51 | |||
52 | public XmppMessageBody() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public XmppMessageBody(string message) | ||
57 | { | ||
58 | Text = message; | ||
59 | } | ||
60 | |||
61 | new public string ToString() | ||
62 | { | ||
63 | return Text; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | [XmlRoot("message")] | ||
68 | public class XmppMessageStanza: XmppStanza | ||
69 | { | ||
70 | /// <summary> | ||
71 | /// IQ type: one of set, get, result, error | ||
72 | /// </summary> | ||
73 | [XmlAttribute("type")] | ||
74 | public XmppMessageType MessageType; | ||
75 | |||
76 | // [XmlAttribute("error")] | ||
77 | // public XmppError Error; | ||
78 | |||
79 | [XmlElement("body")] | ||
80 | public XmppMessageBody Body; | ||
81 | |||
82 | public XmppMessageStanza() : base() | ||
83 | { | ||
84 | } | ||
85 | |||
86 | public XmppMessageStanza(string fromJid, string toJid, XmppMessageType mType, string message) : | ||
87 | base(fromJid, toJid) | ||
88 | { | ||
89 | MessageType = mType; | ||
90 | Body = new XmppMessageBody(message); | ||
91 | } | ||
92 | } | ||
93 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs deleted file mode 100644 index 4d45ac0..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Xml.Serialization; | ||
29 | |||
30 | namespace OpenSim.Framework.Communications.XMPP | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Message types. | ||
34 | /// </summary> | ||
35 | public enum XmppPresenceType | ||
36 | { | ||
37 | [XmlEnum("unavailable")] unavailable, | ||
38 | [XmlEnum("subscribe")] subscribe, | ||
39 | [XmlEnum("subscribed")] subscribed, | ||
40 | [XmlEnum("unsubscribe")] unsubscribe, | ||
41 | [XmlEnum("unsubscribed")] unsubscribed, | ||
42 | [XmlEnum("probe")] probe, | ||
43 | [XmlEnum("error")] error, | ||
44 | } | ||
45 | |||
46 | |||
47 | [XmlRoot("message")] | ||
48 | public class XmppPresenceStanza: XmppStanza | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// IQ type: one of set, get, result, error | ||
52 | /// </summary> | ||
53 | [XmlAttribute("type")] | ||
54 | public XmppPresenceType PresenceType; | ||
55 | |||
56 | // [XmlAttribute("error")] | ||
57 | // public XmppError Error; | ||
58 | |||
59 | public XmppPresenceStanza() : base() | ||
60 | { | ||
61 | } | ||
62 | |||
63 | public XmppPresenceStanza(string fromJid, string toJid, XmppPresenceType pType) : | ||
64 | base(fromJid, toJid) | ||
65 | { | ||
66 | PresenceType = pType; | ||
67 | } | ||
68 | } | ||
69 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs b/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs deleted file mode 100644 index e37ef28..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Xml; | ||
31 | using System.Xml.Serialization; | ||
32 | |||
33 | namespace OpenSim.Framework.Communications.XMPP | ||
34 | { | ||
35 | public class XmppSerializer | ||
36 | { | ||
37 | // private static readonly ILog _log = | ||
38 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
39 | |||
40 | // need to do it this way, as XmlSerializer(type, extratypes) | ||
41 | // does not work on mono (at least). | ||
42 | private Dictionary<Type, XmlSerializer> _serializerForType = new Dictionary<Type, XmlSerializer>(); | ||
43 | private Dictionary<string, XmlSerializer> _serializerForName = new Dictionary<string, XmlSerializer>(); | ||
44 | private XmlSerializerNamespaces _xmlNs; | ||
45 | private string _defaultNS; | ||
46 | |||
47 | public XmppSerializer(bool server) | ||
48 | { | ||
49 | _xmlNs = new XmlSerializerNamespaces(); | ||
50 | _xmlNs.Add(String.Empty, String.Empty); | ||
51 | if (server) | ||
52 | _defaultNS = "jabber:server"; | ||
53 | else | ||
54 | _defaultNS = "jabber:client"; | ||
55 | |||
56 | // TODO: do this via reflection | ||
57 | _serializerForType[typeof(XmppMessageStanza)] = _serializerForName["message"] = | ||
58 | new XmlSerializer(typeof(XmppMessageStanza), _defaultNS); | ||
59 | } | ||
60 | |||
61 | public void Serialize(XmlWriter xw, object o) | ||
62 | { | ||
63 | if (!_serializerForType.ContainsKey(o.GetType())) | ||
64 | throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType())); | ||
65 | |||
66 | _serializerForType[o.GetType()].Serialize(xw, o, _xmlNs); | ||
67 | } | ||
68 | |||
69 | public object Deserialize(XmlReader xr) | ||
70 | { | ||
71 | // position on next element | ||
72 | xr.Read(); | ||
73 | if (!_serializerForName.ContainsKey(xr.LocalName)) | ||
74 | throw new ArgumentException(String.Format("no serializer available for name {0}", xr.LocalName)); | ||
75 | |||
76 | return _serializerForName[xr.LocalName].Deserialize(xr); | ||
77 | } | ||
78 | } | ||
79 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppStanza.cs deleted file mode 100644 index 5312a31..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppStanza.cs +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Xml.Serialization; | ||
30 | |||
31 | namespace OpenSim.Framework.Communications.XMPP | ||
32 | { | ||
33 | public abstract class XmppStanza | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// counter used for generating ID | ||
37 | /// </summary> | ||
38 | [XmlIgnore] | ||
39 | private static ulong _ctr = 0; | ||
40 | |||
41 | /// <summary> | ||
42 | /// recipient JID | ||
43 | /// </summary> | ||
44 | [XmlAttribute("to")] | ||
45 | public string ToJid; | ||
46 | |||
47 | /// <summary> | ||
48 | /// sender JID | ||
49 | /// </summary> | ||
50 | [XmlAttribute("from")] | ||
51 | public string FromJid; | ||
52 | |||
53 | /// <summary> | ||
54 | /// unique ID. | ||
55 | /// </summary> | ||
56 | [XmlAttribute("id")] | ||
57 | public string MessageId; | ||
58 | |||
59 | public XmppStanza() | ||
60 | { | ||
61 | } | ||
62 | |||
63 | public XmppStanza(string fromJid, string toJid) | ||
64 | { | ||
65 | ToJid = toJid; | ||
66 | FromJid = fromJid; | ||
67 | MessageId = String.Format("OpenSim_{0}{1}", DateTime.UtcNow.Ticks, _ctr++); | ||
68 | } | ||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/Framework/Communications/XMPP/XmppWriter.cs b/OpenSim/Framework/Communications/XMPP/XmppWriter.cs deleted file mode 100644 index 415d808..0000000 --- a/OpenSim/Framework/Communications/XMPP/XmppWriter.cs +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using System.Text; | ||
30 | using System.Xml; | ||
31 | using IOStream = System.IO.Stream; | ||
32 | |||
33 | namespace OpenSim.Framework.Communications.XMPP | ||
34 | { | ||
35 | public class XMPPWriter: XmlTextWriter | ||
36 | { | ||
37 | public XMPPWriter(TextWriter textWriter) : base(textWriter) | ||
38 | { | ||
39 | } | ||
40 | |||
41 | public XMPPWriter(IOStream stream) : this(stream, Util.UTF8) | ||
42 | { | ||
43 | } | ||
44 | |||
45 | public XMPPWriter(IOStream stream, Encoding enc) : base(stream, enc) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | public override void WriteStartDocument() | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public override void WriteStartDocument(bool standalone) | ||
54 | { | ||
55 | } | ||
56 | } | ||
57 | } | ||