/// Extract all GET and POST variables into internal storage.
        public void ExtractAllVars()
        {
            var vars = this.GetVars(INPUT_GET);

            this.Vars = this.Vars.Merge(vars);
            this.ExtractPostVars();
        }
Beispiel #2
0
        /// <summary>
        /// Merge hash tables.
        /// </summary>
        /// <param name="extra">Hash table to merge with original one.</param>
        /// <returns>Merged hash table.</returns>
        public THashtable Merge(THashtable extra)
        {
            if (extra == null)
            {
                return(this);
            }

            var output = Create();

            TEnumerator keys1 = new TEnumerator(this.Keys.GetEnumerator());

            while (keys1.MoveNext())
            {
                String key1 = (String)keys1.GetCurrent();
                output[key1] = this[key1];
            }

            TEnumerator keys2 = new TEnumerator(extra.Keys.GetEnumerator());

            while (keys2.MoveNext())
            {
                String key2 = (String)keys2.GetCurrent();
                output[key2] = extra[key2];
            }
            return(output);
        }
        /// <summary>
        /// Test (match) a page request with array of allowed pages.
        /// </summary>
        /// <param name="pages">Array of allowed pages (and their parameters).</param>
        /// <param name="defaultPage">Default page to use for testing.</param>
        /// <returns>Resulting page parameters.</returns>
        public THashtable TestPage(Object[] pages, String defaultPage)
        {
            var pageInfo = new THashtable();

            // Get page name
            var page = (String)null;

            pageInfo["from_get"]  = 0;
            pageInfo["from_post"] = 0;

            var apiValue = this.GetVar(INPUT_GET, "api");

            if (apiValue != null)
            {
                if (EQ(apiValue, "rest")) // Only Rest for now
                {
                    pageInfo["api"] = apiValue;
                }
            }

            var pValue = this.GetVar(INPUT_GET, "p");

            if (pValue != null)
            {
                page = pValue;
                pageInfo["from_get"] = 1;
            }
            pValue = this.GetVar(INPUT_POST, "p");
            if (pValue != null)
            {
                page = pValue;
                pageInfo["from_post"] = 1;
            }
            if (page == null)
            {
                page = defaultPage;
            }

            pageInfo.Remove("page");
            for (int n = 0; n < SIZE(pages); n += 4)
            {
                if (EQ(pages[n], page))
                {
                    pageInfo["page"]          = pages[n + 0];
                    pageInfo["class"]         = pages[n + 1];
                    pageInfo["post_required"] = pages[n + 2];
                    pageInfo["code_required"] = pages[n + 3];
                    break;
                }
            }
            return(pageInfo);
        }
Beispiel #4
0
        /// <summary>
        /// Replace "keys by values" in a string.
        /// </summary>
        /// <param name="template">Input template.</param>
        /// <param name="hash">Set of key/value pairs.</param>
        /// <returns>Resulting string.</returns>
        public static String ReplaceInTemplate(String template, THashtable hash)
        {
            var keys = new TEnumerator(hash.Keys.GetEnumerator());

            while (keys.MoveNext())
            {
                var key = STR(keys.GetCurrent());
                if (template.IndexOf(key) != -1)
                {
                    template = template.Replace(key, STR(hash[key]));
                }
            }
            return(template);
        }
Beispiel #5
0
        /// <summary>
        /// Get all variables of given type.
        /// </summary>
        /// <param name="type">Required type.</param>
        /// <returns>Requested variables.</returns>
        public THashtable GetVars(int type)
        {
            THashtable hash = new THashtable();
            IEnumerator <KeyValuePair <string, Microsoft.Extensions.Primitives.StringValues> > vars = null;

            switch (type)
            {
            case TRequest.INPUT_GET:
            default:
                if (HttpRequest.Method != "GET")
                {
                    return(hash);
                }
                vars = HttpRequest.Query.GetEnumerator();
                break;

            case TRequest.INPUT_POST:
                if (HttpRequest.Method != "POST")
                {
                    return(hash);
                }
                vars = HttpRequest.Form.GetEnumerator();
                break;

            case TRequest.INPUT_SERVER:
                vars = HttpRequest.Headers.GetEnumerator();
                hash.Add("QUERY_STRING", HttpRequest.QueryString);
                break;
            }
            while (vars.MoveNext())
            {
                String   key    = vars.Current.Key;
                String[] values = vars.Current.Value;
                if (key == null)
                {
                    for (int v = 0; v < values.Length; v++)
                    {
                        hash.Add(values[v], null);
                    }
                }
                else
                {
                    hash.Add(key, values[0]);
                }
            }
            return(hash);
        }
 /// Initialize internal variables for new request.
 private void Initialize()
 {
     this.Vars       = THashtable.Create();
     this.ServerVars = THashtable.Create();
 }
        /// Extract all SERVER variables into internal storage.
        public void ExtractServerVars()
        {
            var vars = this.GetVars(INPUT_SERVER);

            this.Vars = this.ServerVars.Merge(vars);
        }
        /// Extract all POST variables into internal variables.
        public void ExtractPostVars()
        {
            var vars = this.GetVars(INPUT_POST);

            this.Vars = this.Vars.Merge(vars);
        }