diff options
author | Sunil Kumar <sunilk@mono-cvs.ximian.com> | 2003-12-10 14:12:29 +0300 |
---|---|---|
committer | Sunil Kumar <sunilk@mono-cvs.ximian.com> | 2003-12-10 14:12:29 +0300 |
commit | 36ae36620d0ed4f6e28b6ba51a58facc9dca45f3 (patch) | |
tree | 1f30be5e79b7feb8b344b488d5e838e4aefc22aa /mcs/class/Novell.Directory.Ldap | |
parent | 4dfed54d4fb10dde0b344d55acbeae6e973a8aca (diff) |
Added for schema support
svn path=/trunk/mcs/; revision=20955
Diffstat (limited to 'mcs/class/Novell.Directory.Ldap')
4 files changed, 1315 insertions, 0 deletions
diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/CharacterTypes.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/CharacterTypes.cs new file mode 100755 index 00000000000..e7d2c71a2eb --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/CharacterTypes.cs @@ -0,0 +1,53 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc., www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.Utilclass.CharacterTypes.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; + +namespace Novell.Directory.Ldap.Utilclass +{ + + /// <summary> + /// Specifies the types of Characters. + /// </summary> +// [Flags] + [Serializable] + [CLSCompliantAttribute(false)] + public enum CharacterTypes:sbyte + { + WHITESPACE = 1, + NUMERIC = 2, + ALPHABETIC = 4, + STRINGQUOTE = 8, + COMMENTCHAR = 16 + } + +} + diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaParser.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaParser.cs new file mode 100755 index 00000000000..99b2a8abecf --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaParser.cs @@ -0,0 +1,682 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapAttributeSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using LdapObjectClassSchema = Novell.Directory.Ldap.LdapObjectClassSchema; +using LdapAttributeSchema = Novell.Directory.Ldap.LdapAttributeSchema; + +namespace Novell.Directory.Ldap.Utilclass +{ + + public class SchemaParser + { + private void InitBlock() + { + usage = LdapAttributeSchema.USER_APPLICATIONS; + qualifiers = new System.Collections.ArrayList(); + } + virtual public System.String RawString + { + get + { + return rawString; + } + + set + { + this.rawString = value; + } + + } + virtual public System.String[] Names + { + get + { + return names; + } + + } + virtual public System.Collections.IEnumerator Qualifiers + { + get + { + return new ArrayEnumeration(qualifiers.ToArray()); + } + + } + virtual public System.String ID + { + get + { + return id; + } + + } + virtual public System.String Description + { + get + { + return description; + } + + } + virtual public System.String Syntax + { + get + { + return syntax; + } + + } + virtual public System.String Superior + { + get + { + return superior; + } + + } + virtual public bool Single + { + get + { + return single; + } + + } + virtual public bool Obsolete + { + get + { + return obsolete; + } + + } + virtual public System.String Equality + { + get + { + return equality; + } + + } + virtual public System.String Ordering + { + get + { + return ordering; + } + + } + virtual public System.String Substring + { + get + { + return substring; + } + + } + virtual public bool Collective + { + get + { + return collective; + } + + } + virtual public bool UserMod + { + get + { + return userMod; + } + + } + virtual public int Usage + { + get + { + return usage; + } + + } + virtual public int Type + { + get + { + return type; + } + + } + virtual public System.String[] Superiors + { + get + { + return superiors; + } + + } + virtual public System.String[] Required + { + get + { + return required; + } + + } + virtual public System.String[] Optional + { + get + { + return optional; + } + + } + virtual public System.String[] Auxiliary + { + get + { + return auxiliary; + } + + } + virtual public System.String[] Precluded + { + get + { + return precluded; + } + + } + virtual public System.String[] Applies + { + get + { + return applies; + } + + } + virtual public System.String NameForm + { + get + { + return nameForm; + } + + } + virtual public System.String ObjectClass + { + get + { + return nameForm; + } + + } + + internal System.String rawString; + internal System.String[] names = null; + internal System.String id; + internal System.String description; + internal System.String syntax; + internal System.String superior; + internal System.String nameForm; + internal System.String objectClass; + internal System.String[] superiors; + internal System.String[] required; + internal System.String[] optional; + internal System.String[] auxiliary; + internal System.String[] precluded; + internal System.String[] applies; + internal bool single = false; + internal bool obsolete = false; + internal System.String equality; + internal System.String ordering; + internal System.String substring; + internal bool collective = false; + internal bool userMod = true; + internal int usage; + internal int type = - 1; + internal int result; + internal System.Collections.ArrayList qualifiers; + + public SchemaParser(System.String aString) + { + InitBlock(); + + int index; + + if ((index = aString.IndexOf((System.Char) '\\')) != - 1) + { + /* + * Unless we escape the slash, StreamTokenizer will interpret the + * single slash and convert it assuming octal values. + * Two successive back slashes are intrepreted as one backslash. + */ + System.Text.StringBuilder newString = new System.Text.StringBuilder(aString.Substring(0, (index) - (0))); + for (int i = index; i < aString.Length; i++) + { + newString.Append(aString[i]); + if (aString[i] == '\\') + { + newString.Append('\\'); + } + } + rawString = newString.ToString(); + } + else + { + rawString = aString; + } + + SchemaTokenCreator st2 = new SchemaTokenCreator(new System.IO.StringReader(rawString)); + st2.OrdinaryCharacter('.'); + st2.OrdinaryCharacters('0', '9'); + st2.OrdinaryCharacter('{'); + st2.OrdinaryCharacter('}'); + st2.OrdinaryCharacter('_'); + st2.OrdinaryCharacter(';'); + st2.WordCharacters('.', '9'); + st2.WordCharacters('{', '}'); + st2.WordCharacters('_', '_'); + st2.WordCharacters(';', ';'); + //First parse out the OID + try + { + System.String currName; + if ((int)TokenTypes.EOF != st2.nextToken()) + { + if (st2.lastttype == '(') + { + if ((int)TokenTypes.WORD == st2.nextToken()) + { + id = st2.StringValue; + } + while ((int)TokenTypes.EOF != st2.nextToken()) + { + if (st2.lastttype == (int)TokenTypes.WORD) + { + if (st2.StringValue.ToUpper().Equals("NAME".ToUpper())) + { + if (st2.nextToken() == '\'') + { + names = new System.String[1]; + names[0] = st2.StringValue; + } + else + { + if (st2.lastttype == '(') + { + System.Collections.ArrayList nameList = new System.Collections.ArrayList(); + while (st2.nextToken() == '\'') + { + if ((System.Object) st2.StringValue != null) + { + nameList.Add(st2.StringValue); + } + } + if (nameList.Count > 0) + { + names = new System.String[nameList.Count]; + SupportClass.ArrayListSupport.ToArray(nameList, names); + } + } + } + continue; + } + if (st2.StringValue.ToUpper().Equals("DESC".ToUpper())) + { + if (st2.nextToken() == '\'') + { + description = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("SYNTAX".ToUpper())) + { + result = st2.nextToken(); + if ((result == (int)TokenTypes.WORD) || (result == '\'')) + //Test for non-standard schema + { + syntax = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("EQUALITY".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + equality = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("ORDERING".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + ordering = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("SUBSTR".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + substring = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("FORM".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + nameForm = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("OC".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + objectClass = st2.StringValue; + } + continue; + } + if (st2.StringValue.ToUpper().Equals("SUP".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + superior = st2.StringValue; + } + if (values.Count > 0) + { + superiors = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, superiors); + } + continue; + } + if (st2.StringValue.ToUpper().Equals("SINGLE-VALUE".ToUpper())) + { + single = true; + continue; + } + if (st2.StringValue.ToUpper().Equals("OBSOLETE".ToUpper())) + { + obsolete = true; + continue; + } + if (st2.StringValue.ToUpper().Equals("COLLECTIVE".ToUpper())) + { + collective = true; + continue; + } + if (st2.StringValue.ToUpper().Equals("NO-USER-MODIFICATION".ToUpper())) + { + userMod = false; + continue; + } + if (st2.StringValue.ToUpper().Equals("MUST".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + } + if (values.Count > 0) + { + required = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, required); + } + continue; + } + if (st2.StringValue.ToUpper().Equals("MAY".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + } + if (values.Count > 0) + { + optional = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, optional); + } + continue; + } + + if (st2.StringValue.ToUpper().Equals("NOT".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + } + if (values.Count > 0) + { + precluded = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, precluded); + } + continue; + } + if (st2.StringValue.ToUpper().Equals("AUX".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + } + if (values.Count > 0) + { + auxiliary = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, auxiliary); + } + continue; + } + if (st2.StringValue.ToUpper().Equals("ABSTRACT".ToUpper())) + { + type = LdapObjectClassSchema.ABSTRACT; + continue; + } + if (st2.StringValue.ToUpper().Equals("STRUCTURAL".ToUpper())) + { + type = LdapObjectClassSchema.STRUCTURAL; + continue; + } + if (st2.StringValue.ToUpper().Equals("AUXILIARY".ToUpper())) + { + type = LdapObjectClassSchema.AUXILIARY; + continue; + } + if (st2.StringValue.ToUpper().Equals("USAGE".ToUpper())) + { + if (st2.nextToken() == (int)TokenTypes.WORD) + { + currName = st2.StringValue; + if (currName.ToUpper().Equals("directoryOperation".ToUpper())) + { + usage = LdapAttributeSchema.DIRECTORY_OPERATION; + } + else if (currName.ToUpper().Equals("distributedOperation".ToUpper())) + { + usage = LdapAttributeSchema.DISTRIBUTED_OPERATION; + } + else if (currName.ToUpper().Equals("dSAOperation".ToUpper())) + { + usage = LdapAttributeSchema.DSA_OPERATION; + } + else if (currName.ToUpper().Equals("userApplications".ToUpper())) + { + usage = LdapAttributeSchema.USER_APPLICATIONS; + } + } + continue; + } + if (st2.StringValue.ToUpper().Equals("APPLIES".ToUpper())) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(); + st2.nextToken(); + if (st2.lastttype == '(') + { + st2.nextToken(); + while (st2.lastttype != ')') + { + if (st2.lastttype != '$') + { + values.Add(st2.StringValue); + } + st2.nextToken(); + } + } + else + { + values.Add(st2.StringValue); + } + if (values.Count > 0) + { + applies = new System.String[values.Count]; + SupportClass.ArrayListSupport.ToArray(values, applies); + } + continue; + } + currName = st2.StringValue; + AttributeQualifier q = parseQualifier(st2, currName); + if (q != null) + { + qualifiers.Add(q); + } + continue; + } + } + } + } + } + catch (System.IO.IOException e) + { + throw e; + } + } + + private AttributeQualifier parseQualifier(SchemaTokenCreator st, System.String name) + { + System.Collections.ArrayList values = new System.Collections.ArrayList(5); + try + { + if (st.nextToken() == '\'') + { + values.Add(st.StringValue); + } + else + { + if (st.lastttype == '(') + { + while (st.nextToken() == '\'') + { + values.Add(st.StringValue); + } + } + } + } + catch (System.IO.IOException e) + { + throw e; + } + System.String[] valArray = new System.String[values.Count]; + valArray = (System.String[]) SupportClass.ArrayListSupport.ToArray(values, valArray); + return new AttributeQualifier(name, valArray); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaTokenCreator.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaTokenCreator.cs new file mode 100755 index 00000000000..8ba3cd59285 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/SchemaTokenCreator.cs @@ -0,0 +1,528 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.Utilclass.SchemaTokenCreator.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; + +namespace Novell.Directory.Ldap.Utilclass +{ + + public class SchemaTokenCreator + { + private string basestring; + private bool cppcomments=false; // C++ style comments enabled + private bool ccomments=false; // C style comments enabled + private bool iseolsig=false; + private bool cidtolower; + private bool pushedback; + private int peekchar; + private sbyte[] ctype; + private int linenumber=1; + private int ichar=1; + private char[] buf; + + private System.IO.StreamReader reader = null; + private System.IO.StringReader sreader = null; + private System.IO.Stream input = null; + + public System.String StringValue; + public double NumberValue; + public int lastttype; + + private void Initialise() + { + ctype = new sbyte[256]; + buf = new char[20]; + peekchar=System.Int32.MaxValue; + WordCharacters('a', 'z'); + WordCharacters('A', 'Z'); + WordCharacters(128 + 32, 255); + WhitespaceCharacters(0, ' '); + CommentCharacter('/'); + QuoteCharacter('"'); + QuoteCharacter('\''); + parseNumbers(); + } + + public SchemaTokenCreator(System.IO.Stream instream) + { + Initialise(); + if (instream == null) + { + throw new System.NullReferenceException(); + } + input = instream; + } + + public SchemaTokenCreator(System.IO.StreamReader r) + { + Initialise(); + if (r == null) + { + throw new System.NullReferenceException(); + } + reader = r; + } + + public SchemaTokenCreator(System.IO.StringReader r) + { + Initialise(); + if (r == null) + { + throw new System.NullReferenceException(); + } + sreader = r; + } + + public void pushBack() + { + pushedback = true; + } + + public int CurrentLine + { + get + { + return linenumber; + } + } + + public System.String ToStringValue() + { + System.String strval; + switch (lastttype) + { + + case (int)TokenTypes.EOF: + strval = "EOF"; + break; + + case (int) TokenTypes.EOL: + strval = "EOL"; + break; + + case (int) TokenTypes.WORD: + strval = StringValue; + break; + + case (int) TokenTypes.STRING: + strval = StringValue; + break; + + case (int) TokenTypes.NUMBER: + case (int) TokenTypes.REAL: + strval = "n=" + NumberValue; + break; + + default: + { + if (lastttype < 256 && ((ctype[lastttype] & (sbyte)CharacterTypes.STRINGQUOTE) != 0)) + { + strval = StringValue; + break; + } + + char[] s = new char[3]; + s[0] = s[2] = '\''; + s[1] = (char) lastttype; + strval = new System.String(s); + break; + } + + } + return strval; + } + + public void WordCharacters(int min, int max) + { + if (min < 0) + min = 0; + if (max >= ctype.Length) + max = ctype.Length - 1; + while (min <= max) + ctype[min++] |= (sbyte)CharacterTypes.ALPHABETIC; + } + + public void WhitespaceCharacters(int min, int max) + { + if (min < 0) + min = 0; + if (max >= ctype.Length) + max = ctype.Length - 1; + while (min <= max) + ctype[min++] = (sbyte)CharacterTypes.WHITESPACE; + } + + public void OrdinaryCharacters(int min, int max) + { + if (min < 0) + min = 0; + if (max >= ctype.Length) + max = ctype.Length - 1; + while (min <= max) + ctype[min++] = 0; + } + + public void OrdinaryCharacter(int ch) + { + if (ch >= 0 && ch < ctype.Length) + ctype[ch] = 0; + } + + public void CommentCharacter(int ch) + { + if (ch >= 0 && ch < ctype.Length) + ctype[ch] = (sbyte)CharacterTypes.COMMENTCHAR; + } + + public void InitTable() + { + for (int i = ctype.Length; --i >= 0; ) + ctype[i] = 0; + } + + public void QuoteCharacter(int ch) + { + if (ch >= 0 && ch < ctype.Length) + ctype[ch] = (sbyte)CharacterTypes.STRINGQUOTE; + } + + public void parseNumbers() + { + for (int i = '0'; i <= '9'; i++) + ctype[i] |= (sbyte)CharacterTypes.NUMERIC; + ctype['.'] |= (sbyte)CharacterTypes.NUMERIC; + ctype['-'] |= (sbyte)CharacterTypes.NUMERIC; + } + + private int read() + { + if (sreader !=null ) + { + return sreader.Read(); + } + else if (reader != null) + { + return reader.Read(); + } + else if (input != null) + return input.ReadByte(); + else + throw new System.SystemException(); + } + + public int nextToken() + { + if (pushedback) + { + pushedback = false; + return lastttype; + } + + StringValue = null; + + int curc = peekchar; + if (curc < 0) + curc = System.Int32.MaxValue; + if (curc == (System.Int32.MaxValue - 1)) + { + curc = read(); + if (curc < 0) + return lastttype = (int) TokenTypes.EOF; + if (curc == '\n') + curc = System.Int32.MaxValue; + } + if (curc == System.Int32.MaxValue) + { + curc = read(); + if (curc < 0) + return lastttype = (int) TokenTypes.EOF; + } + lastttype = curc; + peekchar = System.Int32.MaxValue; + + int ctype = curc < 256?this.ctype[curc]:(sbyte)CharacterTypes.ALPHABETIC; + while ((ctype & (sbyte)CharacterTypes.WHITESPACE) != 0) + { + if (curc == '\r') + { + linenumber++; + if (iseolsig) + { + peekchar = (System.Int32.MaxValue - 1); + return lastttype = (int) TokenTypes.EOL; + } + curc = read(); + if (curc == '\n') + curc = read(); + } + else + { + if (curc == '\n') + { + linenumber++; + if (iseolsig) + { + return lastttype = (int) TokenTypes.EOL; + } + } + curc = read(); + } + if (curc < 0) + return lastttype = (int) TokenTypes.EOF; + ctype = curc < 256?this.ctype[curc]:(sbyte)CharacterTypes.ALPHABETIC; + } + + if ((ctype & (sbyte)CharacterTypes.NUMERIC) != 0) + { + bool checkb = false; + if (curc == '-') + { + curc = read(); + if (curc != '.' && (curc < '0' || curc > '9')) + { + peekchar = curc; + return lastttype = '-'; + } + checkb = true; + } + double dvar = 0; + int tempvar = 0; + int checkdec = 0; + while (true) + { + if (curc == '.' && checkdec == 0) + checkdec = 1; + else if ('0' <= curc && curc <= '9') + { + dvar = dvar * 10 + (curc - '0'); + tempvar += checkdec; + } + else + break; + curc = read(); + } + peekchar = curc; + if (tempvar != 0) + { + double divby = 10; + tempvar--; + while (tempvar > 0) + { + divby *= 10; + tempvar--; + } + dvar = dvar / divby; + } + NumberValue = checkb?- dvar:dvar; + return lastttype = (int) TokenTypes.NUMBER; + } + + if ((ctype & (sbyte)CharacterTypes.ALPHABETIC) != 0) + { + int i = 0; + do + { + if (i >= buf.Length) + { + char[] nb = new char[buf.Length * 2]; + Array.Copy((System.Array) buf, 0, (System.Array) nb, 0, buf.Length); + buf = nb; + } + buf[i++] = (char) curc; + curc = read(); + ctype = curc < 0?(sbyte)CharacterTypes.WHITESPACE:curc < 256?this.ctype[curc]:(sbyte)CharacterTypes.ALPHABETIC; + } + while ((ctype & ((sbyte)CharacterTypes.ALPHABETIC | (sbyte)CharacterTypes.NUMERIC)) != 0); + peekchar = curc; + StringValue = new String(buf, 0, i); + if (cidtolower) + StringValue = StringValue.ToLower(); + return lastttype = (int) TokenTypes.WORD; + } + + if ((ctype & (sbyte)CharacterTypes.STRINGQUOTE) != 0) + { + lastttype = curc; + int i = 0; + int rc = read(); + while (rc >= 0 && rc != lastttype && rc != '\n' && rc != '\r') + { + if (rc == '\\') + { + curc = read(); + int first = curc; + if (curc >= '0' && curc <= '7') + { + curc = curc - '0'; + int loopchar = read(); + if ('0' <= loopchar && loopchar <= '7') + { + curc = (curc << 3) + (loopchar - '0'); + loopchar = read(); + if ('0' <= loopchar && loopchar <= '7' && first <= '3') + { + curc = (curc << 3) + (loopchar - '0'); + rc = read(); + } + else + rc = loopchar; + } + else + rc = loopchar; + } + else + { + switch (curc) + { + + case 'f': + curc = 0xC; + break; + + case 'a': + curc = 0x7; + break; + + case 'b': + curc = '\b'; + break; + + case 'v': + curc = 0xB; + break; + + case 'n': + curc = '\n'; + break; + + case 'r': + curc = '\r'; + break; + + case 't': + curc = '\t'; + break; + + default: + break; + + } + rc = read(); + } + } + else + { + curc = rc; + rc = read(); + } + if (i >= buf.Length) + { + char[] nb = new char[buf.Length * 2]; + Array.Copy((System.Array) buf, 0, (System.Array) nb, 0, buf.Length); + buf = nb; + } + buf[i++] = (char) curc; + } + + peekchar = (rc == lastttype)?System.Int32.MaxValue:rc; + + StringValue = new String(buf, 0, i); + return lastttype; + } + + if (curc == '/' && (cppcomments || ccomments)) + { + curc = read(); + if (curc == '*' && ccomments) + { + int prevc = 0; + while ((curc = read()) != '/' || prevc != '*') + { + if (curc == '\r') + { + linenumber++; + curc = read(); + if (curc == '\n') + { + curc = read(); + } + } + else + { + if (curc == '\n') + { + linenumber++; + curc = read(); + } + } + if (curc < 0) + return lastttype = (int) TokenTypes.EOF; + prevc = curc; + } + return nextToken(); + } + else if (curc == '/' && cppcomments) + { + while ((curc = read()) != '\n' && curc != '\r' && curc >= 0) + ; + peekchar = curc; + return nextToken(); + } + else + { + if ((this.ctype['/'] & (sbyte)CharacterTypes.COMMENTCHAR) != 0) + { + while ((curc = read()) != '\n' && curc != '\r' && curc >= 0) + ; + peekchar = curc; + return nextToken(); + } + else + { + peekchar = curc; + return lastttype = '/'; + } + } + } + + if ((ctype & (sbyte)CharacterTypes.COMMENTCHAR) != 0) + { + while ((curc = read()) != '\n' && curc != '\r' && curc >= 0) + ; + peekchar = curc; + return nextToken(); + } + + return lastttype = curc; + } + + } +} diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/TokenTypes.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/TokenTypes.cs new file mode 100755 index 00000000000..7ad58b068ff --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Utilclass/TokenTypes.cs @@ -0,0 +1,52 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc., www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.Utilclass.TokenType.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; + +namespace Novell.Directory.Ldap.Utilclass +{ + + /// <summary> + /// Specifies the types of Tokens. + /// </summary> + [Serializable] + public enum TokenTypes + { + EOL = '\n', + EOF = -1, + NUMBER = -2, + WORD = -3, + REAL = -4, + STRING = -5 + } + +} + |