File: RequestHandlingThread.h

package info (click to toggle)
between 6%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 97; perl: 67
file content (140 lines) | stat: -rw-r--r-- 3,075 bytes parent folder | download | duplicates (18)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Modification History
 *
 * 2002-March-12   Jason Rohrer
 * Created.
 *
 * 2002-March-29    Jason Rohrer
 * Fixed include order.
 *
 * 2002-August-2   Jason Rohrer
 * Added use of ConnectionPermissionHandler.
 *
 * 2003-September-5   Jason Rohrer
 * Moved into minorGems.
 */


 
#ifndef REQUEST_HANDLING_THREAD_INCLUDED
#define REQUEST_HANDLING_THREAD_INCLUDED 

#include "PageGenerator.h"
#include "ConnectionPermissionHandler.h"


#include "minorGems/io/file/File.h"
#include "minorGems/io/file/FileInputStream.h"

#include "minorGems/network/Socket.h"
#include "minorGems/network/SocketStream.h"

#include "minorGems/system/Thread.h"
#include "minorGems/system/MutexLock.h"

#include <string.h>
#include <stdio.h>
#include <time.h>



#define REQUEST_HANDLING_THREAD_BUFFER_SIZE 4096

/**
 * Request handler for WebServer.
 *
 * @author Jason Rohrer.
 */
class RequestHandlingThread : public Thread {


        
    public:


        
        /**
         * Construct a handler.
         *
         * @param inSocket the socket to send the requested
         *   file trough.  Is destroyed before this thread terminates.
         * @param inGenerator the class that will generate the
         *   page content.
         *   Is not destroyed by this class.
         * @param inConnectionPermissionHandler the class that will
         *   grant connection permissions
         *   Is not destroyed by this class.
         */
        RequestHandlingThread(
            Socket *inSocket,
            PageGenerator *inGenerator,
            ConnectionPermissionHandler *inConnectionPermissionHandler);


        
        ~RequestHandlingThread();


        
        /**
         * Returns true if this handler is done and ready to be destroyed.
         *
         * Synchronized, so may block.
         *
         * @return true if this handler is done and ready to be destroyed.
         */
        char isDone();

        
        
        /**
         * Gets a string representation of the current time.
         *
         * @return a timestamp string.  Must be destroyed by caller.
         */
        static char* getTimestamp();

        
        
        // implements the Thread interface
        virtual void run();

        
        
    private:
        Socket *mSocket;
        PageGenerator *mGenerator;
        ConnectionPermissionHandler *mConnectionPermissionHandler;
        
        MutexLock *mDoneLock;
        char mDone;


        
        /**
         * Sends an HTTP "not found" message with a "not found" web page.
         *
         * @param inStream the stream to send the not found page to.
         * @param inFileName the name of the requested file,
         *   or NULL.
         */
        void sendNotFoundPage( SocketStream *inStream,
                               char *inFileName );

        
        
        /**
         * Sends a "bad request" web page.
         *
         * @param inStream the stream to send the page to.
         */
        void sendBadRequest( SocketStream *inStream );

        
        
    };



#endif