//
-// $Id: fcgio.cpp,v 1.11 2001/11/26 18:09:03 robs Exp $
+// $Id: fcgio.cpp,v 1.14 2003/06/22 00:51:27 robs Exp $
//
// Allows you communicate with FastCGI streams using C++ iostreams
//
#define DLLAPI __declspec(dllexport)
#endif
+#include <limits.h>
#include "fcgio.h"
-fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fcgx, char * buf, int bufsize)
+using std::streambuf;
+using std::istream;
+using std::ostream;
+using std::streamsize;
+
+fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fs, char * b, int bs)
{
- init(fcgx, buf, bufsize);
+ init(fs, b, bs);
}
-fcgi_streambuf::fcgi_streambuf(char * buf, int bufsize)
+fcgi_streambuf::fcgi_streambuf(char_type * b, streamsize bs)
{
- init(NULL, buf, bufsize);
+ init(0, b, bs);
}
-fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fcgx)
+fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fs)
{
- init(fcgx, NULL, 0);
+ init(fs, 0, 0);
}
fcgi_streambuf::~fcgi_streambuf(void)
// FCGX_Finish()/FCGX_Accept() will flush and close
}
-void fcgi_streambuf::init(FCGX_Stream * fcgx, char * buf, int bufsize)
+void fcgi_streambuf::init(FCGX_Stream * fs, char_type * b, streamsize bs)
{
- this->fcgx = fcgx;
- this->buf = NULL;
+ this->fcgx = fs;
+ this->buf = 0;
this->bufsize = 0;
- setbuf(buf, bufsize);
+ setbuf(b, bs);
}
int fcgi_streambuf::overflow(int c)
// uflow() removes the char, underflow() doesn't
int fcgi_streambuf::uflow()
{
- int rv = underflow();
- if (this->bufsize) gbump(1);
- return rv;
+ if (this->bufsize)
+ {
+ int c = underflow();
+ gbump(1);
+ return c;
+ }
+ else
+ {
+ return FCGX_GetChar(this->fcgx);
+ }
}
-// Note that the expected behaviour when there is no buffer varies
int fcgi_streambuf::underflow()
{
if (this->bufsize)
}
else
{
- return FCGX_GetChar(this->fcgx);
+ return FCGX_UnGetChar(FCGX_GetChar(this->fcgx), this->fcgx);
}
}
setp(this->buf, this->buf + this->bufsize);
}
-streambuf * fcgi_streambuf::setbuf(char * buf, int len)
+std::streambuf * fcgi_streambuf::setbuf(char_type * b, streamsize bs)
{
// XXX support moving data from an old buffer
- if (this->bufsize) return NULL;
+ if (this->bufsize) return 0;
- this->buf = buf;
- this->bufsize = len;
+ this->buf = b;
+ this->bufsize = bs;
// the base setbuf() *has* to be called
- streambuf::setbuf(buf, len);
+ streambuf::setbuf(b, bs);
reset();
return this;
}
-int fcgi_streambuf::attach(FCGX_Stream * strm)
+int fcgi_streambuf::attach(FCGX_Stream * fs)
{
- this->fcgx = strm;
+ this->fcgx = fs;
if (this->bufsize)
{
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
-fcgi_istream::fcgi_istream(FCGX_Stream * strm) :
+fcgi_istream::fcgi_istream(FCGX_Stream * fs) :
istream(&fcgi_strmbuf)
{
- fcgi_strmbuf.attach(strm);
+ fcgi_strmbuf.attach(fs);
}
// deprecated
-void fcgi_istream::attach(FCGX_Stream * strm)
+void fcgi_istream::attach(FCGX_Stream * fs)
{
- fcgi_strmbuf.attach(strm);
+ fcgi_strmbuf.attach(fs);
}
// deprecated
-fcgi_ostream::fcgi_ostream(FCGX_Stream * strm) :
+fcgi_ostream::fcgi_ostream(FCGX_Stream * fs) :
ostream(&fcgi_strmbuf)
{
- fcgi_strmbuf.attach(strm);
+ fcgi_strmbuf.attach(fs);
}
// deprecated
-void fcgi_ostream::attach(FCGX_Stream * strm)
+void fcgi_ostream::attach(FCGX_Stream * fs)
{
- fcgi_strmbuf.attach(strm);
+ fcgi_strmbuf.attach(fs);
}