#unless (exists $Config{apiversion} && $Config{apiversion} >= 5.005)
unless ($] >= 5.005) {
for (qw(sv_undef diehook warnhook in_eval)) {
- print OUT "#define PL_$_ $_\n"
+ print OUT "#define PL_$_ $_\n"
}
}
print OUT while <DATA>;
#ifdef USE_SFIO
typedef struct
{
- Sfdisc_t disc;
- FCGX_Stream *stream;
+ Sfdisc_t disc;
+ FCGX_Stream *stream;
} FCGI_Disc;
static ssize_t
sffcgiread(f, buf, n, disc)
-Sfio_t* f; /* stream involved */
-Void_t* buf; /* buffer to read into */
-size_t n; /* number of bytes to read */
-Sfdisc_t* disc; /* discipline */
+Sfio_t* f; /* stream involved */
+Void_t* buf; /* buffer to read into */
+size_t n; /* number of bytes to read */
+Sfdisc_t* disc; /* discipline */
{
return FCGX_GetStr(buf, n, ((FCGI_Disc *)disc)->stream);
}
static ssize_t
sffcgiwrite(f, buf, n, disc)
-Sfio_t* f; /* stream involved */
-const Void_t* buf; /* buffer to read into */
-size_t n; /* number of bytes to read */
-Sfdisc_t* disc; /* discipline */
+Sfio_t* f; /* stream involved */
+const Void_t* buf; /* buffer to read into */
+size_t n; /* number of bytes to read */
+Sfdisc_t* disc; /* discipline */
{
n = FCGX_PutStr(buf, n, ((FCGI_Disc *)disc)->stream);
FCGX_FFlush(((FCGI_Disc *)disc)->stream);
Sfdisc_t *
sfdcnewfcgi(stream)
- FCGX_Stream *stream;
+ FCGX_Stream *stream;
{
- FCGI_Disc* disc;
+ FCGI_Disc* disc;
New(1000,disc,1,FCGI_Disc);
if (!disc) return (Sfdisc_t *)disc;
Sfdisc_t *
sfdcdelfcgi(disc)
- Sfdisc_t* disc;
+ Sfdisc_t* disc;
{
Safefree(disc);
return 0;
#endif
typedef struct FCGP_Request {
- int accepted;
- int bound;
- SV* svin;
- SV* svout;
- SV* sverr;
- GV* gv[3];
- HV* hvEnv;
+ int accepted;
+ int bound;
+ SV* svin;
+ SV* svout;
+ SV* sverr;
+ GV* gv[3];
+ HV* hvEnv;
FCGX_Request* requestPtr;
#ifdef USE_SFIO
- int sfcreated[3];
- IO* io[3];
+ int sfcreated[3];
+ IO* io[3];
#endif
} FCGP_Request;
dTHX;
if(!request->bound) {
- return;
- }
+ return;
+ }
#ifdef USE_SFIO
sfsync(IoOFP(GvIOp(request->gv[1])));
sfsync(IoOFP(GvIOp(request->gv[2])));
slot of the GP rather than the GV itself. */
if (!GvIOp(request->gv[1]))
- GvIOp(request->gv[1]) = newIO();
+ GvIOp(request->gv[1]) = newIO();
if (!GvIOp(request->gv[2]))
- GvIOp(request->gv[2]) = newIO();
+ GvIOp(request->gv[2]) = newIO();
if (!GvIOp(request->gv[0]))
- GvIOp(request->gv[0]) = newIO();
+ GvIOp(request->gv[0]) = newIO();
sv_magic((SV *)GvIOp(request->gv[1]), request->svout, 'q', Nullch, 0);
sv_magic((SV *)GvIOp(request->gv[2]), request->sverr, 'q', Nullch, 0);
hv_clear(hv);
for(i = 0; ; i++) {
- if((p = envp[i]) == NULL) {
- break;
- }
- p1 = strchr(p, '=');
- assert(p1 != NULL);
- sv = newSVpv(p1 + 1, 0);
- /* call magic for this value ourselves */
- hv_store(hv, p, p1 - p, sv, 0);
- SvSETMAGIC(sv);
+ if((p = envp[i]) == NULL) {
+ break;
+ }
+ p1 = strchr(p, '=');
+ assert(p1 != NULL);
+ sv = newSVpv(p1 + 1, 0);
+ /* call magic for this value ourselves */
+ hv_store(hv, p, p1 - p, sv, 0);
+ SvSETMAGIC(sv);
}
}
static int isCGI = -1; /* -1: not checked; 0: FCGI; 1: CGI */
if (request->requestPtr->listen_sock == FCGI_LISTENSOCK_FILENO) {
- if (isCGI == -1)
- isCGI = FCGX_IsCGI();
- return !isCGI;
+ if (isCGI == -1)
+ isCGI = FCGX_IsCGI();
+ return !isCGI;
}
/* A explicit socket is being used -> assume FastCGI */
dTHX;
if (!FCGI_IsFastCGI(request)) {
- static int been_here = 0;
+ static int been_here = 0;
/*
* Not first call to FCGI_Accept and running as CGI means
* application is done.
*/
- if (been_here)
- return EOF;
+ if (been_here)
+ return EOF;
- been_here = 1;
+ been_here = 1;
} else {
#ifdef USE_SFIO
- int i;
+ int i;
#endif
- FCGX_Request *fcgx_req = request->requestPtr;
+ FCGX_Request *fcgx_req = request->requestPtr;
int acceptResult;
- FCGI_Finish(request);
+ FCGI_Finish(request);
#if defined(USE_LOCKING) && defined(USE_THREADS)
- MUTEX_LOCK(&accept_mutex);
+ MUTEX_LOCK(&accept_mutex);
#endif
- acceptResult = FCGX_Accept_r(fcgx_req);
+ acceptResult = FCGX_Accept_r(fcgx_req);
#if defined(USE_LOCKING) && defined(USE_THREADS)
- MUTEX_UNLOCK(&accept_mutex);
+ MUTEX_UNLOCK(&accept_mutex);
#endif
if(acceptResult < 0) {
return acceptResult;
}
- populate_env(fcgx_req->envp, request->hvEnv);
+ populate_env(fcgx_req->envp, request->hvEnv);
#ifdef USE_SFIO
- for (i = 0; i < 3; ++i) {
- request->io[i] = GvIOn(request->gv[i]);
- if (!(i == 0 ? IoIFP(request->io[i])
- : IoOFP(request->io[i]))) {
- IoIFP(request->io[i]) = sftmp(0);
- /*IoIFP(request->io[i]) = sfnew(NULL, NULL, SF_UNBOUND, 0,
- SF_STRING | (i ? SF_WRITE : SF_READ));*/
- if (i != 0)
- IoOFP(request->io[i]) = IoIFP(request->io[i]);
- request->sfcreated[i] = TRUE;
- }
- }
+ for (i = 0; i < 3; ++i) {
+ request->io[i] = GvIOn(request->gv[i]);
+ if (!(i == 0 ? IoIFP(request->io[i])
+ : IoOFP(request->io[i]))) {
+ IoIFP(request->io[i]) = sftmp(0);
+ /*IoIFP(request->io[i]) = sfnew(NULL, NULL, SF_UNBOUND, 0,
+ SF_STRING | (i ? SF_WRITE : SF_READ));*/
+ if (i != 0)
+ IoOFP(request->io[i]) = IoIFP(request->io[i]);
+ request->sfcreated[i] = TRUE;
+ }
+ }
#else
- if (!request->svout) {
- newSVrv(request->svout = newSV(0), "FCGI::Stream");
- newSVrv(request->sverr = newSV(0), "FCGI::Stream");
- newSVrv(request->svin = newSV(0), "FCGI::Stream");
- }
- sv_setiv(SvRV(request->svout), INT2PTR(IV, fcgx_req->out));
- sv_setiv(SvRV(request->sverr), INT2PTR(IV, fcgx_req->err));
- sv_setiv(SvRV(request->svin), INT2PTR(IV, fcgx_req->in));
+ if (!request->svout) {
+ newSVrv(request->svout = newSV(0), "FCGI::Stream");
+ newSVrv(request->sverr = newSV(0), "FCGI::Stream");
+ newSVrv(request->svin = newSV(0), "FCGI::Stream");
+ }
+ sv_setiv(SvRV(request->svout), INT2PTR(IV, fcgx_req->out));
+ sv_setiv(SvRV(request->sverr), INT2PTR(IV, fcgx_req->err));
+ sv_setiv(SvRV(request->svin), INT2PTR(IV, fcgx_req->in));
#endif
- FCGI_Bind(request);
- request->accepted = TRUE;
+ FCGI_Bind(request);
+ request->accepted = TRUE;
}
return 0;
}
dTHX;
if(!request->accepted) {
- return;
+ return;
}
if (was_bound = request->bound) {
- FCGI_UndoBinding(request);
+ FCGI_UndoBinding(request);
}
#ifdef USE_SFIO
for (i = 0; i < 3; ++i) {
- if (request->sfcreated[i]) {
- sfclose(IoIFP(request->io[i]));
- IoIFP(request->io[i]) = IoOFP(request->io[i]) = Nullfp;
- request->sfcreated[i] = FALSE;
- }
+ if (request->sfcreated[i]) {
+ sfclose(IoIFP(request->io[i]));
+ IoIFP(request->io[i]) = IoOFP(request->io[i]) = Nullfp;
+ request->sfcreated[i] = FALSE;
+ }
}
#endif
if (was_bound)
- FCGX_Finish_r(request->requestPtr);
+ FCGX_Finish_r(request->requestPtr);
else
- FCGX_Free(request->requestPtr, 1);
+ FCGX_Free(request->requestPtr, 1);
request->accepted = FALSE;
}
FCGI_StartFilterData(FCGP_Request* request)
{
return request->requestPtr->in ?
- FCGX_StartFilterData(request->requestPtr->in) : -1;
+ FCGX_StartFilterData(request->requestPtr->in) : -1;
}
static FCGP_Request *
FCGI_Request(in, out, err, env, socket, flags)
- GV* in;
- GV* out;
- GV* err;
- HV* env;
- int socket;
- int flags;
+ GV* in;
+ GV* out;
+ GV* err;
+ HV* env;
+ int socket;
+ int flags;
{
FCGX_Request* fcgx_req;
FCGP_Request* req;
FCGX_Init();
}
-typedef FCGX_Stream * FCGI__Stream;
-typedef FCGP_Request * FCGI;
-typedef GV* GLOBREF;
-typedef HV* HASHREF;
+typedef FCGX_Stream * FCGI__Stream;
+typedef FCGP_Request * FCGI;
+typedef GV* GLOBREF;
+typedef HV* HASHREF;
-MODULE = FCGI PACKAGE = FCGI PREFIX = FCGI_
+MODULE = FCGI PACKAGE = FCGI PREFIX = FCGI_
BOOT:
FCGI_Init();
GLOBREF out;
GLOBREF err;
HASHREF env;
- int socket;
- int flags;
+ int socket;
+ int flags;
PROTOTYPE: ***$$$
CODE:
RETVAL = sv_setref_pv(newSV(0), "FCGI",
- FCGI_Request(in, out, err, env, socket, flags));
+ FCGI_Request(in, out, err, env, socket, flags));
OUTPUT:
RETVAL
PROTOTYPE: $
PREINIT:
- int i;
+ int i;
PPCODE:
EXTEND(sp,3);
for (i = 0; i < 3; ++i)
- PUSHs(sv_2mortal(newRV((SV *) request->gv[i])));
+ PUSHs(sv_2mortal(newRV((SV *) request->gv[i])));
int
FCGI_IsFastCGI(request)
-MODULE = FCGI PACKAGE = FCGI::Stream
+MODULE = FCGI PACKAGE = FCGI::Stream
#ifndef USE_SFIO
SV *
PRINT(stream, ...)
- FCGI::Stream stream;
+ FCGI::Stream stream;
- PREINIT:
+ PREINIT:
int n;
STRLEN len;
register char *str;
ok = FALSE;
}
- if (ok && SvTRUEx(perl_get_sv("|", FALSE)) && FCGX_FFlush(stream) < 0)
- ok = FALSE;
+ if (ok && SvTRUEx(perl_get_sv("|", FALSE)) && FCGX_FFlush(stream) < 0)
+ ok = FALSE;
RETVAL = ok ? &PL_sv_yes : &PL_sv_undef;
OUTPUT:
int
WRITE(stream, bufsv, len, ...)
- FCGI::Stream stream;
- SV * bufsv;
- int len;
-
- PREINIT:
- int offset;
- char * buf;
- STRLEN blen;
- int n;
-
- CODE:
- offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
+ FCGI::Stream stream;
+ SV * bufsv;
+ int len;
+
+ PREINIT:
+ int offset;
+ char * buf;
+ STRLEN blen;
+ int n;
+
+ CODE:
+ offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
#ifdef DO_UTF8
if (DO_UTF8(bufsv) && !sv_utf8_downgrade(bufsv, 1) && ckWARN_d(WARN_UTF8))
Perl_warner(aTHX_ WARN_UTF8, "Wide character in FCGI::Stream::WRITE");
#endif
- buf = SvPV(bufsv, blen);
- if (offset < 0) offset += blen;
- if (len > blen - offset)
- len = blen - offset;
- if (offset < 0 || offset >= blen ||
- (n = FCGX_PutStr(buf+offset, len, stream)) < 0)
- ST(0) = &PL_sv_undef;
- else {
- ST(0) = sv_newmortal();
- sv_setiv(ST(0), n);
- }
+ buf = SvPV(bufsv, blen);
+ if (offset < 0) offset += blen;
+ if (len > blen - offset)
+ len = blen - offset;
+ if (offset < 0 || offset >= blen ||
+ (n = FCGX_PutStr(buf+offset, len, stream)) < 0)
+ ST(0) = &PL_sv_undef;
+ else {
+ ST(0) = sv_newmortal();
+ sv_setiv(ST(0), n);
+ }
int
READ(stream, bufsv, len, ...)
- FCGI::Stream stream;
- SV * bufsv;
- int len;
+ FCGI::Stream stream;
+ SV * bufsv;
+ int len;
- PREINIT:
- int offset;
- char * buf;
+ PREINIT:
+ int offset;
+ char * buf;
- CODE:
- offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
+ CODE:
+ offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
#ifdef DO_UTF8
if (DO_UTF8(bufsv) && !sv_utf8_downgrade(bufsv, 1))
croak("Wide character in FCGI::Stream::READ");
#endif
- if (! SvOK(bufsv))
- sv_setpvn(bufsv, "", 0);
- buf = SvGROW(bufsv, len+offset+1);
- len = FCGX_GetStr(buf+offset, len, stream);
- SvCUR_set(bufsv, len+offset);
- *SvEND(bufsv) = '\0';
- (void)SvPOK_only(bufsv);
- SvSETMAGIC(bufsv);
- RETVAL = len;
-
- OUTPUT:
- RETVAL
+ if (! SvOK(bufsv))
+ sv_setpvn(bufsv, "", 0);
+ buf = SvGROW(bufsv, len+offset+1);
+ len = FCGX_GetStr(buf+offset, len, stream);
+ SvCUR_set(bufsv, len+offset);
+ *SvEND(bufsv) = '\0';
+ (void)SvPOK_only(bufsv);
+ SvSETMAGIC(bufsv);
+ RETVAL = len;
+
+ OUTPUT:
+ RETVAL
SV *
GETC(stream)
- FCGI::Stream stream;
+ FCGI::Stream stream;
- PREINIT:
- int retval;
+ PREINIT:
+ int retval;
- CODE:
- if ((retval = FCGX_GetChar(stream)) != -1) {
- ST(0) = sv_newmortal();
- sv_setpvf(ST(0), "%c", retval);
- } else ST(0) = &PL_sv_undef;
+ CODE:
+ if ((retval = FCGX_GetChar(stream)) != -1) {
+ ST(0) = sv_newmortal();
+ sv_setpvf(ST(0), "%c", retval);
+ } else ST(0) = &PL_sv_undef;
bool
CLOSE(stream)
- FCGI::Stream stream;
+ FCGI::Stream stream;
-# ALIAS:
-# DESTROY = 1
+# ALIAS:
+# DESTROY = 1
- CODE:
- RETVAL = FCGX_FClose(stream) != -1;
+ CODE:
+ RETVAL = FCGX_FClose(stream) != -1;
- OUTPUT:
- RETVAL
+ OUTPUT:
+ RETVAL
#endif