Esempio n. 1
0
        private void ConvertHtml(XDocument doc, AsyncArgs args)
        {
            string fap = string.Empty;
            if (args.Settings.FormActionPattern != string.Empty)
            {
                fap = "//form[@" + args.Settings.FormActionPattern + "]";
            }
            else
            {
                fap = "//form[@action=\"" + args.Settings.RefererUrlPart + "\"]";
            }
            XElement formNode = new XPath(fap, true).GetElement(doc);
            if (formNode != null)
            {
                XElement[] inputNodes = XPath.GetElements("//input", formNode);
                foreach (XElement inp in inputNodes)
                {
                    XAttribute nameAtt = inp.Attribute(XName.Get("name"));
                    if (nameAtt != null)
                    {
                        string value = string.Empty;
                        XAttribute valueAtt = inp.Attribute(XName.Get("value"));
                        if (valueAtt != null && valueAtt.Value != string.Empty)
                        {
                            value = valueAtt.Value;
                        }

                        if (nameAtt.Value.Contains("challenge"))
                        {
                            args.IsLoginChallenge = true;
                        }

                        if (nameAtt.Value.Contains("crumb"))
                        {
                            args.Settings.Account.SetCrumb(valueAtt.Value);
                        }
                        else
                        {
                            if (args.Settings.SearchForWebForms != null)
                            {
                                foreach (string name in args.Settings.SearchForWebForms)
                                {
                                    if (name == nameAtt.Value)
                                    {
                                        if (args.Settings.AdditionalWebForms != null && args.Settings.AdditionalWebForms.Count > 0)
                                        {
                                            for (int i = 0; i < args.Settings.AdditionalWebForms.Count; i++)
                                            {
                                                if (args.Settings.AdditionalWebForms[i].Key == nameAtt.Value)
                                                {
                                                    args.Settings.AdditionalWebForms[i] = new KeyValuePair<string, string>(nameAtt.Value, valueAtt.Value);
                                                    break;
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void SetToken(string[] tokenValues)
        {
            if (tokenValues == null || tokenValues.Length == 0)
            {
                throw new ArgumentException();
            }


            mValue = tokenValues[0];
            if (mValue.StartsWith("/"))
            {
                mValue         = mValue.Substring(1);
                mCheckChildren = true;
            }


            if (mValue != string.Empty)
            {
                bool isInQuote          = false;
                bool isInNodeName       = true;
                bool isInAttributeName  = false;
                bool isInAttributeValue = false;
                for (int i = 0; i < mValue.Length; i++)
                {
                    if (mValue[i] == '\"')
                    {
                        isInQuote = !isInQuote; continue;
                    }

                    if (!isInQuote)
                    {
                        switch (mValue[i])
                        {
                        case '[':
                            isInNodeName      = false;
                            isInAttributeName = true;
                            break;

                        case ']':
                            isInAttributeName  = false;
                            isInAttributeValue = false;
                            if (mExtensionType != TokenExtensionType.AttributeID)
                            {
                                if (int.TryParse(mAttributeTag, out mIndex))
                                {
                                    mExtensionType = TokenExtensionType.Index;
                                }
                                mAttributeTag = string.Empty;
                            }
                            break;

                        case '@':
                            mExtensionType = TokenExtensionType.AttributeID;
                            break;

                        case '=':
                            if (isInAttributeName)
                            {
                                isInAttributeName  = false;
                                isInAttributeValue = true;
                            }
                            break;

                        default:
                            if (isInNodeName)
                            {
                                mName += mValue[i];
                            }
                            else if (isInAttributeName)
                            {
                                mAttributeTag += mValue[i];
                            }
                            break;
                        }
                    }
                    else if (isInAttributeValue)
                    {
                        mAttributeValue += mValue[i];
                    }
                }
            }


            if (tokenValues.Length > 1)
            {
                string[] newVals = new string[tokenValues.Length - 1];
                for (int i = 1; i < tokenValues.Length; i++)
                {
                    newVals[i - 1] = tokenValues[i];
                }
                mChild = new XPath(newVals);
            }
        }
Esempio n. 3
0
        private void SetToken(string[] tokenValues)
        {
            if (tokenValues == null || tokenValues.Length == 0) throw new ArgumentException();


            mValue = tokenValues[0];
            if (mValue.StartsWith("/"))
            {
                mValue = mValue.Substring(1);
                mCheckChildren = true;
            }


            if (mValue != string.Empty)
            {
                bool isInQuote = false;
                bool isInNodeName = true;
                bool isInAttributeName = false;
                bool isInAttributeValue = false;
                for (int i = 0; i < mValue.Length; i++)
                {
                    if (mValue[i] == '\"') { isInQuote = !isInQuote; continue; }

                    if (!isInQuote)
                    {
                        switch (mValue[i])
                        {
                            case '[':
                                isInNodeName = false;
                                isInAttributeName = true;
                                break;
                            case ']':
                                isInAttributeName = false;
                                isInAttributeValue = false;
                                if (mExtensionType != TokenExtensionType.AttributeID)
                                {
                                    if (int.TryParse(mAttributeTag, out mIndex))
                                    {
                                        mExtensionType = TokenExtensionType.Index;
                                    }
                                    mAttributeTag = string.Empty;
                                }
                                break;
                            case '@':
                                mExtensionType = TokenExtensionType.AttributeID;
                                break;
                            case '=':
                                if (isInAttributeName)
                                {
                                    isInAttributeName = false;
                                    isInAttributeValue = true;
                                }
                                break;
                            default:
                                if (isInNodeName) { mName += mValue[i]; }
                                else if (isInAttributeName) { mAttributeTag += mValue[i]; }
                                break;
                        }
                    }
                    else if (isInAttributeValue)
                    {
                        mAttributeValue += mValue[i];
                    }
                }
            }


            if (tokenValues.Length > 1)
            {
                string[] newVals = new string[tokenValues.Length - 1];
                for (int i = 1; i < tokenValues.Length; i++)
                {
                    newVals[i - 1] = tokenValues[i];
                }
                mChild = new XPath(newVals);
            }
        }
Esempio n. 4
0
        private XElement[] GetElements(XContainer container, bool returnFirstResult, bool isRootSeek = false)
        {
            List <XElement> matchNodes = new List <XElement>();


            if (this.IsRootPath)
            {
                if (container is XElement && ((XElement)container).Name.LocalName == mChild.mName)
                {
                    if (mChild.mExtensionType == TokenExtensionType.None)
                    {
                        matchNodes.Add((XElement)container);
                    }
                    else if (mChild.mExtensionType == TokenExtensionType.AttributeID)
                    {
                        XAttribute att = ((XElement)container).Attribute(XName.Get(mChild.mAttributeTag));
                        if (att != null && this.StringValuesEquals(mChild.mAttributeValue, att.Value))
                        {
                            matchNodes.Add((XElement)container);
                        }
                    }
                }

                if (!(returnFirstResult && matchNodes.Count > 0))
                {
                    foreach (XElement elem in container.Elements())
                    {
                        matchNodes.AddRange(this.GetElements(elem, returnFirstResult, true));
                        if (returnFirstResult && matchNodes.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                int cnt = 0;
                foreach (XElement elem in container.Elements())
                {
                    if (elem.Name.LocalName == mName)
                    {
                        cnt++;
                        switch (mExtensionType)
                        {
                        case TokenExtensionType.None:
                            matchNodes.Add(elem);
                            break;

                        case TokenExtensionType.Index:
                            if (cnt == mIndex)
                            {
                                matchNodes.Add(elem);
                            }
                            break;

                        case TokenExtensionType.AttributeID:
                            XAttribute att = elem.Attribute(XName.Get(mAttributeTag));
                            if (att != null && this.StringValuesEquals(mAttributeValue, att.Value))
                            {
                                matchNodes.Add(elem);
                            }
                            break;
                        }
                        if (returnFirstResult && matchNodes.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }



            List <XElement> results = new List <XElement>();

            XPath child = mChild;

            if (this.IsRootPath)
            {
                child = child.Child;
            }
            if (!isRootSeek && child != null)
            {
                foreach (XElement match in matchNodes)
                {
                    results.AddRange(child.GetElements(match, returnFirstResult));
                    if (returnFirstResult && results.Count > 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                results.AddRange(matchNodes);
            }

            return(results.ToArray());
        }