Exemple #1
0
/*
 * Release ows struct
 */
void ows_free(ows * o)
{
  assert(o);

  if (o->config_file)          buffer_free(o->config_file);
  if (o->schema_dir)           buffer_free(o->schema_dir);
  if (o->online_resource)      buffer_free(o->online_resource);
  if (o->pg)                   PQfinish(o->pg);
  if (o->log_file)             buffer_free(o->log_file);
  if (o->log)                  fclose(o->log);
  if (o->pg_dsn)               buffer_free(o->pg_dsn);
  if (o->cgi)                  array_free(o->cgi);
  if (o->psql_requests)        list_free(o->psql_requests);
  if (o->layers)               ows_layer_list_free(o->layers);
  if (o->request)              ows_request_free(o->request);
  if (o->max_geobbox)          ows_geobbox_free(o->max_geobbox);
  if (o->metadata)             ows_metadata_free(o->metadata);
  if (o->contact)              ows_contact_free(o->contact);
  if (o->encoding)             buffer_free(o->encoding);
  if (o->db_encoding)          buffer_free(o->db_encoding);
  if (o->wfs_default_version)  ows_version_free(o->wfs_default_version);
  if (o->postgis_version)      ows_version_free(o->postgis_version);
  if (o->schema_wfs_100)       xmlSchemaFree(o->schema_wfs_100);
  if (o->schema_wfs_110)       xmlSchemaFree(o->schema_wfs_110);

  free(o);
  o = NULL;
}
Exemple #2
0
/*
 * Free a layer
 */
void ows_layer_free(ows_layer * l)
{
    assert(l);

    if (l->title) 	buffer_free(l->title);
    if (l->name) 	buffer_free(l->name);
    if (l->abstract) 	buffer_free(l->abstract);
    if (l->keywords) 	list_free(l->keywords);
    if (l->gml_ns) 	list_free(l->gml_ns);
    if (l->srid)	list_free(l->srid);
    if (l->geobbox)	ows_geobbox_free(l->geobbox);
    if (l->ns_uri)	buffer_free(l->ns_uri);
    if (l->ns_prefix)	buffer_free(l->ns_prefix);
    if (l->storage)	ows_layer_storage_free(l->storage);
	if (l->exclude_items) list_free(l->exclude_items);

    free(l);
    l = NULL;
}
Exemple #3
0
/*
 * Parse the configuration file's limits element
 */
static void ows_parse_config_limits(ows * o, xmlTextReaderPtr r)
{
    xmlChar *a;
    ows_geobbox *geo;

    assert(o);
    assert(r);

    a = xmlTextReaderGetAttribute(r, (xmlChar *) "features");
    if (a) {
        o->max_features = atoi((char *) a);
        xmlFree(a);
    }

    a = xmlTextReaderGetAttribute(r, (xmlChar *) "geobbox");
    if (a) {
        geo = ows_geobbox_init();
        if (ows_geobbox_set_from_str(o, geo, (char *) a)) o->max_geobbox = geo;
        else ows_geobbox_free(geo);
        xmlFree(a);
    }
}
/*
 * Specifies the list of feature types available from the wfs
 * Used for both 1.0.0 && 1.1.0 versions
 */
