140 lines
2.3 KiB
C++
140 lines
2.3 KiB
C++
#ifndef headerfile_libscorpiohttpserver_src_server_h
|
|
#define headerfile_libscorpiohttpserver_src_server_h
|
|
|
|
|
|
#include <sys/select.h>
|
|
#include "client.h"
|
|
|
|
|
|
|
|
class Server
|
|
{
|
|
public:
|
|
|
|
|
|
Server();
|
|
virtual ~Server();
|
|
|
|
|
|
void CloseMainSocket();
|
|
void CloseClientSockets();
|
|
void Close();
|
|
|
|
void PrepareMainSocket();
|
|
void Wait();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Client> client_tab;
|
|
int main_socket;
|
|
fd_set read_set, write_set;
|
|
std::wstring tmp_header, tmp_value;
|
|
size_t header_index;
|
|
std::string url_ascii;
|
|
bool close_server;
|
|
|
|
|
|
int AddSocketsToSet();
|
|
void AddNewClient();
|
|
|
|
// change to a better name as it is used to write to a client too
|
|
void ReadInputFromClients();
|
|
|
|
void ReadInputFromClient(Client & client);
|
|
void WriteOutputToClient(Client & client);
|
|
|
|
void CheckHeaders(Client & client, size_t input_buffer_index);
|
|
|
|
|
|
// ptr buffer should consists of at least more 3 characters
|
|
bool IsHeadersEnding(const char * ptr);
|
|
|
|
void ParseHeaders(Client & client);
|
|
bool ParseFirstHeader(Client & client);
|
|
|
|
|
|
bool ParseFirstHeaderMethodName(Client & client);
|
|
|
|
|
|
virtual bool SelectMethodName(Client & client, wchar_t * method_name);
|
|
|
|
|
|
/*
|
|
* The generic URI syntax mandates that new URI schemes that provide for the representation
|
|
* of character data in a URI must, in effect, represent characters from the unreserved set
|
|
* without translation, and should convert all other characters to bytes according to UTF-8,
|
|
* and then percent-encode those values. This requirement was introduced in January 2005
|
|
* with the publication of RFC 3986. URI schemes introduced before this date are not affected.
|
|
*
|
|
*
|
|
*/
|
|
bool ParseFirstHeaderURL(Client & client);
|
|
|
|
bool ParseFirstHeaderHTTPVersion(Client & client);
|
|
|
|
|
|
|
|
// ParseHeaderKey should increment header_index at least once
|
|
bool ParseHeaderKey(Client & client);
|
|
|
|
|
|
void ParseHeaderValue(Client & client);
|
|
|
|
|
|
//void RemoveClientSocket(int client_socket);
|
|
|
|
|
|
bool IsDecDigit(wchar_t c);
|
|
bool IsHexDigit(wchar_t c);
|
|
int HexDigitToValue(wchar_t c);
|
|
wchar_t ToLower(wchar_t c);
|
|
bool CompareNoCase(const wchar_t * str1, const wchar_t * str2);
|
|
bool CompareNoCase(const std::wstring & str1, const wchar_t * str2);
|
|
|
|
// do not use \r or \n here
|
|
bool IsWhite(wchar_t c);
|
|
|
|
void TrimWhiteAtEnd(std::wstring & str);
|
|
void SkipWhite(Client & client);
|
|
virtual void CreateAnswer(Client & client);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|