[mapserver-commits] r11157 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sun Mar 13 18:05:54 EDT 2011


Author: dmorissette
Date: 2011-03-13 15:05:54 -0700 (Sun, 13 Mar 2011)
New Revision: 11157

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapows.c
   trunk/mapserver/mapserver.h
   trunk/mapserver/maptemplate.c
   trunk/mapserver/maputil.c
Log:
Make openlayers mode and [mapserv_onlineresource] work even without OWS support (#3732)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-03-11 21:14:42 UTC (rev 11156)
+++ trunk/mapserver/HISTORY.TXT	2011-03-13 22:05:54 UTC (rev 11157)
@@ -14,8 +14,10 @@
 Current Version (SVN trunk):
 ----------------------------
 
-- Add a static table to define the axis order for soem epsg codes (/3582)
+- Make "openlayers mode" work even without OWS support (#3732)
 
+- Add a static table to define the axis order for soem epsg codes (#3582)
+
 - Add possibility to use KML_NAME_ITEM (#3728)
 
 - Fixed mapfile parsing error when a label angle referenced an attribute 

Modified: trunk/mapserver/mapows.c
===================================================================
--- trunk/mapserver/mapows.c	2011-03-11 21:14:42 UTC (rev 11156)
+++ trunk/mapserver/mapows.c	2011-03-13 22:05:54 UTC (rev 11157)
@@ -570,7 +570,6 @@
                               cgiRequestObj *req)
 {
     const char *value;
-    size_t buffer_size = 0;
     char *online_resource = NULL;
 
     /* We need this script's URL, including hostname. */
@@ -584,69 +583,13 @@
     }
     else 
     {
-        const char *hostname, *port, *script, *protocol="http", *mapparam=NULL;
-        int mapparam_len = 0;
-
-        hostname = getenv("SERVER_NAME");
-        port = getenv("SERVER_PORT");
-        script = getenv("SCRIPT_NAME");
-
-        /* HTTPS is set by Apache to "on" in an HTTPS server ... if not set */
-        /* then check SERVER_PORT: 443 is the default https port. */
-        if ( ((value=getenv("HTTPS")) && strcasecmp(value, "on") == 0) ||
-             ((value=getenv("SERVER_PORT")) && atoi(value) == 443) )
+        if ((online_resource = msBuildOnlineResource(map, req)) == NULL)
         {
-            protocol = "https";
-        }
-
-        /* If map=.. was explicitly set then we'll include it in onlineresource
-         */
-        if (req->type == MS_GET_REQUEST)
-        {
-            int i;
-            for(i=0; i<req->NumParams; i++)
-            {
-                if (strcasecmp(req->ParamNames[i], "map") == 0)
-                {
-                    mapparam = req->ParamValues[i];
-                    mapparam_len = strlen(mapparam)+5; /* +5 for "map="+"&" */
-                    break;
-                }
-            }
-        }
-
-        if (hostname && port && script) {
-            buffer_size = strlen(hostname)+strlen(port)+strlen(script)+mapparam_len+10;
-            online_resource = (char*)malloc(buffer_size);
-            if (online_resource) 
-            {
-                if ((atoi(port) == 80 && strcmp(protocol, "http") == 0) ||
-                    (atoi(port) == 443 && strcmp(protocol, "https") == 0) )
-                    snprintf(online_resource, buffer_size, "%s://%s%s?", protocol, hostname, script);
-                else
-                    snprintf(online_resource, buffer_size, "%s://%s:%s%s?", protocol, hostname, port, script);
-
-                if (mapparam)
-                {
-                    int baselen;
-                    baselen = strlen(online_resource);
-                    snprintf(online_resource+baselen, buffer_size-baselen, "map=%s&", mapparam);
-                }
-            }
-        }
-        else 
-        {
             msSetError(MS_CGIERR, "Impossible to establish server URL.  Please set \"%s\" metadata.", "msOWSGetOnlineResource()", metadata_name);
             return NULL;
         }
     }
 
-    if (online_resource == NULL) 
-    {
-        msSetError(MS_MEMERR, NULL, "msOWSGetOnlineResource()");
-        return NULL;
-    }
-
     return online_resource;
 }
 

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2011-03-11 21:14:42 UTC (rev 11156)
+++ trunk/mapserver/mapserver.h	2011-03-13 22:05:54 UTC (rev 11157)
@@ -2232,6 +2232,7 @@
 MS_DLL_EXPORT void *msSmallCalloc( size_t nCount, size_t nSize );
 
 MS_DLL_EXPORT int msExtentsOverlap(mapObj *map, layerObj *layer);
+MS_DLL_EXPORT char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req);
 
 /* For mapswf */
 MS_DLL_EXPORT int getRgbColor(mapObj *map,int i,int *r,int *g,int *b); /* maputil.c */

Modified: trunk/mapserver/maptemplate.c
===================================================================
--- trunk/mapserver/maptemplate.c	2011-03-11 21:14:42 UTC (rev 11156)
+++ trunk/mapserver/maptemplate.c	2011-03-13 22:05:54 UTC (rev 11157)
@@ -3615,6 +3615,9 @@
 #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)
   outstr = msReplaceSubstring(outstr, "[mapserv_onlineresource]",
                               msOWSGetOnlineResource(mapserv->map, "O", "onlineresource", mapserv->request));
+#else
+  outstr = msReplaceSubstring(outstr, "[mapserv_onlineresource]",
+                              msBuildOnlineResource(mapserv->map, mapserv->request));  
 #endif
 
   if(getenv("HTTP_HOST")) {

Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c	2011-03-11 21:14:42 UTC (rev 11156)
+++ trunk/mapserver/maputil.c	2011-03-13 22:05:54 UTC (rev 11157)
@@ -2108,3 +2108,74 @@
     return pReturn;
 }
 
+/*
+** msBuildOnlineResource()
+**
+** Try to build the online resource (mapserv URL) for this service.
+** "http://$(SERVER_NAME):$(SERVER_PORT)$(SCRIPT_NAME)?"
+** (+append the map=... param if it was explicitly passed in QUERY_STRING)
+**
+** Returns a newly allocated string that should be freed by the caller or
+** NULL in case of error.
+*/
+char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req)
+{
+    char *online_resource = NULL;
+    const char *value, *hostname, *port, *script, *protocol="http", *mapparam=NULL;
+    int mapparam_len = 0;
+
+    hostname = getenv("SERVER_NAME");
+    port = getenv("SERVER_PORT");
+    script = getenv("SCRIPT_NAME");
+
+    /* HTTPS is set by Apache to "on" in an HTTPS server ... if not set */
+    /* then check SERVER_PORT: 443 is the default https port. */
+    if ( ((value=getenv("HTTPS")) && strcasecmp(value, "on") == 0) ||
+	 ((value=getenv("SERVER_PORT")) && atoi(value) == 443) )
+    {
+        protocol = "https";
+    }
+
+    /* If map=.. was explicitly set then we'll include it in onlineresource
+     */
+    if (req->type == MS_GET_REQUEST)
+    {
+        int i;
+        for(i=0; i<req->NumParams; i++)
+        {
+            if (strcasecmp(req->ParamNames[i], "map") == 0)
+            {
+                mapparam = req->ParamValues[i];
+                mapparam_len = strlen(mapparam)+5; /* +5 for "map="+"&" */
+                break;
+            }
+        }
+    }
+
+    if (hostname && port && script) 
+    {
+        size_t buffer_size;
+        buffer_size = strlen(hostname)+strlen(port)+strlen(script)+mapparam_len+10;
+        online_resource = (char*)msSmallMalloc(buffer_size);
+        if ((atoi(port) == 80 && strcmp(protocol, "http") == 0) ||
+            (atoi(port) == 443 && strcmp(protocol, "https") == 0) )
+          snprintf(online_resource, buffer_size, "%s://%s%s?", protocol, hostname, script);
+        else
+          snprintf(online_resource, buffer_size, "%s://%s:%s%s?", protocol, hostname, port, script);
+
+        if (mapparam)
+        {
+            int baselen;
+            baselen = strlen(online_resource);
+            snprintf(online_resource+baselen, buffer_size-baselen, "map=%s&", mapparam);
+        }
+    }
+    else 
+    {
+        msSetError(MS_CGIERR, "Impossible to establish server URL.", "msBuildOnlineResource()");
+        return NULL;
+    }
+
+    return online_resource;
+}
+



More information about the mapserver-commits mailing list