static void wfs_feature_type_list(ows * o)
{
  ows_layer_node *ln;
  ows_geobbox *gb;

  int srid_int;
  buffer *srid;
  buffer *srs;
  list_node *keyword, *l_srid;
  int s;
  bool writable, retrievable;

  assert(o);

  writable = false;
  retrievable = false;

  fprintf(o->output, " <FeatureTypeList>\n");

  /* print global operations */

  if (    ows_layer_list_retrievable(o->layers)
          || ows_layer_list_writable(o->layers))
    fprintf(o->output, "  <Operations>\n");

  if (ows_layer_list_retrievable(o->layers)) {
    if (ows_version_get(o->request->version) == 100)
      fprintf(o->output, "   <Query/>\n");
    else if (ows_version_get(o->request->version) == 110)
      fprintf(o->output, " <Operation>Query</Operation>\n");

    retrievable = true;
  }

  if (ows_layer_list_writable(o->layers)) {
    if (ows_version_get(o->request->version) == 100) {
      fprintf(o->output, "   <Insert/>\n");
      fprintf(o->output, "   <Update/>\n");
      fprintf(o->output, "   <Delete/>\n");
    } else if (ows_version_get(o->request->version) == 110) {
      fprintf(o->output, "   <Operation>Insert</Operation>\n");
      fprintf(o->output, "   <Operation>Update</Operation>\n");
      fprintf(o->output, "   <Operation>Delete</Operation>\n");
    }

    writable = true;
  }

  if (    ows_layer_list_retrievable(o->layers)
          || ows_layer_list_writable(o->layers))
    fprintf(o->output, "  </Operations>\n");

  for (ln = o->layers->first ; ln ; ln = ln->next) {
    /* print each feature type */
    if (ows_layer_match_table(o, ln->layer->name)) {

      fprintf(o->output, "<FeatureType xmlns:%s=\"%s\">\n",
              ln->layer->ns_prefix->buf, ln->layer->ns_uri->buf);

      /* name */
      if (ln->layer->name) {
        for (s = 0; s < ln->layer->depth; s++) fprintf(o->output, " ");

        fprintf(o->output, " <Name>");
        buffer_flush(ows_layer_uri_to_prefix(o->layers, ln->layer->name), o->output);
        fprintf(o->output, "</Name>\n");
      }

      /* title */
      if (ln->layer->title) {
        for (s = 0; s < ln->layer->depth; s++) fprintf(o->output, " ");

        fprintf(o->output, " <Title>");
        buffer_flush(ln->layer->title, o->output);
        fprintf(o->output, "</Title>\n");
      }

      /* abstract */
      if (ln->layer->abstract) {
        for (s = 0; s < ln->layer->depth; s++) fprintf(o->output, " ");

        fprintf(o->output, " <Abstract>");
        buffer_flush(ln->layer->abstract, o->output);
        fprintf(o->output, "</Abstract>\n");
      }

      /* keywords */
      if (ln->layer->keywords) {
        for (s = 0; s < ln->layer->depth; s++) fprintf(o->output, " ");

        fprintf(o->output, " <Keywords>");

        for (keyword = ln->layer->keywords->first ; keyword ; keyword = keyword->next) {
          if (ows_version_get(o->request->version) == 100) {
            fprintf(o->output, "%s", keyword->value->buf);
            if (keyword->next) fprintf(o->output, ",");
          } else if (ows_version_get(o->request->version) == 110) {
            fprintf(o->output, "  <Keyword>");
            fprintf(o->output, "%s", keyword->value->buf);
            fprintf(o->output, "</Keyword>");
          }
        }

        fprintf(o->output, "</Keywords>\n");
      }

      /* SRS */
      srid = buffer_init();
      srid_int = ows_srs_get_srid_from_layer(o, ln->layer->name);
      buffer_add_int(srid, srid_int);
      srs = ows_srs_get_from_a_srid(o, srid_int);

      if (srs->use) {
        if (ows_version_get(o->request->version) == 100) {
          fprintf(o->output, " <SRS>");
          buffer_flush(srs, o->output);
          fprintf(o->output, "</SRS>\n");
        } else if (ows_version_get(o->request->version) == 110) {
          fprintf(o->output, " <DefaultSRS>urn:ogc:def:crs:EPSG::%s</DefaultSRS>\n", srid->buf);

          if (ln->layer->srid) {
            for (l_srid = ln->layer->srid->first; l_srid; l_srid = l_srid->next) {
              if (!buffer_cmp(srid, l_srid->value->buf)) {
                fprintf(o->output, " <OtherSRS>urn:ogc:def:crs:EPSG::%s</OtherSRS>\n", l_srid->value->buf);
              }
            }
          }
        }
      } else {
        if (ows_version_get(o->request->version) == 100)
          fprintf(o->output, " <SRS></SRS>\n");
        else if (ows_version_get(o->request->version) == 110)
          fprintf(o->output, " <NoSRS/>");
      }
      /* Operations */
      if (retrievable != ln->layer->retrievable || writable != ln->layer->writable) {
        fprintf(o->output, "  <Operations>\n");

        if (retrievable == false && ln->layer->retrievable == true) {
          if (ows_version_get(o->request->version) == 100)
            fprintf(o->output, "   <Query/>\n");
          else if (ows_version_get(o->request->version) == 110)
            fprintf(o->output, "   <Operation>Query</Operation>\n");
        }

        if (writable == false && ln->layer->writable == true) {
          if (ows_version_get(o->request->version) == 100) {
            fprintf(o->output, "   <Insert/>\n");
            fprintf(o->output, "   <Update/>\n");
            fprintf(o->output, "   <Delete/>\n");
          } else if (ows_version_get(o->request->version) == 110) {
            fprintf(o->output, "   <Operation>Insert</Operation>\n");
            fprintf(o->output, "   <Operation>Update</Operation>\n");
            fprintf(o->output, "   <Operation>Delete</Operation>\n");
          }
        }

        fprintf(o->output, "  </Operations>\n");
      }

      /* Boundaries */
      if (!ln->layer->geobbox) {
        gb = ows_geobbox_compute(o, ln->layer->name);
      } else {
        gb = ows_geobbox_init();
        gb->west = ln->layer->geobbox->west;
        gb->east = ln->layer->geobbox->east;
        gb->south = ln->layer->geobbox->south;
        gb->north = ln->layer->geobbox->north;
      }
      assert(gb);

      for (s = 0; s < ln->layer->depth; s++) fprintf(o->output, " ");

      if (ows_version_get(o->request->version) == 100)
        fprintf(o->output, " <LatLongBoundingBox");
      else if (ows_version_get(o->request->version) == 110)
        fprintf(o->output, " <ows:WGS84BoundingBox>");

      if (gb->east != DBL_MIN) {
        if (ows_version_get(o->request->version) == 100) {
          if (gb->west < gb->east)
            fprintf(o->output, " minx='%.*f'", o->degree_precision, gb->west);
          else
            fprintf(o->output, " minx='%.*f'", o->degree_precision, gb->east);

          if (gb->north < gb->south)
            fprintf(o->output, " miny='%.*f'", o->degree_precision, gb->north);
          else
            fprintf(o->output, " miny='%.*f'", o->degree_precision, gb->south);

          if (gb->west < gb->east)
            fprintf(o->output, " maxx='%.*f'", o->degree_precision, gb->east);
          else
            fprintf(o->output, " maxx='%.*f'", o->degree_precision, gb->west);

          if (gb->north < gb->south)
            fprintf(o->output, " maxy='%.*f'", o->degree_precision, gb->south);
          else
            fprintf(o->output, " maxy='%.*f'", o->degree_precision, gb->north);

          fprintf(o->output, " />\n");
        } else if (ows_version_get(o->request->version) == 110) {
          fprintf(o->output, " <ows:LowerCorner>%.*f %.*f</ows:LowerCorner>",
                  o->degree_precision, gb->west, o->degree_precision, gb->south);
          fprintf(o->output, " <ows:UpperCorner>%.*f %.*f</ows:UpperCorner>",
                  o->degree_precision, gb->east, o->degree_precision, gb->north);
        }
      } else {
        if (ows_version_get(o->request->version) == 100) {
          fprintf(o->output, " minx='0' miny='0' maxx='0' maxy='0'/>\n");
        } else if (ows_version_get(o->request->version) == 110) {
          fprintf(o->output, " <ows:LowerCorner>0 0</ows:LowerCorner>");
          fprintf(o->output, " <ows:UpperCorner>0 0</ows:UpperCorner>");
        }
      }

      if (ows_version_get(o->request->version) == 110)
        fprintf(o->output, " </ows:WGS84BoundingBox>\n");

      buffer_free(srid);
      buffer_free(srs);
      ows_geobbox_free(gb);

      fprintf(o->output, "</FeatureType>\n");
    }
  }

  fprintf(o->output, " </FeatureTypeList>\n");
}