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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? reqsock.cpp

?? 也是個(gè)http服務(wù)器
?? CPP
?? 第 1 頁 / 共 3 頁
字號(hào):
// ReqSock.cpp : implementation of the CRequestSocket class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1997-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "HttpSvr.h"
#include "HttpDoc.h"
#include "Http.h"
#include "ReqSock.h"
#include "Request.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CRequestSocket, CAsyncSocket)

#define CRLF    "\x0d\x0a"

SECURITY_ATTRIBUTES g_sa = {sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};

CRequestSocket::CRequestSocket( void )
{
}

CRequestSocket::CRequestSocket( CHttpSvrDoc* pDoc )
{
#ifdef IMPL_CGI
	m_pThread = NULL;
	m_pCancel = NULL;
#endif // IMPL_CGI
	m_bKilled = FALSE;
	m_nRefs = 1;
	m_reqStatus = REQ_REQUEST;
	m_buf.SetSize( 1024 );
	m_cbOut = 0;
	m_hFile = INVALID_HANDLE_VALUE;
	m_pRequest = NULL;
	m_pDoc = pDoc;
}

CRequestSocket::~CRequestSocket( void )
{
	// JIC....
#ifdef IMPL_CGI
	if ( m_pCancel )
	{
		if ( m_pThread )
		{
			DWORD dwCode;
			// signal a cancel if still running....
			if ( ::GetExitCodeThread( m_pThread->m_hThread, &dwCode )
				&& dwCode == STILL_ACTIVE )
			{
				// signal a cancel....
				m_pCancel->SetEvent();
				// wait for the thread to die....
				WaitForSingleObject( m_pThread->m_hThread, INFINITE );
			}
			// kill the object...
			delete m_pThread;
		}
		delete m_pCancel;
	}
#endif // IMPL_CGI

	if ( m_hFile )
		CloseHandle( m_hFile );

	if ( m_pRequest )
	{
		// release our hold on the request object....
		m_pRequest->m_bDone = TRUE;
		m_pRequest->Release();
	}
}

void CRequestSocket::OnReceive(int nErrorCode)
{
	if ( m_pRequest == NULL )
	{
		// new request....
		m_pRequest = new CRequest;
		m_bKeepOpen = m_bWantKeepOpen = FALSE;
	}
	if ( m_pRequest )
	{
		// get the bytes....
		int nBytes = Receive( m_buf.GetData(), m_buf.GetSize() );
		if ( nBytes != SOCKET_ERROR )
		{
			int ndx = 0;
			switch ( m_reqStatus )
			{
			case REQ_REQUEST:
			case REQ_HEADER:
				while( GetLine( m_buf, nBytes, ndx ) == TRUE )
				{
					if ( !m_strLine.IsEmpty() )
						ProcessLine();
					else
					{
						m_reqStatus = REQ_BODY;
						break;
					}
				}
				// break if we're not looking for the body....
				if ( m_reqStatus != REQ_BODY )
					break;
				// stop if no body sent....
				if ( !BodySent() )
				{
					m_reqStatus = REQ_DONE;
					break;
				}
				// else fall through....
			case REQ_BODY:
				AddToBody( nBytes, ndx );
				break;
			}
			if ( m_reqStatus == REQ_DONE )
			{
				m_buf.SetSize(0);
				if ( !StartResponse() )
					AsyncSelect( FD_WRITE | FD_CLOSE );
			}
		}
		else
			nBytes = GetLastError();
	}
	else
	{
		// couldn't allocate request object....
		ShutDown( both );
		m_bKilled = TRUE;
		Release();
	}
}

