void writePropertyListToFile (CFDataRef data) {
    CFStringRef errorString;

    CFPropertyListRef propertyList = CFPropertyListCreateFromXMLData (NULL, data, kCFPropertyListMutableContainersAndLeaves, &errorString);

    if (errorString == NULL) {
        CFStringRef urlString = CFStringCreateWithCString (NULL, kFilename, CFStringGetSystemEncoding ());

        CFURLRef fileURL = CFURLCreateWithFileSystemPath (NULL, urlString, kCFURLPOSIXPathStyle, FALSE);

        CFWriteStreamRef stream = CFWriteStreamCreateWithFile (NULL, fileURL);

        Boolean isOpen = CFWriteStreamOpen (stream);

        show (CFSTR ("Property list (as written to file):\n%@"), propertyList);
  
        CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListXMLFormat_v1_0, NULL);

        CFWriteStreamClose (stream);
    }
    else {
        CFShow (errorString);
        CFRelease (errorString);
    }

    CFRelease (propertyList);
}
Пример #2
0
extern CFDataRef GPDuplexClient_Send(GPDuplexClientRef client, SInt32 type, CFDataRef data, Boolean expectsReturn) {
	CFMessagePortRef serverPort;
	if (client != NULL)
		serverPort = client->serverPort;
	else {
		serverPort = CFMessagePortCreateRemote(NULL, CFSTR("hk.kennytm.GriP.server"));
		if (serverPort == NULL) {
			CFShow(CFSTR("GPDuplexClient_Send(): Cannot create server port. Is GriP running?"));
			return NULL;
		}
	}
	
	if (expectsReturn) {
		CFDataRef retData = NULL;
		SInt32 errorCode = CFMessagePortSendRequest(serverPort, type, data, 4, 1, kCFRunLoopDefaultMode, &retData);
		if (client == NULL)
			CFRelease(serverPort);
		if (errorCode != kCFMessagePortSuccess) {
			CFLog(4, CFSTR("GPDuplexClient_Send(): Cannot send data %@ of type %d to server. Returning NULL. Error code = %d"), data, type, errorCode);
			if (retData != NULL) {
				CFRelease(retData);
				retData = NULL;
			}
		}
		return retData;
	} else {
		SInt32 errorCode = CFMessagePortSendRequest(serverPort, type, data, 4, 0, NULL, NULL);
		if (client == NULL)
			CFRelease(serverPort);
		if (errorCode != kCFMessagePortSuccess) {
			CFLog(4, CFSTR("GPDuplexClient_Send(): Cannot send data %@ of type %d to server. Error code = %d"), data, type, errorCode);
		}
		return NULL;
	}
}
Пример #3
0
static CFArrayRef
wireless_scan_ssid(wireless_t wref, CFStringRef ssid)
{
    CFArrayRef			bssid_list = NULL;
    Apple80211Err		error;
    CFDictionaryRef	 	scan_args;
    CFArrayRef 			scan_result = NULL;
	
	EAPLOG(LOG_ERR, "######## DEBUG ####### - FAIL - wireless_scan_ssid");
	
    scan_args = make_scan_args(ssid, 1);
    error = Apple80211Scan((Apple80211Ref)wref, &scan_result, scan_args);
    CFRelease(scan_args);
    if (error != kA11NoErr) {
		EAPLOG(LOG_ERR, "Apple80211Scan failed, %d\n", error);
		goto failed;
    }
    bssid_list = copy_bssid_list_from_scan(scan_result, ssid);
    if (bssid_list == NULL) {
		EAPLOG(LOG_ERR, "No scan results\n");
    }
    else {
		CFShow(bssid_list);
    }
    fflush(stdout);
    fflush(stderr);
	
failed:
    my_CFRelease(&scan_result);
    return (bssid_list);
	
}
Пример #4
0
static void TestDuplicateAndDeleteSet(void)
	// A test of the set duplication and deleting routines.
{
	OSStatus err;
	CFStringRef currentSetID;
	CFStringRef newSetID;
	
	currentSetID = NULL;
	newSetID = NULL;
	err = MoreSCCopyCurrentSet(&currentSetID);
	if (err == noErr) {
		err = MoreSCDuplicateSet(currentSetID, CFSTR("Frog"), &newSetID);
	}
	if (err == noErr) {
		if (!gRunQuiet) {
			fprintf(stderr, "New set ID is ");
			CFShow(newSetID);
		}
		
		err = MoreSCDeleteSet(newSetID);
	}
	
	CFQRelease(currentSetID);
	CFQRelease(newSetID);

	PrintTestResult(err, NULL);
}
Пример #5
0
/*
    JSRunEvaluate
*/
JSObjectRef JSRunEvaluate(JSRunRef ref)
{
    JSObjectRef result = 0;
    JSRun* ptr = (JSRun*)ref;
    if (ptr)
    {
        Completion completion = ptr->Evaluate();
        if (completion.isValueCompletion())
        {
            result = (JSObjectRef)KJSValueToJSObject(completion.value(), ptr->GetInterpreter()->globalExec());
        }

        if (completion.complType() == Throw)
        {
            JSFlags flags = ptr->Flags();
            if (flags & kJSFlagDebug)
            {
                CFTypeRef error = JSObjectCopyCFValue(result);
                if (error)
                {
                    CFShow(error);
                    CFRelease(error);
                }
            }
        }
    }
    return result;
}
CFDictionaryRef GTMSMJobCopyDictionary(CFStringRef jobLabel) {
  CFDictionaryRef dict = NULL;
  CFErrorRef error = NULL;
  launch_data_t resp = GTMPerformOnLabel(LAUNCH_KEY_GETJOB,
                                         jobLabel,
                                         &error);
  if (resp) {
    launch_data_type_t ldata_Type = launch_data_get_type(resp);
    if (ldata_Type == LAUNCH_DATA_DICTIONARY) {
      dict = GTMCFTypeCreateFromLaunchData(resp, true, &error);
    } else {
      error = GTMCFLaunchCreateUnlocalizedError(EINVAL,
                                                CFSTR("Unknown launchd type %d"),
                                                ldata_Type);
    }
    launch_data_free(resp);
  }
  if (error) {
#ifdef DEBUG
    CFShow(error);
#endif //  DEBUG
    CFRelease(error);
  }
  return dict;
}
Пример #7
0
MODULE_SCOPE void
TkMacOSXDebugFlashRegion(
    Drawable d,
    HIShapeRef rgn)
{
    TkMacOSXInitNamedDebugSymbol(HIToolbox, int, QDDebugFlashRegion,
	    CGrafPtr port, RgnHandle region);
    CFShow(rgn);
    if (d && rgn && QDDebugFlashRegion && !HIShapeIsEmpty(rgn)) {
	CGrafPtr port = TkMacOSXGetDrawablePort(d);

	if (port) {
	    static RgnHandle qdRgn = NULL;

	    if (!qdRgn) {
		qdRgn = NewRgn();
	    }
	    ChkErr(HIShapeGetAsQDRgn, rgn, qdRgn);

	    /*
	     * Carbon-internal region flashing SPI (c.f. Technote 2124)
	     */

	    QDDebugFlashRegion(port, qdRgn);
	    SetEmptyRgn(qdRgn);
	}
    }
}
Пример #8
0
static void	_ShowCF (FILE* file, CFStringRef str)
{
	if (CFGetTypeID(str) != CFStringGetTypeID()) {
		CFShow(str);
		return;
	}

	UInt32 len = CFStringGetLength(str);
	char* chars = (char*)CA_malloc (len * 2); // give us plenty of room for unichar chars
	if (CFStringGetCString (str, chars, len * 2, kCFStringEncodingUTF8))
		fprintf (file, "%s", chars);
	else
		CFShow (str);

	free (chars);
}
Пример #9
0
int
main (int argc, const char *argv[])
{
    CFShow(CFSTR("Hello, World!\n"));

    return EXIT_SUCCESS;
}
Пример #10
0
static void
dumpSetProperties(CFMutableDictionaryRef set)
{
    CFPrintf(CFSTR("\n%@\n"), CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetUUIDKey)));
    CFPrintf(CFSTR("\t\"%@\" type = %@ /dev/%@\n"),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetNameKey)),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDLevelNameKey)),
	     CFDictionaryGetValue(set, CFSTR("BSD Name")));
    CFPrintf(CFSTR("\tstatus = %@, sequence = %@\n"),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDStatusKey)),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDSequenceNumberKey)));
    CFPrintf(CFSTR("\tchunk count = %@, chunk size = %@\n"),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDChunkCountKey)),
	     CFDictionaryGetValue(set, CFSTR(kAppleRAIDChunkSizeKey)));

    CFStringRef level = CFDictionaryGetValue(set, CFSTR(kAppleRAIDLevelNameKey));
    if (CFStringCompare(level, CFSTR("mirror"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
	CFPrintf(CFSTR("\tcontent hint = %@, auto = %@, quick = %@, timeout = %@\n"),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetContentHintKey)),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetAutoRebuildKey)),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetQuickRebuildKey)),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetTimeoutKey)));
    } else if (CFStringCompare(level, CFSTR("LVG"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
	CFPrintf(CFSTR("\tcontent hint = %@, lv count = %@, free space %@\n"),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetContentHintKey)),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDLVGVolumeCountKey)),
		 CFDictionaryGetValue(set, CFSTR(kAppleRAIDLVGFreeSpaceKey)));
    } else {
	CFPrintf(CFSTR("\tcontent hint = %@\n"), CFDictionaryGetValue(set, CFSTR(kAppleRAIDSetContentHintKey)));
    }

    if (verbose) CFShow(set);
}
Пример #11
0
/* @overload write_plist(hash, path)
 *
 * Writes the serialized contents of a property list to the specified path.
 *
 * @note This does not yet support all possible types that can exist in a valid property list.
 *
 * @note This currently only assumes to be given an Xcode project document.
 *       This means that it only accepts dictionaries, arrays, and strings in
 *       the document.
 *
 * @param [Hash] hash     The property list to serialize.
 * @param [String] path   The path to the property list file.
 * @return [true, false]  Wether or not saving was successful.
 */
