示例#1
0
void MessageManager::loadUsers() {
    try {
        SimpleXML xml;
        SettingsManager::loadSettingFile(xml, CONFIG_DIR, CONFIG_NAME);
        auto cm = ClientManager::getInstance();
        if (xml.findChild("Ignored")) {
            xml.stepIn();
            xml.resetCurrentChild();
            if (xml.findChild("Users")) {
                xml.stepIn();
                while (xml.findChild("User")) {
                    UserPtr user = cm->getUser(CID(xml.getChildAttrib("CID")));
                    {
                        WLock(cm->getCS());
                        cm->addOfflineUser(user, xml.getChildAttrib("Nick"), xml.getChildAttrib("Hub"), (uint32_t)xml.getIntChildAttrib("LastSeen"));
                    }
                    WLock l(Ignorecs);
                    ignoredUsers.emplace(user);
                    user->setFlag(User::IGNORED);
                }
                xml.stepOut();
            }
            xml.stepOut();
        }
    }
    catch (const Exception& e) {
        LogManager::getInstance()->message(STRING_F(LOAD_FAILED_X, CONFIG_NAME % e.getError()), LogManager::LOG_ERROR);
    }
}
示例#2
0
string MappingManager::getStatus() const {
	if(working.get()) {
		auto& mapper = *working;
		return STRING_F(MAPPER_CREATING_SUCCESS, deviceString(mapper) % mapper.getName());
	}
	return STRING(MAPPER_CREATING_FAILED);
}
示例#3
0
void UpdateManager::updateGeo(bool v6) {
	auto& conn = conns[v6 ? CONN_GEO_V6 : CONN_GEO_V4];
	if(conn)
		return;

	LogManager::getInstance()->message(STRING_F(GEOIP_UPDATING, (v6 ? "IPv6" : "IPv4")), LogMessage::SEV_INFO);
	conn.reset(new HttpDownload(v6 ? links.geoip6 : links.geoip4,
		[this, v6] { completeGeoDownload(v6); }, false));
}
示例#4
0
LRESULT SystemFrame::onDeleteFile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	string path = Text::fromT(selWord);
	string msg = STRING_F(DELETE_FILE_CONFIRM, path);
	if(WinUtil::MessageBoxConfirm(SettingsManager::CONFIRM_FILE_DELETIONS, Text::toT(msg).c_str())) {
		MainFrame::getMainFrame()->addThreadedTask([=] { File::deleteFileEx(path, 3, !ShareManager::getInstance()->isRealPathShared(path)); });
	}

	ctrlPad.SetSelNone();
	return 0;
}
示例#5
0
	void QueueUtils::getBundleSourceInfo(const BundlePtr& aBundle, int& online_, int& total_, string& str_) noexcept {
		auto sources = QueueManager::getInstance()->getBundleSources(aBundle);
		for (const auto& s : sources) {
			if (s.getUser().user->isOnline())
				online_++;
		}

		total_ = sources.size();

		str_ = sources.size() == 0 ? STRING(NONE) : STRING_F(USERS_ONLINE, online_ % sources.size());
	}
