~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
2
 *
 
3
 * PrimeBase Media Stream for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Original author: Paul McCullagh (H&G2JCtL)
 
20
 * Continued development: Barry Leslie
 
21
 *
 
22
 * 2007-06-10
 
23
 *
 
24
 *
 
25
 */
 
26
 
 
27
#ifndef __CSHTTPSTREAM_H__
 
28
#define __CSHTTPSTREAM_H__
 
29
 
 
30
#include "CSDefs.h"
 
31
#include "CSStorage.h"
 
32
#include "CSStream.h"
 
33
 
 
34
// The http tags before and after the exception message text must be well defined so that
 
35
// the client api can parse the error reply and get the error text out.
 
36
#define EXCEPTION_REPLY_MESSAGE_PREFIX_TAG "<P><B>"
 
37
#define EXCEPTION_REPLY_MESSAGE_SUFFIX_TAG "</B></P><PRE>"
 
38
#define EXCEPTION_REPLY_STACK_TRACE_SUFFIX_TAG "</PRE><P><font size=-1>"
 
39
 
 
40
class CSHeader : public CSRefObject {
 
41
public:
 
42
        CSHeader():iName(NULL), iValue(NULL) { }
 
43
        virtual ~CSHeader();
 
44
 
 
45
        void setName(const char *name);
 
46
        void setName(const char *name, uint32_t len);
 
47
        void setName(CSString *name);
 
48
 
 
49
        void setValue(const char *value);
 
50
        void setValue(const char *value, uint32_t len);
 
51
        void setValue(CSString *value);
 
52
 
 
53
        const char *getNameCString() { return iName ? iName->getCString() : ""; }
 
54
        const char *getValueCString() { return iValue ? iValue->getCString() : ""; }
 
55
 
 
56
        void write(CSOutputStream *out);
 
57
        
 
58
        friend class CSHTTPHeaders;
 
59
private:
 
60
        CSString *getName() { return iName; } // Return a none referenced object!!
 
61
        CSString *getValue() { return iValue; }// Return a none referenced object!!
 
62
 
 
63
        CSString        *iName;
 
64
        CSString        *iValue;
 
65
};
 
66
 
 
67
class CSHTTPHeaders {
 
68
public:
 
69
        CSHTTPHeaders(): iHeaders(NULL), iKeepAlive(false), iExpect100Continue(false), iUnknownEpectHeader(false) { }
 
70
        virtual ~CSHTTPHeaders() { if (iHeaders) iHeaders->release();}
 
71
 
 
72
        void clearHeaders();
 
73
        CSVector * takeHeaders();
 
74
        void setHeaders(CSVector *headers);
 
75
        void addHeaders(CSHTTPHeaders *h);
 
76
        void addHeader(CSHeader *h);
 
77
        void addHeader(const char *name, const char *value);
 
78
        void addHeader(const char *name, uint32_t nlen, const char *value, uint32_t vlen);
 
79
        void addHeader(CSString *name, CSString *value);
 
80
        void addHeader(const char *name, CSString *value);
 
81
        void removeHeader(const char *name);
 
82
        void removeHeader(CSString *name);
 
83
        CSString *getHeaderValue(const char *name);
 
84
        void writeHeader(CSOutputStream *out);
 
85
        bool keepAlive();
 
86
        bool expect100Continue();
 
87
        bool unknownEpectHeader();
 
88
 
 
89
        uint32_t numHeaders() { return (iHeaders)?iHeaders->size(): 0; }
 
90
        CSHeader *getHeader(uint32_t idx) 
 
91
        { 
 
92
                CSHeader *header = NULL;
 
93
                
 
94
                if (iHeaders) 
 
95
                        header = (CSHeader *)(iHeaders->get(idx));
 
96
                        
 
97
                if (header)
 
98
                        header->retain();
 
99
                return header;
 
100
        }
 
101
        
 
102
private:
 
103
        CSVector *iHeaders;
 
104
        bool iKeepAlive;
 
105
        bool iExpect100Continue;
 
106
        bool iUnknownEpectHeader;
 
107
};
 
108
 
 
109
class CSHTTPInputStream : public CSInputStream, public CSHTTPHeaders {
 
110
public:
 
111
        CSHTTPInputStream(CSInputStream *s);
 
112
        virtual ~CSHTTPInputStream();
 
113
 
 
114
        void readHead();
 
115
        uint64_t getContentLength();
 
116
        const char *getMethod();
 
117
        int getStatus() { return iStatus; }
 
118
        CSString *getStatusPhrase() { return iStatusPhrase; }
 
119
        CSString *getRequestURI() { return iRequestURI; }
 
120
        bool getRange(uint64_t *size, uint64_t *offset);
 
121
 
 
122
        virtual void close();
 
123
 
 
124
        virtual size_t read(char *b, size_t len);
 
125
 
 
126
        virtual int read();
 
127
 
 
128
        virtual int peek();
 
129
 
 
130
        virtual void reset() {iInput->reset();}
 
131
 
 
132
        static CSHTTPInputStream *newStream(CSInputStream* i);
 
133
 
 
134
private:
 
135
        void freeHead();
 
136
 
 
137
        // Request-Line   = Method SP Request-URI SP HTTP-Version CRLF
 
138
        CSInputStream *iInput;
 
139
        int             iStatus;
 
140
        CSString *iMethod;
 
141
        CSString *iRequestURI;
 
142
        CSString *iHTTPVersion;
 
143
        CSString *iStatusPhrase;
 
144
};
 
145
 
 
146
class CSHTTPOutputStream : public CSOutputStream, public CSHTTPHeaders {
 
147
public:
 
148
        CSHTTPOutputStream(CSOutputStream* s);
 
149
        virtual ~CSHTTPOutputStream();
 
150
 
 
151
        void setStatus(int status) { iStatus = status; }
 
152
        int getStatus() { return iStatus; }
 
153
        void setContentLength(uint64_t size) { iContentLength = size; }
 
154
        void setRange(uint64_t size, uint64_t offset, uint64_t total) { iRangeSize = size; iRangeOffset = offset; iTotalLength = total;}
 
155
 
 
156
        void writeHead();       // Writes a standard HTTP header.
 
157
        void writeHeaders(); // Write the current headers.
 
158
 
 
159
        void clearBody();
 
160
        void writeBody();
 
161
 
 
162
        void appendBody(const char *str);
 
163
        void appendBody(int value);
 
164
 
 
165
        virtual void close();
 
166
 
 
167
        virtual void write(const char *b, size_t len);
 
168
 
 
169
        virtual const char *getEOL() { return "\r\n"; };
 
170
 
 
171
        virtual void flush();
 
172
 
 
173
        virtual void write(char b);
 
174
 
 
175
        virtual void reset() {iOutput->reset();}
 
176
 
 
177
        static const char *getReasonPhrase(int code);
 
178
 
 
179
        static CSHTTPOutputStream *newStream(CSOutputStream* i);
 
180
 
 
181
private:
 
182
        // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
 
183
        CSOutputStream  *iOutput;
 
184
        int                             iStatus;
 
185
        uint64_t                        iContentLength;
 
186
        CSStringBuffer  iBody;
 
187
        uint64_t                        iRangeSize;
 
188
        uint64_t                        iRangeOffset;
 
189
        uint64_t                        iTotalLength;
 
190
};
 
191
 
 
192
#endif