[mapserver-commits] r7650 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Fri Jun 6 10:07:17 EDT 2008


Author: sdlime
Date: 2008-06-06 10:07:17 -0400 (Fri, 06 Jun 2008)
New Revision: 7650

Modified:
   trunk/mapserver/maphttp.c
   trunk/mapserver/mapows.c
   trunk/mapserver/mapows.h
   trunk/mapserver/mapquery.c
   trunk/mapserver/mapwmslayer.c
Log:
Applied patch to allow proxies for remote connections (WMS/WFS). (#571)

Modified: trunk/mapserver/maphttp.c
===================================================================
--- trunk/mapserver/maphttp.c	2008-06-04 19:47:49 UTC (rev 7649)
+++ trunk/mapserver/maphttp.c	2008-06-06 14:07:17 UTC (rev 7650)
@@ -217,6 +217,30 @@
     return fwrite(buffer, size, nmemb, psReq->fp);
 }
 
+/**********************************************************************
+ *                          msGetCURLAuthType()
+ *
+ * Returns the equivalent CURL CURLAUTH_ constant given a
+ * MS_HTTP_AUTH_TYPE, or CURLAUTH_BASIC if no match is found.
+ **********************************************************************/
+long msGetCURLAuthType(MS_HTTP_AUTH_TYPE authType)
+{
+    switch (authType)
+    {
+        case BASIC:
+            return CURLAUTH_BASIC;
+        case DIGEST:
+            return CURLAUTH_DIGEST;
+        case NTLM:
+            return CURLAUTH_NTLM;
+        case ANY:
+            return CURLAUTH_ANY;
+        case ANYSAFE:
+            return CURLAUTH_ANYSAFE;
+        default:
+            return CURLAUTH_BASIC;    
+    }
+}
 
 /**********************************************************************
  *                          msHTTPExecuteRequests()
@@ -365,6 +389,71 @@
 
         /* Set timeout.*/
         curl_easy_setopt(http_handle, CURLOPT_TIMEOUT, nTimeout );
