public static void SetString(IntPtr handle, string symbol, NSString value) { var indirect = dlsym(handle, symbol); if (indirect == IntPtr.Zero) { return; } var strHandle = value == null ? IntPtr.Zero : value.Handle; if (strHandle != IntPtr.Zero) { CFObject.CFRetain(strHandle); } Marshal.WriteIntPtr(indirect, strHandle); }
public static void SetArray(IntPtr handle, string symbol, NSArray?array) { var indirect = dlsym(handle, symbol); if (indirect == IntPtr.Zero) { return; } var arrayHandle = array.GetHandle(); if (arrayHandle != IntPtr.Zero) { CFObject.CFRetain(arrayHandle); } Marshal.WriteIntPtr(indirect, arrayHandle); }
public CFHTTPMessage GetResponseHeader() { var handle = GetProperty(_ResponseHeader); if (handle == IntPtr.Zero) { return(null); } if (CFType.GetTypeID(handle) != CFHTTPMessage.GetTypeID()) { CFObject.CFRelease(handle); throw new InvalidCastException(); } return(new CFHTTPMessage(handle)); }
static SecItem() { var handle = CFObject.dlopen(AppleTlsContext.SecurityLibrary, 0); if (handle == IntPtr.Zero) { return; } try { ReturnRef = CFObject.GetIntPtr(handle, "kSecReturnRef"); MatchSearchList = CFObject.GetIntPtr(handle, "kSecMatchSearchList"); } finally { CFObject.dlclose(handle); } }
static SecClass() { var handle = CFObject.dlopen(AppleTlsContext.SecurityLibrary, 0); if (handle == IntPtr.Zero) { return; } try { Identity = CFObject.GetIntPtr(handle, "kSecClassIdentity"); Certificate = CFObject.GetIntPtr(handle, "kSecClassCertificate"); } finally { CFObject.dlclose(handle); } }
public CMTimebase(CMTimebase masterTimebase) { if (masterTimebase == null) { throw new ArgumentNullException("masterTimebase"); } var error = CMTimebaseCreateWithMasterTimebase(IntPtr.Zero, masterTimebase.Handle, out handle); if (error != CMTimebaseError.None) { throw new ArgumentException(error.ToString()); } CFObject.CFRetain(Handle); }
static T[] ArrayFromHandle <T> (IntPtr handle, bool releaseAfterUse) where T : class, INativeObject { if (handle == IntPtr.Zero) { return(null); } try { return(NSArray.ArrayFromHandle <T> (handle)); } finally { if (releaseAfterUse) { CFObject.CFRetain(handle); } } }
static SecIdentity() { var handle = CFObject.dlopen(AppleTlsContext.SecurityLibrary, 0); if (handle == IntPtr.Zero) { return; } try { ImportExportPassphase = CFObject.GetStringConstant(handle, "kSecImportExportPassphrase"); ImportItemIdentity = CFObject.GetStringConstant(handle, "kSecImportItemIdentity"); } finally { CFObject.dlclose(handle); } }
static SecKeyChain() { var handle = CFObject.dlopen(AppleTlsContext.SecurityLibrary, 0); if (handle == IntPtr.Zero) { return; } try { MatchLimit = CFObject.GetIntPtr(handle, "kSecMatchLimit"); MatchLimitAll = CFObject.GetIntPtr(handle, "kSecMatchLimitAll"); MatchLimitOne = CFObject.GetIntPtr(handle, "kSecMatchLimitOne"); } finally { CFObject.dlclose(handle); } }
static InitConstants() { // ensure we can init. CFObject.CFRelease(ABAddressBook.ABAddressBookCreate()); ABGroupProperty.Init(); ABLabel.Init(); ABPersonAddressKey.Init(); ABPersonDateLabel.Init(); ABPersonInstantMessageKey.Init(); ABPersonInstantMessageService.Init(); ABPersonKindId.Init(); ABPersonPhoneLabel.Init(); ABPersonPropertyId.Init(); ABPersonRelatedNamesLabel.Init(); ABPersonUrlLabel.Init(); }
static public SecStatusCode ImportPkcs12(CFData data, CFDictionary options, out CFDictionary [] array) { if (options == null) { throw new ArgumentNullException("options"); } IntPtr handle; SecStatusCode code = SecPKCS12Import(data.Handle, options.Handle, out handle); array = CFArray.ArrayFromHandle <CFDictionary> (handle, h => new CFDictionary(h, false)); if (handle != IntPtr.Zero) { CFObject.CFRelease(handle); } return(code); }
public CFHTTPMessage?GetFinalRequest() { var handle = GetProperty(_FinalRequest); if (handle == IntPtr.Zero) { return(null); } if (CFType.GetTypeID(handle) != CFHTTPMessage.GetTypeID()) { CFObject.CFRelease(handle); throw new InvalidCastException(); } return(new CFHTTPMessage(handle, true)); }
public SecCertificate(X509Certificate certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } handle = certificate.Impl.GetNativeAppleCertificate(); if (handle != IntPtr.Zero) { CFObject.CFRetain(handle); return; } using (CFData cert = CFData.FromData(certificate.GetRawCertData())) { Initialize(cert); } }
public string GetLocalizedName(PMPrinter printer) { if (printer == null) { throw new ArgumentNullException(nameof(printer)); } IntPtr name; var code = PMPaperCreateLocalizedName(handle, printer.handle, out name); if (code != PMStatusCode.Ok) { return(null); } var str = CFString.FetchString(name); CFObject.CFRelease(name); return(str); }
public static string GetSubjectSummary(SafeSecCertificateHandle certificate) { if (certificate == null || certificate.IsInvalid) { throw new ArgumentNullException(nameof(certificate)); } var subjectSummaryHandle = IntPtr.Zero; try { subjectSummaryHandle = SecCertificateCopySubjectSummary(certificate.DangerousGetHandle()); return(CFString.AsString(subjectSummaryHandle)); } finally { if (subjectSummaryHandle != IntPtr.Zero) { CFObject.CFRelease(subjectSummaryHandle); } } }
public SecCertificate(X509Certificate2 certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } #if XAMARIN_APPLETLS handle = certificate.Impl.GetNativeAppleCertificate(); if (handle != IntPtr.Zero) { CFObject.CFRetain(handle); return; } #endif using (NSData cert = NSData.FromArray(certificate.RawData)) { Initialize(cert); } }
static public VTVideoEncoder [] GetEncoderList() { IntPtr array; if (VTCopyVideoEncoderList(IntPtr.Zero, out array) != VTStatus.Ok) { return(null); } var dicts = NSArray.ArrayFromHandle <NSDictionary> (array); var ret = new VTVideoEncoder [dicts.Length]; int i = 0; foreach (var dict in dicts) { ret [i++] = new VTVideoEncoder(dict); } CFObject.CFRelease(array); return(ret); }
public PMStatusCode TryPrintFromProvider(PMPrintSettings settings, PMPageFormat pageFormat, CGDataProvider provider, string mimeType = null) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (provider == null) { throw new ArgumentNullException(nameof(provider)); } IntPtr mime = CFString.LowLevelCreate(mimeType); var code = PMPrinterPrintWithProvider(handle, settings.handle, pageFormat == null ? IntPtr.Zero : pageFormat.handle, mime, provider.Handle); if (mime != IntPtr.Zero) { CFObject.CFRelease(mime); } return(code); }
public PMStatusCode TryPrintFile(PMPrintSettings settings, PMPageFormat pageFormat, NSUrl fileUrl, string mimeType = null) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (fileUrl == null) { throw new ArgumentNullException(nameof(fileUrl)); } IntPtr mime = CFString.LowLevelCreate(mimeType); var code = PMPrinterPrintWithFile(handle, settings.handle, pageFormat == null ? IntPtr.Zero : pageFormat.handle, mime, fileUrl.Handle); if (mime != IntPtr.Zero) { CFObject.CFRelease(mime); } return(code); }
public SecCertificate(X509Certificate certificate) { if (certificate == null) { throw new ArgumentNullException("certificate"); } #if NATIVE_APPLE_CERTIFICATE handle = certificate.Impl.GetNativeAppleCertificate(); if (handle != IntPtr.Zero) { CFObject.CFRetain(handle); return; } #endif using (NSData cert = NSData.FromArray(certificate.GetRawCertData())) { Initialize(cert); } }
public void RetrievePeripherals(CBUUID [] peripheralUuids) { if (peripheralUuids == null) { throw new ArgumentNullException("peripheralUuids"); } var ptrs = new IntPtr [peripheralUuids.Length]; for (int i = 0; i < peripheralUuids.Length; i++) { using (var s = new NSString(peripheralUuids[i].ToString(true))) ptrs [i] = CFUUID.CFUUIDCreateFromString(IntPtr.Zero, s.Handle); } using (var arr = NSArray.FromIntPtrs(ptrs)) RetrievePeripherals(arr); foreach (var p in ptrs) { CFObject.CFRelease(p); } }
public static PMStatusCode CreatePrinterList(out PMPrinter [] printerList) { IntPtr arr; var code = PMServerCreatePrinterList(IntPtr.Zero /* ServerLocal */, out arr); if (code != PMStatusCode.Ok) { printerList = null; return(code); } int c = (int)CFArray.GetCount(arr); printerList = new PMPrinter [c]; for (int i = 0; i < c; i++) { printerList [i] = new PMPrinter(CFArray.CFArrayGetValueAtIndex(arr, i), owns: false); } CFObject.CFRelease(arr); return(PMStatusCode.Ok); }
public INativeObject DequeueIfDataReady() { // // Our managed objects already take a reference on the object, // and by keeping the objects alive in the `queueObjects' // dictionary, we kept the reference alive. So we need to // release the newly acquired reference // var oHandle = CMBufferQueueDequeueIfDataReadyAndRetain(handle); if (oHandle == IntPtr.Zero) { return(null); } CFObject.CFRelease(oHandle); lock (queueObjects){ var managed = queueObjects [oHandle]; queueObjects.Remove(oHandle); return(managed); } }
public CTFontDescriptor[] GetMatchingFontDescriptors(Comparison <CTFontDescriptor> comparer) { GCHandle comparison = GCHandle.Alloc(comparer); try { var cfArrayRef = CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback( handle, new CTFontCollectionSortDescriptorsCallback(CompareDescriptors), GCHandle.ToIntPtr(comparison)); if (cfArrayRef == IntPtr.Zero) { return(new CTFontDescriptor [0]); } var matches = NSArray.ArrayFromHandle(cfArrayRef, fd => new CTFontDescriptor(cfArrayRef, false)); CFObject.CFRelease(cfArrayRef); return(matches); } finally { comparison.Free(); } }
public static InstrumentInfo [] GetInstrumentInfo(NSUrl url) { if (url == null) { throw new ArgumentNullException("url"); } InstrumentInfo [] result = null; IntPtr array = IntPtr.Zero; var error = CopyInstrumentInfoFromSoundBank(url.Handle, ref array); if (array != IntPtr.Zero) { var dicts = NSArray.ArrayFromHandle <NSDictionary> (array); result = new InstrumentInfo [dicts.Length]; for (int i = 0; i < dicts.Length; i++) { result [i] = new InstrumentInfo(dicts [i]); } CFObject.CFRelease(array); } return((error != 0) ? null : result); }
protected override void Dispose(bool disposing) { try { if (disposed) { return; } if (disposing) { disposed = true; if (serverIdentity != null) { serverIdentity.Dispose(); serverIdentity = null; } if (clientIdentity != null) { clientIdentity.Dispose(); clientIdentity = null; } if (remoteCertificate != null) { remoteCertificate.Dispose(); remoteCertificate = null; } } } finally { disposed = true; if (context != IntPtr.Zero) { CFObject.CFRelease(context); context = IntPtr.Zero; } base.Dispose(disposing); } }
/* invoked by marshallers */ protected internal VTFrameSilo(IntPtr handle) { this.handle = handle; CFObject.CFRetain(this.handle); }
static void Main(string[] args) { int arguments = args.Length; int i; // parse the command-line arguments for (i = 0; i < arguments; i++) { if ((0 == args[i].CompareTo("-i")) && i + 1 < arguments) inFile = args[++i]; if ((0 == args[i].CompareTo("-o")) && i + 1 < arguments) outFile = args[++i]; if ((0 == args[i].CompareTo("-codec")) && i + 1 < arguments) codec = args[++i]; if ((0 == args[i].CompareTo("-promptForSettings")) && i + 1 <= arguments) promptForSettings = true; if ((0 == args[i].CompareTo("-saveSettings")) && i + 1 <= arguments) { saveSettings = true; saveSettingsFile = args[++i]; } if ((0 == args[i].CompareTo("-loadSettings")) && i + 1 <= arguments) { loadSettings = true; loadSettingsFile = args[++i]; } } // check for command usage errors if (null == inFile || null == outFile || ((promptForSettings == false) && (null == codec)) || ((saveSettings == true) && (promptForSettings == false))) { PrintUsage(); return; } // create a new Form - the QTControl must be hosted on a Form or Window frm = new Form1(); try { // retrieve the instance of the QTControl object from the Form qtc = frm.QTControl; // specify that any errors generated will raise an exception qtc.ErrorHandling = (int) QTErrorHandlingOptionsEnum.qtErrorHandlingRaiseException; // use a QTEvent handler to display export progress information qtc.QTEvent += new AxQTOControlLib._IQTControlEvents_QTEventEventHandler(OnQTEvent); // get the source movie for the export operation qtc.URL = inFile; Console.WriteLine("Input file : " + inFile); Console.WriteLine("Output file : " + outFile); if (qtc.Movie != null) { // get the QuickTime object from the QTControl QTOLibrary.QTQuickTime qt = qtc.QuickTime; if (qt != null) { // must first add an exporter to the collection if (qt.Exporters.Count == 0) qt.Exporters.Add(); // retrieve the QTExporter object from the collection QTExporter qtexp = qt.Exporters[1]; if (qtexp != null) { qtexp.SetDataSource(qtc.Movie); // export our movie to specified format // (can be overriden by load settings) qtexp.TypeName = codec; // dont show the progress dialog qtexp.ShowProgressDialog = false; // specify destination file for the export operation qtexp.DestinationFileName = outFile; // optionally load exporter settings from a file if one is specified if (loadSettings) { // first check if settings file actually exists if (File.Exists(loadSettingsFile)) { StreamReader reader = new StreamReader(loadSettingsFile); CFObject settingsObject = new CFObject(); string xml = reader.ReadToEnd(); // read settings file as an XML string settingsObject.XML = xml; // load XML settings string into a CFObject qtexp.Settings = settingsObject; // set the XML onto the exporter reader.Close(); Console.WriteLine("Settings loaded from: " + loadSettingsFile); } } // we'll show the settings dialog if the user asks for it if (promptForSettings) { // show the exporter settings dialog qtexp.ShowSettingsDialog(); // Optionally save the exporter settings to a file if (saveSettings) { StreamWriter writer = new StreamWriter(saveSettingsFile, false); writer.Write(qtexp.Settings.XML); // write the settings as XML writer.Close(); Console.WriteLine("Settings saved to: " + saveSettingsFile); } } // we want export progress events qtexp.EventListeners.Add(QTEventClassesEnum.qtEventClassProgress, QTEventIDsEnum.qtEventExportProgress, 0, 0); Console.WriteLine("Export started..."); exportProgress = 0; // do the export! qtexp.BeginExport(); Console.WriteLine("\nExport done."); } } } } catch(COMException ex) { QTUtils qtu = new QTUtils(); Console.WriteLine("Error occurred: " + ex.ErrorCode.ToString("x") + " " + qtu.QTErrorFromErrorCode(ex.ErrorCode).ToString()); } qtc.URL = ""; frm.Dispose(); }
internal ABGroup(IntPtr handle, ABAddressBook addressbook) : base(CFObject.CFRetain(handle), addressbook) { }
/* invoked by marshallers */ protected internal VTMultiPassStorage(IntPtr handle) { this.handle = handle; CFObject.CFRetain(this.handle); }
public static bool Equals(SafeSecCertificateHandle first, SafeSecCertificateHandle second) { /* * This is a little bit expensive, but unfortunately there is no better API to compare two * SecCertificateRef's for equality. */ if (first == null || first.IsInvalid) { throw new ArgumentNullException(nameof(first)); } if (second == null || second.IsInvalid) { throw new ArgumentNullException(nameof(second)); } if (first.DangerousGetHandle() == second.DangerousGetHandle()) { return(true); } var firstDataPtr = SecCertificateCopyData(first.DangerousGetHandle()); var secondDataPtr = SecCertificateCopyData(first.DangerousGetHandle()); try { if (firstDataPtr == IntPtr.Zero || secondDataPtr == IntPtr.Zero) { throw new ArgumentException("Not a valid certificate."); } if (firstDataPtr == secondDataPtr) { return(true); } var firstLength = (int)CFData.CFDataGetLength(firstDataPtr); var secondLength = (int)CFData.CFDataGetLength(secondDataPtr); if (firstLength != secondLength) { return(false); } var firstBytePtr = CFData.CFDataGetBytePtr(firstDataPtr); var secondBytePtr = CFData.CFDataGetBytePtr(secondDataPtr); if (firstBytePtr == secondBytePtr) { return(true); } var firstBuffer = new byte[firstLength]; var secondBuffer = new byte[secondLength]; Marshal.Copy(firstBytePtr, firstBuffer, 0, firstBuffer.Length); Marshal.Copy(secondBytePtr, secondBuffer, 0, secondBuffer.Length); for (int i = 0; i < firstBuffer.Length; i++) { if (firstBuffer[i] != secondBuffer[i]) { return(false); } } return(true); } finally { if (firstDataPtr != null) { CFObject.CFRelease(firstDataPtr); } if (secondDataPtr != null) { CFObject.CFRelease(secondDataPtr); } } }