[mapserver-commits] r7549 - in trunk/mapserver: . mapscript/php3 mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Wed Apr 30 16:50:31 EDT 2008


Author: dmorissette
Date: 2008-04-30 16:50:31 -0400 (Wed, 30 Apr 2008)
New Revision: 7549

Modified:
   trunk/mapserver/mapows.c
   trunk/mapserver/mapows.h
   trunk/mapserver/mapscript/php3/mapscript_i.c
   trunk/mapserver/mapscript/swiginc/map.i
   trunk/mapserver/mapserv.c
   trunk/mapserver/mapserv.h
   trunk/mapserver/maptemplate.h
Log:
First pass at supporting mode=ows, not fully working yet (#2531)

Modified: trunk/mapserver/mapows.c
===================================================================
--- trunk/mapserver/mapows.c	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapows.c	2008-04-30 20:50:31 UTC (rev 7549)
@@ -40,11 +40,13 @@
 ** msOWSDispatch() is the entry point for any OWS request (WMS, WFS, ...)
 ** - If this is a valid request then it is processed and MS_SUCCESS is returned
 **   on success, or MS_FAILURE on failure.
-** - If this does not appear to be a valid OWS request then MS_DONE
-**   is returned and MapServer is expected to process this as a regular
-**   MapServer request.
+** - If force_ows_mode is true then an exception will be produced if the
+**   request is not recognized as a valid request.
+** - If force_ows_mode is false and this does not appear to be a valid OWS 
+**   request then MS_DONE is returned and MapServer is expected to process 
+**   this as a regular MapServer (traditional CGI) request.
 */
-int msOWSDispatch(mapObj *map, cgiRequestObj *request)
+int msOWSDispatch(mapObj *map, cgiRequestObj *request, int force_ows_mode)
 {
     int i, status = MS_DONE;
     const char *service=NULL;
@@ -59,6 +61,9 @@
     }
 
 #ifdef USE_WMS_SVR
+    /* Note: SERVICE param did not exist in WMS 1.0.0, it was added only in WMS 1.1.0,
+     * so we need to let msWMSDispatch check for known REQUESTs even if SERVICE is not set.
+     */
     if ((status = msWMSDispatch(map, request)) != MS_DONE )
         return status;
 #else
@@ -69,6 +74,9 @@
 #endif
 
 #ifdef USE_WFS_SVR
+    /* Note: WFS supports POST requests, so the SERVICE param may only be in the post data
+     * and not be present in the GET URL
+     */
     if ((status = msWFSDispatch(map, request)) != MS_DONE )
         return status;
 #else
@@ -98,7 +106,32 @@
                     "msOWSDispatch()" );
 #endif
 
-    return MS_DONE;  /* Not a WMS/WFS request... let MapServer handle it */
+    if (force_ows_mode) {
+        if (service == NULL)
+            /* Here we should return real OWS Common exceptions... once 
+             * we have a proper exception handler in mapowscommon.c 
+             */
+            msSetError( MS_MISCERR,
+                        "OWS Common exception: exceptionCode=MissingParameterValue, locator=SERVICE, ExceptionText=SERVICE parameter missing.", 
+                        "msOWSDispatch()");
+        else
+            /* Here we should return real OWS Common exceptions... once 
+             * we have a proper exception handler in mapowscommon.c 
+             */
+            msSetError( MS_MISCERR,
+                        "OWS Common exception: exceptionCode=InvalidParameterValue, locator=SERVICE, ExceptionText=SERVICE parameter value invalid.", 
+                        "msOWSDispatch()");
+        
+        /* Force mapserv to report the error by returning MS_FAILURE. 
+         * The day we have a proper exception handler here then we should 
+         * return MS_SUCCESS since the exception will have been processed 
+         * the OWS way, which is a success as far as mapserv is concerned 
+         */
+        return MS_FAILURE; 
+    }
+
+    return MS_DONE;  /* Not a WMS/WFS request... let MapServer handle it 
+                      * since we're not in force_ows_mode*/
 }
 
 #if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) || defined(USE_WMS_LYR) || defined(USE_WFS_LYR)

Modified: trunk/mapserver/mapows.h
===================================================================
--- trunk/mapserver/mapows.h	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapows.h	2008-04-30 20:50:31 UTC (rev 7549)
@@ -138,7 +138,7 @@
 /*====================================================================
  *   mapows.c
  *====================================================================*/
