[mapserver-commits] r9950 - in trunk/mapserver: . mapscript/php
mapscript/swiginc
svn at osgeo.org
svn at osgeo.org
Wed Mar 17 11:20:28 EDT 2010
Author: aboudreault
Date: 2010-03-17 11:20:27 -0400 (Wed, 17 Mar 2010)
New Revision: 9950
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/cgiutil.c
trunk/mapserver/cgiutil.h
trunk/mapserver/mapscript/php/mapscript_i.c
trunk/mapserver/mapscript/php/owsrequest.c
trunk/mapserver/mapscript/php/php_mapscript.c
trunk/mapserver/mapscript/php/php_mapscript.h
trunk/mapserver/mapscript/swiginc/owsrequest.i
trunk/mapserver/mapserv.c
Log:
Fixed PHP/MapScript owsRequestObj->loadParams() method when using php in a non cgi/fcgi/cli mode. (#1975)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/HISTORY.TXT 2010-03-17 15:20:27 UTC (rev 9950)
@@ -14,6 +14,8 @@
Current Version (SVN trunk):
----------------------------
+- Fixed PHP/MapScript owsRequestObj->loadParams() method when using php in a non cgi/fcgi/cli mode. (#1975)
+
- Ensure that non-file raster datasets work (#3253)
- Correct mutex locking problem with rasters with no inherent georef. (#3368)
Modified: trunk/mapserver/cgiutil.c
===================================================================
--- trunk/mapserver/cgiutil.c 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/cgiutil.c 2010-03-17 15:20:27 UTC (rev 9950)
@@ -76,7 +76,6 @@
data[data_max] = '\0';
return data;
}
-
/* -------------------------------------------------------------------- */
/* Otherwise read in chunks to the end. */
/* -------------------------------------------------------------------- */
@@ -112,12 +111,24 @@
return data;
}
-int loadParams(cgiRequestObj *request) {
+static char* msGetEnv(const char *name, void* thread_context)
+{
+ return getenv(name);
+}
+
+int loadParams(cgiRequestObj *request,
+ char* (*getenv2)(const char*, void* thread_context),
+ char *raw_post_data,
+ uint raw_post_data_length,
+ void* thread_context) {
register int x,m=0;
- char *s;
+ char *s, *queryString = NULL, *httpCookie = NULL;
int debuglevel;
+
+ if (getenv2==NULL)
+ getenv2 = &msGetEnv;
- if(getenv("REQUEST_METHOD")==NULL) {
+ if(getenv2("REQUEST_METHOD", thread_context)==NULL) {
msIO_printf("This script can only be used to decode form results and \n");
msIO_printf("should be initiated as a CGI process via a httpd server.\n");
exit(0);
@@ -125,12 +136,12 @@
debuglevel = (int)msGetGlobalDebugLevel();
- if(strcmp(getenv("REQUEST_METHOD"),"POST") == 0) { /* we've got a post from a form */
+ if(strcmp(getenv2("REQUEST_METHOD", thread_context),"POST") == 0) { /* we've got a post from a form */
char *post_data;
-
+ int data_len;
request->type = MS_POST_REQUEST;
- s = getenv("CONTENT_TYPE");
+ s = getenv2("CONTENT_TYPE", thread_context);
if (s != NULL)
request->contenttype = strdup(s);
/* we've to set default content-type which is
@@ -138,11 +149,19 @@
* W3 RFC 2626 section 7.2.1 */
else request->contenttype = strdup("application/octet-stream");
- post_data = readPostBody( request );
- if(strcmp(request->contenttype, "application/x-www-form-urlencoded"))
- request->postrequest = post_data;
+ if (raw_post_data) {
+ post_data = strdup(raw_post_data);
+ data_len = raw_post_data_length;
+ }
else {
- int data_len = strlen(post_data);
+ post_data = readPostBody( request );
+ data_len = strlen(post_data);
+ }
+
+ /* if the content_type is application/x-www-form-urlencoded,
+ we have to parse it like the QUERY_STRING variable */
+ if(strcmp(request->contenttype, "application/x-www-form-urlencoded") == 0)
+ {
while( data_len > 0 && isspace(post_data[data_len-1]) )
post_data[--data_len] = '\0';
@@ -151,7 +170,6 @@
msIO_printf("Too many name/value pairs, aborting.\n");
exit(0);
}
-
request->ParamValues[m] = makeword(post_data,'&');
plustospace(request->ParamValues[m]);
unescape_url(request->ParamValues[m]);
@@ -160,20 +178,24 @@
}
free( post_data );
}
+ else
+ request->postrequest = post_data;
/* check the QUERY_STRING even in the post request since it can contain
information. Eg a wfs request with */
- s = getenv("QUERY_STRING");
+ s = getenv2("QUERY_STRING", thread_context);
if(s) {
if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
msDebug("loadParams() QUERY_STRING: %s\n", s);
- for(x=0;s[0] != '\0';x++) {
+ queryString = strdup(s);
+ for(x=0;queryString[0] != '\0';x++) {
if(m >= MS_MAX_CGI_PARAMS) {
msIO_printf("Too many name/value pairs, aborting.\n");
+ free(queryString);
exit(0);
- }
- request->ParamValues[m] = makeword(s,'&');
+ }
+ request->ParamValues[m] = makeword(queryString,'&');
plustospace(request->ParamValues[m]);
unescape_url(request->ParamValues[m]);
request->ParamNames[m] = makeword(request->ParamValues[m],'=');
@@ -181,35 +203,38 @@
}
}
} else {
- if(strcmp(getenv("REQUEST_METHOD"),"GET") == 0) { /* we've got a get request */
+ if(strcmp(getenv2("REQUEST_METHOD", thread_context),"GET") == 0) { /* we've got a get request */
request->type = MS_GET_REQUEST;
- s = getenv("QUERY_STRING");
+ s = getenv2("QUERY_STRING", thread_context);
if(s == NULL) {
msIO_printf("Content-type: text/html%c%c",10,10);
msIO_printf("No query information to decode. QUERY_STRING not set.\n");
exit(1);
}
+
+ if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
+ msDebug("loadParams() QUERY_STRING: %s\n", s);
- if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
- msDebug("loadParams() QUERY_STRING: %s\n", s);
-
if(strlen(s)==0) {
msIO_printf("Content-type: text/html%c%c",10,10);
msIO_printf("No query information to decode. QUERY_STRING is set, but empty.\n");
exit(1);
}
-
- for(x=0;s[0] != '\0';x++) {
- if(m >= MS_MAX_CGI_PARAMS) {
+
+ /* don't modify the string returned by getenv2 */
+ queryString = strdup(s);
+ for(x=0;queryString[0] != '\0';x++) {
+ if(m >= MS_MAX_CGI_PARAMS) {
msIO_printf("Too many name/value pairs, aborting.\n");
+ free(queryString);
exit(0);
- }
- request->ParamValues[m] = makeword(s,'&');
- plustospace(request->ParamValues[m]);
- unescape_url(request->ParamValues[m]);
- request->ParamNames[m] = makeword(request->ParamValues[m],'=');
- m++;
+ }
+ request->ParamValues[m] = makeword(queryString,'&');
+ plustospace(request->ParamValues[m]);
+ unescape_url(request->ParamValues[m]);
+ request->ParamNames[m] = makeword(request->ParamValues[m],'=');
+ m++;
}
} else {
msIO_printf("Content-type: text/html%c%c",10,10);
@@ -219,21 +244,28 @@
}
/* check for any available cookies */
- s = getenv("HTTP_COOKIE");
+ s = getenv2("HTTP_COOKIE", thread_context);
if(s != NULL) {
+ httpCookie = strdup(s);
request->httpcookiedata = strdup(s);
- for(x=0;s[0] != '\0';x++) {
- if(m >= MS_MAX_CGI_PARAMS) {
+ for(x=0;httpCookie[0] != '\0';x++) {
+ if(m >= MS_MAX_CGI_PARAMS) {
msIO_printf("Too many name/value pairs, aborting.\n");
+ free(httpCookie);
exit(0);
}
- request->ParamValues[m] = makeword(s,';');
+ request->ParamValues[m] = makeword(httpCookie,';');
plustospace(request->ParamValues[m]);
unescape_url(request->ParamValues[m]);
request->ParamNames[m] = makeword_skip(request->ParamValues[m],'=',' ');
m++;
}
}
+
+ if (queryString)
+ free(queryString);
+ if (httpCookie)
+ free(httpCookie);
return(m);
}
@@ -270,12 +302,12 @@
}
char *makeword(char *line, char stop) {
- int x = 0,y;
+ int x = 0,y;
char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
-
+
for(x=0;((line[x]) && (line[x] != stop));x++)
word[x] = line[x];
-
+
word[x] = '\0';
if(line[x]) ++x;
y=0;
Modified: trunk/mapserver/cgiutil.h
===================================================================
--- trunk/mapserver/cgiutil.h 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/cgiutil.h 2010-03-17 15:20:27 UTC (rev 9950)
@@ -74,7 +74,8 @@
** Function prototypes
*/
#ifndef SWIG
-MS_DLL_EXPORT int loadParams(cgiRequestObj *);
+MS_DLL_EXPORT int loadParams(cgiRequestObj *request, char* (*getenv2)(const char*, void* thread_context),
+ char *raw_post_data, uint raw_post_data_length, void* thread_context);
MS_DLL_EXPORT void getword(char *, char *, char);
MS_DLL_EXPORT char *makeword_skip(char *, char, char);
MS_DLL_EXPORT char *makeword(char *, char);
Modified: trunk/mapserver/mapscript/php/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php/mapscript_i.c 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapscript/php/mapscript_i.c 2010-03-17 15:20:27 UTC (rev 9950)
@@ -1422,10 +1422,14 @@
return request;
}
-int cgirequestObj_loadParams(cgiRequestObj *self)
+int cgirequestObj_loadParams(cgiRequestObj *self,
+ char* (*getenv2)(const char*, void* thread_context),
+ char *raw_post_data,
+ uint raw_post_data_length,
+ void* thread_context)
{
- self->NumParams = loadParams(self);
- return self->NumParams;
+ self->NumParams = loadParams(self, getenv2, raw_post_data, raw_post_data_length, thread_context);
+ return self->NumParams;
}
Modified: trunk/mapserver/mapscript/php/owsrequest.c
===================================================================
--- trunk/mapserver/mapscript/php/owsrequest.c 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapscript/php/owsrequest.c 2010-03-17 15:20:27 UTC (rev 9950)
@@ -30,7 +30,11 @@
**********************************************************************/
#include "php_mapscript.h"
+#include "SAPI.h"
+#include "php_variables.h"
+char *owsrequest_getenv(const char *name, void *thread_context);
+
zend_class_entry *mapscript_ce_owsrequest;
ZEND_BEGIN_ARG_INFO_EX(owsrequest___get_args, 0, 0, 1)
@@ -148,8 +152,16 @@
PHP_METHOD(OWSRequestObj, loadParams)
{
zval *zobj = getThis();
+ zval **val;
php_owsrequest_object *php_owsrequest;
+ void *thread_context;
+#ifdef ZTS
+ thread_context = (void*)TSRMLS_C;
+#else
+ thread_context = NULL;
+#endif
+
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters_none() == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
@@ -159,8 +171,35 @@
php_owsrequest = (php_owsrequest_object *) zend_object_store_get_object(zobj TSRMLS_CC);
- cgirequestObj_loadParams(php_owsrequest->cgirequest);
-
+ if ( (STRING_EQUAL(sapi_module.name,"cli")) ||
+ (STRING_EQUAL(sapi_module.name,"cgi")) ||
+ (STRING_EQUAL(sapi_module.name,"cgi-fcgi")) )
+ {
+ cgirequestObj_loadParams(php_owsrequest->cgirequest, NULL, NULL, 0, thread_context);
+ }
+ else
+ {
+ // check if we have input data for GET method
+ if (SG(request_info).request_method &&
+ STRING_EQUAL(SG(request_info).request_method, "GET"))
+ {
+ zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+ if ( PG(http_globals)[TRACK_VARS_SERVER] &&
+ (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "QUERY_STRING", sizeof("QUERY_STRING"), (void **) &val) == SUCCESS) &&
+ (Z_TYPE_PP(val) == IS_STRING) &&
+ (Z_STRLEN_PP(val) > 0) )
+ {
+ cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, NULL, 0, thread_context);
+ }
+ }
+ else
+ {
+ cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv,
+ SG(request_info).raw_post_data,
+ SG(request_info).raw_post_data_length, thread_context);
+ }
+ }
+
RETURN_LONG(php_owsrequest->cgirequest->NumParams);
}
/* }}} */
@@ -286,6 +325,52 @@
{NULL, NULL, NULL}
};
+char *owsrequest_getenv(const char *name, void *thread_context)
+{
+ zval **val, **ppzval;
+ zval *cookie_result, *key;
+ HashTable *cookies;
+ char *string_key = NULL, *cookie_tmp;
+ ulong num_key;
+ int numElements, i = 0;
+ TSRMLS_FETCH_FROM_CTX(thread_context);
+
+ if (STRING_EQUAL(name, "HTTP_COOKIE"))
+ {
+ cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht;
+ numElements = zend_hash_num_elements(cookies);
+ MAKE_STD_ZVAL(cookie_result);
+ ZVAL_STRING(cookie_result, "",1);
+ for(zend_hash_internal_pointer_reset(cookies);
+ zend_hash_has_more_elements(cookies) == SUCCESS;
+ zend_hash_move_forward(cookies), ++i)
+ {
+ zend_hash_get_current_data(cookies, (void **)&ppzval);
+ zend_hash_get_current_key(cookies, &string_key, &num_key, 1);
+ cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char));
+ sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval));
+ MAKE_STD_ZVAL(key);
+ ZVAL_STRING(key, cookie_tmp,1);
+ add_string_to_string(cookie_result,cookie_result, key);
+ zval_dtor(key);
+ free(cookie_tmp);
+ }
+ return Z_STRVAL_P(cookie_result);
+ }
+ else
+ {
+ zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+ if ( PG(http_globals)[TRACK_VARS_SERVER] &&
+ (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) &&
+ (Z_TYPE_PP(val) == IS_STRING))
+ {
+ return Z_STRVAL_PP(val);
+ }
+ }
+
+ return NULL;
+}
+
void mapscript_create_owsrequest(cgiRequestObj *cgirequest, zval *return_value TSRMLS_DC)
{
php_owsrequest_object * php_owsrequest;
@@ -327,6 +412,7 @@
mapscript_owsrequest_object_new);
mapscript_ce_owsrequest->ce_flags |= ZEND_ACC_FINAL_CLASS;
-
+
return SUCCESS;
}
+
Modified: trunk/mapserver/mapscript/php/php_mapscript.c
===================================================================
--- trunk/mapserver/mapscript/php/php_mapscript.c 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapscript/php/php_mapscript.c 2010-03-17 15:20:27 UTC (rev 9950)
@@ -1208,15 +1208,15 @@
PHP_MINIT(shapefile)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(layer)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(map)(INIT_FUNC_ARGS_PASSTHRU);
-
+
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(mapscript)
{
/* Cleanup MapServer resources */
- msCleanup();
-
+ msCleanup();
+
return SUCCESS;
}
Modified: trunk/mapserver/mapscript/php/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php/php_mapscript.h 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapscript/php/php_mapscript.h 2010-03-17 15:20:27 UTC (rev 9950)
@@ -735,7 +735,11 @@
cgiRequestObj *cgirequestObj_new();
-int cgirequestObj_loadParams(cgiRequestObj *self);
+int cgirequestObj_loadParams(cgiRequestObj *self,
+ char* (*getenv2)(const char*, void* thread_context),
+ char *raw_post_data,
+ uint raw_post_data_length,
+ void* thread_context);
void cgirequestObj_setParameter(cgiRequestObj *self, char *name, char *value);
char *cgirequestObj_getName(cgiRequestObj *self, int index);
char *cgirequestObj_getValue(cgiRequestObj *self, int index);
Modified: trunk/mapserver/mapscript/swiginc/owsrequest.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/owsrequest.i 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapscript/swiginc/owsrequest.i 2010-03-17 15:20:27 UTC (rev 9950)
@@ -76,7 +76,7 @@
int loadParams()
{
- self->NumParams = loadParams( self );
+ self->NumParams = loadParams( self, NULL, NULL, 0, NULL);
return self->NumParams;
}
Modified: trunk/mapserver/mapserv.c
===================================================================
--- trunk/mapserver/mapserv.c 2010-03-17 02:25:35 UTC (rev 9949)
+++ trunk/mapserver/mapserv.c 2010-03-17 15:20:27 UTC (rev 9950)
@@ -1207,7 +1207,7 @@
writeError();
}
- mapserv->request->NumParams = loadParams(mapserv->request);
+ mapserv->request->NumParams = loadParams(mapserv->request, NULL, NULL, 0, NULL);
if( mapserv->request->NumParams == -1 ) {
#ifdef USE_FASTCGI
/* FCGI_ --- return to top of loop */
More information about the mapserver-commits
mailing list