summaryrefslogtreecommitdiff
path: root/sapi/cgi/libfcgi
diff options
context:
space:
mode:
authorShane Caraveo <shane@php.net>2002-12-01 21:37:14 +0000
committerShane Caraveo <shane@php.net>2002-12-01 21:37:14 +0000
commita3bd39429ca53a1a6647c505bb82803490943ee5 (patch)
treedc16515cb37323386ce3baa1e5fc3e3c0edc8cc0 /sapi/cgi/libfcgi
parent529762a21aca6afe44f42550d2f4d134b61ece60 (diff)
downloadphp-git-a3bd39429ca53a1a6647c505bb82803490943ee5.tar.gz
Fix CGI to match cgi spec.
This patch properly fixes support for CGI in PHP. For backwards compatible broken behaviour, cgi.fix_pathinfo can be set to zero in php.ini. CGI failed to work under apache at all, either using the cgi-script directive or as a ScriptAlias setup. Typicaly it would try to parse itself. This will still happen if you dissable fix_pathinfo, and set DISCARD_PATH. This also fixes PATH_INFO, and finally we can run pres2 under cgi or fastcgi. This patch has been tested under Apache 1.3, 2.0, IIS, as both cgi and fastcgi, on Windows and OSX. A followup patch with build stuff for linux will follow.
Diffstat (limited to 'sapi/cgi/libfcgi')
-rw-r--r--sapi/cgi/libfcgi/fcgiapp.c58
-rw-r--r--sapi/cgi/libfcgi/include/fcgiapp.h22
2 files changed, 55 insertions, 25 deletions
diff --git a/sapi/cgi/libfcgi/fcgiapp.c b/sapi/cgi/libfcgi/fcgiapp.c
index 863b5e8d6e..75d91f5b93 100644
--- a/sapi/cgi/libfcgi/fcgiapp.c
+++ b/sapi/cgi/libfcgi/fcgiapp.c
@@ -980,24 +980,7 @@ void FCGX_ClearError(FCGX_Stream *stream) {
*/
}
-/*
- *======================================================================
- * Parameters
- *======================================================================
- */
-/*
- * A vector of pointers representing the parameters received
- * by a FastCGI application server, with the vector's length
- * and last valid element so adding new parameters is efficient.
- */
-
-typedef struct Params {
- FCGX_ParamArray vec; /* vector of strings */
- int length; /* number of string vec can hold */
- char **cur; /* current item in vec; *cur == NULL */
-} Params;
-typedef Params *ParamsPtr;
/*
*----------------------------------------------------------------------
@@ -1071,13 +1054,45 @@ static void PutParam(ParamsPtr paramsPtr, char *nameValue)
*paramsPtr->cur++ = nameValue;
size = paramsPtr->cur - paramsPtr->vec;
if(size >= paramsPtr->length) {
- paramsPtr->length *= 2;
- paramsPtr->vec = (FCGX_ParamArray)realloc(paramsPtr->vec, paramsPtr->length * sizeof(char *));
- paramsPtr->cur = paramsPtr->vec + size;
+ paramsPtr->length *= 2;
+ paramsPtr->vec = (FCGX_ParamArray)realloc(paramsPtr->vec, paramsPtr->length * sizeof(char *));
+ paramsPtr->cur = paramsPtr->vec + size;
}
*paramsPtr->cur = NULL;
}
+
+void FCGX_PutEnv(FCGX_Request *request, char *var)
+{
+ char *nameValue;
+ char *e, **p;
+ int len;
+
+ if (!strchr(var,'=')) {
+ return;
+ }
+ nameValue = StringCopy(var);
+ e = strchr(nameValue,'=');
+ *e = 0;
+
+ /* find the name and replace it */
+ len = strlen(nameValue);
+
+ for (p = request->envp; p && *p; ++p) {
+ if((strncmp(nameValue, *p, len) == 0) && ((*p)[len] == '=')) {
+ free(*p);
+ *e = '=';
+ *p = nameValue;
+ return;
+ }
+ }
+ *e = '=';
+ /* this is a new var, add it to the environment */
+ PutParam(request->paramsPtr,nameValue);
+ request->envp = request->paramsPtr->vec;
+}
+
+
/*
*----------------------------------------------------------------------
*
@@ -1100,7 +1115,7 @@ char *FCGX_GetParam(const char *name, FCGX_ParamArray envp)
len = strlen(name);
- for (p = envp; *p; ++p) {
+ for (p = envp; p && *p; ++p) {
if((strncmp(name, *p, len) == 0) && ((*p)[len] == '=')) {
return *p+len+1;
}
@@ -2027,6 +2042,7 @@ void FCGX_Free(FCGX_Request * request, int close)
_FCGX_FreeStream(&request->out, FALSE);
_FCGX_FreeStream(&request->err, FALSE);
FreeParams(&request->paramsPtr);
+ request->envp = NULL;
if (close) {
OS_IpcClose(request->ipcFd);
diff --git a/sapi/cgi/libfcgi/include/fcgiapp.h b/sapi/cgi/libfcgi/include/fcgiapp.h
index 394e2078f9..8e35e0776c 100644
--- a/sapi/cgi/libfcgi/include/fcgiapp.h
+++ b/sapi/cgi/libfcgi/include/fcgiapp.h
@@ -80,6 +80,19 @@ typedef struct FCGX_Stream {
typedef char **FCGX_ParamArray;
/*
+ * A vector of pointers representing the parameters received
+ * by a FastCGI application server, with the vector's length
+ * and last valid element so adding new parameters is efficient.
+ */
+
+typedef struct Params {
+ FCGX_ParamArray vec; /* vector of strings */
+ int length; /* number of string vec can hold */
+ char **cur; /* current item in vec; *cur == NULL */
+} Params;
+typedef Params *ParamsPtr;
+
+/*
* FCGX_Request Flags
*
* Setting FCGI_FAIL_ACCEPT_ON_INTR prevents FCGX_Accept() from
@@ -98,11 +111,11 @@ typedef struct FCGX_Request {
FCGX_Stream *in;
FCGX_Stream *out;
FCGX_Stream *err;
- char **envp;
+ FCGX_ParamArray envp;
/* Don't use anything below here */
- struct Params *paramsPtr;
+ ParamsPtr paramsPtr;
int ipcFd; /* < 0 means no connection */
int isBeginProcessed; /* FCGI_BEGIN_REQUEST seen */
int keepConnection; /* don't close ipcFd at end of request */
@@ -351,7 +364,8 @@ DLLAPI void FCGX_SetExitStatus(int status, FCGX_Stream *stream);
*----------------------------------------------------------------------
*/
DLLAPI char *FCGX_GetParam(const char *name, FCGX_ParamArray envp);
-
+DLLAPI void FCGX_PutEnv(FCGX_Request *request, char *nameValue);
+
/*
*======================================================================
* Readers
@@ -533,7 +547,7 @@ DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg);
*----------------------------------------------------------------------
*/
DLLAPI int FCGX_FFlush(FCGX_Stream *stream);
-
+
/*
*======================================================================
* Both Readers and Writers