-MS_DLL_EXPORT int msOWSDispatch(mapObj *map, cgiRequestObj *request);
+MS_DLL_EXPORT int msOWSDispatch(mapObj *map, cgiRequestObj *request, int force_ows_mode);
 
 #if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) || defined(USE_WMS_LYR) || defined(USE_WFS_LYR)
 

Modified: trunk/mapserver/mapscript/php3/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php3/mapscript_i.c	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapscript/php3/mapscript_i.c	2008-04-30 20:50:31 UTC (rev 7549)
@@ -332,7 +332,7 @@
 
 int mapObj_OWSDispatch(mapObj *self, cgiRequestObj *req )
 {
-    return msOWSDispatch( self, req);
+    return msOWSDispatch( self, req, TRUE);
 }
 
 /**********************************************************************

Modified: trunk/mapserver/mapscript/swiginc/map.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/map.i	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapscript/swiginc/map.i	2008-04-30 20:50:31 UTC (rev 7549)
@@ -452,7 +452,7 @@
 
     int OWSDispatch( cgiRequestObj *req )
     {
-	return msOWSDispatch( self, req );
+	return msOWSDispatch( self, req, TRUE );
     }
 
 }

Modified: trunk/mapserver/mapserv.c
===================================================================
--- trunk/mapserver/mapserv.c	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapserv.c	2008-04-30 20:50:31 UTC (rev 7549)
@@ -274,11 +274,49 @@
 }
 
 /*
+** Set operation mode. First look in MS_MODE env. var. as a
+** default value that can be overridden by the mode=... CGI param.
+** Returns silently, leaving msObj->Mode unchanged if mode param not set.
+*/
+static int setMode(void)
+{
+    const char *mode = NULL;
+    int i, j;
+
+
+    mode = getenv("MS_MODE");
+    for( i=0; i<msObj->request->NumParams; i++ ) 
+    {
+        if(strcasecmp(msObj->request->ParamNames[i], "mode") == 0)
+        {
+            mode = msObj->request->ParamValues[i];
+            break;
+        }
+    }
+
+    if (mode) {
+      for(j=0; j<numModes; j++) {
+        if(strcasecmp(mode, modeStrings[j]) == 0) {
+          msObj->Mode = j;
+          break;
+        }
+      }
+
+      if(j == numModes) {
+        msSetError(MS_WEBERR, "Invalid mode.", "setMode()");
+        return MS_FAILURE;
+      }
+    }
+
+    return MS_SUCCESS;
+}
+
+/*
 ** Process CGI parameters.
 */
 void loadForm(void)
 {
-  int i,j,n;
+  int i,n;
   char **tokens=NULL;
   int rosa_type=0;
 
@@ -817,32 +855,6 @@
       continue;
     }
 
-    if(strcasecmp(msObj->request->ParamNames[i],"mode") == 0) { /* set operation mode */
-      for(j=0; j<numModes; j++) {
-        if(strcasecmp(msObj->request->ParamValues[i], modeStrings[j]) == 0) {
-          msObj->Mode = j;
-
-          if(msObj->Mode == ZOOMIN) {
-            msObj->ZoomDirection = 1;
-            msObj->Mode = BROWSE;
-          }
-          if(msObj->Mode == ZOOMOUT) {
-            msObj->ZoomDirection = -1;
-            msObj->Mode = BROWSE;
-          }
-
-          break;
-        }
-      }
-
-      if(j == numModes) {
-        msSetError(MS_WEBERR, "Invalid mode.", "loadForm()");
-        writeError();
-      }
-
-      continue;
-    }
-
     /* -------------------------------------------------------------------- 
      *   The following code is used to support mode=tile                    
      * -------------------------------------------------------------------- */ 
@@ -940,6 +952,15 @@
 
   } /* next parameter */
 
