void Config::handleCmdLine() { // at this point opts_ should be populated with command line options if (opts_.count(OPT_HELP_ONLYLONG)) { help_ = true; ok_ = true; std::cout << optdesc_ << std::endl; } else if (opts_.count(OPT_VERSION_ONLYLONG)) { version_ = true; ok_ = true; } else { // extract options values try { if (opts_.count(OPT_PID_ONLYLONG)) { pidfile_ = expandTilde(opts_[OPT_PID_ONLYLONG].as<std::string>()); pidfile_set_ = true; } if (opts_.count(OPT_LOG_ONLYLONG)) { getLogFromChar(opts_[OPT_LOG_ONLYLONG].as<char>()); } if (opts_.count(OPT_LOG_FILE_ONLYLONG)) { logfile_ = expandTilde(opts_[OPT_LOG_FILE_ONLYLONG].as<std::string>()); logfile_set_ = true; } if (opts_.count(OPT_CONFIG_ONLYLONG)) { config_file_ = opts_[OPT_CONFIG_ONLYLONG].as<std::string>(); config_file_set_ = true; } if (opts_.count(OPT_MODE_ONLYLONG)) { getModeFromString(opts_[OPT_MODE_ONLYLONG].as<std::string>()); } if (opts_.count(OPT_FOREGROUND_ONLYLONG)) { foreground_ = true; } ok_ = true; } catch(std::exception &e) { error_ = e.what(); } } }
void initForbidden(void) { redirectorKill(); if(forbiddenFile) forbiddenFile = expandTilde(forbiddenFile); if(forbiddenFile == NULL) { forbiddenFile = expandTilde(internAtom("~/.polipo-forbidden")); if(forbiddenFile) { if(access(forbiddenFile->string, F_OK) < 0) { releaseAtom(forbiddenFile); forbiddenFile = NULL; } } } if(forbiddenFile == NULL) { if(access("/etc/polipo/forbidden", F_OK) >= 0) forbiddenFile = internAtom("/etc/polipo/forbidden"); } parseDomainFile(forbiddenFile, &forbiddenDomains, &forbiddenRegex); if(uncachableFile) uncachableFile = expandTilde(uncachableFile); if(uncachableFile == NULL) { uncachableFile = expandTilde(internAtom("~/.polipo-uncachable")); if(uncachableFile) { if(access(uncachableFile->string, F_OK) < 0) { releaseAtom(uncachableFile); uncachableFile = NULL; } } } if(uncachableFile == NULL) { if(access("/etc/polipo/uncachable", F_OK) >= 0) uncachableFile = internAtom("/etc/polipo/uncachable"); } parseDomainFile(uncachableFile, &uncachableDomains, &uncachableRegex); return; }
void KURLCompletion::adjustMatch(QString &match) const { if(match.at(match.length() - 1) != '/') { QString copy; if(match.startsWith(QString("file:"))) copy = KURL(match).path(); else copy = match; expandTilde(copy); expandEnv(copy); if(QDir::isRelativePath(copy)) copy.prepend(d->cwd + '/'); // kdDebug() << "postProcess: stating " << copy << endl; KDE_struct_stat sbuff; QCString file = QFile::encodeName(copy); if(KDE_stat((const char *)file, &sbuff) == 0) { if(S_ISDIR(sbuff.st_mode)) match.append('/'); } else { kdDebug() << "Could not stat file " << copy << endl; } } }
void KNewFileMenuPrivate::executeStrategy() { m_tempFileToDelete = m_copyData.tempFileToDelete(); const QString src = m_copyData.sourceFileToCopy(); QString chosenFileName = expandTilde(m_copyData.chosenFileName(), true); if (src.isEmpty()) return; KUrl uSrc(src); if (uSrc.isLocalFile()) { // In case the templates/.source directory contains symlinks, resolve // them to the target files. Fixes bug #149628. KFileItem item(uSrc, QString(), KFileItem::Unknown); if (item.isLink()) uSrc.setPath(item.linkDest()); if (!m_copyData.m_isSymlink) { // If the file is not going to be detected as a desktop file, due to a // known extension (e.g. ".pl"), append ".desktop". #224142. QFile srcFile(uSrc.toLocalFile()); if (srcFile.open(QIODevice::ReadOnly)) { KMimeType::Ptr wantedMime = KMimeType::findByUrl(uSrc); KMimeType::Ptr mime = KMimeType::findByNameAndContent(m_copyData.m_chosenFileName, srcFile.read(1024)); //kDebug() << "mime=" << mime->name() << "wantedMime=" << wantedMime->name(); if (!mime->is(wantedMime->name())) chosenFileName += wantedMime->mainExtension(); } } } // The template is not a desktop file [or it's a URL one] // Copy it. KUrl::List::const_iterator it = m_popupFiles.constBegin(); for (; it != m_popupFiles.constEnd(); ++it) { KUrl dest(*it); dest.addPath(KIO::encodeFileName(chosenFileName)); KUrl::List lstSrc; lstSrc.append(uSrc); KIO::Job* kjob; if (m_copyData.m_isSymlink) { kjob = KIO::symlink(src, dest); // This doesn't work, FileUndoManager registers new links in copyingLinkDone, // which KIO::symlink obviously doesn't emit... Needs code in FileUndoManager. //KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Link, lstSrc, dest, kjob); } else { //kDebug(1203) << "KIO::copyAs(" << uSrc.url() << "," << dest.url() << ")"; KIO::CopyJob * job = KIO::copyAs(uSrc, dest); job->setDefaultPermissions(true); kjob = job; KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Copy, lstSrc, dest, job); } kjob->ui()->setWindow(m_parentWidget); QObject::connect(kjob, SIGNAL(result(KJob*)), q, SLOT(slotResult(KJob*))); } }
void KURLCompletion::MyURL::filter(bool replace_user_dir, bool replace_env) { QString d = dir() + file(); if(replace_user_dir) expandTilde(d); if(replace_env) expandEnv(d); m_kurl->setPath(d); }
PUBLIC char* (CSCfileExpandPath) ( const char* const path, const size_t pathMax, CSCmemListType const memList, int memTag ) { char* dstPtr = NULL; char* tmpPtr = NULL; char* srcPtr = (char*)path; size_t index; ASSERT_RTN (path != NULL, "CSCfileExpandPath: NULL path", NULL); ASSERT_RTN (pathMax > 0, "CSCfileExpandPath: no pathMax", NULL); ASSERT_RTN (memList != NULL, "CSCfileExpandPath: NULL memList", NULL); ASSERT (sizeof(ptrdiff_t) <= sizeof(size_t)); /* note #1 */ if ((path == NULL) || (pathMax == 0) || (memList == NULL)) return (NULL); if (CSCmemAlloc(memList,(void**)&dstPtr,1,pathMax+1,memTag) == CSC_OK) { (void)memset (dstPtr, '\0', pathMax+1); tmpPtr = expandTilde (dstPtr, &srcPtr, pathMax); if (tmpPtr != NULL) index = (size_t)(tmpPtr - dstPtr); /* note #1 */ else { index = (size_t)pathMax + 1; } while ((*srcPtr != '\0') && (index <= pathMax)) { while ((*srcPtr != '$') && (*srcPtr != '\0') && (index++ <= pathMax)) { *tmpPtr++ = *srcPtr++; } if (*srcPtr == '$') { tmpPtr = expandEnv (tmpPtr, &srcPtr, pathMax-index); index = (size_t)(tmpPtr - dstPtr); /* note #1 */ } } *tmpPtr = '\0'; if (*srcPtr != '\0') { (void)CSCmemFree (memList, (void**)&dstPtr, memTag); dstPtr = NULL; } } return (dstPtr); }
static struct slName *parsePath(char *path) /* Convert : separated path into a name list. */ { struct slName *list = NULL; char *dupe = cloneString(path); char *s, *e; for (s = dupe; s != NULL && s[0] != 0; s = e) { e = strchr(s, ':'); if (e != NULL) *e++ = 0; slNameAddTail(&list, expandTilde(s)); } freeMem(dupe); return list; }
void KNewFileMenuPrivate::executeStrategy() { m_tempFileToDelete = m_strategy.tempFileToDelete(); const QString src = m_strategy.sourceFileToCopy(); QString chosenFileName = expandTilde(m_strategy.chosenFileName(), true); if (src.isEmpty()) return; KUrl uSrc(src); if (uSrc.isLocalFile()) { // In case the templates/.source directory contains symlinks, resolve // them to the target files. Fixes bug #149628. KFileItem item(uSrc, QString(), KFileItem::Unknown); if (item.isLink()) uSrc.setPath(item.linkDest()); } // The template is not a desktop file [or it's a URL one] // Copy it. KUrl::List::const_iterator it = m_popupFiles.constBegin(); for (; it != m_popupFiles.constEnd(); ++it) { KUrl dest(*it); dest.addPath(KIO::encodeFileName(chosenFileName)); KUrl::List lstSrc; lstSrc.append(uSrc); KIO::Job* kjob; if (m_strategy.m_isSymlink) { kjob = KIO::symlink(src, dest); // This doesn't work, FileUndoManager registers new links in copyingLinkDone, // which KIO::symlink obviously doesn't emit... Needs code in FileUndoManager. //KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Link, lstSrc, dest, kjob); } else { //kDebug(1203) << "KIO::copyAs(" << uSrc.url() << "," << dest.url() << ")"; KIO::CopyJob * job = KIO::copyAs(uSrc, dest); job->setDefaultPermissions(true); kjob = job; KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Copy, lstSrc, dest, job); } kjob->ui()->setWindow(m_parentWidget); QObject::connect(kjob, SIGNAL(result(KJob*)), q, SLOT(slotResult(KJob*))); } }
int main(int argc, char **argv) { FdEventHandlerPtr listener; int i; int rc; int expire = 0, printConfig = 0; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); preinitOffline(); i = 1; while(i < argc) { if(argv[i][0] != '-') break; if(strcmp(argv[i], "--") == 0) { i++; break; } else if(strcmp(argv[i], "-h") == 0) { usage(argv[0]); exit(0); } else if(strcmp(argv[i], "-v") == 0) { printConfig = 1; i++; } else if(strcmp(argv[i], "-x") == 0) { expire = 1; i++; } else if(strcmp(argv[i], "-c") == 0) { i++; if(i >= argc) { usage(argv[0]); exit(1); } if(configFile) releaseAtom(configFile); configFile = internAtom(argv[i]); i++; } else { usage(argv[0]); exit(1); } } if(configFile) configFile = expandTilde(configFile); if(configFile == NULL) { configFile = expandTilde(internAtom("~/.polipo")); if(configFile) if(access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } if(configFile == NULL) { if(access("/etc/polipo/config", F_OK) >= 0) configFile = internAtom("/etc/polipo/config"); if(configFile && access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } rc = parseConfigFile(configFile); if(rc < 0) exit(1); while(i < argc) { rc = parseConfigLine(argv[i], "command line", 0, 0); if(rc < 0) exit(1); i++; } initChunks(); initLog(); initObject(); if(!expire && !printConfig) initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); initOffline(); if(printConfig) { printConfigVariables(stdout, 0); exit(0); } if(expire) { expireDiskObjects(); exit(0); } if(daemonise) do_daemonise(logFile == NULL || logFile->length == 0); if(pidFile) writePid(pidFile->string); listener = create_listener(proxyAddress->string, proxyPort, httpAccept, NULL); if(!listener) { if(pidFile) unlink(pidFile->string); exit(1); } eventLoop(); if(pidFile) unlink(pidFile->string); return 0; }
Config::Config() : optdesc_("Command line options"), help_(false), version_(false), ok_(false), loglevel_set_(false), pidfile_set_(false), loglevel_(DEF_LOGLEVEL), logfile_set_(false), config_file_(DEF_CONFIGFILE), config_file_set_(false), opmode_(OpMode::STANDALONE), opmode_set_(false), foreground_(false), pollTimeout_(DEF_POLL_TIMEOUT), connTimeout_(DEF_CONN_TIMEOUT), disconnectTimeout_(DEF_DISCONNECT_TIMEOUT), ledTimeout_(DEF_LED_UPDATE_TIMEOUT), moveThreshold_(DEF_MOVE_THRESHOLD), gestureThreshold_(DEF_GESTURE_THRESHOLD), gestureTimeout_(DEF_GESTURE_TIMEOUT) { // default pid file location pidfile_ = expandTilde(DEF_PIDFILE); // default log file location logfile_ = expandTilde(DEF_LOGFILE); // command line options description optdesc_.add_options() (OPT_HELP, OPT_HELP_DESC) (OPT_VERSION, OPT_VERSION_DESC) (OPT_PID, po::value<std::string>(), OPT_PID_DESC) (OPT_LOG, po::value<char>(), OPT_LOG_DESC) (OPT_LOG_FILE, po::value<std::string>(), OPT_LOG_FILE_DESC) (OPT_CONFIG, po::value<std::string>(), OPT_CONFIG_DESC) (OPT_MODE, po::value<std::string>(), OPT_MODE_DESC) (OPT_FOREGROUND, OPT_FOREGROUND_DESC); // config file options description configdesc_.add_options() (OPT_CONF_PID, po::value<std::string>()) (OPT_CONF_LOG, po::value<char>()) (OPT_CONF_LOG_FILE, po::value<std::string>()) (OPT_MOVEC_X, po::value<double>()) (OPT_MOVEC_Y, po::value<double>()) (OPT_PSBTN_TRIANGLE, po::value<std::string>()) (OPT_PSBTN_CIRCLE, po::value<std::string>()) (OPT_PSBTN_CROSS, po::value<std::string>()) (OPT_PSBTN_SQUARE, po::value<std::string>()) (OPT_PSBTN_SELECT, po::value<std::string>()) (OPT_PSBTN_START, po::value<std::string>()) (OPT_PSBTN_PS, po::value<std::string>()) (OPT_PSBTN_MOVE, po::value<std::string>()) (OPT_PSBTN_T, po::value<std::string>()) (OPT_PSBTN_1_TRIANGLE, po::value<std::string>()) (OPT_PSBTN_1_CIRCLE, po::value<std::string>()) (OPT_PSBTN_1_CROSS, po::value<std::string>()) (OPT_PSBTN_1_SQUARE, po::value<std::string>()) (OPT_PSBTN_1_SELECT, po::value<std::string>()) (OPT_PSBTN_1_START, po::value<std::string>()) (OPT_PSBTN_1_PS, po::value<std::string>()) (OPT_PSBTN_1_MOVE, po::value<std::string>()) (OPT_PSBTN_1_T, po::value<std::string>()) (OPT_CONF_MODE, po::value<std::string>()) (OPT_CONF_POLL_TIMEOUT, po::value<int>()) (OPT_CONF_CONN_TIMEOUT, po::value<int>()) (OPT_CONF_DISCONNECT_TIMEOUT, po::value<int>()) (OPT_CONF_LED_UPDATE_TIMEOUT, po::value<int>()) (OPT_CONF_MOVE_THRESHOLD, po::value<int>()) (OPT_GESTURE_UP, po::value<std::string>()) (OPT_GESTURE_DOWN, po::value<std::string>()) (OPT_GESTURE_LEFT, po::value<std::string>()) (OPT_GESTURE_RIGHT, po::value<std::string>()) (OPT_CONF_GESTURE_THRESHOLD, po::value<int>()) (OPT_CONF_GESTURE_TIMEOUT, po::value<int>()); }
void Config::parseConfig() { if (configFileOK() == false) { return; } try { po::store(po::parse_config_file<char>(config_file_.c_str(), configdesc_), conf_opts_); po::notify(conf_opts_); // store pidfile, logfile and log level, but don't override command line values if (conf_opts_.count(OPT_CONF_PID) && !pidfile_set_) { pidfile_ = expandTilde(conf_opts_[OPT_CONF_PID].as<std::string>()); pidfile_set_ = true; } if (conf_opts_.count(OPT_CONF_LOG) && !loglevel_set_) { getLogFromChar(conf_opts_[OPT_CONF_LOG].as<char>()); } if (conf_opts_.count(OPT_CONF_LOG_FILE) && !logfile_set_) { logfile_ = expandTilde(conf_opts_[OPT_CONF_LOG_FILE].as<std::string>()); logfile_set_ = true; } // store move coefficients if (conf_opts_.count(OPT_MOVEC_X)) { coeffs_.cx = conf_opts_[OPT_MOVEC_X].as<double>(); } if (conf_opts_.count(OPT_MOVEC_Y)) { coeffs_.cy = conf_opts_[OPT_MOVEC_Y].as<double>(); } if (conf_opts_.count(OPT_CONF_MODE) && !opmode_set_) { getModeFromString(conf_opts_[OPT_CONF_MODE].as<std::string>()); } // store timeouts if (conf_opts_.count(OPT_CONF_POLL_TIMEOUT)) { pollTimeout_= conf_opts_[OPT_CONF_POLL_TIMEOUT].as<int>(); } if (conf_opts_.count(OPT_CONF_CONN_TIMEOUT)) { connTimeout_= conf_opts_[OPT_CONF_CONN_TIMEOUT].as<int>(); } if (conf_opts_.count(OPT_CONF_DISCONNECT_TIMEOUT)) { disconnectTimeout_= conf_opts_[OPT_CONF_DISCONNECT_TIMEOUT].as<int>(); } if (conf_opts_.count(OPT_CONF_LED_UPDATE_TIMEOUT)) { ledTimeout_= conf_opts_[OPT_CONF_LED_UPDATE_TIMEOUT].as<int>(); } if (conf_opts_.count(OPT_CONF_GESTURE_TIMEOUT)) { gestureTimeout_ = conf_opts_[OPT_CONF_GESTURE_TIMEOUT].as<int>(); } // store move threshold if (conf_opts_.count(OPT_CONF_MOVE_THRESHOLD)) { moveThreshold_= conf_opts_[OPT_CONF_MOVE_THRESHOLD].as<int>(); } // store gesture threshold if (conf_opts_.count(OPT_CONF_GESTURE_THRESHOLD)) { gestureThreshold_= conf_opts_[OPT_CONF_GESTURE_THRESHOLD].as<int>(); } // add key map entries one by one const std::vector<boost::shared_ptr<po::option_description>> &opts = configdesc_.options(); for (boost::shared_ptr<po::option_description> opt : opts) { const std::string &longname = opt->long_name(); // filter out non-key options if ( (longname != OPT_CONF_PID) && (longname != OPT_CONF_LOG) && (longname != OPT_CONF_LOG_FILE) && (longname != OPT_MOVEC_X) && (longname != OPT_MOVEC_Y) && (longname != OPT_CONF_MODE) && (longname != OPT_CONF_POLL_TIMEOUT) && (longname != OPT_CONF_CONN_TIMEOUT) && (longname != OPT_CONF_DISCONNECT_TIMEOUT) && (longname != OPT_CONF_LED_UPDATE_TIMEOUT) && (longname != OPT_CONF_MOVE_THRESHOLD) && (longname != OPT_CONF_GESTURE_THRESHOLD) && (longname != OPT_CONF_GESTURE_TIMEOUT) && conf_opts_.count(longname) ) { KeyMapEntry entry; entry = keymap_parser_.createEntry(longname, conf_opts_[longname].as<std::string>()); if ((entry.pscode != 0) && (entry.lincode != KEY_RESERVED)) { if ((longname == OPT_PSBTN_TRIANGLE) || (longname == OPT_PSBTN_CIRCLE) || (longname == OPT_PSBTN_CROSS) || (longname == OPT_PSBTN_SQUARE) || (longname == OPT_PSBTN_SELECT) || (longname == OPT_PSBTN_START) || (longname == OPT_PSBTN_PS) || (longname == OPT_PSBTN_MOVE) || (longname == OPT_PSBTN_T)) { // first controller keymaps_[0].push_back(entry); } // gesture options go to the second controller map else { // second controller keymaps_[1].push_back(entry); } } else { // invalid key map entry ok_ = false; break; } } } } catch(boost::bad_any_cast &e) { error_ = e.what(); ok_ = false; } catch (std::exception &e) { error_ = e.what(); ok_ = false; } }
char * cleanInput( char * in ) { return expandTilde( expandEnv( removeQuotes( in ) ) ); }