Beispiel #1
0
void Network::BoostClient::OnBulletHit( unsigned long ip, const PACKAGE& p )
{
	std::cout << "OnBulletHit\n";
	// 获取炮弹类型
	BulletHittedBag* bag = (BulletHittedBag*)p.GetData();

	if ( bag->target_index == m_index )
	{
		auto pEngine = MyIrrlichtEngine::GetEngine();
		if ( pEngine->GetCurrentPlayer()->GetShip()->GetShield() <= 0
			&& pEngine->GetCurrentPlayer()->GetShip()->GetArmor() <= 0 )
		{
			// 自己挂了
			pEngine->GetCurrentPlayer()->SetState( IPlayer::PS_Dead );

			// 通知别人自己挂了
			ScoreArrivalBag score;
			score.ip = 0;
			score.KillCount = pEngine->GetCurrentPlayer()->GetKill();
			score.DeathCount = pEngine->GetCurrentPlayer()->GetDeath();

			PACKAGE pack;
			pack.SetCMD( SCORE_ARRIVAL );			
			pack.SetData( (char*)&score, sizeof( BulletCreateBag ) );			

			TcpSendTo( m_server_IP, m_target_port, pack );
			//m_network->SendTo( m_server_IP, pack );
		}
	}

	// 判断击中目标是否有效
	if ( 0 <= bag->target_index && bag->target_index < 100 )
	{
		ISceneManager* smgr = MyIrrlichtEngine::GetEngine()->GetSceneManager();

		smgr->getSceneNodeFromId( bag->owner_index );

		// 获取命中的节点
		ISceneNode* target_node = smgr->getSceneNodeFromId( bag->target_index );

		IShip* ship = dynamic_cast<IShip*>( target_node );
		if ( ship )
		{
			ship->SetArmor( (f32)bag->armor );
			ship->SetShield( (f32)bag->shield );
		}
		//int damage;
		//// 炮弹
		//if ( bag->bullet_type == 0 )
		//{
		//	damage = 10;
		//}
		//// 导弹
		//else if ( bag->bullet_type == 1 )
		//{
		//	damage = 100;
		//}

	}
}
Beispiel #2
0
	DWORD WINAPI ThreadProc(LPVOID lpParameter)		//接收数据包线程函数
	{
		ThreadParam* param = (ThreadParam*) lpParameter;
		SOCKET s = param->m_s;
		OnMsgComeEvent callback =  param->m_fun;
			
		delete param;
		
		PACKAGE package;

		SOCKADDR_IN addrClient;
		int len=sizeof(SOCKADDR);

		int revlength = 0;
		int length;
		
		int recvlen = 0;

		while (true)
		{
			int recvlen = recvfrom(s, package.Getdata(0),sizeof(PACKAGE), 0, (SOCKADDR*)&addrClient, &len);	//接收包中的前四个字节 得到包长度		
			
			if (recvlen == package.GetLength())		//接收到一个包	UDP不会粘包
			{
				callback(addrClient.sin_addr.S_un.S_addr, package);
			}
		}
		return 0;
	}