static VALUE
write_plist(VALUE self, VALUE hash, VALUE path) {
  VALUE h = rb_check_convert_type(hash, T_HASH, "Hash", "to_hash");
  if (NIL_P(h)) {
    rb_raise(rb_eTypeError, "%s can't be coerced to Hash", rb_obj_classname(hash));
  }

  CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL,
                                                          0,
                                                          &kCFTypeDictionaryKeyCallBacks,
                                                          &kCFTypeDictionaryValueCallBacks);

  rb_hash_foreach(h, dictionary_set, (st_data_t)dict);

  CFURLRef fileURL = str_to_url(path);
  CFWriteStreamRef stream = CFWriteStreamCreateWithFile(NULL, fileURL);
  CFRelease(fileURL);

  CFIndex success = 0;
  if (CFWriteStreamOpen(stream)) {
    CFStringRef errorString;
    success = CFPropertyListWriteToStream(dict, stream, kCFPropertyListXMLFormat_v1_0, &errorString);
    if (!success) {
      CFShow(errorString);
    }
  } else {
    printf("Unable to open stream!\n");
  }

  CFRelease(dict);
  return success ? Qtrue : Qfalse;
}
Пример #12
0
	static void DebugModemScriptSearch(void)
		// Used for debugging the modem script code.
	{
		OSStatus 	err;
		CFArrayRef	cclArray;
		CFIndex		indexOfDefaultCCL;
		
		cclArray = NULL;
		err = MoreSCCreateCCLArray(&cclArray, &indexOfDefaultCCL);
		if (err == noErr) {
			CFIndex i;
			CFIndex c;
			
			c = CFArrayGetCount(cclArray);
			fprintf(stderr, "CCL Count = %ld\n", c);
			for (i = 0; i < c; i++) {
				fprintf(stderr, "%3ld %c ", i, i == indexOfDefaultCCL ? '*' : ' ');
				CFShow(CFArrayGetValueAtIndex(cclArray, i));
			}
		}
		
		CFQRelease(cclArray);
		
	    if (err == noErr) {
    	    fprintf(stderr, "Success!\n");
	    } else {
    	    fprintf(stderr, "*** Failed with error %ld!\n", err);
	    }
	}
