diff --git a/libsecondlife-cs/JSONlib/JSONArray.cs b/libsecondlife-cs/JSONlib/JSONArray.cs
index 58b968ff..9ce043f4 100644
--- a/libsecondlife-cs/JSONlib/JSONArray.cs
+++ b/libsecondlife-cs/JSONlib/JSONArray.cs
@@ -61,7 +61,7 @@ namespace Nii.JSON
/// The ArrayList where the JSONArray's properties are kept.
private ArrayList myArrayList;
- #region JSONArray Constructors
+
///
/// Construct an empty JSONArray
///
@@ -105,25 +105,6 @@ namespace Nii.JSON
}
}
- ///
- /// Construct a JSONArray from a source string.
- ///
- /// A string that begins with '[' and ends with ']'.
- public JSONArray(string s) : this(new JSONTokener(s))
- {
- }
-
- ///
- /// Construct a JSONArray from a Collection.
- ///
- /// A Collection.
- public JSONArray(ICollection collection)
- {
- myArrayList = new ArrayList(collection);
- }
- #endregion
-
- #region C# extensions. Indexer and property
///
/// Alternate to Java get/put method, by using indexer
///
@@ -140,224 +121,6 @@ namespace Nii.JSON
}
}
- ///
- /// Alternativ to Java, getArrayList, by using propery
- ///
- public IList List
- {
- get
- {
- return myArrayList;
- }
- }
- #endregion
-
- #region Getters for a value associated with an index.
- ///
- /// Get the object value associated with an index.
- /// Use indexer instead!!! Added to be true to the original Java implementation
- ///
- /// index subscript. The index must be between 0 and length()-1
- /// An object value.
- public object getValue(int i)
- {
- object obj = opt(i);
- if (obj == null)
- {
- string msg = string.Format("JSONArray[{0}] not found", i);
- throw new Exception(msg);
- }
- return obj;
- //return myArrayList[i];
- }
-
- ///
- /// Get the ArrayList which is holding the elements of the JSONArray.
- /// Use the indexer instead!! Added to be true to the orignal Java src
- ///
- /// The ArrayList
- public IList getArrayList()
- {
- return myArrayList;
- }
-
- ///
- /// Get the boolean value associated with an index.
- /// The string values "true" and "false" are converted to boolean.
- ///
- /// index subscript
- /// The truth
- public bool getBoolean(int i)
- {
- object obj = getValue(i);
- if (obj is bool)
- {
- return (bool)obj;
- }
- string msg = string.Format("JSONArray[{0}]={1} not a Boolean", i, obj);
- throw new Exception(msg);
- }
-
- ///
- /// Get the double value associated with an index.
- ///
- /// index subscript
- /// A double value
- public double getDouble(int i)
- {
- object obj = getValue(i);
- if (obj is double)
- return (double)obj;
- if (obj is float)
- return (double)obj;
- if (obj is string)
- {
- return Convert.ToDouble(obj);
- }
- string msg = string.Format("JSONArray[{0}]={1} not a double", i, obj);
- throw new Exception(msg);
- }
-
- ///
- /// Get the int value associated with an index.
- ///
- /// index subscript
- /// The int value
- public int getInt(int i)
- {
- object obj = getValue(i);
- if (obj is int)
- return (int)obj;
- if (obj is string)
- {
- return Convert.ToInt32(obj);
- }
- string msg = string.Format("JSONArray[{0}]={1} not a int", i, obj);
- throw new Exception(msg);
- }
-
- ///
- /// Get the JSONArray associated with an index.
- ///
- /// index subscript
- /// A JSONArray value
- public JSONArray getJSONArray(int i)
- {
- object obj = getValue(i);
- if (obj is JSONArray)
- {
- return (JSONArray)obj;
- }
- string msg = string.Format("JSONArray[{0}]={1} not a JSONArray", i, obj);
- throw new Exception(msg);
- }
-
- ///
- /// Get the JSONObject associated with an index.
- ///
- /// index subscript
- /// A JSONObject value
- public JSONObject getJSONObject(int i)
- {
- object obj = getValue(i);
- if (obj is JSONObject)
- {
- return (JSONObject)obj;
- }
- string msg = string.Format("JSONArray[{0}]={1} not a JSONObject", i, obj);
- throw new Exception(msg);
- }
-
- ///
- /// Get the string associated with an index.
- ///
- /// index subscript
- /// A string value.
- public string getString(int i)
- {
- object obj = getValue(i);
- if (obj is string)
- {
- return (string)obj;
- }
- string msg = string.Format("JSONArray[{0}]={1} not a string", i, obj);
- throw new Exception(msg);
- }
- #endregion
-
- ///
- /// Determine if the value is null.
- ///
- /// index subscript
- /// true if the value at the index is null, or if there is no value.
- public bool isNull(int i)
- {
- object obj = opt(i);
- return (obj == null || obj.Equals(null));
- }
-
- ///
- /// Make a string from the contents of this JSONArray. The separator string
- /// is inserted between each element.
- /// Warning: This method assumes that the data structure is acyclical.
- ///
- /// separator A string that will be inserted between the elements.
- /// A string.
- public string join(string separator)
- {
- object obj;
- StringBuilder sb = new StringBuilder();
- for (int i=0; i 0)
- {
- sb.Append(separator);
- }
- obj = myArrayList[i];
-
- if (obj == null)
- {
- sb.Append("");
- }
- else if (obj is string)
- {
- sb.Append(JSONUtils.Enquote((string)obj));
- }
- else if (obj is int)
- {
- sb.Append(((int)obj).ToString());
- }
- else
- {
- sb.Append(obj.ToString());
- }
- }
- return sb.ToString();
- }
-
- ///
- /// Get the length of the JSONArray.
- /// Added to be true to the original Java implementation
- ///
- /// Number of JSONObjects in array
- public int Length()
- {
- return myArrayList.Count;
- }
- ///
- /// Get the length of the JSONArray.
- /// Using a propery instead of method
- ///
- public int Count
- {
- get
- {
- return myArrayList.Count;
- }
- }
-
-
- #region Get the optional value associated with an index.
///
/// Get the optional object value associated with an index.
///
@@ -371,193 +134,6 @@ namespace Nii.JSON
return myArrayList[i];
}
- ///
- /// Get the optional boolean value associated with an index.
- ///
- /// index subscript
- /// The truth
- public bool optBoolean(int i)
- {
- return optBoolean(i,false);
- }
-
- ///
- /// Get the optional boolean value associated with an index.
- /// It returns the defaultValue if there is no value at that index or if it is not
- /// a Boolean or the String "true" or "false".
- ///
- /// index subscript
- ///
- /// The truth.
- public bool optBoolean(int i, bool defaultValue)
- {
- object obj = opt(i);
- if (obj != null)
- {
- return (bool)obj;
- }
- return defaultValue;
- }
-
- ///
- /// Get the optional double value associated with an index.
- /// NaN is returned if the index is not found,
- /// or if the value is not a number and cannot be converted to a number.
- ///
- /// index subscript
- /// The double value object
- public double optDouble(int i)
- {
- return optDouble(i,double.NaN);
- }
-
- ///
- /// Get the optional double value associated with an index.
- /// NaN is returned if the index is not found,
- /// or if the value is not a number and cannot be converted to a number.
- ///
- /// index subscript
- ///
- /// The double value object
- public double optDouble(int i, double defaultValue)
- {
- object obj = opt(i);
- if (obj != null)
- {
- if (obj is double)
- return (double)obj;
- if (obj is float)
- return (float)obj;
- if (obj is string)
- {
- return Convert.ToDouble(obj);
- }
- string msg = string.Format("JSONArray[{0}]={1} not a double", i, obj);
- throw new Exception(msg);
- }
- return defaultValue;
- }
-
- ///
- /// Get the optional int value associated with an index.
- /// Zero is returned if the index is not found,
- /// or if the value is not a number and cannot be converted to a number.
- ///
- /// index subscript
- /// The int value object
- public int optInt(int i)
- {
- return optInt(i,0);
- }
-
- ///
- /// Get the optional int value associated with an index.
- /// The defaultValue is returned if the index is not found,
- /// or if the value is not a number and cannot be converted to a number.
- ///
- /// index subscript
- /// The default value
- /// The int value object
- public int optInt(int i, int defaultValue)
- {
- object obj = opt(i);
- if (obj != null)
- {
- if (obj is int)
- return (int)obj;
- if (obj is string)
- return Convert.ToInt32(obj);
- string msg = string.Format("JSONArray[{0}]={1} not a int", i, obj);
- throw new Exception(msg);
- }
- return defaultValue;
- }
-
- ///
- /// Get the optional JSONArray associated with an index.
- ///
- /// index subscript
- /// A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
- public JSONArray optJSONArray(int i)
- {
- object obj = opt(i);
- if (obj is JSONArray)
- return (JSONArray)obj;
- return null;
- }
-
- ///
- /// Get the optional JSONObject associated with an index.
- /// Null is returned if the key is not found, or null if the index has
- /// no value, or if the value is not a JSONObject.
- ///
- /// index subscript
- /// A JSONObject value
- public JSONObject optJSONObject(int i)
- {
- object obj = opt(i);
- if (obj is JSONObject)
- {
- return (JSONObject)obj;
- }
- return null;
- }
-
- ///
- /// Get the optional string value associated with an index. It returns an
- /// empty string if there is no value at that index. If the value
- /// is not a string and is not null, then it is coverted to a string.
- ///
- /// index subscript
- /// A String value
- public string optString(int i)
- {
- return optString(i, "");
- }
-
- ///
- /// Get the optional string associated with an index.
- /// The defaultValue is returned if the key is not found.
- ///
- /// index subscript
- /// The default value
- /// A string value
- public string optString(int i, string defaultValue)
- {
- object obj = opt(i);
- if (obj != null)
- {
- return obj.ToString();
- }
- return defaultValue;
- }
-
- #endregion
-
- #region Put methods - use indexer instead
-/**
- * OMITTED:
- * public JSONArray put(bool val)
- * public JSONArray put(double val)
- * public JSONArray put(int val)
-*/
- ///
- /// Append an object value.
- ///
- /// An object value. The value should be a Boolean, Double, Integer, JSONArray, JSObject, or String, or the JSONObject.NULL object
- /// this (JSONArray)
- public JSONArray put(object val)
- {
- myArrayList.Add(val);
- return this;
- }
-
-/*
- * OMITTED:
- * public JSONArray put(int index, boolean value)
- * public JSONArray put(int index, double value)
- * public JSONArray put(int index, int value)
- */
///
/// Put or replace a boolean value in the JSONArray.
///
@@ -592,38 +168,5 @@ namespace Nii.JSON
}
return this;
}
- #endregion
-
- ///
- /// Produce a JSONObject by combining a JSONArray of names with the values
- /// of this JSONArray.
- ///
- ///
- /// A JSONArray containing a list of key strings. These will be paired with the values.
- ///
- /// A JSONObject, or null if there are no names or if this JSONArray
- public JSONObject toJSONObject(JSONArray names)
- {
- if (names == null || names.Length() == 0 || this.Length() == 0)
- {
- return null;
- }
- JSONObject jo = new JSONObject();
- for (int i=0; i
- /// Make an JSON external form string of this JSONArray. For compactness, no
- /// unnecessary whitespace is added.
- ///
- /// a printable, displayable, transmittable representation of the array.
- public override string ToString()
- {
- return '['+ join(",") + ']';
- }
}
}
diff --git a/libsecondlife-cs/JSONlib/JSONFacade.cs b/libsecondlife-cs/JSONlib/JSONFacade.cs
index 45cc4b4e..045e0489 100644
--- a/libsecondlife-cs/JSONlib/JSONFacade.cs
+++ b/libsecondlife-cs/JSONlib/JSONFacade.cs
@@ -12,16 +12,6 @@ namespace Nii.JSON
public sealed class JsonFacade
{
///
- /// Parse a Hashtable and return a JSON formatted string
- ///
- ///
- ///
- public static string toJSON(IDictionary idict)
- {
- JSONObject jsob = new JSONObject(idict);
- return jsob.ToString();
- }
- ///
/// Parse JSON formatted string and return a Hashtable
///
///
diff --git a/libsecondlife-cs/JSONlib/JSONObject.cs b/libsecondlife-cs/JSONlib/JSONObject.cs
index bd1f8521..47597c80 100644
--- a/libsecondlife-cs/JSONlib/JSONObject.cs
+++ b/libsecondlife-cs/JSONlib/JSONObject.cs
@@ -103,7 +103,6 @@ namespace Nii.JSON
///
public class JSONObject
{
- #region Local struct JSONNull
///
/// Make a Null object
/// JSONObject.NULL is equivalent to the value that JavaScript calls null,
@@ -133,7 +132,6 @@ namespace Nii.JSON
return "null";
}
}
- #endregion
///The hash map where the JSONObject's properties are kept.
private Hashtable myHashMap;
@@ -148,7 +146,7 @@ namespace Nii.JSON
///
public static readonly JSONNull NULL = new JSONNull();
- #region Constructors for JSONObject
+
///
/// Construct an empty JSONObject.
///
@@ -223,106 +221,6 @@ namespace Nii.JSON
}
- // public JSONObject(Hashtable map)
- // By changing to arg to interface, all classes that implements IDictionary can be used
- // public interface IDictionary : ICollection, IEnumerable
- // Classes that implements IDictionary
- // 1. BaseChannelObjectWithProperties - Provides a base implementation of a channel object that wants to provide a dictionary interface to its properties.
- // 2. DictionaryBase - Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection of key-and-value pairs.
- // 3. Hashtable - Represents a collection of key-and-value pairs that are organized based on the hash code of the key.
- // 4. HybridDictionary - Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.
- // 5. ListDictionary - Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
- // 6. PropertyCollection - Contains the properties of a DirectoryEntry.
- // 7. PropertyDescriptorCollection - Represents a collection of PropertyDescriptor objects.
- // 8. SortedList - Represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.
- // 9. StateBag - Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited.
- // See ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsidictionaryclasstopic.htm
-
-
- ///
- /// Construct a JSONObject from a IDictionary
- ///
- ///
- public JSONObject(IDictionary map)
- {
- myHashMap = new Hashtable(map);
- myKeyIndexList = new ArrayList(map);
- }
-
- #endregion
-
- ///
- /// Accumulate values under a key. It is similar to the put method except
- /// that if there is already an object stored under the key then a
- /// JSONArray is stored under the key to hold all of the accumulated values.
- /// If there is already a JSONArray, then the new value is appended to it.
- /// In contrast, the put method replaces the previous value.
- ///
- /// A key string.
- /// An object to be accumulated under the key.
- /// this
- public JSONObject accumulate(string key, object val)
- {
- JSONArray a;
- object obj = opt(key);
- if (obj == null)
- {
- put(key, val);
- }
- else if (obj is JSONArray)
- {
- a = (JSONArray)obj;
- a.put(val);
- }
- else
- {
- a = new JSONArray();
- a.put(obj);
- a.put(val);
- put(key,a);
- }
- return this;
- }
-
-
- #region C# specific extensions
- ///
- /// Return the key for the associated index
- ///
- public string this[int i]
- {
- get
- {
- DictionaryEntry de = (DictionaryEntry)myKeyIndexList[i];
- return de.Key.ToString();
- }
- }
-
- ///
- /// Get/Add an object with the associated key
- ///
- public object this[string key]
- {
- get
- {
- return getValue(key);
- }
- set
- {
- put(key,value);
- }
- }
-
- ///
- /// Return the number of JSON items in hashtable
- ///
- public int Count
- {
- get
- {
- return myHashMap.Count;
- }
- }
///
/// C# convenience method
///
@@ -331,416 +229,7 @@ namespace Nii.JSON
{
return myHashMap;
}
- #endregion
-
- #region Gettes for a value associated with a key - use indexer instead
- ///
- /// Alias to Java get method
- /// Get the value object associated with a key.
- ///
- /// A key string.
- /// The object associated with the key.
- public object getValue(string key)
- {
- //return myHashMap[key];
- object obj = opt(key);
- if (obj == null)
- {
- throw new Exception("No such element");
- }
- return obj;
- }
-
- ///
- /// Get the boolean value associated with a key.
- ///
- /// A key string.
- /// The truth.
- public bool getBool(string key)
- {
- object o = getValue(key);
- if (o is bool)
- {
- bool b = (bool)o;
- return b;
- }
- string msg = string.Format("JSONObject[{0}] is not a Boolean",JSONUtils.Enquote(key));
- throw new Exception(msg);
- }
-
- ///
- /// Get the double value associated with a key.
- ///
- /// A key string.
- /// The double value
- public double getDouble(string key)
- {
- object o = getValue(key);
- if (o is double)
- return (double)o;
- if (o is float)
- return (double)o;
-
- if (o is string)
- {
- return Convert.ToDouble(o);
- }
- string msg = string.Format("JSONObject[{0}] is not a double",JSONUtils.Enquote(key));
- throw new Exception(msg);
- }
-
- ///
- /// Get the int value associated with a key.
- ///
- /// A key string
- /// The integer value.
- public int getInt(string key)
- {
- object o = getValue(key);
- if (o is int)
- {
- return (int)o;
- }
-
- if (o is string)
- {
- return Convert.ToInt32(o);
- }
- string msg = string.Format("JSONObject[{0}] is not a int",JSONUtils.Enquote(key));
- throw new Exception(msg);
- }
-
- ///
- /// Get the JSONArray value associated with a key.
- ///
- /// A key string
- /// A JSONArray which is the value
- public JSONArray getJSONArray(string key)
- {
- object o = getValue(key);
- if (o is JSONArray)
- {
- return (JSONArray)o;
- }
- string msg = string.Format("JSONObject[{0}]={1} is not a JSONArray",JSONUtils.Enquote(key),o);
- throw new Exception(msg);
- }
-
- ///
- /// Get the JSONObject value associated with a key.
- ///
- /// A key string.
- /// A JSONObject which is the value.
- public JSONObject getJSONObject(string key)
- {
- object o = getValue(key);
- if (o is JSONObject)
- {
- return (JSONObject)o;
- }
- string msg = string.Format("JSONObject[{0}]={1} is not a JSONArray",JSONUtils.Enquote(key),o);
- throw new Exception(msg);
- }
-
- ///
- /// Get the string associated with a key.
- ///
- /// A key string.
- /// A string which is the value.
- public string getString(string key)
- {
- return getValue(key).ToString();
- }
- #endregion
-
-
- ///
- /// Determine if the JSONObject contains a specific key.
- ///
- /// A key string.
- /// true if the key exists in the JSONObject.
- public bool has(string key)
- {
- return myHashMap.ContainsKey(key);
- }
-
-
- ///
- /// Get an enumeration of the keys of the JSONObject.
- /// Added to be true to orginal Java implementation
- /// Indexers are easier to use
- ///
- ///
- public IEnumerator keys()
- {
- return myHashMap.Keys.GetEnumerator();
- }
-
- ///
- /// Determine if the value associated with the key is null or if there is no value.
- ///
- /// A key string
- /// true if there is no value associated with the key or if the valus is the JSONObject.NULL object
- public bool isNull(string key)
- {
- return JSONObject.NULL.Equals(opt(key));
- }
-
- ///
- /// Get the number of keys stored in the JSONObject.
- ///
- /// The number of keys in the JSONObject.
- public int Length()
- {
- return myHashMap.Count;
- }
-
- ///
- /// Produce a JSONArray containing the names of the elements of this JSONObject
- ///
- /// A JSONArray containing the key strings, or null if the JSONObject
- public JSONArray names()
- {
- JSONArray ja = new JSONArray();
-
- //NOTE!! I choose to use keys stored in the ArrayList, to maintain sequence order
- foreach (string key in myKeyIndexList)
- {
- ja.put(key);
- }
- if (ja.Length() == 0)
- {
- return null;
- }
- return ja;
- }
-
- ///
- /// Produce a string from a number.
- ///
- /// Number value type object
- /// String representation of the number
- public string numberToString(object number)
- {
- if (number is float && ((float)number) == float.NaN)
- {
- string msg = string.Format("");
- throw new ArgumentException("object must be a valid number", "number");
- }
- if (number is double && ((double)number) == double.NaN)
- {
- string msg = string.Format("");
- throw new ArgumentException("object must be a valid number", "number");
- }
-
- // Shave off trailing zeros and decimal point, if possible
-
- string s = ((double) number).ToString(NumberFormatInfo.InvariantInfo).ToLower();
-
- if (s.IndexOf('e') < 0 && s.IndexOf('.') > 0)
- {
- while(s.EndsWith("0"))
- {
- s.Substring(0,s.Length-1);
- }
- if (s.EndsWith("."))
- {
- s.Substring(0,s.Length-1);
- }
- }
- return s;
- }
-
- #region Get an optional value associated with a key.
- ///
- /// Get an optional value associated with a key.
- ///
- /// A key string
- /// An object which is the value, or null if there is no value.
- public object opt(string key)
- {
- if (key == null)
- {
- throw new ArgumentNullException("key", "Null key");
- }
- return myHashMap[key];
- }
-
- ///
- /// Get an optional value associated with a key.
- /// It returns false if there is no such key, or if the value is not
- /// Boolean.TRUE or the String "true".
- ///
- /// A key string.
- /// bool value object
- public bool optBoolean(string key)
- {
- return optBoolean(key, false);
- }
-
- ///
- /// Get an optional value associated with a key.
- /// It returns false if there is no such key, or if the value is not
- /// Boolean.TRUE or the String "true".
- ///
- /// A key string.
- /// The preferred return value if conversion fails
- /// bool value object
- public bool optBoolean(string key, bool defaultValue)
- {
- object obj = opt(key);
- if (obj != null)
- {
- if (obj is bool)
- return (bool)obj;
- if (obj is string)
- {
- return Convert.ToBoolean(obj);
- }
- }
- return defaultValue;
- }
-
- ///
- /// Get an optional double associated with a key,
- /// or NaN if there is no such key or if its value is not a number.
- /// If the value is a string, an attempt will be made to evaluate it as
- /// a number.
- ///
- /// A string which is the key.
- /// A double value object
- public double optDouble(string key)
- {
- return optDouble(key, double.NaN);
- }
-
- ///
- /// Get an optional double associated with a key,
- /// or NaN if there is no such key or if its value is not a number.
- /// If the value is a string, an attempt will be made to evaluate it as
- /// a number.
- ///
- /// A string which is the key.
- /// The default
- /// A double value object
- public double optDouble(string key, double defaultValue)
- {
- object obj = opt(key);
- if (obj != null)
- {
- if (obj is double)
- return (double)obj;
- if (obj is float)
- return (double)obj;
- if (obj is string)
- {
- return Convert.ToDouble(obj);
- }
- }
- return defaultValue;
- }
-
- ///
- /// Get an optional double associated with a key, or the
- /// defaultValue if there is no such key or if its value is not a number.
- /// If the value is a string, an attempt will be made to evaluate it as
- /// number.
- ///
- /// A key string.
- /// An int object value
- public int optInt(string key)
- {
- return optInt(key, 0);
- }
-
- ///
- /// Get an optional double associated with a key, or the
- /// defaultValue if there is no such key or if its value is not a number.
- /// If the value is a string, an attempt will be made to evaluate it as
- /// number.
- ///
- /// A key string.
- /// The default value
- /// An int object value
- public int optInt(string key, int defaultValue)
- {
- object obj = opt(key);
- if (obj != null)
- {
- if (obj is int)
- return (int)obj;
- if (obj is string)
- return Convert.ToInt32(obj);
- }
- return defaultValue;
- }
-
- ///
- /// Get an optional JSONArray associated with a key.
- /// It returns null if there is no such key, or if its value is not a JSONArray
- ///
- /// A key string
- /// A JSONArray which is the value
- public JSONArray optJSONArray(string key)
- {
- object obj = opt(key);
- if (obj is JSONArray)
- {
- return (JSONArray)obj;
- }
- return null;
- }
-
- ///
- /// Get an optional JSONObject associated with a key.
- /// It returns null if there is no such key, or if its value is not a JSONObject.
- ///
- /// A key string.
- /// A JSONObject which is the value
- public JSONObject optJSONObject(string key)
- {
- object obj = opt(key);
- if (obj is JSONObject)
- {
- return (JSONObject)obj;
- }
- return null;
- }
-
- ///
- /// Get an optional string associated with a key.
- /// It returns an empty string if there is no such key. If the value is not
- /// a string and is not null, then it is coverted to a string.
- ///
- /// A key string.
- /// A string which is the value.
- public string optString(string key)
- {
- object obj = opt(key);
-
- return optString(key, "");
- }
-
- ///
- /// Get an optional string associated with a key.
- /// It returns the defaultValue if there is no such key.
- ///
- /// A key string.
- /// The default
- /// A string which is the value.
- public string optString(string key, string defaultValue)
- {
- object obj = opt(key);
- if (obj != null)
- {
- return obj.ToString();
- }
- return defaultValue;
- }
- #endregion
-
- #region Put methods for adding key/value pairs
// OMITTED - all put methods can be replaced by a indexer in C#
// - ===================================================
// public JSONObject put(String key, boolean value)
@@ -768,7 +257,6 @@ namespace Nii.JSON
{
if (!myHashMap.ContainsKey(key))
{
- string test = key;
myHashMap.Add(key,val);
myKeyIndexList.Add(key);
}
@@ -784,22 +272,6 @@ namespace Nii.JSON
return this;
}
- ///
- /// Add a key value pair
- ///
- ///
- ///
- ///
- public JSONObject putOpt(string key, object val)
- {
- if (val != null)
- {
- put(key,val);
- }
- return this;
- }
- #endregion
-
///
/// Remove a object assosiateted with the given key
///
@@ -817,66 +289,5 @@ namespace Nii.JSON
}
return null;
}
-
- ///
- /// Append an array of JSONObjects to current object
- ///
- ///
- ///
- public JSONArray toJSONArray(JSONArray names)
- {
- if (names == null | names.Length() == 0)
- return null;
-
- JSONArray ja = new JSONArray();
- for (int i=0; i
- /// Overridden to return a JSON formattet object as a string
- ///
- /// JSON object as formatted string
- public override string ToString()
- {
- object obj = null;
- //string s;
- StringBuilder sb = new StringBuilder();
-
- sb.Append('{');
- foreach (string key in myHashMap.Keys) //NOTE! Could also use myKeyIndexList !!!
- {
- if (obj != null)
- sb.Append(',');
- obj = myHashMap[key];
- if (obj != null)
- {
- sb.Append(JSONUtils.Enquote(key));
- sb.Append(':');
-
- if (obj is string)
- {
- sb.Append(JSONUtils.Enquote((string)obj));
- }
- else if (obj is float || obj is double)
- {
- sb.Append(numberToString(obj));
- }
- else if (obj is bool)
- {
- sb.Append(obj.ToString().ToLower());
- }
- else
- {
- sb.Append(obj.ToString());
- }
- }
- }
- sb.Append('}');
- return sb.ToString();
- }
}
}
diff --git a/libsecondlife-cs/JSONlib/JSONTokener.cs b/libsecondlife-cs/JSONlib/JSONTokener.cs
index a4c7f7b1..ee77f670 100644
--- a/libsecondlife-cs/JSONlib/JSONTokener.cs
+++ b/libsecondlife-cs/JSONlib/JSONTokener.cs
@@ -97,22 +97,6 @@ namespace Nii.JSON
return c;
}
- ///
- /// Consume the next character, and check that it matches a specified character
- ///
- /// The character to match.
- /// The character.
- public char next(char c)
- {
- char n = next();
- if (n != c)
- {
- string msg = "Expected '" + c + "' and instead saw '" + n + "'.";
- throw (new Exception(msg));
- }
- return n;
- }
-
///
/// Get the next n characters.
///
@@ -242,55 +226,6 @@ namespace Nii.JSON
}//END-while
}
- ///
- /// Get the text up but not including the specified character or the
- /// end of line, whichever comes first.
- ///
- /// A delimiter character.
- /// A string.
- public string nextTo(char d)
- {
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- char c = next();
- if (c == d || c == (char)0 || c == '\n' || c == '\r')
- {
- if (c != (char)0)
- {
- back();
- }
- return sb.ToString().Trim();
- }
- sb.Append(c);
- }
- }
-
- ///
- /// Get the text up but not including one of the specified delimeter
- /// characters or the end of line, which ever comes first.
- ///
- /// A set of delimiter characters.
- /// A string, trimmed.
- public string nextTo(string delimiters)
- {
- char c;
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- c = next();
- if ((delimiters.IndexOf(c) >= 0) || (c == (char)0 ) || (c == '\n') || (c == '\r'))
- {
- if (c != (char)0)
- {
- back();
- }
- return sb.ToString().Trim();
- }
- sb.Append(c);
- }
- }
-
///
/// Get the next value as object. The value can be a Boolean, Double, Integer,
/// JSONArray, JSONObject, or String, or the JSONObject.NULL object.
@@ -343,17 +278,15 @@ namespace Nii.JSON
{
return Convert.ToInt32(s);
}
- catch (Exception e)
+ catch
{
- string msg = e.Message;
}
try
{
return Convert.ToDouble(s, NumberFormatInfo.InvariantInfo);
}
- catch (Exception e)
+ catch
{
- string msg = e.Message;
}
}
if (s == "")
@@ -363,62 +296,6 @@ namespace Nii.JSON
return s;
}
- ///
- /// Skip characters until the next character is the requested character.
- /// If the requested character is not found, no characters are skipped.
- ///
- /// A character to skip to.
- ///
- /// The requested character, or zero if the requested character is not found.
- ///
- public char skipTo(char to)
- {
- char c;
- int i = myIndex;
- do
- {
- c = next();
- if (c == (char)0)
- {
- myIndex = i;
- return c;
- }
- }while (c != to);
-
- back();
- return c;
- }
-
- ///
- /// Skip characters until past the requested string.
- /// If it is not found, we are left at the end of the source.
- ///
- /// A string to skip past.
- public void skipPast(string to)
- {
- myIndex = mySource.IndexOf(to, myIndex);
- if (myIndex < 0)
- {
- myIndex = mySource.Length;
- }
- else
- {
- myIndex += to.Length;
- }
- }
-
- // TODO implement exception SyntaxError
-
-
- ///
- /// Make a printable string of this JSONTokener.
- ///
- /// " at character [myIndex] of [mySource]"
- public override string ToString()
- {
- return " at charachter " + myIndex + " of " + mySource;
- }
-
///
/// Unescape the source text. Convert %hh sequences to single characters,
/// and convert plus to space. There are Web transport systems that insist on
diff --git a/libsecondlife-cs/JSONlib/JSONUtils.cs b/libsecondlife-cs/JSONlib/JSONUtils.cs
index 6e5af027..e69de29b 100644
--- a/libsecondlife-cs/JSONlib/JSONUtils.cs
+++ b/libsecondlife-cs/JSONlib/JSONUtils.cs
@@ -1,69 +0,0 @@
-using System;
-using System.Text;
-
-namespace Nii.JSON
-{
- ///
- /// Public Domain 2002 JSON.org
- /// @author JSON.org
- /// @version 0.1
- /// Ported to C# by Are Bjolseth, teleplan.no
- ///
- public sealed class JSONUtils
- {
- ///
- /// Produce a string in double quotes with backslash sequences in all the right places.
- ///
- /// A String
- /// A String correctly formatted for insertion in a JSON message.
- public static string Enquote(string s)
- {
- if (s == null || s.Length == 0)
- {
- return "\"\"";
- }
- char c;
- int i;
- int len = s.Length;
- StringBuilder sb = new StringBuilder(len + 4);
- string t;
-
- sb.Append('"');
- for (i = 0; i < len; i += 1)
- {
- c = s[i];
- if ((c == '\\') || (c == '"') || (c == '>'))
- {
- sb.Append('\\');
- sb.Append(c);
- }
- else if (c == '\b')
- sb.Append("\\b");
- else if (c == '\t')
- sb.Append("\\t");
- else if (c == '\n')
- sb.Append("\\n");
- else if (c == '\f')
- sb.Append("\\f");
- else if (c == '\r')
- sb.Append("\\r");
- else
- {
- if (c < ' ')
- {
- //t = "000" + Integer.toHexString(c);
- string tmp = new string(c,1);
- t = "000" + int.Parse(tmp,System.Globalization.NumberStyles.HexNumber);
- sb.Append("\\u" + t.Substring(t.Length - 4));
- }
- else
- {
- sb.Append(c);
- }
- }
- }
- sb.Append('"');
- return sb.ToString();
- }
- }
-}
diff --git a/libsecondlife-cs/JSONlib/Nii.JSON.csproj b/libsecondlife-cs/JSONlib/Nii.JSON.csproj
index 8c9be8a8..ab250b6d 100644
--- a/libsecondlife-cs/JSONlib/Nii.JSON.csproj
+++ b/libsecondlife-cs/JSONlib/Nii.JSON.csproj
@@ -29,7 +29,7 @@
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
- DocumentationFile = "json.doc.xml"
+ DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
diff --git a/libsecondlife-cs/JSONlib/json.doc.xml b/libsecondlife-cs/JSONlib/json.doc.xml
deleted file mode 100644
index 0d0006f1..00000000
--- a/libsecondlife-cs/JSONlib/json.doc.xml
+++ /dev/null
@@ -1,878 +0,0 @@
-
-
-
- JSON
-
-
-
-
-
- A JSONArray is an ordered sequence of values. Its external form is a string
- wrapped in square brackets with commas between the values. The internal form
- is an object having get() and opt() methods for accessing the values by
- index, and put() methods for adding or replacing values. The values can be
- any of these types: Boolean, JSONArray, JSONObject, Number, String, or the
- JSONObject.NULL object.
-
-
- The constructor can convert a JSON external form string into an
- internal form Java object. The toString() method creates an external
- form string.
-
-
- A get() method returns a value if one can be found, and throws an exception
- if one cannot be found. An opt() method returns a default value instead of
- throwing an exception, and so is useful for obtaining optional values.
-
-
- The generic get() and opt() methods return an object which you can cast or
- query for type. There are also typed get() and opt() methods that do typing
- checking and type coersion for you.
-
-
- The texts produced by the toString() methods are very strict.
- The constructors are more forgiving in the texts they will accept.
-
-
-
- - An extra comma may appear just before the closing bracket.
- - Strings may be quoted with single quotes.
- - Strings do not need to be quoted at all if they do not contain leading
- or trailing spaces, and if they do not contain any of these characters:
- { } [ ] / \ : ,
- - Numbers may have the 0- (octal) or 0x- (hex) prefix.
-
-
-
- Public Domain 2002 JSON.org
- @author JSON.org
- @version 0.1
-
- Ported to C# by Are Bjolseth, teleplan.no
- TODO:
- 1. Implement Custom exceptions
- 2. Add indexer JSONObject[i] = object, and object = JSONObject[i];
- 3. Add indexer JSONObject["key"] = object, and object = JSONObject["key"]
- 4. Add unit testing
- 5. Add log4net
- 6. Make get/put methods private, to force use of indexer instead?
-
-
-
- The ArrayList where the JSONArray's properties are kept.
-
-
-
- Construct an empty JSONArray
-
-
-
-
- Construct a JSONArray from a JSONTokener.
-
- A JSONTokener
-
-
-
- Construct a JSONArray from a source string.
-
- A string that begins with '[' and ends with ']'.
-
-
-
- Construct a JSONArray from a Collection.
-
- A Collection.
-
-
-
- Get the object value associated with an index.
- Use indexer instead!!! Added to be true to the original Java implementation
-
- index subscript. The index must be between 0 and length()-1
- An object value.
-
-
-
- Get the ArrayList which is holding the elements of the JSONArray.
- Use the indexer instead!! Added to be true to the orignal Java src
-
- The ArrayList
-
-
-
- Get the boolean value associated with an index.
- The string values "true" and "false" are converted to boolean.
-
- index subscript
- The truth
-
-
-
- Get the double value associated with an index.
-
- index subscript
- A double value
-
-
-
- Get the int value associated with an index.
-
- index subscript
- The int value
-
-
-
- Get the JSONArray associated with an index.
-
- index subscript
- A JSONArray value
-
-
-
- Get the JSONObject associated with an index.
-
- index subscript
- A JSONObject value
-
-
-
- Get the string associated with an index.
-
- index subscript
- A string value.
-
-
-
- Determine if the value is null.
-
- index subscript
- true if the value at the index is null, or if there is no value.
-
-
-
- Make a string from the contents of this JSONArray. The separator string
- is inserted between each element.
- Warning: This method assumes that the data structure is acyclical.
-
- separator A string that will be inserted between the elements.
- A string.
-
-
-
- Get the length of the JSONArray.
- Added to be true to the original Java implementation
-
- Number of JSONObjects in array
-
-
-
- Get the optional object value associated with an index.
-
- index subscript
- object at that index.
-
-
-
- Get the optional boolean value associated with an index.
-
- index subscript
- The truth
-
-
-
- Get the optional boolean value associated with an index.
- It returns the defaultValue if there is no value at that index or if it is not
- a Boolean or the String "true" or "false".
-
- index subscript
-
- The truth.
-
-
-
- Get the optional double value associated with an index.
- NaN is returned if the index is not found,
- or if the value is not a number and cannot be converted to a number.
-
- index subscript
- The double value object
-
-
-
- Get the optional double value associated with an index.
- NaN is returned if the index is not found,
- or if the value is not a number and cannot be converted to a number.
-
- index subscript
-
- The double value object
-
-
-
- Get the optional int value associated with an index.
- Zero is returned if the index is not found,
- or if the value is not a number and cannot be converted to a number.
-
- index subscript
- The int value object
-
-
-
- Get the optional int value associated with an index.
- The defaultValue is returned if the index is not found,
- or if the value is not a number and cannot be converted to a number.
-
- index subscript
- The default value
- The int value object
-
-
-
- Get the optional JSONArray associated with an index.
-
- index subscript
- A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.
-
-
-
- Get the optional JSONObject associated with an index.
- Null is returned if the key is not found, or null if the index has
- no value, or if the value is not a JSONObject.
-
- index subscript
- A JSONObject value
-
-
-
- Get the optional string value associated with an index. It returns an
- empty string if there is no value at that index. If the value
- is not a string and is not null, then it is coverted to a string.
-
- index subscript
- A String value
-
-
-
- Get the optional string associated with an index.
- The defaultValue is returned if the key is not found.
-
- index subscript
- The default value
- A string value
-
-
- OMITTED:
- public JSONArray put(bool val)
- public JSONArray put(double val)
- public JSONArray put(int val)
-
- Append an object value.
-
- An object value. The value should be a Boolean, Double, Integer, JSONArray, JSObject, or String, or the JSONObject.NULL object
- this (JSONArray)
-
-
-
- Put or replace a boolean value in the JSONArray.
-
-
- The subscript. If the index is greater than the length of
- the JSONArray, then null elements will be added as necessary to pad it out.
-
- An object value.
- this (JSONArray)
-
-
-
- Produce a JSONObject by combining a JSONArray of names with the values
- of this JSONArray.
-
-
- A JSONArray containing a list of key strings. These will be paired with the values.
-
- A JSONObject, or null if there are no names or if this JSONArray
-
-
-
- Make an JSON external form string of this JSONArray. For compactness, no
- unnecessary whitespace is added.
-
- a printable, displayable, transmittable representation of the array.
-
-
-
- Alternate to Java get/put method, by using indexer
-
-
-
-
- Alternativ to Java, getArrayList, by using propery
-
-
-
-
- Get the length of the JSONArray.
- Using a propery instead of method
-
-
-
-
- Summary description for JsonFacade.
-
-
-
-
- Parse a Hashtable and return a JSON formatted string
-
-
-
-
-
-
- Parse JSON formatted string and return a Hashtable
-
-
-
-
-
-
-
- A JSONArray is an ordered sequence of values. Its external form is a string
- wrapped in square brackets with commas between the values. The internal form
- is an object having get() and opt() methods for accessing the values by
- index, and put() methods for adding or replacing values. The values can be
- any of these types: Boolean, JSONArray, JSONObject, Number, String, or the
- JSONObject.NULL object.
-
-
- The constructor can convert a JSON external form string into an
- internal form Java object. The toString() method creates an external
- form string.
-
-
- A get() method returns a value if one can be found, and throws an exception
- if one cannot be found. An opt() method returns a default value instead of
- throwing an exception, and so is useful for obtaining optional values.
-
-
- The generic get() and opt() methods return an object which you can cast or
- query for type. There are also typed get() and opt() methods that do typing
- checking and type coersion for you.
-
-
- The texts produced by the toString() methods are very strict.
- The constructors are more forgiving in the texts they will accept.
-
-
-
- - An extra comma may appear just before the closing bracket.
- - Strings may be quoted with single quotes.
- - Strings do not need to be quoted at all if they do not contain leading
- or trailing spaces, and if they do not contain any of these characters:
- { } [ ] / \ : ,
- - Numbers may have the 0- (octal) or 0x- (hex) prefix.
-
-
-
- Public Domain 2002 JSON.org
- @author JSON.org
- @version 0.1
-
- Ported to C# by Are Bjolseth, teleplan.no
- TODO:
- 1. Implement Custom exceptions
- 2. Add indexer JSONObject[i] = object, and object = JSONObject[i];
- 3. Add indexer JSONObject["key"] = object, and object = JSONObject["key"]
- 4. Add unit testing
- 5. Add log4net
- 6. Make get/put methods private, to force use of indexer instead?
-
-
-
- The hash map where the JSONObject's properties are kept.
-
-
- A shadow list of keys to enable access by sequence of insertion
-
-
-
- It is sometimes more convenient and less ambiguous to have a NULL
- object than to use C#'s null value.
- JSONObject.NULL.toString() returns "null".
-
-
-
-
- Construct an empty JSONObject.
-
-
-
-
- Construct a JSONObject from a JSONTokener.
-
- A JSONTokener object containing the source string.
-
-
-
- Construct a JSONObject from a string.
-
- A string beginning with '{' and ending with '}'.
-
-
-
- Construct a JSONObject from a IDictionary
-
-
-
-
-
- Accumulate values under a key. It is similar to the put method except
- that if there is already an object stored under the key then a
- JSONArray is stored under the key to hold all of the accumulated values.
- If there is already a JSONArray, then the new value is appended to it.
- In contrast, the put method replaces the previous value.
-
- A key string.
- An object to be accumulated under the key.
- this
-
-
-
- C# convenience method
-
- The Hashtable
-
-
-
- Alias to Java get method
- Get the value object associated with a key.
-
- A key string.
- The object associated with the key.
-
-
-
- Get the boolean value associated with a key.
-
- A key string.
- The truth.
-
-
-
- Get the double value associated with a key.
-
- A key string.
- The double value
-
-
-
- Get the int value associated with a key.
-
- A key string
- The integer value.
-
-
-
- Get the JSONArray value associated with a key.
-
- A key string
- A JSONArray which is the value
-
-
-
- Get the JSONObject value associated with a key.
-
- A key string.
- A JSONObject which is the value.
-
-
-
- Get the string associated with a key.
-
- A key string.
- A string which is the value.
-
-
-
- Determine if the JSONObject contains a specific key.
-
- A key string.
- true if the key exists in the JSONObject.
-
-
-
- Get an enumeration of the keys of the JSONObject.
- Added to be true to orginal Java implementation
- Indexers are easier to use
-
-
-
-
-
- Determine if the value associated with the key is null or if there is no value.
-
- A key string
- true if there is no value associated with the key or if the valus is the JSONObject.NULL object
-
-
-
- Get the number of keys stored in the JSONObject.
-
- The number of keys in the JSONObject.
-
-
-
- Produce a JSONArray containing the names of the elements of this JSONObject
-
- A JSONArray containing the key strings, or null if the JSONObject
-
-
-
- Produce a string from a number.
-
- Number value type object
- String representation of the number
-
-
-
- Get an optional value associated with a key.
-
- A key string
- An object which is the value, or null if there is no value.
-
-
-
- Get an optional value associated with a key.
- It returns false if there is no such key, or if the value is not
- Boolean.TRUE or the String "true".
-
- A key string.
- bool value object
-
-
-
- Get an optional value associated with a key.
- It returns false if there is no such key, or if the value is not
- Boolean.TRUE or the String "true".
-
- A key string.
- The preferred return value if conversion fails
- bool value object
-
-
-
- Get an optional double associated with a key,
- or NaN if there is no such key or if its value is not a number.
- If the value is a string, an attempt will be made to evaluate it as
- a number.
-
- A string which is the key.
- A double value object
-
-
-
- Get an optional double associated with a key,
- or NaN if there is no such key or if its value is not a number.
- If the value is a string, an attempt will be made to evaluate it as
- a number.
-
- A string which is the key.
- The default
- A double value object
-
-
-
- Get an optional double associated with a key, or the
- defaultValue if there is no such key or if its value is not a number.
- If the value is a string, an attempt will be made to evaluate it as
- number.
-
- A key string.
- An int object value
-
-
-
- Get an optional double associated with a key, or the
- defaultValue if there is no such key or if its value is not a number.
- If the value is a string, an attempt will be made to evaluate it as
- number.
-
- A key string.
- The default value
- An int object value
-
-
-
- Get an optional JSONArray associated with a key.
- It returns null if there is no such key, or if its value is not a JSONArray
-
- A key string
- A JSONArray which is the value
-
-
-
- Get an optional JSONObject associated with a key.
- It returns null if there is no such key, or if its value is not a JSONObject.
-
- A key string.
- A JSONObject which is the value
-
-
-
- Get an optional string associated with a key.
- It returns an empty string if there is no such key. If the value is not
- a string and is not null, then it is coverted to a string.
-
- A key string.
- A string which is the value.
-
-
-
- Get an optional string associated with a key.
- It returns the defaultValue if there is no such key.
-
- A key string.
- The default
- A string which is the value.
-
-
-
- Put a key/value pair in the JSONObject. If the value is null,
- then the key will be removed from the JSONObject if it is present.
-
- A key string.
-
- An object which is the value. It should be of one of these
- types: Boolean, Double, Integer, JSONArray, JSONObject, String, or the
- JSONObject.NULL object.
-
- JSONObject
-
-
-
- Add a key value pair
-
-
-
-
-
-
-
- Remove a object assosiateted with the given key
-
-
-
-
-
-
- Append an array of JSONObjects to current object
-
-
-
-
-
-
- Overridden to return a JSON formattet object as a string
-
- JSON object as formatted string
-
-
-
- Return the key for the associated index
-
-
-
-
- Get/Add an object with the associated key
-
-
-
-
- Return the number of JSON items in hashtable
-
-
-
-
- Make a Null object
- JSONObject.NULL is equivalent to the value that JavaScript calls null,
- whilst C#'s null is equivalent to the value that JavaScript calls undefined.
-
-
-
-
- Overriden to return "null"
-
- null
-
-
-
-
- A JSONTokener takes a source string and extracts characters and tokens from
- it. It is used by the JSONObject and JSONArray constructors to parse
- JSON source strings.
-
-
- Public Domain 2002 JSON.org
- @author JSON.org
- @version 0.1
-
- Ported to C# by Are Bjolseth, teleplan.no
-
-
- - Implement Custom exceptions
- - Add unit testing
- - Add log4net
-
-
-
-
-
- The index of the next character.
-
-
- The source string being tokenized.
-
-
-
- Construct a JSONTokener from a string.
-
- A source string.
-
-
-
- Back up one character. This provides a sort of lookahead capability,
- so that you can test for a digit or letter before attempting to parse
- the next number or identifier.
-
-
-
-
- Get the hex value of a character (base16).
-
-
- A character between '0' and '9' or between 'A' and 'F' or
- between 'a' and 'f'.
-
- An int between 0 and 15, or -1 if c was not a hex digit.
-
-
-
- Determine if the source string still contains characters that next() can consume.
-
- true if not yet at the end of the source.
-
-
-
- Get the next character in the source string.
-
- The next character, or 0 if past the end of the source string.
-
-
-
- Consume the next character, and check that it matches a specified character
-
- The character to match.
- The character.
-
-
-
- Get the next n characters.
-
- The number of characters to take.
- A string of n characters.
-
-
-
- Get the next char in the string, skipping whitespace
- and comments (slashslash and slashstar).
-
- A character, or 0 if there are no more characters.
-
-
-
- Return the characters up to the next close quote character.
- Backslash processing is done. The formal JSON format does not
- allow strings in single quotes, but an implementation is allowed to
- accept them.
-
- The quoting character, either " or '
- A String.
-
-
-
- Get the text up but not including the specified character or the
- end of line, whichever comes first.
-
- A delimiter character.
- A string.
-
-
-
- Get the text up but not including one of the specified delimeter
- characters or the end of line, which ever comes first.
-
- A set of delimiter characters.
- A string, trimmed.
-
-
-
- Get the next value as object. The value can be a Boolean, Double, Integer,
- JSONArray, JSONObject, or String, or the JSONObject.NULL object.
-
- An object.
-
-
-
- Skip characters until the next character is the requested character.
- If the requested character is not found, no characters are skipped.
-
- A character to skip to.
-
- The requested character, or zero if the requested character is not found.
-
-
-
-
- Skip characters until past the requested string.
- If it is not found, we are left at the end of the source.
-
- A string to skip past.
-
-
-
- Make a printable string of this JSONTokener.
-
- " at character [myIndex] of [mySource]"
-
-
-
- Unescape the source text. Convert %hh sequences to single characters,
- and convert plus to space. There are Web transport systems that insist on
- doing unnecessary URL encoding. This provides a way to undo it.
-
-
-
-
- Convert %hh sequences to single characters, and convert plus to space.
-
- A string that may contain plus and %hh sequences.
- The unescaped string.
-
-
-
- Public Domain 2002 JSON.org
- @author JSON.org
- @version 0.1
- Ported to C# by Are Bjolseth, teleplan.no
-
-
-
-
- Produce a string in double quotes with backslash sequences in all the right places.
-
- A String
- A String correctly formatted for insertion in a JSON message.
-
-
-
diff --git a/libsecondlife-cs/XmlRpcCS/AssemblyInfo.cs b/libsecondlife-cs/XmlRpcCS/AssemblyInfo.cs
index 05f089d3..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/AssemblyInfo.cs
+++ b/libsecondlife-cs/XmlRpcCS/AssemblyInfo.cs
@@ -1,8 +0,0 @@
-using System.Reflection;
-
-[assembly: AssemblyVersion("1.10.*")]
-[assembly: AssemblyTitle("XmlRpcCS")]
-[assembly: AssemblyCompany("Ronin Consulting Inc")]
-[assembly: AssemblyDescription("XML RPC client and server")]
-
-
diff --git a/libsecondlife-cs/XmlRpcCS/SimpleHttpRequest.cs b/libsecondlife-cs/XmlRpcCS/SimpleHttpRequest.cs
index 4b408de5..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/SimpleHttpRequest.cs
+++ b/libsecondlife-cs/XmlRpcCS/SimpleHttpRequest.cs
@@ -1,204 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.IO;
- using System.Net.Sockets;
- using System.Collections;
-
- ///Very basic HTTP request handler.
- ///This class is designed to accept a TcpClient and treat it as an HTTP request.
- /// It will do some basic header parsing and manage the input and output streams associated
- /// with the request.
- public class SimpleHttpRequest
- {
- private String _httpMethod = null;
- private String _protocol;
- private String _filePathFile = null;
- private String _filePathDir = null;
- private String __filePath;
- private TcpClient _client;
- private StreamReader _input;
- private StreamWriter _output;
- private Hashtable _headers;
-
- /// A constructor which accepts the TcpClient.
- /// It creates the associated input and output streams, determines the request type,
- /// and parses the remaining HTTP header.
- /// The TcpClient associated with the HTTP connection.
- public SimpleHttpRequest(TcpClient client)
- {
- _client = client;
- _output = new StreamWriter(client.GetStream());
- _input = new StreamReader(client.GetStream());
- GetRequestMethod();
- GetRequestHeaders();
- }
-
- /// The output StreamWriter associated with the request.
- public StreamWriter Output
- {
- get { return _output; }
- }
-
- /// The input StreamReader associated with the request.
- public StreamReader Input
- {
- get { return _input; }
- }
-
- /// The TcpClient with the request.
- public TcpClient Client
- {
- get { return _client; }
- }
-
- private String _filePath
- {
- get { return __filePath; }
- set
- {
- __filePath = value;
- _filePathDir = null;
- _filePathFile = null;
- }
- }
-
- /// The type of HTTP request (i.e. PUT, GET, etc.).
- public String HttpMethod
- {
- get { return _httpMethod; }
- }
-
- /// The level of the HTTP protocol.
- public String Protocol
- {
- get { return _protocol; }
- }
-
- /// The "path" which is part of any HTTP request.
- public String FilePath
- {
- get { return _filePath; }
- }
-
- /// The file portion of the "path" which is part of any HTTP request.
- public String FilePathFile
- {
- get
- {
- if (_filePathFile != null)
- return _filePathFile;
-
- int i = FilePath.LastIndexOf("/");
-
- if (i == -1)
- return "";
-
- i++;
- _filePathFile = FilePath.Substring(i, FilePath.Length - i);
- return _filePathFile;
- }
- }
-
- /// The directory portion of the "path" which is part of any HTTP request.
- public String FilePathDir
- {
- get
- {
- if (_filePathDir != null)
- return _filePathDir;
-
- int i = FilePath.LastIndexOf("/");
-
- if (i == -1)
- return "";
-
- i++;
- _filePathDir = FilePath.Substring(0, i);
- return _filePathDir;
- }
- }
-
- private void GetRequestMethod()
- {
- string req = _input.ReadLine();
- if (req == null)
- throw new ApplicationException("Void request.");
-
- if (0 == String.Compare("GET ", req.Substring (0, 4), true))
- _httpMethod = "GET";
- else if (0 == String.Compare("POST ", req.Substring (0, 5), true))
- _httpMethod = "POST";
- else
- throw new InvalidOperationException("Unrecognized method in query: " + req);
-
- req = req.TrimEnd ();
- int idx = req.IndexOf(' ') + 1;
- if (idx >= req.Length)
- throw new ApplicationException ("What do you want?");
-
- string page_protocol = req.Substring(idx);
- int idx2 = page_protocol.IndexOf(' ');
- if (idx2 == -1)
- idx2 = page_protocol.Length;
-
- _filePath = page_protocol.Substring(0, idx2).Trim();
- _protocol = page_protocol.Substring(idx2).Trim();
- }
-
- private void GetRequestHeaders()
- {
- String line;
- int idx;
-
- _headers = new Hashtable();
-
- while ((line = _input.ReadLine ()) != "")
- {
- if (line == null)
- {
- break;
- }
-
- idx = line.IndexOf (':');
- if (idx == -1 || idx == line.Length - 1)
- {
- Logger.WriteEntry("Malformed header line: " + line, LogLevel.Information);
- continue;
- }
-
- String key = line.Substring (0, idx);
- String value = line.Substring (idx + 1);
-
- try
- {
- _headers.Add(key, value);
- }
- catch (Exception)
- {
- Logger.WriteEntry("Duplicate header key in line: " + line, LogLevel.Information);
- }
- }
- }
-
- ///
- /// Format the object contents into a useful string representation.
- ///
- ///String representation of the SimpleHttpRequest as the HttpMethod FilePath Protocol.
- override public String ToString()
- {
- return HttpMethod + " " + FilePath + " " + Protocol;
- }
-
- ///
- /// Close the SimpleHttpRequest. This flushes and closes all associated io streams.
- ///
- public void Close()
- {
- _output.Flush();
- _output.Close();
- _input.Close();
- _client.Close();
- }
- }
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcBoxcarRequest.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcBoxcarRequest.cs
index f87f7a50..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcBoxcarRequest.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcBoxcarRequest.cs
@@ -1,51 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Collections;
- using System.IO;
- using System.Xml;
- using System.Net;
- using System.Text;
- using System.Reflection;
-
- /// Class that collects individual XmlRpcRequest objects and submits them as a boxcarred request.
- /// A boxcared request is when a number of request are collected before being sent via XML-RPC, and then are sent via
- /// a single HTTP connection. This results in a speed up from reduced connection time. The results are then retuned collectively
- /// as well.
- ///
- ///
- public class XmlRpcBoxcarRequest : XmlRpcRequest
- {
- /// ArrayList to collect the requests to boxcar.
- public IList Requests = new ArrayList();
-
- /// Basic constructor.
- public XmlRpcBoxcarRequest()
- {
- }
-
- /// Returns the String "system.multiCall" which is the server method that handles boxcars.
- public override String MethodName
- {
- get { return "system.multiCall"; }
- }
-
- /// The ArrayList of boxcarred Requests as properly formed parameters.
- public override IList Params
- {
- get {
- _params.Clear();
- ArrayList reqArray = new ArrayList();
- foreach (XmlRpcRequest request in Requests)
- {
- Hashtable requestEntry = new Hashtable();
- requestEntry.Add(XmlRpcXmlTokens.METHOD_NAME, request.MethodName);
- requestEntry.Add(XmlRpcXmlTokens.PARAMS, request.Params);
- reqArray.Add(requestEntry);
- }
- _params.Add(reqArray);
- return _params;
- }
- }
- }
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcClientProxy.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcClientProxy.cs
index f52273a7..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcClientProxy.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcClientProxy.cs
@@ -1,61 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Runtime.Remoting.Proxies;
- using System.Runtime.Remoting.Messaging;
-
- /// This class provides support for creating local proxies of XML-RPC remote objects
- ///
- /// To create a local proxy you need to create a local C# interface and then, via createProxy
- /// associate that interface with a remote object at a given URL.
- ///
-public class XmlRpcClientProxy : RealProxy
-{
- private String _remoteObjectName;
- private String _url;
- private XmlRpcRequest _client = new XmlRpcRequest();
-
- /// Factory method to create proxies.
- ///
- /// To create a local proxy you need to create a local C# interface with methods that mirror those of the server object.
- /// Next, pass that interface into createProxy along with the object name and URL of the remote object and
- /// cast the resulting object to the specifice interface.
- ///
- /// String The name of the remote object.
- /// String The URL of the remote object.
- /// Type The typeof() of a C# interface.
- /// Object A proxy for your specified interface. Cast to appropriate type.
- public static Object createProxy(String remoteObjectName, String url, Type anInterface)
- {
- return new XmlRpcClientProxy(remoteObjectName, url, anInterface).GetTransparentProxy();
- }
-
- private XmlRpcClientProxy(String remoteObjectName, String url, Type t) : base(t)
- {
- _remoteObjectName = remoteObjectName;
- _url = url;
- }
-
- /// The local method dispatcher - do not invoke.
- override public IMessage Invoke(IMessage msg)
- {
- IMethodCallMessage methodMessage = (IMethodCallMessage)msg;
-
- _client.MethodName = _remoteObjectName + "." + methodMessage.MethodName;
- _client.Params.Clear();
- foreach (Object o in methodMessage.Args)
- _client.Params.Add(o);
-
- try
- {
- Object ret = _client.Invoke(_url);
- return new ReturnMessage(ret,null,0,
- methodMessage.LogicalCallContext, methodMessage);
- }
- catch (Exception e)
- {
- return new ReturnMessage(e, methodMessage);
- }
- }
-}
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcDeserializer.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcDeserializer.cs
index 36a398c1..7af124f3 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcDeserializer.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcDeserializer.cs
@@ -31,7 +31,6 @@ namespace Nwc.XmlRpc
/// Protected reference to last name field.
protected String _name;
-
/// Basic constructor.
public XmlRpcDeserializer()
{
@@ -175,20 +174,6 @@ namespace Nwc.XmlRpc
_container = null;
_containerStack = new Stack();
}
-
-#if __MONO__
- private DateTime DateParse(String str)
- {
- int year = Int32.Parse(str.Substring(0,4));
- int month = Int32.Parse(str.Substring(4,2));
- int day = Int32.Parse(str.Substring(6,2));
- int hour = Int32.Parse(str.Substring(9,2));
- int min = Int32.Parse(str.Substring(12,2));
- int sec = Int32.Parse(str.Substring(15,2));
- return new DateTime(year,month,day,hour,min,sec);
- }
-#endif
-
}
}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs
index 29f2dceb..01a0ad97 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcErrorCodes.cs
@@ -5,40 +5,6 @@ namespace Nwc.XmlRpc
/// Standard XML-RPC error codes.
public class XmlRpcErrorCodes
{
- ///
- public const int PARSE_ERROR_MALFORMED = -32700;
- ///
- public const String PARSE_ERROR_MALFORMED_MSG = "Parse Error, not well formed";
-
- ///
- public const int PARSE_ERROR_ENCODING = -32701;
- ///
- public const String PARSE_ERROR_ENCODING_MSG = "Parse Error, unsupported encoding";
-
- /**
- -32702 ---> parse error. invalid character for encoding
- -32600 ---> server error. invalid xml-rpc. not conforming to spec.
- **/
-
- ///
- public const int SERVER_ERROR_METHOD = -32601;
- ///
- public const String SERVER_ERROR_METHOD_MSG = "Server Error, requested method not found";
-
- ///
- public const int SERVER_ERROR_PARAMS = -32602;
- ///
- public const String SERVER_ERROR_PARAMS_MSG = "Server Error, invalid method parameters";
-
- /**
- -32603 ---> server error. internal xml-rpc error
- **/
-
- ///
- public const int APPLICATION_ERROR = -32500;
- ///
- public const String APPLICATION_ERROR_MSG = "Application Error";
-
/**
-32400 ---> system error
**/
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcExposedAttribute.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcExposedAttribute.cs
index c10edceb..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcExposedAttribute.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcExposedAttribute.cs
@@ -1,60 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Reflection;
-
- ///
- /// Simple tagging attribute to indicate participation is XML-RPC exposure.
- ///
- ///
- /// If present at the class level it indicates that this class does explicitly
- /// expose methods. If present at the method level it denotes that the method
- /// is exposed.
- ///
- [AttributeUsage(
- AttributeTargets.Class | AttributeTargets.Method,
- AllowMultiple=false,
- Inherited=true
- )]
- public class XmlRpcExposedAttribute : Attribute
- {
- /// Check if obj is an object utilizing the XML-RPC exposed Attribute.
- /// Object of a class or method to check for attribute.
- /// Boolean true if attribute present.
- public static Boolean ExposedObject(Object obj)
- {
- return IsExposed(obj.GetType());
- }
-
- /// Check if obj.methodName is an XML-RPC exposed method.
- /// A method is considered to be exposed if it exists and, either, the object does not use the XmlRpcExposed attribute,
- /// or the object does use the XmlRpcExposed attribute and the method has the XmlRpcExposed attribute as well.
- /// Boolean true if the method is exposed.
- public static Boolean ExposedMethod(Object obj, String methodName)
- {
- Type type = obj.GetType();
- MethodInfo method = type.GetMethod(methodName);
-
- if (method == null)
- throw new MissingMethodException("Method " + methodName + " not found.");
-
- if (!IsExposed(type))
- return true;
-
- return IsExposed(method);
- }
-
- /// Check if mi is XML-RPC exposed.
- /// MemberInfo of a class or method to check for attribute.
- /// Boolean true if attribute present.
- public static Boolean IsExposed(MemberInfo mi)
- {
- foreach (Attribute attr in mi.GetCustomAttributes(true))
- {
- if (attr is XmlRpcExposedAttribute)
- return true;
- }
- return false;
- }
- }
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcRequest.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcRequest.cs
index 35109196..9d306bd4 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcRequest.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcRequest.cs
@@ -40,16 +40,6 @@ namespace Nwc.XmlRpc
_params = new ArrayList();
}
- /// Instantiate an XmlRpcRequest for a specified method and parameters.
- /// String designating the object.method on the server the request
- /// should be directed to.
- /// ArrayList of XML-RPC type parameters to invoke the request with.
- public XmlRpcRequest(String methodName, IList parameters)
- {
- MethodName = methodName;
- _params = parameters;
- }
-
/// ArrayList conntaining the parameters for the request.
public virtual IList Params
{
@@ -63,46 +53,6 @@ namespace Nwc.XmlRpc
set { _methodName = value; }
}
- /// String object name portion of the method name.
- public String MethodNameObject
- {
- get {
- int index = MethodName.IndexOf(".");
-
- if (index == -1)
- return MethodName;
-
- return MethodName.Substring(0,index);
- }
- }
-
- /// String method name portion of the object.method name.
- public String MethodNameMethod
- {
- get {
- int index = MethodName.IndexOf(".");
-
- if (index == -1)
- return MethodName;
-
- return MethodName.Substring(index + 1, MethodName.Length - index - 1);
- }
- }
-
- /// Invoke this request on the server.
- /// String The url of the XML-RPC server.
- /// Object The value returned from the method invocation on the server.
- /// If an exception generated on the server side.
- public Object Invoke(String url)
- {
- XmlRpcResponse res = Send(url);
-
- if (res.IsFault)
- throw new XmlRpcException(res.FaultCode, res.FaultString);
-
- return res.Value;
- }
-
/// Send the request to the server.
/// String The url of the XML-RPC server.
/// XmlRpcResponse The response generated.
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcRequestSerializer.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcRequestSerializer.cs
index 200493a7..c232caf1 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcRequestSerializer.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcRequestSerializer.cs
@@ -11,19 +11,6 @@ namespace Nwc.XmlRpc
///
public class XmlRpcRequestSerializer : XmlRpcSerializer
{
- static private XmlRpcRequestSerializer _singleton;
- /// A static singleton instance of this deserializer.
- static public XmlRpcRequestSerializer Singleton
- {
- get
- {
- if (_singleton == null)
- _singleton = new XmlRpcRequestSerializer();
-
- return _singleton;
- }
- }
-
/// Serialize the XmlRpcRequest to the output stream.
/// An XmlTextWriter stream to write data to.
/// An XmlRpcRequest to serialize.
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcResponder.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcResponder.cs
index 736bd2de..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcResponder.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcResponder.cs
@@ -1,98 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Xml;
- using System.Net.Sockets;
-
- /// 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
- /// side dialog. Namely they manage an inbound deserializer and an outbound serializer.
- public class XmlRpcResponder
- {
- private XmlRpcRequestDeserializer _deserializer = new XmlRpcRequestDeserializer();
- private XmlRpcResponseSerializer _serializer = new XmlRpcResponseSerializer();
- private XmlRpcServer _server;
- private TcpClient _client;
- private SimpleHttpRequest _httpReq;
-
- /// The SimpleHttpRequest based on the TcpClient.
- public SimpleHttpRequest HttpReq
- {
- get { return _httpReq; }
- }
-
- /// Basic constructor.
- /// XmlRpcServer that this XmlRpcResponder services.
- /// TcpClient with the connection.
- public XmlRpcResponder(XmlRpcServer server, TcpClient client)
- {
- _server = server;
- _client = client;
- _httpReq = new SimpleHttpRequest(_client);
- }
-
- /// Call close to insure proper shutdown.
- ~XmlRpcResponder()
- {
- Close();
- }
-
- ///Respond using this responders HttpReq.
- public void Respond()
- {
- Respond(HttpReq);
- }
-
- /// Handle an HTTP request containing an XML-RPC request.
- /// This method deserializes the XML-RPC request, invokes the
- /// described method, serializes the response (or fault) and sends the XML-RPC response
- /// back as a valid HTTP page.
- ///
- /// SimpleHttpRequest containing the request.
- public void Respond(SimpleHttpRequest httpReq)
- {
- XmlRpcRequest xmlRpcReq = (XmlRpcRequest)_deserializer.Deserialize(httpReq.Input);
- XmlRpcResponse xmlRpcResp = new XmlRpcResponse();
-
- try
- {
- xmlRpcResp.Value = _server.Invoke(xmlRpcReq);
- }
- catch (XmlRpcException e)
- {
- xmlRpcResp.SetFault(e.FaultCode, e.FaultString);
- }
- catch (Exception e2)
- {
- xmlRpcResp.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
- XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
- }
-
- if (Logger.Delegate != null)
- Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
-
- 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();
- httpReq.Output.Flush();
- }
-
- ///Close all contained resources, both the HttpReq and client.
- public void Close()
- {
- if (_httpReq != null)
- {
- _httpReq.Close();
- _httpReq = null;
- }
-
- if (_client != null)
- {
- _client.Close();
- _client = null;
- }
- }
- }
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcResponse.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcResponse.cs
index d0a14026..6484268d 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcResponse.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcResponse.cs
@@ -19,14 +19,6 @@ namespace Nwc.XmlRpc
IsFault = false;
}
- /// Constructor for a fault.
- /// int the numeric faultCode value.
- /// String the faultString value.
- public XmlRpcResponse(int code, String message) : this()
- {
- SetFault(code,message);
- }
-
/// The data value of the response, may be fault data.
public Object Value
{
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcResponseDeserializer.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcResponseDeserializer.cs
index eb17f0d7..a94388a4 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcResponseDeserializer.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcResponseDeserializer.cs
@@ -8,20 +8,6 @@ namespace Nwc.XmlRpc
/// Class to deserialize XML data representing a response.
public class XmlRpcResponseDeserializer : XmlRpcDeserializer
{
- static private XmlRpcResponseDeserializer _singleton;
- /// A static singleton instance of this deserializer.
- [Obsolete("This object is now thread safe, just use an instance.",false)]
- static public XmlRpcResponseDeserializer Singleton
- {
- get
- {
- if (_singleton == null)
- _singleton = new XmlRpcResponseDeserializer();
-
- return _singleton;
- }
- }
-
/// Static method that parses XML data into a response using the Singleton.
/// StreamReader containing an XML-RPC response.
/// XmlRpcResponse object resulting from the parse.
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcServer.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcServer.cs
index 0ceef7b4..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcServer.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcServer.cs
@@ -1,236 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Collections;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Xml;
-
- /// A restricted HTTP server for use with XML-RPC.
- /// It only handles POST requests, and only POSTs representing XML-RPC calls.
- /// In addition to dispatching requests it also provides a registry for request handlers.
- ///
-public class XmlRpcServer : IEnumerable
- {
- const int RESPONDER_COUNT = 10;
- private TcpListener _myListener;
- private int _port;
- private IPAddress _address;
- private IDictionary _handlers;
- private XmlRpcSystemObject _system;
- private WaitCallback _wc;
-
- ///Constructor with port and address.
- ///This constructor sets up a TcpListener listening on the
- ///given port and address. It also calls a Thread on the method StartListen().
- ///IPAddress value of the address to listen on.
- ///Int value of the port to listen on.
- public XmlRpcServer(IPAddress address, int port)
- {
- _port = port;
- _address = address;
- _handlers = new Hashtable();
- _system = new XmlRpcSystemObject(this);
- _wc = new WaitCallback(WaitCallback);
- }
-
- ///Basic constructor.
- ///This constructor sets up a TcpListener listening on the
- ///given port. It also calls a Thread on the method StartListen(). IPAddress.Any
- ///is assumed as the address here.
- ///Int value of the port to listen on.
- public XmlRpcServer(int port) : this(IPAddress.Any, port) {}
-
- /// Start the server.
- public void Start()
- {
- try
- {
- Stop();
- //start listing on the given port
- // IPAddress addr = IPAddress.Parse("127.0.0.1");
- lock (this)
- {
- _myListener = new TcpListener(_port);
- _myListener.Start();
- //start the thread which calls the method 'StartListen'
- Thread th = new Thread(new ThreadStart(StartListen));
- th.Start();
- }
- }
- catch(Exception e)
- {
- Logger.WriteEntry("An Exception Occurred while Listening :" +e.ToString(), LogLevel.Error);
- }
- }
-
- /// Stop the server.
- public void Stop()
- {
- try
- {
- if (_myListener != null)
- {
- lock (this)
- {
- _myListener.Stop();
- _myListener = null;
- }
- }
- } catch(Exception e)
- {
- Logger.WriteEntry("An Exception Occurred while stopping :" +
- e.ToString(), LogLevel.Error);
- }
- }
-
- /// Get an enumeration of my XML-RPC handlers.
- /// IEnumerable the handler enumeration.
- public IEnumerator GetEnumerator()
- {
- return _handlers.GetEnumerator();
- }
-
- /// Retrieve a handler by name.
- /// String naming a handler
- /// Object that is the handler.
- public Object this [String name]
- {
- get { return _handlers[name]; }
- }
-
- ///
- ///This method Accepts new connections and dispatches them when appropriate.
- ///
- public void StartListen()
- {
- while(true && _myListener != null)
- {
- //Accept a new connection
- XmlRpcResponder responder = new XmlRpcResponder(this, _myListener.AcceptTcpClient());
- ThreadPool.QueueUserWorkItem(_wc,responder);
- }
- }
-
-
- ///
- ///Add an XML-RPC handler object by name.
- ///
- ///String XML-RPC dispatch name of this object.
- ///Object The object that is the XML-RPC handler.
- public void Add(String name, Object obj)
- {
- _handlers.Add(name,obj);
- }
-
- ///Return a C# object.method name for and XML-RPC object.method name pair.
- ///The XML-RPC object.method.
- ///String of form object.method for the underlying C# method.
- public String MethodName(String methodName)
- {
- int dotAt = methodName.LastIndexOf('.');
-
- if (dotAt == -1)
- {
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Bad method name " + methodName);
- }
-
- String objectName = methodName.Substring(0,dotAt);
- Object target = _handlers[objectName];
-
- if (target == null)
- {
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Object " + objectName + " not found");
- }
-
- return target.GetType().FullName + "." + methodName.Substring(dotAt + 1);
- }
-
- ///Invoke a method described in a request.
- ///XmlRpcRequest containing a method descriptions.
- ///
- ///
- public Object Invoke(XmlRpcRequest req)
- {
- return Invoke(req.MethodNameObject, req.MethodNameMethod, req.Params);
- }
-
- ///Invoke a method on a named handler.
- ///String The name of the handler.
- ///String The name of the method to invoke on the handler.
- ///IList The parameters to invoke the method with.
- ///
- public Object Invoke(String objectName, String methodName, IList parameters)
- {
- Object target = _handlers[objectName];
-
- if (target == null)
- {
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Object " + objectName + " not found");
- }
-
- return XmlRpcSystemObject.Invoke(target, methodName, parameters);
- }
-
- /// The method the thread pool invokes when a thread is available to handle an HTTP request.
- /// TcpClient from the socket accept.
- public void WaitCallback(object responder)
- {
- XmlRpcResponder resp = (XmlRpcResponder)responder;
-
- if (resp.HttpReq.HttpMethod == "POST")
- {
- try
- {
- resp.Respond();
- }
- catch (Exception e)
- {
- Logger.WriteEntry("Failed on post: " + e, LogLevel.Error);
- }
- }
- else
- {
- Logger.WriteEntry("Only POST methods are supported: " + resp.HttpReq.HttpMethod +
- " ignored", LogLevel.Error);
- }
-
- resp.Close();
- }
-
- ///
- /// This function send the Header Information to the client (Browser)
- ///
- /// HTTP Version
- /// Mime Type
- /// Total Bytes to be sent in the body
- ///
- /// Socket reference
- static public void HttpHeader(string sHttpVersion, string sMIMEHeader, long iTotBytes, string sStatusCode, TextWriter output)
- {
- String sBuffer = "";
-
- // if Mime type is not provided set default to text/html
- if (sMIMEHeader.Length == 0 )
- {
- sMIMEHeader = "text/html"; // Default Mime Type is text/html
- }
-
- sBuffer += sHttpVersion + sStatusCode + "\r\n";
- sBuffer += "Connection: close\r\n";
- if (iTotBytes > 0)
- sBuffer += "Content-Length: " + iTotBytes + "\r\n";
- sBuffer += "Server: XmlRpcServer \r\n";
- sBuffer += "Content-Type: " + sMIMEHeader + "\r\n";
- sBuffer += "\r\n";
-
- output.Write(sBuffer);
- }
- }
-}
diff --git a/libsecondlife-cs/XmlRpcCS/XmlRpcSystemObject.cs b/libsecondlife-cs/XmlRpcCS/XmlRpcSystemObject.cs
index f6cf0957..e69de29b 100644
--- a/libsecondlife-cs/XmlRpcCS/XmlRpcSystemObject.cs
+++ b/libsecondlife-cs/XmlRpcCS/XmlRpcSystemObject.cs
@@ -1,251 +0,0 @@
-namespace Nwc.XmlRpc
-{
- using System;
- using System.Collections;
- using System.Reflection;
-
- /// XML-RPC System object implementation of extended specifications.
- [XmlRpcExposed]
- public class XmlRpcSystemObject
- {
- private XmlRpcServer _server;
- static private IDictionary _methodHelp = new Hashtable();
-
- /// Static IDictionary to hold mappings of method name to associated documentation String
- static public IDictionary MethodHelp {
- get { return _methodHelp; }
- }
-
- /// Constructor.
- /// XmlRpcServer server to be the system object for.
- public XmlRpcSystemObject(XmlRpcServer server)
- {
- _server = server;
- server.Add("system",this);
- _methodHelp.Add(this.GetType().FullName + ".methodHelp", "Return a string description.");
- }
-
- /// Invoke a method on a given object.
- /// Using reflection, and respecting the XmlRpcExposed attribute,
- /// invoke the methodName method on the target
- /// instance with the parameters provided. All this packages other Invoke methods
- /// end up calling this.
- /// Object the value the invoked method returns.
- /// If method does not exist, is not exposed, parameters invalid, or invocation
- /// results in an exception. Note, the XmlRpcException.Code will indicate cause.
- static public Object Invoke(Object target, String methodName, IList parameters)
- {
- if (target == null)
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Invalid target object.");
-
- Type type = target.GetType();
- MethodInfo method = type.GetMethod(methodName);
-
- try
- {
- if (!XmlRpcExposedAttribute.ExposedMethod(target,methodName))
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Method " + methodName + " is not exposed.");
- }
- catch (MissingMethodException me)
- {
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
- XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": " + me.Message);
- }
-
- Object[] args = new Object[parameters.Count];
-
- int index = 0;
- foreach (Object arg in parameters)
- {
- args[index] = arg;
- index++;
- }
-
- try
- {
- Object retValue = method.Invoke(target, args);
- if (retValue == null)
- throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR,
- XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": Method returned NULL.");
- return retValue;
- }
- catch (XmlRpcException e)
- {
- throw e;
- }
- catch (ArgumentException ae)
- {
- Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + ae.Message,
- LogLevel.Information);
- String call = methodName + "( ";
- foreach (Object o in args)
- {
- call += o.GetType().Name;
- call += " ";
- }
- call += ")";
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS,
- XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement type mismatch invoking " + call);
- }
- catch (TargetParameterCountException tpce)
- {
- Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + tpce.Message,
- LogLevel.Information);
- throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS,
- XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement count mismatch invoking " + methodName);
- }
- catch (TargetInvocationException tie)
- {
- throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR,
- XmlRpcErrorCodes.APPLICATION_ERROR_MSG + " Invoked method " + methodName + ": " + tie.Message);
- }
- }
-
- /// List methods available on all handlers of this server.
- /// IList An array of Strings, each String will have form "object.method".
- [XmlRpcExposed]
- public IList listMethods()
- {
- IList methods = new ArrayList();
- Boolean considerExposure;
-
- foreach (DictionaryEntry handlerEntry in _server)
- {
- considerExposure = XmlRpcExposedAttribute.IsExposed(handlerEntry.Value.GetType());
-
- foreach (MemberInfo mi in handlerEntry.Value.GetType().GetMembers())
- {
- if (mi.MemberType != MemberTypes.Method)
- continue;
-
- if(!((MethodInfo)mi).IsPublic)
- continue;
-
- if (considerExposure && !XmlRpcExposedAttribute.IsExposed(mi))
- continue;
-
- methods.Add(handlerEntry.Key + "." + mi.Name);
- }
- }
-
- return methods;
- }
-
- /// Given a method name return the possible signatures for it.
- /// String The object.method name to look up.
- /// IList Of arrays of signatures.
- [XmlRpcExposed]
- public IList methodSignature(String name)
- {
- IList signatures = new ArrayList();
- int index = name.IndexOf('.');
-
- if (index < 0)
- return signatures;
-
- String oName = name.Substring(0,index);
- Object obj = _server[oName];
-
- if (obj == null)
- return signatures;
-
- MemberInfo[] mi = obj.GetType().GetMember(name.Substring(index + 1));
-
- if (mi == null || mi.Length != 1) // for now we want a single signature
- return signatures;
-
- MethodInfo method;
-
- try
- {
- method = (MethodInfo)mi[0];
- }
- catch (Exception e)
- {
- Logger.WriteEntry("Attempted methodSignature call on " + mi[0] + " caused: " + e,
- LogLevel.Information);
- return signatures;
- }
-
- if (!method.IsPublic)
- return signatures;
-
- IList signature = new ArrayList();
- signature.Add(method.ReturnType.Name);
-
- foreach (ParameterInfo param in method.GetParameters())
- {
- signature.Add(param.ParameterType.Name);
- }
-
-
- signatures.Add(signature);
-
- return signatures;
- }
-
- /// Help for given method signature. Not implemented yet.
- /// String The object.method name to look up.
- /// String help text. Rich HTML text.
- [XmlRpcExposed]
- public String methodHelp(String name)
- {
- String help = null;
-
- try
- {
- help = (String)_methodHelp[_server.MethodName(name)];
- }
- catch (XmlRpcException e)
- {
- throw e;
- }
- catch (Exception) { /* ignored */ };
-
- if (help == null)
- help = "No help available for: " + name;
-
- return help;
- }
-
- /// Boxcarring support method.
- /// IList of calls
- /// ArrayList of results/faults.
- [XmlRpcExposed]
- public IList multiCall(IList calls)
- {
- IList responses = new ArrayList();
- XmlRpcResponse fault = new XmlRpcResponse();
-
- foreach (IDictionary call in calls)
- {
- try
- {
- XmlRpcRequest req = new XmlRpcRequest((String)call[XmlRpcXmlTokens.METHOD_NAME],
- (ArrayList)call[XmlRpcXmlTokens.PARAMS]);
- Object results = _server.Invoke(req);
- IList response = new ArrayList();
- response.Add(results);
- responses.Add(response);
- }
- catch (XmlRpcException e)
- {
- fault.SetFault(e.FaultCode, e.FaultString);
- responses.Add(fault.Value);
- }
- catch (Exception e2)
- {
- fault.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
- XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
- responses.Add(fault.Value);
- }
- }
-
- return responses;
- }
-
- }
-}
-