1 #if !defined(_NETWORKPROTOCOLS_H_) 2 #define _NETWORKPROTOCOLS_H_ 6 #include "DataMessage.h" 7 #include "NetworkConnections.h" 9 #define PROTOCOL_HTTP_SERVER 1 10 #define PROTOCOL_HTTP_CLIENT 2 11 #define PROTOCOL_MESSAGE 4 12 #define PROTOCOL_TELNET 8 13 #define PROTOCOL_3GCAM 16 14 #define ENCRYPTION_SSL 1 15 #define ENCRYPTION_AES 2 28 #define HTTP_OPTIONS 6 30 static char HTTP_Type[][8] =
63 return ( name.length() && content && contentSize );
65 bool setContent(
const char* content, uint32 size) {
66 if (!content)
return false;
67 this->contentSize = size;
68 this->content =
new char[size+1];
69 memcpy(this->content, content, size);
70 this->content[size] = 0;
84 HTTPRequest(uint64 source = 0, uint64 startRecTime = 0);
89 bool processHeader(
const char* buffer, uint32 size,
bool &isInvalid);
90 bool processContent(
const char* buffer, uint32 size);
91 const char* getHeaderEntry(
const char* entry);
92 const char* getRequest();
94 const char* getProtocol();
95 std::string decodeBasicAuthorization();
96 const char* getBasicAuthorization();
97 std::string getBasicAuthorizationUser();
98 std::string getBasicAuthorizationPassword();
99 bool setBasicAuthorization(
const char* authB64);
100 bool setBasicAuthorization(
const char* user,
const char* password);
101 const char* getParameter(
const char* entry);
102 const char* getPostData(
const char* entry, uint32& size,
const char** type);
103 const char* getPostData(
const char* entry, uint32& size);
104 const char* getPostDataType(
const char* entry);
105 bool parseURIParameters(
const char* text);
106 bool parseContentParameters(
const char* content, uint32 size);
107 bool parseContentChunk(
const char* chunk, uint32 size);
111 const char* getContent(uint32& size);
113 bool createRequest(uint8 type,
const char* host,
const char* uri,
const char* content, uint32 contentSize,
bool keepAlive, uint64 ifModifiedSince);
118 uint64 endReceiveTime;
121 uint32 contentLength;
122 uint64 ifModifiedSince;
126 std::map<std::string, std::string> entries;
127 std::map<std::string, std::string> params;
128 std::map<std::string, HTTPPostEntry*> postEntries;
129 std::string postBoundary;
132 #define TELNET_WINDOWS 1 133 #define TELNET_UNIX 2 140 bool setLine(
const char* buffer,
bool addCR);
141 bool setLine(
const char* buffer, uint32 len,
bool addCR =
false);
142 bool giveData(
char* buffer, uint32 len);
144 bool setCR(uint8 type);
162 #define HTTP_MOVED_PERMANENTLY 1 163 #define HTTP_USE_LOCAL_COPY 2 164 #define HTTP_MALFORMED_URL 3 165 #define HTTP_UNAUTHORIZED 4 166 #define HTTP_ACCESS_DENIED 5 167 #define HTTP_FILE_NOT_FOUND 6 168 #define HTTP_INTERNAL_ERROR 7 169 #define HTTP_NOT_IMPLEMENTED 8 170 #define HTTP_SERVICE_NOT_AVAILABLE 9 171 #define HTTP_GATEWAY_TIMEOUT 10 172 #define HTTP_SERVER_UNAVAILABLE 11 173 #define HTTP_SERVER_NOREPLY 12 174 #define HTTP_SERVER_MALFORMED_REPLY 13 176 static char HTTP_Status[][128] =
179 "HTTP/1.1 301 Moved Permanently",
180 "HTTP/1.1 304 Use Local Copy",
181 "HTTP/1.1 400 Bad Request <H1>Malformed URL</H1>",
182 "HTTP/1.1 401 Unauthorized",
183 "HTTP/1.1 403 Access Denied",
184 "HTTP/1.1 404 Object Not Found",
185 "HTTP/1.1 500 Internal Server Error <H1>Error while creating page</H1>",
186 "HTTP/1.1 501 Not Implemented <H1>Not implemented</H1>",
187 "HTTP/1.1 503 Service Unavailable <H1>Service Unavailable</H1>",
188 "HTTP/1.1 504 Gateway Timeout <H1>Gateway Timeout</H1>",
189 "HTTP/1.1 500 Internal Server Error <H1>Server unavailable</H1>",
190 "HTTP/1.1 500 Internal Server Error <H1>No reply from server</H1>",
191 "HTTP/1.1 500 Internal Server Error <H1>Malformed server reply</H1>" 196 static HTTPReply* CreateErrorReply(uint8 type);
197 static HTTPReply* CreateAuthorizationReply(
const char* realm);
204 bool processHeader(
const char* buffer, uint32 size,
bool &isInvalid);
205 bool processContent(
const char* buffer, uint32 size);
206 const char* getHeaderEntry(
const char* entry);
207 const char* getProtocol();
209 const char* getContent(uint32& size);
212 bool createPage(uint8 status, uint64 time,
const char* serverName,
213 uint64 lastMod,
bool keepAlive,
bool cache,
const char* contentType,
214 const char* content, uint32 contentSize = 0,
const char* additionalHeaderEntries = NULL);
216 bool createFromFile(uint64 time,
const char* serverName,
217 uint64 ifLastMod,
bool keepAlive,
bool cache,
218 const char* filename);
220 bool createOptionsResponse(uint8 status, uint64 time,
const char* serverName,
bool keepAlive,
const char* origin,
const char* operations);
221 bool createErrorPage(uint8 status, uint64 time,
const char* serverName,
bool keepAlive);
222 bool createAuthorizationReply(
const char* realm);
230 uint32 contentLength;
234 std::map<std::string, std::string> entries;
235 std::map<std::string, std::string> params;
247 static bool CheckBufferForCompatibility(
const char* buffer, uint32 length) {
return false;};
255 static bool CheckBufferForCompatibility(
const char* buffer, uint32 length);
267 static bool CheckBufferForCompatibility(
const char* buffer, uint32 length);
279 static bool CheckBufferForCompatibility(
const char* buffer, uint32 length);
289 static bool CheckBufferForCompatibility(
const char* buffer, uint32 length);
298 #endif // _NETWORKPROTOCOLS_H_ Definition: NetworkProtocols.h:194
Definition: NetworkProtocols.h:57
Definition: NetworkProtocols.h:285
Definition: NetworkProtocols.h:251
Definition: NetworkProtocols.h:135
Definition: NetworkProtocols.h:275
Definition: NetworkConnections.h:95
Definition: NetworkProtocols.h:81
Definition: NetworkProtocols.h:243
Definition: DataMessage.h:95
Definition: NetworkProtocols.h:263