CPage类中的函数

 

CPage::NormalizeUrl

//规格化链接
bool CPage::NormalizeUrl(string& strUrl){ string::size_type idx;
//查找http://
if( CStrFun::FindCase(strUrl, "http://") == string::npos ) return false;
// convert " http://e.pku.cn" to " http://e.pku.cn/"
//从url最后查找/ //如果没有/,那么自动添加一个斜杠
idx = strUrl.rfind('/'); if( idx < 8 ) { strUrl = strUrl + "/"; return true; }
//去除/./
//http://e.pku.cn/./sds/../index.jsp
while( (idx=strUrl.find("/./")) != string::npos ){ if( idx != string::npos ) strUrl.erase(idx,2); }
//http://e.pku.cn/sds/../index.jsp
while( (idx = strUrl.find("/../")) != string::npos ){ string strPre,strSuf;
//去除../ //http://e.pku.cn/sds/index.jsp
//strPre= http://e.pku.cn/sds
strPre = strUrl.substr(0, idx);
//strSuf= index.jsp if( strUrl.length() > idx+4 ) strSuf = strUrl.substr(idx+4);
idx = strPre.rfind("/"); if( idx != string::npos) strPre = strPre.substr(0,idx+1); if( strPre.length() < 10 ) return false;
strUrl = strPre + strSuf; }
if( CStrFun::FindCase(strUrl, "http://") != 0 ) return false;
return true;}

CPage::IsFilterLink

//判断该url中是否有需要过滤的字符
//如果有,那么函数返回true;否则,返回false
bool CPage::IsFilterLink(string plink)
{ //空的url或者长度太长的url都是需要处理的,返回true
if( plink.empty() ) return true; if( plink.size() > URL_LEN ) return true;
string link = plink, tmp; string::size_type idx = 0;
//将link字符串转换成小写
CStrFun::Str2Lower( link, link.length() );
//http://www.whut.edu.cn/wa?name=admin
tmp = link;
//连接字符串中只能存在最多一个?
idx = tmp.find("?"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("?"); if( idx != string::npos ) return true; }
//连接字符串中只能存在最多一个- tmp = link; idx = tmp.find("-"); if( idx != string::npos ){ tmp = tmp.substr(idx+1);
//这里是不是写错了?应该是tmp.find("-"),是不是代码中缺少判断+
idx = tmp.find("+"); if( idx != string::npos ) return true; }
//连接字符串中只能存在最多一个&
//这个判断条件有问题,如果这个链接中有两个参数
//那么应该有两个&是合法的,但是这个函数却返回true
tmp = link; idx = tmp.find("&"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("&"); if( idx != string::npos ) return true; }
//连接字符串中只能存在最多一个//
tmp = link; idx = tmp.find("//"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("//"); if( idx != string::npos ) return true; }
//连接字符串中只能存在最多一个http
//但是我觉得这个判断条件有问题
//" http://www.whuthttp.edu.cn/a.jsp?name=admin";
//连接字符串中有两个http字样,但是这个链接是正确的
//但是这个函数却返回true
tmp = link; idx = tmp.find("http"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("http"); if( idx != string::npos ) return true; }
//misc是什么?
tmp = link; idx = tmp.find("misc"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("misc"); if( idx != string::npos ) return true; }
//ipb是什么? tmp = link; idx = tmp.find("ipb"); if( idx != string::npos ){ tmp = tmp.substr(idx+1); idx = tmp.find("ipb"); if( idx != string::npos ) return true; }
//应该过滤的字符集
const char *filter_str[]={ "cgi-bin", "htbin", "linder", "srs5", "uin-cgi",
"uhtbin", "snapshot", "=+", "=", "script", "gate", "search", "clickfile", "data/scop", "names", "staff/", "enter", "user", "mail", "pst?", "find?", "ccc?", "fwd?", "tcon?", "&amp", "counter?", "forum", "cgisirsi", "{", "}", "proxy", "login", "00.pl?", "sciserv.pl", "sign.asp", "<", ">", "review.asp?", "result.asp?", "keyword", "/"", "'", "php?s=", "error", "showdate", "niceprot.pl?", "volue.asp?id", ".css", ".asp?month", "prot.pl?", "msg.asp", "register.asp", "database", "reg.asp", "qry?u", "p?msg", "tj_all.asp?page", ".plot.", "comment.php", "nicezyme.pl?", "entr", "compute-map?", "view-pdb?", "list.cgi?", "lists.cgi?", "details.pl?", "aligner?", "raw.pl?", "interface.pl?","memcp.php?", "member.php?", "post.php?", "thread.php", "bbs/", "/bbs" };
int filter_str_num = 75;
//如果这个链接中存在filter_str中的一个值,那么就返回true
//循环将上面的过滤字符集合中的每一个字符串在url中查找
//如果找到,那么返回true
//以上条件都不满足,即这个url是不需要过滤的,那么返回false
return false;}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值