+        
+        /* Set proxying settings */
+        if (pasReqInfo[i].pszProxyAddress != NULL
+            && strlen(pasReqInfo[i].pszProxyAddress) > 0)
+        {
+            long    nProxyType     = CURLPROXY_HTTP;
+            long    nProxyAuthType = CURLAUTH_BASIC;
+            char    szUsernamePasswd[128];    
+            
+            curl_easy_setopt(http_handle, CURLOPT_PROXY,
+                             pasReqInfo[i].pszProxyAddress);
+            
+            if (pasReqInfo[i].nProxyPort > 0
+                && pasReqInfo[i].nProxyPort < 65535)
+            {
+                curl_easy_setopt(http_handle, CURLOPT_PROXYPORT,
+                                 pasReqInfo[i].nProxyPort);
+            }
+            
+            switch (pasReqInfo[i].eProxyType)
+            {
+                case HTTP:
+                    nProxyType = CURLPROXY_HTTP;
+                    break;
+                case SOCKS5:
+                    nProxyType = CURLPROXY_SOCKS5;
+                    break;
+            }
+            curl_easy_setopt(http_handle, CURLOPT_PROXYTYPE, nProxyType);
+            
+            /* If there is proxy authentication information, set it */
+            if (pasReqInfo[i].pszProxyUsername != NULL
+                && pasReqInfo[i].pszProxyPassword != NULL
+                && strlen(pasReqInfo[i].pszProxyUsername) > 0
+                && strlen(pasReqInfo[i].pszProxyPassword) > 0)
+            {
+                nProxyAuthType = msGetCURLAuthType(pasReqInfo[i].eProxyAuthType);
+                curl_easy_setopt(http_handle, CURLOPT_PROXYAUTH, nProxyAuthType);
+                
+                snprintf(szUsernamePasswd, 127, "%s:%s",
+                         pasReqInfo[i].pszProxyUsername,
+                         pasReqInfo[i].pszProxyPassword);
+                curl_easy_setopt(http_handle, CURLOPT_PROXYUSERPWD,
+                                 szUsernamePasswd);
+            }
+        }
+        
+        /* Set HTTP Authentication settings */
+        if (pasReqInfo[i].pszHttpUsername != NULL
+            && pasReqInfo[i].pszHttpPassword != NULL
+            && strlen(pasReqInfo[i].pszHttpUsername) > 0
+            && strlen(pasReqInfo[i].pszHttpPassword) > 0)
+        {
+            char    szUsernamePasswd[128];
+            long    nHttpAuthType = CURLAUTH_BASIC;
+            
+            snprintf(szUsernamePasswd, 127, "%s:%s",
+                     pasReqInfo[i].pszHttpUsername,
+                     pasReqInfo[i].pszHttpPassword);
+            curl_easy_setopt(http_handle, CURLOPT_USERPWD,
+                             szUsernamePasswd);
+                                 
+            nHttpAuthType = msGetCURLAuthType(pasReqInfo[i].eHttpAuthType);
+            curl_easy_setopt(http_handle, CURLOPT_HTTPAUTH, nHttpAuthType);
+        }
 
         /* NOSIGNAL should be set to true for timeout to work in multithread
          * environments on Unix, requires libcurl 7.10 or more recent.

Modified: trunk/mapserver/mapows.c
===================================================================
--- trunk/mapserver/mapows.c	2008-06-04 19:47:49 UTC (rev 7649)
+++ trunk/mapserver/mapows.c	2008-06-06 14:07:17 UTC (rev 7650)
@@ -545,6 +545,35 @@
 }
 
 /*
+** msOWSLookupMetadata2()
+**
+** Attempts to lookup a given metadata name in multiple hashTables, and
+** in multiple OWS namespaces within each. First searches the primary
+** table and if no result is found, attempts the search using the 
+** secondary (fallback) table.
+**
+** 'namespaces' is a string with a letter for each namespace to lookup 
+** in the order they should be looked up. e.g. "MO" to lookup wms_ and ows_
+** If namespaces is NULL then this function just does a regular metadata
+** lookup.
+*/
+const char *msOWSLookupMetadata2(hashTableObj *pri,
+                                        hashTableObj *sec,
+                                        const char *namespaces,
+                                        const char *name)
+{
+    const char *result;
+    
+    if ((result = msOWSLookupMetadata(pri, namespaces, name)) == NULL)
+    {
+        // Try the secondary table
+        result = msOWSLookupMetadata(sec, namespaces, name);
+    }
+
+    return result;
+}
+
+/*
 ** msOWSPrintMetadata()
 **
 ** Attempt to output a capability item.  If corresponding metadata is not 

Modified: trunk/mapserver/mapows.h
===================================================================
--- trunk/mapserver/mapows.h	2008-06-04 19:47:49 UTC (rev 7649)
+++ trunk/mapserver/mapows.h	2008-06-06 14:07:17 UTC (rev 7650)
@@ -45,6 +45,21 @@
 
 #define MS_HTTP_SUCCESS(status)  (status == 200 || status == 242)
 
+typedef enum
+{
+    HTTP,
+    SOCKS5
+} MS_HTTP_PROXY_TYPE;
+
+typedef enum
+{
+    BASIC,
+    DIGEST,
+    NTLM,
+    ANY,
+    ANYSAFE
+} MS_HTTP_AUTH_TYPE;
+
 typedef struct http_request_info
 {
     int     nLayerId;
@@ -59,6 +74,17 @@
     char    *pszPostContentType;/* post request MIME type */
     char    *pszUserAgent;      /* User-Agent, auto-generated if not set */
     char    *pszHTTPCookieData; /* HTTP Cookie data */
