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