예제 #1
0
        /// <summary>Adds <paramref name="filter"/> to the list of filters attached to <paramref name="stream"/>.</summary>
        /// <param name="stream">The target stream.</param>
        /// <param name="filter">The filter name.</param>
        /// <param name="read_write">Combination of the <see cref="FilterChainOptions"/> flags.</param>
        /// <param name="parameters">Additional parameters for a user filter.</param>
        public static bool stream_filter_prepend(PhpResource stream, string filter, FilterChainOptions read_write, PhpValue parameters)
        {
            var s = PhpStream.GetValid(stream);

            if (s == null)
            {
                return(false);
            }

            var where = (FilterChainOptions)read_write & FilterChainOptions.ReadWrite;
            return(PhpFilter.AddToStream(s, filter, where | FilterChainOptions.Head, parameters));
        }
        /// <summary>
        /// Insert the filter into the filter chains.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="stream">Which stream's filter chains.</param>
        /// <param name="filter">What filter.</param>
        /// <param name="where">What position in the chains.</param>
        /// <param name="parameters">Additional parameters for the filter.</param>
        /// <returns>True if successful.</returns>
        public static bool AddToStream(Context ctx, PhpStream stream, string filter, FilterChainOptions where, PhpValue parameters)
        {
            PhpFilter readFilter, writeFilter;

            if ((stream.Options & StreamAccessOptions.Read) == 0)
            {
                where &= ~FilterChainOptions.Read;
            }
            if ((stream.Options & StreamAccessOptions.Write) == 0)
            {
                where &= ~FilterChainOptions.Write;
            }

            if ((where & FilterChainOptions.Read) > 0)
            {
                if (!GetFilter(ctx, filter, true, out readFilter, parameters))
                {
                    //PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_filter_name", filter));
                    //return false;
                    throw new ArgumentException(nameof(filter));
                }

                stream.AddFilter(readFilter, where);
                readFilter.OnCreate();
                // Add to chain, (filters buffers too).
            }

            if ((where & FilterChainOptions.Write) > 0)
            {
                if (!GetFilter(ctx, filter, true, out writeFilter, parameters))
                {
                    //PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_filter_name", filter));
                    //return false;
                    throw new ArgumentException(nameof(filter));
                }

                stream.AddFilter(writeFilter, where);
                writeFilter.OnCreate();
                // Add to chain.
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Adds a filter to one of the read or write filter chains.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="where">The position in the chain.</param>
        public void AddFilter(IFilter filter, FilterChainOptions where)
        {
            Debug.Assert((where & FilterChainOptions.ReadWrite) != FilterChainOptions.ReadWrite);
            List<IFilter> list = null;

            // Which chain.
            if ((where & FilterChainOptions.Read) > 0)
            {
                if (readFilters == null) readFilters = new List<IFilter>();
                list = readFilters;
            }
            else
            {
                if (writeFilters == null) writeFilters = new List<IFilter>();
                list = writeFilters;
            }

            // Position in the chain.
            if ((where & FilterChainOptions.Tail) > 0)
            {
                list.Add(filter);
                if ((list == readFilters) && (ReadBufferLength > 0))
                {
                    // Process all the data in the read buffers.
                    var q = new Queue<TextElement>();
                    foreach (var o in readBuffers)
                    {
                        q.Enqueue(filter.Filter(_ctx, o, false));
                    }

                    readBuffers = q;
                }
            }
            else
            {
                list.Insert(0, filter);
            }
        }
예제 #4
0
        public static PhpResource stream_filter_prepend(Context ctx, PhpResource stream, string filter, FilterChainOptions read_write = FilterChainOptions.ReadWrite, PhpValue parameters = default)
        {
            var s = PhpStream.GetValid(stream);

            if (s == null)
            {
                return(null);           // false;
            }
            var where = read_write & FilterChainOptions.ReadWrite;
            var added = PhpFilter.AddToStream(ctx, s, filter, where | FilterChainOptions.Head, parameters);

            //
            if (added.readFilter != null || added.writeFilter != null)
            {
                return(new StreamFilterResource(s, added.writeFilter, added.readFilter));
            }
            else
            {
                return(null); // false
            }
        }
예제 #5
0
 /// <summary>Adds <paramref name="filter"/> to the list of filters attached to <paramref name="stream"/>.</summary>
 /// <param name="stream">The target stream.</param>
 /// <param name="filter">The filter name.</param>
 /// <param name="read_write">Combination of the <see cref="FilterChainOptions"/> flags.</param>
 public static bool stream_filter_prepend(PhpResource stream, string filter, FilterChainOptions read_write = FilterChainOptions.ReadWrite)
 {
     return(stream_filter_prepend(stream, filter, read_write, PhpValue.Null));
 }
예제 #6
0
        /// <summary>
        /// Insert the filter into the filter chains.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="stream">Which stream's filter chains.</param>
        /// <param name="filter">What filter.</param>
        /// <param name="where">What position in the chains.</param>
        /// <param name="parameters">Additional parameters for the filter.</param>
        /// <returns>Filters that have been added.</returns>
        internal static (PhpFilter readFilter, PhpFilter writeFilter) AddToStream(Context ctx, PhpStream stream, string filter, FilterChainOptions where, PhpValue parameters)
        {
            if ((stream.Options & StreamAccessOptions.Read) == 0)
            {
                where &= ~FilterChainOptions.Read;
            }
            if ((stream.Options & StreamAccessOptions.Write) == 0)
            {
                where &= ~FilterChainOptions.Write;
            }

            PhpFilter readFilter = null, writeFilter = null;

            if ((where & FilterChainOptions.Read) != 0)
            {
                if (GetFilter(ctx, filter, true, out readFilter, parameters))
                {
                    stream.AddFilter(readFilter, where);
                    readFilter.OnCreate();
                    // Add to chain, (filters buffers too).
                }
                else
                {
                    PhpException.Throw(PhpError.Warning, Core.Resources.ErrResources.invalid_filter_name, filter);
                    //return false;
                    throw new ArgumentException(nameof(filter));
                }
            }

            if ((where & FilterChainOptions.Write) != 0)
            {
                if (GetFilter(ctx, filter, true, out writeFilter, parameters))
                {
                    stream.AddFilter(writeFilter, where);
                    writeFilter.OnCreate();
                    // Add to chain.
                }
                else
                {
                    PhpException.Throw(PhpError.Warning, Core.Resources.ErrResources.invalid_filter_name, filter);
                    //return false;
                    throw new ArgumentException(nameof(filter));
                }
            }

            return(readFilter, writeFilter);
        }
예제 #7
0
		/// <summary>
		/// Adds a filter to one of the read or write filter chains.
		/// </summary>
		/// <param name="filter">The filter.</param>
		/// <param name="where">The position in the chain.</param>
		public void AddFilter(IFilter filter, FilterChainOptions where)
		{
			Debug.Assert((where & FilterChainOptions.ReadWrite) != FilterChainOptions.ReadWrite);
			ArrayList list = null;

			// Which chain.
			if ((where & FilterChainOptions.Read) > 0)
			{
				if (readFilters == null) readFilters = new ArrayList();
				list = readFilters;
			}
			else
			{
				if (writeFilters == null) writeFilters = new ArrayList();
				list = writeFilters;
			}

			// Position in the chain.
			if ((where & FilterChainOptions.Tail) > 0)
			{
				list.Add(filter);
				if ((list == readFilters) && (ReadBufferLength > 0))
				{
					// Process all the data in the read buffers.
					Queue q = new Queue();
					foreach (object o in readBuffers)
						q.Enqueue(filter.Filter(o, false));
					readBuffers = q;
				}
			}
			else
			{
				list.Insert(0, filter);
			}
		}