void CRequestSocket::OnSend(int nErrorCode)
{
	int nBytes = Send( m_buf.GetData(), m_cbOut );
	if ( nBytes == SOCKET_ERROR )
	{
		if ( GetLastError() != WSAEWOULDBLOCK )
		{
			ShutDown( both );
			m_bKilled = TRUE;
			Release();
		}
		else
			AsyncSelect( FD_WRITE | FD_CLOSE );
	}
	else if ( nBytes < m_cbOut )
	{
		// still got some left....
		m_buf.RemoveAt( 0, nBytes );
		m_cbOut -= nBytes;
		// adjust the bytes-sent value for the request....
		m_pRequest->m_cbSent += nBytes;
		// set up for next write....
		AsyncSelect( FD_WRITE | FD_CLOSE );
	}
	else
	{
		// adjust the bytes-sent value for the request....
		m_pRequest->m_cbSent += nBytes;
		// if we're not done with the file....
		if ( m_hFile != INVALID_HANDLE_VALUE )
		{
			DWORD dwRead = 0;
			// read next chunk....
			ReadFile( m_hFile, m_buf.GetData(),
				m_buf.GetSize(), &dwRead, NULL );
			if ( dwRead > 0 )
				m_cbOut = dwRead;
			else
			{
				// no more data to send....
				CloseHandle( m_hFile );
				m_hFile = INVALID_HANDLE_VALUE;
			}
		}
		// see if we need to keep going....
		if ( m_hFile != INVALID_HANDLE_VALUE )
			AsyncSelect( FD_WRITE | FD_CLOSE );
		else
		{
			// eh, we're outta here....
			ShutDown( both );
			m_bKilled = TRUE;
			Release();
		}
	}
}

void CRequestSocket::OnClose(int nErrorCode)
{
	m_bKilled = TRUE;
	Release();
}

BOOL CRequestSocket::GetLine( const CByteArray& bytes, int nBytes, int& ndx )
{
	BOOL bLine = FALSE;
	while ( bLine == FALSE && ndx < nBytes )
	{
		char ch = (char)(bytes.GetAt( ndx ));
		switch( ch )
		{
		case '\r': // ignore
			break;
		case '\n': // end-of-line
			bLine = TRUE;
			break;
		default:   // other....
			m_strLine += ch;
			break;
		}
		++ndx;
	}
	return bLine;
}

void CRequestSocket::ProcessLine( void )
{
	int ndx;
	switch( m_reqStatus )
	{
	case REQ_REQUEST:
		ndx = m_strLine.Find( ' ' );
		if ( ndx != -1 )
		{
			m_pRequest->m_strMethod = m_strLine.Left( ndx );
			m_strLine = m_strLine.Mid( ndx+1 );
			m_strLine.TrimLeft();
			ndx = m_strLine.Find( ' ' );
			if ( ndx == -1 )
			{
				m_pRequest->m_strURL = m_strLine;
				m_pRequest->m_strURL.TrimRight();
				m_reqStatus = REQ_SIMPLE;
			}
			else
			{
				m_pRequest->m_strURL = m_strLine.Left( ndx );
				m_pRequest->m_strVersion = m_strLine.Mid( ndx+1 );
				m_pRequest->m_strVersion.TrimLeft();
			}
			// check for execution arguments....
			ndx = m_pRequest->m_strURL.Find( '?' );
			if ( ndx != -1 )
			{
				// yup; save the args....
				m_pRequest->m_strArgs = m_pRequest->m_strURL.Mid( ndx+1 );
				// strip from file name....
				m_pRequest->m_strURL = m_pRequest->m_strURL.Left( ndx );
				m_pRequest->m_dwExecute = CRequest::APP_EXECUTE;
			}

			// change any "%xx"s to the appropriate char....
			m_pRequest->m_strURL = Decode( m_pRequest->m_strURL );
		}
		m_reqStatus = REQ_HEADER;
		break;
	case REQ_HEADER:
		ndx = m_strLine.Find( ':' );
		if ( ndx != -1 )
		{
			CString strName = m_strLine.Left( ndx );
			CString strValue = m_strLine.Mid( ndx+1 );
			strName.MakeLower();
			strValue.TrimLeft();
			m_pRequest->m_mapHeaders.SetAt( strName, strValue );
		}
		break;
	};
	m_strLine.Empty();
}

BOOL CRequestSocket::BodySent( void )
{
	BOOL bSent = FALSE;
	CString strValue = m_pRequest->GetHeaderValue( "Content-Length" );
	if ( !strValue.IsEmpty() )
	{
		m_pRequest->m_cbBody = atoi( strValue );
		bSent = TRUE;
	}
	return bSent;
}

