예제 #1
0
        // called by libcurlshim
        private static int ReadDelegate(IntPtr buf, int sz, int nmemb,
                                        IntPtr parm)
        {
            int bytes = sz * nmemb;

            byte[]   b    = new byte[bytes];
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            if (easy == null)
            {
                return(0);
            }
            if (easy.m_pfRead == null)
            {
                return(0);
            }
            int nRead = easy.m_pfRead(b, sz, nmemb, easy.m_readData);

            if (nRead > 0)
            {
                for (int i = 0; i < nRead; i++)
                {
                    Marshal.WriteByte(buf, i, b[i]);
                }
            }
            return(nRead);
        }
예제 #2
0
        // called by libcurlshim
        private static CURLIOERR IoctlDelegate(CURLIOCMD cmd,
                                               IntPtr parm)
        {
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            // let's require all of these to be non-null
            if (easy == null || easy.m_pfIoctl == null ||
                easy.m_ioctlData == null)
            {
                return(CURLIOERR.CURLIOE_UNKNOWNCMD);
            }
            return(easy.m_pfIoctl(cmd, easy.m_ioctlData));
        }
예제 #3
0
        // called by libcurlshim
        private static int SSLCtxDelegate(IntPtr ctx, IntPtr parm)
        {
            int      ok   = (int)CURLcode.CURLE_OK;
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            if (easy == null)
            {
                return(ok);
            }
            if (easy.m_pfSSLContext == null)
            {
                return(ok);  // keep going
            }
            SSLContext context = new SSLContext(ctx);

            return((int)easy.m_pfSSLContext(context, easy.m_sslContextData));
        }
예제 #4
0
        // called by libcurlshim
        private static int ProgressDelegate(IntPtr parm, double dlTotal,
                                            double dlNow, double ulTotal, double ulNow)
        {
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            if (easy == null)
            {
                return(0);
            }
            if (easy.m_pfProgress == null)
            {
                return(0);
            }
            int nprog = easy.m_pfProgress(easy.m_progressData, dlTotal,
                                          dlNow, ulTotal, ulNow);

            return(nprog);
        }
예제 #5
0
        // called by libcurlshim
        private static int DebugDelegate(CURLINFOTYPE infoType,
                                         IntPtr msgBuf, int msgBufSize, IntPtr parm)
        {
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            if (easy == null)
            {
                return(0);
            }
            if (easy.m_pfDebug == null)
            {
                return(0);
            }
            String message = Marshal.PtrToStringAnsi(msgBuf, msgBufSize);

            easy.m_pfDebug(infoType, message, easy.m_debugData);
            return(0);
        }
예제 #6
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();
 }
예제 #7
0
        // called by libcurlshim
        private static int WriteDelegate(IntPtr buf, int sz, int nmemb,
                                         IntPtr parm)
        {
            int bytes = sz * nmemb;

            byte[] b = new byte[bytes];
            for (int i = 0; i < bytes; i++)
            {
                b[i] = Marshal.ReadByte(buf, i);
            }
            GCHandle gch  = (GCHandle)parm;
            Easy     easy = (Easy)gch.Target;

            if (easy == null)
            {
                return(0);
            }
            if (easy.m_pfWrite == null)
            {
                return(bytes);   // keep going
            }
            return(easy.m_pfWrite(b, sz, nmemb, easy.m_writeData));
        }