Skip to content

Commit

Permalink
improve MapServer#19. Add propertyname handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Courtin committed Nov 4, 2012
1 parent 8f18265 commit 33a9701
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/fe/fe_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ buffer *fe_property_name(ows * o, buffer * typename, filter_encoding * fe, buffe
xmlChar *content;
array *prop_table;
buffer *tmp;
list *l;
list *l, *ll;

assert(o);
assert(typename);
Expand Down Expand Up @@ -245,6 +245,10 @@ buffer *fe_property_name(ows * o, buffer * typename, filter_encoding * fe, buffe
}

/* Check if propertyname is available */
ll = list_init();
list_add(ll, typename);
tmp = wfs_request_remove_prop_ns_prefix(o, tmp, ll);
free(ll); /* don't call list_free here */
if (array_is_key(prop_table, tmp->buf)) {
buffer_copy(sql, tmp);
} else if (mandatory) fe->error_code = FE_ERROR_PROPERTYNAME;
Expand Down
1 change: 1 addition & 0 deletions src/ows_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void wfs_gml_feature_member (ows * o, wfs_request * wr, buffer * layer_name, lis
void wfs_parse_operation (ows * o, wfs_request * wr, buffer * op);
void wfs_request_check (ows * o, wfs_request * wr, const array * cgi);
void wfs_request_flush (wfs_request * wr, FILE * output);
buffer *wfs_request_remove_prop_ns_prefix(ows * o, buffer * prop, list * layer_name);
void wfs_request_free (wfs_request * wr);
wfs_request *wfs_request_init ();
ows_layer_storage * ows_layer_storage_init();
Expand Down
37 changes: 32 additions & 5 deletions src/wfs/wfs_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static void wfs_request_check_resulttype(ows * o, wfs_request * wr)
/*
* Check and fill the sortBy parameter
*/
static void wfs_request_check_sortby(ows * o, wfs_request * wr)
static void wfs_request_check_sortby(ows * o, wfs_request * wr, list * layer_name)
{
buffer *b;
list *l, *fe;
Expand All @@ -537,12 +537,13 @@ static void wfs_request_check_sortby(ows * o, wfs_request * wr)

for (ln = l->first ; ln ; ln = ln->next) {
fe = list_explode(' ', ln->value);
ln->value = wfs_request_remove_prop_ns_prefix(o, ln->value, layer_name);

/* add quotation marks */
/* Add quotation marks */
buffer_add_head_str(fe->first->value, "\"");
buffer_add_str(fe->first->value, "\"");

/* put the order into postgresql syntax */
/* SQL Order syntax */
if (fe->last->value && fe->last != fe->first) {
if (buffer_cmp(fe->last->value, "D") || buffer_cmp(fe->last->value, "DESC")) {
buffer_empty(fe->last->value);
Expand Down Expand Up @@ -592,6 +593,31 @@ static void wfs_request_check_maxfeatures(ows * o, wfs_request * wr)
}


/*
* TODO
*/
buffer *wfs_request_remove_prop_ns_prefix(ows * o, buffer * prop, list * layer_name)
{
list * ns;
list_node * ln;

assert(o);
assert(prop);
assert(layer_name);

ns = ows_layer_list_ns_prefix(o->layers, layer_name);

for (ln = ns->first ; ln ; ln = ln->next) {
if (buffer_ncmp(ln->value, prop->buf, ln->value->use)) {
buffer_shift(prop, ln->value->use + 1); /* +1 for : separator */
return prop;
}
}

return prop; /* if ns_prefix don't match, just don't do anything */
}


/*
* Check and fill the propertyName parameter
*/
Expand Down Expand Up @@ -633,10 +659,11 @@ static void wfs_request_check_propertyname(ows * o, wfs_request * wr, list * lay
ln->value = fe_xpath_property_name(o, ln_tpn->value, ln->value);

/* check if propertyname values are correct */
ln->value = wfs_request_remove_prop_ns_prefix(o, ln->value, layer_name);
if (!buffer_cmp(ln->value, "*") && !array_is_key(prop_table, ln->value->buf)) {
mlist_free(f);
ows_error(o, OWS_ERROR_INVALID_PARAMETER_VALUE,
"propertyname values not available", "GetFeature");
"PropertyName values not available", "GetFeature");
return;
}
}
Expand Down Expand Up @@ -858,7 +885,7 @@ static void wfs_request_check_get_feature(ows * o, wfs_request * wr, const array
if (!o->exit) wfs_request_check_propertyname(o, wr, layer_name); /* PropertyName */
if (!o->exit) wfs_request_check_output(o, wr); /* outputFormat */
if (!o->exit) wfs_request_check_resulttype(o, wr); /* resultType */
if (!o->exit) wfs_request_check_sortby(o, wr); /* sortBy */
if (!o->exit) wfs_request_check_sortby(o, wr, layer_name); /* sortBy */
if (!o->exit) wfs_request_check_maxfeatures(o, wr); /* maxFeatures */
if (!o->exit) wfs_request_check_filter(o, wr); /* Filter */

Expand Down
5 changes: 5 additions & 0 deletions src/wfs/wfs_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
ows_srs *srs_root;
int srid_root = 0;
xmlChar *attr = NULL;
list *l;

assert(o);
assert(wr);
Expand Down Expand Up @@ -901,6 +902,10 @@ static buffer *wfs_update_xml(ows * o, wfs_request * wr, xmlDocPtr xmldoc, xmlNo
buffer_add_str(property_name, (char *) content);
xmlFree(content);
buffer_add_str(sql, "\"");
l = list_init();
list_add(l, property_name);
property_name = wfs_request_remove_prop_ns_prefix(o, property_name, l);
free(l);
escaped = ows_psql_escape_string(o, property_name->buf);
if (escaped) {
buffer_add_str(sql, escaped);
Expand Down

0 comments on commit 33a9701

Please sign in to comment.