[mapserver-commits] r7520 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Apr 14 11:29:38 EDT 2008


Author: tomkralidis
Date: 2008-04-14 11:29:38 -0400 (Mon, 14 Apr 2008)
New Revision: 7520

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapserver.h
   trunk/mapserver/mapstring.c
   trunk/mapserver/mapwmslayer.c
Log:
set WMS request parameters correctly (#1296)


Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-04-14 14:37:48 UTC (rev 7519)
+++ trunk/mapserver/HISTORY.TXT	2008-04-14 15:29:38 UTC (rev 7520)
@@ -13,6 +13,8 @@
 Current Version (5.1-dev, SVN trunk):
 -------------------------------------
 
+- encode WMS parameters correctly (#1296)
+
 - Added alignment option within a scalebar (#2468)
 
 - RFC-42 HTTP Cookie Forwarding (#2566)

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2008-04-14 14:37:48 UTC (rev 7519)
+++ trunk/mapserver/mapserver.h	2008-04-14 15:29:38 UTC (rev 7520)
@@ -1605,6 +1605,8 @@
 MS_DLL_EXPORT char *msIntToString(int value);
 MS_DLL_EXPORT void msStringToUpper(char *string);
 MS_DLL_EXPORT void msStringToLower(char *string);
+MS_DLL_EXPORT int msEncodeChar(const char);
+MS_DLL_EXPORT char *msEncodeUrlExcept(const char*, const char);
 MS_DLL_EXPORT char *msEncodeUrl(const char*);
 MS_DLL_EXPORT char *msEncodeHTMLEntities(const char *string);
 MS_DLL_EXPORT void msDecodeHTMLEntities(const char *string);

Modified: trunk/mapserver/mapstring.c
===================================================================
--- trunk/mapserver/mapstring.c	2008-04-14 14:37:48 UTC (rev 7519)
+++ trunk/mapserver/mapstring.c	2008-04-14 15:29:38 UTC (rev 7520)
@@ -607,8 +607,55 @@
   return(token);
 }
 
+/**********************************************************************
+ *                       msEncodeChar()
+ *
+ * Return 1 if the character argument should be encoded for safety
+ * in URL use and 0 otherwise. Specific character map taken from 
+ * http://www.ietf.org/rfc/rfc2396.txt
+ *
+ **********************************************************************/
+
+int msEncodeChar(const char c)
+{
+  if ( 
+       (c >= 0x61 && c <= 0x7A ) ||   /* Letters a-z */
+       (c >= 0x41 && c <= 0x5A ) ||   /* Letters A-Z */
+       (c >= 0x30 && c <= 0x39 ) ||   /* Numbers 0-9 */
+       (c >= 0x27 && c <= 0x2A ) ||   /* * ' ( )     */
+       (c >= 0x2D && c <= 0x2E ) ||   /* - .         */
+       (c == 0x5F ) ||                /* _           */
+       (c == 0x21 ) ||                /* !           */
+       (c == 0x7E ) )                 /* ~           */
+  {
+    return(0);
+  }
+  else 
+  {
+    return(1);
+  }
+}
+
 char *msEncodeUrl(const char *data)
 {
+       /*
+        * Delegate to msEncodeUrlExcept, with a null second argument
+        * to render the except handling moot.
+        */ 
+	return(msEncodeUrlExcept(data, '\0'));
+}
+
+/**********************************************************************
+ *                       msEncodeCharExcept()
+ *
+ * URL encoding, applies RFP2396 encoding to all characters 
+ * except the one exception character. An exception character
+ * of '\0' implies no exception handling.
+ *
+ **********************************************************************/
+ 
+char *msEncodeUrlExcept(const char *data, const char except)
+{
   char *hex = "0123456789ABCDEF";
   const char *i;
   char  *j, *code;
@@ -616,7 +663,7 @@
   unsigned char ch;
 
   for (inc=0, i=data; *i!='\0'; i++)
-    if (!isalnum(*i))
+    if (msEncodeChar(*i))
       inc += 2;
   
   if (!(code = (char*)malloc(strlen(data)+inc+1)))
@@ -627,11 +674,16 @@
       if (*i == ' ')
 	*j = '+';
       else
-      if (!isalnum(*i))
+      if ( except != '\0' && *i == except )
+        {
+	  *j = except;
+        }
+      else 
+      if (msEncodeChar(*i))
 	{
 	  ch = *i;
-	  *j++ = '%';
-	  *j++ = hex[ch/16];
+	  *j++ = '%'; 
+	  *j++ = hex[ch/16]; 
 	  *j   = hex[ch%16];
 	}
       else

Modified: trunk/mapserver/mapwmslayer.c
===================================================================
--- trunk/mapserver/mapwmslayer.c	2008-04-14 14:37:48 UTC (rev 7519)
+++ trunk/mapserver/mapwmslayer.c	2008-04-14 15:29:38 UTC (rev 7520)
@@ -85,7 +85,33 @@
     if (urlencode)
     {
         char *pszTmp;
-        pszTmp = msEncodeUrl(value);
+
+        /*
+         *  Special case handling for characters the WMS specification
+         *  says should not be encoded, when they occur in certain
+         *  parameters.
+         *  
+         *  TODO: WMS 1.3 removes SRS and FORMAT from the set of 
+         *        exceptional cases.
+         */
+        if( strcmp(name,"LAYERS") == 0 ||
+            strcmp(name,"STYLES") == 0 ||
+            strcmp(name,"BBOX") == 0 )
+        {
+            pszTmp = msEncodeUrlExcept(value,',');
+        }
+        else if ( strcmp(name,"SRS") == 0 )
+        {
+            pszTmp = msEncodeUrlExcept(value,':');
+        }
+        else if ( strcmp(name,"FORMAT") == 0 )
+        {
+            pszTmp = msEncodeUrlExcept(value,'/');
+        }
+        else {
+            pszTmp = msEncodeUrl(value);
+        }
+
         msInsertHashTable(psWMSParams->params, name, pszTmp);
         msFree(pszTmp);
     }
@@ -172,6 +198,7 @@
     /* Get rid of trailing '&'*/
     pszURL[nLen-1] = '\0';
 
+
     return pszURL;
 }
 
@@ -235,7 +262,7 @@
 
     psWMSParams->onlineresource = strdup(pszOnlineResource);
 
-    if (strncmp(pszVersion, "1.0.7", 5) < 0)
+    if (strncmp(pszVersion, "1.0.7", 5) < 0) 
         pszVersionKeyword = "WMTVER";
     else
         pszVersionKeyword = "VERSION";
@@ -980,7 +1007,6 @@
  * ------------------------------------------------------------------ */
     pszURL = msBuildURLFromWMSParams(&sThisWMSParams);
 
-
     if (bOkToMerge && (*numRequests)>0)
     {
 /* ------------------------------------------------------------------



More information about the mapserver-commits mailing list