Fixed indent style and braces to be consistent
chansen [Sun, 29 Aug 2010 22:12:23 +0000 (00:12 +0200)]
perl/FCGI.XL

index 5628a2b..cc3536f 100644 (file)
@@ -94,7 +94,7 @@ sfdcdelfcgi(disc)
 #endif
 
 #if defined(USE_LOCKING) && defined(USE_THREADS)
-static perl_mutex   accept_mutex;
+static perl_mutex accept_mutex;
 #endif
 
 typedef struct FCGP_Request {
@@ -115,13 +115,10 @@ typedef struct FCGP_Request {
 static void FCGI_Finish(FCGP_Request* request);
 
 static void 
-FCGI_Flush(FCGP_Request* request)
-{
+FCGI_Flush(FCGP_Request* request) {
     dTHX;
-
-    if(!request->bound) {
-    return;
-    }
+    if(!request->bound)
+        return;
 #ifdef USE_SFIO
     sfsync(IoOFP(GvIOp(request->gv[1])));
     sfsync(IoOFP(GvIOp(request->gv[2])));
@@ -132,10 +129,8 @@ FCGI_Flush(FCGP_Request* request)
 }
 
 static void
-FCGI_UndoBinding(FCGP_Request* request)
-{
+FCGI_UndoBinding(FCGP_Request* request) {
     dTHX;
-
 #ifdef USE_SFIO
     sfdcdelfcgi(sfdisc(IoIFP(request->io[0]), SF_POPDISC));
     sfdcdelfcgi(sfdisc(IoOFP(request->io[1]), SF_POPDISC));
@@ -155,10 +150,8 @@ FCGI_UndoBinding(FCGP_Request* request)
 }
 
 static void
-FCGI_Bind(FCGP_Request* request)
-{
+FCGI_Bind(FCGP_Request* request) {
     dTHX;
-
 #ifdef USE_SFIO
     sfdisc(IoIFP(request->io[0]), sfdcnewfcgi(request->requestPtr->in));
     sfdisc(IoOFP(request->io[1]), sfdcnewfcgi(request->requestPtr->out));
@@ -169,11 +162,11 @@ FCGI_Bind(FCGP_Request* request)
        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);
@@ -188,38 +181,33 @@ FCGI_Bind(FCGP_Request* request)
 }
 
 static void
-populate_env(envp, hv)
-char **envp;
-HV *hv;
-{
+populate_env(char **envp, HV *hv) {
     int i;
     char *p, *p1;
-    SV   *sv;
+    SV *sv;
     dTHX;
 
     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
-FCGI_IsFastCGI(FCGP_Request* request)
-{
+FCGI_IsFastCGI(FCGP_Request* request) {
     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 */
@@ -227,119 +215,106 @@ FCGI_IsFastCGI(FCGP_Request* request)
 }
 
 static int 
-FCGI_Accept(FCGP_Request* request)
-{
+FCGI_Accept(FCGP_Request* request) {
     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;
-
-    been_here = 1;
-    } else {
+        * Not first call to FCGI_Accept and running as CGI means
+        * application is done.
+        */
+        if (been_here)
+            return EOF;
+        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, 
+        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;
+                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;
 }
 
 static void 
-FCGI_Finish(FCGP_Request* request)
-{
+FCGI_Finish(FCGP_Request* request) {
 #ifdef USE_SFIO
     int i;
 #endif
     int was_bound;
     dTHX;
 
-    if(!request->accepted) {
-    return;
-    }
+    if(!request->accepted)
+        return;
 
-    if (was_bound = request->bound) {
-    FCGI_UndoBinding(request);
-    }
+    if (was_bound = request->bound)
+        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;
 }
 
 static int 
-FCGI_StartFilterData(FCGP_Request* request)
-{
+FCGI_StartFilterData(FCGP_Request* request) {
     return request->requestPtr->in ? 
         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;
-{
+FCGI_Request(GV *in, GV *out, GV *err, HV *env, int socket, int flags) {
     FCGX_Request* fcgx_req;
     FCGP_Request* req;
 
@@ -360,8 +335,7 @@ FCGI_Request(in, out, err, env, socket, flags)
 }
 
 static void
-FCGI_Release_Request(FCGP_Request *req)
-{
+FCGI_Release_Request(FCGP_Request *req) {
     SvREFCNT_dec(req->gv[0]);
     SvREFCNT_dec(req->gv[1]);
     SvREFCNT_dec(req->gv[2]);
@@ -372,23 +346,20 @@ FCGI_Release_Request(FCGP_Request *req)
 }
 
 static void
-FCGI_Init()
-{
+FCGI_Init() {
 #if defined(USE_LOCKING) && defined(USE_THREADS)
     dTHX;
-
     MUTEX_INIT(&accept_mutex);
 #endif
-
     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();
@@ -401,92 +372,75 @@ RequestX(in, out, err, env, socket, flags)
     HASHREF env;
     int     socket;
     int     flags;
-
-    PROTOTYPE: ***$$$
-    CODE:
+  PROTOTYPE: ***$$$
+  CODE:
     RETVAL = sv_setref_pv(newSV(0), "FCGI", 
         FCGI_Request(in, out, err, env, socket, flags));
-
-    OUTPUT:
+  OUTPUT:
     RETVAL
 
 int
 OpenSocket(path, backlog)
     char* path;
     int backlog;
-
-    PROTOTYPE: $$
-    CODE:
+  PROTOTYPE: $$
+  CODE:
     RETVAL = FCGX_OpenSocket(path, backlog);
-    OUTPUT:
+  OUTPUT:
     RETVAL
 
 void
 CloseSocket(socket)
     int socket;
-
-    PROTOTYPE: $
-    CODE:
+  PROTOTYPE: $
+  CODE:
     close(socket);
 
 int
 FCGI_Accept(request)
-
     FCGI    request;
-
-    PROTOTYPE: $
+  PROTOTYPE: $
 
 void
 FCGI_Finish(request)
-    FCGI    request;
-
-    PROTOTYPE: $
+    FCGI request;
+  PROTOTYPE: $
 
 void
 FCGI_Flush(request)
-    FCGI    request;
-
-    PROTOTYPE: $
+    FCGI request;
+  PROTOTYPE: $
 
 HV *
 GetEnvironment(request)
-    FCGI    request;
-
-    PROTOTYPE: $
-
-    CODE:
+    FCGI request;
+  PROTOTYPE: $
+  CODE:
     RETVAL = request->hvEnv;
-
-    OUTPUT: 
+  OUTPUT: 
     RETVAL
 
 void
 GetHandles(request)
-    FCGI    request;
-
-    PROTOTYPE: $
-
-    PREINIT:
-    int     i;
-
-    PPCODE:
+    FCGI request;
+  PROTOTYPE: $
+  PREINIT:
+    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)
-    FCGI    request;
-
-    PROTOTYPE: $
+    FCGI request;
+  PROTOTYPE: $
 
 void
 Detach(request)
-    FCGI    request;
-
-    PROTOTYPE: $
-
-    CODE:
+    FCGI request;
+  PROTOTYPE: $
+  CODE:
     if (request->accepted && request->bound) {
         FCGI_UndoBinding(request);
         FCGX_Detach(request->requestPtr);
@@ -494,11 +448,9 @@ Detach(request)
 
 void
 Attach(request)
-    FCGI    request;
-
-    PROTOTYPE: $
-
-    CODE:
+    FCGI request;
+  PROTOTYPE: $
+  CODE:
     if (request->accepted && !request->bound) {
         FCGI_Bind(request);
         FCGX_Attach(request->requestPtr);
@@ -506,44 +458,35 @@ Attach(request)
 
 void
 LastCall(request)
-    FCGI    request;
-
-    PROTOTYPE: $
-
-    CODE:
+    FCGI request;
+  PROTOTYPE: $
+  CODE:
     FCGX_ShutdownPending();
 
 int
 FCGI_StartFilterData(request)
-
-    FCGI    request;
-
-    PROTOTYPE: $
+    FCGI request;
+  PROTOTYPE: $
 
 void
 DESTROY(request)
-    FCGI    request;
-
-    CODE:
+    FCGI request;
+  CODE:
     FCGI_Release_Request(request);
 
-
-
-MODULE = FCGI       PACKAGE = FCGI::Stream
+MODULE = FCGI PACKAGE = FCGI::Stream
 
 #ifndef USE_SFIO
 
 SV *
 PRINT(stream, ...)
-    FCGI::Stream    stream;
-
-    PREINIT:
+    FCGI::Stream stream;
+  PREINIT:
     int n;
     STRLEN len;
     register char *str;
     bool ok = TRUE;
-
-    CODE:
+  CODE:
     for (n = 1; ok && n < items; ++n) {
 #ifdef DO_UTF8
         if (DO_UTF8(ST(n)) && !sv_utf8_downgrade(ST(n), 1) && ckWARN_d(WARN_UTF8))
@@ -553,27 +496,23 @@ PRINT(stream, ...)
         if (FCGX_PutStr(str, len, 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:
-        RETVAL
+  OUTPUT:
+    RETVAL
 
 int
 WRITE(stream, bufsv, len, ...)
-    FCGI::Stream    stream;
-    SV *    bufsv;
+    FCGI::Stream stream;
+    SV *bufsv;
     int len;
-
-    PREINIT:
+  PREINIT:
     int offset;
-    char *  buf;
-    STRLEN  blen;
+    char *buf;
+    STRLEN blen;
     int n;
-
-    CODE:
+  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))
@@ -593,21 +532,19 @@ WRITE(stream, bufsv, len, ...)
 
 int
 READ(stream, bufsv, len, ...)
-    FCGI::Stream    stream;
-    SV *    bufsv;
+    FCGI::Stream stream;
+    SV *bufsv;
     int len;
-
-    PREINIT:
+  PREINIT:
     int offset;
-    char *  buf;
-
-    CODE:
+    char *buf;
+  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))
+    if (!SvOK(bufsv))
         sv_setpvn(bufsv, "", 0);
     buf = SvGROW(bufsv, len+offset+1);
     len = FCGX_GetStr(buf+offset, len, stream);
@@ -616,34 +553,28 @@ READ(stream, bufsv, len, ...)
     (void)SvPOK_only(bufsv);
     SvSETMAGIC(bufsv);
     RETVAL = len;
-
-    OUTPUT:
+  OUTPUT:
     RETVAL
 
 SV *
 GETC(stream)
-    FCGI::Stream    stream;
-
-    PREINIT:
+    FCGI::Stream stream;
+  PREINIT:
     int retval;
-
-    CODE:
+  CODE:
     if ((retval = FCGX_GetChar(stream)) != -1) {
         ST(0) = sv_newmortal();
         sv_setpvf(ST(0), "%c", retval);
-    } else ST(0) = &PL_sv_undef;
+    }
+    else
+        ST(0) = &PL_sv_undef;
 
 bool
 CLOSE(stream)
-    FCGI::Stream    stream;
-
-#   ALIAS:
-#   DESTROY = 1
-
-    CODE:
+    FCGI::Stream stream;
+  CODE:
     RETVAL = FCGX_FClose(stream) != -1;
-
-    OUTPUT:
+  OUTPUT:
     RETVAL
 
 #endif