//----------------------------------------------------------------------------- // InitializeCustomToolbarItem //----------------------------------------------------------------------------- // This is called after our item has been constructed. We are called here so // that we can pull parameters out of the Carbon Event that is passed into the // HIObjectCreate call. // static OSStatus InitializeCustomToolbarItem( CustomToolbarItem* inItem, EventRef inEvent ) { CFTypeRef data; IconRef iconRef; if ( GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL, sizeof( CFTypeRef ), NULL, &data ) == noErr ) { if ( CFGetTypeID( data ) == CFStringGetTypeID() ) inItem->url = CFURLCreateWithString( NULL, (CFStringRef)data, NULL ); else inItem->url = (CFURLRef)CFRetain( data ); } else { inItem->url = CFURLCreateWithString( NULL, CFSTR( "http://www.apple.com" ), NULL ); } HIToolbarItemSetLabel( inItem->toolbarItem, CFSTR( "URL Item" ) ); if ( GetIconRef( kOnSystemDisk, kSystemIconsCreator, kGenericURLIcon, &iconRef ) == noErr ) { HIToolbarItemSetIconRef( inItem->toolbarItem, iconRef ); ReleaseIconRef( iconRef ); } HIToolbarItemSetHelpText( inItem->toolbarItem, CFURLGetString( inItem->url ), NULL ); return noErr; }
CFErrorRef ResourceError::cfError() const { if (m_isNull) { ASSERT(!m_platformError); return 0; } if (!m_platformError) { RetainPtr<CFMutableDictionaryRef> userInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); if (!m_localizedDescription.isEmpty()) { RetainPtr<CFStringRef> localizedDescriptionString(AdoptCF, m_localizedDescription.createCFString()); CFDictionarySetValue(userInfo.get(), kCFErrorLocalizedDescriptionKey, localizedDescriptionString.get()); } if (!m_failingURL.isEmpty()) { RetainPtr<CFStringRef> failingURLString(AdoptCF, m_failingURL.createCFString()); CFDictionarySetValue(userInfo.get(), failingURLStringKey, failingURLString.get()); RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(0, failingURLString.get(), 0)); CFDictionarySetValue(userInfo.get(), failingURLKey, url.get()); } #if PLATFORM(WIN) if (m_certificate) wkSetSSLPeerCertificateData(userInfo.get(), m_certificate.get()); #endif RetainPtr<CFStringRef> domainString(AdoptCF, m_domain.createCFString()); m_platformError.adoptCF(CFErrorCreate(0, domainString.get(), m_errorCode, userInfo.get())); } return m_platformError.get(); }
URL::URL( CFStringRef value ) { if( value != NULL && CFGetTypeID( value ) == CFStringGetTypeID() ) { this->_cfObject = CFURLCreateWithString( static_cast< CFAllocatorRef >( NULL ), value, NULL ); } }
CFBundleRef LoadBundle(const char* lpBundlePath) { if(lpBundlePath == NULL) { return NULL; } CFStringRef bundlePath = CFStringCreateWithCString(kCFAllocatorSystemDefault, lpBundlePath, CFStringGetSystemEncoding()); if(NULL == bundlePath) { return NULL; } CFURLRef bundleURL = CFURLCreateWithString(kCFAllocatorSystemDefault, bundlePath, NULL); if(NULL == bundleURL) { return NULL; } #endif // 2.get bundle ref CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL); CFRelease(bundleURL); if(NULL != bundleRef) { } return bundleRef; }
bool LaunchBrowser(const char* url) { #ifdef WIN32 int r = (int)ShellExecuteA(0, "open", url, "", "", 1); return (r > 32); #else #ifdef MACOSX CFStringRef strurl = //CFSTR("http://www.amju.com"); // TODO HACK CFStringCreateWithBytes( 0, (const unsigned char*)url, strlen(url), kCFStringEncodingMacRoman, false); CFURLRef cfurl = CFURLCreateWithString(0, strurl, 0); OSStatus ret = LSOpenCFURLRef(cfurl, 0); std::cout << "Launch URL: " << CFStringGetCStringPtr(strurl, kCFStringEncodingMacRoman) << "\n"; std::cout << "Launch result: " << ret << "\n"; // TODO deal with ret return true; #else // Not implemented for this platform return false; #endif #endif }
/* * Given a Dfs Referral string create a CFURL. Remember referral have a file * syntax * * Example: "/smb-win2003.apple.com/DfsRoot/DfsLink1" */ CFURLRef CreateURLFromReferral(CFStringRef inStr) { CFURLRef ct_url = NULL; CFMutableStringRef urlString = CFStringCreateMutableCopy(NULL, 0, CFSTR("smb:/")); CFStringRef escapeStr = inStr; /* * CreateStringByAddingPercentEscapesUTF8() will either create a new string * or return the original with ref count incremented. Either way we have to * call CFRelease on the returned string */ CreateStringByAddingPercentEscapesUTF8(&escapeStr, NULL, NULL, FALSE); if (urlString) { CFStringAppend(urlString, escapeStr); ct_url = CFURLCreateWithString(kCFAllocatorDefault, urlString, NULL); CFRelease(urlString); /* We create it now release it */ } if (!ct_url) { LogCFString(inStr, "creating url failed", __FUNCTION__, __LINE__); } if (escapeStr) { CFRelease(escapeStr); } return ct_url; }
void CWebKitActiveScroller::SetURL(const cdstring& urltxt) { MyCFString cfstring(urltxt, kCFStringEncodingUTF8); CFURLRef url = CFURLCreateWithString( NULL, cfstring, NULL ); URLToWebView(mViewRef, url); CFRelease(url); }
/* * Return a pretty command, on some OS's we might do something * different than just display the command. * * free_ret - whether or not to free the return value */ char * execview_pretty_command(MCAP_CMD_S *mc_cmd, int *free_ret) { char *str; int rv_to_free = 0; if(free_ret) *free_ret = rv_to_free; if(!mc_cmd) return NULL; str = mc_cmd->command; #ifdef _WINDOWS if(*str == '*' || (*str == '\"' && str[1] == '*')){ if(!strncmp(str + ((*str == '\"') ? 2 : 1), "DDE*", 4)) str = cpystr("via app already running"); else if(!strncmp(str + ((*str == '\"') ? 2 : 1),"ShellEx*",8)) str = cpystr("via Explorer defined app"); else str = cpystr("via Windows-specific method"); rv_to_free = 1; } #elif OSX_TARGET if(mc_cmd->special_handling){ CFStringRef str_ref = NULL, kind_str_ref = NULL; CFURLRef url_ref; char buf[256]; if((str_ref = CFStringCreateWithCString(NULL, mc_cmd->command, kCFStringEncodingASCII)) == NULL) return ""; if((url_ref = CFURLCreateWithString(NULL, str_ref, NULL)) == NULL) return ""; if(LSCopyDisplayNameForURL(url_ref, &kind_str_ref) != noErr) return ""; if(CFStringGetCString(kind_str_ref, buf, (CFIndex)255, kCFStringEncodingASCII) == false) return ""; buf[255] = '\0'; str = cpystr(buf); rv_to_free = 1; if(kind_str_ref) CFRelease(kind_str_ref); } #else /* always pretty */ #endif if(free_ret) *free_ret = rv_to_free; return(str); }
/* Create a URI suitable for use in an http GET request, will return NULL if the length would exceed 255 bytes. */ static CFURLRef createGetURL(CFURLRef responder, CFDataRef request) { CFURLRef getURL = NULL; CFMutableDataRef base64Request = NULL; CFStringRef base64RequestString = NULL; CFStringRef peRequest = NULL; CFIndex base64Len; base64Len = SecBase64Encode(NULL, CFDataGetLength(request), NULL, 0); /* Don't bother doing all the work below if we know the end result will exceed 255 bytes (minus one for the '/' separator makes 254). */ if (base64Len + CFURLGetBytes(responder, NULL, 0) > 254) return NULL; require(base64Request = CFDataCreateMutable(kCFAllocatorDefault, base64Len), errOut); CFDataSetLength(base64Request, base64Len); SecBase64Encode(CFDataGetBytePtr(request), CFDataGetLength(request), (char *)CFDataGetMutableBytePtr(base64Request), base64Len); require(base64RequestString = CFStringCreateWithBytes(kCFAllocatorDefault, CFDataGetBytePtr(base64Request), base64Len, kCFStringEncodingUTF8, false), errOut); require(peRequest = CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, base64RequestString, NULL, CFSTR("+/="), kCFStringEncodingUTF8), errOut); #if 1 CFStringRef urlString = CFURLGetString(responder); CFStringRef fullURL; if (CFStringHasSuffix(urlString, CFSTR("/"))) { fullURL = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@%@"), urlString, peRequest); } else { fullURL = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@/%@"), urlString, peRequest); } getURL = CFURLCreateWithString(kCFAllocatorDefault, fullURL, NULL); CFRelease(fullURL); #else getURL = CFURLCreateWithString(kCFAllocatorDefault, peRequest, responder); #endif errOut: CFReleaseSafe(base64Request); CFReleaseSafe(base64RequestString); CFReleaseSafe(peRequest); return getURL; }
URL::URL( std::string value ) { CF::String s; s = value; this->_cfObject = CFURLCreateWithString( static_cast< CFAllocatorRef >( NULL ), static_cast< CFStringRef >( s ), NULL ); }
static void FetchIPAddress() { if(publicIPState == IPStateFetching) return; publicIPState = IPStateFetching; const UInt8 bodyBytes[] = {0}; CFDataRef body = CFDataCreate(kCFAllocatorDefault, bodyBytes, 0); CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("http://icanhazip.com"), NULL); CFHTTPMessageRef request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), url, kCFHTTPVersion1_1); CFHTTPMessageSetBody(request, body); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" // Apple suggests the NSURLSession API instead of CFReadStreamCreateForHTTPRequest, // But obviously that doesn't really work here CFReadStreamRef stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request); #pragma clang diagnostic pop CFRelease(body); CFRelease(url); CFRelease(request); CFMutableDataRef responseData = CFDataCreateMutable(kCFAllocatorDefault, 17); CFStreamClientContext context = { 0, responseData, NULL, NULL, NULL }; if(!CFReadStreamSetClient(stream, kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred, &IPStreamCallback, &context)) { CFRelease(stream); publicIPState = IPStateInvalid; return; } // Add to the run loop and open the stream CFReadStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); if(!CFReadStreamOpen(stream)) { CFReadStreamSetClient(stream, 0, NULL, NULL); CFReadStreamUnscheduleFromRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); CFRelease(stream); publicIPState = IPStateInvalid; return; } // Run the run loop do { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, TRUE); } while(publicIPState == IPStateFetching); }
/* * Parse file extension and attempt to map it to format and type. Returns true * on success. */ bool impExpImportParseFileExten( CFStringRef fstr, SecExternalFormat *inputFormat, // RETURNED SecExternalItemType *itemType) // RETURNED { if(fstr == NULL) { /* nothing to work with */ return false; } if(CFStringHasSuffix(fstr, CFSTR(".cer")) || CFStringHasSuffix(fstr, CFSTR(".crt"))) { *inputFormat = kSecFormatX509Cert; *itemType = kSecItemTypeCertificate; SecImpInferDbg("Inferring kSecFormatX509Cert from file name"); return true; } if(CFStringHasSuffix(fstr, CFSTR(".p12")) || CFStringHasSuffix(fstr, CFSTR(".pfx"))) { *inputFormat = kSecFormatPKCS12; *itemType = kSecItemTypeAggregate; SecImpInferDbg("Inferring kSecFormatPKCS12 from file name"); return true; } /* Get extension, look for key indicators as substrings */ CFURLRef url = CFURLCreateWithString(NULL, fstr, NULL); if(url == NULL) { SecImpInferDbg("impExpImportParseFileExten: error creating URL"); return false; } CFStringRef exten = CFURLCopyPathExtension(url); CFRelease(url); if(exten == NULL) { /* no extension, app probably passed in only an extension */ exten = fstr; CFRetain(exten); } bool ortn = false; CFRange cfr; cfr = CFStringFind(exten, CFSTR("p7"), kCFCompareCaseInsensitive); if(cfr.length != 0) { *inputFormat = kSecFormatPKCS7; *itemType = kSecItemTypeAggregate; SecImpInferDbg("Inferring kSecFormatPKCS7 from file name"); ortn = true; } if(!ortn) { cfr = CFStringFind(exten, CFSTR("p8"), kCFCompareCaseInsensitive); if(cfr.length != 0) { *inputFormat = kSecFormatWrappedPKCS8; *itemType = kSecItemTypePrivateKey; SecImpInferDbg("Inferring kSecFormatPKCS8 from file name"); ortn = true; } } CFRelease(exten); return ortn; }
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(CFURLCreateWithString) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2) { jintLong rc = 0; WebKit_win32_NATIVE_ENTER(env, that, CFURLCreateWithString_FUNC); rc = (jintLong)CFURLCreateWithString((CFAllocatorRef)arg0, (CFStringRef)arg1, (CFURLRef)arg2); WebKit_win32_NATIVE_EXIT(env, that, CFURLCreateWithString_FUNC); return rc; }
void loadKernelExtension() { // Check if the kernel extension package is installed. auto results = SQL::selectAllFrom( "package_receipts", "path", EQUALS, kKernelPackageReceipt); if (results.size() == 0) { // The kernel package is not installed. return; } // Find the panic log file for the last panic if we are booting out of panic. results = SQL::SQL( "SELECT f.path AS path FROM (SELECT * FROM nvram WHERE name like " "'%panic%') AS nv JOIN (SELECT * FROM file WHERE " "directory='/Library/Logs/DiagnosticReports/' AND path like " "'%/Kernel%' ORDER BY ctime DESC LIMIT 1) as f;") .rows(); // If a panic exists, check if it was caused by the osquery extension. if (results.size() == 1) { std::string panic_content; if (readFile(results[0]["path"], panic_content).ok()) { auto rx = xp::sregex::compile(kKernelBundleRegex); xp::smatch matches; // If so, write a blacklist file that prevents future load attempts. if (xp::regex_search(panic_content, matches, rx)) { LOG(ERROR) << "Panic was caused by osquery kernel extension"; writeTextFile(kBlockingFile, ""); } } } // Check if the kernel extension is manually (or set from crash) blocked. results = SQL::selectAllFrom("file", "path", EQUALS, kBlockingFile); if (FLAGS_disable_kernel) { LOG(INFO) << "Kernel extension is disabled"; return; } else if (results.size() > 0) { LOG(WARNING) << "Kernel extension disabled by file"; return; } CFURLRef urls[1]; CFArrayRef directoryArray; urls[0] = CFURLCreateWithString(nullptr, kKernelExtensionDirectory, nullptr); directoryArray = CFArrayCreate(nullptr, (const void**)urls, 1, &kCFTypeArrayCallBacks); if (KextManagerLoadKextWithIdentifier(kKernelBundleId, directoryArray) != kOSReturnSuccess) { VLOG(1) << "Could not autoload kernel extension"; } else { VLOG(1) << "Autoloaded osquery kernel extension"; } CFRelease(directoryArray); }
CFURLRef Caching_Stream::createFileURLWithPath(CFStringRef path) { CFURLRef regularUrl = CFURLCreateWithString(kCFAllocatorDefault, path, NULL); CFURLRef fileUrl = CFURLCreateFilePathURL(kCFAllocatorDefault, regularUrl, NULL); CFRelease(regularUrl); return fileUrl; }
// Open a URL with the user's default web browser. // Must begin with protocol identifier. void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url, bool async) { // I'm fairly certain that this is all legitimate under Apple's currently supported APIs. bool found = false; S32 i; for (i = 0; i < gURLProtocolWhitelistCount; i++) { if (escaped_url.find(gURLProtocolWhitelist[i]) != std::string::npos) { found = true; break; } } if (!found) { LL_WARNS() << "spawn_web_browser called for url with protocol not on whitelist: " << escaped_url << LL_ENDL; return; } S32 result = 0; CFURLRef urlRef = NULL; LL_INFOS() << "Opening URL " << escaped_url << LL_ENDL; CFStringRef stringRef = CFStringCreateWithCString(NULL, escaped_url.c_str(), kCFStringEncodingUTF8); if (stringRef) { // This will succeed if the string is a full URL, including the http:// // Note that URLs specified this way need to be properly percent-escaped. urlRef = CFURLCreateWithString(NULL, stringRef, NULL); // Don't use CRURLCreateWithFileSystemPath -- only want valid URLs CFRelease(stringRef); } if (urlRef) { result = LSOpenCFURLRef(urlRef, NULL); if (result != noErr) { LL_INFOS() << "Error " << result << " on open." << LL_ENDL; } CFRelease(urlRef); } else { LL_INFOS() << "Error: couldn't create URL." << LL_ENDL; } }
static bool lsOpen(const QUrl &url) { if (!url.isValid() || url.scheme().isEmpty()) return false; QCFType<CFURLRef> cfUrl = CFURLCreateWithString(0, QCFString(QString::fromLatin1(url.toEncoded())), 0); if (cfUrl == 0) return false; const OSStatus err = LSOpenCFURLRef(cfUrl, 0); return (err == noErr); }
// --------------------------------- void USys::openURL(const char *url) { CFStringRef urlString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s"), url); if (urlString) { CFURLRef pathRef = CFURLCreateWithString(NULL, urlString, NULL); if (pathRef) { //OSStatus err = LSOpenCFURLRef( pathRef, NULL ); CFRelease(pathRef); } CFRelease(urlString); } }
void QuartzBitmap_Output(QuartzDesc_t dev, QuartzBitmapDevice *qbd) { if(qbd->path && qbd->uti) { /* On 10.4+ we can employ the CGImageDestination API to create a variety of different bitmap formats */ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 char buf[PATH_MAX+1]; snprintf(buf, PATH_MAX, qbd->path, qbd->page); buf[PATH_MAX] = '\0'; CFStringRef pathString = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) buf, strlen(buf), kCFStringEncodingUTF8, FALSE); CFURLRef path; if(CFStringFind(pathString, CFSTR("://"), 0).location != kCFNotFound) { CFStringRef pathEscaped = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, pathString, NULL, NULL, kCFStringEncodingUTF8); path = CFURLCreateWithString(kCFAllocatorDefault, pathEscaped, NULL); CFRelease(pathEscaped); } else { path = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*) buf, strlen(buf), FALSE); } CFRelease(pathString); CFStringRef scheme = CFURLCopyScheme(path); CFStringRef type = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) qbd->uti, strlen(qbd->uti), kCFStringEncodingUTF8, FALSE); CGImageRef image = CGBitmapContextCreateImage(qbd->bitmap); if(CFStringCompare(scheme,CFSTR("file"), 0) == 0) { /* file output */ CGImageDestinationRef dest = CGImageDestinationCreateWithURL(path, type, 1, NULL); if(dest) { CGImageDestinationAddImage(dest, image, NULL); CGImageDestinationFinalize(dest); CFRelease(dest); } else error(_("QuartzBitmap_Output - unable to open file '%s'"), buf); } else if(CFStringCompare(scheme, CFSTR("clipboard"), 0) == 0) { /* clipboard output */ CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); CGImageDestinationRef dest = CGImageDestinationCreateWithData(data, type, 1, NULL); CGImageDestinationAddImage(dest, image, NULL); CGImageDestinationFinalize(dest); CFRelease(dest); PasteboardRef pb = NULL; if(PasteboardCreate(kPasteboardClipboard, &pb) == noErr) { PasteboardClear(pb); PasteboardSynchronize(pb); PasteboardPutItemFlavor(pb, (PasteboardItemID) 1, type, data, 0); } CFRelease(data); } else warning(_("not a supported scheme, no image data written")); CFRelease(scheme); CFRelease(type); CFRelease(path); CFRelease(image); #endif } }
void BrowserView::goToURL(const std::wstring& urlString) { CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size()); CFURLRef cfURL = CFURLCreateWithString(0, string, 0); CFRelease(string); WKURLRef url = WKURLCreateWithCFURL(cfURL); CFRelease(cfURL); WKPageRef page = WKViewGetPage(m_webView); WKPageLoadURL(page, url); WKRelease(url); }
// --------------------------------- void USys::executeFile(const char *file) { CFStringRef fileString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s"), file); if (fileString) { CFURLRef pathRef = CFURLCreateWithString(NULL, fileString, NULL); if (pathRef) { FSRef fsRef; CFURLGetFSRef(pathRef, &fsRef); //OSStatus err = LSOpenFSRef( &fsRef, NULL ); CFRelease(pathRef); } CFRelease(fileString); } }
/* MySimpleDirectoryListing implements the directory list command. It sets up a MyStreamInfo 'object' with the read stream being an FTP stream of the directory to list and with no write stream. It then returns, and the real work happens asynchronously in the runloop. The function returns true if the stream setup succeeded, and false if it failed. */ static Boolean MySimpleDirectoryListing(CFStringRef urlString, CFStringRef username, CFStringRef password) { CFReadStreamRef readStream; CFStreamClientContext context = { 0, NULL, NULL, NULL, NULL }; CFURLRef downloadURL; Boolean success = true; MyStreamInfo *streamInfo; assert(urlString != NULL); downloadURL = CFURLCreateWithString(kCFAllocatorDefault, urlString, NULL); assert(downloadURL != NULL); /* Create an FTP read stream for downloading operation from an FTP URL. */ readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, downloadURL); assert(readStream != NULL); CFRelease(downloadURL); /* Initialize our MyStreamInfo structure, which we use to store some information about the stream. */ MyStreamInfoCreate(&streamInfo, readStream, NULL); context.info = (void *)streamInfo; /* CFReadStreamSetClient registers a callback to hear about interesting events that occur on a stream. */ success = CFReadStreamSetClient(readStream, kNetworkEvents, MyDirectoryListingCallBack, &context); if (success) { /* Schedule a run loop on which the client can be notified about stream events. The client callback will be triggered via the run loop. It's the caller's responsibility to ensure that the run loop is running. */ CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); MyCFStreamSetUsernamePassword(readStream, username, password); MyCFStreamSetFTPProxy(readStream, &streamInfo->proxyDict); /* CFReadStreamOpen will return success/failure. Opening a stream causes it to reserve all the system resources it requires. If the stream can open non-blocking, this will always return TRUE; listen to the run loop source to find out when the open completes and whether it was successful. */ success = CFReadStreamOpen(readStream); if (success == false) { fprintf(stderr, "CFReadStreamOpen failed\n"); MyStreamInfoDestroy(streamInfo); } } else { fprintf(stderr, "CFReadStreamSetClient failed\n"); MyStreamInfoDestroy(streamInfo); } return success; }
static CFURLRef FindJnlpURLInFile(char* fileName) { XMLNode* doc = NULL; CFURLRef returnValue = NULL; char* jnlbuffer = NULL; /* Parse XML document. */ if (!ReadFileToBuffer(fileName, &jnlbuffer)) { return NULL; } doc = ParseXMLDocument(jnlbuffer); if (doc != NULL) { XMLNode* node = NULL; char *codebase = NULL; char *href = NULL; CFStringRef baseURLString = NULL; CFStringRef hrefString = NULL; CFMutableStringRef fullURL = NULL; node = FindXMLChild(doc, "jnlp"); require(node != NULL, bail); codebase = FindXMLAttribute(node->_attributes, "codebase"); require(codebase != NULL, bail); href = FindXMLAttribute(node->_attributes, "href"); require(href != NULL, bail); baseURLString = CFStringCreateWithCString(NULL, codebase, kCFStringEncodingUTF8); require(baseURLString != NULL, bail); fullURL = CFStringCreateMutableCopy(NULL, 0, baseURLString); hrefString = CFStringCreateWithCString(NULL, href, kCFStringEncodingUTF8); require(hrefString != NULL, bail); // a relative JNLP path needs a URL that starts at the specificed codebase if (!CFStringHasSuffix(fullURL, CFSTR("/"))) CFStringAppend(fullURL, CFSTR("/")); CFStringAppend(fullURL, hrefString); returnValue = CFURLCreateWithString(NULL, fullURL, NULL); bail: if (baseURLString != NULL) CFRelease(baseURLString); if (hrefString != NULL) CFRelease(hrefString); if (fullURL != NULL) CFRelease(fullURL); FreeXMLDocument(doc); } free(jnlbuffer); return returnValue; }
URL & URL::operator = ( std::string value ) { CF::String s; if( this->_cfObject != NULL ) { CFRelease( this->_cfObject ); } s = value; this->_cfObject = CFURLCreateWithString( static_cast< CFAllocatorRef >( NULL ), static_cast< CFStringRef >( s ), NULL ); return *( this ); }
/* * Get the user and workgroup names and return them in CFStringRef. * First get the CFURLCopyNetLocation because it will not escape out the string. */ static CFStringRef CopyUserAndWorkgroupFromURL(CFStringRef *outWorkGroup, CFURLRef url) { CFURLRef net_url = NULL; CFArrayRef userArray = NULL; CFStringRef userString = NULL; CFMutableStringRef urlString = NULL; CFStringRef wrkgrpString = NULL; *outWorkGroup = NULL; /* Always start like we didn't get one. */ /* This will return null if no workgroup in the URL */ userArray = CreateWrkgrpUserArray(url); if (!userArray) /* We just have a username name */ return(CFURLCopyUserName(url)); /* This will escape out the character for us. */ /* Now for the hard part; netlocation contains one of the following: * * URL = "//workgroup;username:[email protected]" * URL = "//workgroup;username:@smb-win2003.apple.com" * URL = "//workgroup;[email protected]" * URL = "//workgroup;@smb-win2003.apple.com" */ /* Get the username first */ urlString = CFStringCreateMutableCopy(NULL, 1024, CFSTR("smb://")); if (!urlString) { CFRelease(userArray); return(CFURLCopyUserName(url)); /* This will escape out the character for us. */ } CFStringAppend(urlString, (CFStringRef)CFArrayGetValueAtIndex(userArray, 1)); net_url = CFURLCreateWithString(NULL, urlString, NULL); CFRelease(urlString); urlString = NULL; /* Not sure what to do if we fail here */ if (!net_url) { CFRelease(userArray); return(CFURLCopyUserName(url)); /* This will escape out the character for us. */ } /* We now have a URL without the workgroup name, just copy out the username. */ userString = CFURLCopyUserName(net_url); CFRelease(net_url); /* Now get the workgroup */ wrkgrpString = CFStringCreateCopy(NULL, (CFStringRef)CFArrayGetValueAtIndex(userArray, 0)); CreateStringByReplacingPercentEscapesUTF8(&wrkgrpString, CFSTR("")); if (wrkgrpString) *outWorkGroup = wrkgrpString; /* We have the workgroup return it to the calling routine */ CFRelease(userArray); return(userString); }
bool wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params) { wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault, wxCFStringRef( params.url ), NULL ) ); OSStatus err = LSOpenCFURLRef( curl , NULL ); if (err == noErr) { return true; } else { wxLogDebug(wxT("Browser Launch error %d"), (int) err); return false; } }
static bool OnLionOrLater() { if (sOnLionOrLater < 0) { SInt32 major = 0, minor = 0; CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("file:///System/Library/CoreServices/SystemVersion.plist"), NULL); CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, url); CFReadStreamOpen(stream); CFDictionaryRef sysVersionPlist = (CFDictionaryRef) CFPropertyListCreateWithStream(kCFAllocatorDefault, stream, 0, kCFPropertyListImmutable, NULL, NULL); CFReadStreamClose(stream); CFRelease(stream); CFRelease(url); CFStringRef versionString = (CFStringRef) CFDictionaryGetValue(sysVersionPlist, CFSTR("ProductVersion")); CFArrayRef versions = CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, versionString, CFSTR(".")); CFIndex count = CFArrayGetCount(versions); if (count > 0) { CFStringRef component = (CFStringRef) CFArrayGetValueAtIndex(versions, 0); major = CFStringGetIntValue(component); if (count > 1) { component = (CFStringRef) CFArrayGetValueAtIndex(versions, 1); minor = CFStringGetIntValue(component); } } CFRelease(sysVersionPlist); CFRelease(versions); if (major < 10) { sOnLionOrLater = 0; } else { int version = 0x1000 + (minor << 4); sOnLionOrLater = version >= MAC_OS_X_VERSION_10_7_HEX ? 1 : 0; } } return sOnLionOrLater > 0 ? true : false; }
URL & URL::operator = ( CFStringRef value ) { if( this->_cfObject != NULL ) { CFRelease( this->_cfObject ); } if( value != NULL && CFGetTypeID( value ) == CFStringGetTypeID() ) { this->_cfObject = CFURLCreateWithString( static_cast< CFAllocatorRef >( NULL ), value, NULL ); } else { this->_cfObject = NULL; } return *( this ); }
void openURL(const std::string &url) { #ifdef BBGE_BUILD_WINDOWS ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL); #endif #if defined(BBGE_BUILD_MACOSX) CFStringRef str = CFStringCreateWithCString (0, url.c_str(), 0); CFURLRef ref = CFURLCreateWithString(kCFAllocatorDefault, str, NULL); LSOpenCFURLRef(ref, 0); CFRelease(ref); CFRelease(str); #elif BBGE_BUILD_UNIX std::string cmd("PATH=$PATH:. xdg-open '"); cmd += url; cmd += "'"; if (system(cmd.c_str()) != 0) debugLog("system(xdg_open '" + url + "') failed"); #endif }
JNIEXPORT jobjectArray JNICALL Java_com_zimbra_znative_ProxyInfo_getProxyInfo(JNIEnv *env, jclass cls, jstring jurl) { check_initialized(env); CFStringRef urlstr = getCFString(env, jurl); CFURLRef url = CFURLCreateWithString(NULL, urlstr, NULL); CFDictionaryRef systemProxy = CFNetworkCopySystemProxySettings(); CFArrayRef proxyArray = CFNetworkCopyProxiesForURL(url, systemProxy); CFIndex size = CFArrayGetCount(proxyArray); jobjectArray results = (*env)->NewObjectArray(env, (jsize) size, pi_cls, NULL); int i; for (i = 0; i < size; i++) { CFDictionaryRef proxy = CFArrayGetValueAtIndex(proxyArray, i); (*env)->SetObjectArrayElement(env, results, i, getProxyInfo(env, proxy)); } CFRelease(proxyArray); CFRelease(systemProxy); CFRelease(url); CFRelease(urlstr); return results; }