aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDr Scofield2008-06-04 18:09:55 +0000
committerDr Scofield2008-06-04 18:09:55 +0000
commitcaee0288fbf5fdc2abfbaa0890d3de62110de324 (patch)
tree33fb76b77da568838eda6651f3a715ebfb0d1ab7 /OpenSim
parentchange clientCircuits_reverse to a synchronized hash table. This (diff)
downloadopensim-SC-caee0288fbf5fdc2abfbaa0890d3de62110de324.zip
opensim-SC-caee0288fbf5fdc2abfbaa0890d3de62110de324.tar.gz
opensim-SC-caee0288fbf5fdc2abfbaa0890d3de62110de324.tar.bz2
opensim-SC-caee0288fbf5fdc2abfbaa0890d3de62110de324.tar.xz
* adding XmppPresenceStanza and deserialization/reification support
having reached the intermediate level of .NET's XmlSudoku, i've now figured out how to do deserialization using different XmlSerializers (this stuff begins to grow on me, sigh). [still not used code, work-in-progress] * adding convenience property on OSHttpRequest.cs (from awebb)
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs5
-rw-r--r--OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs71
-rw-r--r--OpenSim/Framework/Communications/XMPP/XmppSerializer.cs30
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequest.cs5
4 files changed, 105 insertions, 6 deletions
diff --git a/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs
index e80c0aa..b221459 100644
--- a/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs
+++ b/OpenSim/Framework/Communications/XMPP/XmppMessageStanza.cs
@@ -59,6 +59,11 @@ namespace OpenSim.Framework.Communications.XMPP
59 { 59 {
60 Text = message; 60 Text = message;
61 } 61 }
62
63 public string ToString()
64 {
65 return Text;
66 }
62 } 67 }
63 68
64 [XmlRoot("message")] 69 [XmlRoot("message")]
diff --git a/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs b/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs
new file mode 100644
index 0000000..d63a0d1
--- /dev/null
+++ b/OpenSim/Framework/Communications/XMPP/XmppPresenceStanza.cs
@@ -0,0 +1,71 @@
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 OpenSim 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
28using System;
29using System.Xml;
30using System.Xml.Serialization;
31
32namespace OpenSim.Framework.Communications.XMPP
33{
34 /// <summary>
35 /// Message types.
36 /// </summary>
37 public enum XmppPresenceType
38 {
39 [XmlEnum("unavailable")] unavailable,
40 [XmlEnum("subscribe")] subscribe,
41 [XmlEnum("subscribed")] subscribed,
42 [XmlEnum("unsubscribe")] unsubscribe,
43 [XmlEnum("unsubscribed")] unsubscribed,
44 [XmlEnum("probe")] probe,
45 [XmlEnum("error")] error,
46 }
47
48
49 [XmlRoot("message")]
50 public class XmppPresenceStanza: XmppStanza
51 {
52 /// <summary>
53 /// IQ type: one of set, get, result, error
54 /// </summary>
55 [XmlAttribute("type")]
56 public XmppPresenceType PresenceType;
57
58 // [XmlAttribute("error")]
59 // public XmppError Error;
60
61 public XmppPresenceStanza() : base()
62 {
63 }
64
65 public XmppPresenceStanza(string fromJid, string toJid, XmppPresenceType pType) :
66 base(fromJid, toJid)
67 {
68 PresenceType = pType;
69 }
70 }
71}
diff --git a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs b/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
index f0d2cd5..30a9eac 100644
--- a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
+++ b/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
@@ -28,21 +28,27 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection;
31using System.Text; 32using System.Text;
32using System.Xml; 33using System.Xml;
33using System.Xml.Serialization; 34using System.Xml.Serialization;
35using log4net;
34 36
35namespace OpenSim.Framework.Communications.XMPP 37namespace OpenSim.Framework.Communications.XMPP
36{ 38{
37 public class XMPPSerializer 39 public class XmppSerializer
38 { 40 {
41 private static readonly ILog _log =
42 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
39 // need to do it this way, as XmlSerializer(type, extratypes) 44 // need to do it this way, as XmlSerializer(type, extratypes)
40 // does not work on mono (at least). 45 // does not work on mono (at least).
41 private Dictionary<Type, XmlSerializer> _serializers = new Dictionary<Type, XmlSerializer>(); 46 private Dictionary<Type, XmlSerializer> _serializerForType = new Dictionary<Type, XmlSerializer>();
47 private Dictionary<string, XmlSerializer> _serializerForName = new Dictionary<string, XmlSerializer>();
42 private XmlSerializerNamespaces _xmlNs; 48 private XmlSerializerNamespaces _xmlNs;
43 private string _defaultNS; 49 private string _defaultNS;
44 50
45 public XMPPSerializer(bool server) 51 public XmppSerializer(bool server)
46 { 52 {
47 _xmlNs = new XmlSerializerNamespaces(); 53 _xmlNs = new XmlSerializerNamespaces();
48 _xmlNs.Add(String.Empty, String.Empty); 54 _xmlNs.Add(String.Empty, String.Empty);
@@ -51,15 +57,27 @@ namespace OpenSim.Framework.Communications.XMPP
51 else 57 else
52 _defaultNS = "jabber:client"; 58 _defaultNS = "jabber:client";
53 59
54 _serializers[typeof(XmppMessageStanza)] = new XmlSerializer(typeof(XmppMessageStanza), _defaultNS); 60 // TODO: do this via reflection
61 _serializerForType[typeof(XmppMessageStanza)] = _serializerForName["message"] =
62 new XmlSerializer(typeof(XmppMessageStanza), _defaultNS);
55 } 63 }
56 64
57 public void Serialize(XmlWriter xw, object o) 65 public void Serialize(XmlWriter xw, object o)
58 { 66 {
59 if (!_serializers.ContainsKey(o.GetType())) 67 if (!_serializerForType.ContainsKey(o.GetType()))
60 throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType())); 68 throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType()));
61 69
62 _serializers[o.GetType()].Serialize(xw, o, _xmlNs); 70 _serializerForType[o.GetType()].Serialize(xw, o, _xmlNs);
71 }
72
73 public object Deserialize(XmlReader xr)
74 {
75 // position on next element
76 xr.Read();
77 if (!_serializerForName.ContainsKey(xr.LocalName))
78 throw new ArgumentException(String.Format("no serializer available for name {0}", xr.LocalName));
79
80 return _serializerForName[xr.LocalName].Deserialize(xr);
63 } 81 }
64 } 82 }
65} 83}
diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs
index dac2347..d733f3d 100644
--- a/OpenSim/Framework/Servers/OSHttpRequest.cs
+++ b/OpenSim/Framework/Servers/OSHttpRequest.cs
@@ -67,6 +67,11 @@ namespace OpenSim.Framework.Servers
67 get { return _contentLength64; } 67 get { return _contentLength64; }
68 } 68 }
69 69
70 public long ContentLength64
71 {
72 get { return _contentLength64; }
73 }
74
70 public string ContentType 75 public string ContentType
71 { 76 {
72 get { return _contentType; } 77 get { return _contentType; }