Пример #13
0
int main(int argc, const char * argv[])
{

    // insert code here...
    CFShow(CFSTR("Hello, World!\n"));
    return 0;
}
Пример #14
0
// ---------------------------------
// Load the element strings from the given resource (XML) file into a CFPropertyListRef
static CFPropertyListRef xml_load(const CFStringRef pResourceName,const CFStringRef pResourceExtension)
{
	CFPropertyListRef tCFPropertyListRef = NULL;
	CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), pResourceName, pResourceExtension, NULL);

	if (NULL != resFileCFURLRef)
	{
		CFDataRef resCFDataRef;

		if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, resFileCFURLRef, &resCFDataRef, nil, nil, nil))
		{
			if (NULL != resCFDataRef)
			{
				CFStringRef errorString;

				tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resCFDataRef, kCFPropertyListImmutable, &errorString);
				if (NULL == tCFPropertyListRef)
					CFShow(errorString);
				CFRelease(resCFDataRef);
			}
		}
		CFRelease(resFileCFURLRef);
	}
	return tCFPropertyListRef;
}
CFDictionaryRef GTMSMCopyAllJobDictionaries(void) {
  CFDictionaryRef dict = NULL;
  launch_data_t msg = launch_data_new_string(LAUNCH_KEY_GETJOBS);
  launch_data_t resp = launch_msg(msg);
  launch_data_free(msg);
  CFErrorRef error = NULL;

  if (resp) {
    launch_data_type_t ldata_Type = launch_data_get_type(resp);
    if (ldata_Type == LAUNCH_DATA_DICTIONARY) {
      dict = GTMCFTypeCreateFromLaunchData(resp, true, &error);
    } else {
      error = GTMCFLaunchCreateUnlocalizedError(EINVAL,
                                                CFSTR("Unknown launchd type %d"),
                                                ldata_Type);
    }
    launch_data_free(resp);
  } else {
    error
      = GTMCFLaunchCreateUnlocalizedError(errno, CFSTR(""));
  }
  if (error) {
#ifdef DEBUG
    CFShow(error);
#endif //  DEBUG
    CFRelease(error);
  }
  return dict;
}
Пример #16
0
/* Get the value for the given key. We don't allow NULL ad a value, so
 * returning NULL means failure (not present).
 */