void CRequestSocket::AddToBody( int nBytes, int ndx )
{
	// save the buffer size....
	int nOldSize = m_buf.GetSize();
	// get rid of old stuff; append to body data....
	m_buf.RemoveAt( 0, ndx );
	m_buf.SetSize( nBytes - ndx );
	m_pRequest->m_baBody.Append( m_buf );
	// restore the buffer size....
	m_buf.SetSize( nOldSize );
	// see if we're done....
	if ( m_pRequest->m_baBody.GetSize() >= m_pRequest->m_cbBody )
	{
		m_pRequest->m_baBody.SetSize( m_pRequest->m_cbBody );
		m_reqStatus = REQ_DONE;
	}
}

BOOL CRequestSocket::StartResponse( void )
{
	BOOL bWait = FALSE;
	CString strFile;
	UINT uPort;
	// save the host address....
	GetPeerName( m_pRequest->m_strHost, uPort );
	// switch on the method....
	if ( m_pRequest->m_cbBody == 0 &&
		m_pRequest->m_strMethod.CompareNoCase( "GET" ) == 0 )
	{
		FindTarget( strFile );
		if( m_pRequest->m_uStatus == 0 )
		{
			if ( m_pRequest->m_dwExecute )
				bWait=StartSvrApp();
			else
			{
				if ( StuffHeading() )
					StartTargetStuff();
			}
		}
	}
	else if ( m_pRequest->m_cbBody == 0 && m_reqStatus == REQ_DONE &&
		m_pRequest->m_strMethod.CompareNoCase( "HEAD" ) == 0 )
	{
		FindTarget( strFile );
		if( m_pRequest->m_uStatus == 0 )
		{
			if ( m_pRequest->m_dwExecute )
				bWait=StartSvrApp();
			else
			{
				StuffHeading();
				// we don't send the file for HEAD reqs....
				if ( m_hFile != INVALID_HANDLE_VALUE)
				{
					CloseHandle( m_hFile );
					m_hFile = INVALID_HANDLE_VALUE;
				}
			}
		}
	}
	else if ( m_pRequest->m_cbBody > 0 && m_reqStatus == REQ_DONE &&
		m_pRequest->m_strMethod.CompareNoCase( "POST" ) == 0 )
	{
		// assume an executable....
		m_pRequest->m_dwExecute = CRequest::APP_EXECUTE;
		FindTarget( strFile );
		if ( m_pRequest->m_uStatus == 0 )
		{
			bWait=StartSvrApp();
		}
	}
	else
		StuffError( IDS_STATUS_NOTIMPL );

	// notify the active view of the hit....
	m_pDoc->DocHit( m_pRequest );
	return bWait;
}

BOOL CRequestSocket::FindTarget( CString& strFile )
{
	BOOL bFound = FALSE;
	strFile = m_pRequest->m_strURL;
	// change from URL to local file system path....
	if ( URLtoPath( strFile ) )
	{
		CString strExtra; // extra path info
		m_pRequest->m_dwAttr = GetFileAttributes( strFile );
		if ( m_pRequest->m_dwAttr != -1 )
			bFound = TRUE;
		else
		{
			// rip off the last portion....
			strExtra = StripLast( strFile );
			while( !strFile.IsEmpty() )
			{
				// anything there?
				m_pRequest->m_dwAttr = GetFileAttributes( strFile );
				if ( m_pRequest->m_dwAttr != -1 )
				{
					// found something; better not be a folder....
					if( (m_pRequest->m_dwAttr&FILE_ATTRIBUTE_DIRECTORY) == 0 )
						bFound = TRUE;
					break;
				}
				// rip off the next portion....
				strExtra = StripLast( strFile ) + strExtra;
			}
		}

		if ( bFound )
		{
			// strip any trailing SEPCHAR....
			if ( strFile.GetAt( strFile.GetLength()-1) == SEPCHAR )
				m_pRequest->m_strFullPath = strFile.Left( strFile.GetLength()-1 );
			else
				m_pRequest->m_strFullPath = strFile;

			// see if we need to set the extra path info....
			if ( !strExtra.IsEmpty() )
			{
				m_pRequest->m_strPathInfo = strExtra;
				if ( URLtoPath( strExtra ) )
					m_pRequest->m_strPathTranslated = strExtra;
			}

			// if it's a folder, see if we can redirect to
			// on of the default docs or apps....
			if ( m_pRequest->m_dwAttr & FILE_ATTRIBUTE_DIRECTORY )
			{
				// check for existence of a default doc or app....
				if ( !CheckDefault( IDS_DEFAULTDOC, FALSE ) )
					CheckDefault( IDS_DEFAULTAPP, TRUE );
			}
			else if ( m_pRequest->m_dwExecute && !IsSvrApp() )
			{
				StuffError( IDS_STATUS_BADREQUEST );
			}
		}
		else
			StuffError( IDS_STATUS_NOTFOUND );
	}
	else
		StuffError( IDS_STATUS_BADREQUEST );

	return bFound;
}

