├── CurlThin
├── NuGet
│ └── icon.png
├── Enums
│ ├── CURLcselect.cs
│ ├── CURLMSG.cs
│ ├── CURLpoll.cs
│ ├── CURLPROTO.cs
│ ├── CURLMcode.cs
│ ├── CURLglobal.cs
│ ├── CURLMoption.cs
│ ├── CURLINFO.cs
│ ├── CURLcode.cs
│ └── CURLoption.cs
├── Logging.cs
├── SafeHandles
│ ├── SafeEasyHandle.cs
│ ├── SafeMultiHandle.cs
│ ├── SafeSlistHandle.cs
│ └── SafeSocketHandle.cs
├── HyperPipe
│ ├── IntPtrEqualityComparer.cs
│ ├── HandleCompletedAction.cs
│ ├── IRequestProvider.cs
│ ├── SocketPollMap.cs
│ ├── IResponseConsumer.cs
│ ├── EasyPool.cs
│ └── HyperPipe.cs
├── CurlThin.csproj
├── Helpers
│ └── DataCallbackCopier.cs
├── CurlException.cs
└── CurlNative.cs
├── CurlThin.Native
├── NuGet
│ └── icon.png
├── CurlThin.Native.csproj
├── StringExtensions.cs
├── PackCurlNative.ps1
└── CurlResources.cs
├── CurlThin.Samples
├── ISample.cs
├── CurlThin.Samples.csproj
├── NLog.config
├── Easy
│ ├── GetSample.cs
│ ├── PostSample.cs
│ └── HttpHeadersSample.cs
├── Program.cs
└── Multi
│ └── HyperSample.cs
├── CurlThin.Tests
├── NLog.config
└── CurlThin.Tests.csproj
├── azure-pipelines.yml
├── LICENSE
├── README.md
├── .gitignore
└── CurlThin.sln
/CurlThin/NuGet/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stil/CurlThin/HEAD/CurlThin/NuGet/icon.png
--------------------------------------------------------------------------------
/CurlThin.Native/NuGet/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stil/CurlThin/HEAD/CurlThin.Native/NuGet/icon.png
--------------------------------------------------------------------------------
/CurlThin.Samples/ISample.cs:
--------------------------------------------------------------------------------
1 | namespace CurlThin.Samples
2 | {
3 | internal interface ISample
4 | {
5 | void Run();
6 | }
7 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLcselect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics.CodeAnalysis;
3 |
4 | namespace CurlThin.Enums
5 | {
6 | [Flags]
7 | [SuppressMessage("ReSharper", "InconsistentNaming")]
8 | public enum CURLcselect
9 | {
10 | IN = 0x01,
11 | OUT = 0x02,
12 | ERR = 0x04
13 | }
14 | }
--------------------------------------------------------------------------------
/CurlThin/Logging.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using Microsoft.Extensions.Logging;
3 |
4 | namespace CurlThin
5 | {
6 | public static class Logging
7 | {
8 | public static ILoggerFactory Factory { get; } = new LoggerFactory();
9 |
10 | internal static ILogger GetCurrentClassLogger()
11 | {
12 | return Factory.CreateLogger(
13 | new StackFrame(1).GetMethod().DeclaringType
14 | );
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/CurlThin/SafeHandles/SafeEasyHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace CurlThin.SafeHandles
5 | {
6 | public sealed class SafeEasyHandle : SafeHandle
7 | {
8 | private SafeEasyHandle() : base(IntPtr.Zero, false)
9 | {
10 | }
11 |
12 | public override bool IsInvalid => handle == IntPtr.Zero;
13 |
14 | protected override bool ReleaseHandle()
15 | {
16 | CurlNative.Easy.Cleanup(handle);
17 | return true;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CurlThin/SafeHandles/SafeMultiHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace CurlThin.SafeHandles
5 | {
6 | public sealed class SafeMultiHandle : SafeHandle
7 | {
8 | private SafeMultiHandle() : base(IntPtr.Zero, false)
9 | {
10 | }
11 |
12 | public override bool IsInvalid => handle == IntPtr.Zero;
13 |
14 | protected override bool ReleaseHandle()
15 | {
16 | CurlNative.Multi.Cleanup(handle);
17 | return true;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/IntPtrEqualityComparer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace CurlThin.HyperPipe
5 | {
6 | ///
7 | /// Equality comparer for struct.
8 | ///
9 | internal class IntPtrEqualityComparer : IEqualityComparer
10 | {
11 | public bool Equals(IntPtr x, IntPtr y)
12 | {
13 | return x == y;
14 | }
15 |
16 | public int GetHashCode(IntPtr obj)
17 | {
18 | return obj.GetHashCode();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLMSG.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | [SuppressMessage("ReSharper", "InconsistentNaming")]
6 | public enum CURLMSG
7 | {
8 | ///
9 | /// First, not used.
10 | ///
11 | NONE,
12 |
13 | ///
14 | /// This easy handle has completed. 'result' contains the CURLcode of the transfer.
15 | ///
16 | DONE,
17 |
18 | ///
19 | /// Last, not used.
20 | ///
21 | LAST
22 | }
23 | }
--------------------------------------------------------------------------------
/CurlThin/SafeHandles/SafeSlistHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace CurlThin.SafeHandles
5 | {
6 | public sealed class SafeSlistHandle : SafeHandle
7 | {
8 | private SafeSlistHandle() : base(IntPtr.Zero, false)
9 | {
10 | }
11 |
12 | public override bool IsInvalid => handle == IntPtr.Zero;
13 |
14 | public static SafeSlistHandle Null => new SafeSlistHandle();
15 |
16 | protected override bool ReleaseHandle()
17 | {
18 | CurlNative.Slist.FreeAll(this);
19 | return true;
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/CurlThin.Samples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | PreserveNewest
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/CurlThin.Native/CurlThin.Native.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Contains x86 and x64 native libcurl binaries for Windows. Current libcurl version: 7.69.1 released on the 11th of March 2020.
5 | libcurl native binaries x86 x64
6 | icon.png
7 |
8 |
9 |
10 | netstandard2.1
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/CurlThin.Tests/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/CurlThin/SafeHandles/SafeSocketHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace CurlThin.SafeHandles
5 | {
6 | public sealed class SafeSocketHandle : SafeHandle
7 | {
8 | private SafeSocketHandle() : base(new IntPtr(-1), false)
9 | {
10 | }
11 |
12 | public override bool IsInvalid => handle == new IntPtr(-1);
13 |
14 | public static SafeSocketHandle Invalid = new IntPtr(-1);
15 |
16 | protected override bool ReleaseHandle()
17 | {
18 | throw new NotImplementedException();
19 | }
20 |
21 | public static implicit operator SafeSocketHandle(IntPtr ptr)
22 | {
23 | var handle = new SafeSocketHandle();
24 | handle.SetHandle(ptr);
25 | return handle;
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLpoll.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | [SuppressMessage("ReSharper", "InconsistentNaming")]
6 | public enum CURLpoll
7 | {
8 | ///
9 | /// Register, not interested in readiness (yet).
10 | ///
11 | NONE = 0,
12 |
13 | ///
14 | /// Register, interested in read readiness.
15 | ///
16 | IN = 1,
17 |
18 | ///
19 | /// Register, interested in write readiness.
20 | ///
21 | OUT = 2,
22 |
23 | ///
24 | /// Register, interested in both read and write readiness.
25 | ///
26 | INOUT = 3,
27 |
28 | ///
29 | /// Unregister.
30 | ///
31 | REMOVE = 4
32 | }
33 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/CurlThin.Native/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.RegularExpressions;
2 |
3 | namespace CurlThin.Native
4 | {
5 | public static class StringExtensions
6 | {
7 | ///
8 | /// Compares the string against a given pattern.
9 | ///
10 | /// The string.
11 | ///
12 | /// The pattern to match, where "*" means any sequence of characters, and "?" means any single
13 | /// character.
14 | ///
15 | /// true if the string matches the given pattern; otherwise false.
16 | public static bool Like(this string str, string pattern)
17 | {
18 | return new Regex(
19 | Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", "."),
20 | RegexOptions.IgnoreCase | RegexOptions.Singleline
21 | ).IsMatch(str);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/HandleCompletedAction.cs:
--------------------------------------------------------------------------------
1 | namespace CurlThin.HyperPipe
2 | {
3 | ///
4 | /// What should be done after handle has completed its work?
5 | ///
6 | public enum HandleCompletedAction
7 | {
8 | ///
9 | /// Reuse the handle with all its options unchanged and attach it to again.
10 | /// Useful for example if your request has failed and you want to try again.
11 | /// If you return this value, won't call .
12 | ///
13 | ReuseHandleAndRetry,
14 |
15 | ///
16 | /// Reset the handle with . You'll have to set up the handle from scratch in your
17 | /// implementation of .
18 | ///
19 | ResetHandleAndNext
20 | }
21 | }
--------------------------------------------------------------------------------
/azure-pipelines.yml:
--------------------------------------------------------------------------------
1 | # ASP.NET Core (.NET Framework)
2 | # Build and test ASP.NET Core projects targeting the full .NET Framework.
3 | # Add steps that publish symbols, save build artifacts, and more:
4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
5 |
6 | trigger:
7 | - master
8 |
9 | pool:
10 | vmImage: 'windows-latest'
11 |
12 | variables:
13 | solution: '**/*.sln'
14 | buildPlatform: 'Any CPU'
15 | buildConfiguration: 'Release'
16 |
17 | steps:
18 | - task: UsePythonVersion@0
19 | inputs:
20 | versionSpec: '3.x'
21 | addToPath: true
22 | architecture: 'x64'
23 |
24 | - task: PythonScript@0
25 | inputs:
26 | scriptSource: 'filePath'
27 | scriptPath: 'CurlThin.Native/pack_curl_native.py'
28 | arguments: '--libcurl-version=$(LIBCURL_VER) --openssl-version=$(OPENSSL_VER) --clean'
29 |
30 | - task: DotNetCoreCLI@2
31 | inputs:
32 | command: 'build'
33 | projects: '$(solution)'
34 | feedsToUse: 'select'
35 | versioningScheme: 'off'
36 |
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/IRequestProvider.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using CurlThin.SafeHandles;
3 |
4 | namespace CurlThin.HyperPipe
5 | {
6 | ///
7 | /// Provides requests to
8 | ///
9 | ///
10 | public interface IRequestProvider
11 | {
12 | ///
13 | /// Gets the current element in the collection.
14 | ///
15 | T Current { get; }
16 |
17 | ///
18 | /// Advances the enumerator to the next element of the collection asynchronously.
19 | ///
20 | ///
21 | /// Returns a Task that does transition to the next element. The result of the task is True if the enumerator was
22 | /// successfully advanced to the next element, or False if the enumerator has passed the end of the collection.
23 | ///
24 | ValueTask MoveNextAsync(SafeEasyHandle easy);
25 | }
26 | }
--------------------------------------------------------------------------------
/CurlThin/CurlThin.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | Thin libcurl wrapper for C#. Keeps original enum naming, so you can easily switch if you already know libcurl. Provides convenient access to concurrent curl_multi interface with polling.
6 | https://github.com/stil/CurlThin
7 | https://github.com/stil/CurlThin
8 | curl libcurl http
9 | icon.png
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/CurlThin.Tests/CurlThin.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers; buildtransitive
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | Always
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Author:
2 | Aaron Bockover
3 |
4 | Copyright 2014 Aaron Bockover
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 | of the Software, and to permit persons to whom the Software is furnished to do
11 | so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/SocketPollMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using NetUV.Core.Handles;
4 |
5 | namespace CurlThin.HyperPipe
6 | {
7 | internal class SocketPollMap : IDisposable
8 | {
9 | private readonly ConcurrentDictionary _sockets
10 | = new ConcurrentDictionary(new IntPtrEqualityComparer());
11 |
12 | public void Dispose()
13 | {
14 | foreach (var poll in _sockets.Values)
15 | {
16 | poll.Stop();
17 | poll.Dispose();
18 | }
19 | }
20 |
21 | public Poll GetOrCreatePoll(IntPtr sockfd, Loop loop)
22 | {
23 | if (!_sockets.TryGetValue(sockfd, out Poll poll))
24 | {
25 | poll = loop.CreatePoll(sockfd);
26 | _sockets.TryAdd(sockfd, poll);
27 | }
28 |
29 | return poll;
30 | }
31 |
32 | public void RemovePoll(IntPtr sockfd)
33 | {
34 | if (_sockets.TryRemove(sockfd, out Poll poll))
35 | {
36 | poll.Stop();
37 | poll.Dispose();
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLPROTO.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics.CodeAnalysis;
3 |
4 | namespace CurlThin.Enums
5 | {
6 | ///
7 | /// Reference: https://github.com/curl/curl/blob/master/include/curl/curl.h
8 | ///
9 | [Flags]
10 | [SuppressMessage("ReSharper", "InconsistentNaming")]
11 | public enum CURLPROTO
12 | {
13 | HTTP = 1<<0,
14 | HTTPS = 1<<1,
15 | FTP = 1<<2,
16 | FTPS = 1<<3,
17 | SCP = 1<<4,
18 | SFTP = 1<<5,
19 | TELNET = 1<<6,
20 | LDAP = 1<<7,
21 | LDAPS = 1<<8,
22 | DICT = 1<<9,
23 | FILE = 1<<10,
24 | TFTP = 1<<11,
25 | IMAP = 1<<12,
26 | IMAPS = 1<<13,
27 | POP3 = 1<<14,
28 | POP3S = 1<<15,
29 | SMTP = 1<<16,
30 | SMTPS = 1<<17,
31 | RTSP = 1<<18,
32 | RTMP = 1<<19,
33 | RTMPT = 1<<20,
34 | RTMPE = 1<<21,
35 | RTMPTE = 1<<22,
36 | RTMPS = 1<<23,
37 | RTMPTS = 1<<24,
38 | GOPHER = 1<<25,
39 | SMB = 1<<26,
40 | SMBS = 1<<27,
41 |
42 | ///
43 | /// Enable everything.
44 | ///
45 | ALL = ~0
46 | }
47 | }
--------------------------------------------------------------------------------
/CurlThin/Helpers/DataCallbackCopier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace CurlThin.Helpers
6 | {
7 | public class DataCallbackCopier : IDisposable
8 | {
9 | public DataCallbackCopier()
10 | {
11 | DataHandler = (data, size, nmemb, userdata) =>
12 | {
13 | var length = (int) size * (int) nmemb;
14 | var buffer = new byte[length];
15 | Marshal.Copy(data, buffer, 0, length);
16 | Stream.Write(buffer, 0, length);
17 | return (UIntPtr) length;
18 | };
19 | }
20 |
21 | public MemoryStream Stream { get; } = new MemoryStream();
22 |
23 | public CurlNative.Easy.DataHandler DataHandler { get; }
24 |
25 | public void Dispose()
26 | {
27 | Stream?.Dispose();
28 | }
29 |
30 | public void Reset()
31 | {
32 | Stream.Position = 0;
33 | Stream.SetLength(0);
34 | }
35 |
36 | public string ReadAsString()
37 | {
38 | Stream.Seek(0, SeekOrigin.Begin);
39 | var reader = new StreamReader(Stream);
40 | return reader.ReadToEnd();
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/IResponseConsumer.cs:
--------------------------------------------------------------------------------
1 | using CurlThin.Enums;
2 | using CurlThin.SafeHandles;
3 |
4 | namespace CurlThin.HyperPipe
5 | {
6 | ///
7 | /// This interface defines class that should consume completed cURL requests.
8 | ///
9 | /// Your custom request context type.
10 | public interface IResponseConsumer
11 | {
12 | ///
13 | /// Implement this method to process completed cURL requests. For example you can call
14 | /// curl_easy_getinfo() to extract information from cURL handle such as HTTP response code
15 | /// or total request time.
16 | ///
17 | ///
18 | /// cURL easy handle. You MUST NOT dispose it. Use this handle to for example pass it to
19 | /// curl_easy_getinfo().
20 | ///
21 | /// Request context. You should use it to recognize "which one request it was".
22 | /// Error code. On success it's
23 | /// This method returns one of actions that will be taken after this request is processed.
24 | HandleCompletedAction OnComplete(SafeEasyHandle easy, T context, CURLcode errorCode);
25 | }
26 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/Easy/GetSample.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using CurlThin.Enums;
4 | using CurlThin.Helpers;
5 |
6 | namespace CurlThin.Samples.Easy
7 | {
8 | internal class GetSample : ISample
9 | {
10 | public void Run()
11 | {
12 | // curl_global_init() with default flags.
13 | var global = CurlNative.Init();
14 |
15 | // curl_easy_init() to create easy handle.
16 | var easy = CurlNative.Easy.Init();
17 | try
18 | {
19 | var dataCopier = new DataCallbackCopier();
20 |
21 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, "http://httpbin.org/ip");
22 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, dataCopier.DataHandler);
23 |
24 | var result = CurlNative.Easy.Perform(easy);
25 |
26 | Console.WriteLine($"Result code: {result}.");
27 | Console.WriteLine();
28 | Console.WriteLine("Response body:");
29 | Console.WriteLine(Encoding.UTF8.GetString(dataCopier.Stream.ToArray()));
30 | }
31 | finally
32 | {
33 | easy.Dispose();
34 |
35 | if (global == CURLcode.OK)
36 | {
37 | CurlNative.Cleanup();
38 | }
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using CurlThin.Native;
6 |
7 | namespace CurlThin.Samples
8 | {
9 | internal class Program
10 | {
11 | private static void Main(string[] args)
12 | {
13 | CurlResources.Init();
14 |
15 | var samples = FindSamples();
16 |
17 | Console.WriteLine("Available samples:");
18 | for (var i = 0; i < samples.Count; i++)
19 | {
20 | Console.WriteLine($"{i+1}. {samples[i].GetType().FullName}");
21 | }
22 |
23 | Console.Write($"Which one do you choose [1-{samples.Count}]: ");
24 | var selection = int.Parse(Console.ReadLine());
25 | Console.WriteLine();
26 | Console.WriteLine();
27 |
28 | samples[selection-1].Run();
29 |
30 | Console.WriteLine();
31 | Console.WriteLine();
32 | Console.WriteLine("Finished! Press ENTER to exit...");
33 | Console.ReadLine();
34 | }
35 |
36 | private static List FindSamples() where T : class
37 | {
38 | return typeof(Program).GetTypeInfo()
39 | .Assembly.GetTypes()
40 | .Where(t => t.GetInterfaces().Contains(typeof(T)) && t.GetConstructor(Type.EmptyTypes) != null)
41 | .Select(t => Activator.CreateInstance(t) as T)
42 | .OrderBy(arg => arg?.GetType().FullName)
43 | .ToList();
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLMcode.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | ///
6 | /// Reference: https://github.com/curl/curl/blob/master/include/curl/multi.h
7 | ///
8 | [SuppressMessage("ReSharper", "InconsistentNaming")]
9 | public enum CURLMcode
10 | {
11 | ///
12 | /// Please call curl_multi_perform() or curl_multi_socket*() soon.
13 | ///
14 | CALL_MULTI_PERFORM = -1,
15 |
16 | OK,
17 |
18 | ///
19 | /// The passed-in handle is not a valid CURLM handle.
20 | ///
21 | BAD_HANDLE,
22 |
23 | ///
24 | /// An easy handle was not good/valid.
25 | ///
26 | BAD_EASY_HANDLE,
27 |
28 | ///
29 | /// If you ever get this, you're in deep sh*t.
30 | ///
31 | OUT_OF_MEMORY,
32 |
33 | ///
34 | /// This is a libcurl bug.
35 | ///
36 | INTERNAL_ERROR,
37 |
38 | ///
39 | /// The passed in socket argument did not match.
40 | ///
41 | BAD_SOCKET,
42 |
43 | ///
44 | /// curl_multi_setopt() with unsupported option.
45 | ///
46 | UNKNOWN_OPTION,
47 |
48 | ///
49 | /// An easy handle already added to a multi handle was attempted to get added - again.
50 | ///
51 | ADDED_ALREADY,
52 |
53 | LAST
54 | }
55 | }
--------------------------------------------------------------------------------
/CurlThin/CurlException.cs:
--------------------------------------------------------------------------------
1 | //
2 | // CurlException.cs
3 | //
4 | // Author:
5 | // Aaron Bockover
6 | //
7 | // Copyright 2014 Aaron Bockover
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 |
27 | using System;
28 | using CurlThin.Enums;
29 |
30 | namespace CurlThin
31 | {
32 | public class CurlException : Exception
33 | {
34 | public CurlException (string format, params object [] args) : base (string.Format (format, args))
35 | {
36 | }
37 |
38 | public CurlException (CURLcode code) : base (code.ToString ())
39 | {
40 | }
41 |
42 | public CurlException (CURLMcode code) : base (code.ToString ())
43 | {
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/Easy/PostSample.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using CurlThin.Enums;
4 | using CurlThin.Helpers;
5 |
6 | namespace CurlThin.Samples.Easy
7 | {
8 | internal class PostSample : ISample
9 | {
10 | public void Run()
11 | {
12 | // curl_global_init() with default flags.
13 | var global = CurlNative.Init();
14 |
15 | // curl_easy_init() to create easy handle.
16 | var easy = CurlNative.Easy.Init();
17 | try
18 | {
19 | var postData = "fieldname1=fieldvalue1&fieldname2=fieldvalue2";
20 |
21 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, "http://httpbin.org/post");
22 |
23 | // This one has to be called before setting COPYPOSTFIELDS.
24 | CurlNative.Easy.SetOpt(easy, CURLoption.POSTFIELDSIZE, Encoding.ASCII.GetByteCount(postData));
25 | CurlNative.Easy.SetOpt(easy, CURLoption.COPYPOSTFIELDS, postData);
26 |
27 | var dataCopier = new DataCallbackCopier();
28 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, dataCopier.DataHandler);
29 |
30 | var result = CurlNative.Easy.Perform(easy);
31 |
32 | Console.WriteLine($"Result code: {result}.");
33 | Console.WriteLine();
34 | Console.WriteLine("Response body:");
35 | Console.WriteLine(Encoding.UTF8.GetString(dataCopier.Stream.ToArray()));
36 | }
37 | finally
38 | {
39 | easy.Dispose();
40 |
41 | if (global == CURLcode.OK)
42 | {
43 | CurlNative.Cleanup();
44 | }
45 | }
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/CurlThin.Native/PackCurlNative.ps1:
--------------------------------------------------------------------------------
1 | function GetLibcurlArch($arch, $version)
2 | {
3 | Invoke-WebRequest `
4 | "https://bintray.com/artifact/download/vszakats/generic/curl-$version-$arch-mingw.zip" `
5 | -OutFile "curl-$arch-mingw.zip"
6 |
7 | Expand-Archive -Path "curl-$arch-mingw.zip" -DestinationPath "."
8 | Remove-Item "curl-$arch-mingw.zip"
9 |
10 | if ($arch -eq "win32")
11 | {
12 | $libcurlDll = "libcurl.dll"
13 | }
14 | else
15 | {
16 | $libcurlDll = "libcurl-x64.dll"
17 | }
18 |
19 | Copy-Item -Path "curl-$version-$arch-mingw\bin\$libcurlDll" -Destination "$arch\libcurl.dll"
20 | Copy-Item -Path "curl-$version-$arch-mingw\bin\*.crt" -Destination "$arch\"
21 | Remove-Item -Recurse "curl-$version-$arch-mingw"
22 | }
23 |
24 | function GetOpensslArch($arch, $version)
25 | {
26 | Invoke-WebRequest `
27 | "https://bintray.com/artifact/download/vszakats/generic/openssl-$version-$arch-mingw.zip" `
28 | -OutFile "openssl-$arch-mingw.zip"
29 |
30 | Expand-Archive -Path "openssl-$arch-mingw.zip" -DestinationPath "."
31 | Remove-Item "openssl-$arch-mingw.zip"
32 | Copy-Item -Path "openssl-$version-$arch-mingw\*.dll" -Destination "$arch\"
33 | Remove-Item -Recurse "openssl-$version-$arch-mingw"
34 | }
35 |
36 | New-Item -Name win64 -ItemType "directory"
37 | New-Item -Name win32 -ItemType "directory"
38 |
39 | GetLibcurlArch win64 "7.69.1"
40 | GetLibcurlArch win32 "7.69.1"
41 |
42 | GetOpensslArch win64 "1.1.1f"
43 | GetOpensslArch win32 "1.1.1f"
44 |
45 | $compress = @{
46 | Path = "win64", "win32"
47 | CompressionLevel = "Optimal"
48 | DestinationPath = "Resources.zip"
49 | }
50 |
51 | Compress-Archive @compress
52 |
53 | Remove-Item -Recurse win64
54 | Remove-Item -Recurse win32
--------------------------------------------------------------------------------
/CurlThin.Samples/Easy/HttpHeadersSample.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using CurlThin.Enums;
4 | using CurlThin.Helpers;
5 | using CurlThin.SafeHandles;
6 |
7 | namespace CurlThin.Samples.Easy
8 | {
9 | internal class HttpHeadersSample : ISample
10 | {
11 | public void Run()
12 | {
13 | // curl_global_init() with default flags.
14 | var global = CurlNative.Init();
15 |
16 | // curl_easy_init() to create easy handle.
17 | var easy = CurlNative.Easy.Init();
18 | try
19 | {
20 | var dataCopier = new DataCallbackCopier();
21 |
22 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, "http://httpbin.org/headers");
23 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, dataCopier.DataHandler);
24 |
25 | // Initialize HTTP header list with first value.
26 | var headers = CurlNative.Slist.Append(SafeSlistHandle.Null, "X-Foo: Bar");
27 | // Add one more value to existing HTTP header list.
28 | CurlNative.Slist.Append(headers, "X-Qwerty: Asdfgh");
29 |
30 | // Configure libcurl easy handle to send HTTP headers we configured.
31 | CurlNative.Easy.SetOpt(easy, CURLoption.HTTPHEADER, headers.DangerousGetHandle());
32 |
33 | var result = CurlNative.Easy.Perform(easy);
34 |
35 | // Cleanup HTTP header list after request has complete.
36 | CurlNative.Slist.FreeAll(headers);
37 |
38 | Console.WriteLine($"Result code: {result}.");
39 | Console.WriteLine();
40 | Console.WriteLine("Response body:");
41 | Console.WriteLine(Encoding.UTF8.GetString(dataCopier.Stream.ToArray()));
42 | }
43 | finally
44 | {
45 | easy.Dispose();
46 |
47 | if (global == CURLcode.OK)
48 | {
49 | CurlNative.Cleanup();
50 | }
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLglobal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics.CodeAnalysis;
3 |
4 | namespace CurlThin.Enums
5 | {
6 | ///
7 | /// Contains values used to initialize libcurl internally. One of
8 | /// these is passed in the call to .
9 | ///
10 | [Flags]
11 | [SuppressMessage("ReSharper", "InconsistentNaming")]
12 | public enum CURLglobal
13 | {
14 | ///
15 | /// Initialise nothing extra. This sets no bit.
16 | ///
17 | NOTHING = 0,
18 |
19 | ///
20 | /// Initialize SSL.
21 | /// The implication here is that if this bit is not set, the initialization of the SSL layer needs to be done by the
22 | /// application or at least outside of libcurl. The exact procedure how to do SSL initializtion depends on the
23 | /// TLS backend libcurl uses.
24 | /// Doing TLS based transfers without having the TLS layer initialized may lead to unexpected behaviors.
25 | ///
26 | SSL = 1 << 0,
27 |
28 | ///
29 | /// Initialize the Win32 socket libraries.
30 | /// The implication here is that if this bit is not set, the initialization of winsock has to be done by the
31 | /// application or you risk getting undefined behaviors. This option exists for when the initialization is
32 | /// handled outside of libcurl so there's no need for libcurl to do it again.
33 | ///
34 | WIN32 = 1 << 1,
35 |
36 | ///
37 | /// When this flag is set, curl will acknowledge EINTR condition when connecting or when waiting for data.
38 | /// Otherwise, curl waits until full timeout elapses. (Added in 7.30.0)
39 | ///
40 | ACK_EINTR = 1 << 2,
41 |
42 | ///
43 | /// Initialize everything possible. This sets all known bits except .
44 | ///
45 | ALL = SSL | WIN32,
46 |
47 | ///
48 | /// A sensible default. It will init both SSL and Win32. Right now, this equals the functionality of the
49 | /// mask.
50 | ///
51 | DEFAULT = ALL
52 | }
53 | }
--------------------------------------------------------------------------------
/CurlThin.Native/CurlResources.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.IO.Compression;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Runtime.InteropServices;
7 |
8 | namespace CurlThin.Native
9 | {
10 | public static class CurlResources
11 | {
12 | private const string CaBundleFilename = "curl-ca-bundle.crt";
13 |
14 | private static readonly DirectoryInfo OutputDir;
15 |
16 | private static readonly FileInfo CaBundleFile;
17 |
18 | static CurlResources()
19 | {
20 | OutputDir = new DirectoryInfo(Assembly.GetEntryAssembly().Location).Parent;
21 | CaBundleFile = new FileInfo(Path.Combine(OutputDir.FullName, CaBundleFilename));
22 | }
23 |
24 | public static string CaBundlePath
25 | {
26 | get
27 | {
28 | if (!CaBundleFile.Exists)
29 | {
30 | throw new FileNotFoundException($"{CaBundleFilename} is missing.");
31 | }
32 | return CaBundleFile.FullName;
33 | }
34 | }
35 |
36 | public static void Init()
37 | {
38 | ExtractResource(CaBundleFilename, OutputDir);
39 |
40 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
41 | {
42 | SetDllDirectory(OutputDir.FullName);
43 | ExtractResource(Environment.Is64BitProcess ? "win64/*.dll" : "win32/*.dll", OutputDir);
44 | }
45 | }
46 |
47 | private static void ExtractResource(string resourcePath, DirectoryInfo outputDir)
48 | {
49 | var assembly = typeof(CurlResources).GetTypeInfo().Assembly;
50 |
51 | // We keep our resources in ZIP file to cut assembly size.
52 | // Also, ZIP archive retains file modification timestamps.
53 | var zipResource = assembly.GetManifestResourceNames()
54 | .First(name => name.Like("Resources.zip"));
55 |
56 | using (var zipStream = assembly.GetManifestResourceStream(zipResource))
57 | using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read))
58 | {
59 | foreach (var entry in archive.Entries.Where(e => e.FullName.Replace('\\', '/').Like(resourcePath)))
60 | {
61 | var outputPath = new FileInfo(Path.Combine(outputDir.FullName, entry.Name));
62 |
63 | // Extract if not exist or overwrite if filesizes mismatch.
64 | if (!outputPath.Exists || outputPath.Length != entry.Length)
65 | {
66 | entry.ExtractToFile(outputPath.FullName, true);
67 | }
68 | }
69 | }
70 | }
71 |
72 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
73 | [return: MarshalAs(UnmanagedType.Bool)]
74 | private static extern bool SetDllDirectory(string lpPathName);
75 | }
76 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLMoption.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | ///
6 | /// Reference: https://github.com/curl/curl/blob/master/include/curl/multi.h
7 | ///
8 | [SuppressMessage("ReSharper", "InconsistentNaming")]
9 | public enum CURLMoption : uint
10 | {
11 | ///
12 | /// This is the socket callback function pointer.
13 | ///
14 | SOCKETFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 1,
15 |
16 | ///
17 | /// This is the argument passed to the socket callback.
18 | ///
19 | SOCKETDATA = CURLOPTTYPE.OBJECTPOINT + 2,
20 |
21 | ///
22 | /// Set to 1 to enable pipelining for this multi handle.
23 | ///
24 | PIPELINING = CURLOPTTYPE.LONG + 3,
25 |
26 | ///
27 | /// This is the timer callback function pointer.
28 | ///
29 | TIMERFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 4,
30 |
31 | ///
32 | /// This is the argument passed to the timer callback.
33 | ///
34 | TIMERDATA = CURLOPTTYPE.OBJECTPOINT + 5,
35 |
36 | ///
37 | /// Maximum number of entries in the connection cache.
38 | ///
39 | MAXCONNECTS = CURLOPTTYPE.LONG + 6,
40 |
41 | ///
42 | /// Maximum number of (pipelining) connections to one host.
43 | ///
44 | MAX_HOST_CONNECTIONS = CURLOPTTYPE.LONG + 7,
45 |
46 | /* maximum number of requests in a pipeline */
47 | MAX_PIPELINE_LENGTH = CURLOPTTYPE.LONG + 8,
48 |
49 | ///
50 | /// A connection with a content-length longer than this will not be considered for pipelining.
51 | ///
52 | CONTENT_LENGTH_PENALTY_SIZE = CURLOPTTYPE.OFF_T + 9,
53 |
54 | ///
55 | /// A connection with a chunk length longer than this will not be considered for pipelining.
56 | ///
57 | CHUNK_LENGTH_PENALTY_SIZE = CURLOPTTYPE.OFF_T + 10,
58 |
59 | ///
60 | /// A list of site names(+port) that are blacklisted from pipelining.
61 | ///
62 | PIPELINING_SITE_BL = CURLOPTTYPE.OBJECTPOINT + 11,
63 |
64 | ///
65 | /// A list of server types that are blacklisted from pipelining.
66 | ///
67 | PIPELINING_SERVER_BL = CURLOPTTYPE.OBJECTPOINT + 12,
68 |
69 | ///
70 | /// Maximum number of open connections in total.
71 | ///
72 | MAX_TOTAL_CONNECTIONS = CURLOPTTYPE.LONG + 13,
73 |
74 | ///
75 | /// This is the server push callback function pointer.
76 | ///
77 | PUSHFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 14,
78 |
79 | ///
80 | /// This is the argument passed to the server push callback.
81 | ///
82 | PUSHDATA = CURLOPTTYPE.OBJECTPOINT + 15,
83 |
84 | ///
85 | /// The last unused.
86 | ///
87 | CURLMOPT_LASTENTRY
88 | }
89 | }
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/EasyPool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Collections.Immutable;
4 | using CurlThin.SafeHandles;
5 |
6 | namespace CurlThin.HyperPipe
7 | {
8 | internal class EasyPool : IDisposable
9 | {
10 | private readonly ConcurrentDictionary _busy;
11 | private readonly ConcurrentBag _free;
12 | private readonly ImmutableDictionary _pool;
13 |
14 | public EasyPool(int size)
15 | {
16 | Size = size;
17 | var poolBuilder = ImmutableDictionary.CreateBuilder(
18 | new IntPtrEqualityComparer());
19 |
20 | for (var i = 0; i < size; i++)
21 | {
22 | var handle = CurlNative.Easy.Init();
23 | poolBuilder.Add(handle.DangerousGetHandle(), handle);
24 | }
25 |
26 | _pool = poolBuilder.ToImmutable();
27 | _free = new ConcurrentBag(_pool.Values);
28 | _busy = new ConcurrentDictionary();
29 | }
30 |
31 | ///
32 | /// Size of requests pool.
33 | ///
34 | public int Size { get; }
35 |
36 | ///
37 | /// Closes native cURL easy handles.
38 | ///
39 | public void Dispose()
40 | {
41 | foreach (var easyHandle in _pool)
42 | {
43 | CurlNative.Easy.Cleanup(easyHandle.Key);
44 | }
45 | }
46 |
47 | ///
48 | /// Retruns wrapped for given dangerous handle pointer.
49 | ///
50 | public SafeEasyHandle GetSafeHandleFromPtr(IntPtr handle)
51 | {
52 | return _pool[handle];
53 | }
54 |
55 | ///
56 | /// Try get unused cURL easy handle.
57 | ///
58 | /// TRUE if successful, FALSE if all handles are busy.
59 | public bool TryTakeFree(out SafeEasyHandle easy)
60 | {
61 | return _free.TryTake(out easy);
62 | }
63 |
64 | ///
65 | /// Change status of cURL easy handle from busy to free.
66 | ///
67 | public void Free(SafeEasyHandle easy)
68 | {
69 | _free.Add(easy);
70 | }
71 |
72 | ///
73 | /// Assigns request context to given easy handle.
74 | ///
75 | public void AssignContext(SafeEasyHandle easy, T context)
76 | {
77 | if (!_busy.TryAdd(easy, context))
78 | {
79 | throw new Exception("Trying to assign request context to handle that already has its context.");
80 | }
81 | }
82 |
83 | ///
84 | /// Retrieves request context for given easy handle.
85 | ///
86 | public void GetAssignedContext(SafeEasyHandle easy, out T context)
87 | {
88 | if (!_busy.TryGetValue(easy, out context))
89 | {
90 | throw new Exception("Cannot find request context for given easy handle.");
91 | }
92 | }
93 |
94 | ///
95 | /// Unassigns request context for given easy handle.
96 | ///
97 | public void UnassignContext(SafeEasyHandle easy)
98 | {
99 | if (!_busy.TryRemove(easy, out T _))
100 | {
101 | throw new Exception("Given handle doesn't have stored any request context.");
102 | }
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLINFO.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | ///
6 | /// Reference: https://github.com/curl/curl/blob/master/include/curl/curl.h
7 | ///
8 | [SuppressMessage("ReSharper", "InconsistentNaming")]
9 | internal static class CURLINFOTYPE
10 | {
11 | public const uint STRING = 0x100000;
12 | public const uint LONG = 0x200000;
13 | public const uint DOUBLE = 0x300000;
14 | public const uint SLIST = 0x400000;
15 | public const uint PTR = 0x400000; // same as SLIST
16 | public const uint SOCKET = 0x500000;
17 | public const uint OFF_T = 0x600000;
18 | public const uint MASK = 0x0fffff;
19 | public const uint TYPEMASK = 0xf00000;
20 | }
21 |
22 | [SuppressMessage("ReSharper", "InconsistentNaming")]
23 | public enum CURLINFO : uint
24 | {
25 | NONE, // First, never use this.
26 | EFFECTIVE_URL = CURLINFOTYPE.STRING + 1,
27 | RESPONSE_CODE = CURLINFOTYPE.LONG + 2,
28 | TOTAL_TIME = CURLINFOTYPE.DOUBLE + 3,
29 | NAMELOOKUP_TIME = CURLINFOTYPE.DOUBLE + 4,
30 | CONNECT_TIME = CURLINFOTYPE.DOUBLE + 5,
31 | PRETRANSFER_TIME = CURLINFOTYPE.DOUBLE + 6,
32 | SIZE_UPLOAD = CURLINFOTYPE.DOUBLE + 7,
33 | SIZE_UPLOAD_T = CURLINFOTYPE.OFF_T + 7,
34 | SIZE_DOWNLOAD = CURLINFOTYPE.DOUBLE + 8,
35 | SIZE_DOWNLOAD_T = CURLINFOTYPE.OFF_T + 8,
36 | SPEED_DOWNLOAD = CURLINFOTYPE.DOUBLE + 9,
37 | SPEED_DOWNLOAD_T = CURLINFOTYPE.OFF_T + 9,
38 | SPEED_UPLOAD = CURLINFOTYPE.DOUBLE + 10,
39 | SPEED_UPLOAD_T = CURLINFOTYPE.OFF_T + 10,
40 | HEADER_SIZE = CURLINFOTYPE.LONG + 11,
41 | REQUEST_SIZE = CURLINFOTYPE.LONG + 12,
42 | SSL_VERIFYRESULT = CURLINFOTYPE.LONG + 13,
43 | FILETIME = CURLINFOTYPE.LONG + 14,
44 | CONTENT_LENGTH_DOWNLOAD = CURLINFOTYPE.DOUBLE + 15,
45 | CONTENT_LENGTH_DOWNLOAD_T = CURLINFOTYPE.OFF_T + 15,
46 | CONTENT_LENGTH_UPLOAD = CURLINFOTYPE.DOUBLE + 16,
47 | CONTENT_LENGTH_UPLOAD_T = CURLINFOTYPE.OFF_T + 16,
48 | STARTTRANSFER_TIME = CURLINFOTYPE.DOUBLE + 17,
49 | CONTENT_TYPE = CURLINFOTYPE.STRING + 18,
50 | REDIRECT_TIME = CURLINFOTYPE.DOUBLE + 19,
51 | REDIRECT_COUNT = CURLINFOTYPE.LONG + 20,
52 | PRIVATE = CURLINFOTYPE.STRING + 21,
53 | HTTP_CONNECTCODE = CURLINFOTYPE.LONG + 22,
54 | HTTPAUTH_AVAIL = CURLINFOTYPE.LONG + 23,
55 | PROXYAUTH_AVAIL = CURLINFOTYPE.LONG + 24,
56 | OS_ERRNO = CURLINFOTYPE.LONG + 25,
57 | NUM_CONNECTS = CURLINFOTYPE.LONG + 26,
58 | SSL_ENGINES = CURLINFOTYPE.SLIST + 27,
59 | COOKIELIST = CURLINFOTYPE.SLIST + 28,
60 | LASTSOCKET = CURLINFOTYPE.LONG + 29,
61 | FTP_ENTRY_PATH = CURLINFOTYPE.STRING + 30,
62 | REDIRECT_URL = CURLINFOTYPE.STRING + 31,
63 | PRIMARY_IP = CURLINFOTYPE.STRING + 32,
64 | APPCONNECT_TIME = CURLINFOTYPE.DOUBLE + 33,
65 | CERTINFO = CURLINFOTYPE.PTR + 34,
66 | CONDITION_UNMET = CURLINFOTYPE.LONG + 35,
67 | RTSP_SESSION_ID = CURLINFOTYPE.STRING + 36,
68 | RTSP_CLIENT_CSEQ = CURLINFOTYPE.LONG + 37,
69 | RTSP_SERVER_CSEQ = CURLINFOTYPE.LONG + 38,
70 | RTSP_CSEQ_RECV = CURLINFOTYPE.LONG + 39,
71 | PRIMARY_PORT = CURLINFOTYPE.LONG + 40,
72 | LOCAL_IP = CURLINFOTYPE.STRING + 41,
73 | LOCAL_PORT = CURLINFOTYPE.LONG + 42,
74 | TLS_SESSION = CURLINFOTYPE.PTR + 43,
75 | ACTIVESOCKET = CURLINFOTYPE.SOCKET + 44,
76 | TLS_SSL_PTR = CURLINFOTYPE.PTR + 45,
77 | HTTP_VERSION = CURLINFOTYPE.LONG + 46,
78 | PROXY_SSL_VERIFYRESULT = CURLINFOTYPE.LONG + 47,
79 | PROTOCOL = CURLINFOTYPE.LONG + 48,
80 | SCHEME = CURLINFOTYPE.STRING + 49,
81 | // Fill in new entries below here!
82 |
83 | LASTONE = 49
84 | }
85 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CurlThin #
2 | [](https://gitter.im/CurlThin/Lobby)
3 |
4 |
5 | _CurlThin_ is a NET Standard compatible binding library against [libcurl](http://curl.haxx.se/libcurl).
6 | It includes a modern wrapper for `curl_multi` interface which uses polling with [libuv](https://libuv.org/) library instead of using inefficient `select`.
7 |
8 | _CurlThin_ has a very thin abstraction layer, which means that writing the code is as close as possible to writing purely in libcurl. libcurl has extensive documentation and relatively strong support of community and not having additional abstraction layer makes it easier to search solutions for your problems.
9 |
10 | Using this library is very much like working with cURL's raw C API.
11 |
12 | ### License ###
13 | Library is MIT licensed. NuGet icon made by [Freepik](http://www.freepik.com) and is licensed by [CC 3.0 BY](https://creativecommons.org/licenses/by/3.0/)
14 |
15 | ## Installation ##
16 |
17 | | Package | NuGet | MyGet | Description |
18 | |-----------|--------------|-------|--------------|
19 | | `CurlThin` | [](https://www.nuget.org/packages/CurlThin/) |  | The C# wrapper for libcurl. |
20 | | `CurlThin.Native` | [](https://www.nuget.org/packages/CurlThin.Native/) |  | Contains embedded libcurl native binaries for x86 and x64 Windows. |
21 |
22 | If you have `libcurl` or `libcurl.dll` already in your PATH directory, you don't need to install `CurlThin.Native` package. Once you have installed `CurlThin.Native` NuGet package, call following method just once before you use cURL:
23 |
24 | ```csharp
25 | CurlResources.Init();
26 | ```
27 |
28 | It will extract following files to your application output directory
29 |
30 | | Windows x86 | Windows x64 | Description |
31 | |-------------|-------------|-------------|
32 | | libcurl.dll | libcurl.dll | The multiprotocol file transfer library. |
33 | | libssl-1_1.dll | libssl-1_1-x64.dll | Portion of OpenSSL which supports TLS ( SSL and TLS Protocols), and depends on libcrypto. |
34 | | libcrypto-1_1.dll | libcrypto-1_1-x64.dll | Provides the fundamental cryptographic routines used by libssl. |
35 | | curl-ca-bundle.crt | curl-ca-bundle.crt | Certificate Authority (CA) bundle. You can use it via [`CURLOPT_CAINFO`](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html). |
36 |
37 | ## Examples ##
38 |
39 | ### Easy interface ###
40 |
41 | #### GET request ####
42 | ```csharp
43 | // curl_global_init() with default flags.
44 | var global = CurlNative.Init();
45 |
46 | // curl_easy_init() to create easy handle.
47 | var easy = CurlNative.Easy.Init();
48 | try
49 | {
50 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, "http://httpbin.org/ip");
51 |
52 | var stream = new MemoryStream();
53 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, (data, size, nmemb, user) =>
54 | {
55 | var length = (int) size * (int) nmemb;
56 | var buffer = new byte[length];
57 | Marshal.Copy(data, buffer, 0, length);
58 | stream.Write(buffer, 0, length);
59 | return (UIntPtr) length;
60 | });
61 |
62 | var result = CurlNative.Easy.Perform(easy);
63 |
64 | Console.WriteLine($"Result code: {result}.");
65 | Console.WriteLine();
66 | Console.WriteLine("Response body:");
67 | Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));
68 | }
69 | finally
70 | {
71 | easy.Dispose();
72 |
73 | if (global == CURLcode.OK)
74 | {
75 | CurlNative.Cleanup();
76 | }
77 | }
78 | ```
79 |
80 |
81 | #### POST request ####
82 | ```csharp
83 | // curl_global_init() with default flags.
84 | var global = CurlNative.Init();
85 |
86 | // curl_easy_init() to create easy handle.
87 | var easy = CurlNative.Easy.Init();
88 | try
89 | {
90 | var postData = "fieldname1=fieldvalue1&fieldname2=fieldvalue2";
91 |
92 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, "http://httpbin.org/post");
93 |
94 | // This one has to be called before setting COPYPOSTFIELDS.
95 | CurlNative.Easy.SetOpt(easy, CURLoption.POSTFIELDSIZE, Encoding.ASCII.GetByteCount(postData));
96 | CurlNative.Easy.SetOpt(easy, CURLoption.COPYPOSTFIELDS, postData);
97 |
98 | var stream = new MemoryStream();
99 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, (data, size, nmemb, user) =>
100 | {
101 | var length = (int) size * (int) nmemb;
102 | var buffer = new byte[length];
103 | Marshal.Copy(data, buffer, 0, length);
104 | stream.Write(buffer, 0, length);
105 | return (UIntPtr) length;
106 | });
107 |
108 | var result = CurlNative.Easy.Perform(easy);
109 |
110 | Console.WriteLine($"Result code: {result}.");
111 | Console.WriteLine();
112 | Console.WriteLine("Response body:");
113 | Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));
114 | }
115 | finally
116 | {
117 | easy.Dispose();
118 |
119 | if (global == CURLcode.OK)
120 | {
121 | CurlNative.Cleanup();
122 | }
123 | }
124 | ```
125 |
126 | ### Multi interface ###
127 |
128 | #### Web scrape StackOverflow questions ####
129 | See [Multi/HyperSample.cs](CurlThin.Samples/Multi/HyperSample.cs).
130 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/visualstudio
3 |
4 | ### VisualStudio ###
5 | ## Ignore Visual Studio temporary files, build results, and
6 | ## files generated by popular Visual Studio add-ons.
7 | ##
8 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
9 |
10 | # User-specific files
11 | *.suo
12 | *.user
13 | *.userosscache
14 | *.sln.docstates
15 |
16 | # User-specific files (MonoDevelop/Xamarin Studio)
17 | *.userprefs
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | bld/
27 | [Bb]in/
28 | [Oo]bj/
29 | [Ll]og/
30 |
31 | # Visual Studio 2015 cache/options directory
32 | .vs/
33 | # Uncomment if you have tasks that create the project's static files in wwwroot
34 | #wwwroot/
35 |
36 | # MSTest test Results
37 | [Tt]est[Rr]esult*/
38 | [Bb]uild[Ll]og.*
39 |
40 | # NUNIT
41 | *.VisualState.xml
42 | TestResult.xml
43 |
44 | # Build Results of an ATL Project
45 | [Dd]ebugPS/
46 | [Rr]eleasePS/
47 | dlldata.c
48 |
49 | # .NET Core
50 | project.lock.json
51 | project.fragment.lock.json
52 | artifacts/
53 | **/Properties/launchSettings.json
54 |
55 | *_i.c
56 | *_p.c
57 | *_i.h
58 | *.ilk
59 | *.meta
60 | *.obj
61 | *.pch
62 | *.pdb
63 | *.pgc
64 | *.pgd
65 | *.rsp
66 | *.sbr
67 | *.tlb
68 | *.tli
69 | *.tlh
70 | *.tmp
71 | *.tmp_proj
72 | *.log
73 | *.vspscc
74 | *.vssscc
75 | .builds
76 | *.pidb
77 | *.svclog
78 | *.scc
79 |
80 | # Chutzpah Test files
81 | _Chutzpah*
82 |
83 | # Visual C++ cache files
84 | ipch/
85 | *.aps
86 | *.ncb
87 | *.opendb
88 | *.opensdf
89 | *.sdf
90 | *.cachefile
91 | *.VC.db
92 | *.VC.VC.opendb
93 |
94 | # Visual Studio profiler
95 | *.psess
96 | *.vsp
97 | *.vspx
98 | *.sap
99 |
100 | # TFS 2012 Local Workspace
101 | $tf/
102 |
103 | # Guidance Automation Toolkit
104 | *.gpState
105 |
106 | # ReSharper is a .NET coding add-in
107 | _ReSharper*/
108 | *.[Rr]e[Ss]harper
109 | *.DotSettings.user
110 |
111 | # JustCode is a .NET coding add-in
112 | .JustCode
113 |
114 | # TeamCity is a build add-in
115 | _TeamCity*
116 |
117 | # DotCover is a Code Coverage Tool
118 | *.dotCover
119 |
120 | # Visual Studio code coverage results
121 | *.coverage
122 | *.coveragexml
123 |
124 | # NCrunch
125 | _NCrunch_*
126 | .*crunch*.local.xml
127 | nCrunchTemp_*
128 |
129 | # MightyMoose
130 | *.mm.*
131 | AutoTest.Net/
132 |
133 | # Web workbench (sass)
134 | .sass-cache/
135 |
136 | # Installshield output folder
137 | [Ee]xpress/
138 |
139 | # DocProject is a documentation generator add-in
140 | DocProject/buildhelp/
141 | DocProject/Help/*.HxT
142 | DocProject/Help/*.HxC
143 | DocProject/Help/*.hhc
144 | DocProject/Help/*.hhk
145 | DocProject/Help/*.hhp
146 | DocProject/Help/Html2
147 | DocProject/Help/html
148 |
149 | # Click-Once directory
150 | publish/
151 |
152 | # Publish Web Output
153 | *.[Pp]ublish.xml
154 | *.azurePubxml
155 | # TODO: Comment the next line if you want to checkin your web deploy settings
156 | # but database connection strings (with potential passwords) will be unencrypted
157 | *.pubxml
158 | *.publishproj
159 |
160 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
161 | # checkin your Azure Web App publish settings, but sensitive information contained
162 | # in these scripts will be unencrypted
163 | PublishScripts/
164 |
165 | # NuGet Packages
166 | *.nupkg
167 | # The packages folder can be ignored because of Package Restore
168 | **/packages/*
169 | # except build/, which is used as an MSBuild target.
170 | !**/packages/build/
171 | # Uncomment if necessary however generally it will be regenerated when needed
172 | #!**/packages/repositories.config
173 | # NuGet v3's project.json files produces more ignorable files
174 | *.nuget.props
175 | *.nuget.targets
176 |
177 | # Microsoft Azure Build Output
178 | csx/
179 | *.build.csdef
180 |
181 | # Microsoft Azure Emulator
182 | ecf/
183 | rcf/
184 |
185 | # Windows Store app package directories and files
186 | AppPackages/
187 | BundleArtifacts/
188 | Package.StoreAssociation.xml
189 | _pkginfo.txt
190 |
191 | # Visual Studio cache files
192 | # files ending in .cache can be ignored
193 | *.[Cc]ache
194 | # but keep track of directories ending in .cache
195 | !*.[Cc]ache/
196 |
197 | # Others
198 | ClientBin/
199 | ~$*
200 | *~
201 | *.dbmdl
202 | *.dbproj.schemaview
203 | *.jfm
204 | *.pfx
205 | *.publishsettings
206 | orleans.codegen.cs
207 |
208 | # Since there are multiple workflows, uncomment next line to ignore bower_components
209 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
210 | #bower_components/
211 |
212 | # RIA/Silverlight projects
213 | Generated_Code/
214 |
215 | # Backup & report files from converting an old project file
216 | # to a newer Visual Studio version. Backup files are not needed,
217 | # because we have git ;-)
218 | _UpgradeReport_Files/
219 | Backup*/
220 | UpgradeLog*.XML
221 | UpgradeLog*.htm
222 |
223 | # SQL Server files
224 | *.mdf
225 | *.ldf
226 | *.ndf
227 |
228 | # Business Intelligence projects
229 | *.rdl.data
230 | *.bim.layout
231 | *.bim_*.settings
232 |
233 | # Microsoft Fakes
234 | FakesAssemblies/
235 |
236 | # GhostDoc plugin setting file
237 | *.GhostDoc.xml
238 |
239 | # Node.js Tools for Visual Studio
240 | .ntvs_analysis.dat
241 | node_modules/
242 |
243 | # Typescript v1 declaration files
244 | typings/
245 |
246 | # Visual Studio 6 build log
247 | *.plg
248 |
249 | # Visual Studio 6 workspace options file
250 | *.opt
251 |
252 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
253 | *.vbw
254 |
255 | # Visual Studio LightSwitch build output
256 | **/*.HTMLClient/GeneratedArtifacts
257 | **/*.DesktopClient/GeneratedArtifacts
258 | **/*.DesktopClient/ModelManifest.xml
259 | **/*.Server/GeneratedArtifacts
260 | **/*.Server/ModelManifest.xml
261 | _Pvt_Extensions
262 |
263 | # Paket dependency manager
264 | .paket/paket.exe
265 | paket-files/
266 |
267 | # FAKE - F# Make
268 | .fake/
269 |
270 | # JetBrains Rider
271 | .idea/
272 | *.sln.iml
273 |
274 | # CodeRush
275 | .cr/
276 |
277 | # Python Tools for Visual Studio (PTVS)
278 | __pycache__/
279 | *.pyc
280 |
281 | # Cake - Uncomment if you are using it
282 | # tools/**
283 | # !tools/packages.config
284 |
285 | # Telerik's JustMock configuration file
286 | *.jmconfig
287 |
288 | # BizTalk build output
289 | *.btp.cs
290 | *.btm.cs
291 | *.odx.cs
292 | *.xsd.cs
293 |
294 | # End of https://www.gitignore.io/api/visualstudio
295 |
296 | CurlThin.Native/Resources.zip
297 | CurlThin.Native/build/
298 |
--------------------------------------------------------------------------------
/CurlThin/CurlNative.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using CurlThin.Enums;
4 | using CurlThin.SafeHandles;
5 |
6 | namespace CurlThin
7 | {
8 | ///
9 | /// Type mappings (C -> C#):
10 | /// - size_t -> UIntPtr
11 | /// - int -> int
12 | /// - long -> int
13 | ///
14 | public static class CurlNative
15 | {
16 | private const string LIBCURL = "libcurl";
17 |
18 | [DllImport(LIBCURL, EntryPoint = "curl_global_init")]
19 | public static extern CURLcode Init(CURLglobal flags = CURLglobal.DEFAULT);
20 |
21 | [DllImport(LIBCURL, EntryPoint = "curl_global_cleanup")]
22 | public static extern void Cleanup();
23 |
24 | public static class Easy
25 | {
26 | public delegate UIntPtr DataHandler(IntPtr data, UIntPtr size, UIntPtr nmemb, IntPtr userdata);
27 |
28 | [DllImport(LIBCURL, EntryPoint = "curl_easy_init")]
29 | public static extern SafeEasyHandle Init();
30 |
31 | [DllImport(LIBCURL, EntryPoint = "curl_easy_cleanup")]
32 | public static extern void Cleanup(IntPtr handle);
33 |
34 | [DllImport(LIBCURL, EntryPoint = "curl_easy_perform")]
35 | public static extern CURLcode Perform(SafeEasyHandle handle);
36 |
37 | [DllImport(LIBCURL, EntryPoint = "curl_easy_reset")]
38 | public static extern void Reset(SafeEasyHandle handle);
39 |
40 | [DllImport(LIBCURL, EntryPoint = "curl_easy_setopt")]
41 | public static extern CURLcode SetOpt(SafeEasyHandle handle, CURLoption option, int value);
42 |
43 | [DllImport(LIBCURL, EntryPoint = "curl_easy_setopt")]
44 | public static extern CURLcode SetOpt(SafeEasyHandle handle, CURLoption option, IntPtr value);
45 |
46 | [DllImport(LIBCURL, EntryPoint = "curl_easy_setopt", CharSet = CharSet.Ansi)]
47 | public static extern CURLcode SetOpt(SafeEasyHandle handle, CURLoption option, string value);
48 |
49 | [DllImport(LIBCURL, EntryPoint = "curl_easy_setopt")]
50 | public static extern CURLcode SetOpt(SafeEasyHandle handle, CURLoption option, DataHandler value);
51 |
52 | [DllImport(LIBCURL, EntryPoint = "curl_easy_getinfo")]
53 | public static extern CURLcode GetInfo(SafeEasyHandle handle, CURLINFO option, out int value);
54 |
55 | [DllImport(LIBCURL, EntryPoint = "curl_easy_getinfo")]
56 | public static extern CURLcode GetInfo(SafeEasyHandle handle, CURLINFO option, out IntPtr value);
57 |
58 | [DllImport(LIBCURL, EntryPoint = "curl_easy_getinfo")]
59 | public static extern CURLcode GetInfo(SafeEasyHandle handle, CURLINFO option, out double value);
60 |
61 | [DllImport(LIBCURL, EntryPoint = "curl_easy_getinfo", CharSet = CharSet.Ansi)]
62 | public static extern CURLcode GetInfo(SafeEasyHandle handle, CURLINFO option, IntPtr value);
63 |
64 | [DllImport(LIBCURL, EntryPoint = "curl_easy_strerror")]
65 | public static extern IntPtr StrError(CURLcode errornum);
66 | }
67 |
68 | public static class Multi
69 | {
70 | [DllImport(LIBCURL, EntryPoint = "curl_multi_init")]
71 | public static extern SafeMultiHandle Init();
72 |
73 | [DllImport(LIBCURL, EntryPoint = "curl_multi_cleanup")]
74 | public static extern CURLMcode Cleanup(IntPtr multiHandle);
75 |
76 | [DllImport(LIBCURL, EntryPoint = "curl_multi_add_handle")]
77 | public static extern CURLMcode AddHandle(SafeMultiHandle multiHandle, SafeEasyHandle easyHandle);
78 |
79 | [DllImport(LIBCURL, EntryPoint = "curl_multi_remove_handle")]
80 | public static extern CURLMcode RemoveHandle(SafeMultiHandle multiHandle, SafeEasyHandle easyHandle);
81 |
82 | [DllImport(LIBCURL, EntryPoint = "curl_multi_setopt")]
83 | public static extern CURLMcode SetOpt(SafeMultiHandle multiHandle, CURLMoption option, int value);
84 |
85 | [DllImport(LIBCURL, EntryPoint = "curl_multi_info_read")]
86 | public static extern IntPtr InfoRead(SafeMultiHandle multiHandle, out int msgsInQueue);
87 |
88 | [DllImport(LIBCURL, EntryPoint = "curl_multi_socket_action")]
89 | public static extern CURLMcode SocketAction(SafeMultiHandle multiHandle, SafeSocketHandle sockfd,
90 | CURLcselect evBitmask,
91 | out int runningHandles);
92 |
93 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
94 | public struct CURLMsg
95 | {
96 | public CURLMSG msg; /* what this message means */
97 | public IntPtr easy_handle; /* the handle it concerns */
98 | public CURLMsgData data;
99 |
100 | [StructLayout(LayoutKind.Explicit)]
101 | public struct CURLMsgData
102 | {
103 | [FieldOffset(0)] public IntPtr whatever; /* (void*) message-specific data */
104 | [FieldOffset(0)] public CURLcode result; /* return code for transfer */
105 | }
106 | }
107 |
108 | #region curl_multi_setopt for CURLMOPT_TIMERFUNCTION
109 |
110 | public delegate int TimerCallback(IntPtr multiHandle, int timeoutMs, IntPtr userp);
111 |
112 | [DllImport(LIBCURL, EntryPoint = "curl_multi_setopt")]
113 | public static extern CURLMcode SetOpt(SafeMultiHandle multiHandle, CURLMoption option, TimerCallback value);
114 |
115 | #endregion
116 |
117 | #region curl_multi_setopt for CURLMOPT_SOCKETFUNCTION
118 |
119 | public delegate int SocketCallback(IntPtr easy, IntPtr s, CURLpoll what, IntPtr userp, IntPtr socketp);
120 |
121 | [DllImport(LIBCURL, EntryPoint = "curl_multi_setopt")]
122 | public static extern CURLMcode SetOpt(SafeMultiHandle multiHandle, CURLMoption option,
123 | SocketCallback value);
124 |
125 | #endregion
126 | }
127 |
128 | public static class Slist
129 | {
130 | [DllImport(LIBCURL, EntryPoint = "curl_slist_append")]
131 | public static extern SafeSlistHandle Append(SafeSlistHandle slist, string data);
132 |
133 | [DllImport(LIBCURL, EntryPoint = "curl_slist_free_all")]
134 | public static extern void FreeAll(SafeSlistHandle pList);
135 | }
136 | }
137 | }
--------------------------------------------------------------------------------
/CurlThin.Samples/Multi/HyperSample.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Runtime.InteropServices;
4 | using System.Text.RegularExpressions;
5 | using System.Threading.Tasks;
6 | using CurlThin.Enums;
7 | using CurlThin.Helpers;
8 | using CurlThin.HyperPipe;
9 | using CurlThin.Native;
10 | using CurlThin.SafeHandles;
11 |
12 | namespace CurlThin.Samples.Multi
13 | {
14 | internal class HyperSample : ISample
15 | {
16 | public void Run()
17 | {
18 | if (CurlNative.Init() != CURLcode.OK)
19 | {
20 | throw new Exception("Could not init curl");
21 | }
22 |
23 | var reqProvider = new MyRequestProvider();
24 | var resConsumer = new MyResponseConsumer();
25 |
26 | using (var pipe = new HyperPipe(4, reqProvider, resConsumer))
27 | {
28 | pipe.RunLoopWait();
29 | }
30 | }
31 | }
32 |
33 | ///
34 | /// What exactly is request context? It can be any type (string, int, custom class, whatever) that will help pass some
35 | /// data to method that will process response.
36 | ///
37 | public class MyRequestContext : IDisposable
38 | {
39 | public MyRequestContext(string label)
40 | {
41 | Label = label;
42 | }
43 |
44 | public string Label { get; }
45 | public DataCallbackCopier HeaderData { get; } = new DataCallbackCopier();
46 | public DataCallbackCopier ContentData { get; } = new DataCallbackCopier();
47 |
48 | public void Dispose()
49 | {
50 | HeaderData?.Dispose();
51 | ContentData?.Dispose();
52 | }
53 | }
54 |
55 | ///
56 | /// Request provider generates requests that you want to send to cURL.
57 | /// This example shows how to web scrape StackOverflow questions (https://stackoverflow.com/)
58 | /// beginning with ID 4400000 until ID 4400050.
59 | ///
60 | public class MyRequestProvider : IRequestProvider
61 | {
62 | private readonly int _maxQuestion = 4400050;
63 | private int _currentQuestion = 4400000;
64 |
65 | public MyRequestContext Current { get; private set; }
66 |
67 | public ValueTask MoveNextAsync(SafeEasyHandle easy)
68 | {
69 | // If question ID is higher than maximum, return false.
70 | if (_currentQuestion > _maxQuestion)
71 | {
72 | Current = null;
73 | return new ValueTask(false);
74 | }
75 |
76 | // Create request context. Assign it a label to easily recognize it later.
77 | var context = new MyRequestContext($"StackOverflow Question #{_currentQuestion}");
78 |
79 | // Set request URL.
80 | CurlNative.Easy.SetOpt(easy, CURLoption.URL, $"https://stackoverflow.com/questions/{_currentQuestion}/");
81 |
82 | // Follow redirects.
83 | CurlNative.Easy.SetOpt(easy, CURLoption.FOLLOWLOCATION, 1);
84 |
85 | // Set request timeout.
86 | CurlNative.Easy.SetOpt(easy, CURLoption.TIMEOUT_MS, 3000);
87 |
88 | // Copy response header (it contains HTTP code and response headers, for example
89 | // "Content-Type") to MemoryStream in our RequestContext.
90 | CurlNative.Easy.SetOpt(easy, CURLoption.HEADERFUNCTION, context.HeaderData.DataHandler);
91 |
92 | // Copy response body (it for example contains HTML source) to MemoryStream
93 | // in our RequestContext.
94 | CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, context.ContentData.DataHandler);
95 |
96 | // Point the certificate bundle file path to verify HTTPS certificates.
97 | CurlNative.Easy.SetOpt(easy, CURLoption.CAINFO, CurlResources.CaBundlePath);
98 |
99 | _currentQuestion++;
100 | Current = context;
101 | return new ValueTask(true);
102 | }
103 | }
104 |
105 | ///
106 | /// This class will process HTTP responses.
107 | ///
108 | public class MyResponseConsumer : IResponseConsumer
109 | {
110 | public HandleCompletedAction OnComplete(SafeEasyHandle easy, MyRequestContext context, CURLcode errorCode)
111 | {
112 | Console.WriteLine($"Request label: {context.Label}.");
113 | if (errorCode != CURLcode.OK)
114 | {
115 | Console.BackgroundColor = ConsoleColor.DarkRed;
116 | Console.ForegroundColor = ConsoleColor.White;
117 |
118 | Console.WriteLine($"cURL error code: {errorCode}");
119 | var pErrorMsg = CurlNative.Easy.StrError(errorCode);
120 | var errorMsg = Marshal.PtrToStringAnsi(pErrorMsg);
121 | Console.WriteLine($"cURL error message: {errorMsg}");
122 |
123 | Console.ResetColor();
124 | Console.WriteLine("--------");
125 | Console.WriteLine();
126 |
127 | context.Dispose();
128 | return HandleCompletedAction.ResetHandleAndNext;
129 | }
130 |
131 | // Get HTTP response code.
132 | CurlNative.Easy.GetInfo(easy, CURLINFO.RESPONSE_CODE, out int httpCode);
133 | if (httpCode != 200)
134 | {
135 | Console.BackgroundColor = ConsoleColor.DarkRed;
136 | Console.ForegroundColor = ConsoleColor.White;
137 |
138 | Console.WriteLine($"Invalid HTTP response code: {httpCode}");
139 |
140 | Console.ResetColor();
141 | Console.WriteLine("--------");
142 | Console.WriteLine();
143 |
144 | context.Dispose();
145 | return HandleCompletedAction.ResetHandleAndNext;
146 | }
147 | Console.WriteLine($"Response code: {httpCode}");
148 |
149 | // Get effective URL.
150 | IntPtr pDoneUrl;
151 | CurlNative.Easy.GetInfo(easy, CURLINFO.EFFECTIVE_URL, out pDoneUrl);
152 | var doneUrl = Marshal.PtrToStringAnsi(pDoneUrl);
153 | Console.WriteLine($"Effective URL: {doneUrl}");
154 |
155 | // Get response body as string.
156 | var html = context.ContentData.ReadAsString();
157 |
158 | // Scrape question from HTML source.
159 | var match = Regex.Match(html, "(.+?)<\\/");
160 |
161 | Console.WriteLine($"Question: {match.Groups[1].Value.Trim()}");
162 | Console.WriteLine("--------");
163 | Console.WriteLine();
164 |
165 | context.Dispose();
166 | return HandleCompletedAction.ResetHandleAndNext;
167 | }
168 | }
169 | }
--------------------------------------------------------------------------------
/CurlThin.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27004.2008
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurlThin.Native", "CurlThin.Native\CurlThin.Native.csproj", "{F50DF089-F0F9-464B-97BB-8EBA9BDF7B4F}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurlThin", "CurlThin\CurlThin.csproj", "{72DCABEB-E6BB-4213-A710-64EF7089460C}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurlThin.Tests", "CurlThin.Tests\CurlThin.Tests.csproj", "{E95EB360-DD7E-4324-B27C-73D99FD9DBFE}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurlThin.Samples", "CurlThin.Samples\CurlThin.Samples.csproj", "{E4CB73A4-8984-4341-AEDC-CE8AA1598BA8}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {F50DF089-F0F9-464B-97BB-8EBA9BDF7B4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {F50DF089-F0F9-464B-97BB-8EBA9BDF7B4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {F50DF089-F0F9-464B-97BB-8EBA9BDF7B4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {F50DF089-F0F9-464B-97BB-8EBA9BDF7B4F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {72DCABEB-E6BB-4213-A710-64EF7089460C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {72DCABEB-E6BB-4213-A710-64EF7089460C}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {72DCABEB-E6BB-4213-A710-64EF7089460C}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {72DCABEB-E6BB-4213-A710-64EF7089460C}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {E95EB360-DD7E-4324-B27C-73D99FD9DBFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {E95EB360-DD7E-4324-B27C-73D99FD9DBFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {E95EB360-DD7E-4324-B27C-73D99FD9DBFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {E95EB360-DD7E-4324-B27C-73D99FD9DBFE}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {E4CB73A4-8984-4341-AEDC-CE8AA1598BA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {E4CB73A4-8984-4341-AEDC-CE8AA1598BA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {E4CB73A4-8984-4341-AEDC-CE8AA1598BA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {E4CB73A4-8984-4341-AEDC-CE8AA1598BA8}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {1D12C33D-A9B3-4E0B-96D6-C6F79BEEB28F}
42 | EndGlobalSection
43 | GlobalSection(MonoDevelopProperties) = preSolution
44 | StartupItem = Curl.csproj
45 | Policies = $0
46 | $0.StandardHeader = $1
47 | $1.Text = @\n${FileName}\n \nAuthor:\n ${AuthorName} <${AuthorEmail}>\n\nCopyright ${Year} ${CopyrightHolder}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.
48 | $1.IncludeInNewFiles = True
49 | $0.NameConventionPolicy = $2
50 | $2.Rules = $3
51 | $3.NamingRule = $23
52 | $4.Name = Namespaces
53 | $4.AffectedEntity = Namespace
54 | $4.VisibilityMask = VisibilityMask
55 | $4.NamingStyle = PascalCase
56 | $4.IncludeInstanceMembers = True
57 | $4.IncludeStaticEntities = True
58 | $5.Name = Types
59 | $5.AffectedEntity = Class, Struct, Enum, Delegate
60 | $5.VisibilityMask = Public
61 | $5.NamingStyle = PascalCase
62 | $5.IncludeInstanceMembers = True
63 | $5.IncludeStaticEntities = True
64 | $6.Name = Interfaces
65 | $6.RequiredPrefixes = $7
66 | $7.String = I
67 | $6.AffectedEntity = Interface
68 | $6.VisibilityMask = Public
69 | $6.NamingStyle = PascalCase
70 | $6.IncludeInstanceMembers = True
71 | $6.IncludeStaticEntities = True
72 | $8.Name = Attributes
73 | $8.RequiredSuffixes = $9
74 | $9.String = Attribute
75 | $8.AffectedEntity = CustomAttributes
76 | $8.VisibilityMask = Public
77 | $8.NamingStyle = PascalCase
78 | $8.IncludeInstanceMembers = True
79 | $8.IncludeStaticEntities = True
80 | $10.Name = Event Arguments
81 | $10.RequiredSuffixes = $11
82 | $11.String = EventArgs
83 | $10.AffectedEntity = CustomEventArgs
84 | $10.VisibilityMask = Public
85 | $10.NamingStyle = PascalCase
86 | $10.IncludeInstanceMembers = True
87 | $10.IncludeStaticEntities = True
88 | $12.Name = Exceptions
89 | $12.RequiredSuffixes = $13
90 | $13.String = Exception
91 | $12.AffectedEntity = CustomExceptions
92 | $12.VisibilityMask = VisibilityMask
93 | $12.NamingStyle = PascalCase
94 | $12.IncludeInstanceMembers = True
95 | $12.IncludeStaticEntities = True
96 | $14.Name = Methods
97 | $14.AffectedEntity = Methods
98 | $14.VisibilityMask = Protected, Public
99 | $14.NamingStyle = PascalCase
100 | $14.IncludeInstanceMembers = True
101 | $14.IncludeStaticEntities = True
102 | $15.Name = Static Readonly Fields
103 | $15.AffectedEntity = ReadonlyField
104 | $15.VisibilityMask = Protected, Public
105 | $15.NamingStyle = PascalCase
106 | $15.IncludeInstanceMembers = False
107 | $15.IncludeStaticEntities = True
108 | $16.Name = Fields
109 | $16.AffectedEntity = Field
110 | $16.VisibilityMask = Protected, Public
111 | $16.NamingStyle = PascalCase
112 | $16.IncludeInstanceMembers = True
113 | $16.IncludeStaticEntities = True
114 | $17.Name = ReadOnly Fields
115 | $17.AffectedEntity = ReadonlyField
116 | $17.VisibilityMask = Protected, Public
117 | $17.NamingStyle = PascalCase
118 | $17.IncludeInstanceMembers = True
119 | $17.IncludeStaticEntities = False
120 | $18.Name = Constant Fields
121 | $18.AffectedEntity = ConstantField
122 | $18.VisibilityMask = Protected, Public
123 | $18.NamingStyle = PascalCase
124 | $18.IncludeInstanceMembers = True
125 | $18.IncludeStaticEntities = True
126 | $19.Name = Properties
127 | $19.AffectedEntity = Property
128 | $19.VisibilityMask = Protected, Public
129 | $19.NamingStyle = PascalCase
130 | $19.IncludeInstanceMembers = True
131 | $19.IncludeStaticEntities = True
132 | $20.Name = Events
133 | $20.AffectedEntity = Event
134 | $20.VisibilityMask = Protected, Public
135 | $20.NamingStyle = PascalCase
136 | $20.IncludeInstanceMembers = True
137 | $20.IncludeStaticEntities = True
138 | $21.Name = Enum Members
139 | $21.AffectedEntity = EnumMember
140 | $21.VisibilityMask = VisibilityMask
141 | $21.NamingStyle = PascalCase
142 | $21.IncludeInstanceMembers = True
143 | $21.IncludeStaticEntities = True
144 | $22.Name = Parameters
145 | $22.AffectedEntity = Parameter
146 | $22.VisibilityMask = VisibilityMask
147 | $22.NamingStyle = CamelCase
148 | $22.IncludeInstanceMembers = True
149 | $22.IncludeStaticEntities = True
150 | $23.Name = Type Parameters
151 | $23.RequiredPrefixes = $24
152 | $24.String = T
153 | $23.AffectedEntity = TypeParameter
154 | $23.VisibilityMask = VisibilityMask
155 | $23.NamingStyle = PascalCase
156 | $23.IncludeInstanceMembers = True
157 | $23.IncludeStaticEntities = True
158 | EndGlobalSection
159 | EndGlobal
160 |
--------------------------------------------------------------------------------
/CurlThin/HyperPipe/HyperPipe.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using CurlThin.Enums;
6 | using CurlThin.SafeHandles;
7 | using Microsoft.Extensions.Logging;
8 | using NetUV.Core.Handles;
9 | using Timer = NetUV.Core.Handles.Timer;
10 |
11 | namespace CurlThin.HyperPipe
12 | {
13 | public class HyperPipe : IDisposable
14 | {
15 | private static readonly ILogger Logger = Logging.GetCurrentClassLogger();
16 |
17 | private readonly EasyPool _easyPool;
18 | private readonly Loop _loop;
19 | private readonly SafeMultiHandle _multiHandle;
20 | private readonly SemaphoreSlim _oneRequestPullAtOnce = new SemaphoreSlim(1);
21 | private readonly IRequestProvider _requestProvider;
22 | private readonly IResponseConsumer _responseConsumer;
23 | private readonly CurlNative.Multi.SocketCallback _socketCallback;
24 | private readonly SocketPollMap _socketMap;
25 | private readonly Timer _timeout;
26 | private readonly CurlNative.Multi.TimerCallback _timerCallback;
27 |
28 | public HyperPipe(int poolSize,
29 | IRequestProvider requestProvider,
30 | IResponseConsumer responseConsumer)
31 | {
32 | _requestProvider = requestProvider;
33 | _responseConsumer = responseConsumer;
34 |
35 | _easyPool = new EasyPool(poolSize);
36 | _multiHandle = CurlNative.Multi.Init();
37 | if (_multiHandle.IsInvalid)
38 | {
39 | throw new Exception("Could not init curl_multi handle.");
40 | }
41 |
42 | _socketMap = new SocketPollMap();
43 | _loop = new Loop();
44 | _timeout = _loop.CreateTimer();
45 |
46 | // Explicitly define callback functions to keep them from being GCed.
47 | _socketCallback = HandleSocket;
48 | _timerCallback = StartTimeout;
49 |
50 | Logger.LogDebug($"Set {CURLMoption.SOCKETFUNCTION}.");
51 | CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.SOCKETFUNCTION, _socketCallback);
52 | Logger.LogDebug($"Set {CURLMoption.TIMERFUNCTION}.");
53 | CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.TIMERFUNCTION, _timerCallback);
54 | }
55 |
56 | public void Dispose()
57 | {
58 | _multiHandle.Dispose();
59 | _loop.Dispose();
60 | _timeout.Dispose();
61 | _socketMap.Dispose();
62 | _oneRequestPullAtOnce.Dispose();
63 | }
64 |
65 | public void RunLoopWait()
66 | {
67 | Refill();
68 |
69 | // Kickstart.
70 | Logger.LogDebug("Kickstarting...");
71 | CurlNative.Multi.SocketAction(_multiHandle, SafeSocketHandle.Invalid, 0, out int _);
72 |
73 | Logger.LogDebug("Starting libuv loop...");
74 | _loop.RunDefault();
75 | }
76 |
77 | ///
78 | /// SOCKETFUNCTION implementation.
79 | ///
80 | ///
81 | ///
82 | ///
83 | ///
84 | ///
85 | ///
86 | private int HandleSocket(IntPtr easy, IntPtr sockfd, CURLpoll what, IntPtr userp, IntPtr socketp)
87 | {
88 | Logger.LogTrace(
89 | $"Called {nameof(CURLMoption.SOCKETFUNCTION)}. We need to poll for {what} on socket {sockfd}.");
90 |
91 | switch (what)
92 | {
93 | case CURLpoll.IN:
94 | case CURLpoll.OUT:
95 | case CURLpoll.INOUT:
96 | PollMask events = 0;
97 |
98 | if (what != CURLpoll.IN)
99 | {
100 | events |= PollMask.Writable;
101 | }
102 | if (what != CURLpoll.OUT)
103 | {
104 | events |= PollMask.Readable;
105 | }
106 |
107 | Logger.LogTrace($"Polling socket {sockfd} using libuv with mask {events}.");
108 |
109 | _socketMap.GetOrCreatePoll(sockfd, _loop).Start(events, (poll, status) =>
110 | {
111 | CURLcselect flags = 0;
112 |
113 | if (status.Mask.HasFlag(PollMask.Readable))
114 | {
115 | flags |= CURLcselect.IN;
116 | }
117 | if (status.Mask.HasFlag(PollMask.Writable))
118 | {
119 | flags |= CURLcselect.OUT;
120 | }
121 |
122 | Logger.LogTrace($"Finished polling socket {sockfd}.");
123 | CurlNative.Multi.SocketAction(_multiHandle, sockfd, flags, out int _);
124 | CheckMultiInfo();
125 | });
126 | break;
127 | case CURLpoll.REMOVE:
128 | Logger.LogTrace($"Removing poll of socket {sockfd}.");
129 | _socketMap.RemovePoll(sockfd);
130 | break;
131 | default:
132 | throw new ArgumentOutOfRangeException(nameof(what));
133 | }
134 |
135 | return 0;
136 | }
137 |
138 | ///
139 | /// TIMERFUNCTION implementation.
140 | ///
141 | ///
142 | ///
143 | ///
144 | ///
145 | private int StartTimeout(IntPtr multiHandle, int timeoutMs, IntPtr userp)
146 | {
147 | if (timeoutMs < 0)
148 | {
149 | Logger.LogTrace($"Called {nameof(CURLMoption.TIMERFUNCTION)} with timeout set to {timeoutMs}. "
150 | + "Deleting our timer.");
151 | _timeout.Stop();
152 | }
153 | else if (timeoutMs == 0)
154 | {
155 | Logger.LogTrace($"Called {nameof(CURLMoption.TIMERFUNCTION)} with timeout set to {timeoutMs}. "
156 | + "We should call curl_multi_socket_action or curl_multi_perform (once) as soon as possible.");
157 |
158 | CurlNative.Multi.SocketAction(_multiHandle, SafeSocketHandle.Invalid, 0, out int _);
159 | CheckMultiInfo();
160 | }
161 | else
162 | {
163 | Logger.LogTrace($"Called {nameof(CURLMoption.TIMERFUNCTION)} with timeout set to {timeoutMs} ms.");
164 |
165 | _timeout.Start(t =>
166 | {
167 | CurlNative.Multi.SocketAction(_multiHandle, SafeSocketHandle.Invalid, 0, out int _);
168 | CheckMultiInfo();
169 | }, timeoutMs, 0);
170 | }
171 | return 0;
172 | }
173 |
174 | private void CheckMultiInfo()
175 | {
176 | IntPtr pMessage;
177 |
178 | while ((pMessage = CurlNative.Multi.InfoRead(_multiHandle, out int _)) != IntPtr.Zero)
179 | {
180 | var message = Marshal.PtrToStructure(pMessage);
181 | if (message.msg != CURLMSG.DONE)
182 | {
183 | throw new Exception($"Unexpected curl_multi_info_read result message: {message.msg}.");
184 | }
185 |
186 | var easy = _easyPool.GetSafeHandleFromPtr(message.easy_handle);
187 |
188 | /* Do not use message data after calling curl_multi_remove_handle() and
189 | curl_easy_cleanup(). As per curl_multi_info_read() docs:
190 | "WARNING: The data the returned pointer points to will not survive
191 | calling curl_multi_cleanup, curl_multi_remove_handle or
192 | curl_easy_cleanup." */
193 |
194 | _easyPool.GetAssignedContext(easy, out T requestContext);
195 | var action = _responseConsumer.OnComplete(easy, requestContext, message.data.result);
196 |
197 | if (action == HandleCompletedAction.ReuseHandleAndRetry)
198 | {
199 | CurlNative.Multi.RemoveHandle(_multiHandle, easy);
200 | CurlNative.Multi.AddHandle(_multiHandle, easy);
201 | }
202 | else if (action == HandleCompletedAction.ResetHandleAndNext)
203 | {
204 | CurlNative.Multi.RemoveHandle(_multiHandle, easy);
205 | CurlNative.Easy.Reset(easy);
206 | _easyPool.UnassignContext(easy);
207 | _easyPool.Free(easy);
208 | Refill();
209 | }
210 | }
211 | }
212 |
213 | private void Refill()
214 | {
215 | if (!_easyPool.TryTakeFree(out SafeEasyHandle easy))
216 | {
217 | return; // All handles are in use.
218 | }
219 |
220 | var asyncHandle = _loop.CreateAsync(async =>
221 | {
222 | var result = ((bool HasNext, T Next)) async.UserToken;
223 | if (result.HasNext)
224 | {
225 | _easyPool.AssignContext(easy, result.Next);
226 | CurlNative.Multi.AddHandle(_multiHandle, easy);
227 | Refill();
228 | }
229 |
230 | async.CloseHandle();
231 | async.Dispose();
232 | });
233 |
234 | Task.Run(async () =>
235 | {
236 | await _oneRequestPullAtOnce.WaitAsync();
237 | var result = await _requestProvider.MoveNextAsync(easy);
238 | asyncHandle.UserToken = (result, _requestProvider.Current);
239 | _oneRequestPullAtOnce.Release();
240 | asyncHandle.Send();
241 | });
242 | }
243 | }
244 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLcode.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | ///
6 | /// Reference: https://github.com/curl/curl/blob/master/include/curl/curl.h
7 | ///
8 | [SuppressMessage("ReSharper", "InconsistentNaming")]
9 | public enum CURLcode : uint
10 | {
11 | OK = 0,
12 |
13 | /// 1
14 | UNSUPPORTED_PROTOCOL,
15 |
16 | /// 2
17 | FAILED_INIT,
18 |
19 | /// 3
20 | URL_MALFORMAT,
21 |
22 | /// 4 - [was obsoleted in August 2007 for 7.17.0, reused in April 2011 for 7.21.5]
23 | NOT_BUILT_IN,
24 |
25 | /// 5
26 | COULDNT_RESOLVE_PROXY,
27 |
28 | /// 6
29 | COULDNT_RESOLVE_HOST,
30 |
31 | /// 7
32 | COULDNT_CONNECT,
33 |
34 | /// 8
35 | WEIRD_SERVER_REPLY,
36 |
37 | /// 9 a service was denied by the server due to lack of access - when login fails this is not returned.
38 | REMOTE_ACCESS_DENIED,
39 |
40 | /// 10 - [was obsoleted in April 2006 for 7.15.4, reused in Dec 2011 for 7.24.0]
41 | FTP_ACCEPT_FAILED,
42 |
43 | /// 11
44 | FTP_WEIRD_PASS_REPLY,
45 |
46 | ///
47 | /// 12 - timeout occurred accepting server
48 | /// [was obsoleted in August 2007 for 7.17.0, reused in Dec 2011 for 7.24.0]
49 | ///
50 | FTP_ACCEPT_TIMEOUT,
51 |
52 | /// 13
53 | FTP_WEIRD_PASV_REPLY,
54 |
55 | /// 14
56 | FTP_WEIRD_227_FORMAT,
57 |
58 | /// 15
59 | FTP_CANT_GET_HOST,
60 |
61 | ///
62 | /// 16 - A problem in the http2 framing layer.
63 | /// [was obsoleted in August 2007 for 7.17.0, reused in July 2014 for 7.38.0]
64 | ///
65 | HTTP2,
66 |
67 | /// 17
68 | FTP_COULDNT_SET_TYPE,
69 |
70 | /// 18
71 | PARTIAL_FILE,
72 |
73 | /// 19
74 | FTP_COULDNT_RETR_FILE,
75 |
76 | /// 20 - NOT USED
77 | OBSOLETE20,
78 |
79 | /// 21 - quote command failure
80 | QUOTE_ERROR,
81 |
82 | /// 22
83 | HTTP_RETURNED_ERROR,
84 |
85 | /// 23
86 | WRITE_ERROR,
87 |
88 | /// 24 - NOT USED
89 | OBSOLETE24,
90 |
91 | /// 25 - failed upload "command"
92 | UPLOAD_FAILED,
93 |
94 | /// 26 - couldn't open/read from file
95 | READ_ERROR,
96 |
97 | ///
98 | /// 27 - Note: OUT_OF_MEMORY may sometimes indicate a conversion error instead of a memory allocation error if
99 | /// CURL_DOES_CONVERSIONS is defined
100 | ///
101 | OUT_OF_MEMORY,
102 |
103 | /// 28 - the timeout time was reached
104 | OPERATION_TIMEDOUT,
105 |
106 | /// 29 - NOT USED
107 | OBSOLETE29,
108 |
109 | /// 30 - FTP PORT operation failed
110 | FTP_PORT_FAILED,
111 |
112 | /// 31 - the REST command failed
113 | FTP_COULDNT_USE_REST,
114 |
115 | /// 32 - NOT USED
116 | OBSOLETE32,
117 |
118 | /// 33 - RANGE "command" didn't work
119 | RANGE_ERROR,
120 |
121 | /// 34
122 | HTTP_POST_ERROR,
123 |
124 | /// 35 - wrong when connecting with SSL
125 | SSL_CONNECT_ERROR,
126 |
127 | /// 36 - couldn't resume download
128 | BAD_DOWNLOAD_RESUME,
129 |
130 | /// 37
131 | FILE_COULDNT_READ_FILE,
132 |
133 | /// 38
134 | LDAP_CANNOT_BIND,
135 |
136 | /// 39
137 | LDAP_SEARCH_FAILED,
138 |
139 | /// 40 - NOT USED
140 | OBSOLETE40,
141 |
142 | /// 41 - NOT USED starting with 7.53.0
143 | FUNCTION_NOT_FOUND,
144 |
145 | /// 42
146 | ABORTED_BY_CALLBACK,
147 |
148 | /// 43
149 | BAD_FUNCTION_ARGUMENT,
150 |
151 | /// 44 - NOT USED
152 | OBSOLETE44,
153 |
154 | /// 45 - CURLOPT_INTERFACE failed
155 | INTERFACE_FAILED,
156 |
157 | /// 46 - NOT USED
158 | OBSOLETE46,
159 |
160 | /// 47 - catch endless re-direct loops
161 | TOO_MANY_REDIRECTS,
162 |
163 | /// 48 - User specified an unknown option
164 | UNKNOWN_OPTION,
165 |
166 | /// 49 - Malformed telnet option
167 | TELNET_OPTION_SYNTAX,
168 |
169 | /// 50 - NOT USED
170 | OBSOLETE50,
171 |
172 | /// 51 - peer's certificate or fingerprint wasn't verified fine
173 | PEER_FAILED_VERIFICATION,
174 |
175 | /// 52 - when this is a specific error
176 | GOT_NOTHING,
177 |
178 | /// 53 - SSL crypto engine not found
179 | SSL_ENGINE_NOTFOUND,
180 |
181 | /// 54 - can not set SSL crypto engine as default
182 | SSL_ENGINE_SETFAILED,
183 |
184 | /// 55 - failed sending network data
185 | SEND_ERROR,
186 |
187 | /// 56 - failure in receiving network data
188 | RECV_ERROR,
189 |
190 | /// 57 - NOT IN USE
191 | OBSOLETE57,
192 |
193 | /// 58 - problem with the local certificate
194 | SSL_CERTPROBLEM,
195 |
196 | /// 59 - couldn't use specified cipher
197 | SSL_CIPHER,
198 |
199 | /// 60 - problem with the CA cert (path?)
200 | SSL_CACERT,
201 |
202 | /// 61 - Unrecognized/bad encoding
203 | BAD_CONTENT_ENCODING,
204 |
205 | /// 62 - Invalid LDAP URL
206 | LDAP_INVALID_URL,
207 |
208 | /// 63 - Maximum file size exceeded
209 | FILESIZE_EXCEEDED,
210 |
211 | /// 64 - Requested FTP SSL level failed
212 | USE_SSL_FAILED,
213 |
214 | /// 65 - Sending the data requires a rewind that failed
215 | SEND_FAIL_REWIND,
216 |
217 | /// 66 - failed to initialise ENGINE
218 | SSL_ENGINE_INITFAILED,
219 |
220 | /// 67 - user, password or similar was not accepted and we failed to login
221 | LOGIN_DENIED,
222 |
223 | /// 68 - file not found on server
224 | TFTP_NOTFOUND,
225 |
226 | /// 69 - permission problem on server
227 | TFTP_PERM,
228 |
229 | /// 70 - out of disk space on server
230 | REMOTE_DISK_FULL,
231 |
232 | /// 71 - Illegal TFTP operation
233 | TFTP_ILLEGAL,
234 |
235 | /// 72 - Unknown transfer ID
236 | TFTP_UNKNOWNID,
237 |
238 | /// 73 - File already exists
239 | REMOTE_FILE_EXISTS,
240 |
241 | /// 74 - No such user
242 | TFTP_NOSUCHUSER,
243 |
244 | /// 75 - conversion failed
245 | CONV_FAILED,
246 |
247 | ///
248 | /// 76 - caller must register conversion callbacks using curl_easy_setopt options
249 | /// CURLOPT_CONV_FROM_NETWORK_FUNCTION,
250 | /// CURLOPT_CONV_TO_NETWORK_FUNCTION, and
251 | /// CURLOPT_CONV_FROM_UTF8_FUNCTION
252 | ///
253 | CONV_REQD,
254 |
255 | /// 77 - could not load CACERT file, missing or wrong format
256 | SSL_CACERT_BADFILE,
257 |
258 | /// 78 - remote file not found
259 | REMOTE_FILE_NOT_FOUND,
260 |
261 | ///
262 | /// 79 - error from the SSH layer, somewhat generic so the error message will be of interest when this has
263 | /// happened
264 | ///
265 | SSH,
266 |
267 | /// 80 - Failed to shut down the SSL connection
268 | SSL_SHUTDOWN_FAILED,
269 |
270 | /// 81 - socket is not ready for send/recv, wait till it's ready and try again (Added in 7.18.2)
271 | AGAIN,
272 |
273 | /// 82 - could not load CRL file, missing or wrong format (Added in 7.19.0)
274 | SSL_CRL_BADFILE,
275 |
276 | /// 83 - Issuer check failed. (Added in 7.19.0)
277 | SSL_ISSUER_ERROR,
278 |
279 | /// 84 - a PRET command failed
280 | FTP_PRET_FAILED,
281 |
282 | /// 85 - mismatch of RTSP CSeq numbers
283 | RTSP_CSEQ_ERROR,
284 |
285 | /// 86 - mismatch of RTSP Session Ids
286 | RTSP_SESSION_ERROR,
287 |
288 | /// 87 - unable to parse FTP file list
289 | FTP_BAD_FILE_LIST,
290 |
291 | /// 88 - chunk callback reported error
292 | CHUNK_FAILED,
293 |
294 | /// 89 - No connection available, the session will be queued
295 | NO_CONNECTION_AVAILABLE,
296 |
297 | /// 90 - specified pinned public key did not match
298 | SSL_PINNEDPUBKEYNOTMATCH,
299 |
300 | /// 91 - invalid certificate status
301 | SSL_INVALIDCERTSTATUS,
302 |
303 | /// 92 - stream error in HTTP/2 framing layer
304 | HTTP2_STREAM,
305 |
306 | /// never use!
307 | CURL_LAST
308 | }
309 | }
--------------------------------------------------------------------------------
/CurlThin/Enums/CURLoption.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace CurlThin.Enums
4 | {
5 | [SuppressMessage("ReSharper", "InconsistentNaming")]
6 | internal static class CURLOPTTYPE
7 | {
8 | public const uint LONG = 0;
9 | public const uint OBJECTPOINT = 10000;
10 | public const uint STRINGPOINT = 10000;
11 | public const uint FUNCTIONPOINT = 20000;
12 | public const uint OFF_T = 30000;
13 | }
14 |
15 | [SuppressMessage("ReSharper", "InconsistentNaming")]
16 | public enum CURLoption : uint
17 | {
18 | /* This is the FILE * or void * the regular output should be written to. */
19 | WRITEDATA = CURLOPTTYPE.OBJECTPOINT + 1,
20 |
21 | /* The full URL to get/put */
22 | URL = CURLOPTTYPE.STRINGPOINT + 2,
23 |
24 | /* Port number to connect to, if other than default. */
25 | PORT = CURLOPTTYPE.LONG + 3,
26 |
27 | /* Name of proxy to use. */
28 | PROXY = CURLOPTTYPE.STRINGPOINT + 4,
29 |
30 | /* "user:password;options" to use when fetching. */
31 | USERPWD = CURLOPTTYPE.STRINGPOINT + 5,
32 |
33 | /* "user:password" to use with proxy. */
34 | PROXYUSERPWD = CURLOPTTYPE.STRINGPOINT + 6,
35 |
36 | /* Range to get, specified as an ASCII string. */
37 | RANGE = CURLOPTTYPE.STRINGPOINT + 7,
38 |
39 | /* not used */
40 |
41 | /* Specified file stream to upload from (use as input): */
42 | READDATA = CURLOPTTYPE.OBJECTPOINT + 9,
43 |
44 | /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE
45 | * bytes big. If this is not used, error messages go to stderr instead: */
46 | ERRORBUFFER = CURLOPTTYPE.OBJECTPOINT + 10,
47 |
48 | /* Function that will be called to store the output (instead of fwrite). The
49 | * parameters will use fwrite() syntax, make sure to follow them. */
50 | WRITEFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 11,
51 |
52 | /* Function that will be called to read the input (instead of fread). The
53 | * parameters will use fread() syntax, make sure to follow them. */
54 | READFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 12,
55 |
56 | /* Time-out the read operation after this amount of seconds */
57 | TIMEOUT = CURLOPTTYPE.LONG + 13,
58 |
59 | /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about
60 | * how large the file being sent really is. That allows better error
61 | * checking and better verifies that the upload was successful. -1 means
62 | * unknown size.
63 | *
64 | * For large file support, there is also a _LARGE version of the key
65 | * which takes an off_t type, allowing platforms with larger off_t
66 | * sizes to handle larger files. See below for INFILESIZE_LARGE.
67 | */
68 | INFILESIZE = CURLOPTTYPE.LONG + 14,
69 |
70 | /* POST static input fields. */
71 | POSTFIELDS = CURLOPTTYPE.OBJECTPOINT + 15,
72 |
73 | /* Set the referrer page (needed by some CGIs) */
74 | REFERER = CURLOPTTYPE.STRINGPOINT + 16,
75 |
76 | /* Set the FTP PORT string (interface name, named or numerical IP address)
77 | Use i.e '-' to use default address. */
78 | FTPPORT = CURLOPTTYPE.STRINGPOINT + 17,
79 |
80 | /* Set the User-Agent string (examined by some CGIs) */
81 | USERAGENT = CURLOPTTYPE.STRINGPOINT + 18,
82 |
83 | /* If the download receives less than "low speed limit" bytes/second
84 | * during "low speed time" seconds, the operations is aborted.
85 | * You could i.e if you have a pretty high speed connection, abort if
86 | * it is less than 2000 bytes/sec during 20 seconds.
87 | */
88 |
89 | /* Set the "low speed limit" */
90 | LOW_SPEED_LIMIT = CURLOPTTYPE.LONG + 19,
91 |
92 | /* Set the "low speed time" */
93 | LOW_SPEED_TIME = CURLOPTTYPE.LONG + 20,
94 |
95 | /* Set the continuation offset.
96 | *
97 | * Note there is also a _LARGE version of this key which uses
98 | * off_t types, allowing for large file offsets on platforms which
99 | * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE.
100 | */
101 | RESUME_FROM = CURLOPTTYPE.LONG + 21,
102 |
103 | /* Set cookie in request: */
104 | COOKIE = CURLOPTTYPE.STRINGPOINT + 22,
105 |
106 | /* This points to a linked list of headers, struct curl_slist kind. This
107 | list is also used for RTSP (in spite of its name) */
108 | HTTPHEADER = CURLOPTTYPE.OBJECTPOINT + 23,
109 |
110 | /* This points to a linked list of post entries, struct curl_httppost */
111 | HTTPPOST = CURLOPTTYPE.OBJECTPOINT + 24,
112 |
113 | /* name of the file keeping your private SSL-certificate */
114 | SSLCERT = CURLOPTTYPE.STRINGPOINT + 25,
115 |
116 | /* password for the SSL or SSH private key */
117 | KEYPASSWD = CURLOPTTYPE.STRINGPOINT + 26,
118 |
119 | /* send TYPE parameter? */
120 | CRLF = CURLOPTTYPE.LONG + 27,
121 |
122 | /* send linked-list of QUOTE commands */
123 | QUOTE = CURLOPTTYPE.OBJECTPOINT + 28,
124 |
125 | /* send FILE * or void * to store headers to, if you use a callback it
126 | is simply passed to the callback unmodified */
127 | HEADERDATA = CURLOPTTYPE.OBJECTPOINT + 29,
128 |
129 | /* point to a file to read the initial cookies from, also enables
130 | "cookie awareness" */
131 | COOKIEFILE = CURLOPTTYPE.STRINGPOINT + 31,
132 |
133 | /* What version to specifically try to use.
134 | See CURL_SSLVERSION defines below. */
135 | SSLVERSION = CURLOPTTYPE.LONG + 32,
136 |
137 | /* What kind of HTTP time condition to use, see defines */
138 | TIMECONDITION = CURLOPTTYPE.LONG + 33,
139 |
140 | /* Time to use with the above condition. Specified in number of seconds
141 | since 1 Jan 1970 */
142 | TIMEVALUE = CURLOPTTYPE.LONG + 34,
143 |
144 | /* 35 = OBSOLETE */
145 |
146 | /* Custom request, for customizing the get command like
147 | HTTP: DELETE, TRACE and others
148 | FTP: to use a different list command
149 | */
150 | CUSTOMREQUEST = CURLOPTTYPE.STRINGPOINT + 36,
151 |
152 | /* FILE handle to use instead of stderr */
153 | STDERR = CURLOPTTYPE.OBJECTPOINT + 37,
154 |
155 | /* 38 is not used */
156 |
157 | /* send linked-list of post-transfer QUOTE commands */
158 | POSTQUOTE = CURLOPTTYPE.OBJECTPOINT + 39,
159 |
160 | OBSOLETE40 = CURLOPTTYPE.OBJECTPOINT + 40, /* OBSOLETE, do not use! */
161 |
162 | VERBOSE = CURLOPTTYPE.LONG + 41, /* talk a lot */
163 | HEADER = CURLOPTTYPE.LONG + 42, /* throw the header out too */
164 | NOPROGRESS = CURLOPTTYPE.LONG + 43, /* shut off the progress meter */
165 | NOBODY = CURLOPTTYPE.LONG + 44, /* use HEAD to get http document */
166 | FAILONERROR = CURLOPTTYPE.LONG + 45, /* no output on http error codes >= 400 */
167 | UPLOAD = CURLOPTTYPE.LONG + 46, /* this is an upload */
168 | POST = CURLOPTTYPE.LONG + 47, /* HTTP POST method */
169 | DIRLISTONLY = CURLOPTTYPE.LONG + 48, /* bare names when listing directories */
170 |
171 | APPEND = CURLOPTTYPE.LONG + 50, /* Append instead of overwrite on upload! */
172 |
173 | /* Specify whether to read the user+password from the .netrc or the URL.
174 | * This must be one of the CURL_NETRC_* enums below. */
175 | NETRC = CURLOPTTYPE.LONG + 51,
176 |
177 | FOLLOWLOCATION = CURLOPTTYPE.LONG + 52, /* use Location: Luke! */
178 |
179 | TRANSFERTEXT = CURLOPTTYPE.LONG + 53, /* transfer data in text/ASCII format */
180 | PUT = CURLOPTTYPE.LONG + 54, /* HTTP PUT */
181 |
182 | /* 55 = OBSOLETE */
183 |
184 | /* DEPRECATED
185 | * Function that will be called instead of the internal progress display
186 | * function. This function should be defined as the curl_progress_callback
187 | * prototype defines. */
188 | PROGRESSFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 56,
189 |
190 | /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION
191 | callbacks */
192 | PROGRESSDATA = CURLOPTTYPE.OBJECTPOINT + 57,
193 |
194 | /* We want the referrer field set automatically when following locations */
195 | AUTOREFERER = CURLOPTTYPE.LONG + 58,
196 |
197 | /* Port of the proxy, can be set in the proxy string as well with:
198 | "[host]:[port]" */
199 | PROXYPORT = CURLOPTTYPE.LONG + 59,
200 |
201 | /* size of the POST input data, if strlen() is not good to use */
202 | POSTFIELDSIZE = CURLOPTTYPE.LONG + 60,
203 |
204 | /* tunnel non-http operations through a HTTP proxy */
205 | HTTPPROXYTUNNEL = CURLOPTTYPE.LONG + 61,
206 |
207 | /* Set the interface string to use as outgoing network interface */
208 | INTERFACE = CURLOPTTYPE.STRINGPOINT + 62,
209 |
210 | /* Set the krb4/5 security level, this also enables krb4/5 awareness. This
211 | * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string
212 | * is set but doesn't match one of these, 'private' will be used. */
213 | KRBLEVEL = CURLOPTTYPE.STRINGPOINT + 63,
214 |
215 | /* Set if we should verify the peer in ssl handshake, set 1 to verify. */
216 | SSL_VERIFYPEER = CURLOPTTYPE.LONG + 64,
217 |
218 | /* The CApath or CAfile used to validate the peer certificate
219 | this option is used only if SSL_VERIFYPEER is true */
220 | CAINFO = CURLOPTTYPE.STRINGPOINT + 65,
221 |
222 | /* 66 = OBSOLETE */
223 | /* 67 = OBSOLETE */
224 |
225 | /* Maximum number of http redirects to follow */
226 | MAXREDIRS = CURLOPTTYPE.LONG + 68,
227 |
228 | /* Pass a long set to 1 to get the date of the requested document (if
229 | possible)! Pass a zero to shut it off. */
230 | FILETIME = CURLOPTTYPE.LONG + 69,
231 |
232 | /* This points to a linked list of telnet options */
233 | TELNETOPTIONS = CURLOPTTYPE.OBJECTPOINT + 70,
234 |
235 | /* Max amount of cached alive connections */
236 | MAXCONNECTS = CURLOPTTYPE.LONG + 71,
237 |
238 | OBSOLETE72 = CURLOPTTYPE.LONG + 72, /* OBSOLETE, do not use! */
239 |
240 | /* 73 = OBSOLETE */
241 |
242 | /* Set to explicitly use a new connection for the upcoming transfer.
243 | Do not use this unless you're absolutely sure of this, as it makes the
244 | operation slower and is less friendly for the network. */
245 | FRESH_CONNECT = CURLOPTTYPE.LONG + 74,
246 |
247 | /* Set to explicitly forbid the upcoming transfer's connection to be re-used
248 | when done. Do not use this unless you're absolutely sure of this, as it
249 | makes the operation slower and is less friendly for the network. */
250 | FORBID_REUSE = CURLOPTTYPE.LONG + 75,
251 |
252 | /* Set to a file name that contains random data for libcurl to use to
253 | seed the random engine when doing SSL connects. */
254 | RANDOM_FILE = CURLOPTTYPE.STRINGPOINT + 76,
255 |
256 | /* Set to the Entropy Gathering Daemon socket pathname */
257 | EGDSOCKET = CURLOPTTYPE.STRINGPOINT + 77,
258 |
259 | /* Time-out connect operations after this amount of seconds, if connects are
260 | OK within this time, then fine... This only aborts the connect phase. */
261 | CONNECTTIMEOUT = CURLOPTTYPE.LONG + 78,
262 |
263 | /* Function that will be called to store headers (instead of fwrite). The
264 | * parameters will use fwrite() syntax, make sure to follow them. */
265 | HEADERFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 79,
266 |
267 | /* Set this to force the HTTP request to get back to GET. Only really usable
268 | if POST, PUT or a custom request have been used first.
269 | */
270 | HTTPGET = CURLOPTTYPE.LONG + 80,
271 |
272 | /* Set if we should verify the Common name from the peer certificate in ssl
273 | * handshake, set 1 to check existence, 2 to ensure that it matches the
274 | * provided hostname. */
275 | SSL_VERIFYHOST = CURLOPTTYPE.LONG + 81,
276 |
277 | /* Specify which file name to write all known cookies in after completed
278 | operation. Set file name to "-" (dash) to make it go to stdout. */
279 | COOKIEJAR = CURLOPTTYPE.STRINGPOINT + 82,
280 |
281 | /* Specify which SSL ciphers to use */
282 | SSL_CIPHER_LIST = CURLOPTTYPE.STRINGPOINT + 83,
283 |
284 | /* Specify which HTTP version to use! This must be set to one of the
285 | CURL_HTTP_VERSION* enums set below. */
286 | HTTP_VERSION = CURLOPTTYPE.LONG + 84,
287 |
288 | /* Specifically switch on or off the FTP engine's use of the EPSV command. By
289 | default, that one will always be attempted before the more traditional
290 | PASV command. */
291 | FTP_USE_EPSV = CURLOPTTYPE.LONG + 85,
292 |
293 | /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */
294 | SSLCERTTYPE = CURLOPTTYPE.STRINGPOINT + 86,
295 |
296 | /* name of the file keeping your private SSL-key */
297 | SSLKEY = CURLOPTTYPE.STRINGPOINT + 87,
298 |
299 | /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */
300 | SSLKEYTYPE = CURLOPTTYPE.STRINGPOINT + 88,
301 |
302 | /* crypto engine for the SSL-sub system */
303 | SSLENGINE = CURLOPTTYPE.STRINGPOINT + 89,
304 |
305 | /* set the crypto engine for the SSL-sub system as default
306 | the param has no meaning...
307 | */
308 | SSLENGINE_DEFAULT = CURLOPTTYPE.LONG + 90,
309 |
310 | /* Non-zero value means to use the global dns cache */
311 | DNS_USE_GLOBAL_CACHE = CURLOPTTYPE.LONG + 91, /* DEPRECATED, do not use! */
312 |
313 | /* DNS cache timeout */
314 | DNS_CACHE_TIMEOUT = CURLOPTTYPE.LONG + 92,
315 |
316 | /* send linked-list of pre-transfer QUOTE commands */
317 | PREQUOTE = CURLOPTTYPE.OBJECTPOINT + 93,
318 |
319 | /* set the debug function */
320 | DEBUGFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 94,
321 |
322 | /* set the data for the debug function */
323 | DEBUGDATA = CURLOPTTYPE.OBJECTPOINT + 95,
324 |
325 | /* mark this as start of a cookie session */
326 | COOKIESESSION = CURLOPTTYPE.LONG + 96,
327 |
328 | /* The CApath directory used to validate the peer certificate
329 | this option is used only if SSL_VERIFYPEER is true */
330 | CAPATH = CURLOPTTYPE.STRINGPOINT + 97,
331 |
332 | /* Instruct libcurl to use a smaller receive buffer */
333 | BUFFERSIZE = CURLOPTTYPE.LONG + 98,
334 |
335 | /* Instruct libcurl to not use any signal/alarm handlers, even when using
336 | timeouts. This option is useful for multi-threaded applications.
337 | See libcurl-the-guide for more background information. */
338 | NOSIGNAL = CURLOPTTYPE.LONG + 99,
339 |
340 | /* Provide a CURLShare for mutexing non-ts data */
341 | SHARE = CURLOPTTYPE.OBJECTPOINT + 100,
342 |
343 | /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default),
344 | CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and
345 | CURLPROXY_SOCKS5. */
346 | PROXYTYPE = CURLOPTTYPE.LONG + 101,
347 |
348 | /* Set the Accept-Encoding string. Use this to tell a server you would like
349 | the response to be compressed. Before 7.21.6, this was known as
350 | CURLOPT_ENCODING */
351 | ACCEPT_ENCODING = CURLOPTTYPE.STRINGPOINT + 102,
352 |
353 | /* Set pointer to private data */
354 | PRIVATE = CURLOPTTYPE.OBJECTPOINT + 103,
355 |
356 | /* Set aliases for HTTP 200 in the HTTP Response header */
357 | HTTP200ALIASES = CURLOPTTYPE.OBJECTPOINT + 104,
358 |
359 | /* Continue to send authentication (user+password) when following locations,
360 | even when hostname changed. This can potentially send off the name
361 | and password to whatever host the server decides. */
362 | UNRESTRICTED_AUTH = CURLOPTTYPE.LONG + 105,
363 |
364 | /* Specifically switch on or off the FTP engine's use of the EPRT command (
365 | it also disables the LPRT attempt). By default, those ones will always be
366 | attempted before the good old traditional PORT command. */
367 | FTP_USE_EPRT = CURLOPTTYPE.LONG + 106,
368 |
369 | /* Set this to a bitmask value to enable the particular authentications
370 | methods you like. Use this in combination with CURLOPT_USERPWD.
371 | Note that setting multiple bits may cause extra network round-trips. */
372 | HTTPAUTH = CURLOPTTYPE.LONG + 107,
373 |
374 | /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx
375 | in second argument. The function must be matching the
376 | curl_ssl_ctx_callback proto. */
377 | SSL_CTX_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 108,
378 |
379 | /* Set the userdata for the ssl context callback function's third
380 | argument */
381 | SSL_CTX_DATA = CURLOPTTYPE.OBJECTPOINT + 109,
382 |
383 | /* FTP Option that causes missing dirs to be created on the remote server.
384 | In 7.19.4 we introduced the convenience enums for this option using the
385 | CURLFTP_CREATE_DIR prefix.
386 | */
387 | FTP_CREATE_MISSING_DIRS = CURLOPTTYPE.LONG + 110,
388 |
389 | /* Set this to a bitmask value to enable the particular authentications
390 | methods you like. Use this in combination with CURLOPT_PROXYUSERPWD.
391 | Note that setting multiple bits may cause extra network round-trips. */
392 | PROXYAUTH = CURLOPTTYPE.LONG + 111,
393 |
394 | /* FTP option that changes the timeout, in seconds, associated with
395 | getting a response. This is different from transfer timeout time and
396 | essentially places a demand on the FTP server to acknowledge commands
397 | in a timely manner. */
398 | FTP_RESPONSE_TIMEOUT = CURLOPTTYPE.LONG + 112,
399 |
400 | /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to
401 | tell libcurl to resolve names to those IP versions only. This only has
402 | affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */
403 | IPRESOLVE = CURLOPTTYPE.LONG + 113,
404 |
405 | /* Set this option to limit the size of a file that will be downloaded from
406 | an HTTP or FTP server.
407 | Note there is also _LARGE version which adds large file support for
408 | platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */
409 | MAXFILESIZE = CURLOPTTYPE.LONG + 114,
410 |
411 | /* See the comment for INFILESIZE above, but in short, specifies
412 | * the size of the file being uploaded. -1 means unknown.
413 | */
414 | INFILESIZE_LARGE = CURLOPTTYPE.OFF_T + 115,
415 |
416 | /* Sets the continuation offset. There is also a LONG version of this;
417 | * look above for RESUME_FROM.
418 | */
419 | RESUME_FROM_LARGE = CURLOPTTYPE.OFF_T + 116,
420 |
421 | /* Sets the maximum size of data that will be downloaded from
422 | * an HTTP or FTP server. See MAXFILESIZE above for the LONG version.
423 | */
424 | MAXFILESIZE_LARGE = CURLOPTTYPE.OFF_T + 117,
425 |
426 | /* Set this option to the file name of your .netrc file you want libcurl
427 | to parse (using the CURLOPT_NETRC option). If not set, libcurl will do
428 | a poor attempt to find the user's home directory and check for a .netrc
429 | file in there. */
430 | NETRC_FILE = CURLOPTTYPE.STRINGPOINT + 118,
431 |
432 | /* Enable SSL/TLS for FTP, pick one of:
433 | CURLUSESSL_TRY - try using SSL, proceed anyway otherwise
434 | CURLUSESSL_CONTROL - SSL for the control connection or fail
435 | CURLUSESSL_ALL - SSL for all communication or fail
436 | */
437 | USE_SSL = CURLOPTTYPE.LONG + 119,
438 |
439 | /* The _LARGE version of the standard POSTFIELDSIZE option */
440 | POSTFIELDSIZE_LARGE = CURLOPTTYPE.OFF_T + 120,
441 |
442 | /* Enable/disable the TCP Nagle algorithm */
443 | TCP_NODELAY = CURLOPTTYPE.LONG + 121,
444 |
445 | /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
446 | /* 123 OBSOLETE. Gone in 7.16.0 */
447 | /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
448 | /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
449 | /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
450 | /* 127 OBSOLETE. Gone in 7.16.0 */
451 | /* 128 OBSOLETE. Gone in 7.16.0 */
452 |
453 | /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option
454 | can be used to change libcurl's default action which is to first try
455 | "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK
456 | response has been received.
457 | Available parameters are:
458 | CURLFTPAUTH_DEFAULT - let libcurl decide
459 | CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS
460 | CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL
461 | */
462 | FTPSSLAUTH = CURLOPTTYPE.LONG + 129,
463 |
464 | IOCTLFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 130,
465 | IOCTLDATA = CURLOPTTYPE.OBJECTPOINT + 131,
466 |
467 | /* 132 OBSOLETE. Gone in 7.16.0 */
468 | /* 133 OBSOLETE. Gone in 7.16.0 */
469 |
470 | /* zero terminated string for pass on to the FTP server when asked for
471 | "account" info */
472 | FTP_ACCOUNT = CURLOPTTYPE.STRINGPOINT + 134,
473 |
474 | /* feed cookie into cookie engine */
475 | COOKIELIST = CURLOPTTYPE.STRINGPOINT + 135,
476 |
477 | /* ignore Content-Length */
478 | IGNORE_CONTENT_LENGTH = CURLOPTTYPE.LONG + 136,
479 |
480 | /* Set to non-zero to skip the IP address received in a 227 PASV FTP server
481 | response. Typically used for FTP-SSL purposes but is not restricted to
482 | that. libcurl will then instead use the same IP address it used for the
483 | control connection. */
484 | FTP_SKIP_PASV_IP = CURLOPTTYPE.LONG + 137,
485 |
486 | /* Select "file method" to use when doing FTP, see the curl_ftpmethod
487 | above. */
488 | FTP_FILEMETHOD = CURLOPTTYPE.LONG + 138,
489 |
490 | /* Local port number to bind the socket to */
491 | LOCALPORT = CURLOPTTYPE.LONG + 139,
492 |
493 | /* Number of ports to try, including the first one set with LOCALPORT.
494 | Thus, setting it to 1 will make no additional attempts but the first.
495 | */
496 | LOCALPORTRANGE = CURLOPTTYPE.LONG + 140,
497 |
498 | /* no transfer, set up connection and let application use the socket by
499 | extracting it with CURLINFO_LASTSOCKET */
500 | CONNECT_ONLY = CURLOPTTYPE.LONG + 141,
501 |
502 | /* Function that will be called to convert from the
503 | network encoding (instead of using the iconv calls in libcurl) */
504 | CONV_FROM_NETWORK_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 142,
505 |
506 | /* Function that will be called to convert to the
507 | network encoding (instead of using the iconv calls in libcurl) */
508 | CONV_TO_NETWORK_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 143,
509 |
510 | /* Function that will be called to convert from UTF8
511 | (instead of using the iconv calls in libcurl)
512 | Note that this is used only for SSL certificate processing */
513 | CONV_FROM_UTF8_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 144,
514 |
515 | /* if the connection proceeds too quickly then need to slow it down */
516 | /* limit-rate: maximum number of bytes per second to send or receive */
517 | MAX_SEND_SPEED_LARGE = CURLOPTTYPE.OFF_T + 145,
518 | MAX_RECV_SPEED_LARGE = CURLOPTTYPE.OFF_T + 146,
519 |
520 | /* Pointer to command string to send if USER/PASS fails. */
521 | FTP_ALTERNATIVE_TO_USER = CURLOPTTYPE.STRINGPOINT + 147,
522 |
523 | /* callback function for setting socket options */
524 | SOCKOPTFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 148,
525 | SOCKOPTDATA = CURLOPTTYPE.OBJECTPOINT + 149,
526 |
527 | /* set to 0 to disable session ID re-use for this transfer, default is
528 | enabled (== 1) */
529 | SSL_SESSIONID_CACHE = CURLOPTTYPE.LONG + 150,
530 |
531 | /* allowed SSH authentication methods */
532 | SSH_AUTH_TYPES = CURLOPTTYPE.LONG + 151,
533 |
534 | /* Used by scp/sftp to do public/private key authentication */
535 | SSH_PUBLIC_KEYFILE = CURLOPTTYPE.STRINGPOINT + 152,
536 | SSH_PRIVATE_KEYFILE = CURLOPTTYPE.STRINGPOINT + 153,
537 |
538 | /* Send CCC (Clear Command Channel) after authentication */
539 | FTP_SSL_CCC = CURLOPTTYPE.LONG + 154,
540 |
541 | /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */
542 | TIMEOUT_MS = CURLOPTTYPE.LONG + 155,
543 | CONNECTTIMEOUT_MS = CURLOPTTYPE.LONG + 156,
544 |
545 | /* set to zero to disable the libcurl's decoding and thus pass the raw body
546 | data to the application even when it is encoded/compressed */
547 | HTTP_TRANSFER_DECODING = CURLOPTTYPE.LONG + 157,
548 | HTTP_CONTENT_DECODING = CURLOPTTYPE.LONG + 158,
549 |
550 | /* Permission used when creating new files and directories on the remote
551 | server for protocols that support it, SFTP/SCP/FILE */
552 | NEW_FILE_PERMS = CURLOPTTYPE.LONG + 159,
553 | NEW_DIRECTORY_PERMS = CURLOPTTYPE.LONG + 160,
554 |
555 | /* Set the behaviour of POST when redirecting. Values must be set to one
556 | of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */
557 | POSTREDIR = CURLOPTTYPE.LONG + 161,
558 |
559 | /* used by scp/sftp to verify the host's public key */
560 | SSH_HOST_PUBLIC_KEY_MD5 = CURLOPTTYPE.STRINGPOINT + 162,
561 |
562 | /* Callback function for opening socket (instead of socket(2)). Optionally,
563 | callback is able change the address or refuse to connect returning
564 | CURL_SOCKET_BAD. The callback should have type
565 | curl_opensocket_callback */
566 | OPENSOCKETFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 163,
567 | OPENSOCKETDATA = CURLOPTTYPE.OBJECTPOINT + 164,
568 |
569 | /* POST volatile input fields. */
570 | COPYPOSTFIELDS = CURLOPTTYPE.OBJECTPOINT + 165,
571 |
572 | /* set transfer mode (;type=) when doing FTP via an HTTP proxy */
573 | PROXY_TRANSFER_MODE = CURLOPTTYPE.LONG + 166,
574 |
575 | /* Callback function for seeking in the input stream */
576 | SEEKFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 167,
577 | SEEKDATA = CURLOPTTYPE.OBJECTPOINT + 168,
578 |
579 | /* CRL file */
580 | CRLFILE = CURLOPTTYPE.STRINGPOINT + 169,
581 |
582 | /* Issuer certificate */
583 | ISSUERCERT = CURLOPTTYPE.STRINGPOINT + 170,
584 |
585 | /* (IPv6) Address scope */
586 | ADDRESS_SCOPE = CURLOPTTYPE.LONG + 171,
587 |
588 | /* Collect certificate chain info and allow it to get retrievable with
589 | CURLINFO_CERTINFO after the transfer is complete. */
590 | CERTINFO = CURLOPTTYPE.LONG + 172,
591 |
592 | /* "name" and "pwd" to use when fetching. */
593 | USERNAME = CURLOPTTYPE.STRINGPOINT + 173,
594 | PASSWORD = CURLOPTTYPE.STRINGPOINT + 174,
595 |
596 | /* "name" and "pwd" to use with Proxy when fetching. */
597 | PROXYUSERNAME = CURLOPTTYPE.STRINGPOINT + 175,
598 | PROXYPASSWORD = CURLOPTTYPE.STRINGPOINT + 176,
599 |
600 | /* Comma separated list of hostnames defining no-proxy zones. These should
601 | match both hostnames directly, and hostnames within a domain. For
602 | example, local.com will match local.com and www.local.com, but NOT
603 | notlocal.com or www.notlocal.com. For compatibility with other
604 | implementations of this, .local.com will be considered to be the same as
605 | local.com. A single * is the only valid wildcard, and effectively
606 | disables the use of proxy. */
607 | NOPROXY = CURLOPTTYPE.STRINGPOINT + 177,
608 |
609 | /* block size for TFTP transfers */
610 | TFTP_BLKSIZE = CURLOPTTYPE.LONG + 178,
611 |
612 | /* Socks Service */
613 | SOCKS5_GSSAPI_SERVICE = CURLOPTTYPE.STRINGPOINT + 179, /* DEPRECATED, do not use! */
614 |
615 | /* Socks Service */
616 | SOCKS5_GSSAPI_NEC = CURLOPTTYPE.LONG + 180,
617 |
618 | /* set the bitmask for the protocols that are allowed to be used for the
619 | transfer, which thus helps the app which takes URLs from users or other
620 | external inputs and want to restrict what protocol(s) to deal
621 | with. Defaults to CURLPROTO_ALL. */
622 | PROTOCOLS = CURLOPTTYPE.LONG + 181,
623 |
624 | /* set the bitmask for the protocols that libcurl is allowed to follow to,
625 | as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
626 | to be set in both bitmasks to be allowed to get redirected to. Defaults
627 | to all protocols except FILE and SCP. */
628 | REDIR_PROTOCOLS = CURLOPTTYPE.LONG + 182,
629 |
630 | /* set the SSH knownhost file name to use */
631 | SSH_KNOWNHOSTS = CURLOPTTYPE.STRINGPOINT + 183,
632 |
633 | /* set the SSH host key callback, must point to a curl_sshkeycallback
634 | function */
635 | SSH_KEYFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 184,
636 |
637 | /* set the SSH host key callback custom pointer */
638 | SSH_KEYDATA = CURLOPTTYPE.OBJECTPOINT + 185,
639 |
640 | /* set the SMTP mail originator */
641 | MAIL_FROM = CURLOPTTYPE.STRINGPOINT + 186,
642 |
643 | /* set the list of SMTP mail receiver(s) */
644 | MAIL_RCPT = CURLOPTTYPE.OBJECTPOINT + 187,
645 |
646 | /* FTP: send PRET before PASV */
647 | FTP_USE_PRET = CURLOPTTYPE.LONG + 188,
648 |
649 | /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */
650 | RTSP_REQUEST = CURLOPTTYPE.LONG + 189,
651 |
652 | /* The RTSP session identifier */
653 | RTSP_SESSION_ID = CURLOPTTYPE.STRINGPOINT + 190,
654 |
655 | /* The RTSP stream URI */
656 | RTSP_STREAM_URI = CURLOPTTYPE.STRINGPOINT + 191,
657 |
658 | /* The Transport: header to use in RTSP requests */
659 | RTSP_TRANSPORT = CURLOPTTYPE.STRINGPOINT + 192,
660 |
661 | /* Manually initialize the client RTSP CSeq for this handle */
662 | RTSP_CLIENT_CSEQ = CURLOPTTYPE.LONG + 193,
663 |
664 | /* Manually initialize the server RTSP CSeq for this handle */
665 | RTSP_SERVER_CSEQ = CURLOPTTYPE.LONG + 194,
666 |
667 | /* The stream to pass to INTERLEAVEFUNCTION. */
668 | INTERLEAVEDATA = CURLOPTTYPE.OBJECTPOINT + 195,
669 |
670 | /* Let the application define a custom write method for RTP data */
671 | INTERLEAVEFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 196,
672 |
673 | /* Turn on wildcard matching */
674 | WILDCARDMATCH = CURLOPTTYPE.LONG + 197,
675 |
676 | /* Directory matching callback called before downloading of an
677 | individual file (chunk) started */
678 | CHUNK_BGN_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 198,
679 |
680 | /* Directory matching callback called after the file (chunk)
681 | was downloaded, or skipped */
682 | CHUNK_END_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 199,
683 |
684 | /* Change match (fnmatch-like) callback for wildcard matching */
685 | FNMATCH_FUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 200,
686 |
687 | /* Let the application define custom chunk data pointer */
688 | CHUNK_DATA = CURLOPTTYPE.OBJECTPOINT + 201,
689 |
690 | /* FNMATCH_FUNCTION user pointer */
691 | FNMATCH_DATA = CURLOPTTYPE.OBJECTPOINT + 202,
692 |
693 | /* send linked-list of name:port:address sets */
694 | RESOLVE = CURLOPTTYPE.OBJECTPOINT + 203,
695 |
696 | /* Set a username for authenticated TLS */
697 | TLSAUTH_USERNAME = CURLOPTTYPE.STRINGPOINT + 204,
698 |
699 | /* Set a password for authenticated TLS */
700 | TLSAUTH_PASSWORD = CURLOPTTYPE.STRINGPOINT + 205,
701 |
702 | /* Set authentication type for authenticated TLS */
703 | TLSAUTH_TYPE = CURLOPTTYPE.STRINGPOINT + 206,
704 |
705 | /* Set to 1 to enable the "TE:" header in HTTP requests to ask for
706 | compressed transfer-encoded responses. Set to 0 to disable the use of TE:
707 | in outgoing requests. The current default is 0, but it might change in a
708 | future libcurl release.
709 | libcurl will ask for the compressed methods it knows of, and if that
710 | isn't any, it will not ask for transfer-encoding at all even if this
711 | option is set to 1.
712 | */
713 | TRANSFER_ENCODING = CURLOPTTYPE.LONG + 207,
714 |
715 | /* Callback function for closing socket (instead of close(2)). The callback
716 | should have type curl_closesocket_callback */
717 | CLOSESOCKETFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 208,
718 | CLOSESOCKETDATA = CURLOPTTYPE.OBJECTPOINT + 209,
719 |
720 | /* allow GSSAPI credential delegation */
721 | GSSAPI_DELEGATION = CURLOPTTYPE.LONG + 210,
722 |
723 | /* Set the name servers to use for DNS resolution */
724 | DNS_SERVERS = CURLOPTTYPE.STRINGPOINT + 211,
725 |
726 | /* Time-out accept operations (currently for FTP only) after this amount
727 | of milliseconds. */
728 | ACCEPTTIMEOUT_MS = CURLOPTTYPE.LONG + 212,
729 |
730 | /* Set TCP keepalive */
731 | TCP_KEEPALIVE = CURLOPTTYPE.LONG + 213,
732 |
733 | /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */
734 | TCP_KEEPIDLE = CURLOPTTYPE.LONG + 214,
735 | TCP_KEEPINTVL = CURLOPTTYPE.LONG + 215,
736 |
737 | /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */
738 | SSL_OPTIONS = CURLOPTTYPE.LONG + 216,
739 |
740 | /* Set the SMTP auth originator */
741 | MAIL_AUTH = CURLOPTTYPE.STRINGPOINT + 217,
742 |
743 | /* Enable/disable SASL initial response */
744 | SASL_IR = CURLOPTTYPE.LONG + 218,
745 |
746 | /* Function that will be called instead of the internal progress display
747 | * function. This function should be defined as the curl_xferinfo_callback
748 | * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */
749 | XFERINFOFUNCTION = CURLOPTTYPE.FUNCTIONPOINT + 219,
750 |
751 | /* The XOAUTH2 bearer token */
752 | XOAUTH2_BEARER = CURLOPTTYPE.STRINGPOINT + 220,
753 |
754 | /* Set the interface string to use as outgoing network
755 | * interface for DNS requests.
756 | * Only supported by the c-ares DNS backend */
757 | DNS_INTERFACE = CURLOPTTYPE.STRINGPOINT + 221,
758 |
759 | /* Set the local IPv4 address to use for outgoing DNS requests.
760 | * Only supported by the c-ares DNS backend */
761 | DNS_LOCAL_IP4 = CURLOPTTYPE.STRINGPOINT + 222,
762 |
763 | /* Set the local IPv4 address to use for outgoing DNS requests.
764 | * Only supported by the c-ares DNS backend */
765 | DNS_LOCAL_IP6 = CURLOPTTYPE.STRINGPOINT + 223,
766 |
767 | /* Set authentication options directly */
768 | LOGIN_OPTIONS = CURLOPTTYPE.STRINGPOINT + 224,
769 |
770 | /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */
771 | SSL_ENABLE_NPN = CURLOPTTYPE.LONG + 225,
772 |
773 | /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */
774 | SSL_ENABLE_ALPN = CURLOPTTYPE.LONG + 226,
775 |
776 | /* Time to wait for a response to a HTTP request containing an
777 | * Expect: 100-continue header before sending the data anyway. */
778 | EXPECT_100_TIMEOUT_MS = CURLOPTTYPE.LONG + 227,
779 |
780 | /* This points to a linked list of headers used for proxy requests only,
781 | struct curl_slist kind */
782 | PROXYHEADER = CURLOPTTYPE.OBJECTPOINT + 228,
783 |
784 | /* Pass in a bitmask of "header options" */
785 | HEADEROPT = CURLOPTTYPE.LONG + 229,
786 |
787 | /* The public key in DER form used to validate the peer public key
788 | this option is used only if SSL_VERIFYPEER is true */
789 | PINNEDPUBLICKEY = CURLOPTTYPE.STRINGPOINT + 230,
790 |
791 | /* Path to Unix domain socket */
792 | UNIX_SOCKET_PATH = CURLOPTTYPE.STRINGPOINT + 231,
793 |
794 | /* Set if we should verify the certificate status. */
795 | SSL_VERIFYSTATUS = CURLOPTTYPE.LONG + 232,
796 |
797 | /* Set if we should enable TLS false start. */
798 | SSL_FALSESTART = CURLOPTTYPE.LONG + 233,
799 |
800 | /* Do not squash dot-dot sequences */
801 | PATH_AS_IS = CURLOPTTYPE.LONG + 234,
802 |
803 | /* Proxy Service Name */
804 | PROXY_SERVICE_NAME = CURLOPTTYPE.STRINGPOINT + 235,
805 |
806 | /* Service Name */
807 | SERVICE_NAME = CURLOPTTYPE.STRINGPOINT + 236,
808 |
809 | /* Wait/don't wait for pipe/mutex to clarify */
810 | PIPEWAIT = CURLOPTTYPE.LONG + 237,
811 |
812 | /* Set the protocol used when curl is given a URL without a protocol */
813 | DEFAULT_PROTOCOL = CURLOPTTYPE.STRINGPOINT + 238,
814 |
815 | /* Set stream weight, 1 - 256 (default is 16) */
816 | STREAM_WEIGHT = CURLOPTTYPE.LONG + 239,
817 |
818 | /* Set stream dependency on another CURL handle */
819 | STREAM_DEPENDS = CURLOPTTYPE.OBJECTPOINT + 240,
820 |
821 | /* Set E-xclusive stream dependency on another CURL handle */
822 | STREAM_DEPENDS_E = CURLOPTTYPE.OBJECTPOINT + 241,
823 |
824 | /* Do not send any tftp option requests to the server */
825 | TFTP_NO_OPTIONS = CURLOPTTYPE.LONG + 242,
826 |
827 | /* Linked-list of host:port:connect-to-host:connect-to-port,
828 | overrides the URL's host:port (only for the network layer) */
829 | CONNECT_TO = CURLOPTTYPE.OBJECTPOINT + 243,
830 |
831 | /* Set TCP Fast Open */
832 | TCP_FASTOPEN = CURLOPTTYPE.LONG + 244,
833 |
834 | /* Continue to send data if the server responds early with an
835 | * HTTP status code >= 300 */
836 | KEEP_SENDING_ON_ERROR = CURLOPTTYPE.LONG + 245,
837 |
838 | /* The CApath or CAfile used to validate the proxy certificate
839 | this option is used only if PROXY_SSL_VERIFYPEER is true */
840 | PROXY_CAINFO = CURLOPTTYPE.STRINGPOINT + 246,
841 |
842 | /* The CApath directory used to validate the proxy certificate
843 | this option is used only if PROXY_SSL_VERIFYPEER is true */
844 | PROXY_CAPATH = CURLOPTTYPE.STRINGPOINT + 247,
845 |
846 | /* Set if we should verify the proxy in ssl handshake,
847 | set 1 to verify. */
848 | PROXY_SSL_VERIFYPEER = CURLOPTTYPE.LONG + 248,
849 |
850 | /* Set if we should verify the Common name from the proxy certificate in ssl
851 | * handshake, set 1 to check existence, 2 to ensure that it matches
852 | * the provided hostname. */
853 | PROXY_SSL_VERIFYHOST = CURLOPTTYPE.LONG + 249,
854 |
855 | /* What version to specifically try to use for proxy.
856 | See CURL_SSLVERSION defines below. */
857 | PROXY_SSLVERSION = CURLOPTTYPE.LONG + 250,
858 |
859 | /* Set a username for authenticated TLS for proxy */
860 | PROXY_TLSAUTH_USERNAME = CURLOPTTYPE.STRINGPOINT + 251,
861 |
862 | /* Set a password for authenticated TLS for proxy */
863 | PROXY_TLSAUTH_PASSWORD = CURLOPTTYPE.STRINGPOINT + 252,
864 |
865 | /* Set authentication type for authenticated TLS for proxy */
866 | PROXY_TLSAUTH_TYPE = CURLOPTTYPE.STRINGPOINT + 253,
867 |
868 | /* name of the file keeping your private SSL-certificate for proxy */
869 | PROXY_SSLCERT = CURLOPTTYPE.STRINGPOINT + 254,
870 |
871 | /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") for
872 | proxy */
873 | PROXY_SSLCERTTYPE = CURLOPTTYPE.STRINGPOINT + 255,
874 |
875 | /* name of the file keeping your private SSL-key for proxy */
876 | PROXY_SSLKEY = CURLOPTTYPE.STRINGPOINT + 256,
877 |
878 | /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") for
879 | proxy */
880 | PROXY_SSLKEYTYPE = CURLOPTTYPE.STRINGPOINT + 257,
881 |
882 | /* password for the SSL private key for proxy */
883 | PROXY_KEYPASSWD = CURLOPTTYPE.STRINGPOINT + 258,
884 |
885 | /* Specify which SSL ciphers to use for proxy */
886 | PROXY_SSL_CIPHER_LIST = CURLOPTTYPE.STRINGPOINT + 259,
887 |
888 | /* CRL file for proxy */
889 | PROXY_CRLFILE = CURLOPTTYPE.STRINGPOINT + 260,
890 |
891 | /* Enable/disable specific SSL features with a bitmask for proxy, see
892 | CURLSSLOPT_* */
893 | PROXY_SSL_OPTIONS = CURLOPTTYPE.LONG + 261,
894 |
895 | /* Name of pre proxy to use. */
896 | PRE_PROXY = CURLOPTTYPE.STRINGPOINT + 262,
897 |
898 | /* The public key in DER form used to validate the proxy public key
899 | this option is used only if PROXY_SSL_VERIFYPEER is true */
900 | PROXY_PINNEDPUBLICKEY = CURLOPTTYPE.STRINGPOINT + 263,
901 |
902 | /* Path to an abstract Unix domain socket */
903 | ABSTRACT_UNIX_SOCKET = CURLOPTTYPE.STRINGPOINT + 264,
904 |
905 | /* Suppress proxy CONNECT response headers from user callbacks */
906 | SUPPRESS_CONNECT_HEADERS = CURLOPTTYPE.LONG + 265,
907 |
908 | CURLOPT_LASTENTRY /* the last unused */
909 | }
910 | }
--------------------------------------------------------------------------------