From 8df2119bc766132a36edb988d0963196694c4aa3 Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Thu, 5 Jul 2007 18:31:59 +0000
Subject: * Changed XmlRpc to specify utf-8
---
Common/XmlRpcCS/SimpleHttpRequest.cs | 7 +++++--
Common/XmlRpcCS/XmlRpcRequest.cs | 2 +-
Common/XmlRpcCS/XmlRpcResponder.cs | 4 +++-
Common/XmlRpcCS/XmlRpcSerializer.cs | 26 +++++++++++++++++---------
4 files changed, 26 insertions(+), 13 deletions(-)
(limited to 'Common')
diff --git a/Common/XmlRpcCS/SimpleHttpRequest.cs b/Common/XmlRpcCS/SimpleHttpRequest.cs
index 58a5ae4..aa260f4 100644
--- a/Common/XmlRpcCS/SimpleHttpRequest.cs
+++ b/Common/XmlRpcCS/SimpleHttpRequest.cs
@@ -31,6 +31,7 @@ namespace Nwc.XmlRpc
using System.IO;
using System.Net.Sockets;
using System.Collections;
+ using System.Text;
///Very basic HTTP request handler.
///This class is designed to accept a TcpClient and treat it as an HTTP request.
@@ -55,8 +56,10 @@ namespace Nwc.XmlRpc
public SimpleHttpRequest(TcpClient client)
{
_client = client;
- _output = new StreamWriter(client.GetStream());
- _input = new StreamReader(client.GetStream());
+
+ _output = new StreamWriter(client.GetStream(), Encoding.UTF8 );
+ _input = new StreamReader(client.GetStream(), Encoding.UTF8 );
+
GetRequestMethod();
GetRequestHeaders();
}
diff --git a/Common/XmlRpcCS/XmlRpcRequest.cs b/Common/XmlRpcCS/XmlRpcRequest.cs
index 2bac115..71a0dc9 100644
--- a/Common/XmlRpcCS/XmlRpcRequest.cs
+++ b/Common/XmlRpcCS/XmlRpcRequest.cs
@@ -56,7 +56,7 @@ namespace Nwc.XmlRpc
public class XmlRpcRequest
{
private String _methodName = null;
- private Encoding _encoding = new ASCIIEncoding();
+ private Encoding _encoding = new UTF8Encoding();
private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer();
private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer();
diff --git a/Common/XmlRpcCS/XmlRpcResponder.cs b/Common/XmlRpcCS/XmlRpcResponder.cs
index 41f855c..05377a2 100644
--- a/Common/XmlRpcCS/XmlRpcResponder.cs
+++ b/Common/XmlRpcCS/XmlRpcResponder.cs
@@ -30,6 +30,7 @@ namespace Nwc.XmlRpc
using System;
using System.Xml;
using System.Net.Sockets;
+ using System.Text;
/// The class is a container of the context of an XML-RPC dialog on the server side.
/// Instances of this class maintain the context for an individual XML-RPC server
@@ -98,8 +99,9 @@ namespace Nwc.XmlRpc
if (Logger.Delegate != null)
Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
- XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
+ XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
httpReq.Output.Flush();
+
XmlTextWriter xml = new XmlTextWriter(httpReq.Output);
_serializer.Serialize(xml, xmlRpcResp);
xml.Flush();
diff --git a/Common/XmlRpcCS/XmlRpcSerializer.cs b/Common/XmlRpcCS/XmlRpcSerializer.cs
index a75770e..b682f69 100644
--- a/Common/XmlRpcCS/XmlRpcSerializer.cs
+++ b/Common/XmlRpcCS/XmlRpcSerializer.cs
@@ -31,6 +31,7 @@ namespace Nwc.XmlRpc
using System.Collections;
using System.IO;
using System.Xml;
+ using System.Text;
/// Base class of classes serializing data to XML-RPC's XML format.
/// This class handles the basic type conversions like Integer to <i4>.
@@ -53,15 +54,22 @@ namespace Nwc.XmlRpc
///
public String Serialize(Object obj)
{
- StringWriter strBuf = new StringWriter();
- XmlTextWriter xml = new XmlTextWriter(strBuf);
- xml.Formatting = Formatting.Indented;
- xml.Indentation = 4;
- Serialize(xml, obj);
- xml.Flush();
- String returns = strBuf.ToString();
- xml.Close();
- return returns;
+ using (MemoryStream memStream = new MemoryStream(4096))
+ {
+ XmlTextWriter xml = new XmlTextWriter(memStream, Encoding.UTF8);
+ xml.Formatting = Formatting.Indented;
+ xml.Indentation = 4;
+ Serialize(xml, obj);
+ xml.Flush();
+
+ byte[] resultBytes = memStream.ToArray();
+
+ UTF8Encoding encoder = new UTF8Encoding();
+
+ String returns = encoder.GetString( resultBytes, 0, resultBytes.Length );
+ xml.Close();
+ return returns;
+ }
}
/// Serialize the object to the output stream.
--
cgit v1.1