Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <exception cref="System.InvalidOperationException">This is thrown
 /// if <see cref="Curl"/> hasn't bee properly initialized.</exception>
 /// <exception cref="System.NullReferenceException">This is thrown if
 /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
 public Easy()
 {
     Curl.EnsureCurl();
     m_pCURL = External.curl_easy_init();
     EnsureHandle();
     External.curl_easy_setopt_int(m_pCURL, CURLoption.CURLOPT_NOPROGRESS,
                                   1);
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
Ejemplo n.º 2
0
            public PooledArrayBuilder <T> ReadArray <T>(ReadFunction <T> readFunction, out string?failureReason)
            {
                var builder = PooledArrayBuilder <T> .GetInstance();

                EatSpace();

                Debug.Assert((SymbolKeyType)Data[Position] != SymbolKeyType.Null);

                EatOpenParen();
                Eat(SymbolKeyType.Array);

                string?totalFailureReason = null;
                var    length             = ReadInteger();

                for (var i = 0; i < length; i++)
                {
                    CancellationToken.ThrowIfCancellationRequested();
                    builder.Builder.Add(readFunction(out var elementFailureReason));

                    if (elementFailureReason != null)
                    {
                        var reason = $"element {i} failed {elementFailureReason}";
                        totalFailureReason = totalFailureReason == null
                            ? $"({reason})"
                            : $"({totalFailureReason} -> {reason})";
                    }
                }

                EatCloseParen();
                failureReason = totalFailureReason;
                return(builder);
            }
Ejemplo n.º 3
0
 void IEventHelpers.RegisterSocketRead(IEvent e, BufferedSocket socket, IEventHandler protocol,
                                       ReadFunction callback)
 {
     //Contract.Requires(socket != null);
     Contract.Requires(protocol != null);
     Contract.Requires(callback != null);
 }
Ejemplo n.º 4
0
        public FileManager(FileInfo fileInfo, FileManagerMode mode)
        {
            _fileInfo = fileInfo;
            switch (mode)
            {
            case FileManagerMode.Read:
                _Read       = ReadByteBlock;
                _fileStream = _fileInfo.OpenRead();
                break;

            case FileManagerMode.ReadArchive:
                _Read       = ReadByteBlockFromArchive;
                _fileStream = _fileInfo.OpenRead();
                break;

            case FileManagerMode.Write:
                _Write      = WriteByteBlock;
                _fileStream = _fileInfo.Create();
                break;

            case FileManagerMode.WriteArchive:
                _Write      = WriteByteBlockToArchive;
                _fileStream = _fileInfo.Create();
                break;

            default:
                throw new NotSupportedException("The file manager mode is not supported.");
            }
        }
Ejemplo n.º 5
0
 void IEventHelpers.RegisterSocketPeekRead(IEvent e, BufferedSocket socket, IEventHandler protocol,
                                           ReadFunction callback)
 {
     //Contract.Requires(socket != null);
     Contract.Requires(protocol != null);
     Contract.Requires(callback != null);
 }
Ejemplo n.º 6
0
            public Reader()
            {
                _readString  = ReadString;
                _readBoolean = ReadBoolean;
                _readRefKind = ReadRefKind;

                Data = null !;
            }
Ejemplo n.º 7
0
            public SymbolKeyReader()
            {
                _readSymbolKey = ReadSymbolKey;
                _readLocation  = ReadLocation;

                Compilation = null !;
                Comparer    = null !;
            }
Ejemplo n.º 8
0
        /// <summary>
        /// 构造字节流的分析链
        /// </summary>
        private void BuildReadFunctionChain()
        {
            ReadFunction readMessage = new ReadMessage(0, this.encrypter, this);
            ReadFunction readLength  = new ReadLength(readMessage, this.encrypter);

            readMessage.Next = readLength;
            ReadFunction readHandshake = new ReadHandshake(readLength, encrypter, this);

            this.currentFunction = readHandshake;
        }
Ejemplo n.º 9
0
 public void RegisterSocketPeekRead(IEvent e, BufferedSocket socket, IEventHandler protocol,
                                    ReadFunction callback)
 {
     e.RegisterSocketRead(socket, () =>
     {
         EndPoint ep = new IPEndPoint(IPAddress.Any, 0);
         try
         {
             protocol.Peek(socket, _msg, ref ep);
         }
         catch (SocketException)
         {
             _msg.Clear();
         }
         callback(_msg, ep);
     });
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 读入字节流函数
        /// </summary>
        /// <param name="bytes">读入的字节流</param>
        public void DataCameIn(byte[] bytes)
        {
            do
            {
                //如果关闭,则退出
                if (this.closed)
                {
                    return;
                }

                //计算开始读取位置
                int startIndex = currentFunction.Length - (int)this.buffer.Position;

                //如果开始读取位置比数据流的长度要大,则将数据流写入缓冲区,等待下一个数据流
                int bytesLength = bytes.Length;
                if (startIndex > bytesLength)
                {
                    this.buffer.Write(bytes, 0, bytesLength);
                    return;
                }

                //否则,将数据流写入缓冲区,进入分析数据流
                this.buffer.Write(bytes, 0, startIndex);


                //删除数据流前startIndex个字节
                bytes = Globals.DeleteBytes(bytes, startIndex);

                //清除缓冲区
                byte[] memoryBytes = this.buffer.ToArray();
                this.buffer.Close();
                this.buffer = new MemoryStream();


                //如果读取出现错误,则退出
                if (!currentFunction.ReadBytes(memoryBytes))
                {
                    this.Close();
                    return;
                }

                //转到下一个分析协议类
                this.currentFunction = this.currentFunction.Next;
            } while (true);
        }
Ejemplo n.º 11
0
 private Easy(Easy from)
 {
     m_pCURL = External.curl_easy_duphandle(from.m_pCURL);
     EnsureHandle();
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
Ejemplo n.º 12
0
        private bool TryCreateModbusFunction(KeyValuePair <short, Dictionary <ushort, long> > addressToGidMapKvp, out IReadModbusFunction modbusFunction)
        {
            string verboseMessage = $"{baseLogString} entering TryCreateModbusFunction method => addressToGidMapKvp(key: {addressToGidMapKvp.Key}, value count: {addressToGidMapKvp.Value.Count}).";

            Logger.LogVerbose(verboseMessage);

            modbusFunction = null;
            PointType pointType = (PointType)addressToGidMapKvp.Key;
            Dictionary <ushort, long> addressToGidMap = addressToGidMapKvp.Value;
            ModbusFunctionCode        functionCode;

            try
            {
                functionCode   = MapPointTypeToModbusFunctionCode(pointType);
                verboseMessage = $"{baseLogString} TryCreateModbusFunction => function code mapped: {functionCode}.";
                Logger.LogVerbose(verboseMessage);
            }
            catch (ArgumentException ae)
            {
                Logger.LogVerbose(ae.Message); //recomended to be verbose, becouse Acquisition happens very often
                return(false);
            }

            ushort startAddress = 1;
            ushort quantity     = (ushort)addressToGidMap.Count;

            if (quantity == 0)
            {
                return(false);
            }

            modbusFunction = new ReadFunction(functionCode, startAddress, quantity);
            verboseMessage = $"{baseLogString} TryCreateModbusFunction => ReadFunction with code: {modbusFunction.FunctionCode}, stratring address: {modbusFunction.StartAddress} and quantity: {modbusFunction.Quantity} SUCCESSFULLY created.";
            Logger.LogVerbose(verboseMessage);
            return(true);
        }
Ejemplo n.º 13
0
 public BaseTable(ReadFunction ReadFunc, WriteFunction WriteFunc)
 {
     readFunc  = ReadFunc;
     writeFunc = WriteFunc;
 }
Ejemplo n.º 14
0
 public PackableList(ReadFunction ReadFunc, WriteFunction WriteFunc) : base(ReadFunc, WriteFunc)
 {
 }
Ejemplo n.º 15
0
 public SymbolKeyReader()
 {
     _readSymbolKey = ReadSymbolKey;
     _readLocation  = ReadLocation;
 }
Ejemplo n.º 16
0
 public Reader()
 {
     _readString  = ReadString;
     _readBoolean = ReadBoolean;
     _readRefKind = ReadRefKind;
 }
Ejemplo n.º 17
0
 public void RegisterSocketRead(IEvent e, BufferedSocket socket, IEventHandler protocol, ReadFunction callback)
 {
     e.RegisterSocketRead(socket, () =>
     {
         EndPoint ep = new IPEndPoint(IPAddress.Any, 0);
         try
         {
             protocol.Read(socket, _msg, ref ep);
         }
         catch (SocketException ex)
         {
             Console.WriteLine("SocketException occured: " + ex.Message);
             _msg.Clear();
         }
         callback(_msg, ep);
     });
 }
Ejemplo n.º 18
0
 public PSmartArray(ReadFunction ReadFunc, WriteFunction WriteFunc) : base(ReadFunc, WriteFunc)
 {
 }
Ejemplo n.º 19
0
 public BaseList(ReadFunction ReadFunc, WriteFunction WriteFunc)
 {
     readFunc  = ReadFunc;
     writeFunc = WriteFunc;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <exception cref="System.InvalidOperationException">This is thrown
        /// if <see cref="Curl"/> hasn't bee properly initialized.</exception>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
		public Easy()
		{
            Curl.EnsureCurl();
            m_pCURL = External.curl_easy_init();
            EnsureHandle();
            External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_NOPROGRESS,
                IntPtr.Zero);
            m_pMyStrings = External.curl_shim_alloc_strings();
            m_pfWrite = null;
            m_privateData = null;
            m_writeData = null;
            m_pfRead = null;
            m_readData = null;
            m_pfProgress = null;
            m_progressData = null;
            m_pfDebug = null;
            m_debugData = null;
            m_pfHeader = null;
            m_headerData = null;
            m_pfSSLContext = null;
            m_sslContextData = null;
            m_pfIoctl = null;
            m_ioctlData = null;
            InstallDelegates();
        }
Ejemplo n.º 21
0
 private Easy(Easy from)
 {
     m_pCURL = External.curl_easy_duphandle(from.m_pCURL);
     EnsureHandle();
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Set options for this object. See the <c>EasyGet</c> sample for
        /// basic usage.
        /// </summary>
        /// <param name="option">This should be a valid <see cref="CURLoption"/>.</param>
        /// <param name="parameter">This should be a parameter of a varying
        /// type based on the value of the <c>option</c> parameter.</param>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
        /// <returns>A <see cref="CURLcode"/>, typically obtained from
        /// <c>cURL</c> internally, but sometimes a
        /// <see cref="CURLcode.CURLE_BAD_FUNCTION_ARGUMENT"/>
        /// will be returned if the type of value of <c>parameter</c> is invalid.
        /// </returns>
        public CURLcode SetOpt(CURLoption option, Object parameter)
        {
            EnsureHandle();
            CURLcode retCode = CURLcode.CURLE_OK;

            // numeric cases
            if ((int)option < CURLOPTTYPE_OBJECTPOINT)
            {
                int i = 0;
                if (option == CURLoption.CURLOPT_DNS_USE_GLOBAL_CACHE ||
                    option == CURLoption.CURLOPT_SOURCE_PORT)
                {
                    return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                }
                else if (option == CURLoption.CURLOPT_TIMEVALUE)
                {
                    // unboxing may throw class cast exception
                    DateTime d = (DateTime)parameter;
                    DateTime startTime = new DateTime(1970, 1, 1);
                    TimeSpan currTime = new TimeSpan(DateTime.Now.Ticks -
                        startTime.Ticks);
                    i = Convert.ToInt32(currTime.TotalSeconds);
                }
                else
                    i = Convert.ToInt32(parameter);
                retCode = External.curl_easy_setopt(m_pCURL,
                    option, (IntPtr)i);
            }

            // object cases: the majority
            else if ((int)option < CURLOPTTYPE_FUNCTIONPOINT)
            {
                switch(option)
                {
                    // various data items
                    case CURLoption.CURLOPT_PRIVATE:
                        m_privateData = parameter; break;
                    case CURLoption.CURLOPT_WRITEDATA:
                        m_writeData = parameter; break;
                    case CURLoption.CURLOPT_READDATA:
                        m_readData = parameter; break;
                    case CURLoption.CURLOPT_PROGRESSDATA:
                        m_progressData = parameter; break;
                    case CURLoption.CURLOPT_DEBUGDATA:
                        m_debugData = parameter; break;
                    case CURLoption.CURLOPT_HEADERDATA:
                        m_headerData = parameter; break;
                    case CURLoption.CURLOPT_SSL_CTX_DATA:
                        m_sslContextData = parameter; break;
                    case CURLoption.CURLOPT_IOCTLDATA:
                        m_ioctlData = parameter; break;

                    // items that can't be set externally or
                    // obsolete items
                    case CURLoption.CURLOPT_ERRORBUFFER:
                    case CURLoption.CURLOPT_STDERR:
                    case CURLoption.CURLOPT_SOURCE_HOST:
                    case CURLoption.CURLOPT_SOURCE_PATH:
                    case CURLoption.CURLOPT_PASV_HOST:
                        return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;

                    // singular case for share
                    case CURLoption.CURLOPT_SHARE:
                    {
                        Share share = parameter as Share;
                        if (share == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        retCode = External.curl_easy_setopt(m_pCURL,
                            option, share.GetHandle());
                        break;
                    }

                    // multipart HTTP post
                    case CURLoption.CURLOPT_HTTPPOST:
                    {
                        MultiPartForm mf = parameter as MultiPartForm;
                        if (mf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        retCode = External.curl_easy_setopt(m_pCURL,
                            option, mf.GetHandle());
                        break;
                    }

                    // items curl wants as a curl_slist
                    case CURLoption.CURLOPT_HTTPHEADER:
                    case CURLoption.CURLOPT_PREQUOTE:
                    case CURLoption.CURLOPT_QUOTE:
                    case CURLoption.CURLOPT_POSTQUOTE:
                    case CURLoption.CURLOPT_SOURCE_QUOTE:
                    case CURLoption.CURLOPT_TELNETOPTIONS:
                    case CURLoption.CURLOPT_HTTP200ALIASES:
                    {
                        Slist slist = parameter as Slist;
                        if (slist == null) {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, IntPtr.Zero);
                        }
                        else {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, slist.GetHandle());
                        }
                        break;
                    }

                    // string items
                    default:
                    {
                        string s = parameter as string;
                        if (s == null) {
                            retCode = External.curl_easy_setopt(m_pCURL,
                                option, IntPtr.Zero);
                        }
                        else {
                            IntPtr pCurlStr = External.curl_shim_add_string(
                                m_pMyStrings, s);
                            if (pCurlStr != IntPtr.Zero)
                                retCode = External.curl_easy_setopt(m_pCURL,
                                    option, pCurlStr);
                        }
                        break;
                    }
                }                        
            }

            // FUNCTIONPOINT args, for delegates
            else if ((int)option < CURLOPTTYPE_OFF_T)
            {
                switch(option)
                {
                    case CURLoption.CURLOPT_WRITEFUNCTION:
                    {
                        WriteFunction wf = parameter as WriteFunction;
                        if (wf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfWrite = wf;
                        break;
                    }

                    case CURLoption.CURLOPT_READFUNCTION:
                    {
                        ReadFunction rf = parameter as ReadFunction;
                        if (rf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfRead = rf;
                        break;
                    }

                    case CURLoption.CURLOPT_PROGRESSFUNCTION:
                    {
                        ProgressFunction pf = parameter as ProgressFunction;
                        if (pf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfProgress = pf;
                        break;
                    }

                    case CURLoption.CURLOPT_DEBUGFUNCTION:
                    {
                        DebugFunction pd = parameter as DebugFunction;
                        if (pd == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfDebug = pd;
                        break;
                    }

                    case CURLoption.CURLOPT_HEADERFUNCTION:
                    {
                        HeaderFunction hf = parameter as HeaderFunction;
                        if (hf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfHeader = hf;
                        break;
                    }

                    case CURLoption.CURLOPT_SSL_CTX_FUNCTION:
                    {
                        SSLContextFunction sf = parameter as SSLContextFunction;
                        if (sf == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfSSLContext = sf;
                        break;
                    }

                    case CURLoption.CURLOPT_IOCTLFUNCTION:
                    {
                        IoctlFunction iof = parameter as IoctlFunction;
                        if (iof == null)
                            return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                        m_pfIoctl = iof;
                        break;
                    }

                    default:
                        return CURLcode.CURLE_BAD_FUNCTION_ARGUMENT;
                }
            }

            // otherwise, it's one of those 64-bit off_t guys!
            else
            {
                Int64 i = Convert.ToInt64(parameter);
                retCode = External.curl_easy_setopt_64(m_pCURL,
                    option, i);
            }

            return retCode;
        }
Ejemplo n.º 23
0
        /* ======= Header Functions ======= */

        /**
         * <summary>
         * Creates a ZraHeader object from a file.
         * </summary>
         * <param name="header">A pointer to a pointer to store the ZraHeader pointer in</param>
         * <param name="readFunction">This function is used to read data from the compressed file while supplying the offset and the size, the output should be into the buffer</param>
         * <returns>A <see cref="ZraStatus"/> structure which contains the result code of the completed operation.</returns>
         */
        [DllImport("libzra")] public static extern ZraStatus ZraCreateHeader(out IntPtr header, [MarshalAs(UnmanagedType.FunctionPtr)] ReadFunction readFunction);
Ejemplo n.º 24
0
        /* ======= Streaming Full Decompressor ======= */

        /**
         * <summary>
         * Creates a ZraFullDecompressor object with the specified parameters
         * </summary>
         * <param name="fullDecompressor"> A pointer to store the ZraFullDecompressor pointer in</param>
         * <param name="readFunction"> This function is used to read data from the compressed file while supplying the offset and the size, the output should be into the buffer</param>
         * <returns>A <see cref="ZraStatus"/> structure which contains the result code of the completed operation.</returns>
         */
        [DllImport("libzra")] public static extern ZraStatus ZraCreateFullDecompressor(out IntPtr fullDecompressor, [MarshalAs(UnmanagedType.FunctionPtr)] ReadFunction readFunction);
Ejemplo n.º 25
0
        /* ======= Streaming Random-Access Decompressor ======= */

        /**
         * <summary>
         * Creates a ZraDecompressor object with the specified parameters.
         * </summary>
         * <param name="decompressor"> A pointer to a pointer to store the ZraDecompressor pointer in</param>
         * <param name="readFunction"> This function is used to read data from the compressed file while supplying the offset and the size, the output should be into the buffer</param>
         * <param name="maxCacheSize"> The maximum size of the file cache, if the uncompressed segment read goes above this then it'll be read into it's own buffer</param>
         * <remarks>The cache is to preallocate buffers that are passed into readFunction, so that there isn't constant reallocation.</remarks>
         * <returns>A <see cref="ZraStatus"/> structure which contains the result code of the completed operation.</returns>
         */
        [DllImport("libzra")] public static extern ZraStatus ZraCreateDecompressor(out IntPtr decompressor, [MarshalAs(UnmanagedType.FunctionPtr)] ReadFunction readFunction, ulong maxCacheSize = 1024 * 1024 * 20);
Ejemplo n.º 26
0
 public Reader(IDisposable disposableDependency, AdvancementFunction advancementFunction, ReadFunction readFunction)
 {
     this.advancementFunction  = advancementFunction;
     this.disposableDependency = disposableDependency;
     this.readFunction         = readFunction;
 }
Ejemplo n.º 27
0
 public PList(ReadFunction ReadFunc, WriteFunction WriteFunc) : base(ReadFunc, WriteFunc)
 {
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Set options for this object. See the <c>EasyGet</c> sample for
        /// basic usage.
        /// </summary>
        /// <param name="option">This should be a valid <see cref="CURLoption"/>.</param>
        /// <param name="parameter">This should be a parameter of a varying
        /// type based on the value of the <c>option</c> parameter.</param>
        /// <exception cref="System.NullReferenceException">This is thrown if
        /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
        /// <returns>A <see cref="CURLcode"/>, typically obtained from
        /// <c>cURL</c> internally, but sometimes a
        /// <see cref="CURLcode.CURLE_BAD_FUNCTION_ARGUMENT"/>
        /// will be returned if the type of value of <c>parameter</c> is invalid.
        /// </returns>
        public CURLcode SetOpt(CURLoption option, Object parameter)
        {
            EnsureHandle();
            CURLcode retCode = CURLcode.CURLE_OK;

            // numeric cases
            if ((int)option < CURLOPTTYPE_OBJECTPOINT)
            {
                int i = 0;
                if (option == CURLoption.CURLOPT_DNS_USE_GLOBAL_CACHE ||
                    option == CURLoption.CURLOPT_SOURCE_PORT)
                {
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                }
                else if (option == CURLoption.CURLOPT_TIMEVALUE)
                {
                    // unboxing may throw class cast exception
                    //DateTime d = (DateTime)parameter;
                    DateTime startTime = Main.DateTimeBegin;
                    TimeSpan currTime  = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks);
                    i = Convert.ToInt32(currTime.TotalSeconds);
                }
                else
                {
                    i = Convert.ToInt32(parameter);
                }

                retCode = External.curl_easy_setopt_int(m_pCURL,
                                                        option, i);
            }

            // object cases: the majority
            else if ((int)option < CURLOPTTYPE_FUNCTIONPOINT)
            {
                switch (option)
                {
                // various data items
                case CURLoption.CURLOPT_PRIVATE:
                    m_privateData = parameter; break;

                case CURLoption.CURLOPT_WRITEDATA:
                    m_writeData = parameter; break;

                case CURLoption.CURLOPT_READDATA:
                    m_readData = parameter; break;

                case CURLoption.CURLOPT_PROGRESSDATA:
                    m_progressData = parameter; break;

                case CURLoption.CURLOPT_DEBUGDATA:
                    m_debugData = parameter; break;

                case CURLoption.CURLOPT_HEADERDATA:
                    m_headerData = parameter; break;

                case CURLoption.CURLOPT_SSL_CTX_DATA:
                    m_sslContextData = parameter; break;

                case CURLoption.CURLOPT_IOCTLDATA:
                    m_ioctlData = parameter; break;

                // items that can't be set externally or
                // obsolete items
                case CURLoption.CURLOPT_ERRORBUFFER:
                case CURLoption.CURLOPT_STDERR:
                case CURLoption.CURLOPT_SOURCE_HOST:
                case CURLoption.CURLOPT_SOURCE_PATH:
                case CURLoption.CURLOPT_PASV_HOST:
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);

                // singular case for share
                case CURLoption.CURLOPT_SHARE:
                {
                    Share share = parameter as Share;
                    if (share == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                            option, share.GetHandle());
                    break;
                }

                // multipart HTTP post
                case CURLoption.CURLOPT_HTTPPOST:
                {
                    MultiPartForm mf = parameter as MultiPartForm;
                    if (mf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                            option, mf.GetHandle());
                    break;
                }

                // items curl wants as a curl_slist
                case CURLoption.CURLOPT_HTTPHEADER:
                case CURLoption.CURLOPT_PREQUOTE:
                case CURLoption.CURLOPT_QUOTE:
                case CURLoption.CURLOPT_POSTQUOTE:
                case CURLoption.CURLOPT_SOURCE_QUOTE:
                case CURLoption.CURLOPT_TELNETOPTIONS:
                case CURLoption.CURLOPT_HTTP200ALIASES:
                {
                    Slist slist = parameter as Slist;
                    if (slist == null)
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, IntPtr.Zero);
                    }
                    else
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, slist.GetHandle());
                    }
                    break;
                }

                // string items
                default:
                {
                    string s = parameter as string;
                    if (s == null)
                    {
                        retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                option, IntPtr.Zero);
                    }
                    else
                    {
                        IntPtr pCurlStr = External.curl_shim_add_string(
                            m_pMyStrings, s);
                        if (pCurlStr != IntPtr.Zero)
                        {
                            retCode = External.curl_easy_setopt_ptr(m_pCURL,
                                                                    option, pCurlStr);
                        }
                    }
                    break;
                }
                }
            }

            // FUNCTIONPOINT args, for delegates
            else if ((int)option < CURLOPTTYPE_OFF_T)
            {
                switch (option)
                {
                case CURLoption.CURLOPT_WRITEFUNCTION:
                {
                    WriteFunction wf = parameter as WriteFunction;
                    if (wf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfWrite = wf;
                    break;
                }

                case CURLoption.CURLOPT_READFUNCTION:
                {
                    ReadFunction rf = parameter as ReadFunction;
                    if (rf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfRead = rf;
                    break;
                }

                case CURLoption.CURLOPT_PROGRESSFUNCTION:
                {
                    ProgressFunction pf = parameter as ProgressFunction;
                    if (pf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfProgress = pf;
                    break;
                }

                case CURLoption.CURLOPT_DEBUGFUNCTION:
                {
                    DebugFunction pd = parameter as DebugFunction;
                    if (pd == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfDebug = pd;
                    break;
                }

                case CURLoption.CURLOPT_HEADERFUNCTION:
                {
                    HeaderFunction hf = parameter as HeaderFunction;
                    if (hf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfHeader = hf;
                    break;
                }

                case CURLoption.CURLOPT_SSL_CTX_FUNCTION:
                {
                    SSLContextFunction sf = parameter as SSLContextFunction;
                    if (sf == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfSSLContext = sf;
                    break;
                }

                case CURLoption.CURLOPT_IOCTLFUNCTION:
                {
                    IoctlFunction iof = parameter as IoctlFunction;
                    if (iof == null)
                    {
                        return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                    }
                    m_pfIoctl = iof;
                    break;
                }

                default:
                    return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT);
                }
            }

            // otherwise, it's one of those 64-bit off_t guys!
            else
            {
                Int64 i = Convert.ToInt64(parameter);
                retCode = External.curl_easy_setopt_int64(m_pCURL,
                                                          option, i);
            }

            return(retCode);
        }
Ejemplo n.º 29
0
 public IntrusiveHashTable(ReadFunction ReadFunc, WriteFunction WriteFunc) : base(ReadFunc, WriteFunc)
 {
 }
Ejemplo n.º 30
0
 public PHashTable(ReadFunction ReadFunc, WriteFunction WriteFunc) : base(ReadFunc, WriteFunc)
 {
 }
Ejemplo n.º 31
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="length">分析的长度</param>
 /// <param name="next">下一个分析类</param>
 public ReadFunction(int length, ReadFunction next)
 {
     this.length = length;
     this.next   = next;
 }