[mapserver-commits] r12457 - in trunk/mapserver/mapcache: . src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:28:06 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:28:06 -0700 (Fri, 26 Aug 2011)
New Revision: 12457

Modified:
   trunk/mapserver/mapcache/configure.in
   trunk/mapserver/mapcache/geocache.json
   trunk/mapserver/mapcache/src/cJSON.c
   trunk/mapserver/mapcache/src/configuration_json.c
Log:


Modified: trunk/mapserver/mapcache/configure.in
===================================================================
--- trunk/mapserver/mapcache/configure.in	2011-08-26 11:28:00 UTC (rev 12456)
+++ trunk/mapserver/mapcache/configure.in	2011-08-26 11:28:06 UTC (rev 12457)
@@ -414,6 +414,18 @@
     AC_SUBST(CFLAGS,$CFLAGS)
 ])
 
+AC_DEFUN([JSON_STRICT_CHECK],[
+    AC_ARG_ENABLE(strict-json,
+        AC_HELP_STRING([--enable-strict-json],[Make the JSON parser be strict and reject comments]),
+        ,
+        [enable_strict_json=no]
+    )
+    if test "$enable_strict_json" == "yes"; then
+        CFLAGS="$CFLAGS -DSTRICT_JSON"
+    fi
+    AC_SUBST(CFLAGS,$CFLAGS)
+])
+
 AC_DEFUN([AC_EXPAND_PATH],[
   if test -z "$1" || echo "$1" | grep '^/' >/dev/null ; then
     $2="$1"
@@ -722,6 +734,7 @@
 ])
 
 DEBUG_CHECK
+JSON_STRICT_CHECK
 
 LOCKMECH_CHECK
 

Modified: trunk/mapserver/mapcache/geocache.json
===================================================================
--- trunk/mapserver/mapcache/geocache.json	2011-08-26 11:28:00 UTC (rev 12456)
+++ trunk/mapserver/mapcache/geocache.json	2011-08-26 11:28:06 UTC (rev 12457)
@@ -2,8 +2,22 @@
  "grids": [
   {
    "name":"grid1",
-   "extent":[0,3,4,4]
-  },
+   "extent":[0,3,4,4],
+   "resolutions":[0,2],
+   "size":[256,256],
+   "metadata": {
+    "title":"foo grid title",
+    "fail":"sdffd"
+   },
+   
+   "units":"m" /*sdvfdsffff
+                 rgsdg
+                 */
+
+
+
+
+  }, //comment
   {
    "name":"grid2"
   }

Modified: trunk/mapserver/mapcache/src/cJSON.c
===================================================================
--- trunk/mapserver/mapcache/src/cJSON.c	2011-08-26 11:28:00 UTC (rev 12456)
+++ trunk/mapserver/mapcache/src/cJSON.c	2011-08-26 11:28:06 UTC (rev 12457)
@@ -234,7 +234,24 @@
 static char *print_object(cJSON *item,int depth,int fmt);
 
 /* Utility to jump whitespace and cr/lf */
-static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
+static const char *skip(const char *in) {
+   while (in && *in && (unsigned char)*in<=32) in++;
+#ifndef STRICT_JSON
+   /* skip a c-style / * comment */
+   if(in && *in=='/' && (in+1) && *(in+1)=='*') {
+     in += 2;
+     while(in && *in && !(*in=='*' && (in+1) && *(in+1) && *(in+1)=='/')) in++;
+     return skip(in+2);
+   }
+   /* skip a cpp-style // comment */
+   if(in && *in=='/' && (in+1) && *(in+1)=='/') {
+     in += 2;
+     while(in && *in && *in!='\n') in++;
+     return skip(in+1);
+   }
+#endif
+   return in;
+}
 
 /* Parse an object - create a new root, and populate. */
 cJSON *cJSON_Parse(const char *value)

Modified: trunk/mapserver/mapcache/src/configuration_json.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration_json.c	2011-08-26 11:28:00 UTC (rev 12456)
+++ trunk/mapserver/mapcache/src/configuration_json.c	2011-08-26 11:28:06 UTC (rev 12457)
@@ -18,9 +18,22 @@
    }
 }
 
