亚洲欧美第一页_禁久久精品乱码_粉嫩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 if ( m_pRequest->m_cbBody == 0 && m_reqStatus == REQ_DONE &&
		m_pRequest->m_strMethod.CompareNoCase( "READ" ) == 0 )
	{
		// assume an executable....
		m_pRequest->m_dwExecute = CRequest::APP_NONE;
		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 )

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
2024国产精品| 色一情一乱一乱一91av| 成人黄色大片在线观看| 成人毛片在线观看| 91福利在线导航| 精品免费99久久| 国产精品久久久久影院色老大 | 精品中文字幕一区二区小辣椒| 国产精品一区二区在线播放 | 中文字幕精品综合| 亚洲欧美日韩精品久久久久| 亚洲一区av在线| 久久97超碰国产精品超碰| 成人动漫视频在线| 在线播放中文一区| 国产欧美精品区一区二区三区 | 欧美日韩在线三级| 欧美精品一区二区久久久| 中文字幕在线不卡一区| 婷婷成人综合网| 成人伦理片在线| 337p亚洲精品色噜噜| 国产精品天天看| 日韩二区在线观看| 成人成人成人在线视频| 欧美一级夜夜爽| 亚洲色图在线看| 国产一区久久久| 欧美亚洲动漫精品| 国产欧美一区二区三区在线看蜜臀| 一区二区视频在线看| 国产成人免费在线| 欧美一级一区二区| 亚洲一区二区三区三| 成人性生交大片免费看视频在线| 欧美一区二区三区男人的天堂| 国产精品美女久久久久久久网站| 欧美aaa在线| 欧美午夜电影网| 国产精品嫩草影院com| 日本美女一区二区三区视频| 91麻豆免费视频| 久久久久久99精品| 日韩黄色片在线观看| 色综合久久中文字幕综合网| 久久精品一区二区三区av| 日韩高清不卡一区二区三区| 色综合天天综合网天天看片| 欧美韩国日本一区| 黑人巨大精品欧美一区| 欧美一区二区三区四区五区| 亚洲最大色网站| 91同城在线观看| 国产精品丝袜一区| 国产精品1区2区| 欧美精品一区二区三区在线 | 日韩精品中文字幕一区二区三区| 亚洲一区二区三区激情| 91在线云播放| 国产精品国产三级国产a | 亚洲日本在线观看| 成人在线视频一区| 久久精品一区二区三区不卡牛牛| 久久99精品国产91久久来源| 欧美一区二区三区思思人| 亚洲大片精品永久免费| 欧美三级电影精品| 亚洲成a人片在线不卡一二三区| 一本色道久久综合狠狠躁的推荐| 国产精品麻豆99久久久久久| 成人永久aaa| 国产欧美中文在线| 国产999精品久久久久久绿帽| 久久奇米777| 国产一区二区久久| 欧美韩日一区二区三区四区| 国产999精品久久久久久绿帽| 中文字幕巨乱亚洲| www.亚洲精品| 日韩美女视频19| 欧美在线免费观看视频| 亚洲成人av福利| 欧美一区二区成人| 极品少妇一区二区三区精品视频 | 国产一区高清在线| 久久久久久久综合日本| 成人天堂资源www在线| 国产精品理论片在线观看| 91在线国产福利| 亚洲综合色婷婷| 欧美一区二区三区爱爱| 久久99国产精品免费网站| 国产视频不卡一区| av不卡一区二区三区| 亚洲黄色录像片| 91 com成人网| 久久99精品久久久久久| 国产精品嫩草影院com| 91在线免费播放| 亚洲不卡一区二区三区| 日韩无一区二区| 国产 欧美在线| 亚洲精品一二三| 91精品国产手机| 国产美女在线观看一区| 国产精品久久久久久久浪潮网站| 色八戒一区二区三区| 婷婷久久综合九色综合绿巨人| 欧美刺激午夜性久久久久久久| 国产成人午夜精品影院观看视频| 1024国产精品| 91精品欧美福利在线观看| 国产精品一级片| 一区二区视频在线| 精品国产免费一区二区三区香蕉| 成人在线视频一区| 无码av中文一区二区三区桃花岛| 久久久久久久久97黄色工厂| 91高清视频在线| 激情综合色丁香一区二区| 自拍偷拍国产精品| 日韩欧美高清一区| av中文字幕不卡| 日韩av电影一区| 国产精品久久夜| 日韩一区二区免费电影| 不卡区在线中文字幕| 丝袜a∨在线一区二区三区不卡| 国产亚洲成av人在线观看导航| 欧美视频一区二区三区四区| 国产精品亚洲综合一区在线观看| 亚洲午夜羞羞片| 久久久精品中文字幕麻豆发布| 欧美吻胸吃奶大尺度电影| 国产毛片精品视频| 亚洲成人av在线电影| 国产精品久久久久久久久久久免费看 | 欧美视频一区二区三区| 国产成人一级电影| 日韩成人一区二区| 成人免费一区二区三区在线观看 | 激情六月婷婷久久| 亚洲一区二区视频| 亚洲国产成人一区二区三区| 9191成人精品久久| 在线中文字幕一区| 国产成a人亚洲| 蜜臀va亚洲va欧美va天堂| 一区二区三区**美女毛片| 久久九九久久九九| 日韩美女在线视频 | 蜜臀av一级做a爰片久久| 亚洲日本青草视频在线怡红院 | 国产精品一级片在线观看| 日韩avvvv在线播放| 亚洲少妇中出一区| 欧美激情一区在线观看| 欧美电影免费观看完整版| 欧美日韩国产高清一区| 99久久精品费精品国产一区二区| 国产一区二区精品久久| 麻豆精品国产91久久久久久| 亚洲精品亚洲人成人网| 国产精品久久久久aaaa| 久久精品视频在线看| 欧美xxxxx裸体时装秀| 欧美一区二区三区精品| 欧美狂野另类xxxxoooo| 欧美亚洲国产一卡| 91麻豆精东视频| 93久久精品日日躁夜夜躁欧美| 成人午夜免费av| 成人在线一区二区三区| 国产成人综合网站| 国产一区美女在线| 国产乱码字幕精品高清av| 九九在线精品视频| 激情久久五月天| 国产毛片一区二区| 国产精品一区二区视频| 国产乱码字幕精品高清av| 国产精品夜夜爽| 国产成人精品综合在线观看 | 中文一区在线播放| 国产女人aaa级久久久级| 国产亚洲一区二区在线观看| 久久久久国产精品麻豆| 国产视频911| 国产精品乱码人人做人人爱 | 欧美撒尿777hd撒尿| 欧美日韩国产精品成人| 欧美精品 国产精品| 7777精品伊人久久久大香线蕉经典版下载| 欧美天堂亚洲电影院在线播放| 欧美日韩电影在线播放| 777xxx欧美| 亚洲精品一线二线三线无人区| 久久久天堂av| 亚洲特级片在线| 一区二区激情视频|