Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,80 @@
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : support Raw message in ReadMessage() too.
Allow null content type.
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : support Raw message. Fixed bug #619542.
2010-06-22 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs : return MessageVersion in
GetProperty<T>(). Fixed WebHttpBinding working.
2009-10-23 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs, WebMessageEncoder.cs:
add experimental monotouch build.
2009-09-17 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : handle /js and /jsdebug specially, as raw
javascript stream.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs : implement GetProperty<T>().
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs : some TODO cleanup.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : use content-type correctly.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : attach WebBodyFormatMessageProperty in
ReadMessage() too.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : implement ReadMessage(Stream,...). Use
ContentTypeMapper here, not in WriteMessage().
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : consider WebBodyFormatMessageProperty.
2008-02-08 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs : removed some todos.
* WebMessageEncoder.cs : implement WriteMessage(). (Though I have no
idea how non-xml formats can be specified.)
2008-02-08 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs : implemented
BuildChannelFactory() and BuildChannelListener().
2008-02-06 Atsushi Enomoto <atsushi@ximian.com>
* WebBodyFormatMessageProperty.cs, WebContentTypeMapper.cs,
WebMessageEncodingBindingElement.cs, WebContentFormat.cs,
WebMessageEncoder.cs, WebMessageEncoderFactory.cs :
added missing file headers.
2008-02-05 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElement.cs :
implement CreateMessageEncoderFactory().
* WebMessageEncoderFactory.cs, WebMessageEncoder.cs : implementation.
* WebBodyFormatMessageProperty.cs : ToString() is more informative.
2008-02-05 Atsushi Enomoto <atsushi@ximian.com>
* WebBodyFormatMessageProperty.cs, WebContentTypeMapper.cs,
WebContentFormat.cs, WebMessageEncodingBindingElement.cs :
new files.

View File

@ -0,0 +1,57 @@
//
// WebBodyFormatMessageProperty.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.ServiceModel.Channels
{
public sealed class WebBodyFormatMessageProperty : IMessageProperty
{
WebContentFormat format;
public WebBodyFormatMessageProperty (WebContentFormat format)
{
this.format = format;
}
public const string Name = "WebBodyFormatMessageProperty";
public WebContentFormat Format {
get { return format; }
}
public IMessageProperty CreateCopy ()
{
return (IMessageProperty) MemberwiseClone ();
}
public override string ToString ()
{
return String.Concat (Name, ": WebContentFormat=", format.ToString ());
}
}
}

View File

@ -0,0 +1,37 @@
//
// WebContentFormat.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.ServiceModel.Channels
{
public enum WebContentFormat
{
Default,
Xml,
Json,
Raw,
}
}

View File

@ -0,0 +1,40 @@
//
// WebContentTypeMapper.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.ServiceModel.Channels
{
public abstract class WebContentTypeMapper
{
protected WebContentTypeMapper ()
{
}
public abstract WebContentFormat GetMessageFormatForContentType (string contentType);
}
}

View File

