亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? httptse.cpp

?? 小型搜索引擎,用C/C++編寫,屬于全文搜索引擎
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <strings.h>#include <errno.h>#include <netdb.h>#include <unistd.h>#include <netinet/in.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/time.h>#include <fcntl.h>#include <iostream>#include "HttpTse.h"#include "Tse.h"#include "Url.h"#include "Page.h"#include "StrFun.h"int _checkBufSize(char **buf, int *bufsize, int more);using namespace std;char *userAgent = NULL;int timeout = DEFAULT_TIMEOUT;int hideUserAgent = 0;map<string,string> mapCacheHostLookup;typedef map<string,string>::value_type valTypeCHL;extern map<unsigned long,unsigned long> mapIpBlock;extern vector<string> vsUnreachHost;	/*         * Actually downloads the page, registering a hit (donation)         *      If the fileBuf passed in is NULL, the url is downloaded and then         *      freed; otherwise the necessary space is allocated for fileBuf.         *      Returns size of download on success, -1 on error is set,	 * 	-2 on 301.         */int HttpFetch(string strUrl, char **fileBuf, char **fileHeadBuf, char **location, int* nPSock ){	//const char *url_tmp = strUrl.c_str();	char *tmp, *url, *host, *charIndex, *requestBuf, *pageBuf;	int sock, bytesRead = 0, contentLength = -1, bufsize = REQUEST_BUF_SIZE;	int ret = -1, i=-1, tempSize, selectRet;	//if(url_tmp == NULL){	if( strUrl.empty() ){		cout << "strUrl is NULL" << endl;		return -1;	}	/* Copy the url passed in into a buffer we can work with, change, etc. */	//url = (char*)malloc(strlen(url_tmp)+1);	url = (char*)malloc(strUrl.length()+1);	if(url == NULL){		cout << "can not allocate enought memory for url" << endl;		return -1;	}	memset(url, 0,strUrl.length()+1);	//memset(url, strlen(url_tmp)+1, 0);	//strncpy(url, url_tmp, strlen(url_tmp) + 1);	memcpy(url, strUrl.c_str(), strUrl.length() );	charIndex = strstr(url, "://");	if(charIndex != NULL){		/* url contains a protocol field */		charIndex += strlen("://");		host = charIndex;		charIndex = strchr(charIndex, '/');	}else{		host = (char *)url;		charIndex = strchr(url, '/');	}	/* Compose a request string */	requestBuf = (char*)malloc(bufsize);	if(requestBuf == NULL){		free(url);		cout << "can not allocate enought memory for requestBuf" << endl;		return -1;	}	requestBuf[0] = 0;	if(charIndex == NULL){		/* The url has no '/' in it, assume the user is making a root-level                 *      request */		tempSize = strlen("GET /") + strlen(HTTP_VERSION) +1;		if( tempSize > bufsize ){			free(url);			free(requestBuf);			cout << "tempSize larger than bufsize" << endl;			return -1;		}		if(_checkBufSize(&requestBuf, &bufsize, tempSize) ||			snprintf(requestBuf, bufsize, "GET / %s\n", 			HTTP_VERSION) < 0 )		{			free(url);			free(requestBuf);			cout << "1._checkBuffSize(&requestBuf..) error" << endl;			return -1;		}		//requestBuf = "GET / " + (string)HTTP_VERSION + "\n";	}else{		tempSize = strlen("GET ") + strlen(charIndex) + strlen(HTTP_VERSION) + 3;		if(_checkBufSize(&requestBuf, &bufsize, tempSize) ||			snprintf(requestBuf, bufsize, "GET %s %s\n", 			charIndex, HTTP_VERSION) < 0)		{			free(url);			free(requestBuf);			cout << "2._checkBuffSize(&requestBuf..) error" << endl;			return -1;		}		//requestBuf = "GET / " + (string)charIndex + HTTP_VERSION + "\n";				}	/* Null out the end of the hostname if need be */	if(charIndex != NULL){		*charIndex = 0;	}	/* Use Host: even though 1.0 doesn't specify it.  Some servers         *      won't play nice if we don't send Host, and it shouldn't hurt anything */	tempSize = (int)strlen("Host: ") + (int)strlen(host) + 2;/* +2 for "\n\0" */	if(_checkBufSize(&requestBuf, &bufsize, tempSize + 128)){		free(url);		free(requestBuf);		cout << "3._checkBuffSize(&requestBuf..) error" << endl;		return -1;	}	strcat(requestBuf, "Host: ");	strcat(requestBuf, host);	strcat(requestBuf, "\n");	if(!hideUserAgent && userAgent == NULL) {		tempSize = (int)strlen("User-Agent: ") +			(int)strlen(DEFAULT_USER_AGENT) + (int)strlen(VERSION) + 3;		if(_checkBufSize(&requestBuf, &bufsize, tempSize)) {			free(url);			free(requestBuf);			cout << "4._checkBuffSize(&requestBuf..) error" << endl;			return -1;		}		strcat(requestBuf, "User-Agent: ");		strcat(requestBuf, DEFAULT_USER_AGENT);		strcat(requestBuf, "/");		strcat(requestBuf, VERSION);		strcat(requestBuf, "\n");	} else if(!hideUserAgent) {		tempSize = (int)strlen("User-Agent: ") + (int)strlen(userAgent) + 2;		if(_checkBufSize(&requestBuf, &bufsize, tempSize)) {			free(url);			free(requestBuf);			cout << "5._checkBuffSize(&requestBuf..) error" << endl;			return -1;		}		strcat(requestBuf, "User-Agent: ");		strcat(requestBuf, userAgent);		strcat(requestBuf, "\n");	}	//tempSize = (int)strlen("Connection: Close\n\n");	tempSize = (int)strlen("Connection: Keep-Alive\n\n");	if(_checkBufSize(&requestBuf, &bufsize, tempSize)) {		free(url);		free(requestBuf);		cout << "6._checkBuffSize(&requestBuf..) error" << endl;		return -1;	}	//strcat(requestBuf, "Connection: Close\n\n");	strcat(requestBuf, "Connection: Keep-Alive\n\n");	/* Now free any excess memory allocated to the buffer */	tmp = (char *)realloc(requestBuf, strlen(requestBuf) + 1);	if(tmp == NULL){		free(url);		free(requestBuf);		cout << "realloc for tmp error" << endl;		return -1;	}	requestBuf = tmp;	if( *nPSock != -1 ){		sock = *nPSock;		cout << "using privous socket" << *nPSock << endl;	}else{		cout << "1.get a new one" << endl;		sock = MakeSocket(host);		if(sock == -1) { 			free(url); 			free(requestBuf);			cout << "1.not able to MakeSocket" << endl;			return -1;		}		if(sock == -2) { 			free(url); 			free(requestBuf);			cout << "2.not able to MakeSocket" << endl;			return -1;		}	}		//cout << "requestBuf is " << requestBuf << endl;	if(write(sock, requestBuf, strlen(requestBuf)) == -1){		cout << "write error" << endl;		close(sock);		*nPSock  = -1;		cout << "2.close previous socket " << *nPSock << " and get a new one" << endl;		//maybe sock is dead,try again		sock = MakeSocket(host);		if(sock == -1) { 			free(url);			free(requestBuf);			cout << "3.not able to MakeSocket" << endl;			return -1;		}		if(sock == -2) { 			free(url);			free(requestBuf);			cout << "4.not able to MakeSocket" << endl;			return -1;		}		if(write(sock, requestBuf, strlen(requestBuf)) == -1){			close(sock);			*nPSock = -1;			free(url);			free(requestBuf);			cout << "write error" << endl;			return -1;		}	}	free(url);	free(requestBuf);	char headerBuf[HEADER_BUF_SIZE];	/* Grab enough of the response to get the metadata */	memset( headerBuf,0,HEADER_BUF_SIZE );	//cout << "old sock is " << sock << endl;	ret = _http_read_header(sock, headerBuf);	//cout << "ret = " << ret << endl;	if(ret < 0) { 		close(sock); 		*nPSock = -1;		cout << "_http_read() error " << endl;		return -1;	}	//cout << headerBuf << endl;	charIndex = strstr(headerBuf, "HTTP/");	if(charIndex == NULL){		close(sock);		*nPSock = -1;		cout << headerBuf << endl;		cout << "strstr() error " << endl;		return -1;	}	while(*charIndex != ' '){		charIndex++;	}	charIndex++;		ret = sscanf(charIndex, "%i", &i);	if(ret != 1){		close(sock); 		*nPSock = -1;		cout << "sscanf() error" << endl;		return -1;	}	#ifdef DEBUG	// http return code		cout <<"######Http return code: ######" << endl << i << endl;	#endif	// deal with http://net.cs.pku.edu.cn/~cnds	if(i == 301 || i == 302){		char *loc;		loc = (char*)malloc(URL_LEN);		if(loc == NULL){			close(sock);			*nPSock = -1;			cout << "malloc error" << endl;			return -1;		}		charIndex = strstr(headerBuf, "Location:");		if(charIndex != NULL){			//ret = sscanf(charIndex + strlen("Location: "), "%(URL_LEN-1)s",loc);			ret = sscanf(charIndex + strlen("Location: "), "%255s",loc);			if(ret != 1){				close(sock);				*nPSock = -1;				cout << headerBuf << endl;				cout << "sscanf() error" << endl;				return -1;			} else{				*location = loc;				close(sock);				*nPSock = -1;				//cout << "sscanf() else error" << endl;				return -2;			}		}	}	if(i<200 || i>299 ){		close(sock);		*nPSock = -1;		cout << "ret code = " << i << " < 200 or > 299" << endl;		return -1;	}	charIndex = strstr(headerBuf, "Content-Length:");	if(charIndex == NULL){		charIndex = strstr(headerBuf, "Content-length:");	}	if(charIndex == NULL){		/* Allocate enough memory to hold the page */		//if(contentLength == -1){			contentLength = DEFAULT_PAGE_BUF_SIZE;		//}	}else{		ret = sscanf(charIndex + strlen("content-length: "), "%i", 			&contentLength);		if(ret < 1){			close(sock);			*nPSock = -1;			cout << "sscanf() error" << endl;			return -1;		}	}	if(contentLength < 20){		contentLength = DEFAULT_PAGE_BUF_SIZE;	}	if(contentLength > MAX_PAGE_BUF_SIZE){		cout << "the page discarde due to its size " << contentLength 			<< " is larger than " << MAX_PAGE_BUF_SIZE << endl;		//close(sock);		return -1;	}	#ifdef DEBUG	// http content length		cout <<"######Content length: ######" << endl << contentLength << endl;	#endif	pageBuf = (char *)malloc(contentLength);	if(pageBuf == NULL){		close(sock);		*nPSock = -1;		cout << "malloc for pageBuf" << endl;		return -1;	}	        /* Begin reading the body of the file */	fd_set rfds;	struct timeval tv;	int flags;	flags=fcntl(sock,F_GETFL,0);        if(flags<0){		close(sock);		*nPSock = -1;		free(pageBuf);		cout << "1.fcntl() error " << endl;		return -1;	}        flags|=O_NONBLOCK;        if(fcntl(sock,F_SETFL,flags)<0){		close(sock);		*nPSock = -1;		free(pageBuf);		cout << "2.fcntl() error " << endl;		return -1;	}	int pre_ret=0;	while(ret > 0){		FD_ZERO(&rfds);		FD_SET(sock, &rfds);		if( bytesRead == contentLength ){			tv.tv_sec = 1;		}else{			tv.tv_sec = timeout;		}		tv.tv_usec = 0;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品网站在线观看| 国内精品久久久久影院一蜜桃| 精品人在线二区三区| 欧美视频在线一区二区三区| 日本二三区不卡| 在线亚洲免费视频| 欧美专区日韩专区| 欧美天堂亚洲电影院在线播放| 91农村精品一区二区在线| 不卡一区二区中文字幕| av日韩在线网站| 色综合天天视频在线观看| 色狠狠一区二区三区香蕉| 在线精品亚洲一区二区不卡| 欧美日韩在线三区| 在线综合视频播放| 日韩一级黄色片| 久久久久久久综合日本| 成人app下载| 色综合天天综合给合国产| 在线一区二区视频| 91精品国产欧美一区二区成人| 国产馆精品极品| 97成人超碰视| 欧美怡红院视频| 7777精品伊人久久久大香线蕉的| 51久久夜色精品国产麻豆| 欧美va天堂va视频va在线| 国产三级欧美三级日产三级99 | 欧美一区二区三区四区视频 | 欧美精品在欧美一区二区少妇| 欧美日本在线观看| 精品国产第一区二区三区观看体验| 久久久久97国产精华液好用吗| 国产精品久久久久久亚洲毛片 | 亚洲一区免费视频| 麻豆精品一区二区综合av| 国产成人av一区二区三区在线观看| 99久久精品久久久久久清纯| 另类小说欧美激情| 成人高清免费观看| 欧美日韩aaaaaa| 精品久久人人做人人爰| 自拍视频在线观看一区二区| 天堂蜜桃91精品| 国产精品一品视频| 欧美网站一区二区| 久久青草欧美一区二区三区| 一区二区三区国产精华| 精品亚洲成a人| 在线视频观看一区| 久久久亚洲国产美女国产盗摄 | 精品一区二区在线观看| 91香蕉视频在线| 精品国产免费视频| 玉米视频成人免费看| 韩国成人在线视频| 欧美午夜精品免费| 国产日韩欧美麻豆| 亚洲成av人**亚洲成av**| 国产精品伊人色| 这里只有精品视频在线观看| 中文字幕日本乱码精品影院| 日本vs亚洲vs韩国一区三区 | 成人免费高清视频在线观看| 欧美日韩久久一区| 中文字幕在线一区| 久久精品国产亚洲一区二区三区| 色综合久久久网| 久久久久97国产精华液好用吗| 日韩精品一级中文字幕精品视频免费观看| 91麻豆精品国产91久久久久久久久| 国产成人av福利| 正在播放亚洲一区| 亚洲综合丁香婷婷六月香| 久久综合九色综合欧美就去吻 | 亚洲激情第一区| 亚洲婷婷综合色高清在线| 久久99九九99精品| 精品一区二区三区香蕉蜜桃| 欧美日韩国产片| 亚洲免费大片在线观看| 国产一区二区h| 在线观看一区日韩| 欧美三级中文字| 玉米视频成人免费看| 99精品视频一区| 国产精品三级在线观看| 国产乱码精品一区二区三区av| 欧美一级视频精品观看| 亚洲成a人片综合在线| 色综合网色综合| 亚洲精品中文在线观看| 9久草视频在线视频精品| 中文字幕av免费专区久久| 国产精品美女视频| 国产成人免费在线视频| 久久综合九色综合欧美就去吻| 麻豆精品新av中文字幕| 日韩一区二区三区电影 | 99精品视频在线播放观看| 中文无字幕一区二区三区| 国产成人午夜精品5599| 久久伊人蜜桃av一区二区| 国产一区二区三区视频在线播放| 欧美videos大乳护士334| 麻豆精品久久精品色综合| 日韩久久久久久| 国产一区二区三区在线观看免费视频| 欧美成人综合网站| 精品一区二区三区免费视频| 日韩欧美一区二区免费| 蜜桃av一区二区| 久久综合九色综合97婷婷女人 | 色狠狠桃花综合| 一区2区3区在线看| 欧美日韩国产综合一区二区| 日韩国产在线一| 91精品国产91久久久久久最新毛片 | 欧美日韩不卡在线| 麻豆视频一区二区| 久久久国产精品午夜一区ai换脸| 国产精品白丝jk黑袜喷水| 国产精品天美传媒| 91啪亚洲精品| 首页综合国产亚洲丝袜| 日韩一区二区免费在线观看| 精品无码三级在线观看视频 | 久久精品国产网站| 久久日韩粉嫩一区二区三区 | 国产丝袜在线精品| 91免费版pro下载短视频| 亚洲成人1区2区| 精品毛片乱码1区2区3区| 国产99一区视频免费| 亚洲精品日韩一| 日韩一级精品视频在线观看| 国产黑丝在线一区二区三区| 一区二区三区中文在线观看| 欧美日韩在线三级| 国产白丝网站精品污在线入口| 一色屋精品亚洲香蕉网站| 欧美日韩在线不卡| 国产一区二区三区四区五区美女 | 中文一区一区三区高中清不卡| 欧洲人成人精品| 激情五月激情综合网| 亚洲日穴在线视频| 日韩一区二区高清| 99久久精品免费| 日本欧美一区二区三区| 日本一区二区视频在线| 欧美视频三区在线播放| 国精产品一区一区三区mba桃花| 亚洲色图视频免费播放| 日韩丝袜美女视频| 99精品1区2区| 久草精品在线观看| 一区二区三区四区视频精品免费| 日韩三级.com| 色综合天天综合在线视频| 久久不见久久见免费视频7| 亚洲精选免费视频| 久久精品免费在线观看| 欧美理论片在线| youjizz久久| 久草这里只有精品视频| 欧美变态口味重另类| 一本大道久久a久久精品综合| 国模套图日韩精品一区二区 | 91久久精品国产91性色tv| 国产伦精品一区二区三区免费迷 | 免费av网站大全久久| 自拍偷拍欧美精品| 国产午夜精品在线观看| 欧美高清你懂得| 91久久精品一区二区二区| av在线这里只有精品| 麻豆精品一区二区av白丝在线| 亚洲国产另类av| 中文字幕在线不卡国产视频| 亚洲精品一区二区三区香蕉| 欧美日韩国产小视频在线观看| thepron国产精品| 国产乱码字幕精品高清av| 欧美国产国产综合| 久久综合狠狠综合久久综合88 | 欧美不卡视频一区| 7777女厕盗摄久久久| 欧美艳星brazzers| 91视频观看视频| 成人h动漫精品一区二| 国产乱理伦片在线观看夜一区| 美女视频黄a大片欧美| 天堂蜜桃91精品| 午夜精品一区二区三区电影天堂| 欧美一区二区三区免费视频| 精品视频在线免费| 91传媒视频在线播放| 欧美性色黄大片|