示例#6
0
void UpdateManager::failVersionDownload(const string& aError, bool manualCheck) {
	auto msg = STRING_F(VERSION_CHECK_FAILED, aError);

	if (manualCheck) {
		LogManager::getInstance()->message(msg, LogMessage::SEV_ERROR);
		fire(UpdateManagerListener::UpdateFailed(), msg);
	} else {
		LogManager::getInstance()->message(msg, LogMessage::SEV_WARNING);
	}

	checkAdditionalUpdates(manualCheck);
}
示例#7
0
void UpdateManager::completeLanguageDownload() {
	auto& conn = conns[CONN_LANGUAGE_FILE];
	if(!conn) { return; }
	ScopedFunctor([&conn] { conn.reset(); });

	if(!conn->buf.empty()) {
		try {
			auto path = Localization::getCurLanguageFilePath();
			File::ensureDirectory(Util::getFilePath(path));
			File(path, File::WRITE, File::CREATE | File::TRUNCATE).write(conn->buf);
			LogManager::getInstance()->message(STRING_F(LANGUAGE_UPDATED, Localization::getLanguageStr()), LogMessage::SEV_INFO);
			fire(UpdateManagerListener::LanguageFinished());

			return;
		} catch(const FileException& e) { 
			LogManager::getInstance()->message(STRING_F(LANGUAGE_UPDATE_FAILED, Localization::getLanguageStr() % e.getError()), LogMessage::SEV_WARNING);
		}
	}

	fire(UpdateManagerListener::LanguageFailed(), conn->status);
	LogManager::getInstance()->message(STRING_F(LANGUAGE_UPDATE_FAILED, Localization::getLanguageStr() % conn->status), LogMessage::SEV_WARNING);
}
示例#8
0
void UpdateManager::completeSignatureDownload(bool manualCheck) {
	auto& conn = conns[CONN_SIGNATURE];
	ScopedFunctor([&conn] { conn.reset(); });

	if(conn->buf.empty()) {
		failVersionDownload(STRING_F(DOWNLOAD_SIGN_FAILED, conn->status), manualCheck);
	} else {
		versionSig.assign(conn->buf.begin(), conn->buf.end());
	}

	conns[CONN_VERSION].reset(new HttpDownload(getVersionUrl(),
		[this, manualCheck] { completeVersionDownload(manualCheck); }, false));
}
	string TrackableDownloadItem::formatRunningStatus() const noexcept {
		auto p = find_if(downloads | map_values, PathInfo::IsRunning());

		if (p.base() != downloads.end() && p->trackProgress()) {
			if (p->downloaded == -1) {
				return STRING(DOWNLOAD_STARTING);
			}

			return STRING_F(RUNNING_PCT, p->getDownloadedPercentage());
		}

		return "Downloading";
	}
示例#10
0
	bool operator()(boost::regex& r) const {
		try {
			if (wildCard) {
				r.assign(AirUtil::regexEscape(pattern, true), boost::regex::icase);
			} else {
				r.assign(pattern);
			}
			return true;
		} catch(const std::runtime_error&) {
			LogManager::getInstance()->message(STRING_F(INVALID_PATTERN, pattern), LogManager::LOG_ERROR);
			return false;
		}
	}
示例#11
0
int UDPServer::run() {
	uint8_t* buf = nullptr;
	int len;
	string remoteAddr;

	while(!stop) {
		try {
			if(!socket->wait(400, true, false).first) {
				continue;
			}

			buf = new uint8_t[BUFSIZE];
			if((len = socket->read(buf, BUFSIZE, remoteAddr)) > 0) {
				pp.queue.push(new PacketProcessor::PacketTask(buf, len, remoteAddr));
				pp.s.signal();
				continue;
			}

			delete buf;
		} catch(const SocketException& e) {
			dcdebug("SearchManager::run Error: %s\n", e.getError().c_str());
		}

		bool failed = false;
		while(!stop) {
			try {
				socket->disconnect();
				port = socket->listen(Util::toString(CONNSETTING(UDP_PORT)));
				if(failed) {
					LogManager::getInstance()->message("Search enabled again", LogManager::LOG_INFO);
					failed = false;
				}
				break;
			} catch(const SocketException& e) {
				dcdebug("SearchManager::run Stopped listening: %s\n", e.getError().c_str());

				if(!failed) {
					LogManager::getInstance()->message(STRING_F(SEARCH_DISABLED_X, e.getError()), LogManager::LOG_ERROR);
					failed = true;
				}

				// Spin for 60 seconds
				for(auto i = 0; i < 60 && !stop; ++i) {
					Thread::sleep(1000);
				}
			}
		}
	}

	return 0;
}
示例#12
0
void LogManager::log(const string& area, const string& msg) noexcept {
	tasks.addTask([=] {
		auto aArea = Util::validatePath(area);
		try {
			File::ensureDirectory(aArea);
			File f(aArea, File::WRITE, File::OPEN | File::CREATE);
			f.setEndPos(0);
			f.write(msg + "\r\n");
		} catch (const FileException& e) {
			// Just don't try to write the error into a file...
			message(STRING_F(WRITE_FAILED_X, aArea % e.what()), LogMessage::SEV_NOTIFY);
		}
	});
}
示例#13
0
void FinishedManager::on(UploadManagerListener::Complete, const Upload* u) noexcept
{
	if(u->getType() == Transfer::TYPE_FILE || (u->getType() == Transfer::TYPE_FULL_LIST && SETTING(LOG_FILELIST_TRANSFERS))) {
		FinishedItemPtr item = new FinishedItem(u->getPath(), u->getHintedUser(),	u->getFileSize(), static_cast<int64_t>(u->getAverageSpeed()), GET_TIME());
		{
			Lock l(cs);
			uploads.push_back(item);
		}

		fire(FinishedManagerListener::AddedUl(), item);
		if(SETTING(SYSTEM_SHOW_UPLOADS)) {
			LogManager::getInstance()->message(STRING_F(FINISHED_UPLOAD, u->getPath() % ClientManager::getInstance()->getFormatedNicks(u->getHintedUser())), LogMessage::SEV_INFO);		
		}
	}
}
示例#14
0
void LevelDB::checkDbError(leveldb::Status aStatus) throw(DbException) {
	if (aStatus.ok())
		return;

	if (aStatus.IsNotFound())
		return;

	string ret = Text::toUtf8(aStatus.ToString());

#ifdef _WIN32
	if (aStatus.IsCorruption() || aStatus.IsIOError()) {
		if (ret.back() != '.')
			ret += ".";
		ret += " " + STRING_F(DB_ERROR_HINT, STRING(HASHING));
	}
#endif

	throw DbException(ret);
}
示例#15
0
	void TransferApi::onTick(const Transfer* aTransfer, bool aIsDownload) noexcept {
		auto t = getTransfer(aTransfer->getToken());
		if (!t) {
			return;
		}

		t->setSpeed(aTransfer->getAverageSpeed());
		t->setBytesTransferred(aTransfer->getPos());
		t->setTimeLeft(aTransfer->getSecondsLeft());

		uint64_t timeSinceStarted = GET_TICK() - t->getStarted();
		if (timeSinceStarted < 1000) {
			t->setStatusString("Starting...");
		} else {
			t->setStatusString(STRING_F(RUNNING_PCT, t->getPercentage()));
		}

		view.onItemUpdated(t, { 
			TransferUtils::PROP_STATUS, TransferUtils::PROP_BYTES_TRANSFERRED, 
			TransferUtils::PROP_SPEED, TransferUtils::PROP_SECONDS_LEFT
		});
	}
