示例#1
0
 bool IEnumerator.MoveNext()
 {
     if (current == null)
     {
         current = first;
     }
     else
     {
         current = current.next;
     }
     return (current != null);
 }
示例#2
0
 void IEnumerator.Reset()
 {
     current = null;
 }
示例#3
0
 internal Enumerator(RoutingElement first)
 {
     this.first = first;
 }
示例#4
0
 /// <summary>
 /// Removes a routing element.
 /// 
 /// Preconditions
 ///   e != null
 ///   "e is in list of routing elements"
 /// </summary>
 /// <param name="e">Routing element to be removed.</param>
 public void Remove(RoutingElement e)
 {
     Contract.Requires(e != null);
     Contract.Requires(first != null);
     if (e == first)
     {
         first = e.next;
     }
     else
     {
         RoutingElement h = first;
         while (h.next != e) { h = h.next; Contract.Requires(h != null); }
         h.next = e.next;
     }
 }
示例#5
0
 /// <summary>
 /// This method adds a new request routing element to the
 /// collection, consisting of a request pattern and a request
 /// handler.
 /// 
 /// Preconditions
 ///     method != null
 ///     method.Length >= 3
 ///     path != null
 ///     path.Length > 0
 ///     path[0] == '/'
 ///     handler != null
 /// </summary>
 /// <param name="method">Method of the request pattern.</param>
 /// <param name="path">Path of the request pattern.</param>
 /// <param name="wildcard">If true, the pattern accepts all URIs starting with the given pattern.</param>
 /// <param name="handler">Request handler.</param>
 /// <returns></returns>
 public RoutingElement Add(string method, string path, bool wildcard, RequestHandler handler)
 {
     Contract.Requires(method != null);
     Contract.Requires(method.Length >= 3);
     Contract.Requires(path != null);
     Contract.Requires(path.Length > 0);
     Contract.Requires(path[0] == '/');
     Contract.Requires(handler != null);
     var e = new RoutingElement(method, path, wildcard, handler);
     if (first == null)
     {
         first = e;
     }
     else
     {
         RoutingElement h = first;
         while (h.next != null) { h = h.next; }
         h.next = e;
     }
     return e;
 }
示例#6
0
 /// <summary>
 /// This method adds a new request routing element to the
 /// collection, consisting of a request pattern and a request
 /// handler.
 /// 
 /// Preconditions
 ///     pattern != null
 ///     pattern.Length >= 3
 ///     handler != null
 /// </summary>
 /// <param name="pattern">Request pattern (method, path).</param>
 /// <param name="handler">Request handler.</param>
 public void Add(string pattern, RequestHandler handler)
 {
     Contract.Requires(pattern != null);
     Contract.Requires(pattern.Length >= 3);
     Contract.Requires(handler != null);
     var e = Parse(pattern, handler);
     Contract.Requires(e != null);
     if (first == null)
     {
         first = e;
     }
     else
     {
         RoutingElement h = first;
         while (h.next != null) { h = h.next; }
         h.next = e;
     }
 }
示例#7
0
        internal bool RequestMatch(RoutingElement e)
        {
            Contract.Requires(e != null);
            Contract.Requires(e.Path != null);
            Contract.Requires(e.Path.Length > 0);
            Contract.Requires(e.Path[0] == '/');
            // Pattern = ( Method | '*') path [ '*' ]
            string uri = RequestUri;
            Contract.Requires(uri != null);
            int uriLength = uri.Length;
            Contract.Requires(uriLength >= 1);
            if (uri[0] != '/')      // some proxies return absolute URIs
            {
                return false;
            }
            string method = RequestMethod;
            Contract.Requires(method != null);
            int methodLength = method.Length;
            Contract.Requires(methodLength >= 3);
            if ((method != e.Method) && (e.Method != "*")) { return false; }

            var pos = 1;
            if (relayDomain != null)    // try to match relay domain
            {
                int relayPrefixLength = relayDomain.Length + 1;
                if (uriLength <= relayPrefixLength) { return false; }
                while (pos != relayPrefixLength)
                {
                    if (uri[pos] != relayDomain[pos - 1]) { return false; }
                    pos = pos + 1;
                }
                if (uri[pos] != '/') { return false; }
                pos = pos + 1;
            }
            // try to match request pattern
            int patternLength = e.Path.Length;
            if (uriLength < (pos - 1 + patternLength)) { return false; }
            var i = 1;
            while (i != patternLength)
            {
                if (uri[pos] != e.Path[i]) { return false; }
                pos = pos + 1;
                i = i + 1;
            }
            return ((pos == uriLength) || (e.Wildcard));
        }