CFPropertyListRef Preferences::get_value(CFStringRef key) const
{
    CFPropertyListRef prefval = NULL;

    if (!this->is_loaded()) {
	return NULL;
    }

    if (this->m_plist) {
	prefval = CFDictionaryGetValue((CFDictionaryRef)this->m_plist, key);
    } else if (this->m_scpref) {
	prefval = SCPreferencesGetValue(this->m_scpref, key);
    }

    /* Dump the raw keys for debugging. Useful for figuring out whether our
     * type conversion has gone awry.
     */
    if (Options::Debug) {
	DEBUGMSG("%s value for key %s:\n",
		this->m_pspec.c_str(), cfstring_convert(key).c_str());
	CFShow(prefval);
    }

    return prefval;
}
sint32 GetACLAuthorizationTagFromString(CFStringRef aclStr)
{
	if (NULL == aclStr)
	{
#ifndef NDEBUG
		CFShow(CFSTR("GetACLAuthorizationTagFromString aclStr is NULL"));
#endif
		return 0;
	}

	static CFDictionaryRef gACLMapping = NULL;

	if (NULL == gACLMapping)
	{
		gACLMapping = CreateStringToNumDictionary();
	}

	sint32 result = 0;
	CFNumberRef valueResult = (CFNumberRef)CFDictionaryGetValue(gACLMapping, aclStr);
	if (NULL != valueResult)
	{
		if (!CFNumberGetValue(valueResult, kCFNumberSInt32Type, &result))
		{
			return 0;
		}

	}
	else
	{
		return 0;
	}

	return result;

}
Пример #18
0
OSErr AcroPluginCFragInitFunction( const CFragInitBlock *	initBlock )
{
	OSErr err = __initialize(initBlock);
	
	if (err == noErr)
	{	
#if TARGET_API_MAC_CARBON
		if (initBlock->fragLocator.where == kDataForkCFragLocator)
		{
			// Mac OS X 10.1 and earlier has a bug where packaged CFM libs are still passed 
			// kDataForkCFragLocator instead of kCFBundleCFragLocator. Apple claims this will
			// fixed in Jaguar.
			FSSpec spec = *initBlock->fragLocator.u.onDisk.fileSpec;
			
			// See if parent folder is named "MacOS"
			FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec);
			if (IdenticalString(spec.name, "\pMacOS", NULL) == 0)
			{
				// See if parent folder is named "Contents"
				FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec);
				if (IdenticalString(spec.name, "\pContents", NULL) == 0)
				{
					// Get Bundle Ref
					FSRef fsRef;
					FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec);
					if (noErr == FSpMakeFSRef(&spec, &fsRef))
					{
						CFURLRef cfURL = CFURLCreateFromFSRef(NULL, &fsRef);
						if (cfURL)
						{
							gPluginBundle = CFBundleCreate(NULL, cfURL);
#if DEBUG
							CFShow(cfURL);
							CFShow(gPluginBundle);
#endif
							
							if (gPluginBundle)
								gResFile = CFBundleOpenBundleResourceMap(gPluginBundle);
							
							CFRelease(cfURL);
						}
					}
				}
			}
		}
