/// <summary> /// Constructor /// </summary> /// <exception cref="System.InvalidOperationException">This is thrown /// if <see cref="Curl"/> hasn't bee properly initialized.</exception> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public Easy() { Curl.EnsureCurl(); m_pCURL = External.curl_easy_init(); EnsureHandle(); External.curl_easy_setopt_int(m_pCURL, CURLoption.CURLOPT_NOPROGRESS, 1); m_pMyStrings = External.curl_shim_alloc_strings(); m_pfWrite = null; m_privateData = null; m_writeData = null; m_pfRead = null; m_readData = null; m_pfProgress = null; m_progressData = null; m_pfDebug = null; m_debugData = null; m_pfHeader = null; m_headerData = null; m_pfSSLContext = null; m_sslContextData = null; m_pfIoctl = null; m_ioctlData = null; InstallDelegates(); }
/// <summary> /// Extract <c>DateTime</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be <see cref="CURLINFO.CURLINFO_FILETIME"/>. /// </param> /// <param name="dt">Reference to a <c>DateTime</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref DateTime dt) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; IntPtr ptr = IntPtr.Zero; if (info != CURLINFO.CURLINFO_FILETIME) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_getinfo(m_pCURL, info, ref ptr); if (retCode == CURLcode.CURLE_OK) { if ((int)ptr < 0) { dt = new DateTime(0); } else { int yy = 0, mm = 0, dd = 0, hh = 0, mn = 0, ss = 0; External.curl_shim_get_file_time((int)ptr, ref yy, ref mm, ref dd, ref hh, ref mn, ref ss); dt = new DateTime(yy, mm, dd, hh, mn, ss); } } return(retCode); }
/// <summary> /// Obtain status information for a Multi transfer. /// </summary> /// <returns> /// An array of <see cref="MultiInfo"/> objects, one for each /// <see cref="Easy"/> object child. /// </returns> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public MultiInfo[] InfoRead() { if (m_bGotMultiInfo) { return(m_multiInfo); } m_bGotMultiInfo = true; int nMsgs = 0; IntPtr pInfo = External.curl_shim_multi_info_read(m_pMulti, ref nMsgs); if (pInfo != IntPtr.Zero) { m_multiInfo = new MultiInfo[nMsgs]; for (int i = 0; i < nMsgs; i++) { CURLMSG msg = (CURLMSG)Marshal.ReadInt32( pInfo, i * 12); IntPtr pEasy = Marshal.ReadIntPtr( pInfo, i * 12 + 4); CURLcode code = (CURLcode)Marshal.ReadInt32( pInfo, i * 12 + 8); m_multiInfo[i] = new MultiInfo(msg, (Easy)m_htEasy[pEasy], code); } External.curl_shim_multi_info_free(pInfo); } return(m_multiInfo); }
/// <summary> /// Process-wide cleanup -- call just before exiting process. /// </summary> /// <remarks> /// While it's not necessary that your program call this method /// before exiting, doing so will prevent leaks of native cURL resources. /// </remarks> public static void GlobalCleanup() { if (sm_curlCode == CURLcode.CURLE_OK) { External.curl_shim_cleanup(); External.curl_global_cleanup(); sm_curlCode = CURLcode.CURLE_FAILED_INIT; } }
/// <summary> /// Process-wide initialization -- call only once per process. /// </summary> /// <param name="flags">An or'd combination of /// <see cref="CURLinitFlag"/> members.</param> /// <returns>A <see cref="CURLcode"/>, hopefully /// <c>CURLcode.CURLE_OK</c>.</returns> public static CURLcode GlobalInit(int flags) { sm_curlCode = External.curl_global_init(flags); if (sm_curlCode == CURLcode.CURLE_OK) { External.curl_shim_initialize(); } return(sm_curlCode); }
/// <summary> /// Remove an Easy object. /// </summary> /// <param name="easy"> /// <see cref="Easy"/> object to remove. /// </param> /// <returns> /// A <see cref="CURLMcode"/>, hopefully <c>CURLMcode.CURLM_OK</c> /// </returns> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public CURLMcode RemoveHandle(Easy easy) { EnsureHandle(); IntPtr p = easy.GetHandle(); m_htEasy.Remove(p); return(External.curl_multi_remove_handle(m_pMulti, easy.GetHandle())); }
/// <summary> /// Add an Easy object. /// </summary> /// <param name="easy"> /// <see cref="Easy"/> object to add. /// </param> /// <returns> /// A <see cref="CURLMcode"/>, hopefully <c>CURLMcode.CURLM_OK</c> /// </returns> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public CURLMcode AddHandle(Easy easy) { EnsureHandle(); IntPtr p = easy.GetHandle(); m_htEasy.Add(p, easy); return(External.curl_multi_add_handle(m_pMulti, easy.GetHandle())); }
private void InstallDelegates() { m_pDelLock = new External.CURLSH_LOCK_DELEGATE(LockDelegate); m_pDelUnlock = new External.CURLSH_UNLOCK_DELEGATE(UnlockDelegate); m_hThis = GCHandle.Alloc(this); m_ptrThis = (IntPtr)m_hThis; External.curl_shim_install_share_delegates(m_pShare, m_ptrThis, m_pDelLock, m_pDelUnlock); }
/// <summary> /// URL decode a String. /// </summary> /// <param name="url">The string to URL decode.</param> /// <param name="length">Input string length; /// use 0 for cURL to determine.</param> /// <returns>A new URL decoded string.</returns> /// <exception cref="System.InvalidOperationException"> /// Thrown if cURL isn't properly initialized.</exception> public static string Unescape(string url, int length) { EnsureCurl(); IntPtr p = External.curl_unescape(url, length); String s = Marshal.PtrToStringAnsi(p); External.curl_free(p); return(s); }
private External.CURLSH_UNLOCK_DELEGATE m_pDelUnlock; // unlock delegate /// <summary> /// Constructor /// </summary> /// <exception cref="System.InvalidOperationException">This is thrown /// if <see cref="Curl"/> hasn't bee properly initialized.</exception> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>share</c> handle wasn't created successfully.</exception> public Share() { Curl.EnsureCurl(); m_pShare = External.curl_share_init(); EnsureHandle(); m_pfLock = null; m_pfUnlock = null; m_userData = null; InstallDelegates(); }
private void Dispose(bool disposing) { lock (this) { // no if (disposing) pattern to clean up managed objects if (m_pStringList != IntPtr.Zero) { External.curl_shim_free_slist(m_pStringList); m_pStringList = IntPtr.Zero; } } }
/// <summary> /// Extract <c>int</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be one of the members that obtains a <c>double</c>. /// </param> /// <param name="dblVal">Reference to an <c>double</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref double dblVal) { EnsureHandle(); // ensure it's an integral type if ((int)info < CURLINFO_DOUBLE) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } return(External.curl_easy_getinfo_double(m_pCURL, info, ref dblVal)); }
/// <summary> /// Constructor /// </summary> /// <exception cref="System.InvalidOperationException">This is thrown /// if <see cref="Curl"/> hasn't bee properly initialized.</exception> /// <exception cref="System.NullReferenceException"> /// This is thrown if the native <c>Multi</c> handle wasn't /// created successfully. /// </exception> public Multi() { Curl.EnsureCurl(); m_pMulti = External.curl_multi_init(); EnsureHandle(); m_fdSets = IntPtr.Zero; m_maxFD = 0; m_fdSets = External.curl_shim_alloc_fd_sets(); m_multiInfo = null; m_bGotMultiInfo = false; m_htEasy = new Hashtable(); }
private void Dispose(bool disposing) { lock (this) { // no if (disposing) pattern to clean up managed objects if (m_pItems[0] != IntPtr.Zero) { External.curl_formfree(m_pItems[0]); } m_pItems[0] = IntPtr.Zero; m_pItems[1] = IntPtr.Zero; } }
private void Dispose(bool disposing) { lock (this) { // if (disposing) cleanup managed objects if (m_pShare != IntPtr.Zero) { External.curl_shim_cleanup_share_delegates(m_pShare); External.curl_share_cleanup(m_pShare); m_hThis.Free(); m_ptrThis = IntPtr.Zero; m_pShare = IntPtr.Zero; } } }
/// <summary> /// Set options for this object. /// </summary> /// <param name="option"> /// One of the values in the <see cref="CURLSHoption"/> /// enumeration. /// </param> /// <param name="parameter"> /// An appropriate object based on the value passed in the /// <c>option</c> argument. See <see cref="CURLSHoption"/> /// for more information about the appropriate parameter type. /// </param> /// <returns> /// A <see cref="CURLSHcode"/>, hopefully /// <c>CURLSHcode.CURLSHE_OK</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>share</c> handle wasn't created successfully.</exception> public CURLSHcode SetOpt(CURLSHoption option, Object parameter) { EnsureHandle(); CURLSHcode retCode = CURLSHcode.CURLSHE_OK; switch (option) { case CURLSHoption.CURLSHOPT_LOCKFUNC: LockFunction lf = parameter as LockFunction; if (lf == null) { return(CURLSHcode.CURLSHE_BAD_OPTION); } m_pfLock = lf; break; case CURLSHoption.CURLSHOPT_UNLOCKFUNC: UnlockFunction ulf = parameter as UnlockFunction; if (ulf == null) { return(CURLSHcode.CURLSHE_BAD_OPTION); } m_pfUnlock = ulf; break; case CURLSHoption.CURLSHOPT_SHARE: case CURLSHoption.CURLSHOPT_UNSHARE: { CURLlockData opt = (CURLlockData) Convert.ToInt32(parameter); if ((opt != CURLlockData.CURL_LOCK_DATA_COOKIE) && (opt != CURLlockData.CURL_LOCK_DATA_DNS)) { return(CURLSHcode.CURLSHE_BAD_OPTION); } retCode = External.curl_share_setopt(m_pShare, option, (IntPtr)opt); break; } case CURLSHoption.CURLSHOPT_USERDATA: m_userData = parameter; break; default: retCode = CURLSHcode.CURLSHE_BAD_OPTION; break; } return(retCode); }
// install the fuctions that will be called from libcurlshim private void InstallDelegates() { m_pDelWrite = new External.CURL_WRITE_DELEGATE(WriteDelegate); m_pDelRead = new External.CURL_READ_DELEGATE(ReadDelegate); m_pDelProg = new External.CURL_PROGRESS_DELEGATE(ProgressDelegate); m_pDelDebug = new External.CURL_DEBUG_DELEGATE(DebugDelegate); m_pDelHeader = new External.CURL_HEADER_DELEGATE(HeaderDelegate); m_pDelSSLCtx = new External.CURL_SSL_CTX_DELEGATE(SSLCtxDelegate); m_pDelIoctl = new External.CURL_IOCTL_DELEGATE(IoctlDelegate); m_hThis = GCHandle.Alloc(this); m_ptrThis = (IntPtr)m_hThis; External.curl_shim_install_delegates(m_pCURL, m_ptrThis, m_pDelWrite, m_pDelRead, m_pDelProg, m_pDelDebug, m_pDelHeader, m_pDelSSLCtx, m_pDelIoctl); }
private void Dispose(bool disposing) { lock (this) { // if (disposing) cleanup managed resources // cleanup unmanaged resources if (m_pCURL != IntPtr.Zero) { External.curl_shim_cleanup_delegates(m_ptrThis); External.curl_easy_cleanup(m_pCURL); External.curl_shim_free_strings(m_pMyStrings); m_hThis.Free(); m_pCURL = IntPtr.Zero; } } }
/// <summary> /// Perform a transfer. /// </summary> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_perform()</c>. /// </returns> public CURLcode Perform() { EnsureHandle(); try { return((CURLcode)External.curl_easy_perform(m_pCURL)); } catch (Exception e) { // this.Cleanup(); //check error with , memory corupted here //this.SetOpt(CURLoption.CURLOPT_URL, _URL); // return (CURLcode)External.curl_easy_perform(m_pCURL); Exception myEx = new Exception("Unable to connect to curl", e); myEx.Data.Add("Code", 1); throw myEx; } }
void Dispose(bool disposing) { lock (this) { // if (disposing) // managed member cleanup // unmanaged cleanup if (m_pMulti != IntPtr.Zero) { External.curl_multi_cleanup(m_pMulti); m_pMulti = IntPtr.Zero; } if (m_fdSets != IntPtr.Zero) { External.curl_shim_free_fd_sets(m_fdSets); m_fdSets = IntPtr.Zero; } } }
/// <summary> /// Extract <c>string</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be one of the members that obtains a <c>string</c>. /// </param> /// <param name="strVal">Reference to an <c>string</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref string strVal) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; IntPtr ptr = IntPtr.Zero; if ((int)info < CURLINFO_STRING || (int)info >= CURLINFO_LONG) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_getinfo_ptr(m_pCURL, info, ref ptr); if (retCode == CURLcode.CURLE_OK) { strVal = Marshal.PtrToStringAnsi(ptr); } return(retCode); }
/// <summary> /// Extract <c>DateTime</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be <see cref="CURLINFO.CURLINFO_FILETIME"/>. /// </param> /// <param name="dt">Reference to a <c>DateTime</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref DateTime dt) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; if (info != CURLINFO.CURLINFO_FILETIME) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } int yy = 0, mm = 0, dd = 0, hh = 0, mn = 0, ss = 0; retCode = External.curl_easy_getinfo_time(m_pCURL, info, ref yy, ref mm, ref dd, ref hh, ref mn, ref ss); if (retCode == CURLcode.CURLE_OK) { dt = new DateTime(yy, mm, dd, hh, mn, ss); } return(retCode); }
/// <summary> /// Extract <c>int</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be one of the members that obtains an <c>int</c>. /// </param> /// <param name="intVal">Reference to an <c>int</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref int intVal) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; IntPtr ptr = IntPtr.Zero; // ensure it's an integral type if ((int)info < CURLINFO_LONG || (int)info >= CURLINFO_DOUBLE) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_getinfo(m_pCURL, info, ref ptr); if (retCode == CURLcode.CURLE_OK) { intVal = (int)ptr; } return(retCode); }
private Easy(Easy from) { m_pCURL = External.curl_easy_duphandle(from.m_pCURL); EnsureHandle(); m_pMyStrings = External.curl_shim_alloc_strings(); m_pfWrite = null; m_privateData = null; m_writeData = null; m_pfRead = null; m_readData = null; m_pfProgress = null; m_progressData = null; m_pfDebug = null; m_debugData = null; m_pfHeader = null; m_headerData = null; m_pfSSLContext = null; m_sslContextData = null; m_pfIoctl = null; m_ioctlData = null; InstallDelegates(); }
/// <summary> /// Extract information from a cURL handle. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration.</param> /// <param name="objInfo">Reference to an object into which the /// value specified by <c>info</c> is written.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref Object objInfo) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; IntPtr ptr = IntPtr.Zero; if ((int)info < CURLINFO_STRING) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } // trickery for filetime if (info == CURLINFO.CURLINFO_FILETIME) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } // private data if (info == CURLINFO.CURLINFO_PRIVATE) { objInfo = m_privateData; return(retCode); } // string case if ((int)info < CURLINFO_LONG) { retCode = External.curl_easy_getinfo_ptr(m_pCURL, info, ref ptr); if (retCode == CURLcode.CURLE_OK) { objInfo = (Object)Marshal.PtrToStringAnsi(ptr); } return(retCode); } // int or double: return problem return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); }
/// <summary> /// Extract <c>Slist</c> information from an <c>Easy</c> object. /// </summary> /// <param name="info">One of the values in the /// <see cref="CURLINFO"/> enumeration. In this case, it must /// specifically be one of the members that obtains an <c>Slist</c>. /// </param> /// <param name="slist">Reference to an <c>Slist</c> value.</param> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_getinfo()</c>. /// </returns> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public CURLcode GetInfo(CURLINFO info, ref Slist slist) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; IntPtr ptr = IntPtr.Zero, ptrs = IntPtr.Zero; if ((int)info < CURLINFO_SLIST) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_getinfo_ptr(m_pCURL, info, ref ptr); if (retCode != CURLcode.CURLE_OK) { return(retCode); } slist = new Slist(); while (ptr != IntPtr.Zero) { ptr = External.curl_shim_get_string_from_slist( ptr, ref ptrs); slist.Append(Marshal.PtrToStringAnsi(ptrs)); } return(retCode); }
/// <summary> /// Get a string description of an error code. /// </summary> /// <param name="code">Error code.</param> /// <returns>String description of the error code.</returns> public String StrError(CURLcode code) { return(Marshal.PtrToStringAnsi( External.curl_easy_strerror(code))); }
/// <summary> /// Perform a transfer. /// </summary> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> /// <returns>The <see cref="CURLcode"/> obtained from the internal /// call to <c>curl_easy_perform()</c>. /// </returns> public CURLcode Perform() { EnsureHandle(); return((CURLcode)External.curl_easy_perform(m_pCURL)); }
/// <summary> /// Set options for this object. See the <c>EasyGet</c> sample for /// basic usage. /// </summary> /// <param name="option">This should be a valid <see cref="CURLoption"/>.</param> /// <param name="parameter">This should be a parameter of a varying /// type based on the value of the <c>option</c> parameter.</param> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> /// <returns>A <see cref="CURLcode"/>, typically obtained from /// <c>cURL</c> internally, but sometimes a /// <see cref="CURLcode.CURLE_BAD_FUNCTION_ARGUMENT"/> /// will be returned if the type of value of <c>parameter</c> is invalid. /// </returns> public CURLcode SetOpt(CURLoption option, Object parameter) { EnsureHandle(); CURLcode retCode = CURLcode.CURLE_OK; // numeric cases if ((int)option < CURLOPTTYPE_OBJECTPOINT) { int i = 0; if (option == CURLoption.CURLOPT_DNS_USE_GLOBAL_CACHE || option == CURLoption.CURLOPT_SOURCE_PORT) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } else if (option == CURLoption.CURLOPT_TIMEVALUE) { // unboxing may throw class cast exception //DateTime d = (DateTime)parameter; DateTime startTime = Main.DateTimeBegin; TimeSpan currTime = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks); i = Convert.ToInt32(currTime.TotalSeconds); } else { i = Convert.ToInt32(parameter); } retCode = External.curl_easy_setopt_int(m_pCURL, option, i); } // object cases: the majority else if ((int)option < CURLOPTTYPE_FUNCTIONPOINT) { switch (option) { // various data items case CURLoption.CURLOPT_PRIVATE: m_privateData = parameter; break; case CURLoption.CURLOPT_WRITEDATA: m_writeData = parameter; break; case CURLoption.CURLOPT_READDATA: m_readData = parameter; break; case CURLoption.CURLOPT_PROGRESSDATA: m_progressData = parameter; break; case CURLoption.CURLOPT_DEBUGDATA: m_debugData = parameter; break; case CURLoption.CURLOPT_HEADERDATA: m_headerData = parameter; break; case CURLoption.CURLOPT_SSL_CTX_DATA: m_sslContextData = parameter; break; case CURLoption.CURLOPT_IOCTLDATA: m_ioctlData = parameter; break; // items that can't be set externally or // obsolete items case CURLoption.CURLOPT_ERRORBUFFER: case CURLoption.CURLOPT_STDERR: case CURLoption.CURLOPT_SOURCE_HOST: case CURLoption.CURLOPT_SOURCE_PATH: case CURLoption.CURLOPT_PASV_HOST: return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); // singular case for share case CURLoption.CURLOPT_SHARE: { Share share = parameter as Share; if (share == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_setopt_ptr(m_pCURL, option, share.GetHandle()); break; } // multipart HTTP post case CURLoption.CURLOPT_HTTPPOST: { MultiPartForm mf = parameter as MultiPartForm; if (mf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } retCode = External.curl_easy_setopt_ptr(m_pCURL, option, mf.GetHandle()); break; } // items curl wants as a curl_slist case CURLoption.CURLOPT_HTTPHEADER: case CURLoption.CURLOPT_PREQUOTE: case CURLoption.CURLOPT_QUOTE: case CURLoption.CURLOPT_POSTQUOTE: case CURLoption.CURLOPT_SOURCE_QUOTE: case CURLoption.CURLOPT_TELNETOPTIONS: case CURLoption.CURLOPT_HTTP200ALIASES: { Slist slist = parameter as Slist; if (slist == null) { retCode = External.curl_easy_setopt_ptr(m_pCURL, option, IntPtr.Zero); } else { retCode = External.curl_easy_setopt_ptr(m_pCURL, option, slist.GetHandle()); } break; } // string items default: { string s = parameter as string; if (s == null) { retCode = External.curl_easy_setopt_ptr(m_pCURL, option, IntPtr.Zero); } else { IntPtr pCurlStr = External.curl_shim_add_string( m_pMyStrings, s); if (pCurlStr != IntPtr.Zero) { retCode = External.curl_easy_setopt_ptr(m_pCURL, option, pCurlStr); } } break; } } } // FUNCTIONPOINT args, for delegates else if ((int)option < CURLOPTTYPE_OFF_T) { switch (option) { case CURLoption.CURLOPT_WRITEFUNCTION: { WriteFunction wf = parameter as WriteFunction; if (wf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfWrite = wf; break; } case CURLoption.CURLOPT_READFUNCTION: { ReadFunction rf = parameter as ReadFunction; if (rf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfRead = rf; break; } case CURLoption.CURLOPT_PROGRESSFUNCTION: { ProgressFunction pf = parameter as ProgressFunction; if (pf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfProgress = pf; break; } case CURLoption.CURLOPT_DEBUGFUNCTION: { DebugFunction pd = parameter as DebugFunction; if (pd == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfDebug = pd; break; } case CURLoption.CURLOPT_HEADERFUNCTION: { HeaderFunction hf = parameter as HeaderFunction; if (hf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfHeader = hf; break; } case CURLoption.CURLOPT_SSL_CTX_FUNCTION: { SSLContextFunction sf = parameter as SSLContextFunction; if (sf == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfSSLContext = sf; break; } case CURLoption.CURLOPT_IOCTLFUNCTION: { IoctlFunction iof = parameter as IoctlFunction; if (iof == null) { return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } m_pfIoctl = iof; break; } default: return(CURLcode.CURLE_BAD_FUNCTION_ARGUMENT); } } // otherwise, it's one of those 64-bit off_t guys! else { Int64 i = Convert.ToInt64(parameter); retCode = External.curl_easy_setopt_int64(m_pCURL, option, i); } return(retCode); }
/// <summary> /// Reset the internal cURL handle. /// </summary> /// <exception cref="System.NullReferenceException">This is thrown if /// the native <c>CURL*</c> handle wasn't created successfully.</exception> public void Reset() { EnsureHandle(); External.curl_easy_reset(m_pCURL); }