BOOL CRequestSocket::URLtoPath( CString& strFile )
{
	BOOL bLegal = FALSE;
	CString& strRoot = m_pDoc->m_strRoot;

	// start with the root, append the abs path....
	CString strTemp = strRoot + strFile;
	// now canonicalize it....
	DWORD dwSize = GetFullPathName( strTemp, MAX_PATH, strFile.GetBuffer(MAX_PATH+1), NULL );
	strFile.ReleaseBuffer();

	// get the full path okay?
	if ( dwSize )
	{
		int cchRoot = strRoot.GetLength();
		int cchFile = strFile.GetLength();
		// must be the same or longer than the root....
		if ( cchRoot == cchFile )
		{
			// must be exactly the same....
			if ( strRoot.Compare( strFile ) == 0 )
				bLegal = TRUE;
		}
		else if ( cchRoot < cchFile )
		{
			// must have the root as the base....
			if ( strRoot.Compare( strFile.Left(cchRoot) ) == 0
				&& strFile.GetAt( cchRoot ) == SEPCHAR )
				bLegal = TRUE;
		}
	}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美成人国产一区二区| 成人av电影在线播放| 国产露脸91国语对白| 国产成人精品亚洲午夜麻豆| 91女神在线视频| 欧美一区二区三区色| 国产三级三级三级精品8ⅰ区| 国产精品嫩草久久久久| 亚洲国产一区视频| 国产一区二区在线看| 91美女片黄在线观看91美女| 91精品国产91久久久久久最新毛片| 国产肉丝袜一区二区| 亚洲午夜久久久久久久久久久| 久久精品国产久精国产| 91伊人久久大香线蕉| 日韩免费福利电影在线观看| 最近中文字幕一区二区三区| 日本视频免费一区| av一区二区不卡| 精品日本一线二线三线不卡| 亚洲日本青草视频在线怡红院 | 国产成人精品午夜视频免费| 91国偷自产一区二区三区成为亚洲经典 | 美女在线观看视频一区二区| 粉嫩久久99精品久久久久久夜| 欧美日韩一卡二卡| 国产精品久久久久一区二区三区| 奇米四色…亚洲| 色综合一个色综合亚洲| 精品国产一区二区三区四区四| 亚洲美女一区二区三区| 激情欧美日韩一区二区| 欧美自拍偷拍午夜视频| 久久先锋影音av鲁色资源网| 亚洲无线码一区二区三区| 国产高清精品久久久久| 日韩视频免费观看高清完整版| 中文字幕五月欧美| 国产剧情av麻豆香蕉精品| 欧美精品视频www在线观看| 国产精品久久久久aaaa| 精品中文字幕一区二区小辣椒| 欧洲一区二区三区在线| 中文字幕va一区二区三区| 久久国产精品无码网站| 欧美精品v国产精品v日韩精品 | 成人自拍视频在线观看| 欧美二区三区的天堂| 亚洲色图一区二区| 成人app软件下载大全免费| 久久蜜桃一区二区| 麻豆一区二区三| 6080亚洲精品一区二区| 亚洲一区日韩精品中文字幕| 色综合一区二区三区| 中文字幕在线一区免费| 国产成人免费在线视频| 欧美mv和日韩mv的网站| 日韩电影免费在线| 欧美高清hd18日本| 婷婷中文字幕一区三区| 欧美精品在线观看播放| 亚洲国产精品一区二区久久恐怖片 | 91高清视频在线| 亚洲桃色在线一区| aaa亚洲精品| 中文字幕中文字幕一区二区| 北岛玲一区二区三区四区| 日本一区二区三区久久久久久久久不| 久久av资源网| 26uuu欧美日本| 国产一区久久久| 久久精品网站免费观看| 国产精品一区2区| 国产午夜一区二区三区| 成人性生交大片| 国产精品国产三级国产aⅴ无密码| 成人黄色小视频在线观看| 国产精品丝袜91| 99久久久国产精品| 亚洲欧美另类在线| 欧美在线啊v一区| 五月激情丁香一区二区三区| 欧美一区二区三区视频在线观看| 美腿丝袜亚洲综合| 久久奇米777| 成人国产精品免费| 亚洲免费视频中文字幕| 欧美色图片你懂的| 日本亚洲视频在线| xfplay精品久久| 成人午夜免费av| 一区二区三区不卡视频在线观看| 欧美制服丝袜第一页| 日本不卡一区二区| 久久久国产精品麻豆| 99r国产精品| 香港成人在线视频| 精品国产99国产精品| 国产成人在线看| 亚洲欧美日韩久久| 欧美男人的天堂一二区| 奇米精品一区二区三区在线观看| 欧美精品一区二区精品网| 成人av在线一区二区三区| 亚洲美女一区二区三区| 欧美一区二区三区四区五区| 国产精品一区二区在线播放| 亚洲桃色在线一区| 91精品国产丝袜白色高跟鞋| 国产一区二区三区美女| 亚洲激情校园春色| 日韩精品一区二区三区视频播放| 成人网页在线观看| 亚洲一区二区成人在线观看| 久久伊人蜜桃av一区二区| 91麻豆6部合集magnet| 亚洲国产综合91精品麻豆| 久久综合久久99| 欧美视频一区二区三区四区| 国模大尺度一区二区三区| 自拍偷拍国产精品| 欧美成人一区二区三区| 91麻豆国产精品久久| 久久 天天综合| 亚洲激情综合网| 久久久99久久| 欧美日韩国产小视频| 成人短视频下载| 日本aⅴ亚洲精品中文乱码| 亚洲欧洲成人自拍| 日韩午夜激情电影| 在线亚洲+欧美+日本专区| 久久91精品久久久久久秒播| 亚洲一区二区三区精品在线| 国产女人aaa级久久久级| 欧美日韩一级黄| 国产成人h网站| 日韩电影在线免费| 一区二区三区在线观看网站| 久久九九99视频| 欧美一区二区三区小说| 色欧美日韩亚洲| 丰满放荡岳乱妇91ww| 日本强好片久久久久久aaa| 亚洲美腿欧美偷拍| 国产精品日韩精品欧美在线 | 国产酒店精品激情| 五月激情综合婷婷| 亚洲一区在线视频观看| 国产欧美综合在线观看第十页 | 激情都市一区二区| 日韩和欧美一区二区三区| 亚洲影视在线观看| 中文字幕综合网| 国产欧美综合色| 久久婷婷成人综合色| 日韩欧美卡一卡二| 欧美一三区三区四区免费在线看| 972aa.com艺术欧美| 成人毛片视频在线观看| 韩国v欧美v日本v亚洲v| 青娱乐精品视频在线| 亚洲成人黄色小说| 亚洲电影在线免费观看| 亚洲伦理在线免费看| 亚洲天堂网中文字| 一区在线观看免费| 亚洲欧洲av一区二区三区久久| 欧美国产日韩亚洲一区| 国产免费观看久久| 国产日产欧产精品推荐色| 久久精品一二三| 国产日韩高清在线| 国产亚洲欧美日韩日本| 久久精品男人天堂av| 久久精品欧美日韩| 中文字幕欧美日本乱码一线二线 | 成人免费视频视频在线观看免费| 久久99精品视频| 韩国女主播成人在线观看| 久久国产三级精品| 国内欧美视频一区二区| 狠狠色丁香久久婷婷综| 国产精品自拍三区| 国产精品羞羞答答xxdd| 国产精品资源网站| 国产成人av一区二区三区在线| 国产不卡视频在线播放| 成人精品免费视频| 成人久久久精品乱码一区二区三区 | 欧美久久高跟鞋激| 这里只有精品视频在线观看| 欧美一级片免费看| 欧美大片在线观看一区| 久久综合中文字幕| 国产精品乱码一区二区三区软件| 国产精品网站导航| 亚洲人精品一区|