InternalSetName() private method

private InternalSetName ( string value ) : bool
value string
return bool
Example #1
0
        // twin parsing method, different enough that it's better to split it into
        // a different method
        internal Cookie GetServer() {

            Cookie cookie = m_savedCookie;
            m_savedCookie = null;

            // only first ocurence of an attribute value must be counted
            bool   domainSet = false;
            bool   pathSet = false;
            bool   portSet = false; //special case as it may have no value in header

            do {
                bool first = cookie==null || cookie.Name==null || cookie.Name.Length==0;
                CookieToken token = m_tokenizer.Next(first, false);

                if (first && (token==CookieToken.NameValuePair || token==CookieToken.Attribute)) {
                    if (cookie==null) {
                        cookie = new Cookie();
                    }
                    if (cookie.InternalSetName(m_tokenizer.Name) == false) {
                        //will be rejected
                        cookie.InternalSetName(string.Empty);
                    }
                    cookie.Value = m_tokenizer.Value;
                }
                else {
                    switch (token) {
                    case CookieToken.NameValuePair:
                        switch (m_tokenizer.Token) {
                            case CookieToken.Domain:
                                if (!domainSet) {
                                    domainSet = true;
                                    cookie.Domain = CheckQuoted(m_tokenizer.Value);
                                    cookie.IsQuotedDomain = m_tokenizer.Quoted;
                                }
                                break;

                            case CookieToken.Path:
                                if (!pathSet) {
                                    pathSet = true;
                                    cookie.Path = m_tokenizer.Value;
                                }
                                break;

                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    try {
                                        cookie.Port = m_tokenizer.Value;
                                    }
                                    catch (CookieException) {
                                        //this cookie will be rejected
                                        cookie.InternalSetName(string.Empty);
                                    }
                                }
                                break;

                            case CookieToken.Version:
                                // this is a new cookie, this token is for the next cookie.
                                m_savedCookie = new Cookie();
                                int parsed;
                                if (int.TryParse(m_tokenizer.Value, out parsed)) {
                                    m_savedCookie.Version = parsed;
                                }
                                return cookie;

                            case CookieToken.Unknown:
                                // this is a new cookie, the token is for the next cookie.
                                m_savedCookie = new Cookie();
                                if (m_savedCookie.InternalSetName(m_tokenizer.Name) == false) {
                                    //will be rejected
                                    m_savedCookie.InternalSetName(string.Empty);
                                }
                                m_savedCookie.Value = m_tokenizer.Value;
                                return cookie;

                        }
                        break;

                    case CookieToken.Attribute:
                        switch (m_tokenizer.Token) {
                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    cookie.Port  = string.Empty;
                                }
                                break;
                        }
                        break;
                    }
                }
            } while (!m_tokenizer.Eof && !m_tokenizer.EndOfCookie);
            return cookie;
        }
