bool getFrameworkPath(char *respath) { char tmpPath[MAXPATHLEN]; CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return false; CFURLRef frameworksURL = CFBundleCopyPrivateFrameworksURL(appBundle); if (!frameworksURL) return false; CFURLRef absFrameworksURL = CFURLCopyAbsoluteURL(frameworksURL); CFRelease(frameworksURL); if (!absFrameworksURL) return false; CFURLGetFileSystemRepresentation(absFrameworksURL, true, (UInt8*) tmpPath, sizeof(tmpPath)); printf("abs fw url = %s\n", tmpPath); CFRelease(absFrameworksURL); snprintf(respath, MAXPATHLEN, "%s/XUL.framework/Versions/Current", tmpPath); return true; }
void do_debug(AMDeviceRef device) { CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false); CFURLRef url = CFURLCopyAbsoluteURL(relative_url); AMDeviceConnect(device); assert(AMDeviceIsPaired(device)); assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceStartSession(device) == 0); PRINT("------ Debug phase ------\n"); mount_developer_image(device); // put debugserver on the device start_remote_debug_server(device); // start debugserver write_gdb_prep_cmds(device, url); // dump the necessary gdb commands into a file CFRelease(path); CFRelease(relative_url); CFRelease(url); PRINT("[100%%] Connecting to remote debug server\n"); PRINT("-------------------------\n"); signal(SIGHUP, gdb_ready_handler); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system(GDB_SHELL); // launch gdb kill(parent, SIGHUP); // "No. I am your father." _exit(EXIT_SUCCESS); } }
static wxString MacGetPathToBinary(const wxString& program) { #if !wxCHECK_VERSION(2,9,0) #define wxCFStringRef wxMacCFStringHolder #endif wxCFStringRef programstr(program); CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef urlRel = CFBundleCopyAuxiliaryExecutableURL(bundle, programstr); if ( urlRel == NULL ) { wxLogTrace(_T("poedit.execute"), _T("failed to locate '%s'"), program.c_str()); return program; } CFURLRef urlAbs = CFURLCopyAbsoluteURL(urlRel); wxCFStringRef path(CFURLCopyFileSystemPath(urlAbs, kCFURLPOSIXPathStyle)); CFRelease(urlRel); CFRelease(urlAbs); wxString full = path.AsString(wxLocale::GetSystemEncoding()); wxLogTrace(_T("poedit.execute"), _T("using '%s'"), full.c_str()); return wxString::Format(_T("\"%s\""), full.c_str()); }
JSValue *UserObjectImp::toPrimitive(ExecState *exec, JSType preferredType) const { JSValue *result = jsUndefined(); JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec); CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0; if (cfValue) { CFTypeID cfType = CFGetTypeID(cfValue); // toPrimitive if (cfValue == GetCFNull()) { result = jsNull(); } else if (cfType == CFBooleanGetTypeID()) { if (cfValue == kCFBooleanTrue) { result = jsBoolean(true); } else { result = jsBoolean(false); } } else if (cfType == CFStringGetTypeID()) { result = jsString(CFStringToUString((CFStringRef)cfValue)); } else if (cfType == CFNumberGetTypeID()) { double d = 0.0; CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d); result = jsNumber(d); } else if (cfType == CFURLGetTypeID()) { CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue); if (absURL) { result = jsString(CFStringToUString(CFURLGetString(absURL))); ReleaseCFType(absURL); } } ReleaseCFType(cfValue); } if (jsObjPtr) jsObjPtr->Release(); return result; }
bool getExePath(char *respath) { CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return false; CFURLRef url = CFBundleCopyExecutableURL(appBundle); if (!url) return false; CFURLRef absurl = nullptr; // CFURLRef url2 = url; CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(NULL, url); CFRelease(url); absurl = CFURLCopyAbsoluteURL(url2); CFRelease(url2); char tbuffer[MAXPATHLEN]; CFURLGetFileSystemRepresentation(absurl, true, (UInt8*) tbuffer, sizeof(tbuffer)); printf("abs exec url = %s\n", tbuffer); CFRelease(absurl); snprintf(respath, MAXPATHLEN, "%s/XUL", tbuffer); return true; }
static CFDictionaryRef _CFUserNotificationModifiedDictionary(CFAllocatorRef allocator, CFDictionaryRef dictionary, SInt32 token, SInt32 timeout, CFStringRef source) { CFMutableDictionaryRef md = CFDictionaryCreateMutable(allocator, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFNumberRef tokenNumber = CFNumberCreate(allocator, kCFNumberSInt32Type, &token); CFNumberRef timeoutNumber = CFNumberCreate(allocator, kCFNumberSInt32Type, &timeout); CFURLRef url = NULL; CFStringRef path = NULL; if (dictionary) CFDictionaryApplyFunction(dictionary, _CFUserNotificationAddToDictionary, md); if (source) CFDictionaryAddValue(md, kCFUserNotificationAlertSourceKey, source); if (tokenNumber) { CFDictionaryAddValue(md, kCFUserNotificationTokenKey, tokenNumber); CFRelease(tokenNumber); } if (timeoutNumber) { CFDictionaryAddValue(md, kCFUserNotificationTimeoutKey, timeoutNumber); CFRelease(timeoutNumber); } url = CFDictionaryGetValue(md, kCFUserNotificationIconURLKey); if (url && CFGetTypeID((CFTypeRef)url) == CFURLGetTypeID()) { url = CFURLCopyAbsoluteURL(url); CFDictionaryRemoveValue(md, kCFUserNotificationIconURLKey); path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFDictionaryAddValue(md, kCFUserNotificationIconPathKey, path); CFRelease(url); CFRelease(path); } url = CFDictionaryGetValue(md, kCFUserNotificationSoundURLKey); if (url && CFGetTypeID((CFTypeRef)url) == CFURLGetTypeID()) { url = CFURLCopyAbsoluteURL(url); CFDictionaryRemoveValue(md, kCFUserNotificationSoundURLKey); path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFDictionaryAddValue(md, kCFUserNotificationSoundPathKey, path); CFRelease(url); CFRelease(path); } url = CFDictionaryGetValue(md, kCFUserNotificationLocalizationURLKey); if (url && CFGetTypeID((CFTypeRef)url) == CFURLGetTypeID()) { url = CFURLCopyAbsoluteURL(url); CFDictionaryRemoveValue(md, kCFUserNotificationLocalizationURLKey); path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFDictionaryAddValue(md, kCFUserNotificationLocalizationPathKey, path); CFRelease(url); CFRelease(path); } return md; }
static wxString BundleRelativeURLToPath(CFURLRef relativeURL) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL); wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL")); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle); CFRelease(absoluteURL); return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); }
static wxString BundleRelativeURLToPath(CFURLRef relativeURL) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL); wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL")); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle); CFRelease(absoluteURL); return wxCFStringRef::AsStringWithNormalizationFormC(cfStrPath); }
CFURLRef get_absolute_file_url(const char *file_path) { CFStringRef path = CFStringCreateWithCString(NULL, file_path, kCFStringEncodingUTF8); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false); CFURLRef url = CFURLCopyAbsoluteURL(relative_url); CFRelease(path); CFRelease(relative_url); return url; }
// returns e.g. "/Applications/appname.app/Contents/Resources" if application is bundled, // or the directory of the binary, e.g. "/usr/local/bin/appname", if it is *not* bundled. static wxString GetResourcesDir() { CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLRef absoluteURL = CFURLCopyAbsoluteURL(resourcesURL); // relative -> absolute CFRelease(resourcesURL); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(3, 0, 0) return wxCFStringRef(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #else return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #endif }
void ResourceError::platformLazyInit() { if (m_dataIsUpToDate) return; if (!m_platformError) return; CFStringRef domain = CFErrorGetDomain(m_platformError.get()); if (domain == kCFErrorDomainMach || domain == kCFErrorDomainCocoa) m_domain ="NSCustomErrorDomain"; else if (domain == kCFErrorDomainCFNetwork) m_domain = "CFURLErrorDomain"; else if (domain == kCFErrorDomainPOSIX) m_domain = "NSPOSIXErrorDomain"; else if (domain == kCFErrorDomainOSStatus) m_domain = "NSOSStatusErrorDomain"; else if (domain == kCFErrorDomainWinSock) m_domain = "kCFErrorDomainWinSock"; else m_domain = domain; m_errorCode = CFErrorGetCode(m_platformError.get()); RetainPtr<CFDictionaryRef> userInfo = adoptCF(CFErrorCopyUserInfo(m_platformError.get())); if (userInfo.get()) { CFStringRef failingURLString = (CFStringRef) CFDictionaryGetValue(userInfo.get(), failingURLStringKey); if (failingURLString) m_failingURL = String(failingURLString); else { CFURLRef failingURL = (CFURLRef) CFDictionaryGetValue(userInfo.get(), failingURLKey); if (failingURL) { RetainPtr<CFURLRef> absoluteURLRef = adoptCF(CFURLCopyAbsoluteURL(failingURL)); if (absoluteURLRef.get()) { // FIXME: CFURLGetString returns a normalized URL which is different from what is actually used by CFNetwork. // We should use CFURLGetBytes instead. failingURLString = CFURLGetString(absoluteURLRef.get()); m_failingURL = String(failingURLString); } } } m_localizedDescription = (CFStringRef) CFDictionaryGetValue(userInfo.get(), kCFErrorLocalizedDescriptionKey); #if PLATFORM(WIN) m_certificate = wkGetSSLPeerCertificateData(userInfo.get()); #endif } m_dataIsUpToDate = true; }
static void CFURLRefToLLString(CFURLRef urlRef, std::string &llString, bool releaseWhenDone) { if (urlRef) { CFURLRef absoluteURLRef = CFURLCopyAbsoluteURL(urlRef); if (absoluteURLRef) { CFStringRef stringRef = CFURLCopyFileSystemPath(absoluteURLRef, kCFURLPOSIXPathStyle); CFStringRefToLLString(stringRef, llString, true); CFRelease(absoluteURLRef); } if (releaseWhenDone) CFRelease(urlRef); } }
static stringT GetBundleResourceDir() { stringT retval; CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { CFURLRef helpDir = CFBundleCopyResourcesDirectoryURL(mainBundle); if (helpDir) { CFURLRef helpDirAbsolute = CFURLCopyAbsoluteURL(helpDir); if (helpDirAbsolute) { retval = GetStringTFromURLRef(helpDirAbsolute); CFRelease(helpDirAbsolute); } CFRelease(helpDir); } } return retval; }
std::string getAppBundlePath() { static std::string cachedPathToBundle; if(cachedPathToBundle.size()) return cachedPathToBundle; #if defined(NL_OS_MAC) // get the bundle CFBundleRef bundle = CFBundleGetMainBundle(); if(bundle) { // get the url to the bundles root CFURLRef url = CFBundleCopyBundleURL(bundle); if(url) { // get the file system path CFStringRef str; str = CFURLCopyFileSystemPath( CFURLCopyAbsoluteURL(url), kCFURLPOSIXPathStyle); CFRelease(url); if(str) { cachedPathToBundle = CFStringGetCStringPtr( str, CFStringGetSmallestEncoding(str)); CFRelease(str); } else nlerror("CFStringGetCStringPtr"); } else nlerror("CFBundleCopyBundleURL"); } else nlerror("CFBundleGetMainBundle"); #elif defined(NL_OS_WINDOWS) char buffer[MAX_PATH+1]; if (GetModuleFileNameA(NULL, buffer, MAX_PATH)) cachedPathToBundle = NLMISC::CPath::standardizePath(NLMISC::CFile::getPath(buffer), false); #endif // defined(NL_OS_MAC) return cachedPathToBundle; }
void ResourceError::platformLazyInit() { if (m_dataIsUpToDate) return; if (!m_platformError) return; CFStringRef domain = CFErrorGetDomain(m_platformError.get()); if (domain == kCFErrorDomainMach || domain == kCFErrorDomainCocoa) m_domain ="NSCustomErrorDomain"; else if (domain == kCFErrorDomainCFNetwork) m_domain = "CFURLErrorDomain"; else if (domain == kCFErrorDomainPOSIX) m_domain = "NSPOSIXErrorDomain"; else if (domain == kCFErrorDomainOSStatus) m_domain = "NSOSStatusErrorDomain"; else if (domain == kCFErrorDomainWinSock) m_domain = "kCFErrorDomainWinSock"; m_errorCode = CFErrorGetCode(m_platformError.get()); RetainPtr<CFDictionaryRef> userInfo(AdoptCF, CFErrorCopyUserInfo(m_platformError.get())); if (userInfo.get()) { CFStringRef failingURLString = (CFStringRef) CFDictionaryGetValue(userInfo.get(), failingURLStringKey); if (failingURLString) m_failingURL = String(failingURLString); else { CFURLRef failingURL = (CFURLRef) CFDictionaryGetValue(userInfo.get(), failingURLKey); if (failingURL) { RetainPtr<CFURLRef> absoluteURLRef(AdoptCF, CFURLCopyAbsoluteURL(failingURL)); if (absoluteURLRef.get()) { failingURLString = CFURLGetString(absoluteURLRef.get()); m_failingURL = String(failingURLString); } } } m_localizedDescription = (CFStringRef) CFDictionaryGetValue(userInfo.get(), kCFErrorLocalizedDescriptionKey); #if PLATFORM(WIN) m_certificate = wkGetSSLPeerCertificateData(userInfo.get()); #endif } m_dataIsUpToDate = true; }
/******************************************************************************* * XXX: I'm really not sure this is completely reliable for getting a relative * XXX: path. *******************************************************************************/ CFStringRef copyKextInfoDictionaryPath( OSKextRef theKext, PathSpec pathSpec) { CFStringRef result = NULL; CFURLRef kextURL = NULL; // do not release CFURLRef kextAbsURL = NULL; // must release CFBundleRef kextBundle = NULL; // must release CFURLRef infoDictURL = NULL; // must release kextURL = OSKextGetURL(theKext); if (!kextURL) { OSKextLog(theKext, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Kext has no URL!"); goto finish; } kextAbsURL = CFURLCopyAbsoluteURL(kextURL); if (!kextAbsURL) { OSKextLogMemError(); goto finish; } kextBundle = CFBundleCreate(kCFAllocatorDefault, kextAbsURL); if (!kextBundle) { OSKextLogMemError(); goto finish; } infoDictURL = _CFBundleCopyInfoPlistURL(kextBundle); if (!infoDictURL) { // not able to determine error here, bundle might have no plist // (well, we should never have gotten here if that were the case) result = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); goto finish; } result = copyAdjustedPathForURL(theKext, infoDictURL, pathSpec); finish: SAFE_RELEASE(infoDictURL); SAFE_RELEASE(kextBundle); SAFE_RELEASE(kextAbsURL); return result; }
OSReturn KextManagerLoadKextWithURL( CFURLRef kextURL, CFArrayRef dependencyKextAndFolderURLs) { OSReturn result = kOSReturnError; CFMutableDictionaryRef requestDict = NULL; // must release CFURLRef absURL = NULL; // must release CFStringRef kextPath = NULL; // must release if (!kextURL) { result = kOSKextReturnInvalidArgument; goto finish; } requestDict = CFDictionaryCreateMutable(kCFAllocatorDefault, /* capacity */ 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!requestDict) { result = kOSKextReturnNoMemory; goto finish; } absURL = CFURLCopyAbsoluteURL(kextURL); if (!absURL) { result = kOSKextReturnNoMemory; goto finish; } kextPath = CFURLCopyFileSystemPath(absURL, kCFURLPOSIXPathStyle); if (!kextPath) { result = kOSKextReturnSerialization; goto finish; } CFDictionarySetValue(requestDict, kKextLoadPathKey, kextPath); result = __KextManagerSendLoadKextRequest(requestDict, dependencyKextAndFolderURLs); finish: SAFE_RELEASE(requestDict); SAFE_RELEASE(absURL); SAFE_RELEASE(kextPath); return result; }
RetainPtr<CFURLResponseRef> ResourceHandleCFURLConnectionDelegate::synthesizeRedirectResponseIfNecessary(CFURLRequestRef newRequest, CFURLResponseRef cfRedirectResponse) { if (cfRedirectResponse) return cfRedirectResponse; CFURLRef newURL = CFURLRequestGetURL(newRequest); RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(newURL)); // If the protocols of the new request and the current request match, this is not an HSTS redirect and we shouldn't synthesize a redirect response. const ResourceRequest& currentRequest = m_handle->currentRequest(); if (currentRequest.url().protocol() == String(newScheme.get())) return nullptr; RetainPtr<CFURLRef> currentURL = currentRequest.url().createCFURL(); RetainPtr<CFHTTPMessageRef> responseMessage = adoptCF(CFHTTPMessageCreateResponse(0, 302, 0, kCFHTTPVersion1_1)); RetainPtr<CFURLRef> newAbsoluteURL = adoptCF(CFURLCopyAbsoluteURL(newURL)); CFHTTPMessageSetHeaderFieldValue(responseMessage.get(), CFSTR("Location"), CFURLGetString(newAbsoluteURL.get())); CFHTTPMessageSetHeaderFieldValue(responseMessage.get(), CFSTR("Cache-Control"), CFSTR("no-store")); RetainPtr<CFURLResponseRef> newResponse = adoptCF(CFURLResponseCreateWithHTTPResponse(0, currentURL.get(), responseMessage.get(), kCFURLCacheStorageNotAllowed)); return newResponse; }
DAFileSystemRef DAFileSystemCreate( CFAllocatorRef allocator, CFURLRef path ) { DAFileSystemRef filesystem = NULL; CFDictionaryRef properties; /* * Obtain the file system properties. */ properties = CFBundleCopyInfoDictionaryInDirectory( path ); if ( properties ) { CFURLRef id; /* * Create the file system object's unique identifier. */ id = CFURLCopyAbsoluteURL( path ); if ( id ) { /* * Create the file system object. */ filesystem = __DAFileSystemCreate( allocator, id, properties ); CFRelease( id ); } CFRelease( properties ); } return filesystem; }
/* * SMB_Mount */ int32_t SMBNetFsMount(SMBHANDLE inConnection, CFURLRef url, CFStringRef mPoint, CFDictionaryRef mOptions, CFDictionaryRef *mInfo, void (*callout)(void *, void *), void *args) { int error = 0; struct smb_ctx *hContext = NULL; SMBServerContext(inConnection, (void **)&hContext); /* Now deal with the URL, need a better way of handling this in the future */ if (hContext->ct_url) { CFRelease(hContext->ct_url); } hContext->ct_url = CFURLCopyAbsoluteURL(url); if (hContext->ct_url) { error = ParseSMBURL(hContext); } else { error = ENOMEM; } if (error) { return error; } return smb_mount(hContext, mPoint, mOptions, mInfo, callout, args); }
/******************************************************************************* * XXX: I'm really not sure this is completely reliable for getting a relative * XXX: path. *******************************************************************************/ CFStringRef copyKextExecutablePath( OSKextRef theKext, PathSpec pathSpec) { CFStringRef result = NULL; CFURLRef kextURL = NULL; // do not release CFURLRef kextAbsURL = NULL; // must release CFURLRef executableURL = NULL; // must release kextURL = OSKextGetURL(theKext); if (!kextURL) { OSKextLog(theKext, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Kext has no URL!"); goto finish; } kextAbsURL = CFURLCopyAbsoluteURL(kextURL); if (!kextAbsURL) { OSKextLogMemError(); goto finish; } executableURL = _CFBundleCopyExecutableURLInDirectory(kextAbsURL); if (!executableURL) { // not able to determine error here, bundle might have no executable result = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); goto finish; } result = copyAdjustedPathForURL(theKext, executableURL, pathSpec); finish: SAFE_RELEASE(executableURL); SAFE_RELEASE(kextAbsURL); return result; }
UString UserObjectImp::toString(ExecState *exec) const { UString result; JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec); CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0; if (cfValue) { CFTypeID cfType = CFGetTypeID(cfValue); if (cfValue == GetCFNull()) { // } else if (cfType == CFBooleanGetTypeID()) { if (cfValue == kCFBooleanTrue) { result = "true"; } else { result = "false"; } } else if (cfType == CFStringGetTypeID()) { result = CFStringToUString((CFStringRef)cfValue); } else if (cfType == CFNumberGetTypeID()) { if (cfValue == kCFNumberNaN) { result = "Nan"; } else if (CFNumberCompare(kCFNumberPositiveInfinity, (CFNumberRef)cfValue, 0) == 0) { result = "Infinity"; } else if (CFNumberCompare(kCFNumberNegativeInfinity, (CFNumberRef)cfValue, 0) == 0) { result = "-Infinity"; } else { CFStringRef cfNumStr; double d = 0; CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d); if (CFNumberIsFloatType((CFNumberRef)cfValue)) { cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%f"), d); } else { cfNumStr = CFStringCreateWithFormat(0, 0, CFSTR("%.0f"), d); } result = CFStringToUString(cfNumStr); ReleaseCFType(cfNumStr); } } else if (cfType == CFArrayGetTypeID()) { // } else if (cfType == CFDictionaryGetTypeID()) { // } else if (cfType == CFSetGetTypeID()) { // } else if (cfType == CFURLGetTypeID()) { CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue); if (absURL) { CFStringRef cfStr = CFURLGetString(absURL); if (cfStr) { result = CFStringToUString(cfStr); } ReleaseCFType(absURL); } } } ReleaseCFType(cfValue); if (jsObjPtr) jsObjPtr->Release(); return result; }
bool UserObjectImp::toBoolean(ExecState *exec) const { bool result = false; JSUserObject* jsObjPtr = KJSValueToJSObject(toObject(exec), exec); CFTypeRef cfValue = jsObjPtr ? jsObjPtr->CopyCFValue() : 0; if (cfValue) { CFTypeID cfType = CFGetTypeID(cfValue); // toPrimitive if (cfValue == GetCFNull()) { // } else if (cfType == CFBooleanGetTypeID()) { if (cfValue == kCFBooleanTrue) { result = true; } } else if (cfType == CFStringGetTypeID()) { if (CFStringGetLength((CFStringRef)cfValue)) { result = true; } } else if (cfType == CFNumberGetTypeID()) { if (cfValue != kCFNumberNaN) { double d; if (CFNumberGetValue((CFNumberRef)cfValue, kCFNumberDoubleType, &d)) { if (d != 0) { result = true; } } } } else if (cfType == CFArrayGetTypeID()) { if (CFArrayGetCount((CFArrayRef)cfValue)) { result = true; } } else if (cfType == CFDictionaryGetTypeID()) { if (CFDictionaryGetCount((CFDictionaryRef)cfValue)) { result = true; } } else if (cfType == CFSetGetTypeID()) { if (CFSetGetCount((CFSetRef)cfValue)) { result = true; } } else if (cfType == CFURLGetTypeID()) { CFURLRef absURL = CFURLCopyAbsoluteURL((CFURLRef)cfValue); if (absURL) { CFStringRef cfStr = CFURLGetString(absURL); if (cfStr && CFStringGetLength(cfStr)) { result = true; } ReleaseCFType(absURL); } } } if (jsObjPtr) jsObjPtr->Release(); ReleaseCFType(cfValue); return result; }
void StartDebuggingAndDetach(char *udid, char *app_path) { SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid); if (device) { CFStringRef bundleId = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *)app_path, strlen(app_path), kCFStringEncodingUTF8, false); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, bundleId, kCFURLPOSIXPathStyle, false); CFURLRef disk_app_url = CFURLCopyAbsoluteURL(relative_url); CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url); SDMMD_AMDebugConnectionRef debug = SDMMD_AMDebugConnectionCreateForDevice(device); SDMMD_AMDebugConnectionStart(debug); uintptr_t socket = SDMMD_AMDServiceConnectionGetSocket(debug->connection); CFSocketContext context = { 0, (void*)socket, NULL, NULL, NULL }; CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &socket_callback, &context); int yes = 1; setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); struct sockaddr_un address; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, SDM_LLDB_SOCKET); address.sun_len = SUN_LEN(&address); CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address)); unlink(SDM_LLDB_SOCKET); CFSocketSetAddress(fdvendor, address_data); CFRelease(address_data); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); SDMMD_AMDeviceRef device = SDMMD_AMDServiceConnectionGetDevice(debug->connection); CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS); CFRange range = { 0, CFStringGetLength(cmds) }; CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier); CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{DEVICE_PATH}"), device_app_path, range, 0); range.length = CFStringGetLength(cmds); CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{APP_PATH}"), disk_app_path, range, 0); range.length = CFStringGetLength(cmds); CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url); CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle); CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path); range.length = CFStringGetLength(dcp_noprivate); CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0); range.length = CFStringGetLength(cmds); CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0); range.length = CFStringGetLength(cmds); CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url); CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle); CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0); CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0); FILE *out = fopen(PREP_CMDS_PATH, "w"); fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out); fclose(out); CFSafeRelease(cmds); CFSafeRelease(bundle_identifier); CFSafeRelease(device_app_url); CFSafeRelease(device_app_path); CFSafeRelease(disk_app_path); CFSafeRelease(device_container_url); CFSafeRelease(device_container_path); CFSafeRelease(dcp_noprivate); CFSafeRelease(disk_container_url); CFSafeRelease(disk_container_path); CFSafeRelease(cmds_data); signal(SIGHUP, exit); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system("xcrun -sdk iphoneos lldb /tmp/sdmmd-lldb-prep"); kill(parent, SIGHUP); _exit(0); } CFRunLoopRun(); } }
nsresult GRE_GetGREPathWithProperties(const GREVersionRange *versions, PRUint32 versionsLength, const GREProperty *properties, PRUint32 propertiesLength, char *aBuffer, PRUint32 aBufLen) { #ifdef TARGET_XPCOM_ABI // append the ABI to the properties to match only binary // compatible GREs static const GREProperty kExtraProperty = { "abi", TARGET_XPCOM_ABI }; nsAutoArrayPtr<GREProperty> allProperties(new GREProperty[propertiesLength + 1]); if (!allProperties) return NS_ERROR_OUT_OF_MEMORY; for (PRUint32 i=0; i<propertiesLength; i++) { allProperties[i].property = properties[i].property; allProperties[i].value = properties[i].value; } allProperties[propertiesLength].property = kExtraProperty.property; allProperties[propertiesLength].value = kExtraProperty.value; PRUint32 allPropertiesLength = propertiesLength + 1; #else const GREProperty *allProperties = properties; PRUint32 allPropertiesLength = propertiesLength; #endif // if GRE_HOME is in the environment, use that GRE const char* env = getenv("GRE_HOME"); if (env && *env) { char p[MAXPATHLEN]; snprintf(p, sizeof(p), "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, env); p[sizeof(p) - 1] = '\0'; #if XP_UNIX if (realpath(p, aBuffer)) return NS_OK; #elif WINCE if (p[0] != '\\') { WCHAR dir[MAX_PATH]; WCHAR path[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, p, -1, path, MAX_PATH); _wfullpath(dir,path,MAX_PATH); WideCharToMultiByte(CP_ACP, 0, dir, -1, aBuffer, MAX_PATH, NULL, NULL); } else { strcpy(aBuffer, p); } return NS_OK; #elif XP_WIN if (_fullpath(aBuffer, p, aBufLen)) return NS_OK; #elif XP_OS2 // realpath on OS/2 returns a unix-ized path, so re-native-ize if (realpath(p, aBuffer)) { for (char* ptr = strchr(aBuffer, '/'); ptr; ptr = strchr(ptr, '/')) *ptr = '\\'; return NS_OK; } #elif XP_BEOS BPath path; status_t result; result = path.SetTo(p,0,true); if (result == B_OK) { sprintf(aBuffer, path.Path()); return NS_OK; } #else // hope for the best // xxxbsmedberg: other platforms should have a "make absolute" function #endif if (strlen(p) >= aBufLen) return NS_ERROR_FILE_NAME_TOO_LONG; strcpy(aBuffer, p); return NS_OK; } // the Gecko bits that sit next to the application or in the LD_LIBRARY_PATH env = getenv("USE_LOCAL_GRE"); if (env && *env) { *aBuffer = nsnull; return NS_OK; } #ifdef XP_MACOSX aBuffer[0] = '\0'; // Check the bundle first, for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib CFBundleRef appBundle = CFBundleGetMainBundle(); if (appBundle) { CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle); CFURLRef absfwurl = nsnull; if (fwurl) { absfwurl = CFURLCopyAbsoluteURL(fwurl); CFRelease(fwurl); } if (absfwurl) { CFURLRef xulurl = CFURLCreateCopyAppendingPathComponent(NULL, absfwurl, CFSTR(GRE_FRAMEWORK_NAME), PR_TRUE); if (xulurl) { CFURLRef xpcomurl = CFURLCreateCopyAppendingPathComponent(NULL, xulurl, CFSTR("libxpcom.dylib"), PR_FALSE); if (xpcomurl) { char tbuffer[MAXPATHLEN]; if (CFURLGetFileSystemRepresentation(xpcomurl, PR_TRUE, (UInt8*) tbuffer, sizeof(tbuffer)) && access(tbuffer, R_OK | X_OK) == 0) { if (!realpath(tbuffer, aBuffer)) { aBuffer[0] = '\0'; } } CFRelease(xpcomurl); } CFRelease(xulurl); } CFRelease(absfwurl); } } if (aBuffer[0]) return NS_OK; // Check ~/Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib const char *home = getenv("HOME"); if (home && *home && GRE_FindGREFramework(home, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } // Check /Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib if (GRE_FindGREFramework("", versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } #elif defined(XP_UNIX) env = getenv("MOZ_GRE_CONF"); if (env && GRE_GetPathFromConfigFile(env, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } env = getenv("HOME"); if (env && *env) { char buffer[MAXPATHLEN]; // Look in ~/.gre.config snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_NAME, env); if (GRE_GetPathFromConfigFile(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } // Look in ~/.gre.d/*.conf snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_USER_CONF_DIR, env); if (GRE_GetPathFromConfigDir(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } } // Look for a global /etc/gre.conf file if (GRE_GetPathFromConfigFile(GRE_CONF_PATH, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } // Look for a group of config files in /etc/gre.d/ if (GRE_GetPathFromConfigDir(GRE_CONF_DIR, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } #elif defined(XP_BEOS) env = getenv("MOZ_GRE_CONF"); if (env && GRE_GetPathFromConfigFile(env, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } char p[MAXPATHLEN]; if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, p, MAXPATHLEN)) { char buffer[MAXPATHLEN]; // Look in B_USER_SETTINGS_DIRECTORY/gre.config snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_NAME, p); if (GRE_GetPathFromConfigFile(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } // Look in B_USER_SETTINGS_DIRECTORY/gre.d/*.conf snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_DIR, p); if (GRE_GetPathFromConfigDir(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } } // Hope Zeta OS and Haiku OS multiuser versions will respect BeBook, // for BeOS R5 COMMON and USER are equal if (find_directory(B_COMMON_SETTINGS_DIRECTORY, 0, 0, p, MAXPATHLEN)) { char buffer[MAXPATHLEN]; // Look for a B_COMMON_SETTINGS_DIRECTORY/gre.conf file snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_PATH, p); if (GRE_GetPathFromConfigFile(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } // Look for a group of config files in B_COMMON_SETTINGS_DIRECTORY/gre.d/ snprintf(buffer, sizeof(buffer), "%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_DIR, p); if (GRE_GetPathFromConfigDir(buffer, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen)) { return NS_OK; } } #elif defined(XP_WIN) HKEY hRegKey = NULL; // A couple of key points here: // 1. Note the usage of the "Software\\mozilla.org\\GRE" subkey - this allows // us to have multiple versions of GREs on the same machine by having // subkeys such as 1.0, 1.1, 2.0 etc. under it. // 2. In this sample below we're looking for the location of GRE version 1.2 // i.e. we're compatible with GRE 1.2 and we're trying to find it's install // location. // // Please see http://www.mozilla.org/projects/embedding/GRE.html for // more info. // if (::RegOpenKeyExW(HKEY_CURRENT_USER, GRE_WIN_REG_LOC, 0, KEY_READ, &hRegKey) == ERROR_SUCCESS) { PRBool ok = GRE_GetPathFromRegKey(hRegKey, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen); ::RegCloseKey(hRegKey); if (ok) return NS_OK; } if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, GRE_WIN_REG_LOC, 0, KEY_ENUMERATE_SUB_KEYS, &hRegKey) == ERROR_SUCCESS) { PRBool ok = GRE_GetPathFromRegKey(hRegKey, versions, versionsLength, allProperties, allPropertiesLength, aBuffer, aBufLen); ::RegCloseKey(hRegKey); if (ok) return NS_OK; } #endif return NS_ERROR_FAILURE; }
void handle_device(AMDeviceRef device) { if (found_device) return; // handle one device only CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device); if (device_id != NULL) { if(strcmp(device_id, CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())) == 0) { found_device = true; } else { return; } } else { found_device = true; } CFRetain(device); // don't know if this is necessary? printf("[ 0%%] Found device (%s), beginning install\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())); AMDeviceConnect(device); assert(AMDeviceIsPaired(device)); assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceStartSession(device) == 0); CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false); CFURLRef url = CFURLCopyAbsoluteURL(relative_url); CFRelease(path); CFRelease(relative_url); CFStringRef keys[] = { CFSTR("PackageType") }; CFStringRef values[] = { CFSTR("Developer") }; CFDictionaryRef options = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); mach_error_t transfer_error = AMDeviceSecureTransferPath(0, device, url, options, &transfer_callback, 0); if (transfer_error) { printf("[ !! ] Unable to transfer package to device. (%x)\n", transfer_error); exit(1); } mach_error_t install_error = AMDeviceSecureInstallApplication(0, device, url, options, &install_callback, 0); if (install_error) { printf("[ !! ] Unable to install package. (%x)\n", install_error); exit(1); } CFRelease(options); printf("[100%%] Installed package %s\n", app_path); if (!debug) exit(0); // no debug phase printf("------ Debug phase ------\n"); mount_developer_image(device); // put debugserver on the device start_remote_debug_server(device); // start debugserver write_gdb_prep_cmds(device, url); // dump the necessary gdb commands into a file CFRelease(url); printf("[100%%] Connecting to remote debug server\n"); printf("-------------------------\n"); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { system(GDB_SHELL); // launch gdb kill(parent, SIGTERM); // "No. I am your father." _exit(0); } }
bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir) { wxString dir; m_localTemplate = false; DebugShow(wxT("looking for template: ") + templateName + wxT("\n")); #ifdef __WXMAC__ CFURLRef amuleBundleUrl; OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, // This magic string is the bundle identifier in aMule.app's Info.plist CFSTR("org.amule.aMule"), NULL, NULL, &amuleBundleUrl); if (status == noErr && amuleBundleUrl) { CFBundleRef amuleBundle = CFBundleCreate(NULL, amuleBundleUrl); CFRelease(amuleBundleUrl); if (amuleBundle) { CFURLRef webserverDirUrl = CFBundleCopyResourceURL( amuleBundle, CFSTR("webserver"), NULL, NULL); CFRelease(amuleBundle); if (webserverDirUrl) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(webserverDirUrl); CFRelease(webserverDirUrl); if (absoluteURL) { CFStringRef pathString = CFURLCopyFileSystemPath( absoluteURL, kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(2, 9, 0) dir = wxCFStringRef(pathString). AsString(wxLocale::GetSystemEncoding()); #else dir = wxMacCFStringHolder(pathString). AsString(wxLocale::GetSystemEncoding()); #endif if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } } } } } #endif dir = GetConfigDir(wxT("remote.conf")) + wxT("webserver"); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; m_localTemplate = true; return true; } #ifdef WEBSERVERDIR dir = wxT(WEBSERVERDIR); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } #endif dir = wxStandardPaths::Get().GetResourcesDir(); // Returns 'aMule' when we use 'amule' elsewhere #if !defined(__WXMSW__) && !defined(__WXMAC__) dir = dir.BeforeLast(wxFileName::GetPathSeparator()); dir = JoinPaths(dir, wxT("amule")); #endif dir = JoinPaths(dir, wxT("webserver")); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } // template not found. reverting to default const wxChar* const defaultTemplateName = wxT("default"); if ( templateName == defaultTemplateName ) { return false; } Show(wxT("Template ") + templateName + wxT(" not found, reverting to default\n\n")); return GetTemplateDir(defaultTemplateName, templateDir); }
void handle_device(AMDeviceRef device) { if (found_device) return; // handle one device only CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device); if (device_id != NULL) { if(strcmp(device_id, CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())) == 0) { found_device = true; } else { return; } } else { found_device = true; } CFRetain(device); // don't know if this is necessary? printf("[ 0%%] Found device (%s), beginning install\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())); AMDeviceConnect(device); assert(AMDeviceIsPaired(device)); assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceStartSession(device) == 0); CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false); CFURLRef url = CFURLCopyAbsoluteURL(relative_url); CFRelease(relative_url); service_conn_t afcFd; assert(AMDeviceStartService(device, CFSTR("com.apple.afc"), &afcFd, NULL) == 0); assert(AMDeviceStopSession(device) == 0); assert(AMDeviceDisconnect(device) == 0); assert(AMDeviceTransferApplication(afcFd, path, NULL, transfer_callback, NULL) == 0); close(afcFd); CFStringRef keys[] = { CFSTR("PackageType") }; CFStringRef values[] = { CFSTR("Developer") }; CFDictionaryRef options = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); AMDeviceConnect(device); assert(AMDeviceIsPaired(device)); assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceStartSession(device) == 0); service_conn_t installFd; assert(AMDeviceStartService(device, CFSTR("com.apple.mobile.installation_proxy"), &installFd, NULL) == 0); assert(AMDeviceStopSession(device) == 0); assert(AMDeviceDisconnect(device) == 0); mach_error_t result = AMDeviceInstallApplication(installFd, path, options, install_callback, NULL); if (result != 0) { printf("AMDeviceInstallApplication failed: %d\n", result); exit(1); } close(installFd); CFRelease(path); CFRelease(options); printf("[100%%] Installed package %s\n", app_path); if (!debug) exit(0); // no debug phase AMDeviceConnect(device); assert(AMDeviceIsPaired(device)); assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceStartSession(device) == 0); printf("------ Debug phase ------\n"); mount_developer_image(device); // put debugserver on the device start_remote_debug_server(device); // start debugserver write_gdb_prep_cmds(device, url); // dump the necessary gdb commands into a file CFRelease(url); printf("[100%%] Connecting to remote debug server\n"); printf("-------------------------\n"); signal(SIGHUP, gdb_ready_handler); signal(SIGINT, killed); signal(SIGTERM, killed); pid_t parent = getpid(); int pid = fork(); if (pid == 0) { CFStringRef path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb"), CFSTR("gdb-arm-apple-darwin")); if (path == NULL) { printf("[ !! ] Unable to locate GDB.\n"); kill(parent, SIGHUP); exit(1); } else { CFStringRef gdb_cmd = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ %@ %s"), path, CFSTR(GDB_SHELL), gdb_args); // Convert CFStringRef to char* for system call const char *char_gdb_cmd = CFStringGetCStringPtr(gdb_cmd, kCFStringEncodingMacRoman); system(char_gdb_cmd); // launch gdb } kill(parent, SIGHUP); // "No. I am your father." _exit(0); } }
void* AppleCMIODPSampleNewPlugIn(CFAllocatorRef allocator, CFUUIDRef requestedTypeUUID) { if (not CFEqual(requestedTypeUUID, kCMIOHardwarePlugInTypeID)) return 0; try { // Before going any further, make sure the SampleAssistant process is registerred with Mach's bootstrap service. Normally, this would be done by having an appropriately // configured plist in /Library/LaunchDaemons, but if that is done then the process will be owned by root, thus complicating the debugging process. Therefore, in the event that the // plist is missing (as would be the case for most debugging efforts) attempt to register the SampleAssistant now. It will fail gracefully if allready registered. mach_port_t assistantServicePort; name_t assistantServiceName = "com.apple.cmio.DPA.Sample"; kern_return_t err = bootstrap_look_up(bootstrap_port, assistantServiceName, &assistantServicePort); if (BOOTSTRAP_SUCCESS != err) { // Create an URL to SampleAssistant that resides at "/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant" CACFURL assistantURL(CFURLCreateWithFileSystemPath(NULL, CFSTR("/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant"), kCFURLPOSIXPathStyle, false)); ThrowIf(not assistantURL.IsValid(), CAException(-1), "AppleCMIODPSampleNewPlugIn: unable to create URL for the SampleAssistant"); // Get the maximum size of the of the file system representation of the SampleAssistant's absolute path CFIndex length = CFStringGetMaximumSizeOfFileSystemRepresentation(CACFString(CFURLCopyFileSystemPath(CACFURL(CFURLCopyAbsoluteURL(assistantURL.GetCFObject())).GetCFObject(), kCFURLPOSIXPathStyle)).GetCFString()); // Get the file system representation CAAutoFree<char> path(length); (void) CFURLGetFileSystemRepresentation(assistantURL.GetCFObject(), true, reinterpret_cast<UInt8*>(path.get()), length); mach_port_t assistantServerPort; err = bootstrap_create_server(bootstrap_port, path, getuid(), true, &assistantServerPort); ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create server"); err = bootstrap_check_in(assistantServerPort, assistantServiceName, &assistantServicePort); // The server port is no longer needed so get rid of it (void) mach_port_deallocate(mach_task_self(), assistantServerPort); // Make sure the call to bootstrap_create_service() succeeded ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create SampleAssistant service port"); } // The service port is not longer needed so get rid of it (void) mach_port_deallocate(mach_task_self(), assistantServicePort); CMIO::DP::Sample::PlugIn* plugIn = new CMIO::DP::Sample::PlugIn(requestedTypeUUID); plugIn->Retain(); return plugIn->GetInterface(); } catch (...) { return NULL; } }
kim_error kim_os_library_get_application_path (kim_string *out_path) { kim_error err = KIM_NO_ERROR; kim_string path = NULL; CFBundleRef bundle = CFBundleGetMainBundle (); if (!err && !out_path) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* Check if the caller is a bundle */ if (!err && bundle) { CFURLRef bundle_url = CFBundleCopyBundleURL (bundle); CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL (bundle); CFURLRef executable_url = CFBundleCopyExecutableURL (bundle); CFURLRef absolute_url = NULL; CFStringRef cfpath = NULL; if (bundle_url && resources_url && !CFEqual (bundle_url, resources_url)) { absolute_url = CFURLCopyAbsoluteURL (bundle_url); } else if (executable_url) { absolute_url = CFURLCopyAbsoluteURL (executable_url); } if (absolute_url) { cfpath = CFURLCopyFileSystemPath (absolute_url, kCFURLPOSIXPathStyle); if (!cfpath) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } if (!err && cfpath) { err = kim_os_string_create_from_cfstring (&path, cfpath); } if (cfpath ) { CFRelease (cfpath); } if (absolute_url ) { CFRelease (absolute_url); } if (bundle_url ) { CFRelease (bundle_url); } if (resources_url ) { CFRelease (resources_url); } if (executable_url) { CFRelease (executable_url); } } /* Caller is not a bundle, try _NSGetExecutablePath */ /* Note: this does not work on CFM applications */ if (!err && !path) { char *buffer = NULL; uint32_t len = 0; /* Tiny stupid buffer to get the length of the path */ if (!err) { buffer = malloc (1); if (!buffer) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } /* Get the length of the path */ if (!err) { if (_NSGetExecutablePath (buffer, &len) != 0) { char *temp = realloc (buffer, len + 1); if (!temp) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } else { buffer = temp; } } } /* Get the path */ if (!err) { if (_NSGetExecutablePath (buffer, &len) != 0) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } else { err = kim_string_copy (&path, buffer); } } if (buffer) { free (buffer); } } if (!err) { *out_path = path; path = NULL; } kim_string_free (&path); return check_error (err); }