1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  MapCache tile caching support file: high level service dispatching
6  * Author:   Thomas Bonfort and the MapServer team.
7  *
8  ******************************************************************************
9  * Copyright (c) 1996-2011 Regents of the University of Minnesota.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies of this Software or works derived from this Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  *****************************************************************************/
29 
30 #include "mapcache.h"
31 #include <apr_strings.h>
32 #include <math.h>
33 
34 /** \addtogroup services */
35 /** @{ */
36 
37 
mapcache_service_dispatch_request(mapcache_context * ctx,mapcache_request ** request,char * pathinfo,apr_table_t * params,mapcache_cfg * config)38 void mapcache_service_dispatch_request(mapcache_context *ctx, mapcache_request **request, char *pathinfo, apr_table_t *params, mapcache_cfg *config)
39 {
40   int i;
41 
42   /* skip empty pathinfo */
43   if(!pathinfo) {
44     ctx->set_error(ctx,404,"missing a service");
45     return;
46   }
47 
48   /*skip leading /'s */
49   while((*pathinfo) == '/')
50     ++pathinfo;
51 
52   for(i=0; i<MAPCACHE_SERVICES_COUNT; i++) {
53     /* loop through the services that have been configured */
54     int prefixlen;
55     mapcache_service *service = NULL;
56     service = config->services[i];
57     if(!service) continue; /* skip an unconfigured service */
58     prefixlen = strlen(service->url_prefix);
59     if(strncmp(service->url_prefix,pathinfo, prefixlen)) continue; /*skip a service who's prefix does not correspond */
60     ctx->service = service;
61     //if(*(pathinfo+prefixlen)!='/' && *(pathinfo+prefixlen)!='\0') continue; /*we matched the prefix but there are trailing characters*/
62     pathinfo += prefixlen; /* advance pathinfo to after the service prefix */
63     service->parse_request(ctx,service,request,pathinfo,params,config);
64     if(*request)
65       (*request)->service = service;
66 
67     /* stop looping on services */
68     return;
69   }
70   ctx->set_error(ctx,404,"unknown service %s",pathinfo);
71 }
72 
mapcache_config_services_enabled(mapcache_context * ctx,mapcache_cfg * config)73 int mapcache_config_services_enabled(mapcache_context *ctx, mapcache_cfg *config) {
74   int count=0,i;
75   for(i=0; i<MAPCACHE_SERVICES_COUNT; i++) {
76     if(config->services[i])
77       count++;
78   }
79   return count;
80 }
81 
82 /** @} */
83 
84 
85 
86 
87 
88 /* vim: ts=2 sts=2 et sw=2
89 */
90