+    
+    char    *pszProxyAddress;   /* The address (IP or hostname) of proxy svr */
+    long     nProxyPort;        /* The proxy's port                          */
+    enum MS_HTTP_PROXY_TYPE eProxyType; /* The type of proxy                 */
+    enum MS_HTTP_AUTH_TYPE  eProxyAuthType; /* Auth method against proxy     */
+    char    *pszProxyUsername;  /* Proxy authentication username             */
+    char    *pszProxyPassword;  /* Proxy authentication password             */
+    
+    enum MS_HTTP_AUTH_TYPE eHttpAuthType; /* HTTP Authentication type        */
+    char    *pszHttpUsername;   /* HTTP Authentication username              */
+    char    *pszHttpPassword;   /* HTTP Authentication password              */
 
     /* For debugging/profiling */
     int         debug;         /* Debug mode?  MS_TRUE/MS_FALSE */
@@ -180,6 +206,10 @@
 
 MS_DLL_EXPORT const char * msOWSLookupMetadata(hashTableObj *metadata, 
                                     const char *namespaces, const char *name);
+MS_DLL_EXPORT const char * msOWSLookupMetadata2(hashTableObj *pri,
+                                                hashTableObj *sec,
+                                                const char *namespaces,
+                                                const char *name);
 MS_DLL_EXPORT int msOWSPrintMetadata(FILE *stream, hashTableObj *metadata, 
                        const char *namespaces, const char *name, 
                        int action_if_not_found, const char *format, 

Modified: trunk/mapserver/mapquery.c
===================================================================
--- trunk/mapserver/mapquery.c	2008-06-04 19:47:49 UTC (rev 7649)
+++ trunk/mapserver/mapquery.c	2008-06-06 14:07:17 UTC (rev 7650)
@@ -248,6 +248,14 @@
     return _msQueryByIndex(map, qlayer, tileindex, shapeindex, 0);
 }
 
