Exemplo n.º 1
0
        /// <summary>
        /// Creates a CurlEasy object that calls the given writeback function
        /// when data is received.
        /// Can also write back the header.
        /// </summary>
        /// <returns>The CurlEasy object</returns>
        ///
        /// Adapted from MultiDemo.cs in the curlsharp repo
        public static CurlEasy CreateEasy(string url, string authToken, CurlWriteCallback wf, CurlHeaderCallback hwf = null)
        {
            if (!_initComplete)
            {
                Log.Warn("Curl environment not pre-initialised, performing non-threadsafe init.");
                Init();
            }

            var easy = new CurlEasy()
            {
                Url           = url,
                WriteData     = null,
                WriteFunction = wf,
                Encoding      = "deflate, gzip",
                // Follow redirects
                FollowLocation = true,
                UserAgent      = Net.UserAgentString,
                SslVerifyPeer  = true,
                HeaderData     = null,
                HttpHeader     = GetHeaders(authToken),
            };

            if (hwf != null)
            {
                easy.HeaderFunction = hwf;
            }

            var caBundle = ResolveCurlCaBundle();

            if (caBundle != null)
            {
                easy.CaInfo = caBundle;
            }
            return(easy);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a CurlEasy object that calls the given writeback function
        /// when data is received.
        /// Can also write back the header.
        /// </summary>
        /// <returns>The CurlEasy object</returns>
        ///
        /// Adapted from MultiDemo.cs in the curlsharp repo
        public static CurlEasy CreateEasy(string url, CurlWriteCallback wf, CurlHeaderCallback hwf = null)
        {
            if (!_initComplete)
            {
                Log.Warn("Curl environment not pre-initialised, performing non-threadsafe init.");
                Init();
            }

            var easy = new CurlEasy();

            easy.Url           = url;
            easy.WriteData     = null;
            easy.WriteFunction = wf;
            if (hwf != null)
            {
                easy.HeaderFunction = hwf;
            }
            easy.Encoding       = "deflate, gzip";
            easy.FollowLocation = true; // Follow redirects
            easy.UserAgent      = Net.UserAgentString;
            easy.SslVerifyPeer  = true;

            var caBundle = ResolveCurlCaBundle();

            if (caBundle != null)
            {
                easy.CaInfo = caBundle;
            }

            return(easy);
        }
Exemplo n.º 3
0
Arquivo: Curl.cs Projeto: Zor-X-L/CKAN
        /// <summary>
        /// Creates a CurlEasy object that calls the given writeback function
        /// when data is received.
        /// </summary>
        /// <returns>The CurlEasy obect</returns>
        /// 
        /// Adapted from MultiDemo.cs in the curlsharp repo
        public static CurlEasy CreateEasy(string url, CurlWriteCallback wf)
        {
            if (!_initComplete)
            {
                Log.Warn("Curl environment not pre-initialised, performing non-threadsafe init.");
                Init();
            }

            var easy = new CurlEasy();
            easy.Url = url;
            easy.WriteData = null;
            easy.WriteFunction = wf;
            easy.Encoding = "deflate, gzip";
            easy.FollowLocation = true; // Follow redirects
            easy.UserAgent = Net.UserAgentString;
            easy.SslVerifyPeer = true;

            // ksp.sarbian.com uses a SSL cert that libcurl can't
            // verify, so we skip verification. Yeah, that sucks, I know,
            // but this sucks less than our previous solution that disabled
            // SSL checking entirely.

            if (url.StartsWith("https://ksp.sarbian.com/"))
            {
                easy.SslVerifyPeer = false;
            }

            var caBundle = ResolveCurlCaBundle();
            if (caBundle != null)
            {
                easy.CaInfo = caBundle;
            }

            return easy;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a CurlEasy object that calls the given writeback function
        /// when data is received.
        /// </summary>
        /// <returns>The CurlEasy obect</returns>
        ///
        /// Adapted from MultiDemo.cs in the curlsharp repo
        public static CurlEasy CreateEasy(string url, CurlWriteCallback wf)
        {
            if (!init_complete)
            {
                log.Warn("Curl environment not pre-initialised, performing non-threadsafe init.");
                Init();
            }

            var easy = new CurlEasy();

            easy.Url            = url;
            easy.WriteData      = null;
            easy.WriteFunction  = wf;
            easy.Encoding       = "deflate, gzip";
            easy.FollowLocation = true; // Follow redirects
            easy.UserAgent      = Net.UserAgentString;
            easy.SslVerifyPeer  = true;

            // ksp.sarbian.com uses a SSL cert that libcurl can't
            // verify, so we skip verification. Yeah, that sucks, I know,
            // but this sucks less than our previous solution that disabled
            // SSL checking entirely.

            if (url.StartsWith("https://ksp.sarbian.com/"))
            {
                easy.SslVerifyPeer = false;
            }

            return(easy);
        }
Exemplo n.º 5
0
        private static CurlEasy CreateEasy(string url, CurlWriteCallback wf)
        {
            var easy = new CurlEasy();
            var data = url;

            easy.Url           = url;
            easy.WriteFunction = wf;
            easy.WriteData     = data;
            easy.Encoding      = "deflate, gzip";
            return(easy);
        }
Exemplo n.º 6
0
 // static class constructor to create static delegate
 static EasyThread()
 {
     Console.WriteLine("EasyThread class constructor");
     wf = OnWriteData;
 }
Exemplo n.º 7
0
        public static void Main(String[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                CurlWriteCallback wf = OnWriteData;

                var handles = new List <CurlEasy>();
                var urls    = new[]
                {
                    "http://www.codeplex.com",
                    "http://www.yahoo.com",
                    "http://www.cnn.com",
                    "http://www.abc.com",
                    "http://www.bbc.co.uk"
                };

                using (var multi = new CurlMulti())
                {
                    foreach (var url in urls)
                    {
                        var easy = CreateEasy(url, wf);
                        multi.AddHandle(easy);
                        handles.Add(easy);
                    }

                    var runningObjects = 1;
                    // call CurlMulti.Perform right away (note ref qualifier)
                    multi.Perform(ref runningObjects);

                    while (runningObjects != 0)
                    {
                        var fdret = multi.FdSet();
                        //if (multi.MaxFd > -1)
                        {
                            var rc = multi.Select(1000); // one second
                            switch (rc)
                            {
                            case -1:
                                Console.WriteLine("CurlMulti.Select() returned -1");
                                //runningObjects = 0;
                                break;

                            case 0:     // time out
                            default:
                            {
                                multi.Perform(ref runningObjects);
                                break;
                            }
                            }
                        }
                    }
                }

                foreach (var easy in handles)
                {
                    easy.Dispose();
                }
                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Exemplo n.º 8
0
 private static CurlEasy CreateEasy(string url, CurlWriteCallback wf)
 {
     var easy = new CurlEasy();
     var data = (String) url.Clone();
     easy.Url = url;
     easy.WriteFunction = wf;
     easy.WriteData = data;
     easy.Encoding = "deflate, gzip";
     return easy;
 }
Exemplo n.º 9
0
 // static class constructor to create static delegate
 static EasyThread()
 {
     Console.WriteLine("EasyThread class constructor");
     wf = OnWriteData;
 }