示例#16
0
int MappingManager::run() {
	ScopedFunctor([this] { busy.clear(); });

	// cache ports
	auto
		conn_port = ConnectionManager::getInstance()->getPort(),
		secure_port = ConnectionManager::getInstance()->getSecurePort(),
		search_port = SearchManager::getInstance()->getPort();

	if(renewal) {
		Mapper& mapper = *working;

		ScopedFunctor([&mapper] { mapper.uninit(); });
		if(!mapper.init()) {
			// can't renew; try again later.
			renewLater(mapper);
			return 0;
		}

		auto addRule = [this, &mapper](const string& port, Mapper::Protocol protocol, const string& description) {
			// just launch renewal requests - don't bother with possible failures.
			if(!port.empty()) {
				mapper.open(port, protocol, STRING_F(MAPPER_X_PORT_X,
					description % port % Mapper::protocols[protocol]));
			}
		};

		addRule(conn_port, Mapper::PROTOCOL_TCP, "Transfer");
		addRule(secure_port, Mapper::PROTOCOL_TCP, "Encrypted transfer");
		addRule(search_port, Mapper::PROTOCOL_UDP, "Search");

		renewLater(mapper);
		return 0;
	}

	// move the preferred mapper to the top of the stack.
	const auto& mapperName = SETTING(MAPPER);
	for(auto i = mappers.begin(); i != mappers.end(); ++i) {
		if(i->first == mapperName) {
			if(i != mappers.begin()) {
				auto mapper = *i;
				mappers.erase(i);
				mappers.insert(mappers.begin(), mapper);
			}
			break;
		}
	}

	for(auto& i: mappers) {
		auto setting = v6 ? SettingsManager::BIND_ADDRESS6 : SettingsManager::BIND_ADDRESS;
		unique_ptr<Mapper> pMapper(i.second((SettingsManager::getInstance()->isDefault(setting) ? Util::emptyString : SettingsManager::getInstance()->get(setting)), v6));
		Mapper& mapper = *pMapper;

		ScopedFunctor([&mapper] { mapper.uninit(); });
		if(!mapper.init()) {
			log(STRING_F(MAPPER_INIT_FAILED, mapper.getName()), LogMessage::SEV_WARNING);
			continue;
		}

		auto addRule = [this, &mapper](const string& port, Mapper::Protocol protocol, const string& description) -> bool {
			if (!port.empty() && !mapper.open(port, protocol, STRING_F(MAPPER_X_PORT_X, APPNAME % description % port % Mapper::protocols[protocol]))) {
				this->log(STRING_F(MAPPER_INTERFACE_FAILED, description % port % Mapper::protocols[protocol] % mapper.getName()), LogMessage::SEV_WARNING);
				mapper.close();
				return false;
			}
			return true;
		};

		if(!(addRule(conn_port, Mapper::PROTOCOL_TCP, STRING(TRANSFER)) &&
			addRule(secure_port, Mapper::PROTOCOL_TCP, STRING(ENCRYPTED_TRANSFER)) &&
			addRule(search_port, Mapper::PROTOCOL_UDP, STRING(SEARCH))))
			continue;

		log(STRING_F(MAPPER_CREATING_SUCCESS_LONG, conn_port % secure_port % search_port % deviceString(mapper) % mapper.getName()), LogMessage::SEV_INFO);

		working = move(pMapper);

		if ((!v6 && !CONNSETTING(NO_IP_OVERRIDE)) || (v6 && !CONNSETTING(NO_IP_OVERRIDE6))) {
			setting = v6 ? SettingsManager::EXTERNAL_IP6 : SettingsManager::EXTERNAL_IP;
			string externalIP = mapper.getExternalIP();
			if(!externalIP.empty()) {
				ConnectivityManager::getInstance()->set(setting, externalIP);
			} else {
				// no cleanup because the mappings work and hubs will likely provide the correct IP.
				log(STRING(MAPPER_IP_FAILED), LogMessage::SEV_WARNING);
			}
		}

		ConnectivityManager::getInstance()->mappingFinished(mapper.getName(), v6);

		renewLater(mapper);
		break;
	}

	if(!getOpened()) {
		log(STRING(MAPPER_CREATING_FAILED), LogMessage::SEV_ERROR);
		ConnectivityManager::getInstance()->mappingFinished(Util::emptyString, v6);
	}

	return 0;
}
示例#17
0
void UpdateManager::completeVersionDownload(bool manualCheck) {
	auto& conn = conns[CONN_VERSION];
	if(!conn) { return; }
	ScopedFunctor([&conn] { conn.reset(); });

	if (conn->buf.empty()) {
		failVersionDownload(STRING_F(DOWNLOAD_VERSION_FAILED, conn->status), manualCheck);
		return; 
	}

	bool verified = !versionSig.empty() && UpdateManager::verifyVersionData(conn->buf, versionSig);
	if(!verified) {
		failVersionDownload(STRING(VERSION_VERIFY_FAILED), manualCheck);
	}

	try {
		SimpleXML xml;
		xml.fromXML(conn->buf);
		xml.stepIn();


		//Check for updated HTTP links
		if(xml.findChild("Links")) {
			xml.stepIn();
			if(xml.findChild("Homepage")) {
				links.homepage = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("Downloads")) {
				links.downloads = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("GeoIPv6")) {
				links.geoip6 = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("GeoIPv4")) {
				links.geoip4 = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("Customize")) {
				links.customize = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("Forum")) {
				links.discuss = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("Languages")) {
				links.language = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("Guides")) {
				links.guides = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("IPCheck")) {
				links.ipcheck4 = xml.getChildData();
			}
			xml.resetCurrentChild();
			if(xml.findChild("IPCheck6")) {
				links.ipcheck6 = xml.getChildData();
			}
			xml.stepOut();
		}
		xml.resetCurrentChild();

		updater->onVersionDownloaded(xml, verified, manualCheck);
	} catch (const Exception& e) {
		failVersionDownload(STRING_F(VERSION_PARSING_FAILED, e.getError()), manualCheck);
	}

	checkAdditionalUpdates(manualCheck);
}
示例#18
0
string DirectoryMonitor::Server::getErrorStr(int error) {
	return STRING_F(ERROR_CODE_X, Util::translateError(error) % error);
}
void ConnectivityManager::detectConnection() {
	if(isRunning())
		return;

	bool detectV4 = false;
	if (SETTING(AUTO_DETECT_CONNECTION) && SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DISABLED) {
		detectV4 = true;
		runningV4 = true;
	}

	bool detectV6 = false;
	if (SETTING(AUTO_DETECT_CONNECTION6) && SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_DISABLED) {
		detectV6 = true;
		runningV6 = true;
	}

	if (detectV4) {
		statusV4.clear();
		fire(ConnectivityManagerListener::Started(), false);
	}

	if (detectV6) {
		statusV6.clear();
		fire(ConnectivityManagerListener::Started(), true);
	}

	if(detectV4 && mapperV4.getOpened()) {
		mapperV4.close();
	}

	if(detectV4 && mapperV6.getOpened()) {
		mapperV6.close();
	}

	disconnect();

	// restore auto settings to their default value.
	if (detectV6)
		clearAutoSettings(true, true);
	if (detectV4)
		clearAutoSettings(false, true);

	log(STRING(CONN_DETERMINING), LogManager::LOG_INFO, TYPE_BOTH);

	/*if (runningV4)
		log(STRING(CONN_DETERMINING), LogManager::LOG_INFO, false);
	if (runningV6)
		log(STRING(CONN_DETERMINING), LogManager::LOG_INFO, true);*/

	try {
		listen();
	} catch(const Exception& e) {
		{
			WLock l(cs);
			autoSettings[SettingsManager::INCOMING_CONNECTIONS] = SettingsManager::INCOMING_PASSIVE;
			autoSettings[SettingsManager::INCOMING_CONNECTIONS6] = SettingsManager::INCOMING_PASSIVE;
		}

		log(STRING_F(CONN_PORT_X_FAILED, e.getError()), LogManager::LOG_ERROR, TYPE_NORMAL);
		fire(ConnectivityManagerListener::Finished(), false, true);
		fire(ConnectivityManagerListener::Finished(), true, true);
		if (detectV4)
			runningV4 = false;
		if (detectV6)
			runningV6 = false;
		return;
	}

	autoDetectedV4 = detectV4;
	autoDetectedV6 = detectV6;

	if(detectV4 && !AirUtil::getLocalIp(false, false).empty()) {
		{
			WLock l(cs);
			autoSettings[SettingsManager::INCOMING_CONNECTIONS] = SettingsManager::INCOMING_ACTIVE;
		}

		log(STRING(CONN_DIRECT_DETECTED), LogManager::LOG_INFO, TYPE_V4);
		fire(ConnectivityManagerListener::Finished(), false, false);
		runningV4 = false;
		detectV4 = false;
	}

	if(detectV6) {
		if (!AirUtil::getLocalIp(true, false).empty()) {
			{
				WLock l(cs);
				autoSettings[SettingsManager::INCOMING_CONNECTIONS6] = SettingsManager::INCOMING_ACTIVE;
			}

			log(STRING(CONN_DIRECT_DETECTED), LogManager::LOG_INFO, TYPE_V6);
		} else {
			//disable IPv6 if no public IP address is available
			{
				WLock l(cs);
				autoSettings[SettingsManager::INCOMING_CONNECTIONS6] = SettingsManager::INCOMING_DISABLED;
			}
			log(STRING(IPV6_NO_PUBLIC_IP), LogManager::LOG_INFO, TYPE_V6);
		}

		fire(ConnectivityManagerListener::Finished(), true, false);
		runningV6 = false;
		detectV6 = false;
	}

	if (!detectV6 && !detectV4)
		return;

	if (detectV4) {
		WLock l(cs);
		autoSettings[SettingsManager::INCOMING_CONNECTIONS] = SettingsManager::INCOMING_ACTIVE_UPNP;
	}

	if (detectV6) {
		WLock l(cs);
		autoSettings[SettingsManager::INCOMING_CONNECTIONS6] = SettingsManager::INCOMING_ACTIVE_UPNP;
	}

	log(STRING(CONN_NAT_DETECTED), LogManager::LOG_INFO, (detectV4 && detectV6 ? TYPE_BOTH : detectV4 ? TYPE_V4 : TYPE_V6));

	if (detectV6)
		startMapping(true);
	if (detectV4)
		startMapping(false);
}