public static CFUrl Create (string absolute) { if (string.IsNullOrEmpty (absolute)) return null; CFString str = CFString.Create (absolute); IntPtr handle = CFURLCreateWithString (IntPtr.Zero, str.Handle, IntPtr.Zero); str.Dispose (); if (handle == IntPtr.Zero) return null; return new CFUrl (handle, true); }
public static CFProxy[] ExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, Uri targetURL) { CFUrl url = CFUrl.Create(targetURL.AbsoluteUri); if (url == null) { return(null); } CFProxy[] proxies = null; var runLoop = CFRunLoop.CurrentRunLoop; // Callback that will be called after executing the configuration script CFProxyAutoConfigurationResultCallback cb = delegate(IntPtr client, IntPtr proxyList, IntPtr error) { if (proxyList != IntPtr.Zero) { var array = new CFArray(proxyList, false); proxies = new CFProxy [array.Count]; for (int i = 0; i < proxies.Length; i++) { CFDictionary dict = new CFDictionary(array[i], false); proxies[i] = new CFProxy(dict); } array.Dispose(); } runLoop.Stop(); }; var clientContext = new CFStreamClientContext(); var loopSource = CFNetworkExecuteProxyAutoConfigurationURL(proxyAutoConfigURL, url.Handle, cb, ref clientContext); // Create a private mode var mode = CFString.Create("Mono.MacProxy"); runLoop.AddSource(loopSource, mode); runLoop.RunInMode(mode, double.MaxValue, false); runLoop.RemoveSource(loopSource, mode); return(proxies); }
public bool Unschedule (CFRunLoop runLoop, string mode) { if (runLoop == null) throw new ArgumentNullException ("runLoop"); if (mode == null) throw new ArgumentNullException ("mode"); using (var cfstring = new CFString (mode)){ return SCNetworkReachabilityUnscheduleFromRunLoop (handle, runLoop.Handle, cfstring.Handle) != 0; } }
public bool Schedule (CFRunLoop runLoop, string mode) { if (runLoop == null) throw new ArgumentNullException ("runLoop"); // new CFString already does a null check using (var cfstring = new CFString (mode)){ return SCNetworkReachabilityScheduleWithRunLoop (handle, runLoop.Handle, cfstring.Handle); } }
public int RunInMode(CFString mode, double seconds, bool returnAfterSourceHandled) { return(CFRunLoopRunInMode(mode.Handle, seconds, returnAfterSourceHandled)); }
public void RemoveSource(IntPtr source, CFString mode) { CFRunLoopRemoveSource(Handle, source, mode.Handle); }
public void AddSource(IntPtr source, CFString mode) { CFRunLoopAddSource(Handle, source, mode.Handle); }
public static void CreatePairWithSocketToHost(string host, int port, out CFReadStream readStream, out CFWriteStream writeStream) { using (var str = new CFString (host)) { IntPtr read, write; CFStreamCreatePairWithSocketToHost ( IntPtr.Zero, str.Handle, port, out read, out write); // API not annotated (yet?) but it's safe to bet it match CFStreamCreatePairWithSocketToCFHost readStream = read == IntPtr.Zero ? null : new CFReadStream (read); writeStream = write == IntPtr.Zero ? null : new CFWriteStream (write); } }
public override string ToString() { if (copyDescription != IntPtr.Zero) { var ptr = CFReadStreamRef_InvokeCopyDescription (copyDescription, Info); if (ptr != IntPtr.Zero) { // Copy* -> so we must not retain again using (var s = new CFString (ptr, true)) return s.ToString (); } } return base.ToString (); }
public static CFHost Create (string name) { // CFString will throw the ANE using (var ptr = new CFString (name)) return new CFHost (CFHostCreateWithName (IntPtr.Zero, ptr.Handle)); }
public string GetMethod () { var ptr = CFHTTPAuthenticationCopyMethod (Handle); if (ptr == IntPtr.Zero) return null; using (var method = new CFString (ptr)) return method; }
public void ApplyCredentialDictionary (CFHTTPAuthentication auth, NetworkCredential credential) { if (auth == null) throw new ArgumentNullException ("auth"); if (credential == null) throw new ArgumentNullException ("credential"); var keys = new NSString [3]; var values = new CFString [3]; keys [0] = _AuthenticationUsername; keys [1] = _AuthenticationPassword; keys [2] = _AuthenticationAccountDomain; values [0] = (CFString)credential.UserName; values [1] = (CFString)credential.Password; values [2] = credential.Domain != null ? (CFString)credential.Domain : null; var dict = CFDictionary.FromObjectsAndKeys (values, keys); try { CFStreamError error; var ok = CFHTTPMessageApplyCredentialDictionary ( Handle, auth.Handle, dict.Handle, out error); if (ok) return; throw GetException ((CFStreamErrorHTTPAuthentication) error.code); } finally { dict.Dispose (); values [0].Dispose (); values [1].Dispose (); if (values [2] != null) values [2].Dispose (); } }
public void ApplyCredentials (CFHTTPAuthentication auth, NetworkCredential credential) { if (auth == null) throw new ArgumentNullException ("auth"); if (credential == null) throw new ArgumentNullException ("credential"); if (auth.RequiresAccountDomain) { ApplyCredentialDictionary (auth, credential); return; } var username = new CFString (credential.UserName); var password = new CFString (credential.Password); try { CFStreamError error; var ok = CFHTTPMessageApplyCredentials ( Handle, auth.Handle, username.Handle, password.Handle, out error); if (!ok) throw GetException ((CFStreamErrorHTTPAuthentication) error.code); } finally { username.Dispose (); password.Dispose (); } }
public int RunInMode (CFString mode, double seconds, bool returnAfterSourceHandled) { return CFRunLoopRunInMode (mode.Handle, seconds, returnAfterSourceHandled); }
public void RemoveSource (IntPtr source, CFString mode) { CFRunLoopRemoveSource (Handle, source, mode.Handle); }
public void AddSource (IntPtr source, CFString mode) { CFRunLoopAddSource (Handle, source, mode.Handle); }