61 lines
1.4 KiB
C++
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);
|
|
}
|
|
|
|
}
|