bool operator==(const CString& a, const CString& b) { if (a.isNull() != b.isNull()) return false; if (a.length() != b.length()) return false; return !memcmp(a.data(), b.data(), a.length()); }
bool operator<(const CString& a, const CString& b) { if (a.isNull()) return !b.isNull(); if (b.isNull()) return false; return strcmp(a.data(), b.data()) < 0; }
TEST(CStringTest, UninitializedConstructor) { char* buffer; CString emptyString = CString::newUninitialized(0, buffer); EXPECT_FALSE(emptyString.isNull()); EXPECT_EQ(buffer, emptyString.data()); EXPECT_EQ(0, buffer[0]); const size_t length = 25; CString uninitializedString = CString::newUninitialized(length, buffer); EXPECT_FALSE(uninitializedString.isNull()); EXPECT_EQ(buffer, uninitializedString.data()); EXPECT_EQ(0, uninitializedString.data()[length]); }
UnixEnvironment::UnixEnvironment() { dtMountPoint = getEnvironmentVariable("DTMOUNTPOINT"); if (dtMountPoint.isNull()) #if defined(sun) || defined(USL) || defined(__uxp__) dtMountPoint = "/net/"; #else dtMountPoint = "/nfs/"; #endif CString temp = getEnvironmentVariable("MANPATH"); if (temp.isNull()) #if defined(sun) || defined(USL) || defined(__uxp__) manpath = "/usr/share/man"; #elif defined(_AIX) manpath = "/usr/share/man:/usr/lpp/info"; #elif defined(hpux) manpath = "/usr/man:/usr/contrib/man:/usr/local/man"; #elif defined(__osf__) manpath = "/usr/share/%L/man:/usr/share/man:/usr/local/man"; #elif defined(linux) manpath = "/usr/share/man/%L:/usr/share/man:/usr/contrib/man/%L:/usr/contrib/man:/usr/local/man/%L:/usr/local/man"; #elif defined(__OpenBSD__) manpath = "/usr/share/man:/usr/X11R6/man:/usr/local/man:/usr/ports/infrastructure/man"; #elif defined(__FreeBSD__) manpath = "/usr/share/man:/usr/local/man"; #endif else
bool operator==(const CString& a, const char* b) { if (a.isNull() != !b) return false; if (!b) return true; return !strcmp(a.data(), b); }
static String getExecutablePath() { CString executablePath = getCurrentExecutablePath(); if (!executablePath.isNull()) return directoryName(filenameToString(executablePath.data())); return String(); }
void Scene::edit(CString command) { CString mapName = command.getFirstToken(' '); int w,h; CString token = command.getFirstToken(' '); if (token.isNull()) w = 0; else w = token.toInt(); token = command.getFirstToken(' '); if (token.isNull()) h = 0; else h = token.toInt(); disconnect(); console->add("\x3> Creating Editor"); // ZEVEN_SAFE_DELETE(menuManager.root); editor = new Editor(mapName, font, w, h); // On connect notre jeu au client // menu->hide(); menuManager.root->visible = false; }
void PluginStream::sendJavaScriptStream(const KURL& requestURL, const CString& resultString) { didReceiveResponse(0, ResourceResponse(requestURL, "text/plain", resultString.length(), "", "")); if (m_streamState == StreamStopped) return; if (!resultString.isNull()) { didReceiveData(0, resultString.data(), resultString.length()); if (m_streamState == StreamStopped) return; } m_loader = 0; destroyStream(resultString.isNull() ? NPRES_NETWORK_ERR : NPRES_DONE); }
PassRefPtr<Image> loadImageFromFile(CString fileName) { RefPtr<BitmapImage> img = BitmapImage::create(); if (!fileName.isNull()) { RefPtr<SharedBuffer> buffer = loadResourceSharedBuffer(fileName); img->setData(buffer.release(), true); } return img.release(); }
JSRetainPtr<JSStringRef> LayoutTestController::markerTextForListItem(JSContextRef context, JSValueRef nodeObject) const { CString markerTextGChar = DumpRenderTreeSupportGtk::markerTextForListItem(mainFrame, context, nodeObject); if (markerTextGChar.isNull()) return 0; JSRetainPtr<JSStringRef> markerText(Adopt, JSStringCreateWithUTF8CString(markerTextGChar.data())); return markerText; }
JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef id) { gchar* idGChar = JSStringCopyUTF8CString(id); CString counterValueGChar = DumpRenderTreeSupportGtk::counterValueForElementById(mainFrame, idGChar); g_free(idGChar); if (counterValueGChar.isNull()) return 0; JSRetainPtr<JSStringRef> counterValue(Adopt, JSStringCreateWithUTF8CString(counterValueGChar.data())); return counterValue; }
virtual void runJavaScriptPrompt(WebPageProxy*, const String& message, const String& defaultValue, WebFrameProxy*, std::function<void (const String&)> completionHandler) override { CString result = webkitWebViewRunJavaScriptPrompt(m_webView, message.utf8(), defaultValue.utf8()); if (result.isNull()) { completionHandler(String()); return; } completionHandler(String::fromUTF8(result.data())); }
void ArgumentCoder<CString>::encode(ArgumentEncoder& encoder, const CString& string) { // Special case the null string. if (string.isNull()) { encoder << std::numeric_limits<uint32_t>::max(); return; } uint32_t length = string.length(); encoder << length; encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length, 1); }
PassRefPtr<Image> Image::loadPlatformResource(const char* name) { CString fileName; if (!strcmp("missingImage", name)) fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16); if (fileName.isNull()) { GOwnPtr<gchar> imageName(g_strdup_printf("%s.png", name)); GOwnPtr<gchar> glibFileName(g_build_filename(getWebKitDataDirectory(), "webkitgtk-"WEBKITGTK_API_VERSION_STRING, "images", imageName.get(), NULL)); fileName = glibFileName.get(); } return loadImageFromFile(fileName); }
void AppManagerDirectory::TraversePath() { if (!appsp_.isNull()) { CTokenizedString subpath(appsp_,":"); CString dir = subpath.next(); while (!dir.isNull()) { GatherAppsFromASearchElement (dir); dir = subpath.next(); if (langVersionFound && dir == "/usr/dt/appconfig/appmanager/C") dir = subpath.next(); } } }
PassRefPtr<Image> Image::loadPlatformResource(const char* name) { CString fileName; if (!strcmp("missingImage", name)) fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16); if (fileName.isNull()) { GUniquePtr<gchar> imageName(g_strdup_printf("%s.png", name)); GUniquePtr<gchar> glibFileName(getPathToImageResource(imageName.get())); fileName = glibFileName.get(); } return loadImageFromFile(fileName); }
JSRetainPtr<JSStringRef> LayoutTestController::counterValueForElementById(JSStringRef id) { String idStr = jsStringRefToWebCoreString(id); WebCore::Element* coreElement = mainFrame->document()->getElementById(AtomicString(idStr)); if (!coreElement) return 0; CString counterValueStr = counterValueForElement(coreElement).utf8(); if (counterValueStr.isNull()) return 0; JSRetainPtr<JSStringRef> counterValue(Adopt, JSStringCreateWithUTF8CString(counterValueStr.data())); return counterValue; }
CString applicationDirectoryPath() { CString path = getCurrentExecutablePath(); if (!path.isNull()) return path; // If the above fails, check the PATH env variable. GUniquePtr<char> currentExePath(g_find_program_in_path(g_get_prgname())); if (!currentExePath.get()) return CString(); GUniquePtr<char> dirname(g_path_get_dirname(currentExePath.get())); return dirname.get(); }
PlatformFileHandle openFile(const String& path, FileOpenMode mode) { CString fsRep = fileSystemRepresentation(path); if (fsRep.isNull()) return invalidPlatformFileHandle; int platformFlag = 0; if (mode == OpenForRead) platformFlag |= O_RDONLY; else if (mode == OpenForWrite) platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); return open(fsRep.data(), platformFlag, 0666); }
static NPError copyCString(const CString& string, char** value, uint32_t* len) { ASSERT(!string.isNull()); ASSERT(value); ASSERT(len); *value = npnMemNewArray<char>(string.length()); if (!*value) return NPERR_GENERIC_ERROR; memcpy(*value, string.data(), string.length()); *len = string.length(); return NPERR_NO_ERROR; }
void ManSearchPath::Print() { printf("%s:\n", GetEnvVar()); CString sp(GetSearchPath()); if (!sp.isNull()) { CTokenizedString path (sp,Separator().data()); CString subpath = path.next(); while (!subpath.isNull()) { printf("\t%s\n",subpath.data()); subpath = path.next(); } printf("\n"); } }
PassRefPtr<Image> Image::loadPlatformResource(const char* name) { CString fileName; if (!strcmp("missingImage", name)) fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16); if (fileName.isNull()) { gchar* imagename = g_strdup_printf("%s.png", name); gchar* glibFileName = g_build_filename(DATA_DIR, "webkit-1.0", "images", imagename, 0); fileName = glibFileName; g_free(imagename); g_free(glibFileName); } return loadImageFromFile(fileName); }
TEST(CStringTest, NullStringConstructor) { CString string; EXPECT_TRUE(string.isNull()); EXPECT_EQ(static_cast<const char*>(0), string.data()); EXPECT_EQ(static_cast<size_t>(0), string.length()); CString stringFromCharPointer(static_cast<const char*>(0)); EXPECT_TRUE(stringFromCharPointer.isNull()); EXPECT_EQ(static_cast<const char*>(0), stringFromCharPointer.data()); EXPECT_EQ(static_cast<size_t>(0), stringFromCharPointer.length()); CString stringFromCharAndLength(static_cast<const char*>(0), 0); EXPECT_TRUE(stringFromCharAndLength.isNull()); EXPECT_EQ(static_cast<const char*>(0), stringFromCharAndLength.data()); EXPECT_EQ(static_cast<size_t>(0), stringFromCharAndLength.length()); }
PlatformFileHandle openFile(const String& path, FileOpenMode mode) { CString fsRep = fileSystemRepresentation(path); if (fsRep.isNull()) return invalidPlatformFileHandle; int platformFlag = 0; if (mode == FileOpenMode::Read) platformFlag |= O_RDONLY; else if (mode == FileOpenMode::Write) platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); #if OS(DARWIN) else if (mode == FileOpenMode::EventsOnly) platformFlag |= O_EVTONLY; #endif return open(fsRep.data(), platformFlag, 0666); }
CString sharedResourcesPath() { static CString cachedPath; if (!cachedPath.isNull()) return cachedPath; #if OS(WINDOWS) HMODULE hmodule = 0; GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<char*>(sharedResourcesPath), &hmodule); GUniquePtr<gchar> runtimeDir(g_win32_get_package_installation_directory_of_module(hmodule)); GUniquePtr<gchar> dataPath(g_build_filename(runtimeDir.get(), "share", "webkitgtk-" WEBKITGTK_API_VERSION_STRING, NULL)); #else GUniquePtr<gchar> dataPath(g_build_filename(DATA_DIR, "webkitgtk-" WEBKITGTK_API_VERSION_STRING, NULL)); #endif cachedPath = dataPath.get(); return cachedPath; }
void NetscapePluginStream::sendJavaScriptStream(const String& result) { // starting the stream or delivering the data to it might cause the plug-in stream to go away, so we keep // a reference to it here. Ref<NetscapePluginStream> protect(*this); CString resultCString = result.utf8(); if (resultCString.isNull()) { // There was an error evaluating the JavaScript, call NPP_URLNotify if needed and then destroy the stream. notifyAndDestroyStream(NPRES_NETWORK_ERR); return; } if (!start(m_requestURLString, resultCString.length(), 0, "text/plain", "")) return; deliverData(resultCString.data(), resultCString.length()); stop(NPRES_DONE); }
bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType) { // The page list contains an unformated list of pages that can be inspected with a link to open a session. if (path == "/pagelist.json") { buildPageList(data, contentType); return true; } // Point the default path to a formatted page that queries the page list and display them. CString localPath = WebCore::fileSystemRepresentation(inspectorServerFilesPath() + ((path == "/") ? "/inspectorPageIndex.html" : path)); if (localPath.isNull()) return false; GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(localPath.data())); GOwnPtr<GError> error; GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, 0, &error.outPtr())); if (!fileInfo) { StringBuilder builder; builder.appendLiteral("<!DOCTYPE html><html><head></head><body>Error: "); builder.appendNumber(error->code); builder.appendLiteral(", "); builder.append(error->message); builder.appendLiteral(" occurred during fetching webinspector resource files.<br>Make sure you ran make install or have set WEBKIT_INSPECTOR_SERVER_PATH in your environment to point to webinspector folder.</body></html>"); CString cstr = builder.toString().utf8(); data.append(cstr.data(), cstr.length()); contentType = "text/html; charset=utf-8"; g_warning("Error fetching webinspector resource files: %d, %s", error->code, error->message); return true; } GRefPtr<GFileInputStream> inputStream = adoptGRef(g_file_read(file.get(), 0, 0)); if (!inputStream) return false; data.grow(g_file_info_get_size(fileInfo.get())); if (!g_input_stream_read_all(G_INPUT_STREAM(inputStream.get()), data.data(), data.size(), 0, 0, 0)) return false; contentType = GOwnPtr<gchar>(g_file_info_get_attribute_as_string(fileInfo.get(), G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)).get(); return true; }
void System::unhandeledException(Exception& ex) { QDateTime dt = QDateTime::currentDateTime(); QString logfileName(QString("exception-%1.log").arg(dt.toTime_t())); CString bt = ex.getBacktrace(); QFile logfile(logfileName); logfile.open(QFile::WriteOnly); printf("%s\n%s\n", ex.what(), bt.get()); logfile.write("UNHANDELED EXCEPTION REPORT "); logfile.write(dt.toString(Qt::ISODate).toLocal8Bit().constData()); logfile.write(" gtatools version "); logfile.write(GTATOOLS_VERSION); logfile.write("\n\n"); logfile.write("Unhandeled exception caught:\n\n"); logfile.write(ex.what()); logfile.write("\n\nBacktrace:\n\n"); if (!bt.isNull()) { logfile.write(bt.get()); } else { logfile.write("[Backtrace not supported on this system]"); } logfile.flush(); QString exText = tr("Unhandeled Exception %1%2").arg(ex.what()).arg(logfileName); if (QThread::currentThread() == qApp->thread()) { QMessageBox::critical(NULL, tr("Unhandeled Exception"), exText); } else { fprintf(stderr, "### Unhandeled exception caught ###\n"); fprintf(stderr, "%s\n", exText.toLocal8Bit().constData()); } }
AppManagerDirectory::AppManagerDirectory ( CDEEnvironment * user, const CString & app ) : user_(user), langVersionFound(0), appsp_(app) { // Set the users Application Manager subdirectory CString userhostdir = user->UserHostDir(); if (userhostdir.isNull()) userhostdir = "generic-display-0"; // else if dir is non-NULL and there is a / in DTUSERSESSION, // dtappgather creates /var/dt/appconfig/appmanager/DTUSERSESSION. // This is a possible security hole, so // prevent creation of directories of the form // /var/dt/appconfig/appmanager/directory1/directory2 // else if ((char *)strstr(userhostdir.data(),"/")) userhostdir = "generic-display-0"; dirname_ = "/var/dt/appconfig/appmanager/"; dirname_ += userhostdir; if (user->OS()->isDirectory(dirname_) && 0 == user->OS()->isLink(dirname_)) { user->OS()->changeOwnerGroup(dirname_,"",""); user->OS()->changePermissions(dirname_,0755); #ifdef sun user->OS()->removeFiles(dirname_, ".~*"); #else user->OS()->removeFiles(dirname_, "[.]~*"); #endif user->OS()->removeDeadLinks(dirname_); if (!options->Retain()) #ifdef sun user->OS()->removeFiles(dirname_,"*"); #else user->OS()->removeFiles(dirname_,"[.]*"); #endif } else { // Make /var/dt/appconfig/appmanager directories if not present // // Make user session subdirectory under /var/dt/appconfig/appmanager CString dir(dirname_); dir.replace("/" + userhostdir,""); if (!user->OS()->isDirectory(dir)) { // does appmanager exist? dir.replace("/appmanager",""); if (!user->OS()->isDirectory(dir)) { // does appconfig exist? dir.replace("/appconfig",""); if (!user->OS()->isDirectory(dir)) { // does dt exist? dir.replace("/dt",""); if (!user->OS()->isDirectory(dir)) { // does /var exist? user->OS()->MakeDirectory(dir,0755); user->OS()->changeOwnerGroup(dir,"root","other"); user->OS()->changePermissions(dir,0755); } dir += "/dt"; user->OS()->MakeDirectory(dir,0755); user->OS()->changeOwnerGroup(dir,"root","other"); user->OS()->changePermissions(dir,0755); } dir += "/appconfig"; user->OS()->MakeDirectory(dir,0755); user->OS()->changeOwnerGroup(dir,"bin","bin"); user->OS()->changePermissions(dir,0755); } dir += "/appmanager"; user->OS()->MakeDirectory(dir,0755); user->OS()->changeOwnerGroup(dir,"bin","bin"); user->OS()->changePermissions(dir,0755); } user->OS()->MakeDirectory(dirname_,0755); user->OS()->changeOwnerGroup(dirname_,"",""); } // Make /var/dt/tmp directory if not present CString tmp("/var/dt/tmp/"); if (!user->OS()->isDirectory(tmp)) { // does tmp exist? user->OS()->MakeDirectory(tmp,0755); user->OS()->changeOwnerGroup(tmp,"root","other"); user->OS()->changePermissions(tmp,0755); } tmp += userhostdir; if (!user->OS()->isDirectory(tmp)) { // does tmp/$DTUSERSESSION exist? user->OS()->MakeDirectory(tmp, 0755); user->OS()->changeOwnerGroup(tmp,"",""); user->OS()->changePermissions(tmp,0755); } }
void initializeFontConfigSetting() { if (g_getenv("WEBKIT_SKIP_WEBKITTESTRUNNER_FONTCONFIG_INITIALIZATION")) return; FcInit(); // If a test resulted a font being added or removed via the @font-face rule, then // we want to reset the FontConfig configuration to prevent it from affecting other tests. static int numFonts = 0; FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); if (appFontSet && numFonts && appFontSet->nfont == numFonts) return; // Load our configuration file, which sets up proper aliases for family // names like sans, serif and monospace. FcConfig* config = FcConfigCreate(); GUniquePtr<gchar> fontConfigFilename(g_build_filename(FONTS_CONF_DIR, "fonts.conf", nullptr)); if (!g_file_test(fontConfigFilename.get(), G_FILE_TEST_IS_REGULAR)) g_error("Cannot find fonts.conf at %s\n", fontConfigFilename.get()); if (!FcConfigParseAndLoad(config, reinterpret_cast<FcChar8*>(fontConfigFilename.get()), true)) g_error("Couldn't load font configuration file from: %s", fontConfigFilename.get()); CString fontsPath = getFontsPath(); if (fontsPath.isNull()) g_error("Could not locate test fonts at %s. Is WEBKIT_TOP_LEVEL set?", fontsPath.data()); GUniquePtr<GDir> fontsDirectory(g_dir_open(fontsPath.data(), 0, nullptr)); while (const char* directoryEntry = g_dir_read_name(fontsDirectory.get())) { if (!g_str_has_suffix(directoryEntry, ".ttf") && !g_str_has_suffix(directoryEntry, ".otf")) continue; GUniquePtr<gchar> fontPath(g_build_filename(fontsPath.data(), directoryEntry, nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(fontPath.get()))) g_error("Could not load font at %s!", fontPath.get()); } // Ahem is used by many layout tests. GUniquePtr<gchar> ahemFontFilename(g_build_filename(FONTS_CONF_DIR, "AHEM____.TTF", nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(ahemFontFilename.get()))) g_error("Could not load font at %s!", ahemFontFilename.get()); static const char* fontFilenames[] = { "WebKitWeightWatcher100.ttf", "WebKitWeightWatcher200.ttf", "WebKitWeightWatcher300.ttf", "WebKitWeightWatcher400.ttf", "WebKitWeightWatcher500.ttf", "WebKitWeightWatcher600.ttf", "WebKitWeightWatcher700.ttf", "WebKitWeightWatcher800.ttf", "WebKitWeightWatcher900.ttf", 0 }; for (size_t i = 0; fontFilenames[i]; ++i) { GUniquePtr<gchar> fontFilename(g_build_filename(FONTS_CONF_DIR, "..", "..", "fonts", fontFilenames[i], nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontFilename.get()))) g_error("Could not load font at %s!", fontFilename.get()); } // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452 GUniquePtr<gchar> fontWithNoValidEncodingFilename(g_build_filename(FONTS_CONF_DIR, "FontWithNoValidEncoding.fon", nullptr)); if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontWithNoValidEncodingFilename.get()))) g_error("Could not load font at %s!", fontWithNoValidEncodingFilename.get()); if (!FcConfigSetCurrent(config)) g_error("Could not set the current font configuration!"); numFonts = FcConfigGetFonts(config, FcSetApplication)->nfont; }