Example #2
0
    // properties

    // methods

        //
        // Get
        //
        //  Gets the next cookie
        //
        // Inputs:
        //  Nothing
        //
        // Outputs:
        //  Nothing
        //
        // Assumes:
        //  Nothing
        //
        // Returns:
        //  new cookie object, or null if there's no more
        //
        // Throws:
        //  Nothing
        //

        internal Cookie Get() {

            Cookie cookie = null;

            // only first ocurence of an attribute value must be counted
            bool   commentSet = false;
            bool   commentUriSet = false;
            bool   domainSet = false;
            bool   expiresSet = false;
            bool   pathSet = false;
            bool   portSet = false; //special case as it may have no value in header
            bool   versionSet = false;
            bool   secureSet = false;
            bool   discardSet = false;

            do {
                CookieToken token = m_tokenizer.Next(cookie==null, true);
                if (cookie==null && (token==CookieToken.NameValuePair || token==CookieToken.Attribute)) {
                    cookie = new Cookie();
                    if (cookie.InternalSetName(m_tokenizer.Name) == false) {
                        //will be rejected
                        cookie.InternalSetName(string.Empty);
                    }
                    cookie.Value = m_tokenizer.Value;
                }
                else {
                    switch (token) {
                    case CookieToken.NameValuePair:
                        switch (m_tokenizer.Token) {
                            case CookieToken.Comment:
                                if (!commentSet) {
                                    commentSet = true;
                                    cookie.Comment = m_tokenizer.Value;
                                }
                                break;

                            case CookieToken.CommentUrl:
                                if (!commentUriSet) {
                                    commentUriSet = true;
                                    Uri parsed;
                                    if (Uri.TryCreate(CheckQuoted(m_tokenizer.Value), UriKind.Absolute, out parsed)) {
                                        cookie.CommentUri = parsed;
                                    }
                                }
                                break;

                            case CookieToken.Domain:
                                if (!domainSet) {
                                    domainSet = true;
                                    cookie.Domain = CheckQuoted(m_tokenizer.Value);
                                    cookie.IsQuotedDomain = m_tokenizer.Quoted;
                                }
                                break;

                            case CookieToken.Expires:
                                if (!expiresSet) {
                                    expiresSet = true;

                                    DateTime expires;
                                    if (DateTime.TryParse(CheckQuoted(m_tokenizer.Value), 
                                        CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out expires)) {
                                        cookie.Expires = expires;
                                    }
                                    else {
                                        //this cookie will be rejected
                                        cookie.InternalSetName(string.Empty);
                                    }
                                }
                                break;

                            case CookieToken.MaxAge:
                                if (!expiresSet) {
                                    expiresSet = true;
                                    int parsed;
                                    if (int.TryParse(CheckQuoted(m_tokenizer.Value), out parsed)) {
                                        cookie.Expires = DateTime.Now.AddSeconds((double)parsed);
                                    }
                                    else {
                                        //this cookie will be rejected
                                        cookie.InternalSetName(string.Empty);
                                    }
                                }
                                break;

                            case CookieToken.Path:
                                if (!pathSet) {
                                    pathSet = true;
                                    cookie.Path = m_tokenizer.Value;
                                }
                                break;

                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    try {
                                        cookie.Port = m_tokenizer.Value;
                                    }
                                    catch {
                                        //this cookie will be rejected
                                        cookie.InternalSetName(string.Empty);
                                    }
                                }
                                break;

                            case CookieToken.Version:
                                if (!versionSet) {
                                    versionSet = true;
                                    int parsed;
                                    if (int.TryParse(CheckQuoted(m_tokenizer.Value), out parsed)) {
                                        cookie.Version = parsed;
                                        cookie.IsQuotedVersion = m_tokenizer.Quoted;
                                    }
                                    else {
                                        //this cookie will be rejected
                                        cookie.InternalSetName(string.Empty);
                                    }
                                }
                                break;
                        }
                        break;

                    case CookieToken.Attribute:
                        switch (m_tokenizer.Token) {
                            case CookieToken.Discard:
                                if (!discardSet) {
                                    discardSet = true;
                                    cookie.Discard = true;
                                }
                                break;

                            case CookieToken.Secure:
                                if (!secureSet) {
                                    secureSet = true;
                                    cookie.Secure = true;
                                }
                                break;

                            case CookieToken.HttpOnly:
                                cookie.HttpOnly = true;
                                break;

                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    cookie.Port  = string.Empty;
                                }
                                break;
                        }
                        break;
                    }
                }
            } while (!m_tokenizer.Eof && !m_tokenizer.EndOfCookie);
            return cookie;
        }