Beispiel #3
0
void Network::BoostClient::EnterRoom( const std::string& ip )
{
	PACKAGE pack;
	pack.SetCMD( REQUEST_ENTER_ROOM );
	RequestEnterRoomBag bag;
	wcscpy( bag.shipname, MyIrrlichtEngine::GetEngine()->GetCurrentPlayer()->GetShipName().c_str() );
	pack.SetData( (char*)&bag, sizeof( RequestEnterRoomBag ) );
	//m_network->SendTo( ip, pack );
	TcpSendTo( boost::asio::ip::address().from_string( ip ).to_v4().to_ulong(), m_target_port, pack );
}
Beispiel #4
0
void Network::BoostClient::SendLock( int index, int target_index )
{
	PACKAGE p;
	p.SetCMD( PLAYER_LOCK );
	PlayerLockBag bag;
	bag.owner_index = index;
	bag.target_index = target_index;
	p.SetData( (char*)&bag, sizeof(PlayerLockBag) );
	TcpSendTo( m_server_IP, m_target_port, p );
}
Beispiel #5
0
void Network::BoostClient::SendHeroMove( int index, float x, float y, float z )
{
	PACKAGE pack;
	pack.SetCMD( HERO_MOVE );

	HeroMove move( index, x, y, z );

	pack.SetData( (char*)&move, sizeof( HeroMove ) );

	m_network->SendTo( m_server_IP, pack );
}
Beispiel #6
0
void Network::BoostClient::SendHeroRot( int index, float x, float y, float z )
{
	PACKAGE pack;
	pack.SetCMD( HERO_ROTATE );

	HeroRotate rot( index, x, y, z );

	pack.SetData( (char*)&rot, sizeof( HeroRotate ) );

	m_network->SendTo( m_server_IP, pack );
}
Beispiel #7
0
void IAgentPlayer::SendRotate( const core::vector3df& rot )
{
	//RobotShip_->setRotation( getRotation() );

	PACKAGE pack;
	pack.SetCMD( HERO_ROTATE );
	HeroRotate rotate( GetID(), rot.X, rot.Y, rot.Z );
	pack.SetData( (char*)&rotate, sizeof( HeroRotate ) );

	dynamic_pointer_cast<Network::BoostServer >( Server )->AddPacketToBuffer( pack );
}
Beispiel #8
0
void Network::BoostClient::BroadcastMessage( int index, const wchar_t* msg )
{
	BroadcastMessageBag bag;
	bag.index = index;
	bag.target_index = -1;
	bag.SetMsg( msg );

	PACKAGE p;
	p.SetCMD( MESSAGE_TO );
	p.SetData( (char*)&bag, bag.GetLength() );
	TcpSendTo( m_server_IP, m_target_port, p );
}
Beispiel #9
0
void IAgentPlayer::SendMove( const vector3df& pos )
{
	//RobotShip_->setPosition( getPosition() );

	PACKAGE pack;
	pack.SetCMD( HERO_MOVE );
	HeroMove move( GetID(), pos.X, pos.Y, pos.Z );
	pack.SetData( (char*)&move, sizeof( HeroMove ) );

	dynamic_pointer_cast<Network::BoostServer >( Server )->AddPacketToBuffer( pack );
	//Server->OnReceive( 0, pack );
}
Beispiel #10
0
void Network::BoostClient::SendBulletHit( int owner_index, int target_index, int bullet_type, IShip* ship )
{
	BulletHittedBag bag;
	bag.owner_index = owner_index;
	bag.target_index = target_index;
	bag.bullet_type = bullet_type;
	bag.armor = (int)ship->GetArmor();
	bag.shield = (int)ship->GetShield();

	PACKAGE p;
	p.SetCMD( BULLET_HIT );
	p.SetData( (char*)&bag, sizeof( BulletHittedBag ) );

	TcpSendTo( m_server_IP, m_target_port, p );
}
Beispiel #11
0
void Network::BoostClient::SendBullet( int index, int bullet_type, 
	const irr::core::vector3df& start, const irr::core::vector3df& end, u32 life )
{
	BulletCreateBag bullet;
	bullet.owner_index = index;
	bullet.start_point = start;
	bullet.end_point = end;
	bullet.life = life;
	bullet.type = bullet_type;

	PACKAGE pack;
	pack.SetCMD( BULLET_CREATE );
	pack.SetData( (char*)&bullet, sizeof( BulletCreateBag ) );

	m_network->SendTo( m_server_IP, pack );
}
Beispiel #12
0
void Network::BoostClient::OnScoreArrival( unsigned long ip, const PACKAGE& p )
{
	ScoreArrivalBag bag = *(ScoreArrivalBag*)p.GetData();

	ScoreNode score;
	score.ip = ip;
	score.KillCount = bag.KillCount;
	score.DeathCount = bag.DeathCount;
	m_PlayerHelper->SetPlayerScore( ip, score );
}
Beispiel #13
0
void Network::BoostClient::OnPlayerLock( unsigned long ip, const PACKAGE& p )
{
	PlayerLockBag lockBag;
	lockBag = *(PlayerLockBag*)p.GetData();
	if ( lockBag.target_index == m_index )
	{
		//m_PlayerHelper->AddInfoMsg( InfoAndWarn::PIW_PlayerLock );

		MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );
	}
}
Beispiel #14
0
void Network::BoostClient::OnBulletCreate( unsigned long ip, const PACKAGE& p )
{
	BulletCreateBag* bag;
	bag = (BulletCreateBag*)p.GetData();

	// 自己的包或者当自己是服务器是忽略机器人的包
	if ( bag->owner_index == m_index || m_IsServer && bag->owner_index > 70 )	return;

	MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );

}
Beispiel #15
0
void Network::BoostClient::OnAllowJoinRoom( unsigned long ip, const PACKAGE& p )
{
	std::cout << boost::asio::ip::address_v4( ip ).to_string() << " ==>BoostClient receives ALLOW_JOIN_ROOM\n";

	m_server_IP = ip;

	AllowJoinRoomBag allowBag( 0, 0, 0, 0 );
	allowBag = *(AllowJoinRoomBag*)p.GetData();

	m_index = allowBag.index;
}
Beispiel #16
0
void Network::BoostClient::OnHeroRotate( unsigned long ip, const PACKAGE& p )
{
	HeroRotate rot;
	rot = *(HeroRotate*)p.GetData();
	if ( rot.index != m_index )
	{
		auto iter = m_players.find( rot.index );
		if ( iter != m_players.end() )
		{
			//std::cout << "=> HERO_MOVE " << move.index << ' ' << move.x << ' ' << move.y << ' ' << move.z << std::endl;
			iter->second->setRotation( irr::core::vector3df( rot.x, rot.y, rot.z ) );
		}
	}
}
Beispiel #17
0
	//发送数据
	extern "C" INETWORK_API bool SendMessage( PACKAGE& msg, int port /*= 3250*/, unsigned long RecverIP /*= NULL*/ )	
	{
		if (0 == CNetWork::g_SendSocket)
		{
			CNetWork::InitWinSokcet();
		}

		SOCKADDR_IN addrSrv;
		if(0 == RecverIP)
		{
			addrSrv.sin_addr = CNetWork::g_Broadcastaddr;
		}
		else
		{
			addrSrv.sin_addr.S_un.S_addr= RecverIP;
		}

		addrSrv.sin_family=AF_INET;
		addrSrv.sin_port=htons(port);

		int len = sendto(CNetWork::g_SendSocket, msg.Getdata(0), msg.GetLength(), 0,
			(SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
		return true;
	}
Beispiel #18
0
void Network::BoostClient::OnBroadcastRoom( unsigned long ip, const PACKAGE& p )
{
	BroadcastRoomBag bag = *(BroadcastRoomBag*)p.GetData();
	m_roomMap[ boost::asio::ip::address_v4( ip ).to_string() ] = bag;

	//std::cout << "Server broadcast room: ip= " 
	//	<< boost::asio::ip::address_v4( ip ).to_string() 
	//	<< " room name= ";
	//std::wcout << ((BroadcastRoomBag*)p.GetData())->room_name
	//	<< std::endl;

	//std::cout << "<current rooms>\n";
	//for ( auto iter = m_roomMap.begin(); iter != m_roomMap.end(); ++iter )
	//{
	//	std::cout << "ip " << iter->first << std::endl;
	//}
	//std::cout << "</current rooms>\n";
}
Beispiel #19
0
void Network::BoostClient::OnNewPlayerJoin( unsigned long ip, const PACKAGE& p )
{
	OnePlayerInfoBag oneplayer;
	oneplayer = *(OnePlayerInfoBag*)p.GetData();

	if ( oneplayer.player_index != m_index )
	{
		MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );
//		auto smgr = MyIrrlichtEngine::GetEngine()->GetSceneManager();
//
//		// 加载飞船,需要根据玩家飞船信息组装飞船
//		//auto ship = new CFrigate( smgr->getMesh("../model/ship/cf1.obj"), 0, smgr, -1 );
//		auto ship = MyIrrlichtEngine::GetEngine()->GetMySceneManager()->addFrigateSceneNode( L"../model/ship/cf1.obj" );
//		//GeneralCallBack* cb = new GeneralCallBack( ship );
//		//SceneNodeShader shader;
//		//shader.ApplyShaderToSceneNode( ship, cb, "Shader/cf_1V.vert", "Shader/cf_1F.frag" );
//		//cb->drop();
//		//ship->setMaterialFlag( EMF_BACK_FACE_CULLING, false );
//
//		// 设置船的id
//		ship->setID( oneplayer.player_index );
//		// 保存玩家信息
//		m_players[ oneplayer.player_index ] = ship;
//		ship->grab();	///!!!!!!!!!!一定要去drop,还没
//
//		ship->setPosition( core::vector3df( 123141, 12312, 1000000 ) );
//
////		m_playerManager->AddPlayer( ship->getID(), ship );
//		boost::shared_ptr<HumanPlayer> player = boost::shared_ptr<HumanPlayer>( new HumanPlayer( ship ) );
//		player->SetID( oneplayer.player_index );
//		player->SetName( oneplayer.player_name );
//		dynamic_cast<MultiplayerScene*>(
//			MyIrrlichtEngine::GetEngine()->GetGameSceneManager()->GetCurrentGameScene()
//			)->m_playerManager->AddPlayer( player );
//
//		std::cout << "NEW_PLAYER_JOIN " << oneplayer.player_index << std::endl;
	}
	else
	{
		// 设置自己的id		
		//	m_playerManager->m_playerHelper.PlayerShip->setID( m_index );
	}
}
Beispiel #20
0
void Network::BoostClient::OnMessage( unsigned long ip, const PACKAGE& p )
{
	BroadcastMessageBag* bag;
	bag = (BroadcastMessageBag*)p.GetData();

	//bag->GetMsg();
	//bag->index;

	if ( box == 0 )
	{
		box = MyIrrlichtEngine::GetEngine()->GetDevice()->getGUIEnvironment()->addEditBox( _T(""), core::recti( 0, 100, 100, 130 ) );
	}
	box->setVisible( true );
	box->setText( bag->GetMsg() );

	// 两秒后隐藏
	boost::thread t( []()
	{
		boost::thread::sleep( boost::get_system_time() + boost::posix_time::seconds( 2 ) );
		box->setVisible( false );
	} );
}
Beispiel #21
0
void generateDeps(string tgz_filename, bool updateOnly)
{
	if (mConfig.getValue("add_deps_in_build")=="yes") updateOnly=false;
	if (tgz_filename.empty()) {
		mError("No filename specified");
		return;
	}
	say("Generating dependencies for %s\n",tgz_filename.c_str());
	string current_dir = (string) get_current_dir_name();
	// Create a temporary directory
	string tmpdir = get_tmp_file();
	string dep_out = get_tmp_file();
	unlink(tmpdir.c_str());
	system("mkdir -p " + tmpdir);
	say("Extracting\n");
	system("tar zxf " + tgz_filename + " -C " + tmpdir);
	PackageConfig *p = new PackageConfig(tmpdir+"/install/data.xml");
	PACKAGE pkg;
	if (p->parseOk) xml2package(p->getXMLNode(), &pkg);
	delete p;
	say("Building dependencies\n");
	
	system("env LC_ALL=C requiredbuilder -n -v " + tgz_filename + " > "+ dep_out);
	vector<string> data = ReadFileStrings(dep_out);
	
	string tmp;
	string tail;
	DEPENDENCY d;
	//pkg.get_dependencies()->clear();
	string condptr;
	for (unsigned int i=0; i<data.size(); i++)
	{
		tmp = data[i].substr(0,data[i].find_first_of(" "));
		tail = data[i].substr(tmp.length()+1);
		d.set_package_name(&tmp);

		tmp = tail.substr(0, tail.find_first_of(" "));
		tail = tail.substr(tmp.length()+1);
		condptr=IntToStr(condition2int(hcondition2xml(tmp)));
		d.set_condition(&condptr);

		tmp = tail.substr(0,tail.find_first_of("-"));
		d.set_package_version(&tmp);
		if (*d.get_package_name()!=*pkg.get_name()) {
			// Checking existing dependencies
			bool added=false;
			for (unsigned int t=0; t<pkg.get_dependencies()->size(); t++) {
				if (*d.get_package_name()==*pkg.get_dependencies()->at(t).get_package_name()) {
					pkg.get_dependencies()->at(t) = d;
					added=true;
				}
			}
			if (!added) {
				if (updateOnly) mWarning("Found (possible) missing dependencies: " + d.getDepInfo());
				else pkg.get_dependencies()->push_back(d);
			}
		}
	}
	say(_("Got %d dependencies\n"), pkg.get_dependencies()->size());
	p = new PackageConfig(tmpdir+"/install/data.xml");
	dumpPackage(&pkg, p, tmpdir+"/install/data.xml");
	delete p;
	if (tgz_filename[0]!='/') tgz_filename = current_dir + "/"+getDirectory(tgz_filename);
	system ("cd " + tmpdir + "; buildpkg " + tgz_filename );
	system("rm -rf " + tmpdir);
	delete_tmp_files();
}
Beispiel #22
0
// New, very very fast function. The only one who should be used, if fact
int mpkgSys::requestInstall(vector<string> package_name, vector<string> package_version, vector<string> package_build, mpkgDatabase *db, DependencyTracker *DepTracker, vector<string> *eList) {
	
	// First of all, check for local packages
	
	vector<int> localPackages;
	vector<bool> isLocal(package_name.size(), false);
	LocalPackage *_p;
	string pkgType;
	for (size_t i=0; i<package_name.size(); i++) {
		pkgType=getExtension(package_name[i]);
		if (pkgType=="txz" || pkgType == "tbz" || pkgType == "tlz" || pkgType=="tgz" || pkgType == "spkg") {
		       if (FileExists(package_name[i])) {
				_p = new LocalPackage(package_name[i]);
				_p->injectFile();
				db->emerge_to_db(&_p->data);
				package_name[i] = _p->data.get_name();
				package_version[i] = _p->data.get_version();
				package_build[i] = _p->data.get_build();
				isLocal[i]=true;
				//printf("\nDetected local package\nFilename: %s\nName:%s\nVersion:%s\n", _p->data.get_filename().c_str(), _p->data.get_name().c_str(), _p->data.get_version().c_str());
				localPackages.push_back(_p->data.get_id());
				delete _p;
			}
		}
	}
	vector<string> errorList;
	//printf("using error list\n");
	// Creating DB cache
	// 1. Creating a request for all packages which are in package_name vector.
	SQLRecord sqlSearch;
	sqlSearch.setSearchMode(SEARCH_IN);
	for (size_t i=0; i<package_name.size(); i++) {
		if (isLocal[i]) {
			continue;
		}
		sqlSearch.addField("package_name", package_name[i]);
	}
	// 2. Requesting database by search array
	PACKAGE_LIST pCache;
	//printf("SLOW GET_PACKAGELIST CALL: %s %d\n", __func__, __LINE__);
	int query_ret = db->get_packagelist(sqlSearch, &pCache, true, false);
	if (query_ret != 0) {
		errorList.push_back(mError("Error querying database"));
		if (eList) *eList = errorList;
		return MPKGERROR_SQLQUERYERROR;
	}
	// 3. Temporary matrix, temporary list (for each package), and result list
	vector<PACKAGE_LIST> tmpMatrix;
	PACKAGE_LIST *tmpList=new PACKAGE_LIST;
	PACKAGE_LIST resultList;
	PACKAGE_LIST uninstallList;
	// 4. Search by cache for installed ones, check for availability and select the appropriate versions
	// 4.1 Building matrix: one vector per list of packages with same name
	for (size_t i=0; i<package_name.size(); i++) {
		delete tmpList;
		tmpList = new PACKAGE_LIST;
		for (size_t t=0; t<pCache.size(); t++) {
			if (pCache.at(t).get_name() == package_name[i]) {
				if (isLocal[i] && pCache[t].get_id()!=localPackages[i]) continue;
				tmpList->add(pCache.at(t));
			}
		}
		tmpMatrix.push_back(*tmpList);
	}
	//printf("tmpMatrix[0] size = %d\n", tmpMatrix[0].size());
	// So, the matrix has been created.
	// In case of any error, collect all of them, and return MPKGERROR_IMPOSSIBLE
	
	// Sizes of tmpMatrix and input vectors are the same, so we can use any of them
	PACKAGE *outPackage = NULL, *installedOne = NULL;
	for (size_t i=0; i<tmpMatrix.size(); i++) {
		delete tmpList;
		tmpList = new PACKAGE_LIST;
		for (size_t t=0; t<tmpMatrix[i].size(); t++) {
			// Filling the tmpList with reachable (=installed or available) ones for each package
			if (tmpMatrix[i].at(t).available(true) || tmpMatrix[i].at(t).installed()) {
				if (package_version[i].empty() || tmpMatrix[i].at(t).get_version() == package_version[i]) {
					if (package_build[i].empty() || package_build[i]==tmpMatrix[i].at(t).get_build()) tmpList->add(tmpMatrix[i][t]);
				}
			}
		}
		// Now, we have a list of all good candidates. We will filter already installed ones separately for better UI output.
		tmpList->initVersioning();
		outPackage = tmpList->getMaxVersion();
		//if (outPackage) printf("outPackage VERSION: %s\n", outPackage->get_fullversion().c_str());
		installedOne = (PACKAGE *) tmpMatrix[i].getInstalledOne();
		if (outPackage == NULL) {
			string errorText = _("Requested package ") + package_name[i];
		       	if (!package_version[i].empty()) errorText += "-" + package_version[i];
			if (!package_build[i].empty()) errorText += "-" + package_build[i];
			if (!installedOne) errorList.push_back(mError(errorText + _(" cannot be found")));
			else errorList.push_back(mError(errorText + _(" is already installed")));
		}
		else {
			//printf("____________________________CHECK FOR UPDATE, installedOne: %p_____________________________\n", installedOne);
			// Check for update
			if (installedOne && outPackage->get_id() != installedOne->get_id()) {
				// This is update
				//printf("added to uninstall: %d\n", installedOne->get_id());
				uninstallList.add(*installedOne);
			}
			resultList.add(*outPackage);
		}
	}
	delete tmpList;
	// Special addition for local packages installed using -z key: check for installed one
	for (size_t i=0; i<isLocal.size(); ++i) {
		if (!isLocal[i]) continue;
		for (size_t t=0; t<pCache.size(); ++t) {
			if (pCache[t].installed() && pCache[t].get_id()!=localPackages[i] && pCache[t].get_name()==package_name[i]) {
				requestUninstall(pCache.get_package_ptr(t), db, DepTracker);
			}
		}
	}
	// Now, check resultList for installed ones and unavailable ones
	for (size_t i=0; i<resultList.size(); i++) {
		if (resultList[i].installed()) {
			mWarning(_("Package ") + resultList[i].get_name() + "-" + resultList[i].get_fullversion() + _(" is already installed"));
		} 
		else {
			if (!resultList[i].available(true)) {
				errorList.push_back(mError(_("Package ") + resultList[i].get_name() + "-" + resultList[i].get_fullversion() + _(" is unavailable")));
			}
		}
	}
	// NEW: ignore already installed packages
	tmpList = new PACKAGE_LIST;
	for (size_t i=0; i<resultList.size(); ++i) {
		if (!resultList[i].installed()) {
			tmpList->add(resultList[i]);
		}
	}
	resultList = *tmpList;
	delete tmpList;
	

	//printf("resultList size = %d\n", resultList.size());
	if (errorList.empty())	{
		// Push to database
		__requestInstallPkgList(&resultList, db, DepTracker);
		for (size_t i=0; i<uninstallList.size(); i++) requestUninstall(uninstallList.get_package_ptr(i), db, DepTracker);

	}
	else {
		mError(_("Errors detected, cannot continue"));
		if (eList) *eList = errorList;
		return MPKGERROR_IMPOSSIBLE;
	}

	if (eList) *eList = errorList;
	return 0;
}
Beispiel #23
0
int slack_convert(const string& filename, string& xml_output)
{
	mDebug("Preparing to convert " + filename);
	PACKAGE package;
	package.set_filename(filename);
	// Resolving name, version, arch and build
	string tmp;
	string tmp_xml = get_tmp_file();
	extractFromTgz(filename, "install/data.xml", tmp_xml);
	if (FileNotEmpty(tmp_xml))
	{
		WriteFile(xml_output, ReadFile(tmp_xml));
		delete_tmp_files();
		return 0;
	}
	string ptrstr;
	// Guessing type
	string pkgType = getExtension(filename);
	if (pkgType!="tgz" && pkgType!="txz" && pkgType!="tlz" && pkgType!="tbz") {
		mError(_("Unknown package type ") + pkgType);
		return 1;
	}
	// Name-ver-arch-build parsing
	string name_tmp=filename.substr(0,filename.find("." + pkgType));
	name_tmp = name_tmp.substr(name_tmp.find_last_of("/")+1);
	ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_build(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_arch(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	ptrstr=name_tmp.substr(name_tmp.find_last_of("-")+1);
	package.set_version(ptrstr);
	name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-"));
	package.set_name(name_tmp);
	name_tmp.clear();


#define DESCRIPTION_PROCESS
#ifdef DESCRIPTION_PROCESS	
	//DESCRIPTION
	mDebug("Processing description");
	string desc_file= filename.substr(0,filename.length()-3)+"txt";
	bool can_read=false;
#ifdef GET_TXT_DESC
	if (access(desc_file.c_str(), R_OK)==0)
	{
		mDebug("Retrieving from txt");
		can_read=true;
	}
	else 
	{
#endif
		desc_file=get_tmp_file();
		string desc="tar xf "+filename+" install/slack-desc --to-stdout > "+desc_file;
		if (system(desc.c_str())==0)
		{

			mDebug("Retrieving from slack-desc");
			can_read=true;
		}
		else mDebug("Cannot find any description");
#ifdef GET_TXT_DESC
	}
#endif
	if (can_read)
	{
		string description=ReadFile(desc_file);
		delete_tmp_files();
		// Step 1. Skip comments
		unsigned int dpos=0;
		//unsigned int strLen=0;
		string comment;
		string head;
		string short_description;
		//bool str1=true;
		if (!description.empty())
		{
			// Cleaning out comments
			for (unsigned int i=0; i<description.length(); i++)
			{
				if (description[i]=='#')
				{
					while (description[i]!='\n') i++;
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
			string pHead=package.get_name()+":";
			int spos=description.find(pHead,0);
			// Removing package: headers
			for (unsigned int i=spos; i<description.length(); i++)
			{
				//head+=description[i];
				if (i==0 || description[i-1]=='\n')
				{
					i=i+package.get_name().length()+1;
					//if (description[i-1]=='\n') i=i+package.get_name().length()+2;
					//head.clear();
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
	
			// Splitting short and long descriptions
			for (unsigned int i=0; i<description.length() && description[i]!='\n'; i++)
			{
				tmp+=description[i];
				dpos=i+1;
			}
			short_description=tmp;
			tmp.clear();
			for (unsigned int i=dpos; i<description.length(); i++)
			{
				if (i==dpos && description[i]=='\n')
				{
					while (description[i]=='\n' || description[i]==' ') i++;
					if (i>=description.length()) break;
				}
				if (i<description.length()) tmp+=description[i];
			}
			description=tmp;
			tmp.clear();
			package.set_short_description(short_description);
			package.set_description(description);
			mDebug("Description: " + description);
		}
	}
#endif
	XMLNode pkg=XMLNode::createXMLTopNode("package");
	pkg.addChild("name");
	pkg.getChildNode("name").addText(package.get_name().c_str());
	pkg.addChild("version");
	pkg.getChildNode("version").addText(package.get_version().c_str());
	pkg.addChild("arch");
	pkg.getChildNode("arch").addText(package.get_arch().c_str());
	pkg.addChild("build");
	pkg.getChildNode("build").addText(package.get_build().c_str());
#ifdef DESCRIPTION_PROCESS
	mDebug("Adding description to XML node");
	pkg.addChild("short_description");
	pkg.getChildNode("short_description").addText(package.get_short_description().c_str());
	pkg.addChild("description");
	pkg.getChildNode("description").addText(package.get_description().c_str());
#endif
#ifdef TAG_CONVERTED
	pkg.addChild("tags");
	pkg.getChildNode("tags").addChild("tag");
	pkg.getChildNode("tags").getChildNode("tag").addText("slackware");
#endif
	// Get maintainer name and email
	string mName = mConfig.getValue("maintainer_name");
	string mEmail = mConfig.getValue("maintainer_email");
	if (mName.empty()) mName = "Converted by anonymous maintainer";
	if (mEmail.empty()) mEmail = "No email specified";
	pkg.addChild("maintainer");
	pkg.getChildNode("maintainer").addChild("name");
	pkg.getChildNode("maintainer").getChildNode("name").addText(mName.c_str());
	pkg.getChildNode("maintainer").addChild("email");
	pkg.getChildNode("maintainer").getChildNode("email").addText(mEmail.c_str());
	pkg.writeToFile(xml_output.c_str(), "utf-8");
	return 0;
}
Beispiel #24
0
int mpkgSys::requestUninstall(int package_id, mpkgDatabase *db, DependencyTracker *DepTracker, bool purge)
{
	//printf("requestUninstall by ID, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ignoreDeps = %d\n", ignoreDeps);
	mDebug("requestUninstall\n");
	PACKAGE tmpPackage;
	int ret = db->get_package(package_id, &tmpPackage);
	mDebug("uninstall called for id " + IntToStr(package_id) + ", name = " + tmpPackage.get_name() + "-" + tmpPackage.get_fullversion());
	bool process=false;
	if (ret == 0)
	{
		if (tmpPackage.configexist())
		{
			if (purge)
			{
				mDebug("action set to purge");
				tmpPackage.set_action(ST_PURGE, "direct");
				process=true;
			}
			else if (tmpPackage.installed())
			{
				mDebug("action is remove");
				tmpPackage.set_action(ST_REMOVE, "direct");
				process=true;
			}
		}
		else
		{
			say(_("%s-%s doesn't present in the system\n"), tmpPackage.get_name().c_str(), tmpPackage.get_fullversion().c_str());
		}
		if (process)
		{
			mDebug("Processing deps");
			if (!ignoreDeps) {
				//printf("added to remove queue\n");
				DepTracker->addToRemoveQuery(tmpPackage);
			}
			else {
				if (purge) db->set_action(tmpPackage.get_id(), ST_PURGE, "direct");
				else db->set_action(tmpPackage.get_id(), ST_REMOVE, "direct");
			}

			return 0;
		}
		else
		{
			if (purge) mError(_("Package ") + tmpPackage.get_name() + " "+ tmpPackage.get_fullversion() + _(" is already purged"));
			else  mError(_("Package ") + tmpPackage.get_name() + " " + tmpPackage.get_fullversion() + _(" is already purged"));
;
			return MPKGERROR_IMPOSSIBLE;
		}
	}
	else
	{
		return ret;
	}
}
Beispiel #25
0
PkgScanResults checkRevDeps(const PACKAGE &pkg, bool fast, bool skip_symbols) {
	//printf("Running check for %s\n", pkg.get_name().c_str());
	PkgScanResults ret;
	
	// Check if package has files filled in, if no - report error and return empty results. This check includes that package is installed and checkable.
	if (pkg.get_files().empty()) {
		//mError("FATAL: package " + pkg.get_name() + " has no files filled in, check impossible\n");
		return ret;
	}

	// Now go scanning
	string fname;
	vector<string> data;
	string ld_preload;
	string ldd_options;
	if (!skip_symbols) ldd_options = " -r ";
	// Create LD_LIBRARY_PATH variable. For this, we need a full list of .so paths of package
	vector<string> ld_paths;
	bool ld_found;
	for (size_t i=0; i<pkg.get_files().size(); ++i) {
		if (pkg.get_files().at(i).find(".so")==pkg.get_files().at(i).size()-3) {
			ld_found = false;
			for (size_t t=0; !ld_found && t<ld_paths.size(); ++t) {
				if (ld_paths[t]==getDirectory(pkg.get_files().at(i))) ld_found = true;
			}
			if (!ld_found) ld_paths.push_back(getDirectory(pkg.get_files().at(i)));
		}
	}
	string ld_library_path, orig_library_path;
       	if (getenv("LD_LIBRARY_PATH")) orig_library_path = getenv("LD_LIBRARY_PATH");
	ld_library_path = orig_library_path;
	for (size_t i=0; i<ld_paths.size(); ++i) {
		if (ld_library_path.size()>0) ld_library_path += ":";
		ld_library_path += "/" + ld_paths[i];
	}
	string cmdstring;
	setenv("LD_LIBRARY_PATH", ld_library_path.c_str(), 1);
	for (size_t i=0; i<pkg.get_files().size(); ++i) {
		fname = pkg.get_files().at(i);
		//printf("Scanning file %s\n", fname.c_str());
		if (fast) {
			if (fname.find("usr/lib")!=0 && fname.find("usr/bin/")!=0 && fname.find("bin/")!=0 && fname.find("sbin/")!=0 && fname.find("usr/sbin/")!=0) continue;
		}
		// Skip directories and special dirs with huge amount of files
		if (fname.empty() || fname[fname.size()-1]=='/' || fname.find("etc/")==0 || fname.find("dev/")==0 || fname.find("lib/modules/")==0 || fname.find("usr/share/")==0 || fname.find("usr/man/")==0 || fname.find("usr/include/")==0 || fname.find("usr/doc/")==0 || fname.find("usr/lib/locale/")==0 || fname.find("usr/lib64/locale/")==0 || fname.find("opt/")==0) continue;
		// Skip non-executable ones
		if (fast && access(string("/" + fname).c_str(), X_OK)) continue;

		// Too slow, disabled
		//msay("[" + pkg.get_name() + ": errs: " + IntToStr(ret.symbolErrors.size() + ret.notFoundErrors.size()) + "] [" + IntToStr(i+1) + "/" + IntToStr(pkg.get_files().size()) + "]: /" + fname);
		if (fname.find("usr/lib/")==0 && fname.find("python")!=std::string::npos) ld_preload = "LD_PRELOAD=/usr/lib/libpython2.6.so ";
		else if (fname.find("usr/lib64/")==0 && fname.find("python")!=std::string::npos) ld_preload = "LD_PRELOAD=/usr/lib64/libpython2.6.so ";
		else ld_preload = "";

		cmdstring = "LD_PRELOAD=" + ld_preload + " LD_LIBRARY_PATH=" + ld_library_path + " ldd " + ldd_options + " '" + SYS_ROOT + fname + "' 2>&1 | grep -P 'undefined symbol|not found'";

		data = MakeStrings(psystem(cmdstring));
		if (data.empty()) {
			//printf("CMDLINE WAS: %s\n", cmdstring.c_str());
			//printf("Nothing for %s, continue\n", fname.c_str());
			continue;
		}
		//printf("Parsing data for file %s, found %d records\n", fname.c_str(), data.size());
		ret.parseData(fname, data);
	}
	if (orig_library_path.empty()) unsetenv("LD_LIBRARY_PATH");
	else setenv("LD_LIBRARY_PATH", orig_library_path.c_str(), 1);

	return ret;
}
Beispiel #26
0
//XMLNode _rootFList;
int slackpackages2list (string *packageslist, string *md5list, PACKAGE_LIST *pkglist, string server_url)
{
	if (actionBus._abortActions)
	{
		actionBus._abortComplete=true;
		actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		say("aborted\n");
		return MPKGERROR_ABORTED;
	}

	if (packageslist->length()<20)
	{
		say("aborted\n");
		return -1; // It's impossible if it has less size...
	}
	// Parsing slackware PACKAGES.TXT file
	// Keywords (in [] braces to show spaces:
	// [PACKAGE NAME:  ] 		going first or after \n\n symbols.  Until \n, contains package filename (that contains name, version, arch and build information)
	// [PACKAGE LOCATION:  ]	location of package (from repository root). Going after \n
	// [PACKAGE SIZE (compressed):  ]
	// [PACKAGE SIZE (uncompressed):  ]
	// [PACKAGE REQUIRED:  ]
	// [PACKAGE SUGGESTS:  ]
	// [PACKAGE DESCRIPTION:\n]	Package description (max 11 lines starting with [package_name:]) 
	PACKAGE *pkg = new PACKAGE;
	LOCATION *tmplocation = new LOCATION;
#ifdef ENABLE_INTERNATIONAL
	DESCRIPTION *tmpDesc = new DESCRIPTION;
	tmpDesc->set_language("en");
#endif
	string *tmpDescStr = new string;
	string *tmpstr = packageslist;
	int tmpSize;
	int lines = 0;
	int name_start = 0;
	bool endReached = false;

	string slackPackageName;
	string slackPackageLocation;
	string slackCompressedSize;
	string slackUncompressedSize;
	string slackRequired;
	string slackSuggests;
	string slackDescription;
	string filename;
	string tmp;
	string md5tmp;
	string pkgNameKeyword = "PACKAGE NAME:  ";
	string pkgLocationKeyword = "PACKAGE LOCATION:  ";
	string pkgCompressedKeyword = "PACKAGE SIZE (compressed):  ";
	string pkgUncompressedKeyword = "PACKAGE SIZE (uncompressed):  ";
	string pkgRequiredKeyword = "PACKAGE REQUIRED:  ";
	string pkgSuggestsKeyword = "PACKAGE SUGGESTS:  ";
	string pkgDescriptionKeyword = "PACKAGE DESCRIPTION:";
	unsigned int pos;
	unsigned int num=0;
	//tmpstr = packageslist;

	// Visualization
	actionBus.setActionProgress(ACTIONID_DBUPDATE, 0);
	unsigned int tmp_max = tmpstr->length();
	actionBus.setActionProgressMaximum(ACTIONID_DBUPDATE, (double) tmpstr->length());
	//progressEnabled = true;

	while (!endReached)
	{
		if (actionBus._abortActions)
		{
			actionBus._abortComplete=true;
			actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		say("aborted\n");
			return MPKGERROR_ABORTED;
		}

		actionBus.setActionProgress (ACTIONID_DBUPDATE, (double) tmp_max - tmpstr->length());
		mDebug("Parsing "+IntToStr(num)+" package");
		// Stage 1: retrieving dirty info
		pos = tmpstr->find(pkgNameKeyword);
		*tmpstr=tmpstr->substr(pos+pkgNameKeyword.length()); // Cuts off a header and keyword
		pos = tmpstr->find("\n"); // Searching end of line
		slackPackageName = tmpstr->substr(0,pos); // Filling package name (in full form)
		mDebug("slackPackageName = "+slackPackageName);
		
		pos = tmpstr->find(pkgLocationKeyword);
		*tmpstr = tmpstr->substr(pkgLocationKeyword.length()+pos);
		pos = tmpstr->find("\n");
		slackPackageLocation = tmpstr->substr(0,pos);
		mDebug("slackPackageLocation = "+ slackPackageLocation);
	
		pos = tmpstr->find(pkgCompressedKeyword);
		*tmpstr = tmpstr->substr(pos + pkgCompressedKeyword.length());
		pos = tmpstr->find("\n");
		slackCompressedSize = tmpstr->substr(0,pos);
		mDebug("slackCompressedSize = " + slackCompressedSize);

		pos = tmpstr->find(pkgUncompressedKeyword);
		*tmpstr = tmpstr->substr(pos + pkgUncompressedKeyword.length());
		pos = tmpstr->find("\n");
		slackUncompressedSize = tmpstr->substr(0,pos);
		mDebug("slackUncompressedSize = " + slackUncompressedSize);
	
		pos = tmpstr->find(pkgRequiredKeyword);
		if (pos < tmpstr->find(pkgNameKeyword))
		{
			mDebug("required list present!");
			*tmpstr = tmpstr->substr(pos + pkgRequiredKeyword.length());
			pos = tmpstr->find("\n");
			slackRequired = tmpstr->substr(0,pos);
			mDebug("slackRequired = " + slackRequired);
		}
		else
		{
			mDebug("no required list");
			slackRequired.clear();
		}

		pos = tmpstr->find(pkgSuggestsKeyword);
		if (pos < tmpstr->find(pkgNameKeyword))
		{
			mDebug("suggest list present!");
			*tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length());
			pos = tmpstr->find("\n");
			slackSuggests = tmpstr->substr(0,pos);
			mDebug("slackSuggests = " + slackSuggests);
		}
		else
		{
			slackSuggests.clear();
			mDebug("no suggest list");
		}

		pos = tmpstr->find(pkgDescriptionKeyword);
		*tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length()+1); // +1 because there are newline
		pos = tmpstr->find(pkgNameKeyword);
		mDebug("searched end");
		if (pos == std::string::npos)
		{
			mDebug("description end reached");
			slackDescription = *tmpstr;
			
			mDebug("slackDescription = " + slackDescription);
			endReached = true;
		}
		else
		{
			slackDescription = tmpstr->substr(0,pos-1);

			mDebug("slackDescription = "+ slackDescription);
		}
		
		// Stage 2: info cleanup
		
		// Filename
		pkg->set_filename(&slackPackageName);
		
		if (md5list->find(slackPackageName) == std::string::npos)
		{
			mError("MD5 checksum not found for package " +  slackPackageName +", skipping");
		}
		else
		{
			mDebug("md5 found");
			md5tmp = md5list->substr(0,md5list->find(slackPackageName));
		}
		md5tmp = md5tmp.substr(0, md5tmp.find_last_of(" \t"));
		md5tmp = md5tmp.substr(md5tmp.rfind("\n")+1);
		md5tmp = cutSpaces(md5tmp);
		pkg->set_md5(&md5tmp);
		mDebug("MD5 = " + md5tmp);
		
		filename = slackPackageName;

		// Name, version, arch, build
		pos = slackDescription.find(":");
		mDebug("pos = "+IntToStr(pos));
		tmp.clear();
		if (true)
		{
			name_start=0;
			for (int i=filename.length()-1; filename[i]!='/' && i>=0; i--)
			{
				name_start=i;
			}
			for (unsigned int i=name_start; i<filename.length()-1; i++)
			{
				if (filename[i]=='-')
				{
					if (filename[i+1]=='0' || \
						filename[i+1] == '1' || \
						filename[i+1] == '2' || \
						filename[i+1] == '3' || \
						filename[i+1] == '4' || \
						filename[i+1] == '5' || \
						filename[i+1] == '6' || \
						filename[i+1] == '7' || \
						filename[i+1] == '8' || \
						filename[i+1] == '9')
					{
						pkg->set_name(&tmp);
						pos=i+2;
						break;
					}
				}
				tmp+=filename[i];
			}
			tmp.clear();
			//VERSION
			for (unsigned int i=pos-1; i< filename.length(); i++)
			{
				if (filename[i]=='-')
				{
					pkg->set_version(&tmp);
					pos=i+2;
					break;
				}
				tmp+=filename[i];
			}
			tmp.clear();
			//ARCH
			for (unsigned int i=pos-1; i< filename.length(); i++)
			{
				if (filename[i]=='-')
				{
					pkg->set_arch(&tmp);
					pos=i+2;
					break;
				}
				tmp+=filename[i];
			}
			tmp.clear();
			//BUILD
			for (unsigned int i=pos-1; i<filename.length()-4; i++)
			{
				tmp+=filename[i];
			}
			pkg->set_build(&tmp);

			tmp.clear();
		}
		
		mDebug("package name: "+ *pkg->get_name());
		mDebug("package version: "+ *pkg->get_version());
		mDebug("package arch: "+ *pkg->get_arch());
		mDebug("package build: "+ *pkg->get_build());
		// Location
		if (slackPackageLocation.find("./") == 0)
		{
			mDebug("DOTCUT:");
			slackPackageLocation = slackPackageLocation.substr(2);
		}
		tmplocation->set_path(&slackPackageLocation);
		tmplocation->set_server_url(&server_url);
		pkg->get_locations()->push_back(*tmplocation);
		//mDebug("LOC_SET: "+*pkg->get_locations()->at(0)->get_path());

		// Size
		tmpSize = atoi(slackCompressedSize.substr(0, slackCompressedSize.length()-2).c_str());
		*pkg->get_compressed_size()=IntToStr(tmpSize*1024);
		mDebug("package size (compressed): "+ *pkg->get_compressed_size());
		tmpSize = atoi(slackUncompressedSize.substr(0, slackUncompressedSize.length()-2).c_str());
		*pkg->get_installed_size()=IntToStr(tmpSize*1024);
		mDebug("package size (uncompressed): "+ *pkg->get_installed_size());

		mDebug("reached description");
		// Description
		tmpDescStr->clear();
		
		if (slackDescription.length()>0)
		{
			slackDescription = slackDescription.substr(1);
			if (slackDescription.length() >= slackDescription.find(*pkg->get_name()+": ") + pkg->get_name()->length()+2)
			{
				slackDescription = slackDescription.substr(slackDescription.find(*pkg->get_name()+": ")+pkg->get_name()->length()+2);
				//tmpDesc->set_shorttext(slackDescription.substr(0, slackDescription.find_first_of("\n")));
				*pkg->get_short_description()=slackDescription.substr(0, slackDescription.find_first_of("\n"));
				//mDebug("short description: "+slackDescription.substr(0, slackDescription.find_first_of("\n")));
			}
			pos = slackDescription.find("\n");
			lines = 0;
			while (pos != std::string::npos && lines < 11)
			{
				pos = slackDescription.find(*pkg->get_name()+": ");
				if (pos == std::string::npos)
				{
					mDebug("Description end");
				}
				else
				{
					slackDescription = slackDescription.substr(pos+pkg->get_name()->length()+2);
					*tmpDescStr = *tmpDescStr + slackDescription.substr(0,slackDescription.find("\n"))+"\n";
					lines++;
				}
			}
			mDebug("Description: "+ *tmpDescStr);
			//tmpDesc->set_text(*tmpDescStr);
			pkg->set_description(tmpDescStr);
#ifdef ENABLE_INTERNATIONAL			
			pkg->get_descriptions()->add(tmpDesc);
#endif
		}
		pkglist->add(pkg);
		pkg->clear();
		num++;
		mDebug("done");
	}
	delete pkg;
	delete tmplocation;
	//delete tmpDesc;
	delete tmpDescStr;
	//delete tmpstr;

	return 0;
}	// End slackpackages2list()
Beispiel #27
0
void Network::BoostClient::QueryRoom()
{
	PACKAGE p;
	p.SetCMD( QUERY_ROOM );
	m_network->Broadcast( p );
}
Beispiel #28
0
// Add other such functions for other repository types.
int Repository::get_index(string server_url, PACKAGE_LIST *packages, unsigned int type)
{
	if (actionBus._abortActions)
	{
		actionBus._abortComplete=true;
		actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		return MPKGERROR_ABORTED;
	}

	currentStatus = "Updating data from "+ server_url+"...";
	mDebug("get_index!");
	// First: detecting repository type
	// Trying to download in this order (if successful, we have detected a repository type):
	// 1. packages.xml.gz 	(Native MOPSLinux)
	// 2. PACKAGES.TXT	(Legacy Slackware)
	// 3. Packages.gz	(Debian)
	// (and something else for RPM, in future)
	string index_filename = get_tmp_file();
	string md5sums_filename = get_tmp_file();
	if (!dialogMode) say("[%s] ...\r",server_url.c_str());
	string cm = "gunzip -f "+index_filename+".gz 2>/dev/null";
	if (type == TYPE_MPKG || type == TYPE_AUTO)
	{
		actionBus.getActionState(0);
		mDebug("trying MPKG, type = "+ IntToStr(type));
	       if (CommonGetFile(server_url + "packages.xml.gz", index_filename+".gz")==DOWNLOAD_OK)
		{
			actionBus.getActionState(0);
			mDebug("download ok, validating contents...");
			if (system(cm.c_str())==0 && \
					ReadFile(index_filename).find("<?xml version=\"1.0\"")!=std::string::npos && ReadFile(index_filename).find("<repository")!=std::string::npos)
			{
				currentStatus = "Detected native MPKG repository";
				type = TYPE_MPKG;
			}
		}
	}
	if (actionBus._abortActions)
	{
		actionBus._abortComplete=true;
		actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		return MPKGERROR_ABORTED;
	}

	if (type == TYPE_SLACK || type == TYPE_AUTO)
	{
		
		mDebug("trying SLACK, type = "+ IntToStr(type));
		if (CommonGetFile(server_url + "PACKAGES.TXT", index_filename)==DOWNLOAD_OK)
		{
			mDebug("download ok, validating contents...");
			if (ReadFile(index_filename).find("PACKAGE NAME:  ")!=std::string::npos)
			{
				currentStatus = _("Detected legacy Slackware repository");
				if (CommonGetFile(server_url + "CHECKSUMS.md5", md5sums_filename) == DOWNLOAD_OK)
				{
					type = TYPE_SLACK;
				}
				else 
				{
					mError(_("Error downloading checksums"));
					return -1; // Download failed: no checksums or checksums download error
				}
			}
		}
	}
	if (actionBus._abortActions)
	{
		actionBus._abortComplete=true;
		actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		return MPKGERROR_ABORTED;
	}

	if (type == TYPE_DEBIAN || type == TYPE_AUTO)
	{
		if(CommonGetFile(server_url + "Packages.gz", index_filename+".gz")==DOWNLOAD_OK)
		{
			type = TYPE_DEBIAN;
		}
	}

	if (type != TYPE_MPKG && type != TYPE_SLACK && type!=TYPE_DEBIAN)
	{
		currentStatus = _("Error updating data from ") +server_url+_(": download error or unsupported type");
		mError(_("Error downloading package index: download error, or unsupported repository type"));
		return -1;
	}
	mDebug("Starting to parse index");
	PACKAGE *pkg = new PACKAGE;
	string xml_name=index_filename;
//	XMLNode *repository_root = new XMLNode;
	
	xmlDocPtr indexDoc;
	xmlNodePtr indexRootNode;
	
//	int pkg_count;
	int ret=0;
	currentStatus = "["+server_url+"] Importing data...";
	if (actionBus._abortActions)
	{
		actionBus._abortComplete=true;
		actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
		return MPKGERROR_ABORTED;
	}
	string *pList = new string;
	string *mList = new string;
	//XMLNode *tmp = new XMLNode;
	//xmlDocPtr indexDoc;
	//xmlNodePtr indexRootNode;
	switch(type)
	{
		case TYPE_MPKG:
			indexDoc = xmlReadFile(xml_name.c_str(), "UTF-8", 0);
			if (indexDoc == NULL) {
				xmlFreeDoc(indexDoc);
				mError("ппц...");
				return -1;
			}
			else mDebug("indexDoc read successfully");
			
			indexRootNode = xmlDocGetRootElement(indexDoc);
			if (indexRootNode == NULL) {
				mError(_("Failed to get index"));
				xmlFreeDoc(indexDoc);
			}
			else mDebug("indexRootNode read successfully");
			
			if (xmlStrcmp(indexRootNode->name, (const xmlChar *) "repository") ) {
				mError(_("Invalid index file"));
				xmlFreeDoc(indexDoc);
			}
			else mDebug("Found valid repository index");
			
			xmlXPathContextPtr xContext;
			xmlXPathObjectPtr xResult;
			
			xContext = xmlXPathNewContext(indexDoc);
			if (xContext == NULL) {
				mError("ппц");
			}
			
			xResult = xmlXPathEvalExpression((const xmlChar *)"/repository/package", xContext);
			if (xResult == NULL) {
				mError("XPath expression error");
			}
			
			if (xmlXPathNodeSetIsEmpty(xResult->nodesetval)) {
				xmlXPathFreeObject(xResult);

				printf(_("[%s] ... Nothing found\n"), server_url.c_str());
				//mError("No packages found");
				return 0;
			}
			
			xmlNodeSetPtr xNodeSet;
			int xi;
			
			actionBus.setActionProgress(ACTIONID_DBUPDATE, 0);
			
			xNodeSet = xResult->nodesetval;
			xmlXPathFreeContext(xContext);

			actionBus.setActionProgressMaximum(ACTIONID_DBUPDATE, xNodeSet->nodeNr);
			if (xNodeSet->nodeNr==0) printf("[%s] ... Nothing found", server_url.c_str());
			for (xi = 0; xi < xNodeSet->nodeNr; xi++) {
				printf("[%s] ... Importing received data: %d/%d\r",server_url.c_str(), xi+1, xNodeSet->nodeNr);
				actionBus.setActionProgress(ACTIONID_DBUPDATE, xi);
				mDebug("Processing " + IntToStr(xi) + " node");
				if (actionBus._abortActions) {
					actionBus._abortComplete = true;
					actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
					
					return MPKGERROR_ABORTED;
				}
				
				actionBus.setActionProgress(ACTIONID_DBUPDATE, xi);
				pkg->clear();
				mDebug("Calling xml2Package");
				if (xml2package(xNodeSet->nodeTab[xi], pkg)<0) {
					mError("Failed to parse");
					abort();
				}
				else mDebug("xml2package OK");
				// Adding location data
				pkg->get_locations()->at(0).set_server_url(&server_url);
				packages->add(pkg);
			}
			printf("\n");
			xmlCleanupMemory();
			xmlCleanupParser();
			/*
			
 				*repository_root=XMLNode::openFileHelper(xml_name.c_str(), "repository");
				pkg_count=repository_root->nChildNode("package");
				if (pkg_count==0)
				{
					mError("Repository has no packages\n");
					delete pkg;
					return 0;
				}
				
				actionBus.setActionProgress(ACTIONID_DBUPDATE, 0);
				for (int i=0; i<pkg_count; i++)
				{
					if (actionBus._abortActions)
					{
						actionBus._abortComplete=true;
						actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED);
						return MPKGERROR_ABORTED;
					}

					actionBus.setActionProgress(ACTIONID_DBUPDATE, i);
					pkg->clear();
					*tmp = repository_root->getChildNode("package", i);
					xml2package(tmp, pkg);
					// Adding location data
					pkg->get_locations()->at(0).set_server_url(&server_url);
					packages->add(pkg);
				}*/
				//delete tmp;
			break;
		case TYPE_SLACK:
			*pList = ReadFile(index_filename);
			*mList = ReadFile(md5sums_filename);

			ret = slackpackages2list(pList, mList, packages, server_url);
			if (pList!=NULL) delete pList;
			if (mList!=NULL) delete mList;
			break;

		case TYPE_DEBIAN:
			break;
		default:
			break;
	}
	delete pkg;
	return ret;
}