Exemplo n.º 1
0
	void GetDirName(CMyString &path)
	{
		int len=path.GetStrLen();
		int start=0;
		for(int i=len-1;i>=0;i++)
		{
			if(path[i]=='/')
			{
				start=i+1;
				break;
			}
		}
		m_TempStr=path.GetSubStr(start);
		if(path[len-1]=='/')
			m_TempStr.EraseFromRight(1);
	}
Exemplo n.º 2
0
void SpiderThread::ReBuildUrlIfNeed(CMyString &parentUrl,CMyString &url,CMyString &host)
{
	bool needRebuild=false;
	int len=url.GetStrLen();
	host	=CUrl::GetUrlHost(parentUrl);
	if(len>=4)
	{
		if(url[0]=='w'&&url[1]=='w'&&url[2]=='w'&&url[3]=='.')
		{
		}
		else if(url[0]=='b'&&url[1]=='b'&&url[2]=='s'&&url[3]=='.')
		{
		}
		else if(url[0]=='h'&&url[1]=='t'&&url[2]=='t'&&url[3]=='p')
		{
			if(len>=5&&url[4]==':')
			{
			}
			else
			{
				needRebuild=true;
			}
		}
		else
		{
			if(len>0&&url[0]=='.')
			{
				needRebuild=true;
			}
			else if(len>=3&&url[0]=='/'&&url[1]=='.'&&url[2]=='.')
			{
				needRebuild=true;
				len--;
				url.Erase(0,1);
			}
			else
			{
				int status=0;
				int i=0;
				for(;i<len;i++)
				{
					if(!status&&url[i]=='.')
					{
						status=1;
					}
					else if(status==1&&url[i]=='.')
					{
						break;
					}
					else if(status==1&&url[i]=='/')
					{
						break;
					}
				}
				if(i>=len)
					needRebuild=true;
			}
		}
	}
	else
	{
		needRebuild=true;
	}
	
	if(needRebuild)
	{
		CUrl lUrl(parentUrl);
		CMyString path=lUrl.GetUrlHost()+"/"+lUrl.GetUrlPath();
		int count=0;
		while(1)
		{
			if(url[0]=='.'&&url[1]=='.'&&url[2]=='/')
			{
				url.Erase(0,3);
				count++;
			}
			else
			{
				break;
			}
		}
		
		while(count)
		{
			count--;
			char *p=path.GetBuffer()+path.GetStrLen()-1;
			if(*p=='/')
			{
				path.EraseFromRight(1);
				p--;
			}
			char *e=p;
			while(p!=path.GetBuffer()&&*p!='/')p--;
			if(*p!='/')
			{
				_asm int 3;
			}
			else
			{
				if(count)
					path.EraseFromRight(e-p+1);
				else 
					path.EraseFromRight(e-p);
			}
		}