Skip to content

Commit ac9c331

Browse files
committed
Initial buffer support
1 parent bb200f8 commit ac9c331

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

src/http.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include "config.h"
3+
#endif /* HAVE_CONFIG_H */
4+
5+
#include "http.h"
6+
7+
HttpConnection::HttpConnection() {
8+
}
9+
10+
HttpConnection::~HttpConnection() {
11+
}
12+
13+
bool
14+
HttpConnection::addPacket(const Buffer& data) {
15+
return false;
16+
}

src/http.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __HTTP_H__
2+
#define __HTTP_H__
3+
4+
#include "tcp.h"
5+
6+
#include <list>
7+
#include <string>
8+
9+
using namespace std;
10+
11+
class Buffer;
12+
13+
class HttpConnection : public TcpConnection {
14+
public:
15+
HttpConnection();
16+
virtual ~HttpConnection();
17+
18+
virtual bool addPacket(const Buffer& data);
19+
20+
private:
21+
list<pair<string, string>> mRequestHeaders;
22+
Buffer* mRequestBody;
23+
list<pair<string, string>> mResponseHeaders;
24+
Buffer* mResponseBody;
25+
};
26+
27+
#endif /* __HTTP_H__ */

src/tcp.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ TcpAddress::TcpAddress(const struct in_addr& addr, unsigned short port) {
4747
mPort = port;
4848
}
4949

50+
TcpAddress::TcpAddress(string hostname, unsigned short port) : mHostname(hostname), mPort(port) {
51+
}
52+
5053
TcpAddress::~TcpAddress() {
5154
}
5255

@@ -59,3 +62,14 @@ unsigned short
5962
TcpAddress::getPort() const {
6063
return mPort;
6164
}
65+
66+
TcpConnection::TcpConnection() : mLocal("192.168.1.1", 1234), mRemote("stringer.jibemobile.com", 8080) {
67+
}
68+
69+
TcpConnection::~TcpConnection() {
70+
}
71+
72+
TcpConnection*
73+
TcpConnection::newConnection() {
74+
return nullptr;
75+
}

src/tcp.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Netmask {
8989
class TcpAddress {
9090
public:
9191
TcpAddress(const struct in_addr& addr, unsigned short port);
92+
TcpAddress(string hostname, unsigned short port);
9293
virtual ~TcpAddress();
9394

9495
string getHostname() const;
@@ -99,4 +100,34 @@ class TcpAddress {
99100
unsigned short mPort;
100101
};
101102

103+
enum TcpConnectionState {
104+
NONE,
105+
NEW,
106+
ESTABLISHED,
107+
CLOSED
108+
};
109+
110+
class TcpConnection {
111+
public:
112+
TcpConnection();
113+
virtual ~TcpConnection();
114+
115+
virtual bool addPacket(const Buffer& data) = 0;
116+
117+
static TcpConnection* newConnection();
118+
119+
private:
120+
TcpAddress mLocal;
121+
TcpAddress mRemote;
122+
TcpConnectionState mState;
123+
};
124+
125+
class TcpConnectionManager {
126+
public:
127+
static TcpConnection* getConnection();
128+
129+
private:
130+
static list<pair<pair<TcpAddress, TcpAddress>, TcpConnection*>> sConnections;
131+
};
132+
102133
#endif /* __TCP_H__ */

0 commit comments

Comments
 (0)