+/*
+** Query using an OGC filter (in XML). Leverages the code written to support the WFS specs.
+*/
+int msQueryByFilter(mapObj *map, int qlayer, char *qfilter)
+{
+
+}
+
 int msQueryByAttributes(mapObj *map, int qlayer, char *qitem, char *qstring, int mode)
 {
   layerObj *lp;

Modified: trunk/mapserver/mapwmslayer.c
===================================================================
--- trunk/mapserver/mapwmslayer.c	2008-06-04 19:47:49 UTC (rev 7649)
+++ trunk/mapserver/mapwmslayer.c	2008-06-06 14:07:17 UTC (rev 7650)
@@ -805,6 +805,14 @@
     rectObj bbox;
     int nTimeout, bOkToMerge, bForceSeparateRequest;
     wmsParamsObj sThisWMSParams;
+    
+    char    *pszProxyHost=NULL;
+    long     nProxyPort=0;
+    char    *pszProxyUsername=NULL, *pszProxyPassword=NULL;
+    char    *pszHttpAuthUsername=NULL, *pszHttpAuthPassword=NULL;
+    MS_HTTP_AUTH_TYPE eHttpAuthType;
+    MS_HTTP_AUTH_TYPE eProxyAuthType;
+    MS_HTTP_PROXY_TYPE eProxyType;
 
     if (lp->connectiontype != MS_WMS)
         return MS_FAILURE;
@@ -878,6 +886,112 @@
     {
         nTimeout = atoi(pszTmp);
     }
+    
+/* ------------------------------------------------------------------
+ * Check for authentication and proxying metadata. If the metadata is not found
+ * in the layer metadata, check the map-level metadata.
+ * ------------------------------------------------------------------ */
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_host")) != NULL)
+    {
+        pszProxyHost = strdup(pszTmp);
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_port")) != NULL)
+    {
+        nProxyPort = atol(pszTmp);
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_type")) != NULL)
+    {
+        
+        if (strcasecmp(pszTmp, "HTTP") == 0)
+            eProxyType = HTTP;
+        else if (strcasecmp(pszTmp, "SOCKS5") == 0)
+            eProxyType = SOCKS5;
+        else
+        {
+            msSetError(MS_WMSERR, "Invalid proxy_type metadata '%s' specified",
+                       "msPrepareWMSLayerRequest()", pszTmp);
+            return MS_FAILURE;
+        }
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_auth_type")) != NULL)
+    {
+        if (strcasecmp(pszTmp, "BASIC") == 0)
+            eProxyAuthType = BASIC;
+        else if (strcasecmp(pszTmp, "DIGEST") == 0)
+            eProxyAuthType = DIGEST;
+        else if (strcasecmp(pszTmp, "NTLM") == 0)
+            eProxyAuthType = NTLM;
+        else if (strcasecmp(pszTmp, "ANY") == 0)
+            eProxyAuthType = ANY;
+        else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+            eProxyAuthType = ANYSAFE;
+        else
+        {
+            msSetError(MS_WMSERR, "Invalid proxy_auth_type metadata '%s' specified",
+                       "msPrepareWMSLayerRequest()", pszTmp);
+            return MS_FAILURE;
+        }
+    }
+    
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_username")) != NULL)
+    {
+        pszProxyUsername = strdup(pszTmp);
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "proxy_password")) != NULL)
+    {
+        pszProxyPassword = msDecryptStringTokens(map, pszTmp);
+        if (pszProxyPassword == NULL) {
+            return(MS_FAILURE);  /* An error should already have been produced */
+        }
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "auth_type")) != NULL)
+    {
+        if (strcasecmp(pszTmp, "BASIC") == 0)
+            eHttpAuthType = BASIC;
+        else if (strcasecmp(pszTmp, "DIGEST") == 0)
+            eHttpAuthType = DIGEST;
+        else if (strcasecmp(pszTmp, "NTLM") == 0)
+            eHttpAuthType = NTLM;
+        else if (strcasecmp(pszTmp, "ANY") == 0)
+            eHttpAuthType = ANY;
+        else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+            eHttpAuthType = ANYSAFE;
+        else
+        {
+            msSetError(MS_WMSERR, "Invalid auth_type metadata '%s' specified",
+                       "msPrepareWMSLayerRequest()", pszTmp);
+            return MS_FAILURE;
+        }
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "auth_username")) != NULL)
+    {
+        pszHttpAuthUsername = strdup(pszTmp);
+    }
+    
+    if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+                                       "MO", "auth_password")) != NULL)
+    {
+        pszHttpAuthPassword = msDecryptStringTokens(map, pszTmp);
+        if (pszHttpAuthPassword == NULL) {
+            return(MS_FAILURE);  /* An error should already have been produced */
+        }
+    }
+    
 
 /* ------------------------------------------------------------------
  * Check if layer can be merged with previous WMS layer requests
@@ -1052,7 +1166,17 @@
         pasReqInfo[(*numRequests)].nTimeout = nTimeout;
         pasReqInfo[(*numRequests)].bbox = bbox;
         pasReqInfo[(*numRequests)].debug = lp->debug;
-
+        
+        pasReqInfo[(*numRequests)].pszProxyAddress  = pszProxyHost;
+        pasReqInfo[(*numRequests)].nProxyPort       = nProxyPort;
+        pasReqInfo[(*numRequests)].eProxyType       = eProxyType;
+        pasReqInfo[(*numRequests)].eProxyAuthType   = eProxyAuthType;
+        pasReqInfo[(*numRequests)].pszProxyUsername = pszProxyUsername;
+        pasReqInfo[(*numRequests)].pszProxyPassword = pszProxyPassword;
+        pasReqInfo[(*numRequests)].eHttpAuthType    = eHttpAuthType;
+        pasReqInfo[(*numRequests)].pszHttpUsername  = pszHttpAuthUsername;
+        pasReqInfo[(*numRequests)].pszHttpPassword  = pszHttpAuthPassword;
+        
         (*numRequests)++;
     }
 



More information about the mapserver-commits mailing list