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

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

?? reqsock.cpp

?? 也是個http服務器
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
// 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;
		}
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
懂色av一区二区三区免费看| 波波电影院一区二区三区| 26uuu亚洲婷婷狠狠天堂| 成人免费看黄yyy456| 日日摸夜夜添夜夜添精品视频 | 亚洲视频1区2区| 日韩一级视频免费观看在线| 99re6这里只有精品视频在线观看 99re8在线精品视频免费播放 | 日本亚洲三级在线| 亚洲免费观看高清| 久久精品男人的天堂| 国产欧美一区在线| 欧美日韩国产天堂| 97se亚洲国产综合自在线| 国内外成人在线| 三级不卡在线观看| 亚洲一二三四久久| 中文字幕在线一区二区三区| 久久久91精品国产一区二区三区| 欧美精品v国产精品v日韩精品| 91亚洲大成网污www| 粉嫩蜜臀av国产精品网站| 卡一卡二国产精品 | 99久久精品国产一区| 久久99精品国产91久久来源| 午夜精品福利在线| 亚洲夂夂婷婷色拍ww47| 亚洲欧美在线视频| 中文字幕一区二区三区av| 国产偷v国产偷v亚洲高清 | 中文字幕日韩一区二区| 国产亚洲精品aa| 精品日韩欧美在线| 日韩欧美一区二区在线视频| 777奇米成人网| 91精品在线观看入口| 欧美精品久久久久久久多人混战| 欧美日韩综合一区| 欧美午夜寂寞影院| 欧美亚洲图片小说| 精品视频免费在线| 91精品国产综合久久久久久久久久 | 欧美不卡一区二区三区四区| 欧美一二区视频| 精品国产乱码久久久久久久 | 欧美日韩mp4| 在线综合视频播放| 日韩欧美国产三级| 26uuu精品一区二区| 国产亚洲一区二区三区| 国产欧美在线观看一区| 最新欧美精品一区二区三区| 亚洲欧美二区三区| 亚洲午夜一区二区| 人妖欧美一区二区| 国模套图日韩精品一区二区| 国产成人精品影视| 91色九色蝌蚪| 欧美日韩mp4| 欧美精品一区二区三| 国产欧美日韩视频在线观看| 国产精品国模大尺度视频| 亚洲欧美日韩中文字幕一区二区三区| 一区二区免费视频| 日韩av一区二| 国产寡妇亲子伦一区二区| 99re视频精品| 欧美日韩国产色站一区二区三区| 日韩欧美一区二区三区在线| 国产亲近乱来精品视频| 亚洲乱码国产乱码精品精98午夜| 丝袜亚洲另类丝袜在线| 韩国欧美一区二区| 91原创在线视频| 在线成人av网站| 久久久91精品国产一区二区精品 | av亚洲精华国产精华| 91精品91久久久中77777| 日韩一区二区影院| 亚洲国产精品高清| 天天综合日日夜夜精品| 狠狠色2019综合网| 91视频观看免费| 欧美成人一区二区三区| 亚洲欧美另类小说| 麻豆国产欧美一区二区三区| 成人动漫一区二区| 91精品国产麻豆国产自产在线| 日本一区二区在线不卡| 亚洲一二三区视频在线观看| 国产精选一区二区三区| 欧美日韩激情一区二区三区| 亚洲国产精品av| 日本不卡123| 91麻豆产精品久久久久久| 日韩精品一区国产麻豆| 成人欧美一区二区三区白人| 国产曰批免费观看久久久| 欧美系列亚洲系列| 欧美经典一区二区| 美日韩一级片在线观看| 在线观看精品一区| 国产精品久久久久久久浪潮网站| 免费黄网站欧美| 欧美视频完全免费看| 国产精品久久久久久久久免费樱桃| 视频精品一区二区| 日本乱人伦aⅴ精品| 国产精品免费看片| 韩国毛片一区二区三区| 欧美一二三四在线| 日韩vs国产vs欧美| 欧美日韩中文字幕精品| 国产精品久久久久久久久免费樱桃| 韩国理伦片一区二区三区在线播放| 欧美日韩国产综合视频在线观看 | 欧美专区在线观看一区| 国产精品免费网站在线观看| 精品一二线国产| 在线综合+亚洲+欧美中文字幕| 亚洲午夜私人影院| 一本大道久久a久久综合| 国产精品日日摸夜夜摸av| 国产精品18久久久久久久久久久久| 日韩视频永久免费| 日韩激情视频网站| 欧美一区二区三级| 午夜精品一区在线观看| 在线观看不卡视频| 亚洲最色的网站| 91黄色免费观看| 日韩理论片中文av| 91麻豆自制传媒国产之光| 综合在线观看色| 色哟哟国产精品| 亚洲成人在线观看视频| 欧美日韩国产bt| 日本亚洲电影天堂| 精品日韩一区二区三区免费视频| 精品制服美女丁香| 久久精品在线观看| av成人老司机| 一区二区三区**美女毛片| 欧美色视频一区| 日韩av电影一区| 欧美成va人片在线观看| 国产成人av资源| 亚洲日本丝袜连裤袜办公室| 91精彩视频在线观看| 亚洲自拍偷拍综合| 欧美日韩精品一区视频| 美女久久久精品| 国产网站一区二区| 一本色道a无线码一区v| 亚洲成人精品一区| 日韩欧美一区二区三区在线| 国产寡妇亲子伦一区二区| 亚洲三级视频在线观看| 欧美日韩一二区| 美女脱光内衣内裤视频久久影院| 久久久蜜桃精品| 99久久精品国产精品久久| 亚洲自拍欧美精品| 91精品国产丝袜白色高跟鞋| 国产精品一区二区黑丝| 亚洲欧洲精品一区二区三区| 欧美日韩一区二区三区四区五区| 成人午夜免费av| 亚洲尤物在线视频观看| 欧美一级欧美一级在线播放| 粉嫩欧美一区二区三区高清影视| 亚洲一区二区在线免费观看视频| 日韩一区二区在线观看视频| 不卡视频一二三四| 爽好久久久欧美精品| 中文字幕av一区二区三区高| 欧洲一区二区三区在线| 国内不卡的二区三区中文字幕 | 国产老妇另类xxxxx| 亚洲欧美日韩一区二区三区在线观看| 91麻豆精品国产91久久久更新时间 | 一区二区三区免费观看| 日韩一区二区三区在线视频| 91在线精品一区二区三区| 蜜桃视频在线观看一区| 亚洲三级小视频| 精品福利在线导航| 欧美日韩在线播放| 国产风韵犹存在线视精品| 午夜欧美大尺度福利影院在线看| wwwwww.欧美系列| 欧美视频在线播放| 国产成人鲁色资源国产91色综| 亚洲一区在线观看视频| 国产日韩欧美一区二区三区综合| 欧美巨大另类极品videosbest| 成人短视频下载| 国产一区啦啦啦在线观看| 亚洲图片欧美综合| 中文字幕亚洲欧美在线不卡|