Commit | Line | Data |
c124bb9b |
1 | // |
e9c3e4d1 |
2 | // Provides support for FastCGI via C++ iostreams. |
3 | // |
949af0f1 |
4 | // $Id: fcgio.h,v 1.15 2002/02/25 13:16:11 robs Exp $ |
98e2ddaa |
5 | // |
6 | // This work is based on routines written by George Feinberg. They |
7 | // have been mostly re-written and extensively changed by |
c124bb9b |
8 | // Michael Richards. |
9 | // |
98e2ddaa |
10 | // Rewritten again with bug fixes and numerous enhancements by |
e9c3e4d1 |
11 | // Michael Shell. |
12 | // |
f684a497 |
13 | // And rewritten again by Rob Saccoccio. |
98e2ddaa |
14 | // |
15 | // Special Thanks to Dietmar Kuehl for his help and the numerous custom |
16 | // streambuf examples on his web site. |
17 | // |
e9c3e4d1 |
18 | // Copyright (c) 2000 Tux the Linux Penguin |
f684a497 |
19 | // Copyright (c) 2001 Rob Saccoccio and Chelsea Networks |
c124bb9b |
20 | // |
21 | // You are free to use this software without charge or royalty |
98e2ddaa |
22 | // as long as this notice is not removed or altered, and recognition |
c124bb9b |
23 | // is given to the author(s) |
24 | // |
98e2ddaa |
25 | // This code is offered as-is without any warranty either expressed or |
26 | // implied; without even the implied warranty of MERCHANTABILITY or |
e9c3e4d1 |
27 | // FITNESS FOR A PARTICULAR PURPOSE. If it breaks, you get to keep |
f684a497 |
28 | // both halves. |
98e2ddaa |
29 | |
c124bb9b |
30 | #ifndef FCGIO_H |
31 | #define FCGIO_H |
98e2ddaa |
32 | |
134d8dfc |
33 | #include <iostream> |
02089704 |
34 | |
0a62d748 |
35 | #include "fcgiapp.h" |
02089704 |
36 | |
af4a4f30 |
37 | #ifndef DLLAPI |
38 | #ifdef _WIN32 |
39 | #define DLLAPI __declspec(dllimport) |
40 | #else |
41 | #define DLLAPI |
42 | #endif |
43 | #endif |
44 | |
134d8dfc |
45 | #if ! HAVE_STREAMBUF_CHAR_TYPE |
46 | typedef char char_type; |
47 | #endif |
48 | |
f684a497 |
49 | /* |
50 | * fcgi_streambuf |
51 | */ |
134d8dfc |
52 | class DLLAPI fcgi_streambuf : public std::streambuf |
98e2ddaa |
53 | { |
f684a497 |
54 | public: |
98e2ddaa |
55 | |
e9c3e4d1 |
56 | // Note that if no buf is assigned (the default), iostream methods |
57 | // such as peek(), unget() and putback() will fail. If a buf is |
58 | // assigned, I/O is a bit less effecient and output streams will |
59 | // have to be flushed (or the streambuf destroyed) before the next |
60 | // call to "accept". |
134d8dfc |
61 | fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len); |
e9c3e4d1 |
62 | |
134d8dfc |
63 | fcgi_streambuf(char_type * buf, std::streamsize len); |
e9c3e4d1 |
64 | |
134d8dfc |
65 | fcgi_streambuf(FCGX_Stream * fcgx = 0); |
98e2ddaa |
66 | |
134d8dfc |
67 | ~fcgi_streambuf(void); |
98e2ddaa |
68 | |
134d8dfc |
69 | int attach(FCGX_Stream * fcgx); |
98e2ddaa |
70 | |
df70e743 |
71 | protected: |
72 | |
f684a497 |
73 | // Consume the put area (if buffered) and c (if c is not EOF). |
134d8dfc |
74 | virtual int overflow(int); |
98e2ddaa |
75 | |
e9c3e4d1 |
76 | // Flush the put area (if buffered) and the FCGX buffer to the client. |
134d8dfc |
77 | virtual int sync(); |
98e2ddaa |
78 | |
4c4f72f0 |
79 | // Remove and return the current character. |
134d8dfc |
80 | virtual int uflow(); |
4c4f72f0 |
81 | |
82 | // Fill the get area (if buffered) and return the current character. |
134d8dfc |
83 | virtual int underflow(); |
98e2ddaa |
84 | |
e9c3e4d1 |
85 | // Use a buffer. The only reasons that a buffer would be useful is |
86 | // to support the use of the unget()/putback() or seek() methods. Using |
87 | // a buffer will result in less efficient I/O. Note: the underlying |
88 | // FastCGI library (FCGX) maintains its own input and output buffers. |
134d8dfc |
89 | virtual std::streambuf * setbuf(char_type * buf, std::streamsize len); |
98e2ddaa |
90 | |
949af0f1 |
91 | virtual std::streamsize xsgetn(char_type * s, std::streamsize n); |
92 | virtual std::streamsize xsputn(const char_type * s, std::streamsize n); |
98e2ddaa |
93 | |
f684a497 |
94 | private: |
c124bb9b |
95 | |
f684a497 |
96 | FCGX_Stream * fcgx; |
c124bb9b |
97 | |
e9c3e4d1 |
98 | // buf is just handy to have around |
134d8dfc |
99 | char_type * buf; |
e9c3e4d1 |
100 | |
101 | // this isn't kept by the base class |
134d8dfc |
102 | std::streamsize bufsize; |
e9c3e4d1 |
103 | |
134d8dfc |
104 | void init(FCGX_Stream * fcgx, char_type * buf, std::streamsize bufsize); |
e9c3e4d1 |
105 | |
106 | void reset(void); |
c124bb9b |
107 | }; |
108 | |
f684a497 |
109 | /* |
110 | * fcgi_istream - deprecated |
111 | */ |
134d8dfc |
112 | class DLLAPI fcgi_istream : public std::istream |
98e2ddaa |
113 | { |
f684a497 |
114 | public: |
98e2ddaa |
115 | |
f684a497 |
116 | // deprecated |
134d8dfc |
117 | fcgi_istream(FCGX_Stream * fcgx = 0); |
f684a497 |
118 | |
119 | // deprecated |
134d8dfc |
120 | ~fcgi_istream(void) {} |
98e2ddaa |
121 | |
f684a497 |
122 | // deprecated |
134d8dfc |
123 | virtual void attach(FCGX_Stream * fcgx); |
98e2ddaa |
124 | |
f684a497 |
125 | private: |
c124bb9b |
126 | |
98e2ddaa |
127 | fcgi_streambuf fcgi_strmbuf; |
c124bb9b |
128 | }; |
129 | |
f684a497 |
130 | /* |
131 | * fcgi_ostream - deprecated |
132 | */ |
134d8dfc |
133 | class DLLAPI fcgi_ostream : public std::ostream |
98e2ddaa |
134 | { |
f684a497 |
135 | public: |
136 | |
137 | // deprecated |
134d8dfc |
138 | fcgi_ostream(FCGX_Stream * fcgx = 0); |
f684a497 |
139 | |
140 | // deprecated |
134d8dfc |
141 | ~fcgi_ostream(void) {} |
98e2ddaa |
142 | |
f684a497 |
143 | // deprecated |
134d8dfc |
144 | virtual void attach(FCGX_Stream *fcgx); |
98e2ddaa |
145 | |
f684a497 |
146 | private: |
c124bb9b |
147 | |
98e2ddaa |
148 | fcgi_streambuf fcgi_strmbuf; |
149 | }; |
c124bb9b |
150 | |
f684a497 |
151 | #endif /* FCGIO_H */ |