Changeset 195

Show
Ignore:
Timestamp:
01/21/10 22:19:43 (8 months ago)
Author:
ol
Message:

Use PostGIS 1.5 GeomFromGML to parse GML instead of TinyOWS one. Add check_schema and check_valid_geom config properties to allow to bypass schema and is_valid check, cf #44.

Files:
11 modified

Legend:

Unmodified
Added
Removed
  • configure.in

    r100 r195  
    8686 
    8787echo "------------------------" 
    88 echo "This TinyOWS version will need at least PostGIS 1.4.x" 
     88echo "This TinyOWS version will need at least PostGIS 1.5.x" 
    8989echo "------------------------" 
  • demo/install.sh.in

    r179 r195  
    55 
    66PGBIN=@POSTGIS_BIN@ 
    7 PGSHARE=@POSTGIS_SHARE@/contrib/ 
     7PGSHARE=@POSTGIS_SHARE@/contrib/postgis-1.5 
    88PGUSER=postgres 
    99DB=tinyows_demo 
  • src/fe/fe_filter.c

    r191 r195  
    4040    assert(fe != NULL); 
    4141 
    42     fe->sql = NULL; 
     42    fe->sql = buffer_init(); 
    4343    fe->error_code = FE_NO_ERROR; 
    4444 
     
    5656    if (fe->sql != NULL) 
    5757        buffer_free(fe->sql); 
    58  
     58     
    5959    free(fe); 
    6060    fe = NULL; 
     
    443443    xmlInitParser(); 
    444444    LIBXML_TEST_VERSION  
    445     fe->sql = buffer_init(); 
    446445 
    447446    xmldoc = xmlParseMemory(xmlchar->buf, xmlchar->use); 
  • src/fe/fe_spatial_ops.c

    r177 r195  
    5757 
    5858/* 
     59 * Transform syntax coordinates from GML 2.1.2 (x1,y1 x2,y2) into Postgis (x1 y1,x2 y2) 
     60 */ 
     61static  buffer *fe_transform_coord_gml_to_psql(buffer * coord) 
     62{ 
     63    size_t i; 
     64    assert(coord != NULL); 
     65 
     66    /*check if the first separator is a comma else do nothing */ 
     67    if (check_regexp(coord->buf, "^[0-9.-]+,")) { 
     68        for (i = 0; i < coord->use; i++) { 
     69            if (coord->buf[i] == ' ')       coord->buf[i] = ','; 
     70            else if (coord->buf[i] == ',')  coord->buf[i] = ' '; 
     71        } 
     72    } 
     73 
     74    return coord; 
     75} 
     76 
     77 
     78/* 
    5979 * Write a polygon geometry according to postgresql syntax from GML bbox 
    6080 */ 
     
    161181 
    162182/* 
    163  * Transform syntax coordinates from GML 2.1.2 (x1,y1 x2,y2) into Postgis (x1 y1,x2 y2) 
    164  */ 
    165 buffer *fe_transform_coord_gml_to_psql(buffer * coord) 
    166 { 
    167     size_t i; 
    168  
    169     assert(coord != NULL); 
    170  
    171     /*check if the first separator is a comma else do nothing */ 
    172     if (check_regexp(coord->buf, "^[0-9.-]+,")) { 
    173         for (i = 0; i < coord->use; i++) { 
    174             if (coord->buf[i] == ' ') 
    175                 coord->buf[i] = ','; 
    176             else if (coord->buf[i] == ',') 
    177                 coord->buf[i] = ' '; 
    178         } 
    179     } 
    180  
    181     return coord; 
    182 } 
    183  
    184  
    185 /* 
    186  * Transform syntax coordinates from GML 3.1.1 (x1 y1 x2 y2) into Postgis' (x1 y1,x2 y2) 
    187  */ 
    188 buffer *fe_transform_coord_gml3_to_psql(buffer * coord) 
    189 { 
    190     size_t i; 
    191     int nb_spaces; 
    192  
    193     assert(coord != NULL); 
    194  
    195     nb_spaces = 0; 
    196  
    197     for (i = 0; i < coord->use; i++) { 
    198         if (coord->buf[i] == ' ') { 
    199             nb_spaces++; 
    200  
    201             /* transform the second space separator into comma */ 
    202             if (nb_spaces == 2) { 
    203                 coord->buf[i] = ','; 
    204                 nb_spaces = 0; 
    205             } 
    206         } 
    207     } 
    208  
    209     return coord; 
    210 } 
    211  
    212  
    213 /* 
    214  * Transform a geometry expressed in GML into Postgis geometry syntax 
    215  */ 
    216 buffer *fe_transform_geometry_gml_to_psql(ows * o, buffer * typename, 
    217         filter_encoding * fe, xmlNodePtr n) 
    218 { 
    219     xmlChar *content; 
    220     xmlNodePtr node, node_coord; 
    221     buffer *tmp, *geom; 
    222     bool first_ring = true; 
    223     int bracket; 
     183 * Return the SQL request matching the spatial operator 
     184 */ 
     185static buffer *fe_spatial_functions(ows * o, buffer * typename, 
     186                                    filter_encoding * fe, xmlNodePtr n) 
     187{ 
     188    bool transform = false; 
     189    buffer *sql; 
    224190 
    225191    assert(o != NULL); 
     
    228194    assert(n != NULL); 
    229195 
    230     content = NULL; 
    231  
    232     /* jump to the next element if there are spaces */ 
    233     while (n->type != XML_ELEMENT_NODE) n = n->next; 
    234  
    235     buffer_add_str(fe->sql, "setsrid('"); 
    236  
    237     geom = buffer_init(); 
    238     if (strcmp((char *) n->name, "MultiSurface") == 0) 
    239         buffer_add_str(geom, "MultiPolygon"); 
    240     else 
    241         buffer_add_str(geom, (char *) n->name); 
    242  
    243     /* print the geometry type */ 
    244     if (buffer_cmp(geom, "MultiPolygon") || buffer_cmp(geom, "MultiSurface")) { 
    245         buffer_add_str(geom, "((("); 
    246         bracket = 3; 
    247     } else if (buffer_cmp(geom, "MultiLineString") 
    248                || buffer_cmp(geom, "Polygon")) { 
    249         buffer_add_str(geom, "(("); 
    250         bracket =2; 
    251     } else if (buffer_cmp(geom, "MultiPoint") 
    252                || buffer_cmp(geom, "Point")  
    253                || buffer_cmp(geom, "LineString")) { 
    254         buffer_add_str(geom, "("); 
    255         bracket = 1; 
    256     } else { 
    257         fe->error_code = FE_ERROR_GEOMETRY; 
    258         buffer_free(geom); 
    259         return fe->sql; 
    260     } 
    261     n = n->children; 
    262  
    263     /* jump to the next element if there are spaces */ 
    264     while (n->type != XML_ELEMENT_NODE) n = n->next; 
    265  
    266     /* print the coordinates */ 
    267     for (node = n; node != NULL; node = node->next) { 
    268  
    269         /* 
    270          * Ignore GML properties if any 
    271          */ 
    272         if ((strcmp((char *) node->name, "description") == 0  
    273             || strcmp((char *) node->name, "name") == 0   
    274             || strcmp((char *) node->name, "metaDataProperty") == 0)   
    275                 && strcmp((char *) node->ns->href, "http://www.opengis.net/gml")  == 0) 
    276             node = node->next; 
    277  
    278         if (node->type == XML_ELEMENT_NODE) { 
    279             node_coord = node; 
    280  
    281  
    282             /* go to node <coordinates> */ 
    283             while (strcmp((char *) node_coord->name, "coordinates") != 0 
    284                     && strcmp((char *) node_coord->name, "posList") != 0 
    285                     && strcmp((char *) node_coord->name, "pos") != 0) { 
    286  
    287                 while (node_coord != NULL && node_coord->type != XML_ELEMENT_NODE) { 
    288                     node_coord = node_coord->next; 
    289                 } 
    290  
    291                 if (node_coord == NULL) { 
    292                     fe->error_code = FE_ERROR_GEOMETRY; 
    293                     buffer_free(geom); 
    294                     return fe->sql; 
    295                } 
    296  
    297                 if (node_coord != NULL && node_coord->type == XML_ELEMENT_NODE  
    298                         && strcmp((char *) node_coord->name, "LinearRing") == 0) { 
    299                     buffer_pop(geom, 1); /* remove last coord comma or ( */ 
    300                     if (!first_ring) buffer_add_str(geom, "),"); 
    301                     buffer_add_str(geom, "("); 
    302                     first_ring = false; 
    303                 } 
    304  
    305                 /* jump to the next element if there are spaces */ 
    306                 if (strcmp((char *) node_coord->name, "coordinates") != 0 
    307                         && strcmp((char *) node_coord->name, "posList") != 0 
    308                         && strcmp((char *) node_coord->name, "pos") != 0) 
    309                     node_coord = node_coord->children; 
    310             } 
    311  
    312             tmp = buffer_init(); 
    313  
    314             content = xmlNodeGetContent(node_coord); 
    315             buffer_add_str(tmp, (char *) content); 
    316  
    317             if (strcmp((char *) node_coord->name, "coordinates") == 0) 
    318                 tmp = fe_transform_coord_gml_to_psql(tmp); 
    319             else 
    320                 tmp = fe_transform_coord_gml3_to_psql(tmp); 
    321  
    322             buffer_copy(geom, tmp); 
    323             buffer_free(tmp); 
    324             xmlFree(content); 
    325         } 
    326  
    327         if (node->next != NULL) { 
    328             if (node->next->type == XML_ELEMENT_NODE) { 
    329                 if (strcmp((char *) node->next->name, 
    330                            "lineStringMember") == 0) 
    331                     buffer_add_str(geom, "),("); 
    332                 else if (strcmp((char *) node->next->name, "polygonMember") == 0 
    333                      || strcmp((char *) node->next->name, "surfaceMember") == 0) 
    334                     buffer_add_str(geom, ")),(("); 
    335                 else 
    336                     buffer_add_str(geom, ","); 
    337             } 
    338         } 
    339     } 
    340  
    341     /* print the geometry type */ 
    342     if (bracket == 3) buffer_add_str(geom, ")))"); 
    343     else if (bracket == 2) buffer_add_str(geom, "))"); 
    344     else buffer_add_str(geom, ")"); 
    345  
    346     if (!ows_psql_is_geometry_valid(o, geom)) { 
    347         fe->error_code = FE_ERROR_GEOMETRY; 
    348         buffer_free(geom); 
    349         return fe->sql; 
    350     } 
    351  
    352     buffer_add_str(geom, "'::geometry,"); 
    353     buffer_copy(fe->sql, geom); 
    354  
    355     /* print the srid */ 
    356     buffer_add_int(fe->sql, ows_srs_get_srid_from_layer(o, typename)); 
    357     buffer_add_str(fe->sql, ")"); 
    358  
    359     buffer_free(geom); 
    360  
    361     return fe->sql; 
    362 } 
    363  
    364  
    365 /* 
    366  * Return the SQL request matching the spatial operator 
    367  */ 
    368 static buffer *fe_spatial_functions(ows * o, buffer * typename, 
    369                                     filter_encoding * fe, xmlNodePtr n) 
    370 { 
    371     bool transform = false; 
    372  
    373     assert(o != NULL); 
    374     assert(typename != NULL); 
    375     assert(fe != NULL); 
    376     assert(n != NULL); 
    377  
    378196    if (strcmp((char *) n->name, "Equals") == 0) 
    379         buffer_add_str(fe->sql, " Equals("); 
     197        buffer_add_str(fe->sql, " ST_Equals("); 
    380198 
    381199    if (strcmp((char *) n->name, "Disjoint") == 0) 
    382         buffer_add_str(fe->sql, " Disjoint("); 
     200        buffer_add_str(fe->sql, " ST_Disjoint("); 
    383201 
    384202    if (strcmp((char *) n->name, "Touches") == 0) 
    385         buffer_add_str(fe->sql, " Touches("); 
     203        buffer_add_str(fe->sql, " ST_Touches("); 
    386204 
    387205    if (strcmp((char *) n->name, "Within") == 0) 
    388         buffer_add_str(fe->sql, " Within("); 
     206        buffer_add_str(fe->sql, " ST_Within("); 
    389207 
    390208    if (strcmp((char *) n->name, "Overlaps") == 0) 
    391         buffer_add_str(fe->sql, " Overlaps("); 
     209        buffer_add_str(fe->sql, " ST_Overlaps("); 
    392210 
    393211    if (strcmp((char *) n->name, "Crosses") == 0) 
    394         buffer_add_str(fe->sql, " Crosses("); 
     212        buffer_add_str(fe->sql, " ST_Crosses("); 
    395213 
    396214    if (strcmp((char *) n->name, "Intersects") == 0) 
    397         buffer_add_str(fe->sql, " Intersects("); 
     215        buffer_add_str(fe->sql, " ST_Intersects("); 
    398216 
    399217    if (strcmp((char *) n->name, "Contains") == 0) 
    400         buffer_add_str(fe->sql, " Contains("); 
     218        buffer_add_str(fe->sql, " ST_Contains("); 
    401219 
    402220    n = n->children; 
     
    424242    while (n->type != XML_ELEMENT_NODE) n = n->next; 
    425243 
    426     buffer_add(fe->sql, ','); 
     244    buffer_add_str(fe->sql, ",'"); 
    427245 
    428246    if (strcmp((char *) n->name, "Box") == 0 
    429247            || strcmp((char *) n->name, "Envelope") == 0) 
    430248        fe->sql = fe_envelope(o, typename, fe, n); 
    431     else 
    432         fe->sql = fe_transform_geometry_gml_to_psql(o, typename, fe, n); 
    433  
    434     buffer_add(fe->sql, ')'); 
     249    else  { 
     250        sql = ows_psql_gml_to_sql(o, n); 
     251        if (sql != NULL) {  
     252            buffer_copy(fe->sql, sql); 
     253            buffer_free(sql); 
     254        } /* TODO else case */ 
     255    } 
     256 
     257    buffer_add_str(fe->sql, "')"); 
    435258 
    436259    return fe->sql; 
     
    446269{ 
    447270    xmlChar *content, *units; 
     271    buffer *tmp, *op, *sql; 
    448272    float km; 
    449     buffer *tmp, *op; 
    450273 
    451274    assert(o != NULL); 
     
    482305    fe->sql = fe_property_name(o, typename, fe, fe->sql, n, true); 
    483306 
    484     buffer_add_str(fe->sql, "),ST_centroid("); 
     307    buffer_add_str(fe->sql, "),ST_centroid('"); 
    485308 
    486309    n = n->next; 
     
    490313 
    491314    /* display the geometry */ 
    492     fe->sql = fe_transform_geometry_gml_to_psql(o, typename, fe, n); 
    493  
    494     buffer_add_str(fe->sql, "))"); 
     315    sql = ows_psql_gml_to_sql(o, n); 
     316    if (sql != NULL) { 
     317        buffer_copy(fe->sql, sql); 
     318        buffer_free(sql); 
     319    } /* TODO else case */ 
     320 
     321    buffer_add_str(fe->sql, "'))"); 
    495322 
    496323    n = n->next; 
  • src/ows/ows.h

    r168 r195  
    421421    bool wfs_display_bbox; 
    422422 
     423    bool check_schema; 
     424    bool check_valid_geom; 
     425 
    423426    array * cgi; 
    424427    list * psql_requests; 
  • src/ows/ows_config.c

    r193 r195  
    4242 
    4343    a = xmlTextReaderGetAttribute(r, (xmlChar *) "online_resource"); 
    44  
    4544    if (a != NULL) { 
    4645        o->online_resource = buffer_init(); 
     
    5049 
    5150    a = xmlTextReaderGetAttribute(r, (xmlChar *) "schema_dir"); 
    52  
    5351    if (a != NULL) { 
    5452        o->schema_dir = buffer_init(); 
     
    5856 
    5957    a = xmlTextReaderGetAttribute(r, (xmlChar *) "log"); 
    60  
    6158    if (a != NULL) { 
    6259        o->log = buffer_init(); 
     
    6663 
    6764    a = xmlTextReaderGetAttribute(r, (xmlChar *) "degree_precision"); 
    68  
    6965    if (a != NULL) { 
    7066        o->schema_dir = buffer_init(); 
    7167        precision = atoi((char *) a); 
    72  
    7368        if (precision > 0 && precision < 12) 
    7469            o->degree_precision = precision; 
    75  
    7670        xmlFree(a); 
    7771    } 
    7872 
    7973    a = xmlTextReaderGetAttribute(r, (xmlChar *) "meter_precision"); 
    80  
    8174    if (a != NULL) { 
    8275        o->schema_dir = buffer_init(); 
    8376        precision = atoi((char *) a); 
    84  
    8577        if (precision > 0 && precision < 12) 
    8678            o->meter_precision = precision; 
    87  
    8879        xmlFree(a); 
    8980    } 
    9081 
    9182    a = xmlTextReaderGetAttribute(r, (xmlChar *) "wfs_display_bbox"); 
    92  
    9383    o->wfs_display_bbox = true; 
    94  
    95     if (a != NULL) { 
    96         if (atoi((char *) a)) 
    97             o->wfs_display_bbox = true; 
    98         else 
    99             o->wfs_display_bbox = false; 
    100  
    101         xmlFree(a); 
    102     } 
    103  
     84    if (a != NULL) { 
     85        if (atoi((char *) a)) o->wfs_display_bbox = true; 
     86        else                  o->wfs_display_bbox = false; 
     87        xmlFree(a); 
     88    } 
     89 
     90    a = xmlTextReaderGetAttribute(r, (xmlChar *) "check_schema"); 
     91    o->check_schema = true; 
     92    if (a != NULL) { 
     93        if (atoi((char *) a)) o->check_schema = true; 
     94        else                  o->check_schema = false; 
     95        xmlFree(a); 
     96    } 
     97 
     98    a = xmlTextReaderGetAttribute(r, (xmlChar *) "check_valid_geom"); 
     99    o->check_valid_geom = true; 
     100    if (a != NULL) { 
     101        if (atoi((char *) a)) o->check_valid_geom = true; 
     102        else                  o->check_valid_geom = false; 
     103        xmlFree(a); 
     104    } 
    104105} 
    105106 
  • src/ows/ows_psql.c

    r192 r195  
    434434 
    435435 
    436  
    437 /* 
    438  *  * Return the number of rows returned by the specified requests 
    439  *   */ 
     436/* 
     437 * Return the number of rows returned by the specified requests 
     438 */ 
    440439int ows_psql_number_features(ows * o, list * from, list * where) 
    441440{ 
    442         buffer *sql; 
    443         PGresult *res; 
    444         list_node *ln_from, *ln_where; 
    445         int nb; 
    446  
    447         assert(o != NULL); 
    448         assert(from != NULL); 
    449         assert(where != NULL); 
    450  
    451         nb = 0; 
    452  
    453         /* checks if from list and where list have the same size */ 
    454         if (from->size != where->size) return nb; 
    455  
    456  
    457         for (ln_from = from->first, ln_where = where->first; ln_from != NULL; 
    458                  ln_from = ln_from->next, ln_where = ln_where->next) { 
    459                  sql = buffer_init(); 
    460  
    461                  /* execute the request */ 
    462                  buffer_add_str(sql, "SELECT count(*) FROM \""); 
    463                  buffer_copy(sql, ln_from->value); 
    464                  buffer_add_str(sql, "\" "); 
    465                  buffer_copy(sql, ln_where->value); 
    466                  res = PQexec(o->pg, sql->buf); 
    467                  buffer_free(sql); 
    468  
    469                  if (PQresultStatus(res) != PGRES_TUPLES_OK) { 
    470                      PQclear(res); 
    471                      return -1; 
    472                  } 
    473                  nb = nb + atoi(PQgetvalue(res, 0, 0)); 
     441    buffer *sql; 
     442    PGresult *res; 
     443    list_node *ln_from, *ln_where; 
     444    int nb; 
     445 
     446    assert(o != NULL); 
     447    assert(from != NULL); 
     448    assert(where != NULL); 
     449 
     450    nb = 0; 
     451 
     452    /* checks if from list and where list have the same size */ 
     453    if (from->size != where->size) return nb; 
     454 
     455 
     456    for (ln_from = from->first, ln_where = where->first; ln_from != NULL; 
     457             ln_from = ln_from->next, ln_where = ln_where->next) { 
     458             sql = buffer_init(); 
     459 
     460             /* execute the request */ 
     461             buffer_add_str(sql, "SELECT count(*) FROM \""); 
     462             buffer_copy(sql, ln_from->value); 
     463             buffer_add_str(sql, "\" "); 
     464             buffer_copy(sql, ln_where->value); 
     465             res = PQexec(o->pg, sql->buf); 
     466             buffer_free(sql); 
     467 
     468             if (PQresultStatus(res) != PGRES_TUPLES_OK) { 
    474469                 PQclear(res); 
    475          } 
    476  
    477         return nb; 
    478 } 
     470                 return -1; 
     471             } 
     472             nb = nb + atoi(PQgetvalue(res, 0, 0)); 
     473             PQclear(res); 
     474     } 
     475 
     476    return nb; 
     477} 
     478 
     479 
     480static xmlNodePtr ows_psql_recursive_parse_gml(ows * o, xmlNodePtr n) 
     481{ 
     482    xmlNodePtr c; 
     483    static xmlNodePtr result=NULL; 
     484 
     485    assert(o != NULL); 
     486    assert(n != NULL); 
     487 
     488    if (result) return result;  /* avoid recursive loop */ 
     489 
     490    /* We are looking for the geometry part inside GML doc */ 
     491    for (; n ; n = n->next) { 
     492 
     493        if (n->type != XML_ELEMENT_NODE) continue; 
     494 
     495        /* GML SF Geometries Types */ 
     496        if (   !strcmp((char *) n->name, "Point") 
     497            || !strcmp((char *) n->name, "LineString") 
     498            || !strcmp((char *) n->name, "Curve") 
     499            || !strcmp((char *) n->name, "Polygon") 
     500            || !strcmp((char *) n->name, "Surface") 
     501            || !strcmp((char *) n->name, "MultiPoint") 
     502            || !strcmp((char *) n->name, "MultiLineString") 
     503            || !strcmp((char *) n->name, "MultiCurve") 
     504            || !strcmp((char *) n->name, "MultiPolygon") 
     505            || !strcmp((char *) n->name, "MultiSurface") 
     506            || !strcmp((char *) n->name, "MultiGeometry")) { 
     507 
     508            return n; 
     509        } 
     510        /* TODO Add check on namespace GML 3 and GML 3.2 */ 
     511 
     512        /* Recursive exploration */ 
     513        if (n->children) 
     514            for (c = n->children ; c ; c = c->next) 
     515                if ((result = ows_psql_recursive_parse_gml(o, c))) 
     516                    return result; 
     517    } 
     518 
     519    return NULL; 
     520} 
     521 
     522 
     523/* 
     524 * Transform a GML geometry to PostGIS EWKT 
     525 * Return NULL on error 
     526 */ 
     527buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n) 
     528{ 
     529    PGresult *res; 
     530    xmlNodePtr g; 
     531    buffer *result, *sql, *gml; 
     532 
     533    assert(o != NULL); 
     534    assert(n != NULL); 
     535 
     536    g = ows_psql_recursive_parse_gml(o, n); 
     537    if (!g) return NULL;    /* No Geometry founded in GML doc */ 
     538 
     539    /* Retrieve the sub doc and launch GML parse via PostGIS */ 
     540    gml = buffer_init(); 
     541    cgi_add_xml_into_buffer(gml, g); 
     542     
     543    sql = buffer_init(); 
     544    buffer_add_str(sql, "SELECT ST_GeomFromGML('"); 
     545    buffer_add_str(sql, gml->buf); 
     546    buffer_add_str(sql, "')"); 
     547 
     548    res = PQexec(o->pg, sql->buf); 
     549    buffer_free(gml); 
     550 
     551 
     552    /* GML Parse errors cases */ 
     553    if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { 
     554        buffer_free(sql); 
     555        PQclear(res); 
     556        return NULL; 
     557    } 
     558 
     559    result = buffer_init(); 
     560    buffer_add_str(result, PQgetvalue(res, 0, 0)); 
     561    PQclear(res); 
     562 
     563    /* Check if geometry is valid */ 
     564    if (o->check_valid_geom) { 
     565 
     566        buffer_empty(sql); 
     567        buffer_add_str(sql, "SELECT ST_IsValid('"); 
     568        buffer_add_str(sql, result->buf); 
     569        buffer_add_str(sql, "')"); 
     570 
     571        res = PQexec(o->pg, sql->buf); 
     572 
     573        if (   PQresultStatus(res) != PGRES_TUPLES_OK 
     574            || PQntuples(res) != 1 
     575            || (char) PQgetvalue(res, 0, 0)[0] !=  't') { 
     576            buffer_free(sql); 
     577            buffer_free(result); 
     578            PQclear(res); 
     579            return NULL; 
     580        } 
     581    } 
     582 
     583    buffer_free(sql); 
     584    PQclear(res); 
     585 
     586    return result; 
     587} 
     588 
    479589 
    480590/* 
  • src/ows/ows_request.c

    r190 r195  
    390390    if ((cgi_method_post() && strcmp(getenv("CONTENT_TYPE"), "application/x-www-form-urlencoded") != 0) 
    391391            || (!cgi_method_post() && !cgi_method_get() && query[0] == '<')) { 
    392         xmlstring = buffer_init(); 
    393         buffer_add_str(xmlstring, query); 
    394  
    395         if (or->service == WFS) { 
     392 
     393        if (or->service == WFS && o->check_schema) { 
     394 
     395            xmlstring = buffer_init(); 
     396            buffer_add_str(xmlstring, query); 
    396397 
    397398            if (ows_version_get(or->version) == 100) { 
     
    418419 
    419420            buffer_free(schema); 
    420         } 
    421  
    422         buffer_free(xmlstring); 
    423  
    424         if (valid != 0) 
    425             ows_error(o, OWS_ERROR_INVALID_PARAMETER_VALUE, 
     421            buffer_free(xmlstring); 
     422             
     423            if (valid != 0) 
     424                ows_error(o, OWS_ERROR_INVALID_PARAMETER_VALUE, 
    426425                      "xml isn't valid", "request"); 
     426        } 
    427427    } 
    428428} 
  • src/ows_api.h

    r192 r195  
    5555buffer *fe_property_name (ows * o, buffer * typename, filter_encoding * fe, buffer * sql, xmlNodePtr n, bool check_geom_column); 
    5656buffer *fe_spatial_op (ows * o, buffer * typename, filter_encoding * fe, xmlNodePtr n); 
    57 buffer *fe_transform_coord_gml3_to_psql (buffer * coord); 
    58 buffer *fe_transform_coord_gml_to_psql (buffer * coord); 
    59 buffer *fe_transform_geometry_gml_to_psql (ows * o, buffer * typename, filter_encoding * fe, xmlNodePtr n); 
    6057buffer *fe_xpath_property_name (ows * o, buffer * typename, buffer * property); 
    6158buffer *fill_fe_error (ows * o, filter_encoding * fe); 
     
    147144buffer *ows_psql_generate_id (ows * o, buffer * layer_name); 
    148145int ows_psql_number_features(ows * o, list * from, list * where); 
     146buffer * ows_psql_gml_to_sql(ows * o, xmlNodePtr n); 
    149147void ows_request_check (ows * o, ows_request * or, const array * cgi, const char *query); 
    150148void ows_request_flush (ows_request * or, FILE * output); 
  • src/wfs/wfs_transaction.c

    r192 r195  
    316316static buffer *wfs_insert_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNodePtr n) 
    317317{ 
    318     buffer *values, *column, *layer_name, *layer_prefix, *result, *sql; 
     318    buffer *values, *column, *layer_name, *layer_prefix, *result, *sql, *gml; 
    319319    buffer *id, *handle, *id_column, *fid_full_name, *dup_sql; 
    320320    filter_encoding *fe; 
     
    332332    sql = buffer_init(); 
    333333    handle = buffer_init(); 
    334     id =  buffer_init(); 
    335334 
    336335    /* retrieve handle attribute to report it in transaction response */ 
     
    471470                    while (elemt->type != XML_ELEMENT_NODE) elemt = elemt->next; 
    472471 
    473                     fe = filter_encoding_init(); 
    474                     fe->sql = buffer_init(); 
    475  
    476472                    if (strcmp((char *) elemt->name, "Box") == 0 
    477473                            || strcmp((char *) elemt->name, "Envelope") == 0) { 
     474 
     475                        fe = filter_encoding_init(); 
     476                        fe->sql = buffer_init(); 
    478477                        fe->sql = fe_envelope(o, layer_name, fe, elemt); 
    479478                        buffer_copy(values, fe->sql); 
     479                        filter_encoding_free(fe); 
     480 
    480481                    } else if (strcmp((char *) elemt->name, "Null") == 0) { 
    481482                        buffer_add_str(values, "''"); 
    482483                    } else { 
    483                         fe->sql = fe_transform_geometry_gml_to_psql(o, layer_name, fe, elemt); 
    484  
    485                         /* FIXME is it really the right way to handle that ?  
    486                          * What about an ows error instead ? 
    487                          */ 
    488                         if (fe->error_code) 
    489                             buffer_add_str(values, "NULL"); 
    490                         else 
    491                             buffer_copy(values, fe->sql); 
     484                        gml = ows_psql_gml_to_sql(o, n); 
     485                        if (gml != NULL) { 
     486                            buffer_add_str(values, "'"); 
     487                            buffer_copy(values, gml); 
     488                            buffer_add_str(values, "'"); 
     489                            buffer_free(gml); 
     490                        } /* TODO else case */ 
    492491                    } 
    493492 
    494                     filter_encoding_free(fe); 
    495493                } else { 
    496494                    values = wfs_retrieve_value(o, wr, values, xmldoc, node); 
     
    726724static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNodePtr n) 
    727725{ 
    728     buffer *typename, *xmlstring, *result, *sql, *property_name, *values; 
     726    buffer *typename, *xmlstring, *result, *sql, *property_name, *values, *gml; 
    729727    filter_encoding *filter, *fe; 
    730728    xmlNodePtr node, elemt; 
     
    797795                            elemt = elemt->next; 
    798796 
    799                         fe = filter_encoding_init(); 
    800                         fe->sql = buffer_init(); 
    801  
    802797                        if (strcmp((char *) elemt->name, "Box") == 0 
    803798                                || strcmp((char *) elemt->name, "Envelope") == 0) { 
     799 
     800                            fe = filter_encoding_init(); 
     801                            fe->sql = buffer_init(); 
    804802                            fe->sql = fe_envelope(o, typename, fe, elemt); 
    805803                            buffer_copy(values, fe->sql); 
     804                            filter_encoding_free(fe); 
     805 
    806806                        } else if (strcmp((char *) elemt->name, "Null") == 0) { 
    807807                            buffer_add_str(values, "''"); 
    808808                        } else { 
    809                             fe->sql = fe_transform_geometry_gml_to_psql(o, typename, fe, elemt); 
    810                             buffer_copy(values, fe->sql); 
     809                            gml = ows_psql_gml_to_sql(o, n); 
     810                            if (gml != NULL) { 
     811                                buffer_add_str(values, "'"); 
     812                                buffer_copy(values, gml); 
     813                                buffer_add_str(values, "'"); 
     814                                buffer_free(gml); 
     815                            } /* TODO else case */ 
    811816                        } 
    812817 
    813                         filter_encoding_free(fe); 
    814818                    } else { 
    815819                        values = wfs_retrieve_value(o, wr, values, xmldoc, node); 
  • test/install.sh.in

    r183 r195  
    55 
    66PG_BIN=@POSTGIS_BIN@ 
    7 PG_SHARE=@POSTGIS_SHARE@/contrib/ 
     7PG_SHARE=@POSTGIS_SHARE@/contrib/postgis-1.5 
    88PG_USER=postgres 
    99DB=tinyows_test