Permalink
Browse files

Move the common code handling proxy/auth metadata statements in a sin…

…gle function
  • Loading branch information...
1 parent 9e55278 commit 35708af38c2d8ffb155c04d0e5c302bccf057301 @landryb landryb committed Jul 16, 2013
Showing with 145 additions and 242 deletions.
  1. +133 −0 maphttp.c
  2. +3 −0 maphttp.h
  3. +5 −128 mapwfslayer.c
  4. +4 −114 mapwmslayer.c
View
@@ -37,6 +37,7 @@
#include "maphttp.h"
#include "maperror.h"
#include "mapthread.h"
+#include "mapows.h"
@@ -281,6 +282,138 @@ long msGetCURLAuthType(enum MS_HTTP_AUTH_TYPE authType)
}
}
+
+/**********************************************************************
+ * msHTTPAuthProxySetup()
+ *
+ * Common code used by msPrepareWFSLayerRequest() and
+ * msPrepareWMSLayerRequest() to handle proxy / http auth for requests
+ *
+ * Return value:
+ * MS_SUCCESS if all requests completed succesfully.
+ * MS_FAILURE if a fatal error happened
+ **********************************************************************/
+int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd,
+ httpRequestObj *pasReqInfo, int numRequests,
+ mapObj *map, const char* namespaces)
+{
+
+ const char *pszTmp;
+ char *pszProxyHost=NULL;
+ long nProxyPort=0;
+ char *pszProxyUsername=NULL, *pszProxyPassword=NULL;
+ char *pszHttpAuthUsername=NULL, *pszHttpAuthPassword=NULL;
+ enum MS_HTTP_AUTH_TYPE eHttpAuthType = MS_BASIC;
+ enum MS_HTTP_AUTH_TYPE eProxyAuthType = MS_BASIC;
+ enum MS_HTTP_PROXY_TYPE eProxyType = MS_HTTP;
+
+
+ /* ------------------------------------------------------------------
+ * Check for authentication and proxying metadata. If the metadata is not found
+ * in the layer metadata, check the map-level metadata.
+ * ------------------------------------------------------------------ */
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_host")) != NULL) {
+ pszProxyHost = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_port")) != NULL) {
+ nProxyPort = atol(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_type")) != NULL) {
+
+ if (strcasecmp(pszTmp, "HTTP") == 0)
+ eProxyType = MS_HTTP;
+ else if (strcasecmp(pszTmp, "SOCKS5") == 0)
+ eProxyType = MS_SOCKS5;
+ else {
+ msSetError(MS_WMSERR, "Invalid proxy_type metadata '%s' specified",
+ "msHTTPAuthProxySetup()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_auth_type")) != NULL) {
+ if (strcasecmp(pszTmp, "BASIC") == 0)
+ eProxyAuthType = MS_BASIC;
+ else if (strcasecmp(pszTmp, "DIGEST") == 0)
+ eProxyAuthType = MS_DIGEST;
+ else if (strcasecmp(pszTmp, "NTLM") == 0)
+ eProxyAuthType = MS_NTLM;
+ else if (strcasecmp(pszTmp, "ANY") == 0)
+ eProxyAuthType = MS_ANY;
+ else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+ eProxyAuthType = MS_ANYSAFE;
+ else {
+ msSetError(MS_WMSERR, "Invalid proxy_auth_type metadata '%s' specified",
+ "msHTTPAuthProxySetup()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_username")) != NULL) {
+ pszProxyUsername = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "proxy_password")) != NULL) {
+ pszProxyPassword = msDecryptStringTokens(map, pszTmp);
+ if (pszProxyPassword == NULL) {
+ return(MS_FAILURE); /* An error should already have been produced */
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "auth_type")) != NULL) {
+ if (strcasecmp(pszTmp, "BASIC") == 0)
+ eHttpAuthType = MS_BASIC;
+ else if (strcasecmp(pszTmp, "DIGEST") == 0)
+ eHttpAuthType = MS_DIGEST;
+ else if (strcasecmp(pszTmp, "NTLM") == 0)
+ eHttpAuthType = MS_NTLM;
+ else if (strcasecmp(pszTmp, "ANY") == 0)
+ eHttpAuthType = MS_ANY;
+ else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+ eHttpAuthType = MS_ANYSAFE;
+ else {
+ msSetError(MS_WMSERR, "Invalid auth_type metadata '%s' specified",
+ "msHTTPAuthProxySetup()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "auth_username")) != NULL) {
+ pszHttpAuthUsername = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces,
+ "auth_password")) != NULL) {
+ pszHttpAuthPassword = msDecryptStringTokens(map, pszTmp);
+ if (pszHttpAuthPassword == NULL) {
+ return(MS_FAILURE); /* An error should already have been produced */
+ }
+ }
+
+ 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;
+
+ return MS_SUCCESS;
+}
+
/**********************************************************************
* msHTTPExecuteRequests()
*
View
@@ -108,6 +108,9 @@ extern "C" {
int *pnHTTPStatus, int nTimeout, int bCheckLocalCache,
int bDebug);
+ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd,
+ httpRequestObj *pasReqInfo, int numRequests,
+ mapObj *map, const char* namespaces);
#endif /*USE_CURL*/
#ifdef __cplusplus
View
@@ -504,14 +504,6 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
wfsParamsObj *psParams = NULL;
char *pszHTTPCookieData = NULL;
- char *pszProxyHost=NULL;
- long nProxyPort=0;
- char *pszProxyUsername=NULL, *pszProxyPassword=NULL;
- char *pszHttpAuthUsername=NULL, *pszHttpAuthPassword=NULL;
- enum MS_HTTP_AUTH_TYPE eHttpAuthType = MS_BASIC;
- enum MS_HTTP_AUTH_TYPE eProxyAuthType = MS_BASIC;
- enum MS_HTTP_PROXY_TYPE eProxyType = MS_HTTP;
-
if (lp->connectiontype != MS_WFS || lp->connection == NULL)
return MS_FAILURE;
@@ -548,126 +540,17 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
pszURL = msStrdup(lp->connection);
}
-
/* ------------------------------------------------------------------
* check to see if a the metadata wfs_connectiontimeout is set. If it is
* the case we will use it, else we use the default which is 30 seconds.
* First check the metadata in the layer object and then in the map object.
* ------------------------------------------------------------------ */
nTimeout = 30; /* Default is 30 seconds */
- if ((pszTmp = msOWSLookupMetadata(&(lp->metadata),
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
"FO", "connectiontimeout")) != NULL) {
nTimeout = atoi(pszTmp);
- } else if ((pszTmp = msOWSLookupMetadata(&(map->web.metadata),
- "FO", "connectiontimeout")) != NULL) {
- 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),
- "FO", "proxy_host")) != NULL)
- {
- pszProxyHost = msStrdup(pszTmp);
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "proxy_port")) != NULL)
- {
- nProxyPort = atol(pszTmp);
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "proxy_type")) != NULL)
- {
-
- if (strcasecmp(pszTmp, "HTTP") == 0)
- eProxyType = MS_HTTP;
- else if (strcasecmp(pszTmp, "SOCKS5") == 0)
- eProxyType = MS_SOCKS5;
- else
- {
- msSetError(MS_WMSERR, "Invalid proxy_type metadata '%s' specified",
- "msPrepareWFSLayerRequest()", pszTmp);
- return MS_FAILURE;
- }
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "proxy_auth_type")) != NULL)
- {
- if (strcasecmp(pszTmp, "BASIC") == 0)
- eProxyAuthType = MS_BASIC;
- else if (strcasecmp(pszTmp, "DIGEST") == 0)
- eProxyAuthType = MS_DIGEST;
- else if (strcasecmp(pszTmp, "NTLM") == 0)
- eProxyAuthType = MS_NTLM;
- else if (strcasecmp(pszTmp, "ANY") == 0)
- eProxyAuthType = MS_ANY;
- else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
- eProxyAuthType = MS_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),
- "FO", "proxy_username")) != NULL)
- {
- pszProxyUsername = msStrdup(pszTmp);
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "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),
- "FO", "auth_type")) != NULL)
- {
- if (strcasecmp(pszTmp, "BASIC") == 0)
- eHttpAuthType = MS_BASIC;
- else if (strcasecmp(pszTmp, "DIGEST") == 0)
- eHttpAuthType = MS_DIGEST;
- else if (strcasecmp(pszTmp, "NTLM") == 0)
- eHttpAuthType = MS_NTLM;
- else if (strcasecmp(pszTmp, "ANY") == 0)
- eHttpAuthType = MS_ANY;
- else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
- eHttpAuthType = MS_ANYSAFE;
- else
- {
- msSetError(MS_WMSERR, "Invalid auth_type metadata '%s' specified",
- "msPrepareWFSLayerRequest()", pszTmp);
- return MS_FAILURE;
- }
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "auth_username")) != NULL)
- {
- pszHttpAuthUsername = msStrdup(pszTmp);
- }
-
- if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
- "FO", "auth_password")) != NULL)
- {
- pszHttpAuthPassword = msDecryptStringTokens(map, pszTmp);
- if (pszHttpAuthPassword == NULL) {
- return(MS_FAILURE); /* An error should already have been produced */
- }
- }
-
/*------------------------------------------------------------------
* Check to see if there's a HTTP Cookie to forward
* If Cookie differ between the two connection, it's NOT OK to merge
@@ -736,16 +619,10 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
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;
-
+ if (msHTTPAuthProxySetup(&(map->web.metadata), &(lp->metadata),
+ pasReqInfo, *numRequests, map, "FO"))
+ return MS_FAILURE;
+
/* ------------------------------------------------------------------
* Pre-Open the layer now, (i.e. alloc and fill msWFSLayerInfo inside
* layer obj). Layer will be ready for use when the main mapserver
Oops, something went wrong.

0 comments on commit 35708af

Please sign in to comment.