-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket_handler.h
54 lines (44 loc) · 989 Bytes
/
websocket_handler.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
#ifndef __WEBSOCKET_HANDLER__
#define __WEBSOCKET_HANDLER__
#include <arpa/inet.h>
#include <iostream>
#include <map>
#include <sstream>
#include <queue>
#include <algorithm>
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "base64.h"
#include "sha1.h"
#include "debug_log.h"
#include "websocket_request.h"
#define MAGIC_KEY "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
enum WEBSOCKET_STATUS {
WEBSOCKET_UNCONNECT = 0,
WEBSOCKET_HANDSHARKED = 1,
};
typedef std::map<std::string, std::string> HEADER_MAP;
class Websocket_Handler{
public:
Websocket_Handler(int fd);
~Websocket_Handler();
int process();
inline char *getbuff();
void *netw;
private:
int wshandshark();
void parse_str(char *request);
int fetch_http_info();
int send_data(char *buff);
private:
char buff_[2048];
WEBSOCKET_STATUS status_;
HEADER_MAP header_map_;
int fd_;
Websocket_Request *request_;
};
inline char *Websocket_Handler::getbuff(){
return buff_;
}
#endif