| 322 | } |
| 323 | |
| 324 | static int loadQueryParams(mapObj *map, FILE *stream) { |
| 325 | char buffer[MS_BUFFER_LENGTH]; |
| 326 | int lineno; |
| 327 | |
| 328 | int shapetype, numlines, numpoints; |
| 329 | |
| 330 | msInitQuery(&(map->query)); /* this will free any previous query as well */ |
| 331 | |
| 332 | lineno = 2; /* line 1 is the magic string */ |
| 333 | while(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) { |
| 334 | switch(lineno) { |
| 335 | case 2: |
| 336 | if(sscanf(buffer, "%d %d %d %d\n", &(map->query.mode), &(map->query.type), &(map->query.layer), &(map->query.slayer)) != 4) goto parse_error; |
| 337 | break; |
| 338 | case 3: |
| 339 | if(sscanf(buffer, "%lf %lf %lf %d\n", &map->query.point.x, &map->query.point.y, &map->query.buffer, &map->query.maxresults) != 4) goto parse_error; |
| 340 | break; |
| 341 | case 4: |
| 342 | if(sscanf(buffer, "%lf %lf %lf %lf\n", &map->query.rect.minx, &map->query.rect.miny, &map->query.rect.maxx, &map->query.rect.maxy) != 4) goto parse_error; |
| 343 | break; |
| 344 | case 5: |
| 345 | if(sscanf(buffer, "%ld %ld %d\n", &map->query.shapeindex, &map->query.tileindex, &map->query.clear_resultcache) != 3) goto parse_error; |
| 346 | break; |
| 347 | case 6: |
| 348 | if(strncmp(buffer, "NULL", 4) != 0) { |
| 349 | map->query.item = msStrdup(buffer); |
| 350 | msStringChop(map->query.item); |
| 351 | } |
| 352 | break; |
| 353 | case 7: |
| 354 | if(strncmp(buffer, "NULL", 4) != 0) { |
| 355 | map->query.str = msStrdup(buffer); |
| 356 | msStringChop(map->query.str); |
| 357 | } |
| 358 | break; |
| 359 | case 8: |
| 360 | if(sscanf(buffer, "%d\n", &shapetype) != 1) goto parse_error; |
| 361 | |
| 362 | if(shapetype != MS_SHAPE_NULL) { /* load the rest of the shape */ |
| 363 | int i, j; |
| 364 | lineObj line; |
| 365 | |
| 366 | map->query.shape = (shapeObj *) msSmallMalloc(sizeof(shapeObj)); |
| 367 | msInitShape(map->query.shape); |
| 368 | map->query.shape->type = shapetype; |
| 369 | |
| 370 | if(fscanf(stream, "%d\n", &numlines) != 1) goto parse_error; |
| 371 | for(i=0; i<numlines; i++) { |
| 372 | if(fscanf(stream, "%d\n", &numpoints) != 1) goto parse_error; |
| 373 | |
| 374 | line.numpoints = numpoints; |
| 375 | line.point = (pointObj *) msSmallMalloc(line.numpoints*sizeof(pointObj)); |
| 376 | |
| 377 | for(j=0; j<numpoints; j++) |
| 378 | if(fscanf(stream, "%lf %lf\n", &line.point[j].x, &line.point[j].y) != 2) goto parse_error; |
| 379 | |
| 380 | msAddLine(map->query.shape, &line); |
| 381 | free(line.point); |
no test coverage detected