missing file and remove dead code

master
UbitUmarov 2020-02-08 16:27:30 +00:00
parent 68e7e65e2e
commit 8cbe743440
3 changed files with 20 additions and 267 deletions

View File

@ -45,7 +45,6 @@ namespace OpenSim.Framework
Material = -2
}
#region SL / file extension / content-type conversions
/// <summary>
@ -334,262 +333,6 @@ namespace OpenSim.Framework
#endregion SL / file extension / content-type conversions
private class NotecardReader
{
private string rawInput;
private int lineNumber;
public int LineNumber
{
get
{
return lineNumber;
}
}
public NotecardReader(string _rawInput)
{
rawInput = (string)_rawInput.Clone();
lineNumber = 0;
}
public string getLine()
{
if(rawInput.Length == 0)
{
throw new NotANotecardFormatException(lineNumber + 1);
}
int pos = rawInput.IndexOf('\n');
if(pos < 0)
{
pos = rawInput.Length;
}
/* cut line from rest */
++lineNumber;
string line = rawInput.Substring(0, pos);
if (pos + 1 >= rawInput.Length)
{
rawInput = string.Empty;
}
else
{
rawInput = rawInput.Substring(pos + 1);
}
/* clean up line from double spaces and tabs */
line = line.Replace("\t", " ");
while(line.IndexOf(" ") >= 0)
{
line = line.Replace(" ", " ");
}
return line.Replace("\r", "").Trim();
}
public string getBlock(int length)
{
/* cut line from rest */
if(length > rawInput.Length)
{
throw new NotANotecardFormatException(lineNumber);
}
string line = rawInput.Substring(0, length);
rawInput = rawInput.Substring(length);
return line;
}
}
public class NotANotecardFormatException : Exception
{
public int lineNumber;
public NotANotecardFormatException(int _lineNumber)
: base()
{
lineNumber = _lineNumber;
}
}
private static void skipSection(NotecardReader reader)
{
if (reader.getLine() != "{")
throw new NotANotecardFormatException(reader.LineNumber);
string line;
while ((line = reader.getLine()) != "}")
{
if(line.IndexOf('{')>=0)
{
throw new NotANotecardFormatException(reader.LineNumber);
}
}
}
private static void skipInventoryItem(NotecardReader reader)
{
if (reader.getLine() != "{")
throw new NotANotecardFormatException(reader.LineNumber);
string line;
while((line = reader.getLine()) != "}")
{
string[] data = line.Split(' ');
if(data.Length == 0)
{
continue;
}
if(data[0] == "permissions")
{
skipSection(reader);
}
else if(data[0] == "sale_info")
{
skipSection(reader);
}
else if (line.IndexOf('{') >= 0)
{
throw new NotANotecardFormatException(reader.LineNumber);
}
}
}
private static void skipInventoryItems(NotecardReader reader)
{
if(reader.getLine() != "{")
{
throw new NotANotecardFormatException(reader.LineNumber);
}
string line;
while((line = reader.getLine()) != "}")
{
string[] data = line.Split(' ');
if(data.Length == 0)
{
continue;
}
if(data[0] == "inv_item")
{
skipInventoryItem(reader);
}
else if (line.IndexOf('{') >= 0)
{
throw new NotANotecardFormatException(reader.LineNumber);
}
}
}
private static void skipInventory(NotecardReader reader)
{
if (reader.getLine() != "{")
throw new NotANotecardFormatException(reader.LineNumber);
string line;
while((line = reader.getLine()) != "}")
{
string[] data = line.Split(' ');
if(data[0] == "count")
{
int count = Int32.Parse(data[1]);
for(int i = 0; i < count; ++i)
{
skipInventoryItems(reader);
}
}
else if (line.IndexOf('{') >= 0)
{
throw new NotANotecardFormatException(reader.LineNumber);
}
}
}
private static string readNotecardText(NotecardReader reader)
{
if (reader.getLine() != "{")
throw new NotANotecardFormatException(reader.LineNumber);
string notecardString = string.Empty;
string line;
while((line = reader.getLine()) != "}")
{
string[] data = line.Split(' ');
if (data.Length == 0)
{
continue;
}
if (data[0] == "LLEmbeddedItems")
{
skipInventory(reader);
}
else if(data[0] == "Text" && data.Length == 3)
{
int length = Int32.Parse(data[2]);
notecardString = reader.getBlock(length);
}
else if (line.IndexOf('{') >= 0)
{
throw new NotANotecardFormatException(reader.LineNumber);
}
}
return notecardString;
}
private static string readNotecard(byte[] rawInput)
{
string rawIntermedInput = string.Empty;
/* make up a Raw Encoding here */
foreach(byte c in rawInput)
{
char d = (char)c;
rawIntermedInput += d;
}
NotecardReader reader = new NotecardReader(rawIntermedInput);
string line;
try
{
line = reader.getLine();
}
catch(Exception)
{
return System.Text.Encoding.UTF8.GetString(rawInput);
}
string[] versioninfo = line.Split(' ');
if(versioninfo.Length < 3)
{
return System.Text.Encoding.UTF8.GetString(rawInput);
}
else if(versioninfo[0] != "Linden" || versioninfo[1] != "text")
{
return System.Text.Encoding.UTF8.GetString(rawInput);
}
else
{
/* now we actually decode the Encoding, before we needed it in raw */
string o = readNotecardText(reader);
byte[] a = new byte[o.Length];
for(int i = 0; i < o.Length; ++i)
{
a[i] = (byte)o[i];
}
return System.Text.Encoding.UTF8.GetString(a);
}
}
/// <summary>
/// Parse a notecard in Linden format to a string of ordinary text.
/// </summary>
/// <param name="rawInput"></param>
/// <returns></returns>
public static string ParseNotecardToString(byte[] rawInput)
{
return readNotecard(rawInput);
}
static char[] seps = new char[] { '\t', '\n' };
static char[] stringseps = new char[] { '|', '\n' };

View File

@ -732,14 +732,19 @@ namespace OpenSim.Framework
return false;
}
public static List<UUID> GetUUIDsOnString(ref string s, int indx)
public static List<UUID> GetUUIDsOnString(ref string s, int indx, int len)
{
var ids = new List<UUID>();
if (s.Length < 36)
int endA = indx + len;
if(endA > s.Length)
endA = s.Length;
if (endA - indx < 36)
return ids;
int endA = s.Length - 35;
int endB = s.Length - 26;
int endB = endA - 26;
endA -= 35;
int idbase;
int next;
int retry;

View File

@ -595,15 +595,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
try
{
string jsondata = SLUtil.ParseNotecardToString(a.Data);
int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0;
int result;
string[] data = SLUtil.ParseNotecardToArray(a.Data);
if(data.Length == 0)
result = m_store.SetValue(storeID, path, string.Empty, true) ? 1 : 0;
else
{
StringBuilder sb = new StringBuilder(256);
for(int i = 0; i < data.Length; ++i)
sb.AppendLine(data[i]);
result = m_store.SetValue(storeID, path, sb.ToString(),true) ? 1 : 0;
}
m_comms.DispatchReply(scriptID, result, "", reqID.ToString());
return;
}
catch(SLUtil.NotANotecardFormatException e)
{
m_log.WarnFormat("[JsonStoreScripts]: Notecard parsing failed; assetId {0} at line number {1}", assetID.ToString(), e.lineNumber);
}
catch (Exception e)
{
m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);