Пример #19
0
void testValidPemKey(void)
{
	CFStringRef pemKey = CFStringCreateWithCString(kCFAllocatorDefault, pemEncodedKey, kCFStringEncodingUTF8);
	APSetKey(pemKey);
	CFRelease(pemKey);
	
	CFDataRef exampleLicenseFileData = CFDataCreate(NULL,
													(const UInt8 *)exampleLicenseFileContents,
													(CFIndex)strlen(exampleLicenseFileContents));
	Boolean licenseIsValid = APVerifyLicenseData(exampleLicenseFileData);
	CFRelease(exampleLicenseFileData);
	
	if (licenseIsValid) {
		CFShow(CFSTR("Test OK: Valid file recognised using PEM encoded key"));
	} else {
		CFShow(CFSTR("Test FAILED: Valid file not recognised using PEM encoded key"));
	}
}
Пример #20
0
void __security_debug(const char *scope, const char *function,
    const char *file, int line, const char *format, ...)
{
#if !defined(NDEBUG)
	pthread_once(&__security_debug_once, __security_debug_init);

	CFStringRef scopeName = NULL;
	/* Scope NULL is always enabled. */
	if (scope) {
		/* Check if the scope is enabled. */
		if (scopeSet) {
			scopeName = copyScopeName(scope, strlen(scope));
			if (negate == CFSetContainsValue(scopeSet, scopeName)) {
				CFRelease(scopeName);
				return;
			}
		} else if (!negate) {
			return;
		}
	}

	CFStringRef formatStr = CFStringCreateWithCString(kCFAllocatorDefault,
		format, kCFStringEncodingUTF8);
	va_list args;
	va_start(args, format);
	CFStringRef message = CFStringCreateWithFormatAndArguments(
		kCFAllocatorDefault, NULL, formatStr, args);
	va_end(args);
	time_t now = time(NULL);
	char *date = ctime(&now);
	date[19] = '\0';
	CFStringRef logStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
		CFSTR("%s %-*s %s %@\n"), date + 4, MAX_SCOPE_LENGTH - 1,
        scope ? scope : "", function, message);
	CFShow(logStr);
    char logMsg[4096];
    if (CFStringGetCString(logStr, logMsg, sizeof(logMsg), kCFStringEncodingUTF8)) {
#if 0
        asl_log(NULL, NULL, ASL_LEVEL_INFO, logMsg);
#else
        aslmsg msg = asl_new(ASL_TYPE_MSG);
        if (scope) {
            asl_set(msg, ASL_KEY_FACILITY, scope);
        }
        asl_set(msg, ASL_KEY_LEVEL, ASL_STRING_INFO);
        asl_set(msg, ASL_KEY_MSG, logMsg);
        asl_send(NULL, msg);
        asl_free(msg);
#endif
    }
	CFRelease(logStr);
	CFRelease(message);
	CFRelease(formatStr);
	if (scopeName)
		CFRelease(scopeName);
