/// Helper methods for deconstructing and reconstructing
/// URI path data.
///
private void initUrl()
{
uri = request.Url;
if (query == null)
{
query = uri.Query;
}
// If the path has not been previously initialized,
// do so now.
if (path == null)
{
path = uri.AbsolutePath;
if (path.EndsWith(Rest.UrlPathSeparator))
path = path.Substring(0, path.Length-1);
}
// If we succeeded in getting a path, perform any
// additional pre-processing required.
if (path != null)
{
if (Rest.ExtendedEscape)
{
// Handle "+". Not a standard substitution, but
// common enough...
path = path.Replace(Rest.C_PLUS, Rest.C_SPACE);
}
pathNodes = path.Split(Rest.CA_PATHSEP);
}
else
{
pathNodes = EmptyPath;
}
// Elimiate any %-escaped values. This is left until here
// so that escaped "+' are not mistakenly replaced.
path = Uri.UnescapeDataString(path);
// Request server context info
hostname = uri.Host;
port = uri.Port;
}
internal int initParameters(int prfxlen)
{
if (prfxlen < path.Length-1)
{
parameters = path.Substring(prfxlen+1).Split(Rest.CA_PATHSEP);
}
else
{
parameters = new string[0];
}
// Generate a debug list of the decoded parameters
if (Rest.DEBUG && prfxlen < path.Length-1)
{
Rest.Log.DebugFormat("{0} URI: Parameters: {1}", MsgId, path.Substring(prfxlen));
for (int i = 0; i < parameters.Length; i++)
{
Rest.Log.DebugFormat("{0} Parameter[{1}]: {2}", MsgId, i, parameters[i]);
}
}
return parameters.Length;
}
internal string[] PathNodes
{
get
{
if (pathNodes == null)
{
initUrl();
}
return pathNodes;
}
}
internal string BuildUrl(int first, int last)
{
if (pathNodes == null)
{
initUrl();
}
if (first < 0)
{
first = first + pathNodes.Length;
}
if (last < 0)
{
last = last + pathNodes.Length;
if (last < 0)
{
return Rest.UrlPathSeparator;
}
}
sbuilder.Length = 0;
sbuilder.Append(Rest.UrlPathSeparator);
if (first <= last)
{
for (int i = first; i <= last; i++)
{
sbuilder.Append(pathNodes[i]);
sbuilder.Append(Rest.UrlPathSeparator);
}
}
else
{
for (int i = last; i >= first; i--)
{
sbuilder.Append(pathNodes[i]);
sbuilder.Append(Rest.UrlPathSeparator);
}
}
return sbuilder.ToString();
}
// Setup the XML writer for output
internal void initXmlWriter()
{
XmlWriterSettings settings = new XmlWriterSettings();
xmldata = new MemoryStream();
settings.Indent = true;
settings.IndentChars = " ";
settings.Encoding = encoding;
settings.CloseOutput = false;
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
writer = XmlWriter.Create(xmldata, settings);
}
internal void initXmlReader()
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;
settings.IgnoreProcessingInstructions = true;
settings.ValidationType = ValidationType.None;
reader = XmlReader.Create(request.InputStream,settings);
}
private void Flush()
{
byte[] dbuffer = new byte[8192];
while (request.InputStream.Read(dbuffer,0,dbuffer.Length) != 0);
}
// This allows us to make errors a bit more apparent in REST
internal void SendHtml(string text)
{
SendHtml("OpenSim REST Interface 1.0", text);
}
internal void SendHtml(string title, string text)
{
AddHeader(Rest.HttpHeaderContentType, "text/html");
sbuilder.Length = 0;
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append(title);
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("
");
sbuilder.Append("");
sbuilder.Append(text);
sbuilder.Append("
");
sbuilder.Append("");
sbuilder.Append("");
html = sbuilder.ToString();
}
}
}