Changeset 7586

Show
Ignore:
Timestamp:
05/13/08 02:27:00 (2 months ago)
Author:
sdlime
Message:

RFC 36 code actually works now. Still needs cleanup work but test cases output the correct information. Also cleaning up mapservObj member names.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mapserver/mapserv.c

    r7557 r7586  
    4242 
    4343 
    44 mapservObj* msObj
     44mapservObj* mapserv
    4545 
    4646int writeLog(int show_error) 
     
    5151  char szPath[MS_MAXPATHLEN]; 
    5252 
    53   if(!msObj) return(0); 
    54   if(!msObj->Map) return(0); 
    55   if(!msObj->Map->web.log) return(0); 
     53  if(!mapserv) return(0); 
     54  if(!mapserv->map) return(0); 
     55  if(!mapserv->map->web.log) return(0); 
    5656   
    57   if((stream = fopen(msBuildPath(szPath, msObj->Map->mappath,  
    58                                    msObj->Map->web.log),"a")) == NULL) { 
    59     msSetError(MS_IOERR, msObj->Map->web.log, "writeLog()"); 
     57  if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath,  
     58                                   mapserv->map->web.log),"a")) == NULL) { 
     59    msSetError(MS_IOERR, mapserv->map->web.log, "writeLog()"); 
    6060    return(-1); 
    6161  } 
     
    7070    fprintf(stream,"NULL,"); 
    7171  
    72   fprintf(stream,"%s,",msObj->Map->name); 
    73   fprintf(stream,"%d,",msObj->Mode); 
    74  
    75   fprintf(stream,"%f %f %f %f,", msObj->Map->extent.minx, msObj->Map->extent.miny, msObj->Map->extent.maxx, msObj->Map->extent.maxy); 
    76  
    77   fprintf(stream,"%f %f,", msObj->MapPnt.x, msObj->MapPnt.y); 
    78  
    79   for(i=0;i<msObj->NumLayers;i++) 
    80     fprintf(stream, "%s ", msObj->Layers[i]); 
     72  fprintf(stream,"%s,",mapserv->map->name); 
     73  fprintf(stream,"%d,",mapserv->Mode); 
     74 
     75  fprintf(stream,"%f %f %f %f,", mapserv->map->extent.minx, mapserv->map->extent.miny, mapserv->map->extent.maxx, mapserv->map->extent.maxy); 
     76 
     77  fprintf(stream,"%f %f,", mapserv->mappnt.x, mapserv->mappnt.y); 
     78 
     79  for(i=0;i<mapserv->NumLayers;i++) 
     80    fprintf(stream, "%s ", mapserv->Layers[i]); 
    8181  fprintf(stream,","); 
    8282 
     
    9898  writeLog(MS_TRUE); 
    9999 
    100   if(!msObj || !msObj->Map) { 
     100  if(!mapserv || !mapserv->map) { 
    101101    msIO_printf("Content-type: text/html%c%c",10,10); 
    102102    msIO_printf("<HTML>\n"); 
     
    106106    msWriteErrorXML(stdout); 
    107107    msIO_printf("</BODY></HTML>"); 
    108     if(msObj)  
    109       msFreeMapServObj(msObj); 
     108    if(mapserv)  
     109      msFreeMapServObj(mapserv); 
    110110    msCleanup(); 
    111111    exit(0); 
    112112  } 
    113113 
    114   if((ms_error->code == MS_NOTFOUND) && (msObj->Map->web.empty)) { 
    115     /* msRedirect(msObj->Map->web.empty); */ 
    116     if(msReturnURL(msObj, msObj->Map->web.empty, BROWSE) != MS_SUCCESS) { 
     114  if((ms_error->code == MS_NOTFOUND) && (mapserv->map->web.empty)) { 
     115    /* msRedirect(mapserv->map->web.empty); */ 
     116    if(msReturnURL(mapserv, mapserv->map->web.empty, BROWSE) != MS_SUCCESS) { 
    117117      msIO_printf("Content-type: text/html%c%c",10,10); 
    118118      msIO_printf("<HTML>\n"); 
     
    124124    } 
    125125  } else { 
    126     if(msObj->Map->web.error) {       
    127       /* msRedirect(msObj->Map->web.error); */ 
    128       if(msReturnURL(msObj, msObj->Map->web.error, BROWSE) != MS_SUCCESS) { 
     126    if(mapserv->map->web.error) {       
     127      /* msRedirect(mapserv->map->web.error); */ 
     128      if(msReturnURL(mapserv, mapserv->map->web.error, BROWSE) != MS_SUCCESS) { 
    129129        msIO_printf("Content-type: text/html%c%c",10,10); 
    130130        msIO_printf("<HTML>\n"); 
     
    146146  } 
    147147 
    148   /* Clean-up (the following are not stored as part of the msObj) */ 
     148  /* Clean-up (the following are not stored as part of the mapserv) */ 
    149149  if(QueryItem) free(QueryItem); 
    150150  if(QueryString) free(QueryString); 
     
    153153  if(QueryFile) free(QueryFile); 
    154154 
    155   msFreeMapServObj(msObj); 
     155  msFreeMapServObj(mapserv); 
    156156  msCleanup(); 
    157157 
     
    186186  char *tmpstr, *key, *value=NULL; 
    187187   
    188   for(i=0;i<msObj->request->NumParams;i++) /* find the mapfile parameter first */ 
    189     if(strcasecmp(msObj->request->ParamNames[i], "map") == 0) break; 
     188  for(i=0;i<mapserv->request->NumParams;i++) /* find the mapfile parameter first */ 
     189    if(strcasecmp(mapserv->request->ParamNames[i], "map") == 0) break; 
    190190   
    191   if(i == msObj->request->NumParams) { 
     191  if(i == mapserv->request->NumParams) { 
    192192    if(getenv("MS_MAPFILE")) /* has a default file has not been set */ 
    193193      map = msLoadMap(getenv("MS_MAPFILE"), NULL); 
     
    197197    } 
    198198  } else { 
    199     if(getenv(msObj->request->ParamValues[i])) /* an environment references the actual file to use */ 
    200       map = msLoadMap(getenv(msObj->request->ParamValues[i]), NULL); 
     199    if(getenv(mapserv->request->ParamValues[i])) /* an environment references the actual file to use */ 
     200      map = msLoadMap(getenv(mapserv->request->ParamValues[i]), NULL); 
    201201    else 
    202       map = msLoadMap(msObj->request->ParamValues[i], NULL); 
     202      map = msLoadMap(mapserv->request->ParamValues[i], NULL); 
    203203  } 
    204204 
     
    207207  /* check for any %variable% substitutions here, also do any map_ changes, we do this here so WMS/WFS  */ 
    208208  /* services can take advantage of these "vendor specific" extensions */ 
    209   for(i=0;i<msObj->request->NumParams;i++) { 
     209  for(i=0;i<mapserv->request->NumParams;i++) { 
    210210    /* 
    211211                ** a few CGI variables should be skipped altogether 
     
    214214    **          below conflict with that so we avoid it here 
    215215    */ 
    216     if(strncasecmp(msObj->request->ParamNames[i],"qstring",7) == 0) continue; 
    217  
    218     if(strncasecmp(msObj->request->ParamNames[i],"map_",4) == 0 || strncasecmp(msObj->request->ParamNames[i],"map.",4) == 0) { /* check to see if there are any additions to the mapfile */ 
    219       if(msUpdateMapFromURL(map, msObj->request->ParamNames[i], msObj->request->ParamValues[i]) != MS_SUCCESS) writeError(); 
     216    if(strncasecmp(mapserv->request->ParamNames[i],"qstring",7) == 0) continue; 
     217 
     218    if(strncasecmp(mapserv->request->ParamNames[i],"map_",4) == 0 || strncasecmp(mapserv->request->ParamNames[i],"map.",4) == 0) { /* check to see if there are any additions to the mapfile */ 
     219      if(msUpdateMapFromURL(map, mapserv->request->ParamNames[i], mapserv->request->ParamValues[i]) != MS_SUCCESS) writeError(); 
    220220      continue; 
    221221    } 
    222222 
    223223    /* runtime subtitution string */ 
    224     tmpstr = (char *)malloc(sizeof(char)*strlen(msObj->request->ParamNames[i]) + 3); 
    225     sprintf(tmpstr,"%%%s%%", msObj->request->ParamNames[i]); 
     224    tmpstr = (char *)malloc(sizeof(char)*strlen(mapserv->request->ParamNames[i]) + 3); 
     225    sprintf(tmpstr,"%%%s%%", mapserv->request->ParamNames[i]); 
    226226 
    227227    /* validation pattern metadata key */ 
    228     key = (char *)malloc(sizeof(char)*strlen(msObj->request->ParamNames[i]) + 20); 
    229     sprintf(key,"%s_validation_pattern", msObj->request->ParamNames[i]); 
     228    key = (char *)malloc(sizeof(char)*strlen(mapserv->request->ParamNames[i]) + 20); 
     229    sprintf(key,"%s_validation_pattern", mapserv->request->ParamNames[i]); 
    230230         
    231231    for(j=0; j<map->numlayers; j++) { 
    232232      value = msLookupHashTable(&(GET_LAYER(map, j)->metadata), key); 
    233233      if(value) { /* validate parameter value */ 
    234         if(msEvalRegex(value, msObj->request->ParamValues[i]) == MS_FALSE) { 
    235           msSetError(MS_WEBERR, "Parameter '%s' value fails to validate.", "loadMap()", msObj->request->ParamNames[i]); 
     234        if(msEvalRegex(value, mapserv->request->ParamValues[i]) == MS_FALSE) { 
     235          msSetError(MS_WEBERR, "Parameter '%s' value fails to validate.", "loadMap()", mapserv->request->ParamNames[i]); 
    236236          writeError(); 
    237237        } 
     
    239239 
    240240      if(GET_LAYER(map, j)->data && (strstr(GET_LAYER(map, j)->data, tmpstr) != NULL))  
    241         GET_LAYER(map, j)->data = msReplaceSubstring(GET_LAYER(map, j)->data, tmpstr, msObj->request->ParamValues[i]); 
     241        GET_LAYER(map, j)->data = msReplaceSubstring(GET_LAYER(map, j)->data, tmpstr, mapserv->request->ParamValues[i]); 
    242242      if(GET_LAYER(map, j)->tileindex && (strstr(GET_LAYER(map, j)->tileindex, tmpstr) != NULL))  
    243         GET_LAYER(map, j)->tileindex = msReplaceSubstring(GET_LAYER(map, j)->tileindex, tmpstr, msObj->request->ParamValues[i]); 
     243        GET_LAYER(map, j)->tileindex = msReplaceSubstring(GET_LAYER(map, j)->tileindex, tmpstr, mapserv->request->ParamValues[i]); 
    244244      if(GET_LAYER(map, j)->connection && (strstr(GET_LAYER(map, j)->connection, tmpstr) != NULL))  
    245         GET_LAYER(map, j)->connection = msReplaceSubstring(GET_LAYER(map, j)->connection, tmpstr, msObj->request->ParamValues[i]); 
     245        GET_LAYER(map, j)->connection = msReplaceSubstring(GET_LAYER(map, j)->connection, tmpstr, mapserv->request->ParamValues[i]); 
    246246      if(GET_LAYER(map, j)->filter.string && (strstr(GET_LAYER(map, j)->filter.string, tmpstr) != NULL))  
    247         GET_LAYER(map, j)->filter.string = msReplaceSubstring(GET_LAYER(map, j)->filter.string, tmpstr, msObj->request->ParamValues[i]); 
     247        GET_LAYER(map, j)->filter.string = msReplaceSubstring(GET_LAYER(map, j)->filter.string, tmpstr, mapserv->request->ParamValues[i]); 
    248248      for(k=0; k<GET_LAYER(map, j)->numclasses; k++) { 
    249249        if(GET_LAYER(map, j)->class[k]->expression.string && (strstr(GET_LAYER(map, j)->class[k]->expression.string, tmpstr) != NULL))  
    250           GET_LAYER(map, j)->class[k]->expression.string = msReplaceSubstring(GET_LAYER(map, j)->class[k]->expression.string, tmpstr, msObj->request->ParamValues[i]); 
     250          GET_LAYER(map, j)->class[k]->expression.string = msReplaceSubstring(GET_LAYER(map, j)->class[k]->expression.string, tmpstr, mapserv->request->ParamValues[i]); 
    251251      } 
    252252    } 
     
    259259  /* is one load it */ 
    260260 
    261   for(i=0;i<msObj->request->NumParams;i++) { 
    262     if(strcasecmp(msObj->request->ParamNames[i],"context") == 0) { 
    263       if(msObj->request->ParamValues[i] && strlen(msObj->request->ParamValues[i]) > 0) { 
    264         if(strncasecmp(msObj->request->ParamValues[i],"http",4) == 0) { 
     261  for(i=0;i<mapserv->request->NumParams;i++) { 
     262    if(strcasecmp(mapserv->request->ParamNames[i],"context") == 0) { 
     263      if(mapserv->request->ParamValues[i] && strlen(mapserv->request->ParamValues[i]) > 0) { 
     264        if(strncasecmp(mapserv->request->ParamValues[i],"http",4) == 0) { 
    265265          if(msGetConfigOption(map, "CGI_CONTEXT_URL")) 
    266             msLoadMapContextURL(map, msObj->request->ParamValues[i], MS_FALSE); 
     266            msLoadMapContextURL(map, mapserv->request->ParamValues[i], MS_FALSE); 
    267267        } else 
    268             msLoadMapContext(map, msObj->request->ParamValues[i], MS_FALSE);  
     268            msLoadMapContext(map, mapserv->request->ParamValues[i], MS_FALSE);  
    269269      } 
    270270    } 
     
    277277** Set operation mode. First look in MS_MODE env. var. as a 
    278278** default value that can be overridden by the mode=... CGI param. 
    279 ** Returns silently, leaving msObj->Mode unchanged if mode param not set. 
     279** Returns silently, leaving mapserv->Mode unchanged if mode param not set. 
    280280*/ 
    281281static int setMode(void) 
     
    286286 
    287287    mode = getenv("MS_MODE"); 
    288     for( i=0; i<msObj->request->NumParams; i++ )  
     288    for( i=0; i<mapserv->request->NumParams; i++ )  
    289289    { 
    290         if(strcasecmp(msObj->request->ParamNames[i], "mode") == 0) 
     290        if(strcasecmp(mapserv->request->ParamNames[i], "mode") == 0) 
    291291        { 
    292             mode = msObj->request->ParamValues[i]; 
     292            mode = mapserv->request->ParamValues[i]; 
    293293            break; 
    294294        } 
     
    298298      for(j=0; j<numModes; j++) { 
    299299        if(strcasecmp(mode, modeStrings[j]) == 0) { 
    300           msObj->Mode = j; 
     300          mapserv->Mode = j; 
    301301          break; 
    302302        } 
     
    321321  int rosa_type=0; 
    322322 
    323   for(i=0;i<msObj->request->NumParams;i++) { /* now process the rest of the form variables */ 
    324     if(strlen(msObj->request->ParamValues[i]) == 0) 
     323  for(i=0;i<mapserv->request->NumParams;i++) { /* now process the rest of the form variables */ 
     324    if(strlen(mapserv->request->ParamValues[i]) == 0) 
    325325      continue; 
    326326     
    327327     
    328     if(strcasecmp(msObj->request->ParamNames[i],"icon") == 0) {       
    329       msObj->icon = strdup(msObj->request->ParamValues[i]); 
    330       continue; 
    331     } 
    332  
    333     if(strcasecmp(msObj->request->ParamNames[i],"queryfile") == 0) {       
    334       QueryFile = strdup(msObj->request->ParamValues[i]); 
     328    if(strcasecmp(mapserv->request->ParamNames[i],"icon") == 0) {       
     329      mapserv->icon = strdup(mapserv->request->ParamValues[i]); 
     330      continue; 
     331    } 
     332 
     333    if(strcasecmp(mapserv->request->ParamNames[i],"queryfile") == 0) {       
     334      QueryFile = strdup(mapserv->request->ParamValues[i]); 
    335335      continue; 
    336336    } 
    337337     
    338     if(strcasecmp(msObj->request->ParamNames[i],"savequery") == 0) { 
    339       msObj->SaveQuery = MS_TRUE; 
     338    if(strcasecmp(mapserv->request->ParamNames[i],"savequery") == 0) { 
     339      mapserv->savequery = MS_TRUE; 
    340340      continue; 
    341341    } 
    342342     
    343343    /* Insecure as implemented, need to save someplace non accessible by everyone in the universe 
    344         if(strcasecmp(msObj->request->ParamNames[i],"savemap") == 0) {       
    345          msObj->SaveMap = MS_TRUE; 
     344        if(strcasecmp(mapserv->request->ParamNames[i],"savemap") == 0) {       
     345         mapserv->savemap = MS_TRUE; 
    346346         continue; 
    347347        } 
    348348    */ 
    349349 
    350     if(strcasecmp(msObj->request->ParamNames[i],"zoom") == 0) { 
    351       msObj->Zoom = getNumeric(msObj->request->ParamValues[i]);       
    352       if((msObj->Zoom > MAXZOOM) || (msObj->Zoom < MINZOOM)) { 
     350    if(strcasecmp(mapserv->request->ParamNames[i],"zoom") == 0) { 
     351      mapserv->Zoom = getNumeric(mapserv->request->ParamValues[i]);       
     352      if((mapserv->Zoom > MAXZOOM) || (mapserv->Zoom < MINZOOM)) { 
    353353        msSetError(MS_WEBERR, "Zoom value out of range.", "loadForm()"); 
    354354        writeError(); 
     
    357357    } 
    358358 
    359     if(strcasecmp(msObj->request->ParamNames[i],"zoomdir") == 0) { 
    360       msObj->ZoomDirection = (int)getNumeric(msObj->request->ParamValues[i]); 
    361       if((msObj->ZoomDirection != -1) && (msObj->ZoomDirection != 1) && (msObj->ZoomDirection != 0)) { 
     359    if(strcasecmp(mapserv->request->ParamNames[i],"zoomdir") == 0) { 
     360      mapserv->ZoomDirection = (int)getNumeric(mapserv->request->ParamValues[i]); 
     361      if((mapserv->ZoomDirection != -1) && (mapserv->ZoomDirection != 1) && (mapserv->ZoomDirection != 0)) { 
    362362        msSetError(MS_WEBERR, "Zoom direction must be 1, 0 or -1.", "loadForm()"); 
    363363        writeError(); 
     
    366366    } 
    367367 
    368     if(strcasecmp(msObj->request->ParamNames[i],"zoomsize") == 0) { /* absolute zoom magnitude */ 
    369       ZoomSize = (int) getNumeric(msObj->request->ParamValues[i]);       
     368    if(strcasecmp(mapserv->request->ParamNames[i],"zoomsize") == 0) { /* absolute zoom magnitude */ 
     369      ZoomSize = (int) getNumeric(mapserv->request->ParamValues[i]);       
    370370      if((ZoomSize > MAXZOOM) || (ZoomSize < 1)) { 
    371371        msSetError(MS_WEBERR, "Invalid zoom size.", "loadForm()"); 
     
    375375    } 
    376376     
    377     if(strcasecmp(msObj->request->ParamNames[i],"imgext") == 0) { /* extent of an existing image in a web application */ 
    378       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     377    if(strcasecmp(mapserv->request->ParamNames[i],"imgext") == 0) { /* extent of an existing image in a web application */ 
     378      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    379379 
    380380      if(!tokens) { 
     
    388388      } 
    389389 
    390       msObj->ImgExt.minx = getNumeric(tokens[0]); 
    391       msObj->ImgExt.miny = getNumeric(tokens[1]); 
    392       msObj->ImgExt.maxx = getNumeric(tokens[2]); 
    393       msObj->ImgExt.maxy = getNumeric(tokens[3]); 
     390      mapserv->ImgExt.minx = getNumeric(tokens[0]); 
     391      mapserv->ImgExt.miny = getNumeric(tokens[1]); 
     392      mapserv->ImgExt.maxx = getNumeric(tokens[2]); 
     393      mapserv->ImgExt.maxy = getNumeric(tokens[3]); 
    394394 
    395395      msFreeCharArray(tokens, 4); 
     
    397397    } 
    398398 
    399     if(strcasecmp(msObj->request->ParamNames[i],"searchmap") == 0) {       
     399    if(strcasecmp(mapserv->request->ParamNames[i],"searchmap") == 0) {       
    400400      SearchMap = MS_TRUE; 
    401401      continue; 
    402402    } 
    403403 
    404     if(strcasecmp(msObj->request->ParamNames[i],"id") == 0) { 
    405       strncpy(msObj->Id, msObj->request->ParamValues[i], IDSIZE); 
    406       continue; 
    407     } 
    408  
    409     if(strcasecmp(msObj->request->ParamNames[i],"mapext") == 0) { /* extent of the new map or query */ 
    410  
    411       if(strncasecmp(msObj->request->ParamValues[i],"shape",5) == 0) 
    412         msObj->UseShapes = MS_TRUE; 
     404    if(strcasecmp(mapserv->request->ParamNames[i],"id") == 0) { 
     405      strncpy(mapserv->Id, mapserv->request->ParamValues[i], IDSIZE); 
     406      continue; 
     407    } 
     408 
     409    if(strcasecmp(mapserv->request->ParamNames[i],"mapext") == 0) { /* extent of the new map or query */ 
     410 
     411      if(strncasecmp(mapserv->request->ParamValues[i],"shape",5) == 0) 
     412        mapserv->UseShapes = MS_TRUE; 
    413413      else { 
    414         tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     414        tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    415415     
    416416        if(!tokens) { 
     
    424424        } 
    425425     
    426         msObj->Map->extent.minx = getNumeric(tokens[0]); 
    427         msObj->Map->extent.miny = getNumeric(tokens[1]); 
    428         msObj->Map->extent.maxx = getNumeric(tokens[2]); 
    429         msObj->Map->extent.maxy = getNumeric(tokens[3]);     
     426        mapserv->map->extent.minx = getNumeric(tokens[0]); 
     427        mapserv->map->extent.miny = getNumeric(tokens[1]); 
     428        mapserv->map->extent.maxx = getNumeric(tokens[2]); 
     429        mapserv->map->extent.maxy = getNumeric(tokens[3]);     
    430430     
    431431        msFreeCharArray(tokens, 4); 
     
    441441         *         will ensue. 
    442442         */ 
    443         if(msObj->Map->projection.proj && !pj_is_latlong(msObj->Map->projection.proj) 
    444            && (msObj->Map->extent.minx >= -180.0 && msObj->Map->extent.minx <= 180.0)  
    445            && (msObj->Map->extent.miny >= -90.0 && msObj->Map->extent.miny <= 90.0) 
    446            && (msObj->Map->extent.maxx >= -180.0 && msObj->Map->extent.maxx <= 180.0)  
    447            && (msObj->Map->extent.maxy >= -90.0 && msObj->Map->extent.maxy <= 90.0)) { 
    448           msProjectRect(&(msObj->Map->latlon), &(msObj->Map->projection), &(msObj->Map->extent)); /* extent is a in lat/lon */ 
     443        if(mapserv->map->projection.proj && !pj_is_latlong(mapserv->map->projection.proj) 
     444           && (mapserv->map->extent.minx >= -180.0 && mapserv->map->extent.minx <= 180.0)  
     445           && (mapserv->map->extent.miny >= -90.0 && mapserv->map->extent.miny <= 90.0) 
     446           && (mapserv->map->extent.maxx >= -180.0 && mapserv->map->extent.maxx <= 180.0)  
     447           && (mapserv->map->extent.maxy >= -90.0 && mapserv->map->extent.maxy <= 90.0)) { 
     448          msProjectRect(&(mapserv->map->latlon), &(mapserv->map->projection), &(mapserv->map->extent)); /* extent is a in lat/lon */ 
    449449        } 
    450450#endif 
    451451 
    452         if((msObj->Map->extent.minx != msObj->Map->extent.maxx) && (msObj->Map->extent.miny != msObj->Map->extent.maxy)) { /* extent seems ok */ 
    453           msObj->CoordSource = FROMUSERBOX; 
     452        if((mapserv->map->extent.minx != mapserv->map->extent.maxx) && (mapserv->map->extent.miny != mapserv->map->extent.maxy)) { /* extent seems ok */ 
     453          mapserv->CoordSource = FROMUSERBOX; 
    454454          QueryCoordSource = FROMUSERBOX; 
    455455        } 
     
    459459    } 
    460460 
    461     if(strcasecmp(msObj->request->ParamNames[i],"minx") == 0) { /* extent of the new map, in pieces */ 
    462       msObj->Map->extent.minx = getNumeric(msObj->request->ParamValues[i]);       
    463       continue; 
    464     } 
    465     if(strcasecmp(msObj->request->ParamNames[i],"maxx") == 0) {       
    466       msObj->Map->extent.maxx = getNumeric(msObj->request->ParamValues[i]); 
    467       continue; 
    468     } 
    469     if(strcasecmp(msObj->request->ParamNames[i],"miny") == 0) { 
    470       msObj->Map->extent.miny = getNumeric(msObj->request->ParamValues[i]); 
    471       continue; 
    472     } 
    473     if(strcasecmp(msObj->request->ParamNames[i],"maxy") == 0) { 
    474       msObj->Map->extent.maxy = getNumeric(msObj->request->ParamValues[i]); 
    475       msObj->CoordSource = FROMUSERBOX; 
     461    if(strcasecmp(mapserv->request->ParamNames[i],"minx") == 0) { /* extent of the new map, in pieces */ 
     462      mapserv->map->extent.minx = getNumeric(mapserv->request->ParamValues[i]);       
     463      continue; 
     464    } 
     465    if(strcasecmp(mapserv->request->ParamNames[i],"maxx") == 0) {       
     466      mapserv->map->extent.maxx = getNumeric(mapserv->request->ParamValues[i]); 
     467      continue; 
     468    } 
     469    if(strcasecmp(mapserv->request->ParamNames[i],"miny") == 0) { 
     470      mapserv->map->extent.miny = getNumeric(mapserv->request->ParamValues[i]); 
     471      continue; 
     472    } 
     473    if(strcasecmp(mapserv->request->ParamNames[i],"maxy") == 0) { 
     474      mapserv->map->extent.maxy = getNumeric(mapserv->request->ParamValues[i]); 
     475      mapserv->CoordSource = FROMUSERBOX; 
    476476      QueryCoordSource = FROMUSERBOX; 
    477477      continue; 
    478478    }  
    479479 
    480     if(strcasecmp(msObj->request->ParamNames[i],"mapxy") == 0) { /* user map coordinate */ 
    481        
    482       if(strncasecmp(msObj->request->ParamValues[i],"shape",5) == 0) { 
    483         msObj->UseShapes = MS_TRUE;     
     480    if(strcasecmp(mapserv->request->ParamNames[i],"mapxy") == 0) { /* user map coordinate */ 
     481       
     482      if(strncasecmp(mapserv->request->ParamValues[i],"shape",5) == 0) { 
     483        mapserv->UseShapes = MS_TRUE;     
    484484      } else { 
    485         tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     485        tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    486486 
    487487        if(!tokens) { 
     
    495495        } 
    496496     
    497         msObj->MapPnt.x = getNumeric(tokens[0]); 
    498         msObj->MapPnt.y = getNumeric(tokens[1]); 
     497        mapserv->mappnt.x = getNumeric(tokens[0]); 
     498        mapserv->mappnt.y = getNumeric(tokens[1]); 
    499499     
    500500        msFreeCharArray(tokens, 2); 
    501501 
    502502#ifdef USE_PROJ 
    503         if(msObj->Map->projection.proj && !pj_is_latlong(msObj->Map->projection.proj) 
    504            && (msObj->MapPnt.x >= -180.0 && msObj->MapPnt.x <= 180.0)  
    505            && (msObj->MapPnt.y >= -90.0 && msObj->MapPnt.y <= 90.0)) { 
    506           msProjectPoint(&(msObj->Map->latlon), &(msObj->Map->projection), &msObj->MapPnt); /* point is a in lat/lon */ 
     503        if(mapserv->map->projection.proj && !pj_is_latlong(mapserv->map->projection.proj) 
     504           && (mapserv->mappnt.x >= -180.0 && mapserv->mappnt.x <= 180.0)  
     505           && (mapserv->mappnt.y >= -90.0 && mapserv->mappnt.y <= 90.0)) { 
     506          msProjectPoint(&(mapserv->map->latlon), &(mapserv->map->projection), &mapserv->mappnt); /* point is a in lat/lon */ 
    507507        } 
    508508#endif 
    509509 
    510         if(msObj->CoordSource == NONE) { /* don't override previous settings (i.e. buffer or scale ) */ 
    511           msObj->CoordSource = FROMUSERPNT; 
     510        if(mapserv->CoordSource == NONE) { /* don't override previous settings (i.e. buffer or scale ) */ 
     511          mapserv->CoordSource = FROMUSERPNT; 
    512512          QueryCoordSource = FROMUSERPNT; 
    513513        } 
     
    516516    } 
    517517 
    518     if(strcasecmp(msObj->request->ParamNames[i],"mapshape") == 0) { /* query shape */ 
     518    if(strcasecmp(mapserv->request->ParamNames[i],"mapshape") == 0) { /* query shape */ 
    519519      lineObj line={0,NULL}; 
    520520      char **tmp=NULL; 
    521521      int n, j; 
    522522       
    523       tmp = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     523      tmp = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    524524 
    525525      if((line.point = (pointObj *)malloc(sizeof(pointObj)*(n/2))) == NULL) { 
     
    529529      line.numpoints = n/2; 
    530530 
    531       msInitShape(&(msObj->SelectShape)); 
    532       msObj->SelectShape.type = MS_SHAPE_POLYGON; 
     531      msInitShape(&(mapserv->SelectShape)); 
     532      mapserv->SelectShape.type = MS_SHAPE_POLYGON; 
    533533 
    534534      for(j=0; j<n/2; j++) { 
     
    537537 
    538538#ifdef USE_PROJ 
    539         if(msObj->Map->projection.proj && !pj_is_latlong(msObj->Map->projection.proj) 
     539        if(mapserv->map->projection.proj && !pj_is_latlong(mapserv->map->projection.proj) 
    540540           && (line.point[j].x >= -180.0 && line.point[j].x <= 180.0)  
    541541           && (line.point[j].y >= -90.0 && line.point[j].y <= 90.0)) { 
    542           msProjectPoint(&(msObj->Map->latlon), &(msObj->Map->projection), &line.point[j]); /* point is a in lat/lon */ 
     542          msProjectPoint(&(mapserv->map->latlon), &(mapserv->map->projection), &line.point[j]); /* point is a in lat/lon */ 
    543543        } 
    544544#endif 
    545545      } 
    546546 
    547       if(msAddLine(&msObj->SelectShape, &line) == -1) writeError(); 
     547      if(msAddLine(&mapserv->SelectShape, &line) == -1) writeError(); 
    548548 
    549549      msFree(line.point);     
     
    554554    } 
    555555 
    556     if(strcasecmp(msObj->request->ParamNames[i],"img.x") == 0) { /* mouse click, in pieces */ 
    557       msObj->ImgPnt.x = getNumeric(msObj->request->ParamValues[i]); 
    558       if((msObj->ImgPnt.x > (2*msObj->Map->maxsize)) || (msObj->ImgPnt.x < (-2*msObj->Map->maxsize))) { 
     556    if(strcasecmp(mapserv->request->ParamNames[i],"img.x") == 0) { /* mouse click, in pieces */ 
     557      mapserv->ImgPnt.x = getNumeric(mapserv->request->ParamValues[i]); 
     558      if((mapserv->ImgPnt.x > (2*mapserv->map->maxsize)) || (mapserv->ImgPnt.x < (-2*mapserv->map->maxsize))) { 
    559559        msSetError(MS_WEBERR, "Coordinate out of range.", "loadForm()"); 
    560560        writeError(); 
    561561      } 
    562       msObj->CoordSource = FROMIMGPNT; 
     562      mapserv->CoordSource = FROMIMGPNT; 
    563563      QueryCoordSource = FROMIMGPNT; 
    564564      continue; 
    565565    } 
    566     if(strcasecmp(msObj->request->ParamNames[i],"img.y") == 0) { 
    567       msObj->ImgPnt.y = getNumeric(msObj->request->ParamValues[i]);       
    568       if((msObj->ImgPnt.y > (2*msObj->Map->maxsize)) || (msObj->ImgPnt.y < (-2*msObj->Map->maxsize))) { 
     566    if(strcasecmp(mapserv->request->ParamNames[i],"img.y") == 0) { 
     567      mapserv->ImgPnt.y = getNumeric(mapserv->request->ParamValues[i]);       
     568      if((mapserv->ImgPnt.y > (2*mapserv->map->maxsize)) || (mapserv->ImgPnt.y < (-2*mapserv->map->maxsize))) { 
    569569        msSetError(MS_WEBERR, "Coordinate out of range.", "loadForm()"); 
    570570        writeError(); 
    571571      } 
    572       msObj->CoordSource = FROMIMGPNT; 
     572      mapserv->CoordSource = FROMIMGPNT; 
    573573      QueryCoordSource = FROMIMGPNT; 
    574574      continue; 
    575575    } 
    576576 
    577     if(strcasecmp(msObj->request->ParamNames[i],"imgxy") == 0) { /* mouse click, single variable */ 
    578       if(msObj->CoordSource == FROMIMGPNT) 
     577    if(strcasecmp(mapserv->request->ParamNames[i],"imgxy") == 0) { /* mouse click, single variable */ 
     578      if(mapserv->CoordSource == FROMIMGPNT) 
    579579        continue; 
    580580 
    581       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     581      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    582582 
    583583      if(!tokens) { 
     
    591591      } 
    592592 
    593       msObj->ImgPnt.x = getNumeric(tokens[0]); 
    594       msObj->ImgPnt.y = getNumeric(tokens[1]); 
     593      mapserv->ImgPnt.x = getNumeric(tokens[0]); 
     594      mapserv->ImgPnt.y = getNumeric(tokens[1]); 
    595595 
    596596      msFreeCharArray(tokens, 2); 
    597597 
    598       if((msObj->ImgPnt.x > (2*msObj->Map->maxsize)) || (msObj->ImgPnt.x < (-2*msObj->Map->maxsize)) || (msObj->ImgPnt.y > (2*msObj->Map->maxsize)) || (msObj->ImgPnt.y < (-2*msObj->Map->maxsize))) { 
     598      if((mapserv->ImgPnt.x > (2*mapserv->map->maxsize)) || (mapserv->ImgPnt.x < (-2*mapserv->map->maxsize)) || (mapserv->ImgPnt.y > (2*mapserv->map->maxsize)) || (mapserv->ImgPnt.y < (-2*mapserv->map->maxsize))) { 
    599599        msSetError(MS_WEBERR, "Reference map coordinate out of range.", "loadForm()"); 
    600600        writeError(); 
    601601      } 
    602602 
    603       if(msObj->CoordSource == NONE) { /* override nothing since this parameter is usually used to hold a default value */ 
    604         msObj->CoordSource = FROMIMGPNT; 
     603      if(mapserv->CoordSource == NONE) { /* override nothing since this parameter is usually used to hold a default value */ 
     604        mapserv->CoordSource = FROMIMGPNT; 
    605605        QueryCoordSource = FROMIMGPNT; 
    606606      } 
     
    608608    } 
    609609 
    610     if(strcasecmp(msObj->request->ParamNames[i],"imgbox") == 0) { /* selection box (eg. mouse drag) */ 
    611       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     610    if(strcasecmp(mapserv->request->ParamNames[i],"imgbox") == 0) { /* selection box (eg. mouse drag) */ 
     611      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    612612       
    613613      if(!tokens) { 
     
    621621      } 
    622622       
    623       msObj->ImgBox.minx = getNumeric(tokens[0]); 
    624       msObj->ImgBox.miny = getNumeric(tokens[1]); 
    625       msObj->ImgBox.maxx = getNumeric(tokens[2]); 
    626       msObj->ImgBox.maxy = getNumeric(tokens[3]); 
     623      mapserv->ImgBox.minx = getNumeric(tokens[0]); 
     624      mapserv->ImgBox.miny = getNumeric(tokens[1]); 
     625      mapserv->ImgBox.maxx = getNumeric(tokens[2]); 
     626      mapserv->ImgBox.maxy = getNumeric(tokens[3]); 
    627627       
    628628      msFreeCharArray(tokens, 4); 
    629629 
    630       if((msObj->ImgBox.minx != msObj->ImgBox.maxx) && (msObj->ImgBox.miny != msObj->ImgBox.maxy)) { /* must not degenerate into a point */ 
    631         msObj->CoordSource = FROMIMGBOX; 
     630      if((mapserv->ImgBox.minx != mapserv->ImgBox.maxx) && (mapserv->ImgBox.miny != mapserv->ImgBox.maxy)) { /* must not degenerate into a point */ 
     631        mapserv->CoordSource = FROMIMGBOX; 
    632632        QueryCoordSource = FROMIMGBOX; 
    633633      } 
     
    635635    } 
    636636 
    637     if(strcasecmp(msObj->request->ParamNames[i],"imgshape") == 0) { /* shape given in image coordinates */ 
     637    if(strcasecmp(mapserv->request->ParamNames[i],"imgshape") == 0) { /* shape given in image coordinates */ 
    638638      lineObj line={0,NULL}; 
    639639      char **tmp=NULL; 
    640640      int n, j; 
    641641       
    642       tmp = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     642      tmp = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    643643 
    644644      if((line.point = (pointObj *)malloc(sizeof(pointObj)*(n/2))) == NULL) { 
     
    648648      line.numpoints = n/2; 
    649649 
    650       msInitShape(&msObj->SelectShape); 
    651       msObj->SelectShape.type = MS_SHAPE_POLYGON; 
     650      msInitShape(&mapserv->SelectShape); 
     651      mapserv->SelectShape.type = MS_SHAPE_POLYGON; 
    652652 
    653653      for(j=0; j<n/2; j++) { 
     
    656656      } 
    657657 
    658       if(msAddLine(&msObj->SelectShape, &line) == -1) writeError(); 
     658      if(msAddLine(&mapserv->SelectShape, &line) == -1) writeError(); 
    659659 
    660660      msFree(line.point); 
     
    665665    } 
    666666 
    667     if(strcasecmp(msObj->request->ParamNames[i],"ref.x") == 0) { /* mouse click in reference image, in pieces */ 
    668       msObj->RefPnt.x = getNumeric(msObj->request->ParamValues[i]);       
    669       if((msObj->RefPnt.x > (2*msObj->Map->maxsize)) || (msObj->RefPnt.x < (-2*msObj->Map->maxsize))) { 
     667    if(strcasecmp(mapserv->request->ParamNames[i],"ref.x") == 0) { /* mouse click in reference image, in pieces */ 
     668      mapserv->RefPnt.x = getNumeric(mapserv->request->ParamValues[i]);       
     669      if((mapserv->RefPnt.x > (2*mapserv->map->maxsize)) || (mapserv->RefPnt.x < (-2*mapserv->map->maxsize))) { 
    670670        msSetError(MS_WEBERR, "Coordinate out of range.", "loadForm()"); 
    671671        writeError(); 
    672672      } 
    673       msObj->CoordSource = FROMREFPNT; 
    674       continue; 
    675     } 
    676     if(strcasecmp(msObj->request->ParamNames[i],"ref.y") == 0) { 
    677       msObj->RefPnt.y = getNumeric(msObj->request->ParamValues[i]);  
    678       if((msObj->RefPnt.y > (2*msObj->Map->maxsize)) || (msObj->RefPnt.y < (-2*msObj->Map->maxsize))) { 
     673      mapserv->CoordSource = FROMREFPNT; 
     674      continue; 
     675    } 
     676    if(strcasecmp(mapserv->request->ParamNames[i],"ref.y") == 0) { 
     677      mapserv->RefPnt.y = getNumeric(mapserv->request->ParamValues[i]);  
     678      if((mapserv->RefPnt.y > (2*mapserv->map->maxsize)) || (mapserv->RefPnt.y < (-2*mapserv->map->maxsize))) { 
    679679        msSetError(MS_WEBERR, "Coordinate out of range.", "loadForm()"); 
    680680        writeError(); 
    681681      } 
    682       msObj->CoordSource = FROMREFPNT; 
    683       continue; 
    684     } 
    685  
    686     if(strcasecmp(msObj->request->ParamNames[i],"refxy") == 0) { /* mouse click in reference image, single variable */ 
    687       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     682      mapserv->CoordSource = FROMREFPNT; 
     683      continue; 
     684    } 
     685 
     686    if(strcasecmp(mapserv->request->ParamNames[i],"refxy") == 0) { /* mouse click in reference image, single variable */ 
     687      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    688688 
    689689      if(!tokens) { 
     
    697697      } 
    698698 
    699       msObj->RefPnt.x = getNumeric(tokens[0]); 
    700       msObj->RefPnt.y = getNumeric(tokens[1]); 
     699      mapserv->RefPnt.x = getNumeric(tokens[0]); 
     700      mapserv->RefPnt.y = getNumeric(tokens[1]); 
    701701 
    702702      msFreeCharArray(tokens, 2); 
    703703       
    704       if((msObj->RefPnt.x > (2*msObj->Map->maxsize)) || (msObj->RefPnt.x < (-2*msObj->Map->maxsize)) || (msObj->RefPnt.y > (2*msObj->Map->maxsize)) || (msObj->RefPnt.y < (-2*msObj->Map->maxsize))) { 
     704      if((mapserv->RefPnt.x > (2*mapserv->map->maxsize)) || (mapserv->RefPnt.x < (-2*mapserv->map->maxsize)) || (mapserv->RefPnt.y > (2*mapserv->map->maxsize)) || (mapserv->RefPnt.y < (-2*mapserv->map->maxsize))) { 
    705705        msSetError(MS_WEBERR, "Reference map coordinate out of range.", "loadForm()"); 
    706706        writeError(); 
    707707      } 
    708708       
    709       msObj->CoordSource = FROMREFPNT; 
    710       continue; 
    711     } 
    712  
    713     if(strcasecmp(msObj->request->ParamNames[i],"buffer") == 0) { /* radius (map units), actually 1/2 square side */ 
    714       msObj->Buffer = getNumeric(msObj->request->ParamValues[i]);       
    715       msObj->CoordSource = FROMBUF; 
     709      mapserv->CoordSource = FROMREFPNT; 
     710      continue; 
     711    } 
     712 
     713    if(strcasecmp(mapserv->request->ParamNames[i],"buffer") == 0) { /* radius (map units), actually 1/2 square side */ 
     714      mapserv->Buffer = getNumeric(mapserv->request->ParamValues[i]);       
     715      mapserv->CoordSource = FROMBUF; 
    716716      QueryCoordSource = FROMUSERPNT; 
    717717      continue; 
    718718    } 
    719719 
    720     if(strcasecmp(msObj->request->ParamNames[i],"scale") == 0 || strcasecmp(msObj->request->ParamNames[i],"scaledenom") == 0) { /* scale for new map */ 
    721       msObj->ScaleDenom = getNumeric(msObj->request->ParamValues[i]);       
    722       if(msObj->ScaleDenom <= 0) { 
     720    if(strcasecmp(mapserv->request->ParamNames[i],"scale") == 0 || strcasecmp(mapserv->request->ParamNames[i],"scaledenom") == 0) { /* scale for new map */ 
     721      mapserv->ScaleDenom = getNumeric(mapserv->request->ParamValues[i]);       
     722      if(mapserv->ScaleDenom <= 0) { 
    723723        msSetError(MS_WEBERR, "Scale out of range.", "loadForm()"); 
    724724        writeError(); 
    725725      } 
    726       msObj->CoordSource = FROMSCALE; 
     726      mapserv->CoordSource = FROMSCALE; 
    727727      QueryCoordSource = FROMUSERPNT; 
    728728      continue; 
    729729    } 
    730730     
    731     if(strcasecmp(msObj->request->ParamNames[i],"imgsize") == 0) { /* size of existing image (pixels) */ 
    732       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     731    if(strcasecmp(mapserv->request->ParamNames[i],"imgsize") == 0) { /* size of existing image (pixels) */ 
     732      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    733733 
    734734      if(!tokens) { 
     
    742742      } 
    743743 
    744       msObj->ImgCols = (int)getNumeric(tokens[0]); 
    745       msObj->ImgRows = (int)getNumeric(tokens[1]); 
     744      mapserv->ImgCols = (int)getNumeric(tokens[0]); 
     745      mapserv->ImgRows = (int)getNumeric(tokens[1]); 
    746746 
    747747      msFreeCharArray(tokens, 2); 
    748748       
    749       if(msObj->ImgCols > msObj->Map->maxsize || msObj->ImgRows > msObj->Map->maxsize || msObj->ImgCols < 0 || msObj->ImgRows < 0) { 
     749      if(mapserv->ImgCols > mapserv->map->maxsize || mapserv->ImgRows > mapserv->map->maxsize || mapserv->ImgCols < 0 || mapserv->ImgRows < 0) { 
    750750        msSetError(MS_WEBERR, "Image size out of range.", "loadForm()"); 
    751751        writeError(); 
     
    755755    } 
    756756 
    757     if(strcasecmp(msObj->request->ParamNames[i],"mapsize") == 0) { /* size of new map (pixels) */ 
    758       tokens = msStringSplit(msObj->request->ParamValues[i], ' ', &n); 
     757    if(strcasecmp(mapserv->request->ParamNames[i],"mapsize") == 0) { /* size of new map (pixels) */ 
     758      tokens = msStringSplit(mapserv->request->ParamValues[i], ' ', &n); 
    759759 
    760760      if(!tokens) { 
     
    768768      } 
    769769 
    770       msObj->Map->width = (int)getNumeric(tokens[0]); 
    771       msObj->Map->height = (int)getNumeric(tokens[1]); 
     770      mapserv->map->width = (int)getNumeric(tokens[0]); 
     771      mapserv->map->height = (int)getNumeric(tokens[1]); 
    772772 
    773773      msFreeCharArray(tokens, 2); 
    774774       
    775       if(msObj->Map->width > msObj->Map->maxsize || msObj->Map->height > msObj->Map->maxsize || msObj->Map->width < 0 || msObj->Map->height < 0) { 
     775      if(mapserv->map->width > mapserv->map->maxsize || mapserv->map->height > mapserv->map->maxsize || mapserv->map->width < 0 || mapserv->map->height < 0) { 
    776776        msSetError(MS_WEBERR, "Image size out of range.", "loadForm()"); 
    777777        writeError(); 
     
    780780    } 
    781781 
    782     if(strncasecmp(msObj->request->ParamNames[i],"layers", 6) == 0) { /* turn a set of layers, delimited by spaces, on */ 
     782    if(strncasecmp(mapserv->request->ParamNames[i],"layers", 6) == 0) { /* turn a set of layers, delimited by spaces, on */ 
    783783 
    784784      /* If layers=all then turn on all layers */ 
    785       if (strcasecmp(msObj->request->ParamValues[i], "all") == 0 && msObj->Map != NULL) { 
     785      if (strcasecmp(mapserv->request->ParamValues[i], "all") == 0 && mapserv->map != NULL) { 
    786786        int l; 
    787787 
    788788        /* Reset NumLayers=0. If individual layers were already selected then free the previous values.  */ 
    789         for(l=0; l<msObj->NumLayers; l++) 
    790           msFree(msObj->Layers[l]); 
    791         msObj->NumLayers=0; 
    792  
    793         for(msObj->NumLayers=0; msObj->NumLayers < msObj->Map->numlayers; msObj->NumLayers++) { 
    794           if(msGrowMapservLayers(msObj) == MS_FAILURE) 
     789        for(l=0; l<mapserv->NumLayers; l++) 
     790          msFree(mapserv->Layers[l]); 
     791        mapserv->NumLayers=0; 
     792 
     793        for(mapserv->NumLayers=0; mapserv->NumLayers < mapserv->map->numlayers; mapserv->NumLayers++) { 
     794          if(msGrowMapservLayers(mapserv) == MS_FAILURE) 
    795795            writeError(); 
    796796 
    797           if(GET_LAYER(msObj->Map, msObj->NumLayers)->name) { 
    798             msObj->Layers[msObj->NumLayers] = strdup(GET_LAYER(msObj->Map, msObj->NumLayers)->name); 
     797          if(GET_LAYER(mapserv->map, mapserv->NumLayers)->name) { 
     798            mapserv->Layers[mapserv->NumLayers] = strdup(GET_LAYER(mapserv->map, mapserv->NumLayers)->name); 
    799799          } else { 
    800             msObj->Layers[msObj->NumLayers] = strdup(""); 
     800            mapserv->Layers[mapserv->NumLayers] = strdup(""); 
    801801          } 
    802802        } 
     
    805805        char **layers=NULL; 
    806806 
    807         layers = msStringSplit(msObj->request->ParamValues[i], ' ', &(num_layers)); 
     807        layers = msStringSplit(mapserv->request->ParamValues[i], ' ', &(num_layers)); 
    808808        for(l=0; l<num_layers; l++) { 
    809           if(msGrowMapservLayers(msObj) == MS_FAILURE) 
     809          if(msGrowMapservLayers(mapserv) == MS_FAILURE) 
    810810            writeError(); 
    811           msObj->Layers[msObj->NumLayers++] = strdup(layers[l]); 
     811          mapserv->Layers[mapserv->NumLayers++] = strdup(layers[l]); 
    812812        } 
    813813 
     
    819819    } 
    820820 
    821     if(strncasecmp(msObj->request->ParamNames[i],"layer", 5) == 0) { /* turn a single layer/group on */ 
    822       if(msGrowMapservLayers(msObj) == MS_FAILURE) 
    823         writeError(); 
    824       msObj->Layers[msObj->NumLayers] = strdup(msObj->request->ParamValues[i]); 
    825       msObj->NumLayers++; 
    826       continue; 
    827     } 
    828  
    829     if(strcasecmp(msObj->request->ParamNames[i],"qlayer") == 0) { /* layer to query (i.e search) */ 
    830       QueryLayer = strdup(msObj->request->ParamValues[i]); 
    831       continue; 
    832     } 
    833  
    834     if(strcasecmp(msObj->request->ParamNames[i],"qitem") == 0) { /* attribute to query on (optional) */ 
    835       QueryItem = strdup(msObj->request->ParamValues[i]); 
    836       continue; 
    837     } 
    838  
    839     if(strcasecmp(msObj->request->ParamNames[i],"qstring") == 0) { /* attribute query string */ 
    840       QueryString = strdup(msObj->request->ParamValues[i]); 
    841       continue; 
    842     } 
    843  
    844     if(strcasecmp(msObj->request->ParamNames[i],"slayer") == 0) { /* layer to select (for feature based search) */ 
    845       SelectLayer = strdup(msObj->request->ParamValues[i]); 
    846       continue; 
    847     } 
    848  
    849     if(strcasecmp(msObj->request->ParamNames[i],"shapeindex") == 0) { /* used for index queries */ 
    850       ShapeIndex = (int)getNumeric(msObj->request->ParamValues[i]); 
    851       continue; 
    852     } 
    853     if(strcasecmp(msObj->request->ParamNames[i],"tileindex") == 0) { 
    854       TileIndex = (int)getNumeric(msObj->request->ParamValues[i]); 
     821    if(strncasecmp(mapserv->request->ParamNames[i],"layer", 5) == 0) { /* turn a single layer/group on */ 
     822      if(msGrowMapservLayers(mapserv) == MS_FAILURE) 
     823        writeError(); 
     824      mapserv->Layers[mapserv->NumLayers] = strdup(mapserv->request->ParamValues[i]); 
     825      mapserv->NumLayers++; 
     826      continue; 
     827    } 
     828 
     829    if(strcasecmp(mapserv->request->ParamNames[i],"qlayer") == 0) { /* layer to query (i.e search) */ 
     830      QueryLayer = strdup(mapserv->request->ParamValues[i]); 
     831      continue; 
     832    } 
     833 
     834    if(strcasecmp(mapserv->request->ParamNames[i],"qitem") == 0) { /* attribute to query on (optional) */ 
     835      QueryItem = strdup(mapserv->request->ParamValues[i]); 
     836      continue; 
     837    } 
     838 
     839    if(strcasecmp(mapserv->request->ParamNames[i],"qstring") == 0) { /* attribute query string */ 
     840      QueryString = strdup(mapserv->request->ParamValues[i]); 
     841      continue; 
     842    } 
     843