-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecvMsgLiFilter.cpp
More file actions
210 lines (163 loc) · 4.69 KB
/
RecvMsgLiFilter.cpp
File metadata and controls
210 lines (163 loc) · 4.69 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "RecvMsgLiFilter.h"
#include "WFCLPAPI.h"
#include "GloabeParams.h"
#include "CIdResource.h"
void writeLog(std::string& message,EServer* es);
std::string numToStr(int id);
CRecvMsgLiFilter::CRecvMsgLiFilter(io_service& io,short port1,QObject *parent)
: CRecvMsg(io,port1,parent),recvLen(21)
{
}
CRecvMsgLiFilter::~CRecvMsgLiFilter(void)
{
}
void CRecvMsgLiFilter::procBuff(int recv_len)
{
procLen=tmpLen+recv_len;
pProcBuff=new char[procLen];
memcpy_s(pProcBuff,tmpLen,pProcTmp,tmpLen);
memcpy_s(pProcBuff+tmpLen,recv_len,pRecvBuff,recv_len);
int headLen=4;
unsigned int headflag=0;
if(pProcTmp)
{
delete [] pProcTmp;
pProcTmp=NULL;
}
int leftLen=procLen;
while(true)
{
if(leftLen<headLen)
{
pProcTmp=new char[leftLen];
memcpy_s(pProcTmp,leftLen,pProcBuff+(procLen-leftLen),leftLen);
tmpLen=leftLen;
break;
}
memcpy_s(&headflag,headLen,pProcBuff+(procLen-leftLen),headLen);
//if(selfHead->flag!=0xaabbccdd||selfHead->dataLength>256)
if(headflag!=0xaabbccdd)
{
leftLen=leftLen-1;
//QString content=tr("¶ªÊ§Í¬²½Í·");
//QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
//idR->insertLog(relateDevice,content);
continue;
}
leftLen=leftLen-headLen;
int packetlen=17;
if((leftLen<packetlen))
{
pProcTmp=new char[leftLen+headLen];
memcpy_s(pProcTmp,leftLen+headLen,pProcBuff+(procLen-leftLen-headLen),leftLen+headLen);
tmpLen=leftLen+headLen;
break;
}
LiFilterS liFilterS;
memcpy_s(&liFilterS,packetlen,pProcBuff+(procLen-leftLen),packetlen);
proData(liFilterS);
leftLen=leftLen-packetlen;
}
delete [] pProcBuff;
}
void CRecvMsgLiFilter::proData(LiFilterS liFilterS)
{
int lfsLen=sizeof(LiFilterS);
memcpy_s(&liFilterS,lfsLen,pRecvBuff,lfsLen);
int ruleID=uploadRuleLiFilter(liFilterS);
LiSendS liSendS;
liSendS.head=0xaabbccdd;
liSendS.cmdType=1;
liSendS.ruleId=ruleID;
int lssLen=sizeof(LiSendS);
char* pSendBuff=new char[lssLen];
memcpy_s(pSendBuff, lssLen, (char*)&liSendS, lssLen );
sendLiFilter->write(pSendBuff,lssLen);
delete pSendBuff;
}
void CRecvMsgLiFilter::accept_handler(const boost::system::error_code& ec,sock_pt sock)
{
if(ec)
{
ip=sock->remote_endpoint().address().to_string();
std::string message=ip+" "+numToStr(port)+"Á¬½ÓÒì³£";
writeLog(message,es);
return;
}
start();
ip=sock->remote_endpoint().address().to_string();
QString content=QString(tr("ÒÑÁ¬½Ó"));
QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
idR->insertLog(relateDevice,content);
std::string message=ip+" "+numToStr(port)+"ÒÑÁ¬½Ó";
writeLog(message,es);
try{
sock->async_read_some(boost::asio::buffer(pRecvBuff, recvLen),
bind(&CRecvMsg::read_handler, this,
placeholders::error,
placeholders::bytes_transferred,sock));
//boost::posix_time::time_duration td(0,0,2,0);
//boost::this_thread::sleep(td);
}
catch (std::exception& e)
{
//std::cerr << "Exception: " << e.what() << "/n";
std::string message=ip+" "+numToStr(port)+" "+e.what();
writeLog(message,es);
}
}
void CRecvMsgLiFilter::read_handler(const boost::system::error_code& ec,size_t bytes_transferred,sock_pt sock)
{
if (ec)
{
//std::string message=numToStr(port)+"¶ÁÒì³£";
//writeLog(message,es);
ip=sock->remote_endpoint().address().to_string();
QString content=QString(tr("¶ÁÒì³£"));
QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
idR->insertLog(relateDevice,content);
std::string message=ip+" "+numToStr(port)+"¶ÁÒì³£";
writeLog(message,es);
return;
}
//ip=sock->remote_endpoint().address().to_string();
//std::string message=ip+" "+numToStr(port)+"ÒÑÁ¬½Ó";
//writeLog(message,es);
int recv_len=bytes_transferred;
try{
if(recv_len!=0)
{
procBuff(recv_len);
}
sock->async_read_some(boost::asio::buffer(pRecvBuff, recvLen),
bind(&CRecvMsgLiFilter::read_handler, this,
placeholders::error,
placeholders::bytes_transferred,sock));
/*QString content=QString(tr("Ïß³Ì״̬Õý³£"));
QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
idR->insertLog(relateDevice,content);*/
//boost::posix_time::time_duration td(0,0,2,0);
//boost::this_thread::sleep(td);
}
catch (std::exception& e)
{
//std::cerr << "Exception: " << e.what() << "/n";
//std::string message=numToStr(port)+" "+e.what();
//writeLog(message,es);
QString content=QString(tr("%1")).arg(e.what());
QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
idR->insertLog(relateDevice,content);
}
}
std::string CRecvMsgLiFilter::intToIp(int value)
{
return message1;
}
int CRecvMsgLiFilter::uploadRuleLiFilter(LiFilterS liFilterS)
{
SACL sacl;
sacl.id=assignACLID();
wfclpapi->sacl=sacl;
int ret=wfclpapi->uploadACL();
return ruleId;
}