a8/a8/mixedsession.cc
aozhiwei cefcdd78b0 1
2018-10-09 14:21:10 +08:00

61 lines
1.4 KiB
C++

#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <netinet/tcp.h>
#include <a8/a8.h>
#include <a8/openssl.h>
#include <a8/mixedsession.h>
namespace a8
{
static bool IsHttpHead(char* buf, int buflen)
{
return (buflen > 4 && strncmp("GET ", buf, 4) == 0) ||
(buflen > 4 && strncmp("get ", buf, 4) == 0) ||
(buflen > 5 && strncmp("POST ", buf, 5) == 0) ||
(buflen > 5 && strncmp("post ", buf, 5) == 0);
}
void MixedSession::Reset()
{
a8::BaseHttpSession::Reset();
is_first_packet_ = true;
}
void MixedSession::Destory()
{
a8::TcpSession::Destory();
is_first_packet_ = true;
}
void MixedSession::DecodePacket(char* buf, int& offset, unsigned int buflen)
{
if (is_first_packet_) {
if (IsHttpHead(buf, buflen)) {
buf[buflen] = '\0';
ProcessHandShake(buf, offset, buflen);
} else {
DecodeUserPacket(buf, offset, buflen);
}
is_first_packet_ = offset == 0;
} else {
DecodeUserPacket(buf, offset, buflen);
}
}
void MixedSession::ProcessHandShake(char* buf, int& offset, unsigned int buflen)
{
char* pend = strstr(buf + offset, "\r\n\r\n");
if (!pend) {
return;
}
ProcessHttpHandShake(buf, offset, buflen);
}
}