#endif
}
Пример #21
0
static void TestServiceEnumerate(void)
	// A test of the service enumeration routines.
{
	OSStatus  err;
	ItemCount serviceCount;
	ItemCount serviceIndex;
	CFArrayRef localServiceIDs;
	CFArrayRef resolvedServiceIDs;

	localServiceIDs = NULL;
	resolvedServiceIDs = NULL;
	
	err = MoreSCCopyServiceIDs(NULL, &localServiceIDs, &resolvedServiceIDs);
	if (err == noErr) {
		serviceCount = CFArrayGetCount(localServiceIDs);
		for (serviceIndex = 0; serviceIndex < serviceCount; serviceIndex++) {
			CFStringRef userVisible;
			Boolean     active;
			
			userVisible = NULL;
			err = MoreSCCopyUserVisibleNameOfService(NULL, (CFStringRef) CFArrayGetValueAtIndex(localServiceIDs, serviceIndex), &userVisible);
			if (err == noErr) {
				err = MoreSCIsServiceActive(NULL, (CFStringRef) CFArrayGetValueAtIndex(localServiceIDs, serviceIndex), &active);
			}
			if (err == noErr && !gRunQuiet) {
				fprintf(stderr, "#%ld %c ", serviceIndex, (active) ? ' ' : 'X');
				CFShow(userVisible);
				CFShow(CFArrayGetValueAtIndex(localServiceIDs, serviceIndex));
				CFShow(CFArrayGetValueAtIndex(resolvedServiceIDs, serviceIndex));
			}
			
			CFQRelease(userVisible);
			
			if (err != noErr) {
				break;
			}
		}
	}

	CFQRelease(localServiceIDs);
	CFQRelease(resolvedServiceIDs);

	PrintTestResult(err, NULL);
}
Пример #22
0
// Given an iterator across a set of Ethernet interfaces, return the MAC address of the last one.
// If no interfaces are found the MAC address is set to an empty string.
// In this sample the iterator should contain just the primary interface.
static kern_return_t GetMACAddress(io_iterator_t intfIterator, UInt8 *MACAddress, UInt8 bufferSize)
{
    io_object_t    intfService;
    io_object_t    controllerService;
    kern_return_t  kernResult = KERN_FAILURE;

    // Make sure the caller provided enough buffer space. Protect against buffer overflow problems.
  if (bufferSize < kIOEthernetAddressSize) {
    return kernResult;
  }

  // Initialize the returned address
    bzero(MACAddress, bufferSize);

    // IOIteratorNext retains the returned object, so release it when we're done with it.
    while (intfService = IOIteratorNext(intfIterator))
    {
        CFTypeRef  MACAddressAsCFData;

        // IONetworkControllers can't be found directly by the IOServiceGetMatchingServices call,
        // since they are hardware nubs and do not participate in driver matching. In other words,
        // registerService() is never called on them. So we've found the IONetworkInterface and will
        // get its parent controller by asking for it specifically.

        // IORegistryEntryGetParentEntry retains the returned object, so release it when we're done with it.
        kernResult = IORegistryEntryGetParentEntry(intfService,
                           kIOServicePlane,
                           &controllerService);

        if (KERN_SUCCESS != kernResult) {
            printf("IORegistryEntryGetParentEntry returned 0x%08x\n", kernResult);
        }
        else {
            // Retrieve the MAC address property from the I/O Registry in the form of a CFData
            MACAddressAsCFData = IORegistryEntryCreateCFProperty(controllerService,
                                 CFSTR(kIOMACAddress),
                                 kCFAllocatorDefault,
                                 0);
            if (MACAddressAsCFData) {
                CFShow(MACAddressAsCFData); // for display purposes only; output goes to stderr

                // Get the raw bytes of the MAC address from the CFData
                CFDataGetBytes((CFDataRef)MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), MACAddress);
                CFRelease(MACAddressAsCFData);
            }

            // Done with the parent Ethernet controller object so we release it.
            (void) IOObjectRelease(controllerService);
        }

        // Done with the Ethernet interface object so we release it.
        (void) IOObjectRelease(intfService);
    }

    return kernResult;
}
Пример #23
0
Zirk2PortClient::Zirk2PortClient() : Zirk2Port(), mRemoteMessagePort(NULL), mData(NULL)
{
	CFMessagePortSetName(mMessagePort, CFSTR("Zirk2PortClient"));
	mRemoteMessagePort = CFMessagePortCreateRemote(NULL, CFSTR("Zirk2PortServer"));
	if (!mRemoteMessagePort) {
		CFShow(CFSTR("Could not create remote message port"));
		mRemoteMessagePort = NULL;
	}
	mData = CFDataCreateMutable(NULL, 0);
}
int main(int argc, const char** argv) {
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  CFErrorRef error = NULL;
  CFDictionaryRef dict = GTMSMJobCheckIn(&error);
  if (!dict) {
    CFShow(error);
  }
#endif //  if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  return 0;
}
Пример #25
0
bool check_date_constructors ()
{
   CFAbsoluteTime      absTime;
   CFDateRef           aCFDate;
   
   CFShow(CFSTR("Checking date constructors:"));

   absTime = CFAbsoluteTimeGetCurrent();
   aCFDate = CFDateCreate(kCFAllocatorDefault, absTime);
   
   CFShow(CFSTR("Absolute Time is"));
   printf("The current absolute time is %f\n", absTime);
   CFShow(CFSTR("Equivalent CFDate object is"));
   CFShow(aCFDate);
   
   printf("\n");
   
   return true;
}
Пример #26
0
static void TestEnumerateEntities(void)
	// A test of the MoreSCCopyEntities routine.
{
	OSStatus 	err;
	CFArrayRef  localServiceIDs;
	ItemCount	entityCount;
	ItemCount	entityIndex;
	CFArrayRef  protocols;
	CFArrayRef  values;
	
	// Use NULL for the set ID to indicate that we're operating on
	// the current set.
	//
	// Can't use NULL for a service ID, so we have to come up with 
	// a valid service ID first.  We do this by choosing the first 
	// service ID.
	
	localServiceIDs = NULL;
	protocols = NULL;
	values = NULL;
	
	err = MoreSCCopyServiceIDs(NULL, &localServiceIDs, NULL);
	if (err == noErr) {
		assert(CFArrayGetCount(localServiceIDs) > 0);
		err = MoreSCCopyEntities(NULL, (CFStringRef) CFArrayGetValueAtIndex(localServiceIDs, 0), &protocols, &values);
	}

	if (err == noErr && !gRunQuiet) {
		entityCount = CFArrayGetCount(protocols);
		for (entityIndex = 0; entityIndex < entityCount; entityIndex++) {
			fprintf(stderr, "#%ld ", entityIndex);
			CFShow(CFArrayGetValueAtIndex(protocols, entityIndex));
			CFShow(CFArrayGetValueAtIndex(values,    entityIndex));
		}
	}

	CFQRelease(localServiceIDs);
	CFQRelease(protocols);
	CFQRelease(values);
	
	PrintTestResult(err, NULL);
}
Пример #27
0
static void cli_print_info_dict (const void *key,
                                 const void *value,
                                 void *context)
{
  CFStringRef entry = CFStringCreateWithFormat(NULL, NULL,
    CFSTR("%@:\n  %@"), key, value);
  if (entry) {
    CFShow(entry);
    CFRelease(entry);
  }
}
Пример #28
0
/* -------------------------------------------------------------------------- */
void cutils_test_appsupport_path_Create()
{
    LOG0("---- cutils_test_appsupport_path_Create --------------------------");
    
    CFStringRef appSuppLocal = appsupport_path_Create(kLocalDomain);
    CFShow(appSuppLocal);
    //LOG_CF("app support folder (local)", appSuppLocal);
    assert(CFStringCompare(appSuppLocal, 
                           CFSTR("/Library/Application Support"), 0) == 0);
    
}
Пример #29
0
static void TestPortScanner(void)
	// A simple test of the port scanner code.  This doesn't do a 
	// lot of automated testing, but you can look at the results 
	// and visually check them.
{
	OSStatus   	err;
	CFArrayRef 	portArray;
	CFIndex 	portCount;
	CFIndex 	portIndex;
	long		order;
	CFNumberRef	supportsHold;
	
	portArray = NULL;
	
	err = MoreSCCreatePortArray(&portArray);
	if (err == noErr) {
		portCount = CFArrayGetCount(portArray);
		for (portIndex = 0; portIndex < portCount; portIndex++) {
			CFDictionaryRef thisPort;
			
			thisPort = (CFDictionaryRef) CFArrayGetValueAtIndex(portArray, portIndex);
			if (!gRunQuiet) {
				fprintf(stderr, "Port %ld\n", portIndex);
				fprintf(stderr, "  device   = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropNetInterfaceDeviceName));
				fprintf(stderr, "  name     = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropUserDefinedName));
				fprintf(stderr, "  hardware = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropNetInterfaceHardware));
				fprintf(stderr, "  variant  = ");
				CFShow(CFDictionaryGetValue(thisPort, kMoreSCPropNetInterfaceHardwareVariant));
				fprintf(stderr, "  type     = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropNetInterfaceType));
				fprintf(stderr, "  subtype  = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropNetInterfaceSubType));
				fprintf(stderr, "  MAC      = ");
				CFShow(CFDictionaryGetValue(thisPort, kSCPropMACAddress));
				(void) CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(thisPort, CFSTR("SortOrder")), kCFNumberLongType, &order);
				
				supportsHold = (CFNumberRef) CFDictionaryGetValue(thisPort, kSCPropNetInterfaceSupportsModemOnHold);
				if (supportsHold != NULL) {
					long hold;
					
					CFNumberGetValue(supportsHold, kCFNumberLongType, &hold);
					fprintf(stderr, "  hold     = %ld\n", hold);
				}

				fprintf(stderr, "  sort     = %ld\n", order);
			}
		}
	}
	
	CFQRelease(portArray);

	PrintTestResult(err, NULL);
}
Пример #30
0
void mount_developer_image(AMDeviceRef device) {
    CFStringRef ds_path = copy_device_support_path(device);
    CFStringRef image_path = copy_developer_disk_image_path(device);
    CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path);
    CFRelease(ds_path);

    if (verbose) {
        printf("Device support path: ");
        fflush(stdout);
        CFShow(ds_path);
        printf("Developer disk image: ");
        fflush(stdout);
        CFShow(image_path);
    }

    FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb");
    void *sig_buf = malloc(128);
    assert(fread(sig_buf, 1, 128, sig) == 128);
    fclose(sig);
    CFDataRef sig_data = CFDataCreateWithBytesNoCopy(NULL, sig_buf, 128, NULL);
    CFRelease(sig_path);

    CFTypeRef keys[] = { CFSTR("ImageSignature"), CFSTR("ImageType") };
    CFTypeRef values[] = { sig_data, CFSTR("Developer") };
    CFDictionaryRef options = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFRelease(sig_data);

    int result = AMDeviceMountImage(device, image_path, options, &mount_callback, 0);
    if (result == 0) {
        printf("[ 95%%] Developer disk image mounted successfully\n");
    } else if (result == 0xe8000076 /* already mounted */) {
        printf("[ 95%%] Developer disk image already mounted\n");
    } else {
        printf("[ !! ] Unable to mount developer disk image. (%x)\n", result);
        exit(1);
    }

    CFRelease(image_path);
    CFRelease(options);
}