~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSHTTPStream.h

  • Committer: lbieber
  • Date: 2010-10-02 19:48:35 UTC
  • mfrom: (1730.6.19 drizzle-make-lcov)
  • Revision ID: lbieber@orisndriz08-20101002194835-q5zd9qc4lvx1xnfo
Merge Hartmut - clean up lex, now require flex to build, also "make lcov" improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
53
53
        const char *getNameCString() { return iName ? iName->getCString() : ""; }
54
54
        const char *getValueCString() { return iValue ? iValue->getCString() : ""; }
55
55
 
56
 
        void write(CSOutputStream *out, bool trace);
 
56
        void write(CSOutputStream *out);
57
57
        
58
58
        friend class CSHTTPHeaders;
59
59
private:
66
66
 
67
67
class CSHTTPHeaders {
68
68
public:
69
 
        CSHTTPHeaders(CSVector *list = NULL): iHeaders(list), iKeepAlive(false), iExpect100Continue(false), iUnknownEpectHeader(false) { }
 
69
        CSHTTPHeaders(): iHeaders(NULL), iKeepAlive(false), iExpect100Continue(false), iUnknownEpectHeader(false) { }
70
70
        virtual ~CSHTTPHeaders() { if (iHeaders) iHeaders->release();}
71
71
 
72
72
        void clearHeaders();
78
78
        void addHeader(const char *name, uint32_t nlen, const char *value, uint32_t vlen);
79
79
        void addHeader(CSString *name, CSString *value);
80
80
        void addHeader(const char *name, CSString *value);
81
 
        void addHeader(const char *name, uint64_t value);
82
81
        void removeHeader(const char *name);
83
82
        void removeHeader(CSString *name);
84
83
        CSString *getHeaderValue(const char *name);
85
 
        const char *getHeaderCStringValue(const char *name);
86
 
        void writeHeader(CSOutputStream *out, bool trace);
 
84
        void writeHeader(CSOutputStream *out);
87
85
        bool keepAlive();
88
86
        bool expect100Continue();
89
87
        bool unknownEpectHeader();
108
106
        bool iUnknownEpectHeader;
109
107
};
110
108
 
111
 
class CSRefHTTPHeaders : public CSHTTPHeaders, public CSRefObject {
112
 
public:
113
 
        CSRefHTTPHeaders(CSVector *list):CSHTTPHeaders(list){}
114
 
        ~CSRefHTTPHeaders(){}   
115
 
};
116
 
 
117
109
class CSHTTPInputStream : public CSInputStream, public CSHTTPHeaders {
118
110
public:
119
111
        CSHTTPInputStream(CSInputStream *s);
120
112
        virtual ~CSHTTPInputStream();
121
113
 
122
 
        void readHead(bool trace = false);
123
 
        void readBody();
124
 
        bool getContentLength(uint64_t *length);
 
114
        void readHead();
 
115
        uint64_t getContentLength();
125
116
        const char *getMethod();
126
 
        char *getBodyData() { return iBody.getCString(); };
127
 
        size_t getBodyLength() { return iBody.length(); };
128
 
        void setBody(CSStringBufferImpl *buf) { iBody.take(buf); }
129
117
        int getStatus() { return iStatus; }
130
118
        CSString *getStatusPhrase() { return iStatusPhrase; }
131
119
        CSString *getRequestURI() { return iRequestURI; }
139
127
 
140
128
        virtual int peek();
141
129
 
142
 
        virtual void reset() { iInput->reset(); }
143
 
 
144
 
        virtual const char *identify() { return iInput->identify(); }
 
130
        virtual void reset() {iInput->reset();}
145
131
 
146
132
        static CSHTTPInputStream *newStream(CSInputStream* i);
147
133
 
149
135
        void freeHead();
150
136
 
151
137
        // Request-Line   = Method SP Request-URI SP HTTP-Version CRLF
152
 
        CSInputStream   *iInput;
153
 
        int                             iStatus;
154
 
        CSString                *iMethod;
155
 
        CSString                *iRequestURI;
156
 
        CSString                *iHTTPVersion;
157
 
        CSString                *iStatusPhrase;
158
 
        CSStringBuffer  iBody;
 
138
        CSInputStream *iInput;
 
139
        int             iStatus;
 
140
        CSString *iMethod;
 
141
        CSString *iRequestURI;
 
142
        CSString *iHTTPVersion;
 
143
        CSString *iStatusPhrase;
159
144
};
160
145
 
161
146
class CSHTTPOutputStream : public CSOutputStream, public CSHTTPHeaders {
168
153
        void setContentLength(uint64_t size) { iContentLength = size; }
169
154
        void setRange(uint64_t size, uint64_t offset, uint64_t total) { iRangeSize = size; iRangeOffset = offset; iTotalLength = total;}
170
155
 
171
 
        void writeHead(bool trace = false);     // Writes a standard HTTP header.
172
 
        void writeHeaders(bool trace = false); // Write the current headers.
 
156
        void writeHead();       // Writes a standard HTTP header.
 
157
        void writeHeaders(); // Write the current headers.
173
158
 
174
159
        void clearBody();
175
160
        void writeBody();
176
161
 
177
 
        // The virtual and non virtual print() methods
178
 
        // must be kept seperate to avoid possible compiler
179
 
        // warnings about hidden methods.
180
 
        void print(const char *str, bool trace);
181
 
        void print(int32_t value, bool trace);
182
 
        void print(uint64_t value, bool trace);
183
 
 
184
 
        virtual void print(const char *str) {print(str, false);}
185
 
        virtual void print(CSString *s) {print(s->getCString(), false);}
186
 
        virtual void print(int32_t value) {print(value, false);}
187
 
        virtual void print(uint64_t value) {print(value, false);}
188
 
 
189
162
        void appendBody(const char *str);
190
 
        void appendBody(int32_t value);
191
 
        void appendBody(uint32_t value);
192
 
        void appendBody(uint64_t value);
193
 
        const char *getBodyData();
194
 
        size_t getBodyLength();
195
 
        void setBody(CSStringBufferImpl *buf);
 
163
        void appendBody(int value);
196
164
 
197
165
        virtual void close();
198
166
 
204
172
 
205
173
        virtual void write(char b);
206
174
 
207
 
        virtual void reset() { iOutput->reset(); }
208
 
 
209
 
        virtual const char *identify() { return iOutput->identify(); }
 
175
        virtual void reset() {iOutput->reset();}
210
176
 
211
177
        static const char *getReasonPhrase(int code);
212
178