+  if(msObj->Mode == ZOOMIN) {
+    msObj->ZoomDirection = 1;
+    msObj->Mode = BROWSE;
+  }     
+  if(msObj->Mode == ZOOMOUT) {
+    msObj->ZoomDirection = -1;
+    msObj->Mode = BROWSE;
+  }
+
   if(ZoomSize != 0) { /* use direction and magnitude to calculate zoom */
     if(msObj->ZoomDirection == 0) {
       msObj->fZoom = 1;
@@ -1049,6 +1070,7 @@
   writeError();
 }
 
+
 /************************************************************************/
 /*                      FastCGI cleanup functions.                      */
 /************************************************************************/
@@ -1204,11 +1226,22 @@
     }
 
     /*
+    ** Determine 'mode': Check for MS_MODE env. var. and mode=... CGI param
+    */
+    msObj->Mode = -1; /* Not set */
+    if( setMode() != MS_SUCCESS)
+        writeError();
+
+    /*
     ** Start by calling the WMS/WFS/WCS Dispatchers.  If they fail then we'll 
     ** process this as a regular MapServer request.
     */
-    if((status = msOWSDispatch(msObj->Map, msObj->request)) != MS_DONE  )  {
+    if((msObj->Mode == -1 || msObj->Mode == OWS) &&
+       (status = msOWSDispatch(msObj->Map, msObj->request,
+                               (msObj->Mode == OWS))) != MS_DONE  )  {
       /*
+      ** OWSDispatch returned either MS_SUCCESS or MS_FAILURE
+      **
       ** Normally if the OWS service fails it will issue an exception,
       ** and clear the error stack but still return MS_FAILURE.  But in
       ** a few situations it can't issue the exception and will instead 
@@ -1222,7 +1255,7 @@
       }
         
       /* 
-			** This was a WMS/WFS request... cleanup and exit 
+      ** This was a WMS/WFS request... cleanup and exit 
       ** At this point any error has already been handled
       ** as an XML exception by the OGC service.
       */
@@ -1266,6 +1299,8 @@
     /*
     ** Do "traditional" mode processing.
     */
+    if (msObj->Mode == -1)
+        msObj->Mode = BROWSE;
 
     loadForm();
  

Modified: trunk/mapserver/mapserv.h
===================================================================
--- trunk/mapserver/mapserv.h	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/mapserv.h	2008-04-30 20:50:31 UTC (rev 7549)
@@ -57,13 +57,13 @@
 /*
 ** Enumerated types, keep the query modes in sequence and at the end of the enumeration (mode enumeration is in maptemplate.h).
 */
-int numModes = 28;
-static char *modeStrings[28] = {"BROWSE","ZOOMIN","ZOOMOUT","MAP","LEGEND","LEGENDICON","REFERENCE","SCALEBAR","COORDINATE",
+int numModes = 29;
+static char *modeStrings[29] = {"BROWSE","ZOOMIN","ZOOMOUT","MAP","LEGEND","LEGENDICON","REFERENCE","SCALEBAR","COORDINATE",
                                 "QUERY","QUERYMAP","NQUERY","NQUERYMAP",
 			        "ITEMQUERY","ITEMQUERYMAP","ITEMNQUERY","ITEMNQUERYMAP",
 				"FEATUREQUERY","FEATUREQUERYMAP","FEATURENQUERY","FEATURENQUERYMAP",
 				"ITEMFEATUREQUERY","ITEMFEATUREQUERYMAP","ITEMFEATURENQUERY","ITEMFEATURENQUERYMAP",
-				"INDEXQUERY","INDEXQUERYMAP","TILE"};
+				"INDEXQUERY","INDEXQUERYMAP","TILE","OWS"};
 
 /*
 ** Global variables

Modified: trunk/mapserver/maptemplate.h
===================================================================
--- trunk/mapserver/maptemplate.h	2008-04-30 20:27:12 UTC (rev 7548)
+++ trunk/mapserver/maptemplate.h	2008-04-30 20:50:31 UTC (rev 7549)
@@ -45,7 +45,7 @@
             ITEMQUERY, ITEMQUERYMAP, ITEMNQUERY, ITEMNQUERYMAP, 
             FEATUREQUERY, FEATUREQUERYMAP, FEATURENQUERY, FEATURENQUERYMAP, 
             ITEMFEATUREQUERY, ITEMFEATUREQUERYMAP, ITEMFEATURENQUERY, ITEMFEATURENQUERYMAP,
-            INDEXQUERY, INDEXQUERYMAP, TILE};
+            INDEXQUERY, INDEXQUERYMAP, TILE, OWS};
 
 
 /*! \srtuct mapservObj



More information about the mapserver-commits mailing list