int main()
{
	try
	{
		LogFile dummy;
		dummy.write("Writing from main");
	}
	catch (const LogFileException& ex)
	{
		cerr << ex.what();
	}
	
	try
	{
		LogFile logFile("Exceptions.log");
		logFile.write("Writing from main");
		logFile.write("Writing from main - again");
	}
	catch (const LogFileException& ex)
	{
		cerr << ex.what();
	}
	
	getchar();
}
Пример #2
0
		virtual	void	handleRec(const LogRecordPtr& rec)
		{
			if (logfile.isOpen() && !ignore(rec))
			{
				std::string msg;
				formatLog(rec, msg);
				hasWriten+= logfile.write(msg.c_str(), msg.length());
				if (hasWriten >= flushEvery) {
					logfile.flush();
					hasWriten -= flushEvery;
				}
			}
		}
Пример #3
0
int Response::ParseHttpHEAD( SSL* inSSL )
{
	string buf;

	bool isGET = false;
	bool isProtocolVersion_1_1 = false;
	bool isWebSocket = false;
	bool isWebSocketVersion_13 = false;
	string FileName;
	string FileType;
	string WebSocketKey;

	try
	{
		// We are getting string with HTTTP HEAD

		MyCover mySendRecv;
		mySendRecv.my_recv(inSSL, buf);

		cout << buf; 

		WSLexer mLexer;
		const char* buff_s = buf.c_str();
		mLexer.Put_HttpRequest( buff_s,  buff_s + buf.size() );

		bool ContinueToCycle = false;
		WSLexer::Token currToken;
		WSLexer::Token prevToken;

		ContinueToCycle = mLexer.GetNextToken(&currToken, true);
		while(ContinueToCycle)
		{
			string strToken(currToken.ps, currToken.mLen);

			// Find type of request
			if( currToken.mPosition == 0 && currToken.mLine == 1 && strToken == "GET" )
				isGET = true;

			// Find FileName
			if( currToken.mLine == 1 && prevToken.mType == wsDefaultType && strToken == "." )
			{
				ContinueToCycle = mLexer.GetNextToken(&currToken, true);
				strToken = string(currToken.ps, currToken.mLen);

				if( currToken.mType == wsDefaultType && currToken.mLine == 1 )
				{
					FileType = string(currToken.ps, currToken.mLen);
					FileName = string(prevToken.ps, prevToken.mLen);
				}	
				else
				{
					continue; // we have to go to the next iteration of the loop without using function GetNextToken
				}
			}

			// Check version of HTTP
			if( currToken.mLine == 1 && strToken == "HTTP")
			{
				ContinueToCycle = mLexer.GetNextToken(&currToken, true);
				if(currToken.mLine == 1 && currToken.mType == wsSymbolType && *(currToken.ps) == '/' )
				{
					ContinueToCycle = mLexer.GetNextToken(&currToken, true);
					strToken = string(currToken.ps, currToken.mLen);

					if( strToken != "2")
					{
						ContinueToCycle = mLexer.GetNextToken(&currToken, true);
						strToken += string(currToken.ps, currToken.mLen);
						ContinueToCycle = mLexer.GetNextToken(&currToken, true);
						strToken += string(currToken.ps, currToken.mLen);
						
						if( strToken == "1.1")
						{
							isProtocolVersion_1_1 = true;
						}
					}
				}
				else
				{
					continue; // we have to go to the next iteration of the loop without using function GetNextToken
				}

			}

			// This is WebSocket? If not we stop parcing
			if( strToken == "Upgrade" )
			{
				ContinueToCycle = mLexer.GetNextToken(&currToken, true);

				if( string(currToken.ps, currToken.mLen) == ":" )
				{
					ContinueToCycle = mLexer.GetNextToken(&currToken, true);
					strToken = string(currToken.ps, currToken.mLen);
					if( strToken == "websocket" || strToken == "WebSocket" )
						isWebSocket = true;
					else
						break;
				}
				else
				{
					continue; // we have to go to the next iteration of the loop without using function GetNextToken
				}
			}

			// Find WebSocket Key
			if( strToken == "Sec-WebSocket-Key" )
			{
				ContinueToCycle = mLexer.GetNextToken(&currToken, true);
				if( string(currToken.ps, currToken.mLen) == ":" )
				{
					string PartOfKey;

					do
					{
						WebSocketKey += PartOfKey;
						ContinueToCycle = mLexer.GetNextToken(&currToken, true);
						PartOfKey = string(currToken.ps, currToken.mLen);
					}
					while(PartOfKey != "\n" && PartOfKey != "\r");
				}
				else
				{
					continue; // we have to go to the next iteration of the loop without using function GetNextToken
				}
			}

			// Check version of WebSocket? we work only with version 13
			if( strToken == "Sec-WebSocket-Version" )
			{
				ContinueToCycle = mLexer.GetNextToken(&currToken, true);
				if( string(currToken.ps, currToken.mLen) == ":" )
				{
					ContinueToCycle = mLexer.GetNextToken(&currToken, true);
					if(string(currToken.ps, currToken.mLen) == "13")
						isWebSocketVersion_13 = true;
				}
				else
				{
					continue; // we have to go to the next iteration of the loop without using function GetNextToken
				}
			}

			prevToken = currToken;
			ContinueToCycle = mLexer.GetNextToken(&currToken, true);
		}

		GenerateResponse(
			inSSL, 
			isGET, 
			isProtocolVersion_1_1,
			isWebSocket,
			isWebSocketVersion_13,
			FileName,
			FileType,
			WebSocketKey);
	}
	catch(exception& e)
	{
		LogFile log;
		log.write(e.what());
	}

	return 0;
}