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
|
#ifndef __HTTPREQUEST_H__
#define __HTTPREQUEST_H__
#include <string>
#include <cstring>
#include <pthread.h>
#include "log.h"
using namespace std;
struct cRange {
cRange(): isRangeRequest(false), begin(0), end(0) {};
bool isRangeRequest;
unsigned long long begin;
unsigned long long end;
};
enum eConnState {
WAITING,
SERVING,
TOCLOSE
};
class cHttpResource {
public:
cHttpResource(int, int, string, int);
virtual ~cHttpResource();
int readFromClient();
// int sendNextChunk();
void threadLoop();
int run();
private:
Log* mLog;
pthread_t mThreadId;
pthread_mutex_t mSendLock;
string mServerAddr;
int mServerPort;
int mFd;
int mReqId;
bool mConnected;
eConnState mConnState;
string mMethod;
char *mDataBuffer;
bool mBlkData;
int mBlkPos;
int mBlkLen;
// string path;
string mPath;
string mVersion;
string protocol;
bool mAcceptRanges;
cRange rangeHdr;
unsigned long long mFileSize;
uint mRemLength;
FILE *mFile;
// int tcpServerWrite(const char buf[], int buflen);
int writeToClient(const char *buf, size_t buflen);
int sendDataChunk();
void setNonBlocking();
int processHttpHeaderNew();
// int processHttpHeader();
void sendError(int status, const char *title, const char *extra, const char *text);
int sendDir(struct stat *statbuf);
int sendVdrDir(struct stat *statbuf);
int sendRecordingsHtml (struct stat *statbuf);
int sendRecordingsXml (struct stat *statbuf);
string removeEtChar(string line);
void sendHeaders(int status, const char *title, const char *extra, const char *mime,
off_t length, time_t date);
int sendFirstChunk(struct stat *statbuf);
// Helper Functions
char *getMimeType(const char *name);
string getConnStateName();
int parseRangeHeaderValue(string);
int openFile(const char *name);
string hexDump(string in);
string iso8859ToUtf8 (string);
};
#endif
|