-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathServer.h
executable file
·130 lines (103 loc) · 2.59 KB
/
Server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef _SERVER_H
#define _SERVER_H
#include <WinSock2.h>
#include <string>
#include <fstream>
#define AppVersion "1.0beta"
#define DEFAULT_PORT "80"
#define BUFFER_SIZE 1024*5 // 5KB
#define ACC_EXT_NUM 48
#define OS_TYPE_NUM 9
using std::string;
// ERROR HANDLING
extern std::ofstream logger;
extern void logError(string msg,int GetLastError=0);
extern string ToString(int data);
class Server
{
public:
Server(void);
// Main Functions
void Init(); // Initialize Server
void Start(); // Start server
void Stop(); // Close Server
void Communicate(); // Main Loop.
void ErrorQuit(); // Quit And Display An Error Message
// IPs Input/Output
void setServerIP(string ip);
void setClientIP(string ip);
string getServerIP();
string getClientIP();
// Main CMD Display
struct CommandLine{
CommandLine();
void Display();
void Add(string msg);
void Clear();
// Content
string _cmdMessage;
}*CMD;
private:
// Initialize
void loadContentType();
void loadOSTypes();
void resetError();
// Browser Request Manipulation
void checkRequest();
void getCommands();
bool isDirectory();
bool checkFileExists();
bool checkFileExtension();
void checkDataLenght();
// Pass Info To Variables
int getFileRequest();
int getUserAgent();
int getBrowserInfo();
int getOSInfo();
int getAcceptedContent();
// Header Creation
void createHeader();
void resetHeader();
string _header;
string _headerStatus;
string _headerType;
string _redirectLocation;
string _contentLenght;
// Communication Functions
string getMessage(); // Receive Browser Requests
int sendFile();
void sendHeader(); // Send Header Info
void sendMessage(string msg); // Send Text Files
int sendData(char*data); // Send Other Type Files In Binary
void closeConnection(); // Close Connections
// Initialize
int _handleReturn;
WORD _socketVersion;
WSADATA _wsaData;
SOCKET _listeningSocket;
SOCKET _connectionSocket;
addrinfo _hints,*_result;
int _maxConnections;
// Communication Content
int _sendData;
int _bytesReceived;
int _bytesSend;
// Server Info
string _serverIP;
string _clientIP;
string _port;
string _acceptedExtension[ACC_EXT_NUM];
string _contentType[ACC_EXT_NUM];
string _OSType[OS_TYPE_NUM];
// Browser Request Data
string _browserData;
string _fileName;
string _filePath;
string _fileExt;
string _fileType;
int _fileSize;
string _userAgentData;
string _browserInfo;
string _OSInfo;
};
#endif