Commit | Line | Data |
c124bb9b |
1 | // |
e9c3e4d1 |
2 | // Provides support for FastCGI via C++ iostreams. |
3 | // |
4 | // $Id: fcgio.h,v 1.9 2001/11/21 21:12:04 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 | |
c124bb9b |
33 | #include <iostream.h> |
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 | |
f684a497 |
45 | /* |
46 | * fcgi_streambuf |
47 | */ |
98e2ddaa |
48 | class fcgi_streambuf : public streambuf |
49 | { |
f684a497 |
50 | public: |
98e2ddaa |
51 | |
e9c3e4d1 |
52 | // Note that if no buf is assigned (the default), iostream methods |
53 | // such as peek(), unget() and putback() will fail. If a buf is |
54 | // assigned, I/O is a bit less effecient and output streams will |
55 | // have to be flushed (or the streambuf destroyed) before the next |
56 | // call to "accept". |
57 | DLLAPI fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len); |
58 | |
59 | DLLAPI fcgi_streambuf(char * buf, int len); |
60 | |
61 | DLLAPI fcgi_streambuf(FCGX_Stream * fcgx = NULL); |
98e2ddaa |
62 | |
f684a497 |
63 | DLLAPI ~fcgi_streambuf(void); |
98e2ddaa |
64 | |
282622d5 |
65 | DLLAPI int attach(FCGX_Stream * fcgx); |
98e2ddaa |
66 | |
f684a497 |
67 | // Consume the put area (if buffered) and c (if c is not EOF). |
68 | DLLAPI virtual int overflow(int); |
98e2ddaa |
69 | |
e9c3e4d1 |
70 | // Flush the put area (if buffered) and the FCGX buffer to the client. |
f684a497 |
71 | // Note: sync() is protected in some implementations. |
72 | DLLAPI virtual int sync(); |
98e2ddaa |
73 | |
f684a497 |
74 | // Fill the get area (if buffered) and return the next character. |
75 | DLLAPI virtual int underflow(); |
98e2ddaa |
76 | |
e9c3e4d1 |
77 | // Use a buffer. The only reasons that a buffer would be useful is |
78 | // to support the use of the unget()/putback() or seek() methods. Using |
79 | // a buffer will result in less efficient I/O. Note: the underlying |
80 | // FastCGI library (FCGX) maintains its own input and output buffers. |
f684a497 |
81 | // Note: setbuf() is protected in some implementations. |
82 | DLLAPI virtual streambuf * setbuf(char * buf, int len); |
98e2ddaa |
83 | |
e9c3e4d1 |
84 | DLLAPI virtual int xsgetn(char * s, int n); |
85 | DLLAPI virtual int xsputn(const char * s, int n); |
98e2ddaa |
86 | |
f684a497 |
87 | private: |
c124bb9b |
88 | |
f684a497 |
89 | FCGX_Stream * fcgx; |
c124bb9b |
90 | |
e9c3e4d1 |
91 | // buf is just handy to have around |
92 | char * buf; |
93 | |
94 | // this isn't kept by the base class |
f684a497 |
95 | int bufsize; |
e9c3e4d1 |
96 | |
97 | void init(FCGX_Stream * fcgx, char * buf, int bufsize); |
98 | |
99 | void reset(void); |
c124bb9b |
100 | }; |
101 | |
f684a497 |
102 | /* |
103 | * fcgi_istream - deprecated |
104 | */ |
98e2ddaa |
105 | class fcgi_istream : public istream |
106 | { |
f684a497 |
107 | public: |
98e2ddaa |
108 | |
f684a497 |
109 | // deprecated |
282622d5 |
110 | DLLAPI fcgi_istream(FCGX_Stream * fcgx = NULL); |
f684a497 |
111 | |
112 | // deprecated |
113 | DLLAPI ~fcgi_istream(void) {} |
98e2ddaa |
114 | |
f684a497 |
115 | // deprecated |
282622d5 |
116 | DLLAPI virtual void attach(FCGX_Stream * fcgx); |
98e2ddaa |
117 | |
f684a497 |
118 | private: |
c124bb9b |
119 | |
98e2ddaa |
120 | fcgi_streambuf fcgi_strmbuf; |
c124bb9b |
121 | }; |
122 | |
f684a497 |
123 | /* |
124 | * fcgi_ostream - deprecated |
125 | */ |
98e2ddaa |
126 | class fcgi_ostream : public ostream |
127 | { |
f684a497 |
128 | public: |
129 | |
130 | // deprecated |
282622d5 |
131 | DLLAPI fcgi_ostream(FCGX_Stream * fcgx = NULL); |
f684a497 |
132 | |
133 | // deprecated |
134 | DLLAPI ~fcgi_ostream(void) {} |
98e2ddaa |
135 | |
f684a497 |
136 | // deprecated |
282622d5 |
137 | DLLAPI virtual void attach(FCGX_Stream *fcgx); |
98e2ddaa |
138 | |
f684a497 |
139 | private: |
c124bb9b |
140 | |
98e2ddaa |
141 | fcgi_streambuf fcgi_strmbuf; |
142 | }; |
c124bb9b |
143 | |
f684a497 |
144 | #endif /* FCGIO_H */ |