+static void parse_metadata(geocache_context *ctx, cJSON *node, apr_table_t *metadata) {
+   if(!node->child) return;
+   cJSON *child = node->child;
+   while(child) {
+      if(child->type != cJSON_String) {
+         ctx->set_error(ctx,400,"metadata can only contain string values");
+         return;
+      }
+      apr_table_set(metadata,child->string,child->valuestring);
+      child = child->next;
+   }
+}
+
 static void parse_grid_json(geocache_context *ctx, cJSON *node, geocache_cfg *cfg) {
    char *name = NULL;
-   double extent[4];
+   int i;
    cJSON *tmp;
    geocache_grid *grid;
 
@@ -40,7 +53,14 @@
    }
    grid = geocache_grid_create(ctx->pool);
    grid->name = name;
+   
+   tmp = cJSON_GetObjectItem(node,"metadata");
+   if(tmp) {
+      parse_metadata(ctx,tmp,grid->metadata);
+      GC_CHECK_ERROR(ctx);
+   }
 
+
    tmp = cJSON_GetObjectItem(node,"extent");
    if(!tmp) {
       ctx->set_error(ctx, 400, "extent not found in grid \"%s\"",name);
@@ -48,6 +68,63 @@
    }
    parse_extent_json(ctx,tmp,grid->extent);
    GC_CHECK_ERROR(ctx);
+   
+   tmp = cJSON_GetObjectItem(node,"resolutions");
+   if(!tmp) {
+      ctx->set_error(ctx, 400, "resolutions not found in grid \"%s\"",name);
+      return;
+   }
+   i = cJSON_GetArraySize(tmp);
+   if(i == 0) {
+      ctx->set_error(ctx,400,"resolutions for grid %s is not an array",name);
+      return;
+   }
+   grid->levels = apr_pcalloc(ctx->pool,i*sizeof(geocache_grid_level*));
+   grid->nlevels = i;
+   for(i=0;i<grid->nlevels;i++) {
+      cJSON *item = cJSON_GetArrayItem(tmp,i);
+      if(item->type != cJSON_Number) {
+         ctx->set_error(ctx,400,"failed to parse resolution %s in grid %s (not a number)", item->valuestring,name);
+         return;
+      }
+      grid->levels[i] = apr_pcalloc(ctx->pool,sizeof(geocache_grid_level));
+      grid->levels[i]->resolution = item->valuedouble;
+   }
+   
+   tmp = cJSON_GetObjectItem(node,"size");
+   if(!tmp) {
+      ctx->set_error(ctx, 400, "size not found in grid \"%s\"",name);
+      return;
+   }
+   i = cJSON_GetArraySize(tmp);
+   if(i != 2) {
+      ctx->set_error(ctx,400,"size for grid %s is not a correct array, expecting [width,height]",name);
+      return;
+   }
+   for(i=0;i<2;i++) {
+      cJSON *item = cJSON_GetArrayItem(tmp,i);
+      if(item->type != cJSON_Number) {
+         ctx->set_error(ctx,400,"failed to parse size %s in grid %s (not a number)", item->valuestring,name);
+         return;
+      }
+      if(i==0)
+         grid->tile_sx = item->valueint;
+      else
+         grid->tile_sy = item->valueint;
+   }
+   tmp = cJSON_GetObjectItem(node,"units");
+   if(tmp && tmp->valuestring) {
+      if(!strcasecmp(tmp->valuestring,"dd"))
+         grid->unit = GEOCACHE_UNIT_DEGREES;
+      else if(!strcasecmp(tmp->valuestring,"m"))
+         grid->unit = GEOCACHE_UNIT_METERS;
+      else if(!strcasecmp(tmp->valuestring,"ft"))
+         grid->unit = GEOCACHE_UNIT_FEET;
+      else {
+         ctx->set_error(ctx,400,"unknown unit %s for grid %s",tmp->valuestring,name);
+         return;
+      }
+   }
 
    geocache_configuration_add_grid(cfg,grid,name);   
 }



More information about the mapserver-commits mailing list