Example #3
0
    // properties

    // methods

        //
        // Get
        //
        //  Gets the next cookie
        //
        // Inputs:
        //  Nothing
        //
        // Outputs:
        //  Nothing
        //
        // Assumes:
        //  Nothing
        //
        // Returns:
        //  new cookie object, or null if there's no more
        //
        // Throws:
        //  Nothing
        //

        internal Cookie Get() {

            Cookie cookie = null;

            //only first ocurence of an attribute value must be counted
            bool   commentSet = false;
            bool   commentUriSet = false;
            bool   domainSet = false;
            bool   expiresSet = false;
            bool   pathSet = false;
            bool   portSet = false; //special case as it may have no value in header
            bool   versionSet = false;
            bool   secureSet = false;
            bool   discardSet = false;

            do {
                CookieToken token = m_tokenizer.Next(cookie == null);

                if (((token == CookieToken.NameValuePair) || (token == CookieToken.Attribute)) && (cookie == null)) {
                   cookie = new Cookie();
                   if (cookie.InternalSetName(m_tokenizer.Name) == false) {
                       cookie.InternalSetName(string.Empty);    //will be rejected
                   }
                   cookie.Value= m_tokenizer.Value;
                }
                else switch (token) {
                    case CookieToken.NameValuePair:

                        switch (m_tokenizer.Token) {
                            case CookieToken.Comment:
                                if (!commentSet) {
                                    commentSet = true;
                                    cookie.Comment = m_tokenizer.Value;
                                }
                                break;

                            case CookieToken.CommentUrl:
                                if (!commentUriSet) {
                                    commentUriSet = true;
                                    try {
                                        cookie.CommentUri = new Uri(CheckQuoted(m_tokenizer.Value));
                                    }
                                    catch {
                                            //ignore this kind of problem
                                    }
                                }
                                break;

                            case CookieToken.Domain:
                                if (!domainSet) {
                                    domainSet = true;
                                    cookie.Domain = CheckQuoted(m_tokenizer.Value);
                                    cookie.IsQuotedDomain = m_tokenizer.Quoted;
                                }
                                break;

                            case CookieToken.Expires:
                                if (!expiresSet) {
                                    expiresSet = true;
                                    // ParseCookieDate() does many formats for the date.
                                    // Also note that the parser will eat day of the week 
                                    // plus comma and leading spaces
                                    DateTime expires;
                                    if (HttpDateParse.ParseCookieDate(CheckQuoted(m_tokenizer.Value), out expires)) {
                                        cookie.Expires = expires;
                                    }
                                    else {
                                        cookie.InternalSetName(string.Empty); //this cookie will be rejected
                                    }
                                }
                                break;

                            case CookieToken.MaxAge:
                                if (!expiresSet) {
                                    expiresSet = true;
                                    try {
                                        cookie.Expires = DateTime.Now.AddSeconds((Double)(Int32.Parse(CheckQuoted(m_tokenizer.Value))));

                                    }
                                    catch {
                                        cookie.InternalSetName(string.Empty); //this cookie will be rejected
                                    }
                                }
                                break;

                            case CookieToken.Path:
                                if (!pathSet) {
                                    pathSet = true;
                                    cookie.Path = m_tokenizer.Value;
                                }
                                break;

                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    try {
                                        cookie.Port = m_tokenizer.Value;
                                    }
                                    catch {
                                        cookie.InternalSetName(string.Empty); //this cookie will be rejected
                                    }
                                }
                                break;

                            case CookieToken.Version:
                                if (!versionSet) {
                                    versionSet = true;
                                    try {
                                        cookie.Version = Int32.Parse(CheckQuoted(m_tokenizer.Value));
                                        cookie.IsQuotedVersion = m_tokenizer.Quoted;
                                    }
                                    catch {
                                        cookie.InternalSetName(string.Empty); //this cookie will be rejected
                                    }
                                }
                                break;
                        }
                        break;

                    case CookieToken.Attribute:
                        switch (m_tokenizer.Token) {
                            case CookieToken.Discard:
                                if (!discardSet) {
                                    discardSet = true;
                                    cookie.Discard = true;
                                }
                                break;

                            case CookieToken.Secure:
                                if (!secureSet) {
                                    secureSet = true;
                                    cookie.Secure = true;
                                }
                                break;

                            case CookieToken.Port:
                                if (!portSet) {
                                    portSet = true;
                                    cookie.Port  = string.Empty;
                                }
                                break;
                        }
                        break;
                }
            } while (!m_tokenizer.Eof && !m_tokenizer.EndOfCookie);
            return cookie;
        }