@ -0,0 +1,211 @@
//
// WebMessageEncoder.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Channels
{
internal class WebMessageEncoder : MessageEncoder
{
internal const string ScriptPropertyName = "618BC2B0-38AA-21A3-DB4A-404FC87B9B11"; // randomly generated
WebMessageEncodingBindingElement source;
public WebMessageEncoder (WebMessageEncodingBindingElement source)
{
this.source = source;
}
public override string ContentType {
#if NET_2_1
get { return MediaType; }
#else
get { return MediaType + "; charset=" + source.WriteEncoding.HeaderName; }
#endif
}
// FIXME: find out how it can be customized.
public override string MediaType {
get { return "application/xml"; }
}
public override MessageVersion MessageVersion {
get { return MessageVersion.None; }
}
public override bool IsContentTypeSupported (string contentType)
{
if (contentType == null)
throw new ArgumentNullException ("contentType");
return true; // anything is accepted.
}
public override Message ReadMessage (ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
throw new NotImplementedException ();
}
public override Message ReadMessage (Stream stream, int maxSizeOfHeaders, string contentType)
{
if (stream == null)
throw new ArgumentNullException ("stream");
contentType = contentType ?? "application/octet-stream";
Encoding enc = Encoding.UTF8;
var ct = new System.Net.Mime.ContentType (contentType);
if (ct.CharSet != null)
enc = Encoding.GetEncoding (ct.CharSet);
WebContentFormat fmt = WebContentFormat.Xml;
if (source.ContentTypeMapper != null)
fmt = source.ContentTypeMapper.GetMessageFormatForContentType (contentType);
else {
switch (ct.MediaType) {
case "application/json":
fmt = WebContentFormat.Json;
break;
case "application/xml":
fmt = WebContentFormat.Xml;
break;
default:
fmt = WebContentFormat.Raw;
break;
}
}
Message msg = null;
WebBodyFormatMessageProperty wp = null;
switch (fmt) {
case WebContentFormat.Xml:
// FIXME: is it safe/unsafe/required to keep XmlReader open?
msg = Message.CreateMessage (MessageVersion.None, null, XmlReader.Create (new StreamReader (stream, enc)));
wp = new WebBodyFormatMessageProperty (WebContentFormat.Xml);
break;
case WebContentFormat.Json:
// FIXME: is it safe/unsafe/required to keep XmlReader open?
#if NET_2_1
msg = Message.CreateMessage (MessageVersion.None, null, JsonReaderWriterFactory.CreateJsonReader (stream, source.ReaderQuotas));
#else
msg = Message.CreateMessage (MessageVersion.None, null, JsonReaderWriterFactory.CreateJsonReader (stream, enc, source.ReaderQuotas, null));
#endif
wp = new WebBodyFormatMessageProperty (WebContentFormat.Json);
break;
case WebContentFormat.Raw:
msg = new WebMessageFormatter.RawMessage (stream);
wp = new WebBodyFormatMessageProperty (WebContentFormat.Raw);
break;
default:
throw new SystemException ("INTERNAL ERROR: cannot determine content format");
}
if (wp != null)
msg.Properties.Add (WebBodyFormatMessageProperty.Name, wp);
msg.Properties.Encoder = this;
return msg;
}
WebContentFormat GetContentFormat (Message message)
{
string name = WebBodyFormatMessageProperty.Name;
if (message.Properties.ContainsKey (name))
return ((WebBodyFormatMessageProperty) message.Properties [name]).Format;
switch (MediaType) {
case "application/xml":
case "text/xml":
return WebContentFormat.Xml;
case "application/json":
case "text/json":
return WebContentFormat.Json;
case "application/octet-stream":
return WebContentFormat.Raw;
default:
return WebContentFormat.Default;
}
}
public override void WriteMessage (Message message, Stream stream)
{
if (message == null)
throw new ArgumentNullException ("message");
// Handle /js and /jsdebug as the special cases.
var script = message.Properties [ScriptPropertyName] as string;
if (script != null) {
var bytes = source.WriteEncoding.GetBytes (script);
stream.Write (bytes, 0, bytes.Length);
return;
}
if (!MessageVersion.Equals (message.Version))
throw new ProtocolException (String.Format ("MessageVersion {0} is not supported", message.Version));
if (stream == null)
throw new ArgumentNullException ("stream");
switch (GetContentFormat (message)) {
case WebContentFormat.Xml:
#if NET_2_1
using (XmlWriter w = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (new StreamWriter (stream, source.WriteEncoding))))
message.WriteMessage (w);
#else
using (XmlWriter w = XmlDictionaryWriter.CreateTextWriter (stream, source.WriteEncoding))
message.WriteMessage (w);
#endif
break;
case WebContentFormat.Json:
using (XmlWriter w = JsonReaderWriterFactory.CreateJsonWriter (stream, source.WriteEncoding))
message.WriteMessage (w);
break;
case WebContentFormat.Raw:
var rmsg = (WebMessageFormatter.RawMessage) message;
var src = rmsg.Stream;
if (src == null) // null output
break;
int len = 0;
byte [] buffer = new byte [4096];
while ((len = src.Read (buffer, 0, buffer.Length)) > 0)
stream.Write (buffer, 0, len);
break;
case WebContentFormat.Default:
throw new SystemException ("INTERNAL ERROR: cannot determine content format");
}
}
public override ArraySegment<byte> WriteMessage (Message message, int maxMessageSize, BufferManager bufferManager,
int messageOffset)
{
throw new NotImplementedException ();
}
}
}

