MCPcopy Index your code
hub / github.com/MapServer/MapServer / msBuildOnlineResource

Function msBuildOnlineResource

maputil.c:2229–2288  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

2227** NULL in case of error.
2228*/
2229char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req)
2230{
2231 char *online_resource = NULL;
2232 const char *value, *hostname, *port, *script, *protocol="http", *mapparam=NULL;
2233 int mapparam_len = 0;
2234
2235 hostname = getenv("SERVER_NAME");
2236 port = getenv("SERVER_PORT");
2237 script = getenv("SCRIPT_NAME");
2238
2239 /* HTTPS is set by Apache to "on" in an HTTPS server ... if not set */
2240 /* then check SERVER_PORT: 443 is the default https port. */
2241 if ( ((value=getenv("HTTPS")) && strcasecmp(value, "on") == 0) ||
2242 ((value=getenv("SERVER_PORT")) && atoi(value) == 443) )
2243 {
2244 protocol = "https";
2245 }
2246
2247 /* If map=.. was explicitly set then we'll include it in onlineresource
2248 */
2249 if (req->type == MS_GET_REQUEST)
2250 {
2251 int i;
2252 for(i=0; i<req->NumParams; i++)
2253 {
2254 if (strcasecmp(req->ParamNames[i], "map") == 0)
2255 {
2256 mapparam = req->ParamValues[i];
2257 mapparam_len = strlen(mapparam)+5; /* +5 for "map="+"&" */
2258 break;
2259 }
2260 }
2261 }
2262
2263 if (hostname && port && script)
2264 {
2265 size_t buffer_size;
2266 buffer_size = strlen(hostname)+strlen(port)+strlen(script)+mapparam_len+10;
2267 online_resource = (char*)msSmallMalloc(buffer_size);
2268 if ((atoi(port) == 80 && strcmp(protocol, "http") == 0) ||
2269 (atoi(port) == 443 && strcmp(protocol, "https") == 0) )
2270 snprintf(online_resource, buffer_size, "%s://%s%s?", protocol, hostname, script);
2271 else
2272 snprintf(online_resource, buffer_size, "%s://%s:%s%s?", protocol, hostname, port, script);
2273
2274 if (mapparam)
2275 {
2276 int baselen;
2277 baselen = strlen(online_resource);
2278 snprintf(online_resource+baselen, buffer_size-baselen, "map=%s&", mapparam);
2279 }
2280 }
2281 else
2282 {
2283 msSetError(MS_CGIERR, "Impossible to establish server URL.", "msBuildOnlineResource()");
2284 return NULL;
2285 }
2286

Callers 2

msOWSGetOnlineResourceFunction · 0.85
processLineFunction · 0.85

Calls 3

strcasecmpFunction · 0.85
msSmallMallocFunction · 0.85
msSetErrorFunction · 0.85

Tested by

no test coverage detected