~george-edison55/jethttp/jethttp-singlethread

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
//=================================================
//
//            JetHTTP - CJetHTTPSocket.h
//           Copyright 2011 - Nathan Osman
//     This file is released under the GPL v3
//
//=================================================

#ifndef CJETHTTPSOCKET_H
#define CJETHTTPSOCKET_H

// Qt includes
#include <QObject>
#include <QList>
#include <QPair>
#include <QTcpSocket>

// JetHTTP includes
#include <defs.h>
#include <CHeaderManager.h>
#include <COutput.h>

class CJetHTTPSocket : public QObject
{
    Q_OBJECT

public:

    // Constructor / destructor
    CJetHTTPSocket(QObject *, QTcpSocket *);
    ~CJetHTTPSocket();

public slots:

    void OnReadyRead();
    void OnBytesWritten(qint64);

private:

    // Processing functions
    void ProcessRequest();
    bool ProcessTopLine(QString &);
    void ProcessHeader(QString &);

    void SendErrorReply(int, QString, QString);
    void WriteOutput();

    // The actual socket
    QTcpSocket * m_socket;

    // The information received from
    // the socket
    QByteArray m_data_read;    // the data we read from the socket
    REQUEST_TYPE m_request_type;
    QString m_request_url;
    CHeaderManager m_headers;
    int m_content_length;   // Content length of POST data

    // The output class
    COutput * m_output;

    // The information we need to make sure the
    // data gets written to the socket
    int m_output_size;
    int m_output_amount;

    // State variables
    bool m_header_received;  // whether we have seen the end of the header yet

};

#endif // CJETHTTPSOCKET_H