Example #4
0
 private static bool InternalSetNameMethod(Cookie cookie, string value)
 {
     return(cookie.InternalSetName(value));
 }
        internal Cookie Get()
        {
            Cookie cookie = null;
            bool   flag   = false;
            bool   flag2  = false;
            bool   flag3  = false;
            bool   flag4  = false;
            bool   flag5  = false;
            bool   flag6  = false;
            bool   flag7  = false;
            bool   flag8  = false;
            bool   flag9  = false;

            do
            {
                CookieToken token = this.m_tokenizer.Next(cookie == null, true);
                if ((cookie == null) && ((token == CookieToken.NameValuePair) || (token == CookieToken.Attribute)))
                {
                    cookie = new Cookie();
                    if (!cookie.InternalSetName(this.m_tokenizer.Name))
                    {
                        cookie.InternalSetName(string.Empty);
                    }
                    cookie.Value = this.m_tokenizer.Value;
                }
                else
                {
                    switch (token)
                    {
                    case CookieToken.NameValuePair:
                        switch (this.m_tokenizer.Token)
                        {
                        case CookieToken.Comment:
                            if (!flag)
                            {
                                flag           = true;
                                cookie.Comment = this.m_tokenizer.Value;
                            }
                            break;

                        case CookieToken.CommentUrl:
                            if (!flag2)
                            {
                                Uri uri;
                                flag2 = true;
                                if (Uri.TryCreate(CheckQuoted(this.m_tokenizer.Value), UriKind.Absolute, out uri))
                                {
                                    cookie.CommentUri = uri;
                                }
                            }
                            break;

                        case CookieToken.Domain:
                            if (!flag3)
                            {
                                flag3                 = true;
                                cookie.Domain         = CheckQuoted(this.m_tokenizer.Value);
                                cookie.IsQuotedDomain = this.m_tokenizer.Quoted;
                            }
                            break;

                        case CookieToken.Expires:
                            if (!flag4)
                            {
                                DateTime time;
                                flag4 = true;
                                if (DateTime.TryParse(CheckQuoted(this.m_tokenizer.Value), out time))
                                {
                                    cookie.Expires = time;
                                }
                                else
                                {
                                    cookie.InternalSetName(string.Empty);
                                }
                            }
                            break;

                        case CookieToken.MaxAge:
                            if (!flag4)
                            {
                                int num;
                                flag4 = true;
                                if (int.TryParse(CheckQuoted(this.m_tokenizer.Value), out num))
                                {
                                    cookie.Expires = DateTime.Now.AddSeconds((double)num);
                                }
                                else
                                {
                                    cookie.InternalSetName(string.Empty);
                                }
                            }
                            break;

                        case CookieToken.Path:
                            if (!flag5)
                            {
                                flag5       = true;
                                cookie.Path = this.m_tokenizer.Value;
                            }
                            break;

                        case CookieToken.Port:
                            if (!flag6)
                            {
                                flag6 = true;
                                try
                                {
                                    cookie.Port = this.m_tokenizer.Value;
                                }
                                catch
                                {
                                    cookie.InternalSetName(string.Empty);
                                }
                            }
                            break;

                        case CookieToken.Version:
                            if (!flag7)
                            {
                                int num2;
                                flag7 = true;
                                if (int.TryParse(CheckQuoted(this.m_tokenizer.Value), out num2))
                                {
                                    cookie.Version         = num2;
                                    cookie.IsQuotedVersion = this.m_tokenizer.Quoted;
                                }
                                else
                                {
                                    cookie.InternalSetName(string.Empty);
                                }
                            }
                            break;
                        }
                        break;

                    case CookieToken.Attribute:
                        switch (this.m_tokenizer.Token)
                        {
                        case CookieToken.Port:
                            if (!flag6)
                            {
                                flag6       = true;
                                cookie.Port = string.Empty;
                            }
                            break;

                        case CookieToken.Secure:
                            if (!flag8)
                            {
                                flag8         = true;
                                cookie.Secure = true;
                            }
                            break;

                        case CookieToken.HttpOnly:
                            cookie.HttpOnly = true;
                            break;

                        case CookieToken.Discard:
                            if (!flag9)
                            {
                                flag9          = true;
                                cookie.Discard = true;
                            }
                            break;
                        }
                        break;
                    }
                }
            }while (!this.m_tokenizer.Eof && !this.m_tokenizer.EndOfCookie);
            return(cookie);
        }