View File

@ -0,0 +1,50 @@
//
// WebMessageEncoderFactory.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.ServiceModel;
namespace System.ServiceModel.Channels
{
internal class WebMessageEncoderFactory : MessageEncoderFactory
{
MessageEncoder encoder;
public WebMessageEncoderFactory (WebMessageEncodingBindingElement source)
{
encoder = new WebMessageEncoder (source);
}
public override MessageEncoder Encoder {
get { return encoder; }
}
public override MessageVersion MessageVersion {
get { return MessageVersion.None; }
}
}
}

View File

@ -0,0 +1,163 @@
//
// WebMessageEncodingBindingElement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Channels
{
public sealed class WebMessageEncodingBindingElement
#if NET_2_1
: MessageEncodingBindingElement
#else
: MessageEncodingBindingElement, IWsdlExportExtension
#endif
{
Encoding write_encoding;
WebContentTypeMapper content_type_mapper;
int max_read_pool_size = 0x10000, max_write_pool_size = 0x10000;
// Constructors
public WebMessageEncodingBindingElement ()
: this (Encoding.UTF8)
{
}
public WebMessageEncodingBindingElement (Encoding writeEncoding)
{
if (writeEncoding == null)
throw new ArgumentNullException ("writeEncoding");
WriteEncoding = writeEncoding;
ReaderQuotas = new XmlDictionaryReaderQuotas ();
}
// Properties
public WebContentTypeMapper ContentTypeMapper {
get { return content_type_mapper; }
set { content_type_mapper = value; }
}
[MonoTODO]
public int MaxReadPoolSize {
get { return max_read_pool_size; }
set { max_read_pool_size = value; }
}
[MonoTODO]
public int MaxWritePoolSize {
get { return max_write_pool_size; }
set { max_write_pool_size = value; }
}
public override MessageVersion MessageVersion {
get { return MessageVersion.None; }
set {
if (value == null)
throw new ArgumentNullException ("value");
if (!value.Equals (MessageVersion.None))
throw new ArgumentException ("Only MessageVersion.None is supported for WebMessageEncodingBindingElement");
}
}
public XmlDictionaryReaderQuotas ReaderQuotas { get; internal set; }
public Encoding WriteEncoding {
get { return write_encoding; }
set {
if (value == null)
throw new ArgumentNullException ("value");
write_encoding = value;
}
}
// Methods
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
context.RemainingBindingElements.Add (this);
return base.BuildChannelFactory<TChannel> (context);
}
#if !NET_2_1
[MonoTODO ("Why is it overriden?")]
public override bool CanBuildChannelListener<TChannel> (BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
return context.CanBuildInnerChannelListener<TChannel> ();
}
public override IChannelListener<TChannel> BuildChannelListener<TChannel> (BindingContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
context.RemainingBindingElements.Add (this);
return base.BuildChannelListener<TChannel> (context);
}
#endif
public override BindingElement Clone ()
{
return (WebMessageEncodingBindingElement) MemberwiseClone ();
}
public override MessageEncoderFactory CreateMessageEncoderFactory ()
{
return new WebMessageEncoderFactory (this);
}
public override T GetProperty<T> (BindingContext context)
{
if (typeof (T) == typeof (MessageVersion))
return (T) (object) MessageVersion;
if (typeof (T) == typeof (XmlDictionaryReaderQuotas))
return (T) (object) ReaderQuotas;
return context.GetInnerProperty<T> ();
}
#if !NET_2_1
[MonoTODO]
void IWsdlExportExtension.ExportContract (WsdlExporter exporter, WsdlContractConversionContext context)
{
throw new NotImplementedException ();
}
[MonoTODO]
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter, WsdlEndpointConversionContext context)
{
throw new NotImplementedException ();
}
#endif
}
}