//
// Provides support for FastCGI via C++ iostreams.
//
-// $Id: fcgio.h,v 1.13 2001/12/04 00:22:04 robs Exp $
+// $Id: fcgio.h,v 1.14 2002/02/24 20:12:23 robs Exp $
//
// This work is based on routines written by George Feinberg. They
// have been mostly re-written and extensively changed by
#ifndef FCGIO_H
#define FCGIO_H
-#include <iostream.h>
+#include <iostream>
#include "fcgiapp.h"
#endif
#endif
+#if ! HAVE_STREAMBUF_CHAR_TYPE
+typedef char char_type;
+#endif
+
/*
* fcgi_streambuf
*/
-class fcgi_streambuf : public streambuf
+class DLLAPI fcgi_streambuf : public std::streambuf
{
public:
// assigned, I/O is a bit less effecient and output streams will
// have to be flushed (or the streambuf destroyed) before the next
// call to "accept".
- DLLAPI fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len);
+ fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int len);
- DLLAPI fcgi_streambuf(char * buf, int len);
+ fcgi_streambuf(char_type * buf, std::streamsize len);
- DLLAPI fcgi_streambuf(FCGX_Stream * fcgx = 0);
+ fcgi_streambuf(FCGX_Stream * fcgx = 0);
- DLLAPI ~fcgi_streambuf(void);
+ ~fcgi_streambuf(void);
- DLLAPI int attach(FCGX_Stream * fcgx);
+ int attach(FCGX_Stream * fcgx);
protected:
// Consume the put area (if buffered) and c (if c is not EOF).
- DLLAPI virtual int overflow(int);
+ virtual int overflow(int);
// Flush the put area (if buffered) and the FCGX buffer to the client.
- DLLAPI virtual int sync();
+ virtual int sync();
// Remove and return the current character.
- DLLAPI virtual int uflow();
+ virtual int uflow();
// Fill the get area (if buffered) and return the current character.
- DLLAPI virtual int underflow();
+ virtual int underflow();
// Use a buffer. The only reasons that a buffer would be useful is
// to support the use of the unget()/putback() or seek() methods. Using
// a buffer will result in less efficient I/O. Note: the underlying
// FastCGI library (FCGX) maintains its own input and output buffers.
- DLLAPI virtual streambuf * setbuf(char * buf, int len);
+ virtual std::streambuf * setbuf(char_type * buf, std::streamsize len);
- DLLAPI virtual int xsgetn(char * s, int n);
- DLLAPI virtual int xsputn(const char * s, int n);
+ virtual int xsgetn(char_type * s, std::streamsize n);
+ virtual int xsputn(const char_type * s, std::streamsize n);
private:
FCGX_Stream * fcgx;
// buf is just handy to have around
- char * buf;
+ char_type * buf;
// this isn't kept by the base class
- int bufsize;
+ std::streamsize bufsize;
- void init(FCGX_Stream * fcgx, char * buf, int bufsize);
+ void init(FCGX_Stream * fcgx, char_type * buf, std::streamsize bufsize);
void reset(void);
};
/*
* fcgi_istream - deprecated
*/
-class fcgi_istream : public istream
+class DLLAPI fcgi_istream : public std::istream
{
public:
// deprecated
- DLLAPI fcgi_istream(FCGX_Stream * fcgx = 0);
+ fcgi_istream(FCGX_Stream * fcgx = 0);
// deprecated
- DLLAPI ~fcgi_istream(void) {}
+ ~fcgi_istream(void) {}
// deprecated
- DLLAPI virtual void attach(FCGX_Stream * fcgx);
+ virtual void attach(FCGX_Stream * fcgx);
private:
/*
* fcgi_ostream - deprecated
*/
-class fcgi_ostream : public ostream
+class DLLAPI fcgi_ostream : public std::ostream
{
public:
// deprecated
- DLLAPI fcgi_ostream(FCGX_Stream * fcgx = 0);
+ fcgi_ostream(FCGX_Stream * fcgx = 0);
// deprecated
- DLLAPI ~fcgi_ostream(void) {}
+ ~fcgi_ostream(void) {}
// deprecated
- DLLAPI virtual void attach(FCGX_Stream *fcgx);
+ virtual void attach(FCGX_Stream *fcgx);
private:
//
-// $Id: fcgio.cpp,v 1.12 2001/12/04 00:22:06 robs Exp $
+// $Id: fcgio.cpp,v 1.13 2002/02/24 20:12:22 robs Exp $
//
// Allows you communicate with FastCGI streams using C++ iostreams
//
#define DLLAPI __declspec(dllexport)
#endif
+#include <limits.h>
#include "fcgio.h"
+using std::streambuf;
+using std::istream;
+using std::ostream;
+using std::streamsize;
+
fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fs, char * b, int bs)
{
init(fs, b, bs);
}
-fcgi_streambuf::fcgi_streambuf(char * b, int bs)
+fcgi_streambuf::fcgi_streambuf(char_type * b, streamsize bs)
{
init(0, b, bs);
}
// FCGX_Finish()/FCGX_Accept() will flush and close
}
-void fcgi_streambuf::init(FCGX_Stream * fs, char * b, int bs)
+void fcgi_streambuf::init(FCGX_Stream * fs, char_type * b, streamsize bs)
{
this->fcgx = fs;
this->buf = 0;
setp(this->buf, this->buf + this->bufsize);
}
-streambuf * fcgi_streambuf::setbuf(char * b, int bs)
+std::streambuf * fcgi_streambuf::setbuf(char_type * b, streamsize bs)
{
// XXX support moving data from an old buffer
if (this->bufsize) return 0;
return 0;
}
-int fcgi_streambuf::xsgetn(char * s, int n)
+streamsize fcgi_streambuf::xsgetn(char_type * s, streamsize n)
{
+ if (n > INT_MAX) return 0;
return (this->bufsize)
? streambuf::xsgetn(s, n)
- : FCGX_GetStr(s, n, this->fcgx);
+ : (streamsize) FCGX_GetStr((char *) s, (int) n, this->fcgx);
}
-int fcgi_streambuf::xsputn(const char * s, int n)
+streamsize fcgi_streambuf::xsputn(const char_type * s, streamsize n)
{
+ if (n > INT_MAX) return 0;
return (this->bufsize)
? streambuf::xsputn(s, n)
- : FCGX_PutStr(s, n, this->fcgx);
+ : (streamsize) FCGX_PutStr((char *) s, (int) n, this->fcgx);
}
// deprecated